src: Yearly copyright bump
[quassel.git] / src / qtui / chatviewsettings.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2019 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include "chatviewsettings.h"
22
23 #include "chatscene.h"
24 #include "chatview.h"
25
26 ChatViewSettings::ChatViewSettings(const QString& id)
27     : QtUiSettings(QString("ChatView/%1").arg(id))
28 {}
29
30 ChatViewSettings::ChatViewSettings(ChatScene* scene)
31     : QtUiSettings(QString("ChatView/%1").arg(scene->idString()))
32 {}
33
34 ChatViewSettings::ChatViewSettings(ChatView* view)
35     : QtUiSettings(QString("ChatView/%1").arg(view->scene()->idString()))
36 {}
37
38 bool ChatViewSettings::showWebPreview() const
39 {
40     return localValue("ShowWebPreview", false).toBool();
41 }
42
43 void ChatViewSettings::enableWebPreview(bool enabled)
44 {
45     setLocalValue("ShowWebPreview", enabled);
46 }
47
48 bool ChatViewSettings::useCustomTimestampFormat() const
49 {
50     return localValue("UseCustomTimestampFormat", false).toBool();
51 }
52
53 void ChatViewSettings::setUseCustomTimestampFormat(bool enabled)
54 {
55     setLocalValue("UseCustomTimestampFormat", enabled);
56 }
57
58 QString ChatViewSettings::timestampFormatString() const
59 {
60     // Include a space in the default TimestampFormat to give the timestamp a small bit of padding
61     // between the border of the chat buffer window and the numbers.  Helps with readability.
62     return localValue("TimestampFormat", " hh:mm:ss").toString();
63 }
64
65 void ChatViewSettings::setTimestampFormatString(const QString& format)
66 {
67     setLocalValue("TimestampFormat", format);
68 }
69
70 UiStyle::SenderPrefixMode ChatViewSettings::senderPrefixDisplay() const
71 {
72     return static_cast<UiStyle::SenderPrefixMode>(
73         localValue("SenderPrefixMode", QVariant::fromValue<UiStyle::SenderPrefixMode>(UiStyle::SenderPrefixMode::HighestMode)).toInt());
74     // Cast the QVariant to an integer, then cast that to the enum class.
75     // .canConvert<UiStyle::SenderPrefixMode>() returned true, but
76     // .value<UiStyle::SenderPrefixMode>(); always gave the default value 0.
77     //
78     // There's probably a cleaner way of doing this.  I couldn't find it within 4 hours, so...
79 }
80
81 bool ChatViewSettings::showSenderBrackets() const
82 {
83     return localValue("ShowSenderBrackets", false).toBool();
84 }
85
86 void ChatViewSettings::enableSenderBrackets(bool enabled)
87 {
88     setLocalValue("ShowSenderBrackets", enabled);
89 }
90
91 QString ChatViewSettings::webSearchUrlFormatString() const
92 {
93     return localValue("WebSearchUrlFormat", "https://www.google.com/search?q=%s").toString();
94 }
95
96 void ChatViewSettings::setWebSearchUrlFormatString(const QString& format)
97 {
98     setLocalValue("WebSearchUrlFormat", format);
99 }