migrating identities from QSettings to the storage backend
authorMarcus Eggenberger <egs@quassel-irc.org>
Thu, 25 Dec 2008 15:01:35 +0000 (16:01 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Thu, 25 Dec 2008 23:03:50 +0000 (00:03 +0100)
89 files changed:
src/common/identity.cpp
src/common/identity.h
src/core/SQL/SQLite/11/setup_080_ircservers.sql [deleted file]
src/core/SQL/SQLite/12/delete_backlog_by_uid.sql [moved from src/core/SQL/SQLite/11/delete_backlog_by_uid.sql with 100% similarity]
src/core/SQL/SQLite/12/delete_backlog_for_buffer.sql [moved from src/core/SQL/SQLite/11/delete_backlog_for_buffer.sql with 100% similarity]
src/core/SQL/SQLite/12/delete_backlog_for_network.sql [moved from src/core/SQL/SQLite/11/delete_backlog_for_network.sql with 100% similarity]
src/core/SQL/SQLite/12/delete_buffer_for_bufferid.sql [moved from src/core/SQL/SQLite/11/delete_buffer_for_bufferid.sql with 100% similarity]
src/core/SQL/SQLite/12/delete_buffers_by_uid.sql [moved from src/core/SQL/SQLite/11/delete_buffers_by_uid.sql with 100% similarity]
src/core/SQL/SQLite/12/delete_buffers_for_network.sql [moved from src/core/SQL/SQLite/11/delete_buffers_for_network.sql with 100% similarity]
src/core/SQL/SQLite/12/delete_identity.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/delete_ircservers_for_network.sql [moved from src/core/SQL/SQLite/11/delete_ircservers_for_network.sql with 100% similarity]
src/core/SQL/SQLite/12/delete_network.sql [moved from src/core/SQL/SQLite/11/delete_network.sql with 100% similarity]
src/core/SQL/SQLite/12/delete_networks_by_uid.sql [moved from src/core/SQL/SQLite/11/delete_networks_by_uid.sql with 100% similarity]
src/core/SQL/SQLite/12/delete_nicks.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/delete_quasseluser.sql [moved from src/core/SQL/SQLite/11/delete_quasseluser.sql with 100% similarity]
src/core/SQL/SQLite/12/insert_buffer.sql [moved from src/core/SQL/SQLite/11/insert_buffer.sql with 100% similarity]
src/core/SQL/SQLite/12/insert_identity.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/insert_message.sql [moved from src/core/SQL/SQLite/11/insert_message.sql with 100% similarity]
src/core/SQL/SQLite/12/insert_network.sql [moved from src/core/SQL/SQLite/11/insert_network.sql with 100% similarity]
src/core/SQL/SQLite/12/insert_nick.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/insert_quasseluser.sql [moved from src/core/SQL/SQLite/11/insert_quasseluser.sql with 100% similarity]
src/core/SQL/SQLite/12/insert_sender.sql [moved from src/core/SQL/SQLite/11/insert_sender.sql with 100% similarity]
src/core/SQL/SQLite/12/insert_server.sql [moved from src/core/SQL/SQLite/11/insert_server.sql with 100% similarity]
src/core/SQL/SQLite/12/insert_user_setting.sql [moved from src/core/SQL/SQLite/11/insert_user_setting.sql with 100% similarity]
src/core/SQL/SQLite/12/select_authuser.sql [moved from src/core/SQL/SQLite/11/select_authuser.sql with 100% similarity]
src/core/SQL/SQLite/12/select_bufferByName.sql [moved from src/core/SQL/SQLite/11/select_bufferByName.sql with 100% similarity]
src/core/SQL/SQLite/12/select_bufferExists.sql [moved from src/core/SQL/SQLite/11/select_bufferExists.sql with 100% similarity]
src/core/SQL/SQLite/12/select_buffer_by_id.sql [moved from src/core/SQL/SQLite/11/select_buffer_by_id.sql with 100% similarity]
src/core/SQL/SQLite/12/select_buffer_lastseen_messages.sql [moved from src/core/SQL/SQLite/11/select_buffer_lastseen_messages.sql with 100% similarity]
src/core/SQL/SQLite/12/select_buffers.sql [moved from src/core/SQL/SQLite/11/select_buffers.sql with 100% similarity]
src/core/SQL/SQLite/12/select_buffers_for_network.sql [moved from src/core/SQL/SQLite/11/select_buffers_for_network.sql with 100% similarity]
src/core/SQL/SQLite/12/select_checkidentity.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/select_connected_networks.sql [moved from src/core/SQL/SQLite/11/select_connected_networks.sql with 100% similarity]
src/core/SQL/SQLite/12/select_identities.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/select_internaluser.sql [moved from src/core/SQL/SQLite/11/select_internaluser.sql with 100% similarity]
src/core/SQL/SQLite/12/select_messages.sql [moved from src/core/SQL/SQLite/11/select_messages.sql with 100% similarity]
src/core/SQL/SQLite/12/select_messagesAll.sql [moved from src/core/SQL/SQLite/11/select_messagesAll.sql with 100% similarity]
src/core/SQL/SQLite/12/select_messagesAllNew.sql [moved from src/core/SQL/SQLite/11/select_messagesAllNew.sql with 100% similarity]
src/core/SQL/SQLite/12/select_messagesNew.sql [moved from src/core/SQL/SQLite/11/select_messagesNew.sql with 100% similarity]
src/core/SQL/SQLite/12/select_networkExists.sql [moved from src/core/SQL/SQLite/11/select_networkExists.sql with 100% similarity]
src/core/SQL/SQLite/12/select_networks_for_user.sql [moved from src/core/SQL/SQLite/11/select_networks_for_user.sql with 100% similarity]
src/core/SQL/SQLite/12/select_nicks.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/select_persistent_channels.sql [moved from src/core/SQL/SQLite/11/select_persistent_channels.sql with 100% similarity]
src/core/SQL/SQLite/12/select_servers_for_network.sql [moved from src/core/SQL/SQLite/11/select_servers_for_network.sql with 100% similarity]
src/core/SQL/SQLite/12/select_user_setting.sql [moved from src/core/SQL/SQLite/11/select_user_setting.sql with 100% similarity]
src/core/SQL/SQLite/12/select_userid.sql [moved from src/core/SQL/SQLite/11/select_userid.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_000_quasseluser.sql [moved from src/core/SQL/SQLite/11/setup_000_quasseluser.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_010_sender.sql [moved from src/core/SQL/SQLite/11/setup_010_sender.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_020_network.sql [moved from src/core/SQL/SQLite/11/setup_020_network.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_030_buffer.sql [moved from src/core/SQL/SQLite/11/setup_030_buffer.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_040_buffer_idx.sql [moved from src/core/SQL/SQLite/11/setup_040_buffer_idx.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_050_buffer_cname_idx.sql [moved from src/core/SQL/SQLite/11/setup_050_buffer_cname_idx.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_060_backlog.sql [moved from src/core/SQL/SQLite/11/setup_060_backlog.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_070_coreinfo.sql [moved from src/core/SQL/SQLite/11/setup_070_coreinfo.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_080_ircservers.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/setup_090_create_backlog_idx.sql [moved from src/core/SQL/SQLite/11/setup_090_create_backlog_idx.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_100_create_backlog_idx2.sql [moved from src/core/SQL/SQLite/11/setup_100_create_backlog_idx2.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_110_create_buffer_idx.sql [moved from src/core/SQL/SQLite/11/setup_110_create_buffer_idx.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_120_create_user_setting.sql [moved from src/core/SQL/SQLite/11/setup_120_create_user_setting.sql with 100% similarity]
src/core/SQL/SQLite/12/setup_130_identity.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/setup_140_identity_nick.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/setup_999_version.sql [moved from src/core/SQL/SQLite/11/setup_999_version.sql with 100% similarity]
src/core/SQL/SQLite/12/update_buffer_lastseen.sql [moved from src/core/SQL/SQLite/11/update_buffer_lastseen.sql with 100% similarity]
src/core/SQL/SQLite/12/update_buffer_name.sql [moved from src/core/SQL/SQLite/11/update_buffer_name.sql with 100% similarity]
src/core/SQL/SQLite/12/update_buffer_persistent_channel.sql [moved from src/core/SQL/SQLite/11/update_buffer_persistent_channel.sql with 100% similarity]
src/core/SQL/SQLite/12/update_buffer_set_channel_key.sql [moved from src/core/SQL/SQLite/11/update_buffer_set_channel_key.sql with 100% similarity]
src/core/SQL/SQLite/12/update_identity.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/update_network.sql [moved from src/core/SQL/SQLite/11/update_network.sql with 100% similarity]
src/core/SQL/SQLite/12/update_network_connected.sql [moved from src/core/SQL/SQLite/11/update_network_connected.sql with 100% similarity]
src/core/SQL/SQLite/12/update_user_setting.sql [moved from src/core/SQL/SQLite/11/update_user_setting.sql with 100% similarity]
src/core/SQL/SQLite/12/update_username.sql [moved from src/core/SQL/SQLite/11/update_username.sql with 100% similarity]
src/core/SQL/SQLite/12/update_userpassword.sql [moved from src/core/SQL/SQLite/11/update_userpassword.sql with 100% similarity]
src/core/SQL/SQLite/12/upgrade_000_create_identity.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/upgrade_010_create_identity_nick.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/upgrade_020_rename_servertable.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/upgrade_030_create_ircserver.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/upgrade_040_copy_ircserver.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/upgrade_050_drop_ircserverold.sql [new file with mode: 0644]
src/core/SQL/SQLite/12/upgrade_999_version.sql [new file with mode: 0644]
src/core/core.h
src/core/coreidentity.cpp
src/core/coreidentity.h
src/core/coresession.cpp
src/core/coresession.h
src/core/sql.qrc
src/core/sqlitestorage.cpp
src/core/sqlitestorage.h
src/core/storage.h
src/qtui/settingspages/identitiessettingspage.cpp

index da10fb0..aee2e4a 100644 (file)
@@ -185,8 +185,8 @@ void Identity::setQuitReason(const QString &reason) {
 /***  ***/
 
 void Identity::update(const Identity &other) {
 /***  ***/
 
 void Identity::update(const Identity &other) {
-for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(); idx++) {
-    QMetaProperty metaProp = metaObject()->property(idx);
+  for(int idx = staticMetaObject.propertyOffset(); idx < staticMetaObject.propertyCount(); idx++) {
+    QMetaProperty metaProp = staticMetaObject.property(idx);
     Q_ASSERT(metaProp.isValid());
     if(this->property(metaProp.name()) != other.property(metaProp.name())) {
       setProperty(metaProp.name(), other.property(metaProp.name()));
     Q_ASSERT(metaProp.isValid());
     if(this->property(metaProp.name()) != other.property(metaProp.name())) {
       setProperty(metaProp.name(), other.property(metaProp.name()));
@@ -194,9 +194,9 @@ for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(
   }
 }
 
   }
 }
 
-bool Identity::operator==(const Identity &other) {
-  for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(); idx++) {
-    QMetaProperty metaProp = metaObject()->property(idx);
+bool Identity::operator==(const Identity &other) const {
+  for(int idx = staticMetaObject.propertyOffset(); idx < staticMetaObject.propertyCount(); idx++) {
+    QMetaProperty metaProp = staticMetaObject.property(idx);
     Q_ASSERT(metaProp.isValid());
     QVariant v1 = this->property(metaProp.name());
     QVariant v2 = other.property(metaProp.name()); // qDebug() << v1 << v2;
     Q_ASSERT(metaProp.isValid());
     QVariant v1 = this->property(metaProp.name());
     QVariant v2 = other.property(metaProp.name()); // qDebug() << v1 << v2;
@@ -210,7 +210,7 @@ bool Identity::operator==(const Identity &other) {
   return true;
 }
 
   return true;
 }
 
-bool Identity::operator!=(const Identity &other) {
+bool Identity::operator!=(const Identity &other) const {
   return !(*this == other);
 }
 
   return !(*this == other);
 }
 
index a71e0ee..829094a 100644 (file)
@@ -60,8 +60,8 @@ public:
 
   void setToDefaults();
 
 
   void setToDefaults();
 
-  bool operator==(const Identity &other);
-  bool operator!=(const Identity &other);
+  bool operator==(const Identity &other) const;
+  bool operator!=(const Identity &other) const;
 
   inline bool isValid() const { return id().isValid(); }
 
 
   inline bool isValid() const { return id().isValid(); }
 
diff --git a/src/core/SQL/SQLite/11/setup_080_ircservers.sql b/src/core/SQL/SQLite/11/setup_080_ircservers.sql
deleted file mode 100644 (file)
index 89a1698..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-CREATE TABLE ircserver (
-    serverid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
-    userid INTEGER NOT NULL,
-    networkid INTEGER NOT NULL,
-    hostname TEXT NOT NULL,
-    port INTEGER NOT NULL DEFAULT 6667,
-    password TEXT,
-    ssl INTEGER NOT NULL DEFAULT 0
-)
diff --git a/src/core/SQL/SQLite/12/delete_identity.sql b/src/core/SQL/SQLite/12/delete_identity.sql
new file mode 100644 (file)
index 0000000..7d25c0e
--- /dev/null
@@ -0,0 +1,2 @@
+DELETE FROM identity
+WHERE identityid = :identityid AND userid = :userid
diff --git a/src/core/SQL/SQLite/12/delete_nicks.sql b/src/core/SQL/SQLite/12/delete_nicks.sql
new file mode 100644 (file)
index 0000000..8018d63
--- /dev/null
@@ -0,0 +1,2 @@
+DELETE FROM identity_nick
+WHERE userid = :userid
diff --git a/src/core/SQL/SQLite/12/insert_identity.sql b/src/core/SQL/SQLite/12/insert_identity.sql
new file mode 100644 (file)
index 0000000..06b4723
--- /dev/null
@@ -0,0 +1,2 @@
+INSERT INTO identity (userid, identityname, realname, awaynick, awaynickenabled, awayreason, awayreasonenabled, autoawayenabled, autoawaytime, autoawayreason, autoawayreasonenabled, detachawayenabled, detachawayreason, detachawayreasonenabled, ident, kickreason, partreason, quitreason, sslcert, sslkey)
+VALUES (:userid, :identityname, :realname, :awaynick, :awaynickenabled, :awayreason, :awayreasonenabled, :autoawayenabled, :autoawaytime, :autoawayreason, :autoawayreasonenabled, :detachawayenabled, :detachawayreason, :detachawayreasonenabled, :ident, :kickreason, :partreason, :quitreason, :sslcert, :sslkey)
diff --git a/src/core/SQL/SQLite/12/insert_nick.sql b/src/core/SQL/SQLite/12/insert_nick.sql
new file mode 100644 (file)
index 0000000..331da3c
--- /dev/null
@@ -0,0 +1,2 @@
+INSERT INTO identity_nick (identityid, nick)
+VALUES (:identityid, :nick)
diff --git a/src/core/SQL/SQLite/12/select_checkidentity.sql b/src/core/SQL/SQLite/12/select_checkidentity.sql
new file mode 100644 (file)
index 0000000..8254f03
--- /dev/null
@@ -0,0 +1,3 @@
+SELECT count(*)
+FROM identity
+WHERE identityid = :identityid AND userid = :userid
diff --git a/src/core/SQL/SQLite/12/select_identities.sql b/src/core/SQL/SQLite/12/select_identities.sql
new file mode 100644 (file)
index 0000000..cb7a883
--- /dev/null
@@ -0,0 +1,6 @@
+SELECT identityid, identityname, realname, awaynick, awaynickenabled,
+       awayreason, awayreasonenabled, autoawayenabled, autoawaytime, autoawayreason, autoawayreasonenabled,
+       detachawayenabled, detachawayreason, detachawayreasonenabled, ident, kickreason, partreason, quitreason,
+       sslcert, sslkey
+FROM identity
+WHERE userid = :userid
diff --git a/src/core/SQL/SQLite/12/select_nicks.sql b/src/core/SQL/SQLite/12/select_nicks.sql
new file mode 100644 (file)
index 0000000..41dc6e4
--- /dev/null
@@ -0,0 +1,4 @@
+SELECT nick
+FROM identity_nick
+WHERE identityid = :identityid
+ORDER BY nickid ASC
diff --git a/src/core/SQL/SQLite/12/setup_080_ircservers.sql b/src/core/SQL/SQLite/12/setup_080_ircservers.sql
new file mode 100644 (file)
index 0000000..6873726
--- /dev/null
@@ -0,0 +1,16 @@
+CREATE TABLE ircserver (
+    serverid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+    userid INTEGER NOT NULL,
+    networkid INTEGER NOT NULL,
+    hostname TEXT NOT NULL,
+    port INTEGER NOT NULL DEFAULT 6667,
+    password TEXT,
+    ssl INTEGER NOT NULL DEFAULT 0, -- bool
+    sslVersion INTEGER NOT NULL DEFAULT 0,
+    useproxy INTEGER NOT NULL DEFAULT 0, -- bool
+    proxytype INTEGER NOT NULL DEFAULT 0,
+    proxyhost TEXT NOT NULL DEFAULT 'localhost',
+    proxyport INTEGER NOT NULL DEFAULT 8080,
+    proxyuser TEXT,
+    proxypass TEXT
+)
diff --git a/src/core/SQL/SQLite/12/setup_130_identity.sql b/src/core/SQL/SQLite/12/setup_130_identity.sql
new file mode 100644 (file)
index 0000000..277c34e
--- /dev/null
@@ -0,0 +1,24 @@
+CREATE TABLE identity (
+       identityid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+       userid INTEGER NOT NULL,
+       identityname TEXT NOT NULL,
+       realname TEXT NOT NULL,
+       awaynick TEXT,
+       awaynickenabled INTEGER NOT NULL DEFAULT 0, -- BOOL
+       awayreason TEXT,
+       awayreasonenabled INTEGER NOT NULL DEFAULT 0, -- BOOL
+       autoawayenabled INTEGER NOT NULL DEFAULT 0, -- BOOL
+       autoawaytime INTEGER NOT NULL,
+       autoawayreason TEXT,
+       autoawayreasonenabled INTEGER NOT NULL DEFAULT 0, -- BOOL
+       detachawayenabled INTEGER NOT NULL DEFAULT 0, -- BOOL
+       detachawayreason TEXT,
+       detachawayreasonenabled INTEGER NOT NULL DEFAULT 0, -- BOOL       
+       ident TEXT,
+       kickreason TEXT,
+       partreason TEXT,
+       quitreason TEXT,
+       sslcert BLOB,
+       sslkey BLOB,
+       UNIQUE (userid, identityname)
+)
diff --git a/src/core/SQL/SQLite/12/setup_140_identity_nick.sql b/src/core/SQL/SQLite/12/setup_140_identity_nick.sql
new file mode 100644 (file)
index 0000000..ea30a8a
--- /dev/null
@@ -0,0 +1,6 @@
+CREATE TABLE identity_nick (
+       nickid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+       identityid INTEGER NOT NULL,
+       nick TEXT NOT NULL,
+       UNIQUE (identityid, nick)
+)
diff --git a/src/core/SQL/SQLite/12/update_identity.sql b/src/core/SQL/SQLite/12/update_identity.sql
new file mode 100644 (file)
index 0000000..1087e59
--- /dev/null
@@ -0,0 +1,21 @@
+UPDATE identity
+SET    identityname = :identityname,
+       relname = :realname,
+       awaynick = :awaynick,
+       awaynickenabled = :awaynickenabled,
+       awayreason = :awayreason,
+       awayreasonenabled = :awayreasonenabled,
+       autoawayenabled = :autoawayenabled,
+       autoawaytime = :autoawaytime,
+       autoawayreason = :autoawayreason,
+       autoawayreasonenabled = :autoawayreasonenabled,
+       detachawayenabled = :detachawayenabled,
+       detachawayreason = :detachawayreason,
+       detachawayreasonenabled = :detachawayreasonenabled,
+       ident = :ident,
+       kickreason = :kickreason,
+       partreason = :partreason,
+       quitreason = :quitreason,
+       sslcert = :sslcert,
+       sslkey = :sslkey
+WHERE  identityid = :identityid
diff --git a/src/core/SQL/SQLite/12/upgrade_000_create_identity.sql b/src/core/SQL/SQLite/12/upgrade_000_create_identity.sql
new file mode 100644 (file)
index 0000000..277c34e
--- /dev/null
@@ -0,0 +1,24 @@
+CREATE TABLE identity (
+       identityid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+       userid INTEGER NOT NULL,
+       identityname TEXT NOT NULL,
+       realname TEXT NOT NULL,
+       awaynick TEXT,
+       awaynickenabled INTEGER NOT NULL DEFAULT 0, -- BOOL
+       awayreason TEXT,
+       awayreasonenabled INTEGER NOT NULL DEFAULT 0, -- BOOL
+       autoawayenabled INTEGER NOT NULL DEFAULT 0, -- BOOL
+       autoawaytime INTEGER NOT NULL,
+       autoawayreason TEXT,
+       autoawayreasonenabled INTEGER NOT NULL DEFAULT 0, -- BOOL
+       detachawayenabled INTEGER NOT NULL DEFAULT 0, -- BOOL
+       detachawayreason TEXT,
+       detachawayreasonenabled INTEGER NOT NULL DEFAULT 0, -- BOOL       
+       ident TEXT,
+       kickreason TEXT,
+       partreason TEXT,
+       quitreason TEXT,
+       sslcert BLOB,
+       sslkey BLOB,
+       UNIQUE (userid, identityname)
+)
diff --git a/src/core/SQL/SQLite/12/upgrade_010_create_identity_nick.sql b/src/core/SQL/SQLite/12/upgrade_010_create_identity_nick.sql
new file mode 100644 (file)
index 0000000..ea30a8a
--- /dev/null
@@ -0,0 +1,6 @@
+CREATE TABLE identity_nick (
+       nickid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+       identityid INTEGER NOT NULL,
+       nick TEXT NOT NULL,
+       UNIQUE (identityid, nick)
+)
diff --git a/src/core/SQL/SQLite/12/upgrade_020_rename_servertable.sql b/src/core/SQL/SQLite/12/upgrade_020_rename_servertable.sql
new file mode 100644 (file)
index 0000000..1d3ff64
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE ircserver RENAME TO ircserverold
diff --git a/src/core/SQL/SQLite/12/upgrade_030_create_ircserver.sql b/src/core/SQL/SQLite/12/upgrade_030_create_ircserver.sql
new file mode 100644 (file)
index 0000000..6873726
--- /dev/null
@@ -0,0 +1,16 @@
+CREATE TABLE ircserver (
+    serverid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+    userid INTEGER NOT NULL,
+    networkid INTEGER NOT NULL,
+    hostname TEXT NOT NULL,
+    port INTEGER NOT NULL DEFAULT 6667,
+    password TEXT,
+    ssl INTEGER NOT NULL DEFAULT 0, -- bool
+    sslVersion INTEGER NOT NULL DEFAULT 0,
+    useproxy INTEGER NOT NULL DEFAULT 0, -- bool
+    proxytype INTEGER NOT NULL DEFAULT 0,
+    proxyhost TEXT NOT NULL DEFAULT 'localhost',
+    proxyport INTEGER NOT NULL DEFAULT 8080,
+    proxyuser TEXT,
+    proxypass TEXT
+)
diff --git a/src/core/SQL/SQLite/12/upgrade_040_copy_ircserver.sql b/src/core/SQL/SQLite/12/upgrade_040_copy_ircserver.sql
new file mode 100644 (file)
index 0000000..5da418b
--- /dev/null
@@ -0,0 +1,2 @@
+INSERT INTO ircserver (serverid, userid, networkid, hostname, port, password, ssl)
+SELECT serverid, userid, networkid, hostname, port, password, ssl FROM ircserverold
diff --git a/src/core/SQL/SQLite/12/upgrade_050_drop_ircserverold.sql b/src/core/SQL/SQLite/12/upgrade_050_drop_ircserverold.sql
new file mode 100644 (file)
index 0000000..9235cea
--- /dev/null
@@ -0,0 +1 @@
+DROP TABLE ircserverold
diff --git a/src/core/SQL/SQLite/12/upgrade_999_version.sql b/src/core/SQL/SQLite/12/upgrade_999_version.sql
new file mode 100644 (file)
index 0000000..ac97fef
--- /dev/null
@@ -0,0 +1,3 @@
+UPDATE coreinfo
+SET value = 12
+WHERE key = 'schemaversion'
index 083bf8c..0c6e88d 100644 (file)
@@ -79,6 +79,19 @@ class Core : public QObject {
     return instance()->storage->getUserSetting(userId, settingName, data);
   }
 
     return instance()->storage->getUserSetting(userId, settingName, data);
   }
 
+  /* Identity handling */
+  static inline IdentityId createIdentity(UserId user, CoreIdentity &identity) {
+    return instance()->storage->createIdentity(user, identity);
+  }
+  static bool updateIdentity(UserId user, const CoreIdentity &identity) {
+    return instance()->storage->updateIdentity(user, identity);
+  }
+  static void removeIdentity(UserId user, IdentityId identityId) {
+    instance()->storage->removeIdentity(user, identityId);
+  }
+  static QList<CoreIdentity> identities(UserId user) {
+    return instance()->storage->identities(user);
+  }
 
   //! Create a Network in the Storage and store it's Id in the given NetworkInfo
   /** \note This method is thredsafe.
 
   //! Create a Network in the Storage and store it's Id in the given NetworkInfo
   /** \note This method is thredsafe.
index dfad2e9..6fe0e97 100644 (file)
 
 #include "coreidentity.h"
 
 
 #include "coreidentity.h"
 
-#include "coresession.h"
-#include "coreusersettings.h"
 #include "signalproxy.h"
 
 #include "signalproxy.h"
 
-CoreIdentity::CoreIdentity(IdentityId id, SignalProxy *proxy, CoreSession *parent)
+CoreIdentity::CoreIdentity(IdentityId id, QObject *parent)
   : Identity(id, parent),
   : Identity(id, parent),
-    _certManager(new CoreCertManager(this)),
-    _coreSession(parent)
+    _certManager(*this)
 {
 {
-  proxy->synchronize(_certManager);
-  connect(this, SIGNAL(idSet(IdentityId)), _certManager, SLOT(setId(IdentityId)));
+  connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId)));
 }
 
 }
 
-CoreIdentity::CoreIdentity(const Identity &other, SignalProxy *proxy, CoreSession *parent)
+CoreIdentity::CoreIdentity(const Identity &other, QObject *parent)
   : Identity(other, parent),
   : Identity(other, parent),
-    _certManager(new CoreCertManager(this)),
-    _coreSession(parent)
+    _certManager(*this)
 {
 {
-  proxy->synchronize(_certManager);
-  connect(this, SIGNAL(idSet(IdentityId)), _certManager, SLOT(setId(IdentityId)));
+  connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId)));
 }
 
 }
 
-void CoreIdentity::update(const QVariantMap &properties) {
-  SyncableObject::update(properties);
-  save();
+CoreIdentity::CoreIdentity(const CoreIdentity &other, QObject *parent)
+  : Identity(other, parent),
+    _sslKey(other._sslKey),
+    _sslCert(other._sslCert),
+    _certManager(*this)
+{
+  connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId)));
 }
 
 }
 
-void CoreIdentity::save() {
-  CoreUserSettings s(_coreSession->user());
-  s.storeIdentity(*this);
+void CoreIdentity::synchronize(SignalProxy *proxy) {
+  proxy->synchronize(this);
+  proxy->synchronize(&_certManager);
 }
 
 void CoreIdentity::setSslKey(const QByteArray &encoded) {
 }
 
 void CoreIdentity::setSslKey(const QByteArray &encoded) {
@@ -63,24 +61,30 @@ void CoreIdentity::setSslCert(const QByteArray &encoded) {
   setSslCert(QSslCertificate(encoded));
 }
 
   setSslCert(QSslCertificate(encoded));
 }
 
+CoreIdentity &CoreIdentity::operator=(const CoreIdentity &identity) {
+  Identity::operator=(identity);
+  _sslKey = identity._sslKey;
+  _sslCert = identity._sslCert;
+  return *this;
+}
 
 // ========================================
 //  CoreCertManager
 // ========================================
 
 // ========================================
 //  CoreCertManager
 // ========================================
-CoreCertManager::CoreCertManager(CoreIdentity *identity)
-  : CertManager(identity->id(), identity),
-    _identity(identity)
+CoreCertManager::CoreCertManager(CoreIdentity &identity)
+  : CertManager(identity.id()),
+    identity(identity)
 {
   setAllowClientUpdates(true);
 }
 
 void CoreCertManager::setSslKey(const QByteArray &encoded) {
 {
   setAllowClientUpdates(true);
 }
 
 void CoreCertManager::setSslKey(const QByteArray &encoded) {
-  identity()->setSslKey(encoded);
+  identity.setSslKey(encoded);
   CertManager::setSslKey(encoded);
 }
 
 void CoreCertManager::setSslCert(const QByteArray &encoded) {
   CertManager::setSslKey(encoded);
 }
 
 void CoreCertManager::setSslCert(const QByteArray &encoded) {
-  identity()->setSslCert(encoded);
+  identity.setSslCert(encoded);
   CertManager::setSslCert(encoded);
 }
 
   CertManager::setSslCert(encoded);
 }
 
index f22ea44..f87f531 100644 (file)
 #include <QSslKey>
 #include <QSslCertificate>
 
 #include <QSslKey>
 #include <QSslCertificate>
 
-class CoreCertManager;
-class CoreSession;
+class CoreIdentity;
 class SignalProxy;
 
 class SignalProxy;
 
+// ========================================
+//  CoreCertManager
+// ========================================
+class CoreCertManager : public CertManager {
+  Q_OBJECT
+
+public:
+  CoreCertManager(CoreIdentity &identity);
+
+  virtual const QSslKey &sslKey() const;
+  virtual const QSslCertificate &sslCert() const;
+
+public slots:
+  virtual void setSslKey(const QByteArray &encoded);
+  virtual void setSslCert(const QByteArray &encoded);
+
+  void setId(IdentityId id);
+
+private:
+  CoreIdentity &identity;
+};
+
+// =========================================
+//  CoreIdentity
+// =========================================
 class CoreIdentity : public Identity {
   Q_OBJECT
 
 public:
 class CoreIdentity : public Identity {
   Q_OBJECT
 
 public:
-  CoreIdentity(IdentityId id, SignalProxy *proxy, CoreSession *parent);
-  CoreIdentity(const Identity &other, SignalProxy *proxy, CoreSession *parent);
+  CoreIdentity(IdentityId id, QObject *parent = 0);
+  CoreIdentity(const Identity &other, QObject *parent = 0);
+  CoreIdentity(const CoreIdentity &other, QObject *parent = 0);
+
+  void synchronize(SignalProxy *proxy);
 
   inline const QSslKey &sslKey() const { return _sslKey; }
   inline void setSslKey(const QSslKey &key) { _sslKey = key; }
 
   inline const QSslKey &sslKey() const { return _sslKey; }
   inline void setSslKey(const QSslKey &key) { _sslKey = key; }
@@ -44,40 +71,22 @@ public:
   inline void setSslCert(const QSslCertificate &cert) { _sslCert = cert; }
   void setSslCert(const QByteArray &encoded);
 
   inline void setSslCert(const QSslCertificate &cert) { _sslCert = cert; }
   void setSslCert(const QByteArray &encoded);
 
-public slots:
-  virtual void update(const QVariantMap &properties);
-  void save();
+  CoreIdentity& CoreIdentity::operator=(const CoreIdentity &identity);
 
 private:
   QSslKey _sslKey;
   QSslCertificate _sslCert;
 
 
 private:
   QSslKey _sslKey;
   QSslCertificate _sslCert;
 
-  CoreCertManager *_certManager;
-  CoreSession *_coreSession;
+  CoreCertManager _certManager;
 };
 
 };
 
+inline const QSslKey &CoreCertManager::sslKey() const {
+  return identity.sslKey();
+}
+inline const QSslCertificate &CoreCertManager::sslCert() const {
+  return identity.sslCert();
+}
 
 
-// ========================================
-//  CoreCertManager
-// ========================================
-class CoreCertManager : public CertManager {
-  Q_OBJECT
-
-public:
-  CoreCertManager(CoreIdentity *identity);
-
-  inline CoreIdentity *identity() const { return _identity; }
-  virtual inline const QSslKey &sslKey() const { return identity()->sslKey(); }
-  virtual inline const QSslCertificate &sslCert() const { return identity()->sslCert(); }
-
-public slots:
-  virtual void setSslKey(const QByteArray &encoded);
-  virtual void setSslCert(const QByteArray &encoded);
 
 
-  void setId(IdentityId id);
-
-private:
-  CoreIdentity *_identity;
-};
 
 #endif //COREIDENTITY_H
 
 #endif //COREIDENTITY_H
index 2649824..3a05f52 100644 (file)
@@ -125,14 +125,34 @@ CoreIdentity *CoreSession::identity(IdentityId id) const {
 void CoreSession::loadSettings() {
   CoreUserSettings s(user());
 
 void CoreSession::loadSettings() {
   CoreUserSettings s(user());
 
-  foreach(IdentityId id, s.identityIds()) {
-    createIdentity(s.identity(id));
+  // migrate to db
+  QList<IdentityId> ids = s.identityIds();
+  QList<NetworkInfo> networkInfos = Core::networks(user());
+  foreach(IdentityId id, ids) {
+    CoreIdentity identity(s.identity(id));
+    IdentityId newId = Core::createIdentity(user(), identity);
+    QList<NetworkInfo>::iterator networkIter = networkInfos.begin();
+    while(networkIter != networkInfos.end()) {
+      if(networkIter->identity == id) {
+       networkIter->identity = newId;
+       Core::updateNetwork(user(), *networkIter);
+       networkIter = networkInfos.erase(networkIter);
+      } else {
+       networkIter++;
+      }
+    }
+    s.removeIdentity(id);
+  }
+  // end of migration
+
+  foreach(CoreIdentity identity, Core::identities(user())) {
+    createIdentity(identity);
   }
   if(!_identities.count()) {
     Identity identity;
     identity.setToDefaults();
     identity.setIdentityName(tr("Default Identity"));
   }
   if(!_identities.count()) {
     Identity identity;
     identity.setToDefaults();
     identity.setIdentityName(tr("Default Identity"));
-    createIdentity(identity);
+    createIdentity(identity, QVariantMap());
   }
 
   foreach(NetworkInfo info, Core::networks(user())) {
   }
 
   foreach(NetworkInfo info, Core::networks(user())) {
@@ -264,45 +284,41 @@ void CoreSession::scriptRequest(QString script) {
 }
 
 /*** Identity Handling ***/
 }
 
 /*** Identity Handling ***/
-
 void CoreSession::createIdentity(const Identity &identity, const QVariantMap &additional) {
 void CoreSession::createIdentity(const Identity &identity, const QVariantMap &additional) {
-  if(_identities.contains(identity.id())) {
-    qWarning() << "duplicate Identity:" << identity.id();
-    return;
-  }
-
-  int id = identity.id().toInt();
-  bool newId = !identity.isValid();
-  CoreIdentity *coreIdentity = new CoreIdentity(identity, signalProxy(), this);
+  CoreIdentity coreIdentity(identity);
   if(additional.contains("KeyPem"))
   if(additional.contains("KeyPem"))
-    coreIdentity->setSslKey(additional["KeyPem"].toByteArray());
+    coreIdentity.setSslKey(additional["KeyPem"].toByteArray());
   if(additional.contains("CertPem"))
   if(additional.contains("CertPem"))
-    coreIdentity->setSslCert(additional["CertPem"].toByteArray());
-  if(newId) {
-    // find free ID
-    for(id = 1; id <= _identities.count(); id++) {
-      if(!_identities.keys().contains(id))
-       break;
-    }
-    coreIdentity->setId(id);
-    coreIdentity->save();
-  }
+    coreIdentity.setSslCert(additional["CertPem"].toByteArray());
+  IdentityId id = Core::createIdentity(user(), coreIdentity);
+  if(!id.isValid())
+    return;
+  else
+    createIdentity(coreIdentity);
+}
 
 
-  _identities[id] = coreIdentity;
-  qDebug() << id << coreIdentity->id();
-  signalProxy()->synchronize(coreIdentity);
+void CoreSession::createIdentity(const CoreIdentity &identity) {
+  CoreIdentity *coreIdentity = new CoreIdentity(identity, this);
+  _identities[identity.id()] = coreIdentity;
+  // CoreIdentity has it's own synchronize method since it's "private" sslManager needs to be synced aswell
+  coreIdentity->synchronize(signalProxy());
+  connect(coreIdentity, SIGNAL(updated(const QVariantMap &)), this, SLOT(updateIdentityBySender()));
+  emit identityCreated(*coreIdentity);
+}
 
 
-  if(newId)
-    emit identityCreated(*coreIdentity);
+void CoreSession::updateIdentityBySender() {
+  CoreIdentity *identity = qobject_cast<CoreIdentity *>(sender());
+  if(!identity)
+    return;
+  Core::updateIdentity(user(), *identity);
 }
 
 void CoreSession::removeIdentity(IdentityId id) {
 }
 
 void CoreSession::removeIdentity(IdentityId id) {
-  Identity *i = _identities.take(id);
-  if(i) {
+  CoreIdentity *identity = _identities.take(id);
+  if(identity) {
     emit identityRemoved(id);
     emit identityRemoved(id);
-    CoreUserSettings s(user());
-    s.removeIdentity(id);
-    i->deleteLater();
+    Core::removeIdentity(user(), id);
+    identity->deleteLater();
   }
 }
 
   }
 }
 
index f8ada9a..d781f21 100644 (file)
@@ -78,7 +78,8 @@ public slots:
   //! Create an identity and propagate the changes to the clients.
   /** \param identity The identity to be created.
    */
   //! Create an identity and propagate the changes to the clients.
   /** \param identity The identity to be created.
    */
-  void createIdentity(const Identity &identity, const QVariantMap &additional = QVariantMap());
+  void createIdentity(const Identity &identity, const QVariantMap &additional);
+  void createIdentity(const CoreIdentity &identity);
 
   //! Remove identity and propagate that fact to the clients.
   /** \param identity The identity to be removed.
 
   //! Remove identity and propagate that fact to the clients.
   /** \param identity The identity to be removed.
@@ -153,6 +154,8 @@ private slots:
   void clientsConnected();
   void clientsDisconnected();
 
   void clientsConnected();
   void clientsDisconnected();
 
+  void updateIdentityBySender();
+
 private:
   void loadSettings();
   void initScriptEngine();
 private:
   void loadSettings();
   void initScriptEngine();
index 83eb40d..e3459e1 100644 (file)
@@ -9,67 +9,84 @@
     <file>./SQL/SQLite/10/upgrade_030_copy_buffer_table.sql</file>
     <file>./SQL/SQLite/10/upgrade_040_drop_buffer_old_table.sql</file>
     <file>./SQL/SQLite/10/upgrade_999_version.sql</file>
     <file>./SQL/SQLite/10/upgrade_030_copy_buffer_table.sql</file>
     <file>./SQL/SQLite/10/upgrade_040_drop_buffer_old_table.sql</file>
     <file>./SQL/SQLite/10/upgrade_999_version.sql</file>
-    <file>./SQL/SQLite/11/delete_backlog_by_uid.sql</file>
-    <file>./SQL/SQLite/11/delete_backlog_for_buffer.sql</file>
-    <file>./SQL/SQLite/11/delete_backlog_for_network.sql</file>
-    <file>./SQL/SQLite/11/delete_buffer_for_bufferid.sql</file>
-    <file>./SQL/SQLite/11/delete_buffers_by_uid.sql</file>
-    <file>./SQL/SQLite/11/delete_buffers_for_network.sql</file>
-    <file>./SQL/SQLite/11/delete_ircservers_for_network.sql</file>
-    <file>./SQL/SQLite/11/delete_network.sql</file>
-    <file>./SQL/SQLite/11/delete_networks_by_uid.sql</file>
-    <file>./SQL/SQLite/11/delete_quasseluser.sql</file>
-    <file>./SQL/SQLite/11/insert_buffer.sql</file>
-    <file>./SQL/SQLite/11/insert_message.sql</file>
-    <file>./SQL/SQLite/11/insert_network.sql</file>
-    <file>./SQL/SQLite/11/insert_quasseluser.sql</file>
-    <file>./SQL/SQLite/11/insert_sender.sql</file>
-    <file>./SQL/SQLite/11/insert_server.sql</file>
-    <file>./SQL/SQLite/11/insert_user_setting.sql</file>
-    <file>./SQL/SQLite/11/select_authuser.sql</file>
-    <file>./SQL/SQLite/11/select_buffer_by_id.sql</file>
-    <file>./SQL/SQLite/11/select_buffer_lastseen_messages.sql</file>
-    <file>./SQL/SQLite/11/select_bufferByName.sql</file>
-    <file>./SQL/SQLite/11/select_bufferExists.sql</file>
-    <file>./SQL/SQLite/11/select_buffers.sql</file>
-    <file>./SQL/SQLite/11/select_buffers_for_network.sql</file>
-    <file>./SQL/SQLite/11/select_connected_networks.sql</file>
-    <file>./SQL/SQLite/11/select_internaluser.sql</file>
-    <file>./SQL/SQLite/11/select_messages.sql</file>
-    <file>./SQL/SQLite/11/select_messagesAll.sql</file>
-    <file>./SQL/SQLite/11/select_messagesAllNew.sql</file>
-    <file>./SQL/SQLite/11/select_messagesNew.sql</file>
-    <file>./SQL/SQLite/11/select_networkExists.sql</file>
-    <file>./SQL/SQLite/11/select_networks_for_user.sql</file>
-    <file>./SQL/SQLite/11/select_persistent_channels.sql</file>
-    <file>./SQL/SQLite/11/select_servers_for_network.sql</file>
-    <file>./SQL/SQLite/11/select_user_setting.sql</file>
-    <file>./SQL/SQLite/11/select_userid.sql</file>
-    <file>./SQL/SQLite/11/setup_000_quasseluser.sql</file>
-    <file>./SQL/SQLite/11/setup_010_sender.sql</file>
-    <file>./SQL/SQLite/11/setup_020_network.sql</file>
-    <file>./SQL/SQLite/11/setup_030_buffer.sql</file>
-    <file>./SQL/SQLite/11/setup_040_buffer_idx.sql</file>
-    <file>./SQL/SQLite/11/setup_050_buffer_cname_idx.sql</file>
-    <file>./SQL/SQLite/11/setup_060_backlog.sql</file>
-    <file>./SQL/SQLite/11/setup_070_coreinfo.sql</file>
-    <file>./SQL/SQLite/11/setup_080_ircservers.sql</file>
-    <file>./SQL/SQLite/11/setup_090_create_backlog_idx.sql</file>
-    <file>./SQL/SQLite/11/setup_100_create_backlog_idx2.sql</file>
-    <file>./SQL/SQLite/11/setup_110_create_buffer_idx.sql</file>
-    <file>./SQL/SQLite/11/setup_120_create_user_setting.sql</file>
-    <file>./SQL/SQLite/11/setup_999_version.sql</file>
-    <file>./SQL/SQLite/11/update_buffer_lastseen.sql</file>
-    <file>./SQL/SQLite/11/update_buffer_name.sql</file>
-    <file>./SQL/SQLite/11/update_buffer_persistent_channel.sql</file>
-    <file>./SQL/SQLite/11/update_buffer_set_channel_key.sql</file>
-    <file>./SQL/SQLite/11/update_network.sql</file>
-    <file>./SQL/SQLite/11/update_network_connected.sql</file>
-    <file>./SQL/SQLite/11/update_user_setting.sql</file>
-    <file>./SQL/SQLite/11/update_username.sql</file>
-    <file>./SQL/SQLite/11/update_userpassword.sql</file>
     <file>./SQL/SQLite/11/upgrade_000_create_user_setting.sql</file>
     <file>./SQL/SQLite/11/upgrade_999_version.sql</file>
     <file>./SQL/SQLite/11/upgrade_000_create_user_setting.sql</file>
     <file>./SQL/SQLite/11/upgrade_999_version.sql</file>
+    <file>./SQL/SQLite/12/delete_backlog_by_uid.sql</file>
+    <file>./SQL/SQLite/12/delete_backlog_for_buffer.sql</file>
+    <file>./SQL/SQLite/12/delete_backlog_for_network.sql</file>
+    <file>./SQL/SQLite/12/delete_buffer_for_bufferid.sql</file>
+    <file>./SQL/SQLite/12/delete_buffers_by_uid.sql</file>
+    <file>./SQL/SQLite/12/delete_buffers_for_network.sql</file>
+    <file>./SQL/SQLite/12/delete_identity.sql</file>
+    <file>./SQL/SQLite/12/delete_ircservers_for_network.sql</file>
+    <file>./SQL/SQLite/12/delete_network.sql</file>
+    <file>./SQL/SQLite/12/delete_networks_by_uid.sql</file>
+    <file>./SQL/SQLite/12/delete_nicks.sql</file>
+    <file>./SQL/SQLite/12/delete_quasseluser.sql</file>
+    <file>./SQL/SQLite/12/insert_buffer.sql</file>
+    <file>./SQL/SQLite/12/insert_identity.sql</file>
+    <file>./SQL/SQLite/12/insert_message.sql</file>
+    <file>./SQL/SQLite/12/insert_network.sql</file>
+    <file>./SQL/SQLite/12/insert_nick.sql</file>
+    <file>./SQL/SQLite/12/insert_quasseluser.sql</file>
+    <file>./SQL/SQLite/12/insert_sender.sql</file>
+    <file>./SQL/SQLite/12/insert_server.sql</file>
+    <file>./SQL/SQLite/12/insert_user_setting.sql</file>
+    <file>./SQL/SQLite/12/select_authuser.sql</file>
+    <file>./SQL/SQLite/12/select_buffer_by_id.sql</file>
+    <file>./SQL/SQLite/12/select_buffer_lastseen_messages.sql</file>
+    <file>./SQL/SQLite/12/select_bufferByName.sql</file>
+    <file>./SQL/SQLite/12/select_bufferExists.sql</file>
+    <file>./SQL/SQLite/12/select_buffers.sql</file>
+    <file>./SQL/SQLite/12/select_buffers_for_network.sql</file>
+    <file>./SQL/SQLite/12/select_checkidentity.sql</file>
+    <file>./SQL/SQLite/12/select_connected_networks.sql</file>
+    <file>./SQL/SQLite/12/select_identities.sql</file>
+    <file>./SQL/SQLite/12/select_internaluser.sql</file>
+    <file>./SQL/SQLite/12/select_messages.sql</file>
+    <file>./SQL/SQLite/12/select_messagesAll.sql</file>
+    <file>./SQL/SQLite/12/select_messagesAllNew.sql</file>
+    <file>./SQL/SQLite/12/select_messagesNew.sql</file>
+    <file>./SQL/SQLite/12/select_networkExists.sql</file>
+    <file>./SQL/SQLite/12/select_networks_for_user.sql</file>
+    <file>./SQL/SQLite/12/select_nicks.sql</file>
+    <file>./SQL/SQLite/12/select_persistent_channels.sql</file>
+    <file>./SQL/SQLite/12/select_servers_for_network.sql</file>
+    <file>./SQL/SQLite/12/select_user_setting.sql</file>
+    <file>./SQL/SQLite/12/select_userid.sql</file>
+    <file>./SQL/SQLite/12/setup_000_quasseluser.sql</file>
+    <file>./SQL/SQLite/12/setup_010_sender.sql</file>
+    <file>./SQL/SQLite/12/setup_020_network.sql</file>
+    <file>./SQL/SQLite/12/setup_030_buffer.sql</file>
+    <file>./SQL/SQLite/12/setup_040_buffer_idx.sql</file>
+    <file>./SQL/SQLite/12/setup_050_buffer_cname_idx.sql</file>
+    <file>./SQL/SQLite/12/setup_060_backlog.sql</file>
+    <file>./SQL/SQLite/12/setup_070_coreinfo.sql</file>
+    <file>./SQL/SQLite/12/setup_080_ircservers.sql</file>
+    <file>./SQL/SQLite/12/setup_090_create_backlog_idx.sql</file>
+    <file>./SQL/SQLite/12/setup_100_create_backlog_idx2.sql</file>
+    <file>./SQL/SQLite/12/setup_110_create_buffer_idx.sql</file>
+    <file>./SQL/SQLite/12/setup_120_create_user_setting.sql</file>
+    <file>./SQL/SQLite/12/setup_130_identity.sql</file>
+    <file>./SQL/SQLite/12/setup_140_identity_nick.sql</file>
+    <file>./SQL/SQLite/12/setup_999_version.sql</file>
+    <file>./SQL/SQLite/12/update_buffer_lastseen.sql</file>
+    <file>./SQL/SQLite/12/update_buffer_name.sql</file>
+    <file>./SQL/SQLite/12/update_buffer_persistent_channel.sql</file>
+    <file>./SQL/SQLite/12/update_buffer_set_channel_key.sql</file>
+    <file>./SQL/SQLite/12/update_identity.sql</file>
+    <file>./SQL/SQLite/12/update_network.sql</file>
+    <file>./SQL/SQLite/12/update_network_connected.sql</file>
+    <file>./SQL/SQLite/12/update_user_setting.sql</file>
+    <file>./SQL/SQLite/12/update_username.sql</file>
+    <file>./SQL/SQLite/12/update_userpassword.sql</file>
+    <file>./SQL/SQLite/12/upgrade_000_create_identity.sql</file>
+    <file>./SQL/SQLite/12/upgrade_010_create_identity_nick.sql</file>
+    <file>./SQL/SQLite/12/upgrade_020_rename_servertable.sql</file>
+    <file>./SQL/SQLite/12/upgrade_030_create_ircserver.sql</file>
+    <file>./SQL/SQLite/12/upgrade_040_copy_ircserver.sql</file>
+    <file>./SQL/SQLite/12/upgrade_050_drop_ircserverold.sql</file>
+    <file>./SQL/SQLite/12/upgrade_999_version.sql</file>
     <file>./SQL/SQLite/2/upgrade_000_drop_buffergroup.sql</file>
     <file>./SQL/SQLite/2/upgrade_010_update_schemaversion.sql</file>
     <file>./SQL/SQLite/3/upgrade_000_update_backlog_flags.sql</file>
     <file>./SQL/SQLite/2/upgrade_000_drop_buffergroup.sql</file>
     <file>./SQL/SQLite/2/upgrade_010_update_schemaversion.sql</file>
     <file>./SQL/SQLite/3/upgrade_000_update_backlog_flags.sql</file>
index cc48420..054b389 100644 (file)
@@ -191,6 +191,175 @@ QVariant SqliteStorage::getUserSetting(UserId userId, const QString &settingName
   }
 }
 
   }
 }
 
+IdentityId SqliteStorage::createIdentity(UserId user, CoreIdentity &identity) {
+  IdentityId identityId;
+
+  QSqlQuery query(logDb());
+  query.prepare(queryString("insert_identity"));
+  query.bindValue(":userid", user.toInt());
+  query.bindValue(":identityname", identity.identityName());
+  query.bindValue(":realname", identity.realName());
+  query.bindValue(":awaynick", identity.awayNick());
+  query.bindValue(":awaynickenabled", identity.awayNickEnabled() ? 1 : 0);
+  query.bindValue(":awayreason", identity.awayReason());
+  query.bindValue(":awayreasonenabled", identity.awayReasonEnabled() ? 1 : 0);
+  query.bindValue(":autoawayenabled", identity.awayReasonEnabled() ? 1 : 0);
+  query.bindValue(":autoawaytime", identity.autoAwayTime());
+  query.bindValue(":autoawayreason", identity.autoAwayReason());
+  query.bindValue(":autoawayreasonenabled", identity.autoAwayReasonEnabled() ? 1 : 0);
+  query.bindValue(":detachawayenabled", identity.detachAwayEnabled() ? 1 : 0);
+  query.bindValue(":detachawayreason", identity.detachAwayReason());
+  query.bindValue(":detachawayreasonenabled", identity.detachAwayReasonEnabled() ? 1 : 0);
+  query.bindValue(":ident", identity.ident());
+  query.bindValue(":kickreason", identity.kickReason());
+  query.bindValue(":partreason", identity.partReason());
+  query.bindValue(":quitreason", identity.quitReason());
+  query.bindValue(":sslcert", identity.sslCert().toPem());
+  query.bindValue(":sslkey", identity.sslKey().toPem());
+  safeExec(query);
+
+  identityId = query.lastInsertId().toInt();
+  qDebug() << identityId << identity.nicks();
+  if(!identityId.isValid()) {
+    watchQuery(query);
+  } else {
+    QSqlQuery deleteNickQuery(logDb());
+    deleteNickQuery.prepare(queryString("delete_nicks"));
+    deleteNickQuery.bindValue(":identityid", identityId.toInt());
+    safeExec(deleteNickQuery);
+
+    QSqlQuery insertNickQuery(logDb());
+    insertNickQuery.prepare(queryString("insert_nick"));
+    foreach(QString nick, identity.nicks()) {
+      insertNickQuery.bindValue(":identityid", identityId.toInt());
+      insertNickQuery.bindValue(":nick", nick);
+      safeExec(insertNickQuery);
+    }
+  }
+  identity.setId(identityId);
+  return identityId;
+}
+
+bool SqliteStorage::updateIdentity(UserId user, const CoreIdentity &identity) {
+  QSqlQuery checkQuery(logDb());
+  checkQuery.prepare(queryString("select_checkidentity"));
+  checkQuery.bindValue(":identityid", identity.id().toInt());
+  checkQuery.bindValue(":userid", user.toInt());
+  safeExec(checkQuery);
+
+  if(!checkQuery.first() || checkQuery.value(0).toInt() != 1) // there should be exactly one identity for the given id and user
+    return false;
+
+  QSqlQuery query(logDb());
+  query.prepare(queryString("update_identity"));
+  query.bindValue(":identityname", identity.identityName());
+  query.bindValue(":realname", identity.realName());
+  query.bindValue(":awaynick", identity.awayNick());
+  query.bindValue(":awaynickenabled", identity.awayNickEnabled() ? 1 : 0);
+  query.bindValue(":awayreason", identity.awayReason());
+  query.bindValue(":awayreasonenabled", identity.awayReasonEnabled() ? 1 : 0);
+  query.bindValue(":autoawayenabled", identity.awayReasonEnabled() ? 1 : 0);
+  query.bindValue(":autoawaytime", identity.autoAwayTime());
+  query.bindValue(":autoawayreason", identity.autoAwayReason());
+  query.bindValue(":autoawayreasonenabled", identity.autoAwayReasonEnabled() ? 1 : 0);
+  query.bindValue(":detachawayenabled", identity.detachAwayEnabled() ? 1 : 0);
+  query.bindValue(":detachawayreason", identity.detachAwayReason());
+  query.bindValue(":detachawayreasonenabled", identity.detachAwayReasonEnabled() ? 1 : 0);
+  query.bindValue(":ident", identity.ident());
+  query.bindValue(":kickreason", identity.kickReason());
+  query.bindValue(":partreason", identity.partReason());
+  query.bindValue(":quitreason", identity.quitReason());
+  query.bindValue(":sslcert", identity.sslCert().toPem());
+  query.bindValue(":sslkey", identity.sslKey().toPem());
+  query.bindValue(":identityid", identity.id().toInt());
+  safeExec(query);
+
+  QSqlQuery deleteNickQuery(logDb());
+  deleteNickQuery.prepare(queryString("delete_nicks"));
+  deleteNickQuery.bindValue(":identityid", identity.id().toInt());
+  safeExec(deleteNickQuery);
+
+  QSqlQuery insertNickQuery(logDb());
+  insertNickQuery.prepare(queryString("insert_nick"));
+  foreach(QString nick, identity.nicks()) {
+    insertNickQuery.bindValue(":identityid", identity.id().toInt());
+    insertNickQuery.bindValue(":nick", nick);
+    safeExec(insertNickQuery);
+  }
+
+  return true;
+}
+
+void SqliteStorage::removeIdentity(UserId user, IdentityId identityId) {
+  QSqlQuery checkQuery(logDb());
+  checkQuery.prepare(queryString("select_checkidentity"));
+  checkQuery.bindValue(":identityid", identityId.toInt());
+  checkQuery.bindValue(":userid", user.toInt());
+  safeExec(checkQuery);
+
+  if(!checkQuery.first() || checkQuery.value(0).toInt() != 1) // there should be exactly one identity for the given id and user
+    return;
+
+  QSqlQuery deleteNickQuery(logDb());
+  deleteNickQuery.prepare(queryString("delete_nicks"));
+  deleteNickQuery.bindValue(":identityid", identityId.toInt());
+  safeExec(deleteNickQuery);
+
+  QSqlQuery deleteIdentityQuery(logDb());
+  deleteIdentityQuery.prepare(queryString("delete_identity"));
+  deleteIdentityQuery.bindValue(":identityid", identityId.toInt());
+  deleteIdentityQuery.bindValue(":userid", user.toInt());
+  safeExec(deleteIdentityQuery);
+}
+
+QList<CoreIdentity> SqliteStorage::identities(UserId user) {
+  QList<CoreIdentity> identities;
+
+  QSqlQuery query(logDb());
+  query.prepare(queryString("select_identities"));
+  query.bindValue(":userid", user.toInt());
+
+  QSqlQuery nickQuery(logDb());
+  nickQuery.prepare(queryString("select_nicks"));
+
+  safeExec(query);
+
+  while(query.next()) {
+    CoreIdentity identity(IdentityId(query.value(0).toInt()));
+
+    identity.setIdentityName(query.value(1).toString());
+    identity.setRealName(query.value(2).toString());
+    identity.setAwayNick(query.value(3).toString());
+    identity.setAwayNickEnabled(!!query.value(4).toInt());
+    identity.setAwayReason(query.value(5).toString());
+    identity.setAwayReasonEnabled(!!query.value(6).toInt());
+    identity.setAutoAwayEnabled(!!query.value(7).toInt());
+    identity.setAutoAwayTime(query.value(8).toInt());
+    identity.setAutoAwayReason(query.value(9).toString());
+    identity.setAutoAwayReasonEnabled(!!query.value(10).toInt());
+    identity.setDetachAwayEnabled(!!query.value(11).toInt());
+    identity.setDetachAwayReason(query.value(12).toString());
+    identity.setDetachAwayReasonEnabled(!!query.value(13).toInt());
+    identity.setIdent(query.value(14).toString());
+    identity.setKickReason(query.value(15).toString());
+    identity.setPartReason(query.value(16).toString());
+    identity.setQuitReason(query.value(17).toString());
+    identity.setSslCert(query.value(18).toByteArray());
+    identity.setSslKey(query.value(19).toByteArray());
+
+    nickQuery.bindValue(":identityid", identity.id().toInt());
+    QList<QString> nicks;
+    safeExec(nickQuery);
+    watchQuery(nickQuery);
+    while(nickQuery.next()) {
+      nicks << nickQuery.value(0).toString();
+    }
+    identity.setNicks(nicks);
+    identities << identity;
+  }
+  return identities;
+}
+
 NetworkId SqliteStorage::createNetwork(UserId user, const NetworkInfo &info) {
   NetworkId networkId;
   QSqlQuery query(logDb());
 NetworkId SqliteStorage::createNetwork(UserId user, const NetworkInfo &info) {
   NetworkId networkId;
   QSqlQuery query(logDb());
index e9b2f14..5adae63 100644 (file)
@@ -54,6 +54,11 @@ public slots:
   virtual void setUserSetting(UserId userId, const QString &settingName, const QVariant &data);
   virtual QVariant getUserSetting(UserId userId, const QString &settingName, const QVariant &defaultData = QVariant());
 
   virtual void setUserSetting(UserId userId, const QString &settingName, const QVariant &data);
   virtual QVariant getUserSetting(UserId userId, const QString &settingName, const QVariant &defaultData = QVariant());
 
+  /* Identity handling */
+  virtual IdentityId createIdentity(UserId user, CoreIdentity &identity);
+  virtual bool updateIdentity(UserId user, const CoreIdentity &identity);
+  virtual void removeIdentity(UserId user, IdentityId identityId);
+  virtual QList<CoreIdentity> identities(UserId user);
 
   /* Network handling */
   virtual NetworkId createNetwork(UserId user, const NetworkInfo &info);
 
   /* Network handling */
   virtual NetworkId createNetwork(UserId user, const NetworkInfo &info);
index d0c6afb..a80620f 100644 (file)
@@ -24,6 +24,7 @@
 #include <QtCore>
 
 #include "types.h"
 #include <QtCore>
 
 #include "types.h"
+#include "coreidentity.h"
 #include "message.h"
 #include "network.h"
 
 #include "message.h"
 #include "network.h"
 
@@ -128,6 +129,12 @@ public slots:
    * \return the Value of the Setting or the default value if it is unset.
    */
   virtual QVariant getUserSetting(UserId userId, const QString &settingName, const QVariant &data = QVariant()) = 0;
    * \return the Value of the Setting or the default value if it is unset.
    */
   virtual QVariant getUserSetting(UserId userId, const QString &settingName, const QVariant &data = QVariant()) = 0;
+
+  /* Identity handling */
+  virtual IdentityId createIdentity(UserId user, CoreIdentity &identity) = 0;
+  virtual bool updateIdentity(UserId user, const CoreIdentity &identity) = 0;
+  virtual void removeIdentity(UserId user, IdentityId identityId) = 0;
+  virtual QList<CoreIdentity> identities(UserId user) = 0;
   
   /* Network handling */
 
   
   /* Network handling */
 
index fa7bba4..e8bb680 100644 (file)
@@ -46,7 +46,7 @@ IdentitiesSettingsPage::IdentitiesSettingsPage(QWidget *parent)
   ui.nickUp->setIcon(SmallIcon("go-up"));
   ui.nickDown->setIcon(SmallIcon("go-down"));
 
   ui.nickUp->setIcon(SmallIcon("go-up"));
   ui.nickDown->setIcon(SmallIcon("go-down"));
 
-  setEnabled(Client::isConnected());  // need a core connection!
+  coreConnectionStateChanged(Client::isConnected());  // need a core connection!
   setWidgetStates();
   connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), this, SLOT(coreConnectionStateChanged(bool)));
   connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(clientIdentityCreated(IdentityId)));
   setWidgetStates();
   connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), this, SLOT(coreConnectionStateChanged(bool)));
   connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(clientIdentityCreated(IdentityId)));
@@ -103,10 +103,13 @@ void IdentitiesSettingsPage::coreConnectionStateChanged(bool connected) {
   setEnabled(connected);
   if(connected) {
 #ifdef HAVE_SSL
   setEnabled(connected);
   if(connected) {
 #ifdef HAVE_SSL
-    if(Client::signalProxy()->isSecure())
+    if(Client::signalProxy()->isSecure()) {
       ui.keyAndCertSettings->setCurrentIndex(2);
       ui.keyAndCertSettings->setCurrentIndex(2);
-    else
+      _editSsl = true;
+    } else {
       ui.keyAndCertSettings->setCurrentIndex(1);
       ui.keyAndCertSettings->setCurrentIndex(1);
+      _editSsl = false;
+    }
 #else
     ui.keyAndCertSettings->setCurrentIndex(0);
 #endif
 #else
     ui.keyAndCertSettings->setCurrentIndex(0);
 #endif