1 /***************************************************************************
2 * Copyright (C) 2005-2020 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))
30 ChatViewSettings::ChatViewSettings(ChatScene* scene)
31 : QtUiSettings(QString("ChatView/%1").arg(scene->idString()))
34 ChatViewSettings::ChatViewSettings(ChatView* view)
35 : QtUiSettings(QString("ChatView/%1").arg(view->scene()->idString()))
38 bool ChatViewSettings::showWebPreview() const
40 return localValue("ShowWebPreview", false).toBool();
43 void ChatViewSettings::enableWebPreview(bool enabled)
45 setLocalValue("ShowWebPreview", enabled);
48 bool ChatViewSettings::useCustomTimestampFormat() const
50 return localValue("UseCustomTimestampFormat", false).toBool();
53 void ChatViewSettings::setUseCustomTimestampFormat(bool enabled)
55 setLocalValue("UseCustomTimestampFormat", enabled);
58 QString ChatViewSettings::timestampFormatString() const
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();
65 void ChatViewSettings::setTimestampFormatString(const QString& format)
67 setLocalValue("TimestampFormat", format);
70 UiStyle::SenderPrefixMode ChatViewSettings::senderPrefixDisplay() const
72 return static_cast<UiStyle::SenderPrefixMode>(
73 localValue("SenderPrefixMode", QVariant::fromValue(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.
78 // There's probably a cleaner way of doing this. I couldn't find it within 4 hours, so...
81 bool ChatViewSettings::showSenderBrackets() const
83 return localValue("ShowSenderBrackets", false).toBool();
86 void ChatViewSettings::enableSenderBrackets(bool enabled)
88 setLocalValue("ShowSenderBrackets", enabled);
91 QString ChatViewSettings::webSearchUrlFormatString() const
93 return localValue("WebSearchUrlFormat", "https://www.google.com/search?q=%s").toString();
96 void ChatViewSettings::setWebSearchUrlFormatString(const QString& format)
98 setLocalValue("WebSearchUrlFormat", format);