X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclientsettings.cpp;h=3a50c0f87033722a54cb7c6b668ddf5e46a6e7cd;hp=1fd1efbec2f77bdfb6f6281874a0314a00ff1807;hb=b33f7f5cd3f706c27e2822c39606887ce8ade348;hpb=28e33cd3255a838a045303bed073f4f9c40a3af4 diff --git a/src/client/clientsettings.cpp b/src/client/clientsettings.cpp index 1fd1efbe..3a50c0f8 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,170 @@ * 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().toInt()).arg(_subgroup).arg(key), receiver, slot); +} +QList CoreAccountSettings::knownAccounts() { + QList ids; + foreach(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) { + setLocalValue(QString("%1/Connection").arg(id.toInt()), data); } -void CoreAccountSettings::setAutoConnectAccount(const QString &account) { - setLocalValue("AutoConnectAccount", account); +QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) { + return localValue(QString("%1/Connection").arg(id.toInt()), QVariant()).toMap(); } -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().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().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++; } + setLocalValue("JumpKeyMap", variants); } -QHash CoreAccountSettings::retrieveAllAccounts() { - QHash accounts; - foreach(QString name, knownAccounts()) { - accounts[name] = retrieveAccount(name); +QHash CoreAccountSettings::jumpKeyMap() { + QHash keyMap; + QVariantMap variants = localValue("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(const QString &account) { - removeLocalKey(QString("Accounts/%1").arg(account)); +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(); +} + + +// ======================================== +// 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