/*** ***/
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()));
}
}
-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;
return true;
}
-bool Identity::operator!=(const Identity &other) {
+bool Identity::operator!=(const Identity &other) const {
return !(*this == other);
}
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(); }
+++ /dev/null
-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
-)
--- /dev/null
+DELETE FROM identity
+WHERE identityid = :identityid AND userid = :userid
--- /dev/null
+DELETE FROM identity_nick
+WHERE userid = :userid
--- /dev/null
+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)
--- /dev/null
+INSERT INTO identity_nick (identityid, nick)
+VALUES (:identityid, :nick)
--- /dev/null
+SELECT count(*)
+FROM identity
+WHERE identityid = :identityid AND userid = :userid
--- /dev/null
+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
--- /dev/null
+SELECT nick
+FROM identity_nick
+WHERE identityid = :identityid
+ORDER BY nickid ASC
--- /dev/null
+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
+)
--- /dev/null
+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)
+)
--- /dev/null
+CREATE TABLE identity_nick (
+ nickid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ identityid INTEGER NOT NULL,
+ nick TEXT NOT NULL,
+ UNIQUE (identityid, nick)
+)
--- /dev/null
+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
--- /dev/null
+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)
+)
--- /dev/null
+CREATE TABLE identity_nick (
+ nickid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ identityid INTEGER NOT NULL,
+ nick TEXT NOT NULL,
+ UNIQUE (identityid, nick)
+)
--- /dev/null
+ALTER TABLE ircserver RENAME TO ircserverold
--- /dev/null
+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
+)
--- /dev/null
+INSERT INTO ircserver (serverid, userid, networkid, hostname, port, password, ssl)
+SELECT serverid, userid, networkid, hostname, port, password, ssl FROM ircserverold
--- /dev/null
+DROP TABLE ircserverold
--- /dev/null
+UPDATE coreinfo
+SET value = 12
+WHERE key = 'schemaversion'
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.
#include "coreidentity.h"
-#include "coresession.h"
-#include "coreusersettings.h"
#include "signalproxy.h"
-CoreIdentity::CoreIdentity(IdentityId id, SignalProxy *proxy, CoreSession *parent)
+CoreIdentity::CoreIdentity(IdentityId id, QObject *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),
- _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) {
setSslCert(QSslCertificate(encoded));
}
+CoreIdentity &CoreIdentity::operator=(const CoreIdentity &identity) {
+ Identity::operator=(identity);
+ _sslKey = identity._sslKey;
+ _sslCert = identity._sslCert;
+ return *this;
+}
// ========================================
// 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) {
- identity()->setSslKey(encoded);
+ identity.setSslKey(encoded);
CertManager::setSslKey(encoded);
}
void CoreCertManager::setSslCert(const QByteArray &encoded) {
- identity()->setSslCert(encoded);
+ identity.setSslCert(encoded);
CertManager::setSslCert(encoded);
}
#include <QSslKey>
#include <QSslCertificate>
-class CoreCertManager;
-class CoreSession;
+class CoreIdentity;
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:
- 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 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;
- 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
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"));
- createIdentity(identity);
+ createIdentity(identity, QVariantMap());
}
foreach(NetworkInfo info, Core::networks(user())) {
}
/*** Identity Handling ***/
-
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"))
- coreIdentity->setSslKey(additional["KeyPem"].toByteArray());
+ coreIdentity.setSslKey(additional["KeyPem"].toByteArray());
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) {
- Identity *i = _identities.take(id);
- if(i) {
+ CoreIdentity *identity = _identities.take(id);
+ if(identity) {
emit identityRemoved(id);
- CoreUserSettings s(user());
- s.removeIdentity(id);
- i->deleteLater();
+ Core::removeIdentity(user(), id);
+ identity->deleteLater();
}
}
//! 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.
void clientsConnected();
void clientsDisconnected();
+ void updateIdentityBySender();
+
private:
void loadSettings();
void initScriptEngine();
<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/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>
}
}
+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());
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);
#include <QtCore>
#include "types.h"
+#include "coreidentity.h"
#include "message.h"
#include "network.h"
* \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 */
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)));
setEnabled(connected);
if(connected) {
#ifdef HAVE_SSL
- if(Client::signalProxy()->isSecure())
+ if(Client::signalProxy()->isSecure()) {
ui.keyAndCertSettings->setCurrentIndex(2);
- else
+ _editSsl = true;
+ } else {
ui.keyAndCertSettings->setCurrentIndex(1);
+ _editSsl = false;
+ }
#else
ui.keyAndCertSettings->setCurrentIndex(0);
#endif