modernize: Remove old-style slot usage in NetworkModelController
[quassel.git] / src / qtui / chatviewsettings.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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
31
32 ChatViewSettings::ChatViewSettings(ChatScene *scene)
33     : QtUiSettings(QString("ChatView/%1").arg(scene->idString()))
34 {
35 }
36
37
38 ChatViewSettings::ChatViewSettings(ChatView *view)
39     : QtUiSettings(QString("ChatView/%1").arg(view->scene()->idString()))
40 {
41 }
42
43
44 bool ChatViewSettings::showWebPreview() const
45 {
46     return localValue("ShowWebPreview", false).toBool();
47 }
48
49
50 void ChatViewSettings::enableWebPreview(bool enabled)
51 {
52     setLocalValue("ShowWebPreview", enabled);
53 }
54
55
56 bool ChatViewSettings::useCustomTimestampFormat() const
57 {
58     return localValue("UseCustomTimestampFormat", false).toBool();
59 }
60
61
62 void ChatViewSettings::setUseCustomTimestampFormat(bool enabled)
63 {
64     setLocalValue("UseCustomTimestampFormat", enabled);
65 }
66
67
68 QString ChatViewSettings::timestampFormatString() const
69 {
70     // Include a space in the default TimestampFormat to give the timestamp a small bit of padding
71     // between the border of the chat buffer window and the numbers.  Helps with readability.
72     return localValue("TimestampFormat", " hh:mm:ss").toString();
73 }
74
75
76 void ChatViewSettings::setTimestampFormatString(const QString &format)
77 {
78     setLocalValue("TimestampFormat", format);
79 }
80
81
82 UiStyle::SenderPrefixMode ChatViewSettings::senderPrefixDisplay() const
83 {
84     return static_cast<UiStyle::SenderPrefixMode>(
85                 localValue("SenderPrefixMode",
86                            QVariant::fromValue<UiStyle::SenderPrefixMode>(
87                                UiStyle::SenderPrefixMode::HighestMode)).toInt());
88     // Cast the QVariant to an integer, then cast that to the enum class.
89     // .canConvert<UiStyle::SenderPrefixMode>() returned true, but
90     // .value<UiStyle::SenderPrefixMode>(); always gave the default value 0.
91     //
92     // There's probably a cleaner way of doing this.  I couldn't find it within 4 hours, so...
93 }
94
95
96 bool ChatViewSettings::showSenderBrackets() const
97 {
98     return localValue("ShowSenderBrackets", false).toBool();
99 }
100
101
102 void ChatViewSettings::enableSenderBrackets(bool enabled)
103 {
104     setLocalValue("ShowSenderBrackets", enabled);
105 }
106
107
108 QString ChatViewSettings::webSearchUrlFormatString() const
109 {
110     return localValue("WebSearchUrlFormat", "https://www.google.com/search?q=%s").toString();
111 }
112
113
114 void ChatViewSettings::setWebSearchUrlFormatString(const QString &format)
115 {
116     setLocalValue("WebSearchUrlFormat", format);
117 }