X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclientsettings.cpp;h=dfed519f752f0b8d10d174f3441f3d973397da78;hp=2bf6412b2c9de7593de1f0aaa666a0c17a9a27e9;hb=84381d6b74a31c8b1b6468fa490621f8a7a32c23;hpb=1177f164f518b8f47b64f6736d176a995d5c17ed diff --git a/src/client/clientsettings.cpp b/src/client/clientsettings.cpp index 2bf6412b..dfed519f 100644 --- a/src/client/clientsettings.cpp +++ b/src/client/clientsettings.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,13 +18,21 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "client.h" +#include + + #include "clientsettings.h" -#include "global.h" -#include +#include +#ifdef HAVE_SSL +#include +#endif + -ClientSettings::ClientSettings(QString g) : Settings(g, Global::clientApplicationName) { +#include "client.h" +#include "quassel.h" + +ClientSettings::ClientSettings(QString g) : Settings(g, Quassel::buildInfo().clientApplicationName) { } ClientSettings::~ClientSettings() { @@ -32,14 +40,22 @@ ClientSettings::~ClientSettings() { /***********************************************************************************************/ -CoreAccountSettings::CoreAccountSettings(const QString &subgroup) : ClientSettings("CoreAccounts") { - _subgroup = subgroup; +CoreAccountSettings::CoreAccountSettings(const QString &subgroup) + : ClientSettings("CoreAccounts"), + _subgroup(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); } QList CoreAccountSettings::knownAccounts() { QList ids; - foreach(QString key, localChildGroups()) { - ids << key.toInt(); + foreach(const QString &key, localChildGroups()) { + AccountId acc = key.toInt(); + if(acc.isValid()) + ids << acc; } return ids; } @@ -60,39 +76,255 @@ void CoreAccountSettings::setAutoConnectAccount(AccountId account) { setLocalValue("AutoConnectAccount", account.toInt()); } +bool CoreAccountSettings::autoConnectOnStartup() { + return localValue("AutoConnectOnStartup", false).toBool(); +} + +void CoreAccountSettings::setAutoConnectOnStartup(bool b) { + setLocalValue("AutoConnectOnStartup", b); +} + +bool CoreAccountSettings::autoConnectToFixedAccount() { + return localValue("AutoConnectToFixedAccount", false).toBool(); +} + +void CoreAccountSettings::setAutoConnectToFixedAccount(bool b) { + setLocalValue("AutoConnectToFixedAccount", b); +} + void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data) { - setLocalValue(QString("%1/Connection").arg(id.toInt()), 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)); } QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) { - return localValue(QString("%1/Connection").arg(id.toInt()), QVariant()).toMap(); + 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().toInt()).arg(_subgroup).arg(key), value); + if(!Client::currentCoreAccount().isValid()) + return; + setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value); } QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def) { - if(!Client::currentCoreAccount().isValid()) return QVariant(); - return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().toInt()).arg(_subgroup).arg(key), 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); +} + +QSet CoreAccountSettings::bufferViewOverlay() { + QSet viewIds; + QVariantList variants = accountValue("BufferViewOverlay").toList(); + QVariantList::const_iterator iter = variants.constBegin(); + 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); +} + /***********************************************************************************************/ +// CoreConnectionSettings: + +CoreConnectionSettings::CoreConnectionSettings() : ClientSettings("CoreConnection") {} + +void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode) { + setLocalValue("NetworkDetectionMode", mode); +} + +CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode() { +#ifdef HAVE_KDE + NetworkDetectionMode def = UseSolid; +#else + NetworkDetectionMode def = UsePingTimeout; +#endif + return (NetworkDetectionMode)localValue("NetworkDetectionMode", def).toInt(); +} + +void CoreConnectionSettings::setAutoReconnect(bool autoReconnect) { + setLocalValue("AutoReconnect", autoReconnect); +} + +bool CoreConnectionSettings::autoReconnect() { + return localValue("AutoReconnect", true).toBool(); +} + +void CoreConnectionSettings::setPingTimeoutInterval(int interval) { + setLocalValue("PingTimeoutInterval", interval); +} + +int CoreConnectionSettings::pingTimeoutInterval() { + return localValue("PingTimeoutInterval", 60).toInt(); +} + +void CoreConnectionSettings::setReconnectInterval(int interval) { + setLocalValue("ReconnectInterval", interval); +} + +int CoreConnectionSettings::reconnectInterval() { + return localValue("ReconnectInterval", 60).toInt(); +} + +/***********************************************************************************************/ +// NotificationSettings: + +NotificationSettings::NotificationSettings() : ClientSettings("Notification") { +} + +void NotificationSettings::setHighlightList(const QVariantList &highlightList) { + setLocalValue("Highlights/CustomList", highlightList); +} + +QVariantList NotificationSettings::highlightList() { + return localValue("Highlights/CustomList").toList(); +} + +void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType) { + setLocalValue("Highlights/HighlightNick", highlightNickType); +} + +NotificationSettings::HighlightNickType NotificationSettings::highlightNick() { + return (NotificationSettings::HighlightNickType) localValue("Highlights/HighlightNick", CurrentNick).toInt(); +} + +void NotificationSettings::setNicksCaseSensitive(bool cs) { + setLocalValue("Highlights/NicksCaseSensitive", cs); +} + +bool NotificationSettings::nicksCaseSensitive() { + return localValue("Highlights/NicksCaseSensitive", false).toBool(); +} + +// ======================================== +// TabCompletionSettings +// ======================================== + +TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion") { +} + +void TabCompletionSettings::setCompletionSuffix(const QString &suffix) { + setLocalValue("CompletionSuffix", suffix); +} + +QString TabCompletionSettings::completionSuffix() { + return localValue("CompletionSuffix", ": ").toString(); +} + +void TabCompletionSettings::setAddSpaceMidSentence(const bool &space) { + setLocalValue("AddSpaceMidSentence", space); +} + +bool TabCompletionSettings::addSpaceMidSentence() { + return localValue("AddSpaceMidSentence", false).toBool(); +} + +void TabCompletionSettings::setSortMode(SortMode mode) { + setLocalValue("SortMode", mode); +} + +TabCompletionSettings::SortMode TabCompletionSettings::sortMode() { + return static_cast(localValue("SortMode"), LastActivity); +} + +void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs) { + setLocalValue("CaseSensitivity", cs); +} + +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(); +} + +// ======================================== +// ItemViewSettings +// ======================================== + +ItemViewSettings::ItemViewSettings(const QString &group) : ClientSettings(group) { -BufferSettings::BufferSettings(BufferId bufferId) - : CoreAccountSettings(QString("Buffers/%1").arg(bufferId.toInt())) -{ } -void BufferSettings::setLastSeen(QDateTime seenDate) { - setAccountValue("LastSeen", seenDate); +bool ItemViewSettings::displayTopicInTooltip() { + return localValue("DisplayTopicInTooltip", false).toBool(); } -QDateTime BufferSettings::lastSeen() { - return accountValue("LastSeen", QDateTime()).value(); +bool ItemViewSettings::mouseWheelChangesBuffer() { + return localValue("MouseWheelChangesBuffer", false).toBool(); }