target_sources(${TARGET} PRIVATE
abstractmessageprocessor.cpp
backlogrequester.cpp
+ backlogsettings.cpp
buffermodel.cpp
buffersettings.cpp
bufferviewoverlay.cpp
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-2018 by the Quassel Project *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "backlogsettings.h"
+
+BacklogSettings::BacklogSettings()
+ : ClientSettings("Backlog")
+{}
+
+
+int BacklogSettings::requesterType() const
+{
+ return localValue("RequesterType", BacklogRequester::PerBufferUnread).toInt();
+}
+
+
+void BacklogSettings::setRequesterType(int requesterType)
+{
+ setLocalValue("RequesterType", requesterType);
+}
+
+
+int BacklogSettings::dynamicBacklogAmount() const
+{
+ return localValue("DynamicBacklogAmount", 200).toInt();
+}
+
+
+void BacklogSettings::setDynamicBacklogAmount(int amount)
+{
+ return setLocalValue("DynamicBacklogAmount", amount);
+}
+
+
+int BacklogSettings::fixedBacklogAmount() const
+{
+ return localValue("FixedBacklogAmount", 500).toInt();
+}
+
+
+void BacklogSettings::setFixedBacklogAmount(int amount)
+{
+ return setLocalValue("FixedBacklogAmount", amount);
+}
+
+
+int BacklogSettings::globalUnreadBacklogLimit() const
+{
+ return localValue("GlobalUnreadBacklogLimit", 5000).toInt();
+}
+
+
+void BacklogSettings::setGlobalUnreadBacklogLimit(int limit)
+{
+ return setLocalValue("GlobalUnreadBacklogLimit", limit);
+}
+
+
+int BacklogSettings::globalUnreadBacklogAdditional() const
+{
+ return localValue("GlobalUnreadBacklogAdditional", 100).toInt();
+}
+
+
+void BacklogSettings::setGlobalUnreadBacklogAdditional(int additional)
+{
+ return setLocalValue("GlobalUnreadBacklogAdditional", additional);
+}
+
+
+int BacklogSettings::perBufferUnreadBacklogLimit() const
+{
+ return localValue("PerBufferUnreadBacklogLimit", 200).toInt();
+}
+
+
+void BacklogSettings::setPerBufferUnreadBacklogLimit(int limit)
+{
+ return setLocalValue("PerBufferUnreadBacklogLimit", limit);
+}
+
+
+int BacklogSettings::perBufferUnreadBacklogAdditional() const
+{
+ return localValue("PerBufferUnreadBacklogAdditional", 50).toInt();
+}
+
+
+void BacklogSettings::setPerBufferUnreadBacklogAdditional(int additional)
+{
+ return setLocalValue("PerBufferUnreadBacklogAdditional", additional);
+}
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#ifndef BACKLOGSETTINGS_H
-#define BACKLOGSETTINGS_H
+#pragma once
-#include "clientsettings.h"
+#include "client-export.h"
-// For backlog requester types
#include "backlogrequester.h"
+#include "clientsettings.h"
-class BacklogSettings : public ClientSettings
+class CLIENT_EXPORT BacklogSettings : public ClientSettings
{
public:
- BacklogSettings() : ClientSettings("Backlog") {}
- inline int requesterType() { return localValue("RequesterType", BacklogRequester::PerBufferUnread).toInt(); }
+ BacklogSettings();
+ int requesterType() const;
// Default to PerBufferUnread to help work around performance problems on connect when there's
// many buffers that don't have much activity.
- inline void setRequesterType(int requesterType) { setLocalValue("RequesterType", requesterType); }
+ void setRequesterType(int requesterType);
- inline int dynamicBacklogAmount() { return localValue("DynamicBacklogAmount", 200).toInt(); }
- inline void setDynamicBacklogAmount(int amount) { return setLocalValue("DynamicBacklogAmount", amount); }
+ int dynamicBacklogAmount() const;
+ void setDynamicBacklogAmount(int amount);
- inline int fixedBacklogAmount() { return localValue("FixedBacklogAmount", 500).toInt(); }
- inline void setFixedBacklogAmount(int amount) { return setLocalValue("FixedBacklogAmount", amount); }
+ int fixedBacklogAmount() const;
+ void setFixedBacklogAmount(int amount);
- inline int globalUnreadBacklogLimit() { return localValue("GlobalUnreadBacklogLimit", 5000).toInt(); }
- inline void setGlobalUnreadBacklogLimit(int limit) { return setLocalValue("GlobalUnreadBacklogLimit", limit); }
- inline int globalUnreadBacklogAdditional() { return localValue("GlobalUnreadBacklogAdditional", 100).toInt(); }
- inline void setGlobalUnreadBacklogAdditional(int Additional) { return setLocalValue("GlobalUnreadBacklogAdditional", Additional); }
+ int globalUnreadBacklogLimit() const;
+ void setGlobalUnreadBacklogLimit(int limit);
+ int globalUnreadBacklogAdditional() const;
+ void setGlobalUnreadBacklogAdditional(int additional);
- inline int perBufferUnreadBacklogLimit() { return localValue("PerBufferUnreadBacklogLimit", 200).toInt(); }
- inline void setPerBufferUnreadBacklogLimit(int limit) { return setLocalValue("PerBufferUnreadBacklogLimit", limit); }
- inline int perBufferUnreadBacklogAdditional() { return localValue("PerBufferUnreadBacklogAdditional", 50).toInt(); }
- inline void setPerBufferUnreadBacklogAdditional(int Additional) { return setLocalValue("PerBufferUnreadBacklogAdditional", Additional); }
+ int perBufferUnreadBacklogLimit() const;
+ void setPerBufferUnreadBacklogLimit(int limit);
+ int perBufferUnreadBacklogAdditional() const;
+ void setPerBufferUnreadBacklogAdditional(int additional);
};
-
-
-#endif //BACKLOGSETTINGS_H
}
+void BufferSettings::setValue(const QString &key, const QVariant &data)
+{
+ setLocalValue(key, data);
+}
+
+
+QVariant BufferSettings::value(const QString &key, const QVariant &def) const
+{
+ return localValue(key, def);
+}
+
+
void BufferSettings::filterMessage(Message::Type msgType, bool filter)
{
if (!hasFilter())
}
+bool BufferSettings::hasFilter() const
+{
+ return localValue("hasMessageTypeFilter", false).toBool();
+}
+
+
+int BufferSettings::messageFilter() const
+{
+ return localValue("MessageTypeFilter", 0).toInt();
+}
+
+
void BufferSettings::setMessageFilter(int filter)
{
if (!hasFilter())
setLocalValue("hasMessageTypeFilter", false);
removeLocalKey("MessageTypeFilter");
}
+
+
+bool BufferSettings::showUserStateIcons() const
+{
+ return localValue("ShowUserStateIcons", true).toBool();
+}
+
+
+void BufferSettings::enableUserStateIcons(bool enabled)
+{
+ setLocalValue("ShowUserStateIcons", enabled);
+}
+
+
+int BufferSettings::userNoticesTarget() const
+{
+ return localValue("UserNoticesTarget", RedirectTarget::DefaultBuffer | RedirectTarget::CurrentBuffer).toInt();
+}
+
+
+void BufferSettings::setUserNoticesTarget(int target)
+{
+ setLocalValue("UserNoticesTarget", target);
+}
+
+
+int BufferSettings::serverNoticesTarget() const
+{
+ return localValue("ServerNoticesTarget", RedirectTarget::StatusBuffer).toInt();
+}
+
+
+void BufferSettings::setServerNoticesTarget(int target)
+{
+ setLocalValue("ServerNoticesTarget", target);
+}
+
+
+int BufferSettings::errorMsgsTarget() const
+{
+ return localValue("ErrorMsgsTarget", RedirectTarget::DefaultBuffer).toInt();
+}
+
+
+void BufferSettings::setErrorMsgsTarget(int target)
+{
+ setLocalValue("ErrorMsgsTarget", target);
+}
BufferSettings(const QString &idString = "__default__");
BufferSettings(BufferId bufferId);
- inline void setValue(const QString &key, const QVariant &data) { setLocalValue(key, data); }
- inline QVariant value(const QString &key, const QVariant &def = QVariant()) { return localValue(key, def); }
+ void setValue(const QString &key, const QVariant &data);
+ QVariant value(const QString &key, const QVariant &def = {}) const;
// Message Filter (default and per view)
- inline bool hasFilter() { return localValue("hasMessageTypeFilter", false).toBool(); }
- inline int messageFilter() { return localValue("MessageTypeFilter", 0).toInt(); }
+ bool hasFilter() const;
+ int messageFilter() const;
void setMessageFilter(int filter);
void filterMessage(Message::Type msgType, bool filter);
void removeFilter();
// user state icons for query buffers (default)
- inline bool showUserStateIcons() { return localValue("ShowUserStateIcons", true).toBool(); }
- inline void enableUserStateIcons(bool enabled) { setLocalValue("ShowUserStateIcons", enabled); }
+ bool showUserStateIcons() const;
+ void enableUserStateIcons(bool enabled);
// redirection settings (default)
- inline int userNoticesTarget() { return localValue("UserNoticesTarget", DefaultBuffer | CurrentBuffer).toInt(); }
- inline void setUserNoticesTarget(int target) { setLocalValue("UserNoticesTarget", target); }
- inline int serverNoticesTarget() { return localValue("ServerNoticesTarget", StatusBuffer).toInt(); }
- inline void setServerNoticesTarget(int target) { setLocalValue("ServerNoticesTarget", target); }
- inline int errorMsgsTarget() { return localValue("ErrorMsgsTarget", DefaultBuffer).toInt(); }
- inline void setErrorMsgsTarget(int target) { setLocalValue("ErrorMsgsTarget", target); }
+ int userNoticesTarget() const;
+ void setUserNoticesTarget(int target);
+ int serverNoticesTarget() const;
+ void setServerNoticesTarget(int target);
+ int errorMsgsTarget() const;
+ void setErrorMsgsTarget(int target);
};
}
-void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot)
+void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot) const
{
ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), receiver, slot);
}
-QList<AccountId> CoreAccountSettings::knownAccounts()
+QList<AccountId> CoreAccountSettings::knownAccounts() const
{
QList<AccountId> ids;
foreach(const QString &key, localChildGroups()) {
}
-AccountId CoreAccountSettings::lastAccount()
+AccountId CoreAccountSettings::lastAccount() const
{
return localValue("LastAccount", 0).toInt();
}
}
-AccountId CoreAccountSettings::autoConnectAccount()
+AccountId CoreAccountSettings::autoConnectAccount() const
{
return localValue("AutoConnectAccount", 0).toInt();
}
}
-bool CoreAccountSettings::autoConnectOnStartup()
+bool CoreAccountSettings::autoConnectOnStartup() const
{
return localValue("AutoConnectOnStartup", false).toBool();
}
}
-bool CoreAccountSettings::autoConnectToFixedAccount()
+bool CoreAccountSettings::autoConnectToFixedAccount() const
{
return localValue("AutoConnectToFixedAccount", false).toBool();
}
}
-QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id)
+QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) const
{
QVariantMap map;
QString base = QString::number(id.toInt());
}
-QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def)
+QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def) const
{
if (!Client::currentCoreAccount().isValid())
return QVariant();
}
-QHash<int, BufferId> CoreAccountSettings::jumpKeyMap()
+QHash<int, BufferId> CoreAccountSettings::jumpKeyMap() const
{
QHash<int, BufferId> keyMap;
QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap();
}
-QSet<int> CoreAccountSettings::bufferViewOverlay()
+QSet<int> CoreAccountSettings::bufferViewOverlay() const
{
QSet<int> viewIds;
QVariantList variants = accountValue("BufferViewOverlay").toList();
/***********************************************************************************************/
// CoreConnectionSettings:
-CoreConnectionSettings::CoreConnectionSettings() : ClientSettings("CoreConnection") {}
+CoreConnectionSettings::CoreConnectionSettings()
+ : ClientSettings("CoreConnection")
+{}
void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode)
{
}
-CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode()
+CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode() const
{
auto mode = localValue("NetworkDetectionMode", UseQNetworkConfigurationManager).toInt();
if (mode == 0)
}
-bool CoreConnectionSettings::autoReconnect()
+bool CoreConnectionSettings::autoReconnect() const
{
return localValue("AutoReconnect", true).toBool();
}
}
-int CoreConnectionSettings::pingTimeoutInterval()
+int CoreConnectionSettings::pingTimeoutInterval() const
{
return localValue("PingTimeoutInterval", 60).toInt();
}
}
-int CoreConnectionSettings::reconnectInterval()
+int CoreConnectionSettings::reconnectInterval() const
{
return localValue("ReconnectInterval", 60).toInt();
}
/***********************************************************************************************/
// NotificationSettings:
-NotificationSettings::NotificationSettings() : ClientSettings("Notification")
+NotificationSettings::NotificationSettings()
+ : ClientSettings("Notification")
{
}
+void NotificationSettings::setValue(const QString &key, const QVariant &data)
+{
+ setLocalValue(key, data);
+}
+
+
+QVariant NotificationSettings::value(const QString &key, const QVariant &def) const
+{
+ return localValue(key, def);
+}
+
+
+void NotificationSettings::remove(const QString &key)
+{
+ removeLocalKey(key);
+}
+
+
void NotificationSettings::setHighlightList(const QVariantList &highlightList)
{
setLocalValue("Highlights/CustomList", highlightList);
}
-QVariantList NotificationSettings::highlightList()
+QVariantList NotificationSettings::highlightList() const
{
return localValue("Highlights/CustomList").toList();
}
}
-NotificationSettings::HighlightNickType NotificationSettings::highlightNick()
+NotificationSettings::HighlightNickType NotificationSettings::highlightNick() const
{
return (NotificationSettings::HighlightNickType)localValue("Highlights/HighlightNick",
CurrentNick).toInt();
}
-bool NotificationSettings::nicksCaseSensitive()
+bool NotificationSettings::nicksCaseSensitive() const
{
return localValue("Highlights/NicksCaseSensitive", false).toBool();
}
// TabCompletionSettings
// ========================================
-TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion")
+TabCompletionSettings::TabCompletionSettings()
+ : ClientSettings("TabCompletion")
{
}
}
-QString TabCompletionSettings::completionSuffix()
+QString TabCompletionSettings::completionSuffix() const
{
return localValue("CompletionSuffix", ": ").toString();
}
}
-bool TabCompletionSettings::addSpaceMidSentence()
+bool TabCompletionSettings::addSpaceMidSentence() const
{
return localValue("AddSpaceMidSentence", false).toBool();
}
}
-TabCompletionSettings::SortMode TabCompletionSettings::sortMode()
+TabCompletionSettings::SortMode TabCompletionSettings::sortMode() const
{
return static_cast<SortMode>(localValue("SortMode"), LastActivity);
}
}
-Qt::CaseSensitivity TabCompletionSettings::caseSensitivity()
+Qt::CaseSensitivity TabCompletionSettings::caseSensitivity() const
{
return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt();
}
}
-bool TabCompletionSettings::useLastSpokenTo()
+bool TabCompletionSettings::useLastSpokenTo() const
{
return localValue("UseLastSpokenTo", false).toBool();
}
}
-bool ItemViewSettings::displayTopicInTooltip()
+bool ItemViewSettings::displayTopicInTooltip() const
{
return localValue("DisplayTopicInTooltip", false).toBool();
}
-bool ItemViewSettings::mouseWheelChangesBuffer()
+bool ItemViewSettings::mouseWheelChangesBuffer() const
{
return localValue("MouseWheelChangesBuffer", false).toBool();
}
// stores account-specific data in CoreAccounts/$ACCID/$SUBGROUP/$KEY)
CoreAccountSettings(QString subgroup = "General");
- void notify(const QString &key, QObject *receiver, const char *slot) override;
+ void notify(const QString &key, QObject *receiver, const char *slot) const; // shadows Settings::notify()
- QList<AccountId> knownAccounts();
- AccountId lastAccount();
+ QList<AccountId> knownAccounts() const;
+ AccountId lastAccount() const;
void setLastAccount(AccountId);
- AccountId autoConnectAccount();
+ AccountId autoConnectAccount() const;
void setAutoConnectAccount(AccountId);
- bool autoConnectOnStartup();
+ bool autoConnectOnStartup() const;
void setAutoConnectOnStartup(bool);
- bool autoConnectToFixedAccount();
+ bool autoConnectToFixedAccount() const;
void setAutoConnectToFixedAccount(bool);
void clearAccounts();
void storeAccountData(AccountId id, const QVariantMap &data);
- QVariantMap retrieveAccountData(AccountId);
+ QVariantMap retrieveAccountData(AccountId) const;
void removeAccount(AccountId);
void setJumpKeyMap(const QHash<int, BufferId> &keyMap);
- QHash<int, BufferId> jumpKeyMap();
+ QHash<int, BufferId> jumpKeyMap() const;
void setBufferViewOverlay(const QSet<int> &viewIds);
- QSet<int> bufferViewOverlay();
+ QSet<int> bufferViewOverlay() const;
void setAccountValue(const QString &key, const QVariant &data);
- QVariant accountValue(const QString &key, const QVariant &def = QVariant());
+ QVariant accountValue(const QString &key, const QVariant &def = QVariant()) const;
private:
QString _subgroup;
NotificationSettings();
- inline void setValue(const QString &key, const QVariant &data) { setLocalValue(key, data); }
- inline QVariant value(const QString &key, const QVariant &def = QVariant()) { return localValue(key, def); }
- inline void remove(const QString &key) { removeLocalKey(key); }
+ void setValue(const QString &key, const QVariant &data);
+ QVariant value(const QString &key, const QVariant &def = {}) const;
+ void remove(const QString &key);
void setHighlightList(const QVariantList &highlightList);
- QVariantList highlightList();
+ QVariantList highlightList() const;
void setHighlightNick(HighlightNickType);
- HighlightNickType highlightNick();
+ HighlightNickType highlightNick() const;
void setNicksCaseSensitive(bool);
- bool nicksCaseSensitive();
+ bool nicksCaseSensitive() const;
};
CoreConnectionSettings();
void setNetworkDetectionMode(NetworkDetectionMode mode);
- NetworkDetectionMode networkDetectionMode();
+ NetworkDetectionMode networkDetectionMode() const;
void setAutoReconnect(bool autoReconnect);
- bool autoReconnect();
+ bool autoReconnect() const;
void setPingTimeoutInterval(int interval);
- int pingTimeoutInterval();
+ int pingTimeoutInterval() const;
void setReconnectInterval(int interval);
- int reconnectInterval();
+ int reconnectInterval() const;
};
TabCompletionSettings();
void setCompletionSuffix(const QString &);
- QString completionSuffix();
+ QString completionSuffix() const;
void setAddSpaceMidSentence(bool);
- bool addSpaceMidSentence();
+ bool addSpaceMidSentence() const;
void setSortMode(SortMode);
- SortMode sortMode();
+ SortMode sortMode() const;
void setCaseSensitivity(Qt::CaseSensitivity);
- Qt::CaseSensitivity caseSensitivity();
+ Qt::CaseSensitivity caseSensitivity() const;
void setUseLastSpokenTo(bool);
- bool useLastSpokenTo();
+ bool useLastSpokenTo() const;
};
public:
ItemViewSettings(const QString &group = "ItemViews");
- bool displayTopicInTooltip();
- bool mouseWheelChangesBuffer();
+ bool displayTopicInTooltip() const;
+ bool mouseWheelChangesBuffer() const;
};
// QtUiApplication::init() to handle upgrading and downgrading.
const int VERSION_MINOR_INITIAL = 1; /// Initial settings version for compatible changes
-QHash<QString, QVariant> Settings::settingsCache;
-QHash<QString, bool> Settings::settingsKeyPersistedCache;
-QHash<QString, SettingsChangeNotifier *> Settings::settingsChangeNotifier;
+QHash<QString, QVariant> Settings::_settingsCache;
+QHash<QString, bool> Settings::_settingsKeyPersistedCache;
+QHash<QString, std::shared_ptr<SettingsChangeNotifier>> Settings::_settingsChangeNotifier;
#ifdef Q_OS_MAC
-# define create_qsettings QSettings s(QCoreApplication::organizationDomain(), appName)
+# define create_qsettings QSettings s(QCoreApplication::organizationDomain(), _appName)
#else
# define create_qsettings QSettings s(fileName(), format())
#endif
-// Settings::Settings(QString group_, QString appName_)
-// : group(group_),
-// appName(appName_)
-// {
-
-// /* we need to call the constructor immediately in order to set the path...
-// #ifndef Q_WS_QWS
-// QSettings(QCoreApplication::organizationName(), applicationName);
-// #else
-// // FIXME sandboxDir() is not currently working correctly...
-// //if(Qtopia::sandboxDir().isEmpty()) QSettings();
-// //else QSettings(Qtopia::sandboxDir() + "/etc/QuasselIRC.conf", QSettings::NativeFormat);
-// // ...so we have to use a workaround:
-// QString appPath = QCoreApplication::applicationFilePath();
-// if(appPath.startsWith(Qtopia::packagePath())) {
-// QString sandboxPath = appPath.left(Qtopia::packagePath().length() + 32);
-// QSettings(sandboxPath + "/etc/QuasselIRC.conf", QSettings::IniFormat);
-// qDebug() << sandboxPath + "/etc/QuasselIRC.conf";
-// } else {
-// QSettings(QCoreApplication::organizationName(), applicationName);
-// }
-// #endif
-// */
-// }
-
-void Settings::notify(const QString &key, QObject *receiver, const char *slot)
-{
- QObject::connect(notifier(normalizedKey(group, key)), SIGNAL(valueChanged(const QVariant &)),
+Settings::Settings(QString group, QString appName)
+ : _group(std::move(group)), _appName(std::move(appName))
+{}
+
+
+void Settings::setGroup(QString group) {
+ _group = std::move(group);
+}
+
+
+void Settings::notify(const QString &key, QObject *receiver, const char *slot) const
+{
+ QObject::connect(notifier(normalizedKey(_group, key)), SIGNAL(valueChanged(const QVariant &)),
receiver, slot);
}
-void Settings::initAndNotify(const QString &key, QObject *receiver, const char *slot, const QVariant &defaultValue)
+void Settings::initAndNotify(const QString &key, QObject *receiver, const char *slot, const QVariant &defaultValue) const
{
notify(key, receiver, slot);
- emit notifier(normalizedKey(group, key))->valueChanged(localValue(key, defaultValue));
+ emit notifier(normalizedKey(_group, key))->valueChanged(localValue(key, defaultValue));
}
-uint Settings::version()
+uint Settings::version() const
{
// we don't cache this value, and we ignore the group
create_qsettings;
}
-uint Settings::versionMinor()
+uint Settings::versionMinor() const
{
// Don't cache this value; ignore the group
create_qsettings;
// than Config/Version exist. If so, assume it's version 1.
if (verMinor == 0 && s.allKeys().count() > 1) {
// More than 1 key exists, but version's never been set. Assume and set version 1.
- setVersionMinor(VERSION_MINOR_INITIAL);
+ // const_cast is ok, because setVersionMinor() doesn't actually change this instance
+ const_cast<Settings*>(this)->setVersionMinor(VERSION_MINOR_INITIAL);
return VERSION_MINOR_INITIAL;
} else {
return verMinor;
}
-bool Settings::sync() {
+QSettings::Format Settings::format() const
+{
+#ifdef Q_OS_WIN
+ return QSettings::IniFormat;
+#else
+ return QSettings::NativeFormat;
+#endif
+}
+
+
+bool Settings::sync()
+{
create_qsettings;
s.sync();
switch (s.status()) {
}
-bool Settings::isWritable() {
+bool Settings::isWritable() const
+{
create_qsettings;
return s.isWritable();
}
-QStringList Settings::allLocalKeys()
+QStringList Settings::allLocalKeys() const
{
create_qsettings;
- s.beginGroup(group);
+ s.beginGroup(_group);
QStringList res = s.allKeys();
s.endGroup();
return res;
}
-QStringList Settings::localChildKeys(const QString &rootkey)
+QStringList Settings::localChildKeys(const QString &rootkey) const
{
QString g;
if (rootkey.isEmpty())
- g = group;
+ g = _group;
else
- g = QString("%1/%2").arg(group, rootkey);
+ g = QString("%1/%2").arg(_group, rootkey);
create_qsettings;
s.beginGroup(g);
}
-QStringList Settings::localChildGroups(const QString &rootkey)
+QStringList Settings::localChildGroups(const QString &rootkey) const
{
QString g;
if (rootkey.isEmpty())
- g = group;
+ g = _group;
else
- g = QString("%1/%2").arg(group, rootkey);
+ g = QString("%1/%2").arg(_group, rootkey);
create_qsettings;
s.beginGroup(g);
void Settings::setLocalValue(const QString &key, const QVariant &data)
{
- QString normKey = normalizedKey(group, key);
+ QString normKey = normalizedKey(_group, key);
create_qsettings;
s.setValue(normKey, data);
setCacheKeyPersisted(normKey, true);
}
-QVariant Settings::localValue(const QString &key, const QVariant &def)
+QVariant Settings::localValue(const QString &key, const QVariant &def) const
{
- QString normKey = normalizedKey(group, key);
+ QString normKey = normalizedKey(_group, key);
if (!isCached(normKey)) {
create_qsettings;
// Since we're loading from settings anyways, cache whether or not the key exists on disk
}
if (cacheKeyPersisted(normKey)) {
return cacheValue(normKey);
- } else {
- // Don't return possibly wrong cached values
- // A key gets cached with the first default value requested and never changes afterwards
- return def;
}
+ // Don't return possibly wrong cached values
+ // A key gets cached with the first default value requested and never changes afterwards
+ return def;
}
-bool Settings::localKeyExists(const QString &key)
+bool Settings::localKeyExists(const QString &key) const
{
- QString normKey = normalizedKey(group, key);
+ QString normKey = normalizedKey(_group, key);
if (!isKeyPersistedCached(normKey)) {
create_qsettings;
// Cache whether or not key exists on disk
void Settings::removeLocalKey(const QString &key)
{
create_qsettings;
- s.beginGroup(group);
+ s.beginGroup(_group);
s.remove(key);
s.endGroup();
- QString normKey = normalizedKey(group, key);
+ QString normKey = normalizedKey(_group, key);
if (isCached(normKey)) {
- settingsCache.remove(normKey);
+ _settingsCache.remove(normKey);
}
if (isKeyPersistedCached(normKey)) {
- settingsKeyPersistedCache.remove(normKey);
+ _settingsKeyPersistedCache.remove(normKey);
}
if (hasNotifier(normKey)) {
emit notifier(normKey)->valueChanged({});
}
}
+
+
+QString Settings::fileName() const
+{
+ return Quassel::configDirPath() + _appName
+ + ((format() == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"));
+}
+
+
+QString Settings::normalizedKey(const QString &group, const QString &key) const
+{
+ if (group.isEmpty())
+ return key;
+ return group + '/' + key;
+}
+
+
+void Settings::setCacheKeyPersisted(const QString &normKey, bool exists) const
+{
+ _settingsKeyPersistedCache[normKey] = exists;
+}
+
+
+bool Settings::cacheKeyPersisted(const QString &normKey) const
+{
+ return _settingsKeyPersistedCache[normKey];
+}
+
+
+bool Settings::isKeyPersistedCached(const QString &normKey) const
+{
+ return _settingsKeyPersistedCache.contains(normKey);
+}
+
+
+void Settings::setCacheValue(const QString &normKey, const QVariant &data) const
+{
+ _settingsCache[normKey] = data;
+}
+
+
+QVariant Settings::cacheValue(const QString &normKey) const
+{
+ return _settingsCache[normKey];
+}
+
+
+bool Settings::isCached(const QString &normKey) const
+{
+ return _settingsCache.contains(normKey);
+}
+
+
+SettingsChangeNotifier *Settings::notifier(const QString &normKey) const
+{
+ if (!hasNotifier(normKey))
+ _settingsChangeNotifier[normKey] = std::make_shared<SettingsChangeNotifier>();
+ return _settingsChangeNotifier[normKey].get();
+}
+
+
+bool Settings::hasNotifier(const QString &normKey) const
+{
+ return _settingsChangeNotifier.contains(normKey);
+}
#include "common-export.h"
+#include <memory>
+
#include <QCoreApplication>
#include <QHash>
#include <QSettings>
public:
//! Call the given slot on change of the given key
- virtual void notify(const QString &key, QObject *receiver, const char *slot);
+ void notify(const QString &key, QObject *receiver, const char *slot) const;
//! Sets up notification and calls the given slot to set the initial value
- void initAndNotify(const QString &key, QObject *receiver, const char *slot, const QVariant &defaultValue = QVariant());
+ void initAndNotify(const QString &key, QObject *receiver, const char *slot, const QVariant &defaultValue = QVariant()) const;
/**
* Get the major configuration version
*
* @return Major configuration version (the X in XX.YY)
*/
- virtual uint version();
+ virtual uint version() const;
/**
* Get the minor configuration version
* @see Settings::setVersionMinor()
* @return Minor configuration version (the Y in XX.YY)
*/
- virtual uint versionMinor();
+ virtual uint versionMinor() const;
/**
* Set the minor configuration version
*
* @return true if writable, false otherwise
*/
- bool isWritable();
+ bool isWritable() const;
protected:
- inline Settings(QString group_, QString appName_) : group(std::move(group_)), appName(std::move(appName_)) {}
- inline virtual ~Settings() = default;
+ Settings(QString group, QString appName);
+ virtual ~Settings() = default;
- inline void setGroup(const QString &group_) { group = group_; }
+ void setGroup(QString group);
- virtual QStringList allLocalKeys();
- virtual QStringList localChildKeys(const QString &rootkey = QString());
- virtual QStringList localChildGroups(const QString &rootkey = QString());
+ virtual QStringList allLocalKeys() const;
+ virtual QStringList localChildKeys(const QString &rootkey = QString()) const;
+ virtual QStringList localChildGroups(const QString &rootkey = QString()) const;
virtual void setLocalValue(const QString &key, const QVariant &data);
- virtual QVariant localValue(const QString &key, const QVariant &def = QVariant());
+ virtual QVariant localValue(const QString &key, const QVariant &def = QVariant()) const;
/**
* Gets if a key exists in settings
* @param[in] key ID of local settings key
* @returns True if key exists in settings, otherwise false
*/
- virtual bool localKeyExists(const QString &key);
+ virtual bool localKeyExists(const QString &key) const;
virtual void removeLocalKey(const QString &key);
- QString group;
- QString appName;
+ QString _group;
+ QString _appName;
private:
- inline QSettings::Format format()
- {
-#ifdef Q_OS_WIN
- return QSettings::IniFormat;
-#else
- return QSettings::NativeFormat;
-#endif
- }
-
-
- inline QString fileName()
- {
- return Quassel::configDirPath() + appName
- + ((format() == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"));
- }
+ QSettings::Format format() const;
+ QString fileName() const;
- static QHash<QString, QVariant> settingsCache; ///< Cached settings values
- static QHash<QString, bool> settingsKeyPersistedCache; ///< Cached settings key exists on disk
- static QHash<QString, SettingsChangeNotifier *> settingsChangeNotifier;
-
- inline QString normalizedKey(const QString &group, const QString &key)
- {
- if (group.isEmpty())
- return key;
- return group + '/' + key;
- }
-
+ QString normalizedKey(const QString &group, const QString &key) const;
/**
* Update the cache of whether or not a given settings key persists on disk
* @param normKey Normalized settings key ID
* @param exists True if key exists, otherwise false
*/
- inline void setCacheKeyPersisted(const QString &normKey, bool exists)
- {
- settingsKeyPersistedCache[normKey] = exists;
- }
-
+ void setCacheKeyPersisted(const QString &normKey, bool exists) const;
/**
* Check if the given settings key ID persists on disk (rather than being a default value)
* @param normKey Normalized settings key ID
* @return True if key exists and persistence has been cached, otherwise false
*/
- inline const bool &cacheKeyPersisted(const QString &normKey)
- {
- return settingsKeyPersistedCache[normKey];
- }
-
+ bool cacheKeyPersisted(const QString &normKey) const;
/**
* Check if the persistence of the given settings key ID has been cached
* @param normKey Normalized settings key ID
* @return True if key persistence has been cached, otherwise false
*/
- inline bool isKeyPersistedCached(const QString &normKey)
- {
- return settingsKeyPersistedCache.contains(normKey);
- }
-
-
- inline void setCacheValue(const QString &normKey, const QVariant &data)
- {
- settingsCache[normKey] = data;
- }
+ bool isKeyPersistedCached(const QString &normKey) const;
+ void setCacheValue(const QString &normKey, const QVariant &data) const;
- inline const QVariant &cacheValue(const QString &normKey)
- {
- return settingsCache[normKey];
- }
+ QVariant cacheValue(const QString &normKey) const;
+ bool isCached(const QString &normKey) const;
- inline bool isCached(const QString &normKey)
- {
- return settingsCache.contains(normKey);
- }
+ SettingsChangeNotifier *notifier(const QString &normKey) const;
+ bool hasNotifier(const QString &normKey) const;
- inline SettingsChangeNotifier *notifier(const QString &normKey)
- {
- if (!hasNotifier(normKey))
- settingsChangeNotifier[normKey] = new SettingsChangeNotifier();
- return settingsChangeNotifier[normKey];
- }
-
-
- inline bool hasNotifier(const QString &normKey)
- {
- return settingsChangeNotifier.contains(normKey);
- }
+private:
+ static QHash<QString, QVariant> _settingsCache; ///< Cached settings values
+ static QHash<QString, bool> _settingsKeyPersistedCache; ///< Cached settings key exists on disk
+ static QHash<QString, std::shared_ptr<SettingsChangeNotifier>> _settingsChangeNotifier;
};
#include "quassel.h"
-CoreSettings::CoreSettings(const QString group) : Settings(group, Quassel::buildInfo().coreApplicationName)
+CoreSettings::CoreSettings(QString group)
+ : Settings(std::move(group), Quassel::buildInfo().coreApplicationName)
{
}
}
-QVariant CoreSettings::storageSettings(const QVariant &def)
+QVariant CoreSettings::storageSettings(const QVariant &def) const
{
return localValue("StorageSettings", def);
}
-QVariant CoreSettings::authSettings(const QVariant &def)
+void CoreSettings::setAuthSettings(const QVariant &data)
{
- return localValue("AuthSettings", def);
+ setLocalValue("AuthSettings", data);
}
-void CoreSettings::setAuthSettings(const QVariant &data)
+QVariant CoreSettings::authSettings(const QVariant &def) const
{
- setLocalValue("AuthSettings", data);
+ return localValue("AuthSettings", def);
}
// FIXME remove
-QVariant CoreSettings::oldDbSettings()
+QVariant CoreSettings::oldDbSettings() const
{
return localValue("DatabaseSettings");
}
}
-QVariant CoreSettings::coreState(const QVariant &def)
+QVariant CoreSettings::coreState(const QVariant &def) const
{
return localValue("CoreState", def);
}
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#ifndef _CORESETTINGS_H_
-#define _CORESETTINGS_H_
+#pragma once
#include "settings.h"
class CoreSettings : public Settings
{
public:
- CoreSettings(const QString group = "Core");
+ CoreSettings(QString group = "Core");
void setStorageSettings(const QVariant &data);
- QVariant storageSettings(const QVariant &def = QVariant());
+ QVariant storageSettings(const QVariant &def = {}) const;
void setAuthSettings(const QVariant &data);
- QVariant authSettings(const QVariant &def = QVariant());
+ QVariant authSettings(const QVariant &def = {}) const;
- QVariant oldDbSettings(); // FIXME remove
+ QVariant oldDbSettings() const; // FIXME remove
void setCoreState(const QVariant &data);
- QVariant coreState(const QVariant &def = QVariant());
+ QVariant coreState(const QVariant &def = {}) const;
};
-
-
-#endif /*_CORESETTINGS_H_*/
#include "coreusersettings.h"
-CoreUserSettings::CoreUserSettings(UserId uid) : CoreSettings(QString("CoreUser/%1").arg(uid.toInt())), user(uid)
+CoreUserSettings::CoreUserSettings(UserId uid)
+ : CoreSettings(QString("CoreUser/%1").arg(uid.toInt())), user(uid)
{
}
-Identity CoreUserSettings::identity(IdentityId id)
+Identity CoreUserSettings::identity(IdentityId id) const
{
QVariant v = localValue(QString("Identities/%1").arg(id.toInt()));
if (v.canConvert<Identity>()) {
}
-QList<IdentityId> CoreUserSettings::identityIds()
+QList<IdentityId> CoreUserSettings::identityIds() const
{
QList<IdentityId> res;
foreach(QString id, localChildKeys("Identities")) {
}
-QVariant CoreUserSettings::sessionState(const QVariant &def)
+QVariant CoreUserSettings::sessionState(const QVariant &def) const
{
return localValue("SessionState", def);
}
-QVariantMap CoreUserSettings::sessionData()
+QVariantMap CoreUserSettings::sessionData() const
{
QVariantMap res;
foreach(QString key, localChildKeys(QString("SessionData"))) {
}
-QVariant CoreUserSettings::sessionValue(const QString &key, const QVariant &def)
+QVariant CoreUserSettings::sessionValue(const QString &key, const QVariant &def) const
{
return localValue(QString("SessionData/%1").arg(key), def);
}
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#ifndef _COREUSERSETTINGS_H_
-#define _COREUSERSETTINGS_H_
+#pragma once
#include "coresettings.h"
#include "identity.h"
public:
CoreUserSettings(UserId user);
- Identity identity(IdentityId id);
- QList<IdentityId> identityIds();
+ Identity identity(IdentityId id) const;
+ QList<IdentityId> identityIds() const;
void storeIdentity(const Identity &identity);
void removeIdentity(IdentityId id);
void setSessionState(const QVariant &data);
- QVariant sessionState(const QVariant &def = QVariant());
+ QVariant sessionState(const QVariant &def = {}) const;
private:
// this stuff should only be accessed by CoreSession!
- QVariantMap sessionData();
- QVariant sessionValue(const QString &key, const QVariant &def = QVariant());
+ QVariantMap sessionData() const;
+ QVariant sessionValue(const QString &key, const QVariant &def = {}) const;
void setSessionValue(const QString &key, const QVariant &value);
UserId user;
friend class CoreSession;
};
-
-
-#endif
: QtUiSettings(QString("ChatView/%1").arg(view->scene()->idString()))
{
}
+
+
+bool ChatViewSettings::showWebPreview() const
+{
+ return localValue("ShowWebPreview", false).toBool();
+}
+
+
+void ChatViewSettings::enableWebPreview(bool enabled)
+{
+ setLocalValue("ShowWebPreview", enabled);
+}
+
+
+bool ChatViewSettings::useCustomTimestampFormat() const
+{
+ return localValue("UseCustomTimestampFormat", false).toBool();
+}
+
+
+void ChatViewSettings::setUseCustomTimestampFormat(bool enabled)
+{
+ setLocalValue("UseCustomTimestampFormat", enabled);
+}
+
+
+QString ChatViewSettings::timestampFormatString() const
+{
+ // Include a space in the default TimestampFormat to give the timestamp a small bit of padding
+ // between the border of the chat buffer window and the numbers. Helps with readability.
+ return localValue("TimestampFormat", " hh:mm:ss").toString();
+}
+
+
+void ChatViewSettings::setTimestampFormatString(const QString &format)
+{
+ setLocalValue("TimestampFormat", format);
+}
+
+
+UiStyle::SenderPrefixMode ChatViewSettings::senderPrefixDisplay() const
+{
+ return static_cast<UiStyle::SenderPrefixMode>(
+ localValue("SenderPrefixMode",
+ QVariant::fromValue<UiStyle::SenderPrefixMode>(
+ UiStyle::SenderPrefixMode::HighestMode)).toInt());
+ // Cast the QVariant to an integer, then cast that to the enum class.
+ // .canConvert<UiStyle::SenderPrefixMode>() returned true, but
+ // .value<UiStyle::SenderPrefixMode>(); always gave the default value 0.
+ //
+ // There's probably a cleaner way of doing this. I couldn't find it within 4 hours, so...
+}
+
+
+bool ChatViewSettings::showSenderBrackets() const
+{
+ return localValue("ShowSenderBrackets", false).toBool();
+}
+
+
+void ChatViewSettings::enableSenderBrackets(bool enabled)
+{
+ setLocalValue("ShowSenderBrackets", enabled);
+}
+
+
+QString ChatViewSettings::webSearchUrlFormatString() const
+{
+ return localValue("WebSearchUrlFormat", "https://www.google.com/search?q=%s").toString();
+}
+
+
+void ChatViewSettings::setWebSearchUrlFormatString(const QString &format)
+{
+ setLocalValue("WebSearchUrlFormat", format);
+}
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#ifndef CHATVIEWSETTINGS_H
-#define CHATVIEWSETTINGS_H
+#pragma once
#include "qtuisettings.h"
#include "uistyle.h"
OptIn = 1,
OptOut = 2
};
- Q_DECLARE_FLAGS(operationModes, OperationMode)
+ Q_DECLARE_FLAGS(OperationModes, OperationMode)
ChatViewSettings(const QString &id = "__default__");
ChatViewSettings(ChatScene *scene);
ChatViewSettings(ChatView *view);
- inline bool showWebPreview() { return localValue("ShowWebPreview", false).toBool(); }
- inline void enableWebPreview(bool enabled) { setLocalValue("ShowWebPreview", enabled); }
+ bool showWebPreview() const;
+ void enableWebPreview(bool enabled);
/**
* Gets if a custom timestamp format is used.
*
* @returns True if custom timestamp format used, otherwise false
*/
- inline bool useCustomTimestampFormat() { return localValue("UseCustomTimestampFormat", false).toBool(); }
+ bool useCustomTimestampFormat() const;
/**
* Sets whether a custom timestamp format is used.
*
* @param[in] enabled True if custom timestamp format used, otherwise false
*/
- inline void setUseCustomTimestampFormat(bool enabled) { setLocalValue("UseCustomTimestampFormat", enabled); }
+ void setUseCustomTimestampFormat(bool enabled);
/**
* Gets the format string for chat log timestamps.
*
* @returns String representing timestamp format, e.g. "[hh:mm:ss]" or " hh:mm:ss"
*/
- inline QString timestampFormatString() { return localValue("TimestampFormat", " hh:mm:ss").toString(); }
+ QString timestampFormatString() const;
// Include a space in the default TimestampFormat to give the timestamp a small bit of padding
// between the border of the chat buffer window and the numbers. Helps with readability.
/**
*
* @param[in] format String representing timestamp format, e.g. "[hh:mm:ss]" or " hh:mm:ss"
*/
- inline void setTimestampFormatString(const QString &format) { setLocalValue("TimestampFormat", format); }
+ void setTimestampFormatString(const QString &format);
/**
* Gets how prefix modes are shown before sender names
*
* @returns SenderPrefixMode of what format to use for showing sender prefix modes
*/
- inline UiStyle::SenderPrefixMode SenderPrefixDisplay() {
- return static_cast<UiStyle::SenderPrefixMode>(
- localValue("SenderPrefixMode",
- QVariant::fromValue<UiStyle::SenderPrefixMode>(
- UiStyle::SenderPrefixMode::HighestMode)).toInt());
- // Cast the QVariant to an integer, then cast that to the enum class.
- // .canConvert<UiStyle::SenderPrefixMode>() returned true, but
- // .value<UiStyle::SenderPrefixMode>(); always gave the default value 0.
- //
- // There's probably a cleaner way of doing this. I couldn't find it within 4 hours, so...
- }
+ UiStyle::SenderPrefixMode senderPrefixDisplay() const;
/**
* Gets if brackets are shown around sender names
*
* @returns True if sender brackets enabled, otherwise false
*/
- inline bool showSenderBrackets() { return localValue("ShowSenderBrackets", false).toBool(); }
+ bool showSenderBrackets() const;
/**
* Sets whether brackets are shown around around sender names.
*
* @param[in] enabled True if enabling sender brackets, otherwise false
*/
- inline void enableSenderBrackets(bool enabled) { setLocalValue("ShowSenderBrackets", enabled); }
+ void enableSenderBrackets(bool enabled);
- inline QString webSearchUrlFormatString() { return localValue("WebSearchUrlFormat", "https://www.google.com/search?q=%s").toString(); }
- inline void setWebSearchUrlFormatString(const QString &format) { setLocalValue("WebSearchUrlFormat", format); }
+ QString webSearchUrlFormatString() const;
+ void setWebSearchUrlFormatString(const QString &format);
};
-
Q_DECLARE_METATYPE(ChatViewSettings::OperationMode)
-#endif //CHATVIEWSETTINGS_H
#include "qtuisettings.h"
-QtUiSettings::QtUiSettings(const QString &subGroup)
- : UiSettings(QString("QtUi/%1").arg(subGroup))
-{
-}
-
-
QtUiSettings::QtUiSettings()
: UiSettings("QtUi")
{
}
-/***********************************************************************/
-QtUiStyleSettings::QtUiStyleSettings(const QString &subGroup)
- : UiSettings(QString("QtUiStyle/%1").arg(subGroup))
+QtUiSettings::QtUiSettings(const QString &subGroup)
+ : UiSettings(QString("QtUi/%1").arg(subGroup))
{
}
+/***********************************************************************/
+
QtUiStyleSettings::QtUiStyleSettings()
: UiSettings("QtUiStyle")
{
}
+QtUiStyleSettings::QtUiStyleSettings(const QString &subGroup)
+ : UiSettings(QString("QtUiStyle/%1").arg(subGroup))
+{
+}
+
/***********************************************************************/
-WarningsSettings::WarningsSettings() : UiSettings("Warnings")
+WarningsSettings::WarningsSettings()
+ : UiSettings("Warnings")
{
}
-bool WarningsSettings::showWarning(const QString &key)
+bool WarningsSettings::showWarning(const QString &key) const
{
return localValue(key, true).toBool();
}
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#ifndef QTUISETTINGS_H_
-#define QTUISETTINGS_H_
-
-#include <QColor>
+#pragma once
#include "uisettings.h"
class QtUiSettings : public UiSettings
{
public:
- QtUiSettings(const QString &subGroup);
QtUiSettings();
+ QtUiSettings(const QString &subGroup);
};
class QtUiStyleSettings : public UiSettings
{
public:
- QtUiStyleSettings(const QString &subGroup);
QtUiStyleSettings();
+ QtUiStyleSettings(const QString &subGroup);
};
public:
WarningsSettings();
- bool showWarning(const QString &key);
+ bool showWarning(const QString &key) const;
void setShowWarning(const QString &key, bool show);
};
-
-
-#endif
void QtUiStyle::updateSenderPrefixDisplay()
{
ChatViewSettings s;
- setSenderPrefixDisplay(s.SenderPrefixDisplay());
+ setSenderPrefixDisplay(s.senderPrefixDisplay());
}
void QtUiStyle::updateShowSenderBrackets()
indexList.removeAll(index);
indexList.prepend(index);
- GraphicalUi::contextMenuActionProvider()->addActions(contextMenu, indexList, this, "menuActionTriggered", (bool)config());
+ GraphicalUi::contextMenuActionProvider()->addActions(contextMenu, indexList, this, &BufferView::menuActionTriggered, (bool)config());
}
}
-void ContextMenuActionProvider::addActions(QMenu *menu, BufferId bufId, QObject *receiver, const char *method)
+void ContextMenuActionProvider::addActions(QMenu *menu, BufferId bufId, ActionSlot slot)
{
if (!bufId.isValid())
return;
- addActions(menu, Client::networkModel()->bufferIndex(bufId), receiver, method);
+ addActions(menu, Client::networkModel()->bufferIndex(bufId), std::move(slot));
}
-void ContextMenuActionProvider::addActions(QMenu *menu, const QModelIndex &index, QObject *receiver, const char *method, bool isCustomBufferView)
+void ContextMenuActionProvider::addActions(QMenu *menu, const QModelIndex &index, ActionSlot slot, bool isCustomBufferView)
{
if (!index.isValid())
return;
- addActions(menu, QList<QModelIndex>() << index, nullptr, QString(), receiver, method, isCustomBufferView);
+ addActions(menu, QList<QModelIndex>() << index, nullptr, QString(), std::move(slot), isCustomBufferView);
}
-void ContextMenuActionProvider::addActions(QMenu *menu, MessageFilter *filter, BufferId msgBuffer, QObject *receiver, const char *slot)
+void ContextMenuActionProvider::addActions(QMenu *menu, MessageFilter *filter, BufferId msgBuffer, ActionSlot slot)
{
- addActions(menu, filter, msgBuffer, QString(), receiver, slot);
+ addActions(menu, filter, msgBuffer, QString(), std::move(slot));
}
-void ContextMenuActionProvider::addActions(QMenu *menu, MessageFilter *filter, BufferId msgBuffer, const QString &chanOrNick, QObject *receiver, const char *method)
+void ContextMenuActionProvider::addActions(QMenu *menu, MessageFilter *filter, BufferId msgBuffer, const QString &chanOrNick, ActionSlot slot)
{
if (!filter)
return;
- addActions(menu, QList<QModelIndex>() << Client::networkModel()->bufferIndex(msgBuffer), filter, chanOrNick, receiver, method, false);
+ addActions(menu, QList<QModelIndex>() << Client::networkModel()->bufferIndex(msgBuffer), filter, chanOrNick, std::move(slot), false);
}
-void ContextMenuActionProvider::addActions(QMenu *menu, const QList<QModelIndex> &indexList, QObject *receiver, const char *method, bool isCustomBufferView)
+void ContextMenuActionProvider::addActions(QMenu *menu, const QList<QModelIndex> &indexList, ActionSlot slot, bool isCustomBufferView)
{
- addActions(menu, indexList, nullptr, QString(), receiver, method, isCustomBufferView);
+ addActions(menu, indexList, nullptr, QString(), std::move(slot), isCustomBufferView);
}
// add a list of actions sensible for the current item(s)
void ContextMenuActionProvider::addActions(QMenu *menu,
- const QList<QModelIndex> &indexList_,
- MessageFilter *filter_,
- const QString &contextItem_,
- QObject *receiver_,
- const char *method_,
- bool isCustomBufferView)
+ const QList<QModelIndex> &indexList_,
+ MessageFilter *filter_,
+ const QString &contextItem_,
+ ActionSlot actionSlot,
+ bool isCustomBufferView)
{
if (!indexList_.count())
return;
setIndexList(indexList_);
setMessageFilter(filter_);
setContextItem(contextItem_);
- setSlot(receiver_, method_);
+ setSlot(std::move(actionSlot));
if (!messageFilter()) {
// this means we are in a BufferView (or NickView) rather than a ChatView
#include "uisupport-export.h"
+#include <functional>
+
#include "networkmodelcontroller.h"
class UISUPPORT_EXPORT ContextMenuActionProvider : public NetworkModelController
* @param index The item index in the NetworkModel
* @param receiver The optional object that is notified for actions that need to be handled externally.
* The action type will be stored in the QAction's data().
- * @param slot The receiving slot name; should be "mySlot" rather than SLOT(mySlot(QAction *))
+ * @param slot The receiving slot
* @return A list of actions applying to the given item
*/
- void addActions(QMenu *, const QModelIndex &index, QObject *receiver = nullptr, const char *slot = nullptr, bool allowBufferHide = false);
- void addActions(QMenu *, const QList<QModelIndex> &indexList, QObject *receiver = nullptr, const char *slot = nullptr, bool allowBufferHide = false);
- void addActions(QMenu *, BufferId id, QObject *receiver = nullptr, const char *slot = nullptr);
- void addActions(QMenu *, MessageFilter *filter, BufferId msgBuffer, QObject *receiver = nullptr, const char *slot = nullptr);
- void addActions(QMenu *, MessageFilter *filter, BufferId msgBuffer, const QString &chanOrNick, QObject *receiver = nullptr, const char *slot = nullptr);
+ template<typename Receiver, typename Slot>
+ void addActions(QMenu *menu, const QModelIndex &index, Receiver *receiver, Slot slot, bool isCustomBufferView = false)
+ {
+ addActions(menu, index, buildActionSlot(receiver, std::move(slot)), isCustomBufferView);
+ }
+ void addActions(QMenu *menu, const QModelIndex &index, ActionSlot = {}, bool isCustomBufferView = false);
-private:
+ template<typename Receiver, typename Slot>
+ void addActions(QMenu *menu, const QList<QModelIndex> &indexList, Receiver *receiver, Slot slot, bool isCustomBufferView = false)
+ {
+ addActions(menu, indexList, buildActionSlot(receiver, std::move(slot)), isCustomBufferView);
+ }
+ void addActions(QMenu *menu, const QList<QModelIndex> &indexList, ActionSlot = {}, bool isCustomBufferView = false);
+
+ template<typename Receiver, typename Slot>
+ void addActions(QMenu *menu, BufferId id, Receiver *receiver, Slot slot)
+ {
+ addActions(menu, id, buildActionSlot(receiver, std::move(slot)));
+ }
+ void addActions(QMenu *menu, BufferId id, ActionSlot = {});
- void addActions(QMenu *, const QList<QModelIndex> &indexList, MessageFilter *filter, const QString &chanOrNick,
- QObject *receiver, const char *slot, bool allowBufferHide);
+ template<typename Receiver, typename Slot>
+ void addActions(QMenu *menu, MessageFilter *filter, BufferId msgBuffer, Receiver *receiver, Slot slot)
+ {
+ addActions(menu, filter, msgBuffer, buildActionSlot(receiver, std::move(slot)));
+ }
+ void addActions(QMenu *menu, MessageFilter *filter, BufferId msgBuffer, ActionSlot = {});
+
+ template<typename Receiver, typename Slot>
+ void addActions(QMenu *menu, MessageFilter *filter, BufferId msgBuffer, const QString &chanOrNick, Receiver *receiver, Slot slot)
+ {
+ addActions(menu, filter, msgBuffer, chanOrNick, buildActionSlot(receiver, std::move(slot)));
+ }
+ void addActions(QMenu *menu, MessageFilter *filter, BufferId msgBuffer, const QString &chanOrNick, ActionSlot = {});
+
+private:
+ void addActions(QMenu *menu, const QList<QModelIndex> &indexList, MessageFilter *filter, const QString &chanOrNick, ActionSlot actionSlot, bool isCustomBufferView);
Action *addAction(ActionType, QMenu *, bool condition = true);
Action *addAction(Action *, QMenu *, bool condition = true);
}
-void NetworkModelController::setSlot(QObject *receiver, const char *method)
+void NetworkModelController::setSlot(ActionSlot slot)
{
- _receiver = receiver;
- _method = method;
+ _actionSlot = std::move(slot);
}
void NetworkModelController::handleExternalAction(ActionType type, QAction *action)
{
Q_UNUSED(type);
- if (receiver() && method()) {
- if (!QMetaObject::invokeMethod(receiver(), method(), Q_ARG(QAction *, action)))
- qWarning() << "NetworkModelActionController::handleExternalAction(): Could not invoke slot" << receiver() << method();
+ if (_actionSlot) {
+ _actionSlot(action);
}
}
#include "uisupport-export.h"
+#include <functional>
+#include <type_traits>
+
#include <QDialog>
#include "action.h"
inline QList<QModelIndex> indexList() const;
inline MessageFilter *messageFilter() const;
inline QString contextItem() const; ///< Channel name or nick to provide context menu for
- inline QObject *receiver() const;
- inline const char *method() const;
void setIndexList(const QModelIndex &);
void setIndexList(const QList<QModelIndex> &);
void setMessageFilter(MessageFilter *);
void setContextItem(const QString &);
- void setSlot(QObject *receiver, const char *method);
+
+ using ActionSlot = std::function<void(QAction*)>;
+
+ template<typename Receiver, typename Slot>
+ ActionSlot buildActionSlot(Receiver *receiver, Slot slot)
+ {
+ static_assert(!std::is_same<Slot, const char*>::value, "Old-style slots not supported");
+ return [receiver, slot = std::move(slot)](QAction *action) {
+ (receiver->*slot)(action);
+ };
+ }
+
+ void setSlot(ActionSlot slot);
Action *registerAction(ActionType type, const QString &text, bool checkable = false);
Action *registerAction(NetworkModelController::ActionType type, const QIcon &icon, const QString &text, bool checkable = false);
QList<QModelIndex> _indexList;
MessageFilter *_messageFilter{nullptr};
QString _contextItem; ///< Channel name or nick to provide context menu for
- QObject *_receiver{nullptr};
- const char *_method;
+ ActionSlot _actionSlot;
};
QList<QModelIndex> NetworkModelController::indexList() const { return _indexList; }
MessageFilter *NetworkModelController::messageFilter() const { return _messageFilter; }
QString NetworkModelController::contextItem() const { return _contextItem; }
-QObject *NetworkModelController::receiver() const { return _receiver; }
-const char *NetworkModelController::method() const { return _method; }
#include "action.h"
#include "actioncollection.h"
-UiSettings::UiSettings(const QString &group)
- : ClientSettings(group)
+UiSettings::UiSettings(QString group)
+ : ClientSettings(std::move(group))
{
}
+void UiSettings::setValue(const QString &key, const QVariant &data)
+{
+ setLocalValue(key, data);
+}
+
+
+QVariant UiSettings::value(const QString &key, const QVariant &def) const
+{
+ return localValue(key, def);
+}
+
+
+bool UiSettings::valueExists(const QString &key) const
+{
+ return localKeyExists(key);
+}
+
+
+void UiSettings::remove(const QString &key)
+{
+ removeLocalKey(key);
+}
+
/**************************************************************************/
-UiStyleSettings::UiStyleSettings() : UiSettings("UiStyle") {}
-UiStyleSettings::UiStyleSettings(const QString &subGroup) : UiSettings(QString("UiStyle/%1").arg(subGroup))
+UiStyleSettings::UiStyleSettings()
+ : UiSettings("UiStyle")
+{
+}
+
+
+UiStyleSettings::UiStyleSettings(const QString &subGroup)
+ : UiSettings(QString("UiStyle/%1").arg(subGroup))
{
}
-void UiStyleSettings::setCustomFormat(UiStyle::FormatType ftype, QTextCharFormat format)
+void UiStyleSettings::setCustomFormat(UiStyle::FormatType ftype, const QTextCharFormat &format)
{
setLocalValue(QString("Format/%1").arg(static_cast<quint32>(ftype)), format);
}
-QTextCharFormat UiStyleSettings::customFormat(UiStyle::FormatType ftype)
+QTextCharFormat UiStyleSettings::customFormat(UiStyle::FormatType ftype) const
{
return localValue(QString("Format/%1").arg(static_cast<quint32>(ftype)), QTextFormat()).value<QTextFormat>().toCharFormat();
}
}
-QList<UiStyle::FormatType> UiStyleSettings::availableFormats()
+QList<UiStyle::FormatType> UiStyleSettings::availableFormats() const
{
QList<UiStyle::FormatType> formats;
QStringList list = localChildKeys("Format");
* SessionSettings
**************************************************************************/
-SessionSettings::SessionSettings(QString sessionId, const QString &group)
- : UiSettings(group), _sessionId(std::move(sessionId))
+SessionSettings::SessionSettings(QString sessionId, QString group)
+ : UiSettings(std::move(group))
+ , _sessionId(std::move(sessionId))
{
}
}
-QVariant SessionSettings::value(const QString &key, const QVariant &def)
+QVariant SessionSettings::value(const QString &key, const QVariant &def) const
{
return localValue(QString("%1/%2").arg(_sessionId, key), def);
}
}
+QString SessionSettings::sessionId() const
+{
+ return _sessionId;
+}
+
+
+void SessionSettings::setSessionId(QString sessionId)
+{
+ _sessionId = std::move(sessionId);
+}
+
+
int SessionSettings::sessionAge()
{
QVariant val = localValue(QString("%1/_sessionAge").arg(_sessionId), 0);
* ShortcutSettings
**************************************************************************/
-ShortcutSettings::ShortcutSettings() : UiSettings("Shortcuts")
+ShortcutSettings::ShortcutSettings()
+ : UiSettings("Shortcuts")
{
}
void ShortcutSettings::clear()
{
- foreach(const QString &key, allLocalKeys())
- removeLocalKey(key);
+ for (auto &&key : allLocalKeys()) {
+ removeLocalKey(key);
+ }
}
-QStringList ShortcutSettings::savedShortcuts()
+QStringList ShortcutSettings::savedShortcuts() const
{
return localChildKeys();
}
-QKeySequence ShortcutSettings::loadShortcut(const QString &name)
+QKeySequence ShortcutSettings::loadShortcut(const QString &name) const
{
return localValue(name, QKeySequence()).value<QKeySequence>();
}
class UISUPPORT_EXPORT UiSettings : public ClientSettings
{
public:
- UiSettings(const QString &group = "Ui");
+ UiSettings(QString group = "Ui");
- virtual inline void setValue(const QString &key, const QVariant &data) { setLocalValue(key, data); }
- virtual inline QVariant value(const QString &key, const QVariant &def = QVariant()) { return localValue(key, def); }
+ virtual void setValue(const QString &key, const QVariant &data);
+ virtual QVariant value(const QString &key, const QVariant &def = {}) const;
/**
* Gets if a value exists in settings
* @param[in] key ID of local settings key
* @returns True if key exists in settings, otherwise false
*/
- virtual inline bool valueExists(const QString &key) { return localKeyExists(key); }
+ bool valueExists(const QString &key) const;
- inline void remove(const QString &key) { removeLocalKey(key); }
+ void remove(const QString &key);
};
UiStyleSettings();
UiStyleSettings(const QString &subGroup);
- void setCustomFormat(UiStyle::FormatType, QTextCharFormat);
- QTextCharFormat customFormat(UiStyle::FormatType);
+ void setCustomFormat(UiStyle::FormatType, const QTextCharFormat &format);
+ QTextCharFormat customFormat(UiStyle::FormatType) const;
void removeCustomFormat(UiStyle::FormatType);
- QList<UiStyle::FormatType> availableFormats();
+ QList<UiStyle::FormatType> availableFormats() const;
};
class UISUPPORT_EXPORT SessionSettings : public UiSettings
{
public:
- SessionSettings(QString sessionId, const QString &group = "Session");
+ SessionSettings(QString sessionId, QString group = "Session");
void setValue(const QString &key, const QVariant &data) override;
- QVariant value(const QString &key, const QVariant &def = QVariant()) override;
+ QVariant value(const QString &key, const QVariant &def = {}) const override;
void removeKey(const QString &key);
void removeSession();
int sessionAge();
void setSessionAge(int age);
- inline const QString sessionId() { return _sessionId; };
- inline void setSessionId(const QString &sessionId) { _sessionId = sessionId; }
+ QString sessionId() const;
+ void setSessionId(QString sessionId);
private:
QString _sessionId;
//! Remove all stored shortcuts
void clear();
- QStringList savedShortcuts();
+ QStringList savedShortcuts() const;
void saveShortcut(const QString &name, const QKeySequence &shortcut);
- QKeySequence loadShortcut(const QString &name);
+ QKeySequence loadShortcut(const QString &name) const;
};