Prevent ChatView from scrolling up 1px on buffer switch, fixes #544
[quassel.git] / src / client / clientsettings.cpp
index 87ad816..3a50c0f 100644 (file)
@@ -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  *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#include "client.h"
+#include <QStringList>
+
+
 #include "clientsettings.h"
-#include "global.h"
 
-#include <QStringList>
+#include <QHostAddress>
+#ifdef HAVE_SSL
+#include <QSslSocket>
+#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(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().toInt()).arg(_subgroup).arg(key), receiver, slot);
 }
 
 QList<AccountId> CoreAccountSettings::knownAccounts() {
   QList<AccountId> ids;
   foreach(QString key, localChildGroups()) {
-    ids << key.toInt();
+    AccountId acc = key.toInt();
+    if(acc.isValid()) ids << acc;
   }
   return ids;
 }
@@ -83,8 +93,95 @@ QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &d
   return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().toInt()).arg(_subgroup).arg(key), def);
 }
 
+void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap) {
+  QVariantMap variants;
+  QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin();
+  while(mapIter != keyMap.constEnd()) {
+    variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value());
+    mapIter++;
+  }
+  setLocalValue("JumpKeyMap", variants);
+}
+
+QHash<int, BufferId> CoreAccountSettings::jumpKeyMap() {
+  QHash<int, BufferId> keyMap;
+  QVariantMap variants = localValue("JumpKeyMap", QVariant()).toMap();
+  QVariantMap::const_iterator mapIter = variants.constBegin();
+  while(mapIter != variants.constEnd()) {
+    keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>();
+    mapIter++;
+  }
+  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();
+}
+
+
+// ========================================
+//  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