X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclientsettings.cpp;h=cf0cb8d786c6859a07216bc677b2f5f507e12a88;hp=6f9961f6528eacc333b558add3d1dd9cea47dc1d;hb=158443f71d48215eea8b47b836b61afd77654b78;hpb=fa00b68a21c777682d9feb37ade6b3904fc19d92 diff --git a/src/client/clientsettings.cpp b/src/client/clientsettings.cpp index 6f9961f6..cf0cb8d7 100644 --- a/src/client/clientsettings.cpp +++ b/src/client/clientsettings.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-09 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,11 +15,12 @@ * 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., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include +#include +#include #include "clientsettings.h" @@ -28,252 +29,401 @@ #include #endif - #include "client.h" #include "quassel.h" -ClientSettings::ClientSettings(QString g) : Settings(g, Quassel::buildInfo().clientApplicationName) { +ClientSettings::ClientSettings(QString g) : Settings(g, Quassel::buildInfo().clientApplicationName) +{ } -ClientSettings::~ClientSettings() { + +ClientSettings::~ClientSettings() +{ } + /***********************************************************************************************/ -CoreAccountSettings::CoreAccountSettings(const QString &subgroup) - : ClientSettings("CoreAccounts"), - _subgroup(subgroup) +CoreAccountSettings::CoreAccountSettings(QString subgroup) + : ClientSettings("CoreAccounts"), + _subgroup(std::move(subgroup)) { } -void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot) { - ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), receiver, slot); + +void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot) +{ + ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), receiver, slot); } -QList CoreAccountSettings::knownAccounts() { - QList ids; - foreach(const QString &key, localChildGroups()) { - AccountId acc = key.toInt(); - if(acc.isValid()) - ids << acc; - } - return ids; + +QList CoreAccountSettings::knownAccounts() +{ + QList ids; + foreach(const QString &key, localChildGroups()) { + AccountId acc = key.toInt(); + if (acc.isValid()) + ids << acc; + } + return ids; } -AccountId CoreAccountSettings::lastAccount() { - return localValue("LastAccount", 0).toInt(); + +AccountId CoreAccountSettings::lastAccount() +{ + return localValue("LastAccount", 0).toInt(); } -void CoreAccountSettings::setLastAccount(AccountId account) { - setLocalValue("LastAccount", account.toInt()); + +void CoreAccountSettings::setLastAccount(AccountId account) +{ + setLocalValue("LastAccount", account.toInt()); } -AccountId CoreAccountSettings::autoConnectAccount() { - return localValue("AutoConnectAccount", 0).toInt(); + +AccountId CoreAccountSettings::autoConnectAccount() +{ + return localValue("AutoConnectAccount", 0).toInt(); } -void CoreAccountSettings::setAutoConnectAccount(AccountId account) { - setLocalValue("AutoConnectAccount", account.toInt()); + +void CoreAccountSettings::setAutoConnectAccount(AccountId account) +{ + setLocalValue("AutoConnectAccount", account.toInt()); } -void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data) { - QString base = QString::number(id.toInt()); - foreach(const QString &key, data.keys()) { - setLocalValue(base + "/" + key, data.value(key)); - } - // FIXME Migration from 0.5 -> 0.6 - removeLocalKey(QString("%1/Connection").arg(base)); +bool CoreAccountSettings::autoConnectOnStartup() +{ + return localValue("AutoConnectOnStartup", false).toBool(); } -QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) { - QVariantMap map; - QString base = QString::number(id.toInt()); - foreach(const QString &key, localChildKeys(base)) { - map[key] = localValue(base + "/" + key); - } - // FIXME Migration from 0.5 -> 0.6 - if(!map.contains("Uuid") && map.contains("Connection")) { - QVariantMap oldmap = map.value("Connection").toMap(); - map["AccountName"] = oldmap.value("AccountName"); - map["HostName"] = oldmap.value("Host"); - map["Port"] = oldmap.value("Port"); - map["User"] = oldmap.value("User"); - map["Password"] = oldmap.value("Password"); - map["StorePassword"] = oldmap.value("RememberPasswd"); - map["UseSSL"] = oldmap.value("useSsl"); - map["UseProxy"] = oldmap.value("useProxy"); - map["ProxyHostName"] = oldmap.value("proxyHost"); - map["ProxyPort"] = oldmap.value("proxyPort"); - map["ProxyUser"] = oldmap.value("proxyUser"); - map["ProxyPassword"] = oldmap.value("proxyPassword"); - map["ProxyType"] = oldmap.value("proxyType"); +void CoreAccountSettings::setAutoConnectOnStartup(bool b) +{ + setLocalValue("AutoConnectOnStartup", b); +} - map["AccountId"] = id.toInt(); - map["Uuid"] = QUuid::createUuid().toString(); - } - return map; +bool CoreAccountSettings::autoConnectToFixedAccount() +{ + return localValue("AutoConnectToFixedAccount", false).toBool(); } -void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value) { - if(!Client::currentCoreAccount().isValid()) - return; - setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value); + +void CoreAccountSettings::setAutoConnectToFixedAccount(bool b) +{ + setLocalValue("AutoConnectToFixedAccount", b); } -QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def) { - if(!Client::currentCoreAccount().isValid()) - return QVariant(); - return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def); + +void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data) +{ + QString base = QString::number(id.toInt()); + foreach(const QString &key, data.keys()) { + setLocalValue(base + "/" + key, data.value(key)); + } + + // FIXME Migration from 0.5 -> 0.6 + removeLocalKey(QString("%1/Connection").arg(base)); } -void CoreAccountSettings::setJumpKeyMap(const QHash &keyMap) { - QVariantMap variants; - QHash::const_iterator mapIter = keyMap.constBegin(); - while(mapIter != keyMap.constEnd()) { - variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value()); - ++mapIter; - } - setAccountValue("JumpKeyMap", variants); + +QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) +{ + QVariantMap map; + QString base = QString::number(id.toInt()); + foreach(const QString &key, localChildKeys(base)) { + map[key] = localValue(base + "/" + key); + } + + // FIXME Migration from 0.5 -> 0.6 + if (!map.contains("Uuid") && map.contains("Connection")) { + QVariantMap oldmap = map.value("Connection").toMap(); + map["AccountName"] = oldmap.value("AccountName"); + map["HostName"] = oldmap.value("Host"); + map["Port"] = oldmap.value("Port"); + map["User"] = oldmap.value("User"); + map["Password"] = oldmap.value("Password"); + map["StorePassword"] = oldmap.value("RememberPasswd"); + map["UseSSL"] = oldmap.value("useSsl"); + map["UseProxy"] = oldmap.value("useProxy"); + map["ProxyHostName"] = oldmap.value("proxyHost"); + map["ProxyPort"] = oldmap.value("proxyPort"); + map["ProxyUser"] = oldmap.value("proxyUser"); + map["ProxyPassword"] = oldmap.value("proxyPassword"); + map["ProxyType"] = oldmap.value("proxyType"); + map["Internal"] = oldmap.value("InternalAccount"); + + map["AccountId"] = id.toInt(); + map["Uuid"] = QUuid::createUuid().toString(); + } + + return map; +} + + +void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value) +{ + if (!Client::currentCoreAccount().isValid()) + return; + setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value); } -QHash CoreAccountSettings::jumpKeyMap() { - QHash keyMap; - QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap(); - QVariantMap::const_iterator mapIter = variants.constBegin(); - while(mapIter != variants.constEnd()) { - keyMap[mapIter.key().toInt()] = mapIter.value().value(); - ++mapIter; - } - return keyMap; + +QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def) +{ + if (!Client::currentCoreAccount().isValid()) + return QVariant(); + return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def); +} + + +void CoreAccountSettings::setJumpKeyMap(const QHash &keyMap) +{ + QVariantMap variants; + QHash::const_iterator mapIter = keyMap.constBegin(); + while (mapIter != keyMap.constEnd()) { + variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value()); + ++mapIter; + } + setAccountValue("JumpKeyMap", variants); +} + + +QHash CoreAccountSettings::jumpKeyMap() +{ + QHash keyMap; + QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap(); + QVariantMap::const_iterator mapIter = variants.constBegin(); + while (mapIter != variants.constEnd()) { + keyMap[mapIter.key().toInt()] = mapIter.value().value(); + ++mapIter; + } + return keyMap; +} + + +void CoreAccountSettings::setBufferViewOverlay(const QSet &viewIds) +{ + QVariantList variants; + foreach(int viewId, viewIds) { + variants << qVariantFromValue(viewId); + } + setAccountValue("BufferViewOverlay", variants); } -void CoreAccountSettings::removeAccount(AccountId id) { - removeLocalKey(QString("%1").arg(id.toInt())); + +QSet CoreAccountSettings::bufferViewOverlay() +{ + QSet viewIds; + QVariantList variants = accountValue("BufferViewOverlay").toList(); + for (QVariantList::const_iterator iter = variants.constBegin(); iter != variants.constEnd(); ++iter) { + viewIds << iter->toInt(); + } + return viewIds; +} + + +void CoreAccountSettings::removeAccount(AccountId id) +{ + removeLocalKey(QString("%1").arg(id.toInt())); +} + + +void CoreAccountSettings::clearAccounts() +{ + foreach(const QString &key, localChildGroups()) + removeLocalKey(key); } /***********************************************************************************************/ -// NotificationSettings: +// CoreConnectionSettings: -NotificationSettings::NotificationSettings() : ClientSettings("Notification") { +CoreConnectionSettings::CoreConnectionSettings() : ClientSettings("CoreConnection") {} + +void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode) +{ + setLocalValue("NetworkDetectionMode", mode); } -void NotificationSettings::setHighlightList(const QVariantList &highlightList) { - setLocalValue("Highlights/CustomList", highlightList); + +CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode() +{ + auto mode = localValue("NetworkDetectionMode", UseQNetworkConfigurationManager).toInt(); + if (mode == 0) + mode = UseQNetworkConfigurationManager; // UseSolid is gone, map that to the new default + return static_cast(mode); } -QVariantList NotificationSettings::highlightList() { - return localValue("Highlights/CustomList").toList(); + +void CoreConnectionSettings::setAutoReconnect(bool autoReconnect) +{ + setLocalValue("AutoReconnect", autoReconnect); } -void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType) { - setLocalValue("Highlights/HighlightNick", highlightNickType); + +bool CoreConnectionSettings::autoReconnect() +{ + return localValue("AutoReconnect", true).toBool(); } -NotificationSettings::HighlightNickType NotificationSettings::highlightNick() { - return (NotificationSettings::HighlightNickType) localValue("Highlights/HighlightNick", CurrentNick).toInt(); + +void CoreConnectionSettings::setPingTimeoutInterval(int interval) +{ + setLocalValue("PingTimeoutInterval", interval); } -void NotificationSettings::setNicksCaseSensitive(bool cs) { - setLocalValue("Highlights/NicksCaseSensitive", cs); + +int CoreConnectionSettings::pingTimeoutInterval() +{ + return localValue("PingTimeoutInterval", 60).toInt(); } -bool NotificationSettings::nicksCaseSensitive() { - return localValue("Highlights/NicksCaseSensitive", false).toBool(); + +void CoreConnectionSettings::setReconnectInterval(int interval) +{ + setLocalValue("ReconnectInterval", interval); } -// ======================================== -// KnownHostsSettings -// ======================================== -KnownHostsSettings::KnownHostsSettings() - : ClientSettings("KnownHosts") +int CoreConnectionSettings::reconnectInterval() { + return localValue("ReconnectInterval", 60).toInt(); } -QByteArray KnownHostsSettings::knownDigest(const QHostAddress &address) { - return localValue(address.toString(), QByteArray()).toByteArray(); + +/***********************************************************************************************/ +// NotificationSettings: + +NotificationSettings::NotificationSettings() : ClientSettings("Notification") +{ } -void KnownHostsSettings::saveKnownHost(const QHostAddress &address, const QByteArray &certDigest) { - setLocalValue(address.toString(), certDigest); + +void NotificationSettings::setHighlightList(const QVariantList &highlightList) +{ + setLocalValue("Highlights/CustomList", highlightList); } -bool KnownHostsSettings::isKnownHost(const QHostAddress &address, const QByteArray &certDigest) { - return certDigest == localValue(address.toString(), QByteArray()).toByteArray(); + +QVariantList NotificationSettings::highlightList() +{ + return localValue("Highlights/CustomList").toList(); } -#ifdef HAVE_SSL -QByteArray KnownHostsSettings::knownDigest(const QSslSocket *socket) { - return knownDigest(socket->peerAddress()); + +void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType) +{ + setLocalValue("Highlights/HighlightNick", highlightNickType); } -void KnownHostsSettings::saveKnownHost(const QSslSocket *socket) { - Q_ASSERT(socket); - saveKnownHost(socket->peerAddress(), socket->peerCertificate().digest()); + +NotificationSettings::HighlightNickType NotificationSettings::highlightNick() +{ + return (NotificationSettings::HighlightNickType)localValue("Highlights/HighlightNick", + CurrentNick).toInt(); } -bool KnownHostsSettings::isKnownHost(const QSslSocket *socket) { - Q_ASSERT(socket); - return isKnownHost(socket->peerAddress(), socket->peerCertificate().digest()); + +void NotificationSettings::setNicksCaseSensitive(bool cs) +{ + setLocalValue("Highlights/NicksCaseSensitive", cs); +} + + +bool NotificationSettings::nicksCaseSensitive() +{ + return localValue("Highlights/NicksCaseSensitive", false).toBool(); } -#endif // ======================================== // TabCompletionSettings // ======================================== -TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion") { +TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion") +{ +} + + +void TabCompletionSettings::setCompletionSuffix(const QString &suffix) +{ + setLocalValue("CompletionSuffix", suffix); } -void TabCompletionSettings::setCompletionSuffix(const QString &suffix) { - setLocalValue("CompletionSuffix", suffix); + +QString TabCompletionSettings::completionSuffix() +{ + return localValue("CompletionSuffix", ": ").toString(); } -QString TabCompletionSettings::completionSuffix() { - return localValue("CompletionSuffix", ": ").toString(); + +void TabCompletionSettings::setAddSpaceMidSentence(bool space) +{ + setLocalValue("AddSpaceMidSentence", space); } -void TabCompletionSettings::setSortMode(SortMode mode) { - setLocalValue("SortMode", mode); + +bool TabCompletionSettings::addSpaceMidSentence() +{ + return localValue("AddSpaceMidSentence", false).toBool(); } -TabCompletionSettings::SortMode TabCompletionSettings::sortMode() { - return static_cast(localValue("SortMode"), LastActivity); + +void TabCompletionSettings::setSortMode(SortMode mode) +{ + setLocalValue("SortMode", mode); } -void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs) { - setLocalValue("CaseSensitivity", cs); + +TabCompletionSettings::SortMode TabCompletionSettings::sortMode() +{ + return static_cast(localValue("SortMode"), LastActivity); } -Qt::CaseSensitivity TabCompletionSettings::caseSensitivity() { - return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt(); + +void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs) +{ + setLocalValue("CaseSensitivity", cs); } -void TabCompletionSettings::setUseLastSpokenTo(bool use) { - setLocalValue("UseLastSpokenTo", use); + +Qt::CaseSensitivity TabCompletionSettings::caseSensitivity() +{ + return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt(); +} + + +void TabCompletionSettings::setUseLastSpokenTo(bool use) +{ + setLocalValue("UseLastSpokenTo", use); } -bool TabCompletionSettings::useLastSpokenTo() { - return localValue("UseLastSpokenTo", false).toBool(); + +bool TabCompletionSettings::useLastSpokenTo() +{ + return localValue("UseLastSpokenTo", false).toBool(); } + // ======================================== // ItemViewSettings // ======================================== -ItemViewSettings::ItemViewSettings(const QString &group) : ClientSettings(group) { - +ItemViewSettings::ItemViewSettings(const QString &group) : ClientSettings(group) +{ } -bool ItemViewSettings::displayTopicInTooltip() { - return localValue("DisplayTopicInTooltip", false).toBool(); + +bool ItemViewSettings::displayTopicInTooltip() +{ + return localValue("DisplayTopicInTooltip", false).toBool(); } -bool ItemViewSettings::mouseWheelChangesBuffer() { - return localValue("MouseWheelChangesBuffer", false).toBool(); + +bool ItemViewSettings::mouseWheelChangesBuffer() +{ + return localValue("MouseWheelChangesBuffer", false).toBool(); }