From: Manuel Nickschas Date: Wed, 19 Sep 2018 19:05:08 +0000 (+0200) Subject: modernize: Remove old-style slot usage in NetworkModelController X-Git-Tag: test-travis-01~124 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=61f33c7895e324f6e95034d86897ad2e963653f1 modernize: Remove old-style slot usage in NetworkModelController Use member function pointers in NetworkModelController and related classes, instead of old-style slots and invokeMethod(). --- diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 75464431..756a5409 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -3,6 +3,7 @@ quassel_add_module(Client EXPORT) target_sources(${TARGET} PRIVATE abstractmessageprocessor.cpp backlogrequester.cpp + backlogsettings.cpp buffermodel.cpp buffersettings.cpp bufferviewoverlay.cpp diff --git a/src/client/backlogsettings.cpp b/src/client/backlogsettings.cpp new file mode 100644 index 00000000..f1950b0f --- /dev/null +++ b/src/client/backlogsettings.cpp @@ -0,0 +1,109 @@ +/*************************************************************************** + * 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); +} diff --git a/src/client/backlogsettings.h b/src/client/backlogsettings.h index 04ccc528..9d4bbb36 100644 --- a/src/client/backlogsettings.h +++ b/src/client/backlogsettings.h @@ -18,39 +18,35 @@ * 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 diff --git a/src/client/buffersettings.cpp b/src/client/buffersettings.cpp index 498c94c5..c7b123f3 100644 --- a/src/client/buffersettings.cpp +++ b/src/client/buffersettings.cpp @@ -32,6 +32,18 @@ BufferSettings::BufferSettings(const QString &idString) } +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()) @@ -43,6 +55,18 @@ void BufferSettings::filterMessage(Message::Type msgType, bool filter) } +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()) @@ -56,3 +80,51 @@ void BufferSettings::removeFilter() 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); +} diff --git a/src/client/buffersettings.h b/src/client/buffersettings.h index 1d0e3726..711e3bc5 100644 --- a/src/client/buffersettings.h +++ b/src/client/buffersettings.h @@ -36,25 +36,25 @@ public: 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); }; diff --git a/src/client/clientsettings.cpp b/src/client/clientsettings.cpp index 47a89814..87c0fc55 100644 --- a/src/client/clientsettings.cpp +++ b/src/client/clientsettings.cpp @@ -46,13 +46,13 @@ CoreAccountSettings::CoreAccountSettings(QString subgroup) } -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 CoreAccountSettings::knownAccounts() +QList CoreAccountSettings::knownAccounts() const { QList ids; foreach(const QString &key, localChildGroups()) { @@ -64,7 +64,7 @@ QList CoreAccountSettings::knownAccounts() } -AccountId CoreAccountSettings::lastAccount() +AccountId CoreAccountSettings::lastAccount() const { return localValue("LastAccount", 0).toInt(); } @@ -76,7 +76,7 @@ void CoreAccountSettings::setLastAccount(AccountId account) } -AccountId CoreAccountSettings::autoConnectAccount() +AccountId CoreAccountSettings::autoConnectAccount() const { return localValue("AutoConnectAccount", 0).toInt(); } @@ -88,7 +88,7 @@ void CoreAccountSettings::setAutoConnectAccount(AccountId account) } -bool CoreAccountSettings::autoConnectOnStartup() +bool CoreAccountSettings::autoConnectOnStartup() const { return localValue("AutoConnectOnStartup", false).toBool(); } @@ -100,7 +100,7 @@ void CoreAccountSettings::setAutoConnectOnStartup(bool b) } -bool CoreAccountSettings::autoConnectToFixedAccount() +bool CoreAccountSettings::autoConnectToFixedAccount() const { return localValue("AutoConnectToFixedAccount", false).toBool(); } @@ -124,7 +124,7 @@ void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data } -QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) +QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) const { QVariantMap map; QString base = QString::number(id.toInt()); @@ -166,7 +166,7 @@ void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &va } -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(); @@ -186,7 +186,7 @@ void CoreAccountSettings::setJumpKeyMap(const QHash &keyMap) } -QHash CoreAccountSettings::jumpKeyMap() +QHash CoreAccountSettings::jumpKeyMap() const { QHash keyMap; QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap(); @@ -209,7 +209,7 @@ void CoreAccountSettings::setBufferViewOverlay(const QSet &viewIds) } -QSet CoreAccountSettings::bufferViewOverlay() +QSet CoreAccountSettings::bufferViewOverlay() const { QSet viewIds; QVariantList variants = accountValue("BufferViewOverlay").toList(); @@ -236,7 +236,9 @@ void CoreAccountSettings::clearAccounts() /***********************************************************************************************/ // CoreConnectionSettings: -CoreConnectionSettings::CoreConnectionSettings() : ClientSettings("CoreConnection") {} +CoreConnectionSettings::CoreConnectionSettings() + : ClientSettings("CoreConnection") +{} void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode) { @@ -244,7 +246,7 @@ void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode) } -CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode() +CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode() const { auto mode = localValue("NetworkDetectionMode", UseQNetworkConfigurationManager).toInt(); if (mode == 0) @@ -259,7 +261,7 @@ void CoreConnectionSettings::setAutoReconnect(bool autoReconnect) } -bool CoreConnectionSettings::autoReconnect() +bool CoreConnectionSettings::autoReconnect() const { return localValue("AutoReconnect", true).toBool(); } @@ -271,7 +273,7 @@ void CoreConnectionSettings::setPingTimeoutInterval(int interval) } -int CoreConnectionSettings::pingTimeoutInterval() +int CoreConnectionSettings::pingTimeoutInterval() const { return localValue("PingTimeoutInterval", 60).toInt(); } @@ -283,7 +285,7 @@ void CoreConnectionSettings::setReconnectInterval(int interval) } -int CoreConnectionSettings::reconnectInterval() +int CoreConnectionSettings::reconnectInterval() const { return localValue("ReconnectInterval", 60).toInt(); } @@ -292,18 +294,37 @@ int CoreConnectionSettings::reconnectInterval() /***********************************************************************************************/ // 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(); } @@ -315,7 +336,7 @@ void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickT } -NotificationSettings::HighlightNickType NotificationSettings::highlightNick() +NotificationSettings::HighlightNickType NotificationSettings::highlightNick() const { return (NotificationSettings::HighlightNickType)localValue("Highlights/HighlightNick", CurrentNick).toInt(); @@ -328,7 +349,7 @@ void NotificationSettings::setNicksCaseSensitive(bool cs) } -bool NotificationSettings::nicksCaseSensitive() +bool NotificationSettings::nicksCaseSensitive() const { return localValue("Highlights/NicksCaseSensitive", false).toBool(); } @@ -338,7 +359,8 @@ bool NotificationSettings::nicksCaseSensitive() // TabCompletionSettings // ======================================== -TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion") +TabCompletionSettings::TabCompletionSettings() + : ClientSettings("TabCompletion") { } @@ -349,7 +371,7 @@ void TabCompletionSettings::setCompletionSuffix(const QString &suffix) } -QString TabCompletionSettings::completionSuffix() +QString TabCompletionSettings::completionSuffix() const { return localValue("CompletionSuffix", ": ").toString(); } @@ -361,7 +383,7 @@ void TabCompletionSettings::setAddSpaceMidSentence(bool space) } -bool TabCompletionSettings::addSpaceMidSentence() +bool TabCompletionSettings::addSpaceMidSentence() const { return localValue("AddSpaceMidSentence", false).toBool(); } @@ -373,7 +395,7 @@ void TabCompletionSettings::setSortMode(SortMode mode) } -TabCompletionSettings::SortMode TabCompletionSettings::sortMode() +TabCompletionSettings::SortMode TabCompletionSettings::sortMode() const { return static_cast(localValue("SortMode"), LastActivity); } @@ -385,7 +407,7 @@ void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs) } -Qt::CaseSensitivity TabCompletionSettings::caseSensitivity() +Qt::CaseSensitivity TabCompletionSettings::caseSensitivity() const { return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt(); } @@ -397,7 +419,7 @@ void TabCompletionSettings::setUseLastSpokenTo(bool use) } -bool TabCompletionSettings::useLastSpokenTo() +bool TabCompletionSettings::useLastSpokenTo() const { return localValue("UseLastSpokenTo", false).toBool(); } @@ -412,13 +434,13 @@ ItemViewSettings::ItemViewSettings(const QString &group) : ClientSettings(group) } -bool ItemViewSettings::displayTopicInTooltip() +bool ItemViewSettings::displayTopicInTooltip() const { return localValue("DisplayTopicInTooltip", false).toBool(); } -bool ItemViewSettings::mouseWheelChangesBuffer() +bool ItemViewSettings::mouseWheelChangesBuffer() const { return localValue("MouseWheelChangesBuffer", false).toBool(); } diff --git a/src/client/clientsettings.h b/src/client/clientsettings.h index c22eef8c..6c984ed9 100644 --- a/src/client/clientsettings.h +++ b/src/client/clientsettings.h @@ -54,32 +54,32 @@ public: // 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 knownAccounts(); - AccountId lastAccount(); + QList 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 &keyMap); - QHash jumpKeyMap(); + QHash jumpKeyMap() const; void setBufferViewOverlay(const QSet &viewIds); - QSet bufferViewOverlay(); + QSet 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; @@ -100,18 +100,18 @@ public: 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; }; @@ -131,16 +131,16 @@ public: 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; }; @@ -159,19 +159,19 @@ public: 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; }; @@ -183,6 +183,6 @@ class CLIENT_EXPORT ItemViewSettings : public ClientSettings public: ItemViewSettings(const QString &group = "ItemViews"); - bool displayTopicInTooltip(); - bool mouseWheelChangesBuffer(); + bool displayTopicInTooltip() const; + bool mouseWheelChangesBuffer() const; }; diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 2330f45f..868628a3 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -29,56 +29,41 @@ const int VERSION = 1; /// Settings version for backwords/forwards // QtUiApplication::init() to handle upgrading and downgrading. const int VERSION_MINOR_INITIAL = 1; /// Initial settings version for compatible changes -QHash Settings::settingsCache; -QHash Settings::settingsKeyPersistedCache; -QHash Settings::settingsChangeNotifier; +QHash Settings::_settingsCache; +QHash Settings::_settingsKeyPersistedCache; +QHash> 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; @@ -92,7 +77,7 @@ uint Settings::version() } -uint Settings::versionMinor() +uint Settings::versionMinor() const { // Don't cache this value; ignore the group create_qsettings; @@ -105,7 +90,8 @@ uint Settings::versionMinor() // 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(this)->setVersionMinor(VERSION_MINOR_INITIAL); return VERSION_MINOR_INITIAL; } else { return verMinor; @@ -122,7 +108,18 @@ void Settings::setVersionMinor(const uint versionMinor) } -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()) { @@ -134,29 +131,30 @@ bool Settings::sync() { } -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); @@ -166,13 +164,13 @@ QStringList Settings::localChildKeys(const QString &rootkey) } -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); @@ -184,7 +182,7 @@ QStringList Settings::localChildGroups(const QString &rootkey) 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); @@ -195,9 +193,9 @@ void Settings::setLocalValue(const QString &key, const QVariant &data) } -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 @@ -207,17 +205,16 @@ QVariant Settings::localValue(const QString &key, const QVariant &def) } 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 @@ -232,17 +229,82 @@ bool Settings::localKeyExists(const QString &key) 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(); + return _settingsChangeNotifier[normKey].get(); +} + + +bool Settings::hasNotifier(const QString &normKey) const +{ + return _settingsChangeNotifier.contains(normKey); +} diff --git a/src/common/settings.h b/src/common/settings.h index 1a0fa6d7..48dfafdd 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -22,6 +22,8 @@ #include "common-export.h" +#include + #include #include #include @@ -50,10 +52,10 @@ public: 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 @@ -62,7 +64,7 @@ public: * * @return Major configuration version (the X in XX.YY) */ - virtual uint version(); + virtual uint version() const; /** * Get the minor configuration version @@ -72,7 +74,7 @@ public: * @see Settings::setVersionMinor() * @return Minor configuration version (the Y in XX.YY) */ - virtual uint versionMinor(); + virtual uint versionMinor() const; /** * Set the minor configuration version @@ -97,20 +99,20 @@ public: * * @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 @@ -118,42 +120,19 @@ protected: * @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 settingsCache; ///< Cached settings values - static QHash settingsKeyPersistedCache; ///< Cached settings key exists on disk - static QHash 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 @@ -161,11 +140,7 @@ private: * @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) @@ -175,11 +150,7 @@ private: * @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 @@ -187,40 +158,20 @@ private: * @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 _settingsCache; ///< Cached settings values + static QHash _settingsKeyPersistedCache; ///< Cached settings key exists on disk + static QHash> _settingsChangeNotifier; }; diff --git a/src/core/coresettings.cpp b/src/core/coresettings.cpp index a914856c..8ba20c51 100644 --- a/src/core/coresettings.cpp +++ b/src/core/coresettings.cpp @@ -22,7 +22,8 @@ #include "quassel.h" -CoreSettings::CoreSettings(const QString group) : Settings(group, Quassel::buildInfo().coreApplicationName) +CoreSettings::CoreSettings(QString group) + : Settings(std::move(group), Quassel::buildInfo().coreApplicationName) { } @@ -33,25 +34,25 @@ void CoreSettings::setStorageSettings(const QVariant &data) } -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"); } @@ -63,7 +64,7 @@ void CoreSettings::setCoreState(const QVariant &data) } -QVariant CoreSettings::coreState(const QVariant &def) +QVariant CoreSettings::coreState(const QVariant &def) const { return localValue("CoreState", def); } diff --git a/src/core/coresettings.h b/src/core/coresettings.h index ac70a36c..3c05ba16 100644 --- a/src/core/coresettings.h +++ b/src/core/coresettings.h @@ -18,27 +18,23 @@ * 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_*/ diff --git a/src/core/coreusersettings.cpp b/src/core/coreusersettings.cpp index e0f4e9e7..93408674 100644 --- a/src/core/coreusersettings.cpp +++ b/src/core/coreusersettings.cpp @@ -20,12 +20,13 @@ #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()) { @@ -35,7 +36,7 @@ Identity CoreUserSettings::identity(IdentityId id) } -QList CoreUserSettings::identityIds() +QList CoreUserSettings::identityIds() const { QList res; foreach(QString id, localChildKeys("Identities")) { @@ -63,13 +64,13 @@ void CoreUserSettings::setSessionState(const QVariant &data) } -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"))) { @@ -85,7 +86,7 @@ void CoreUserSettings::setSessionValue(const QString &key, const QVariant &data) } -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); } diff --git a/src/core/coreusersettings.h b/src/core/coreusersettings.h index 01a72c81..c89f9387 100644 --- a/src/core/coreusersettings.h +++ b/src/core/coreusersettings.h @@ -18,8 +18,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _COREUSERSETTINGS_H_ -#define _COREUSERSETTINGS_H_ +#pragma once #include "coresettings.h" #include "identity.h" @@ -33,24 +32,21 @@ class CoreUserSettings : public CoreSettings public: CoreUserSettings(UserId user); - Identity identity(IdentityId id); - QList identityIds(); + Identity identity(IdentityId id) const; + QList 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 diff --git a/src/qtui/chatviewsettings.cpp b/src/qtui/chatviewsettings.cpp index ffa90aac..2296989b 100644 --- a/src/qtui/chatviewsettings.cpp +++ b/src/qtui/chatviewsettings.cpp @@ -39,3 +39,79 @@ ChatViewSettings::ChatViewSettings(ChatView *view) : 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( + localValue("SenderPrefixMode", + QVariant::fromValue( + UiStyle::SenderPrefixMode::HighestMode)).toInt()); + // Cast the QVariant to an integer, then cast that to the enum class. + // .canConvert() returned true, but + // .value(); 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); +} diff --git a/src/qtui/chatviewsettings.h b/src/qtui/chatviewsettings.h index 19aed61e..0a4fd6a3 100644 --- a/src/qtui/chatviewsettings.h +++ b/src/qtui/chatviewsettings.h @@ -18,8 +18,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef CHATVIEWSETTINGS_H -#define CHATVIEWSETTINGS_H +#pragma once #include "qtuisettings.h" #include "uistyle.h" @@ -37,34 +36,34 @@ public: 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. /** @@ -72,42 +71,30 @@ public: * * @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( - localValue("SenderPrefixMode", - QVariant::fromValue( - UiStyle::SenderPrefixMode::HighestMode)).toInt()); - // Cast the QVariant to an integer, then cast that to the enum class. - // .canConvert() returned true, but - // .value(); 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 diff --git a/src/qtui/qtuisettings.cpp b/src/qtui/qtuisettings.cpp index 6a8c99c6..fada2501 100644 --- a/src/qtui/qtuisettings.cpp +++ b/src/qtui/qtuisettings.cpp @@ -20,39 +20,40 @@ #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(); } diff --git a/src/qtui/qtuisettings.h b/src/qtui/qtuisettings.h index 63fda386..a3fdd7dd 100644 --- a/src/qtui/qtuisettings.h +++ b/src/qtui/qtuisettings.h @@ -18,26 +18,23 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef QTUISETTINGS_H_ -#define QTUISETTINGS_H_ - -#include +#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); }; @@ -46,9 +43,6 @@ class WarningsSettings : public UiSettings public: WarningsSettings(); - bool showWarning(const QString &key); + bool showWarning(const QString &key) const; void setShowWarning(const QString &key, bool show); }; - - -#endif diff --git a/src/qtui/qtuistyle.cpp b/src/qtui/qtuistyle.cpp index efca13a5..0fd43c1e 100644 --- a/src/qtui/qtuistyle.cpp +++ b/src/qtui/qtuistyle.cpp @@ -57,7 +57,7 @@ void QtUiStyle::updateTimestampFormatString() void QtUiStyle::updateSenderPrefixDisplay() { ChatViewSettings s; - setSenderPrefixDisplay(s.SenderPrefixDisplay()); + setSenderPrefixDisplay(s.senderPrefixDisplay()); } void QtUiStyle::updateShowSenderBrackets() diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index 046dad91..a1200bda 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -439,7 +439,7 @@ void BufferView::addActionsToMenu(QMenu *contextMenu, const QModelIndex &index) 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()); } diff --git a/src/uisupport/contextmenuactionprovider.cpp b/src/uisupport/contextmenuactionprovider.cpp index 3bc7cd07..6cdc9fba 100644 --- a/src/uisupport/contextmenuactionprovider.cpp +++ b/src/uisupport/contextmenuactionprovider.cpp @@ -159,50 +159,49 @@ ContextMenuActionProvider::~ContextMenuActionProvider() } -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() << index, nullptr, QString(), receiver, method, isCustomBufferView); + addActions(menu, QList() << 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() << Client::networkModel()->bufferIndex(msgBuffer), filter, chanOrNick, receiver, method, false); + addActions(menu, QList() << Client::networkModel()->bufferIndex(msgBuffer), filter, chanOrNick, std::move(slot), false); } -void ContextMenuActionProvider::addActions(QMenu *menu, const QList &indexList, QObject *receiver, const char *method, bool isCustomBufferView) +void ContextMenuActionProvider::addActions(QMenu *menu, const QList &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 &indexList_, - MessageFilter *filter_, - const QString &contextItem_, - QObject *receiver_, - const char *method_, - bool isCustomBufferView) + const QList &indexList_, + MessageFilter *filter_, + const QString &contextItem_, + ActionSlot actionSlot, + bool isCustomBufferView) { if (!indexList_.count()) return; @@ -210,7 +209,7 @@ void ContextMenuActionProvider::addActions(QMenu *menu, 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 diff --git a/src/uisupport/contextmenuactionprovider.h b/src/uisupport/contextmenuactionprovider.h index e7e8eb49..7d639fec 100644 --- a/src/uisupport/contextmenuactionprovider.h +++ b/src/uisupport/contextmenuactionprovider.h @@ -22,6 +22,8 @@ #include "uisupport-export.h" +#include + #include "networkmodelcontroller.h" class UISUPPORT_EXPORT ContextMenuActionProvider : public NetworkModelController @@ -41,19 +43,46 @@ public: * @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 &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 + 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 + void addActions(QMenu *menu, const QList &indexList, Receiver *receiver, Slot slot, bool isCustomBufferView = false) + { + addActions(menu, indexList, buildActionSlot(receiver, std::move(slot)), isCustomBufferView); + } + void addActions(QMenu *menu, const QList &indexList, ActionSlot = {}, bool isCustomBufferView = false); + + template + 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 &indexList, MessageFilter *filter, const QString &chanOrNick, - QObject *receiver, const char *slot, bool allowBufferHide); + template + 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 + 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 &indexList, MessageFilter *filter, const QString &chanOrNick, ActionSlot actionSlot, bool isCustomBufferView); Action *addAction(ActionType, QMenu *, bool condition = true); Action *addAction(Action *, QMenu *, bool condition = true); diff --git a/src/uisupport/networkmodelcontroller.cpp b/src/uisupport/networkmodelcontroller.cpp index 0f948f24..c33e0306 100644 --- a/src/uisupport/networkmodelcontroller.cpp +++ b/src/uisupport/networkmodelcontroller.cpp @@ -96,10 +96,9 @@ void NetworkModelController::setContextItem(const QString &contextItem) } -void NetworkModelController::setSlot(QObject *receiver, const char *method) +void NetworkModelController::setSlot(ActionSlot slot) { - _receiver = receiver; - _method = method; + _actionSlot = std::move(slot); } @@ -197,9 +196,8 @@ void NetworkModelController::removeBuffers(const QModelIndexList &indexList) 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); } } diff --git a/src/uisupport/networkmodelcontroller.h b/src/uisupport/networkmodelcontroller.h index 05d4ee36..1d691f70 100644 --- a/src/uisupport/networkmodelcontroller.h +++ b/src/uisupport/networkmodelcontroller.h @@ -22,6 +22,9 @@ #include "uisupport-export.h" +#include +#include + #include #include "action.h" @@ -132,14 +135,24 @@ protected: inline QList 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 &); void setMessageFilter(MessageFilter *); void setContextItem(const QString &); - void setSlot(QObject *receiver, const char *method); + + using ActionSlot = std::function; + + template + ActionSlot buildActionSlot(Receiver *receiver, Slot slot) + { + static_assert(!std::is_same::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); @@ -186,8 +199,7 @@ private: QList _indexList; MessageFilter *_messageFilter{nullptr}; QString _contextItem; ///< Channel name or nick to provide context menu for - QObject *_receiver{nullptr}; - const char *_method; + ActionSlot _actionSlot; }; @@ -220,5 +232,3 @@ Action *NetworkModelController::action(ActionType type) const { return _actionBy QList 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; } diff --git a/src/uisupport/uisettings.cpp b/src/uisupport/uisettings.cpp index dc1199a8..1d8a99ab 100644 --- a/src/uisupport/uisettings.cpp +++ b/src/uisupport/uisettings.cpp @@ -25,27 +25,56 @@ #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(ftype)), format); } -QTextCharFormat UiStyleSettings::customFormat(UiStyle::FormatType ftype) +QTextCharFormat UiStyleSettings::customFormat(UiStyle::FormatType ftype) const { return localValue(QString("Format/%1").arg(static_cast(ftype)), QTextFormat()).value().toCharFormat(); } @@ -57,7 +86,7 @@ void UiStyleSettings::removeCustomFormat(UiStyle::FormatType ftype) } -QList UiStyleSettings::availableFormats() +QList UiStyleSettings::availableFormats() const { QList formats; QStringList list = localChildKeys("Format"); @@ -72,8 +101,9 @@ QList UiStyleSettings::availableFormats() * 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)) { } @@ -84,7 +114,7 @@ void SessionSettings::setValue(const QString &key, const QVariant &data) } -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); } @@ -111,6 +141,18 @@ void SessionSettings::cleanup() } +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); @@ -160,25 +202,27 @@ void SessionSettings::sessionAging() * 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(); } diff --git a/src/uisupport/uisettings.h b/src/uisupport/uisettings.h index c90f9089..e62db07e 100644 --- a/src/uisupport/uisettings.h +++ b/src/uisupport/uisettings.h @@ -28,10 +28,10 @@ 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 @@ -39,9 +39,9 @@ public: * @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); }; @@ -51,21 +51,21 @@ public: 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 availableFormats(); + QList 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(); @@ -75,8 +75,8 @@ public: 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; @@ -91,8 +91,8 @@ public: //! 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; };