X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclientsettings.cpp;h=6f9961f6528eacc333b558add3d1dd9cea47dc1d;hp=1fd1efbec2f77bdfb6f6281874a0314a00ff1807;hb=fa00b68a21c777682d9feb37ade6b3904fc19d92;hpb=28e33cd3255a838a045303bed073f4f9c40a3af4 diff --git a/src/client/clientsettings.cpp b/src/client/clientsettings.cpp index 1fd1efbe..6f9961f6 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,74 +18,262 @@ * 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() { - - } /***********************************************************************************************/ -CoreAccountSettings::CoreAccountSettings() : ClientSettings("CoreAccounts") { +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(const QString &key, localChildGroups()) { + AccountId acc = key.toInt(); + if(acc.isValid()) + ids << acc; + } + return ids; +} +AccountId CoreAccountSettings::lastAccount() { + return localValue("LastAccount", 0).toInt(); } -QStringList CoreAccountSettings::knownAccounts() { - return localChildKeys("Accounts"); +void CoreAccountSettings::setLastAccount(AccountId account) { + setLocalValue("LastAccount", account.toInt()); } -QString CoreAccountSettings::lastAccount() { - return localValue("LastAccount", "").toString(); +AccountId CoreAccountSettings::autoConnectAccount() { + return localValue("AutoConnectAccount", 0).toInt(); } -void CoreAccountSettings::setLastAccount(const QString &account) { - setLocalValue("LastAccount", account); +void CoreAccountSettings::setAutoConnectAccount(AccountId account) { + setLocalValue("AutoConnectAccount", account.toInt()); } -QString CoreAccountSettings::autoConnectAccount() { - return localValue("AutoConnectAccount", "").toString(); +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::setAutoConnectAccount(const QString &account) { - setLocalValue("AutoConnectAccount", account); +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["AccountId"] = id.toInt(); + map["Uuid"] = QUuid::createUuid().toString(); + } + + return map; } -void CoreAccountSettings::storeAccount(const QString name, const QVariantMap &data) { - setLocalValue(QString("Accounts/%2").arg(name), data); +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); } -QVariantMap CoreAccountSettings::retrieveAccount(const QString &name) { - return localValue(QString("Accounts/%2").arg(name), QVariant()).toMap(); +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::storeAllAccounts(const QHash accounts) { - removeLocalKey(QString("Accounts")); - foreach(QString name, accounts.keys()) { - storeAccount(name, accounts[name]); +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::retrieveAllAccounts() { - QHash accounts; - foreach(QString name, knownAccounts()) { - accounts[name] = retrieveAccount(name); +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 accounts; + return keyMap; +} + +void CoreAccountSettings::removeAccount(AccountId id) { + removeLocalKey(QString("%1").arg(id.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(); } -void CoreAccountSettings::removeAccount(const QString &account) { - removeLocalKey(QString("Accounts/%1").arg(account)); + +// ======================================== +// KnownHostsSettings +// ======================================== +KnownHostsSettings::KnownHostsSettings() + : ClientSettings("KnownHosts") +{ +} + +QByteArray KnownHostsSettings::knownDigest(const QHostAddress &address) { + return localValue(address.toString(), QByteArray()).toByteArray(); +} + +void KnownHostsSettings::saveKnownHost(const QHostAddress &address, const QByteArray &certDigest) { + setLocalValue(address.toString(), certDigest); +} + +bool KnownHostsSettings::isKnownHost(const QHostAddress &address, const QByteArray &certDigest) { + return certDigest == localValue(address.toString(), QByteArray()).toByteArray(); +} + +#ifdef HAVE_SSL +QByteArray KnownHostsSettings::knownDigest(const QSslSocket *socket) { + return knownDigest(socket->peerAddress()); +} + +void KnownHostsSettings::saveKnownHost(const QSslSocket *socket) { + Q_ASSERT(socket); + saveKnownHost(socket->peerAddress(), socket->peerCertificate().digest()); +} + +bool KnownHostsSettings::isKnownHost(const QSslSocket *socket) { + Q_ASSERT(socket); + return isKnownHost(socket->peerAddress(), socket->peerCertificate().digest()); +} +#endif + + +// ======================================== +// TabCompletionSettings +// ======================================== + +TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion") { } +void TabCompletionSettings::setCompletionSuffix(const QString &suffix) { + setLocalValue("CompletionSuffix", suffix); +} + +QString TabCompletionSettings::completionSuffix() { + return localValue("CompletionSuffix", ": ").toString(); +} +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) { + +} + +bool ItemViewSettings::displayTopicInTooltip() { + return localValue("DisplayTopicInTooltip", false).toBool(); +} + +bool ItemViewSettings::mouseWheelChangesBuffer() { + return localValue("MouseWheelChangesBuffer", false).toBool(); +}