1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
21 #include "chatviewsettings.h"
23 #include "chatscene.h"
26 ChatViewSettings::ChatViewSettings(const QString &id)
27 : QtUiSettings(QString("ChatView/%1").arg(id))
32 ChatViewSettings::ChatViewSettings(ChatScene *scene)
33 : QtUiSettings(QString("ChatView/%1").arg(scene->idString()))
38 ChatViewSettings::ChatViewSettings(ChatView *view)
39 : QtUiSettings(QString("ChatView/%1").arg(view->scene()->idString()))
44 bool ChatViewSettings::showWebPreview() const
46 return localValue("ShowWebPreview", false).toBool();
50 void ChatViewSettings::enableWebPreview(bool enabled)
52 setLocalValue("ShowWebPreview", enabled);
56 bool ChatViewSettings::useCustomTimestampFormat() const
58 return localValue("UseCustomTimestampFormat", false).toBool();
62 void ChatViewSettings::setUseCustomTimestampFormat(bool enabled)
64 setLocalValue("UseCustomTimestampFormat", enabled);
68 QString ChatViewSettings::timestampFormatString() const
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();
76 void ChatViewSettings::setTimestampFormatString(const QString &format)
78 setLocalValue("TimestampFormat", format);
82 UiStyle::SenderPrefixMode ChatViewSettings::senderPrefixDisplay() const
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.
92 // There's probably a cleaner way of doing this. I couldn't find it within 4 hours, so...
96 bool ChatViewSettings::showSenderBrackets() const
98 return localValue("ShowSenderBrackets", false).toBool();
102 void ChatViewSettings::enableSenderBrackets(bool enabled)
104 setLocalValue("ShowSenderBrackets", enabled);
108 QString ChatViewSettings::webSearchUrlFormatString() const
110 return localValue("WebSearchUrlFormat", "https://www.google.com/search?q=%s").toString();
114 void ChatViewSettings::setWebSearchUrlFormatString(const QString &format)
116 setLocalValue("WebSearchUrlFormat", format);