From 21d8d7f0a79eeeb541664aa80ce481fdbfc41f09 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Mon, 7 Jan 2008 16:34:59 +0000 Subject: [PATCH] Committing a lot of identity stuff which is still disabled. --- Quassel.kdevelop.filelist | 11 +- src/client/client.cpp | 22 +- src/common/global.h | 1 - src/common/identity.cpp | 212 ++++++++++- src/common/identity.h | 90 ++++- src/common/main.cpp | 5 +- src/common/signalproxy.cpp | 1 + src/common/types.h | 3 +- src/core/coresession.cpp | 61 ++-- src/core/coresession.h | 11 +- src/core/coresettings.h | 2 +- src/core/coreusersettings.cpp | 21 ++ src/core/coreusersettings.h | 6 +- src/qtui/mainwin.cpp | 9 +- src/qtui/qtui.h | 5 +- src/qtui/settingsdlg.cpp | 36 +- src/qtui/settingsdlg.h | 6 +- src/qtui/settingspages/createidentitydlg.ui | 143 ++++++++ .../settingspages/identitiessettingspage.cpp | 344 +++++++++++++++++- .../settingspages/identitiessettingspage.h | 65 +++- .../settingspages/identitiessettingspage.ui | 140 +++++-- src/qtui/settingspages/saveidentitiesdlg.ui | 124 +++++++ src/qtui/settingspages/settingspages.pri | 2 +- src/uisupport/settingspage.cpp | 17 +- src/uisupport/settingspage.h | 11 +- 25 files changed, 1237 insertions(+), 111 deletions(-) create mode 100644 src/qtui/settingspages/createidentitydlg.ui create mode 100644 src/qtui/settingspages/saveidentitiesdlg.ui diff --git a/Quassel.kdevelop.filelist b/Quassel.kdevelop.filelist index 7ab1c813..9f4e17e9 100644 --- a/Quassel.kdevelop.filelist +++ b/Quassel.kdevelop.filelist @@ -70,6 +70,8 @@ src/common/settings.cpp src/common/settings.h src/common/signalproxy.cpp src/common/signalproxy.h +src/common/syncableobject.cpp +src/common/syncableobject.h src/common/types.h src/common/util.cpp src/common/util.h @@ -91,8 +93,6 @@ src/core/ircserverhandler.cpp src/core/ircserverhandler.h src/core/server.cpp src/core/server.h -src/core/sessionsettings.cpp -src/core/sessionsettings.h src/core/sqlitestorage.cpp src/core/sqlitestorage.h src/core/storage.cpp @@ -172,8 +172,15 @@ src/qtui/settingsdlg.h src/qtui/settingspages src/qtui/settingspages.cpp src/qtui/settingspages.h +src/qtui/settingspages/createidentitydlg.ui +src/qtui/settingspages/fontssettingspage.cpp +src/qtui/settingspages/fontssettingspage.h +src/qtui/settingspages/fontssettingspage.ui src/qtui/settingspages/identitiessettingspage.cpp src/qtui/settingspages/identitiessettingspage.h +src/qtui/settingspages/identitiessettingspage.ui +src/qtui/settingspages/networkssettingspage.ui +src/qtui/settingspages/servereditdlg.ui src/qtui/settingspages/settingspages.pri src/qtui/topicwidget.cpp src/qtui/topicwidget.h diff --git a/src/client/client.cpp b/src/client/client.cpp index f77ab6c4..1b6e0bba 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -321,7 +321,7 @@ void Client::coreSocketDisconnected() { /* Clear internal data. Hopefully nothing relies on it at this point. */ _networkModel->clear(); - QHash::iterator bufferIter = _buffers.begin(); + QHash::iterator bufferIter = _buffers.begin(); while(bufferIter != _buffers.end()) { Buffer *buffer = bufferIter.value(); disconnect(buffer, SIGNAL(destroyed()), this, 0); @@ -331,7 +331,7 @@ void Client::coreSocketDisconnected() { Q_ASSERT(_buffers.isEmpty()); - QHash::iterator netIter = _networkInfo.begin(); + QHash::iterator netIter = _networkInfo.begin(); while(netIter != _networkInfo.end()) { NetworkInfo *net = netIter.value(); disconnect(net, SIGNAL(destroyed()), this, 0); @@ -340,6 +340,15 @@ void Client::coreSocketDisconnected() { } Q_ASSERT(_networkInfo.isEmpty()); + QHash::iterator idIter = _identities.begin(); + while(idIter != _identities.end()) { + Identity *id = idIter.value(); + emit identityRemoved(id->id()); + idIter = _identities.erase(idIter); + id->deleteLater(); + } + Q_ASSERT(_identities.isEmpty()); + coreConnectionInfo.clear(); sessionData.clear(); layoutQueue.clear(); @@ -370,10 +379,11 @@ void Client::syncToCore(const QVariant &coreState) { // create identities foreach(QVariant vid, sessionState["Identities"].toList()) { - Identity *id = new Identity(vid.value(), this); - _identities[id->id()] = id; - signalProxy()->synchronize(id); - qDebug() << "received identity" << id->identityName(); + coreIdentityCreated(vid.value()); + //Identity *id = new Identity(vid.value(), this); + //_identities[id->id()] = id; + //signalProxy()->synchronize(id); + //qDebug() << "received identity" << id->identityName(); } // store Buffer details diff --git a/src/common/global.h b/src/common/global.h index bd25ccdb..dadbb91f 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -28,7 +28,6 @@ // Enable some shortcuts and stuff //#define DEVELMODE - /** The protocol version we use fo the communication between core and GUI */ #define GUI_PROTOCOL 4 diff --git a/src/common/identity.cpp b/src/common/identity.cpp index b25b5eb0..c2fdeaf5 100644 --- a/src/common/identity.cpp +++ b/src/common/identity.cpp @@ -34,8 +34,23 @@ Identity::Identity(const Identity &other, QObject *parent) : QObject(parent), _realName(other.realName()), _nicks(other.nicks()), _awayNick(other.awayNick()), + _awayNickEnabled(other.awayNickEnabled()), _awayReason(other.awayReason()), - _returnMessage(other.returnMessage()) { + _awayReasonEnabled(other.awayReasonEnabled()), + _returnMessage(other.returnMessage()), + _returnMessageEnabled(other.returnMessageEnabled()), + _autoAwayEnabled(other.autoAwayEnabled()), + _autoAwayTime(other.autoAwayTime()), + _autoAwayReason(other.autoAwayReason()), + _autoAwayReasonEnabled(other.autoAwayReasonEnabled()), + _autoReturnMessage(other.autoReturnMessage()), + _autoReturnMessageEnabled(other.autoReturnMessageEnabled()), + _ident(other.ident()), + _kickReason(other.kickReason()), + _partReason(other.partReason()), + _quitReason(other.quitReason()) + +{ init(); } @@ -51,9 +66,26 @@ void Identity::setToDefaults() { n << QString("quassel%1").arg(qrand() & 0xff); // FIXME provide more sensible default nicks setNicks(n); setAwayNick(""); + setAwayNickEnabled(false); setAwayReason(tr("Gone fishing.")); + setAwayReasonEnabled(true); setReturnMessage(tr("Brought fish.")); + setReturnMessageEnabled(false); + setAutoAwayEnabled(false); + setAutoAwayTime(10); + setAutoAwayReason(tr("Not here. No, really. not here!")); + setAutoAwayReasonEnabled(false); + setAutoReturnMessage(tr("Back in action again!")); + setAutoReturnMessageEnabled(false); + setIdent("quassel"); + setKickReason(tr("Kindergarten is elsewhere!")); + setPartReason(tr("http://quassel-irc.org - Chat comfortably. Anywhere.")); + setQuitReason(tr("http://quassel-irc.org - Chat comfortably. Anywhere.")); + +} +bool Identity::isValid() const { + return (id() > 0); } bool Identity::initialized() const { @@ -84,15 +116,73 @@ QString Identity::awayNick() const { return _awayNick; } +bool Identity::awayNickEnabled() const { + return _awayNickEnabled; +} + QString Identity::awayReason() const { return _awayReason; } +bool Identity::awayReasonEnabled() const { + return _awayReasonEnabled; +} + QString Identity::returnMessage() const { return _returnMessage; } -////////////////////// +bool Identity::returnMessageEnabled() const { + return _returnMessageEnabled; +} + +bool Identity::autoAwayEnabled() const { + return _autoAwayEnabled; +} + +int Identity::autoAwayTime() const { + return _autoAwayTime; +} + +QString Identity::autoAwayReason() const { + return _autoAwayReason; +} + +bool Identity::autoAwayReasonEnabled() const { + return _autoAwayReasonEnabled; +} + +QString Identity::autoReturnMessage() const { + return _autoReturnMessage; +} + +bool Identity::autoReturnMessageEnabled() const { + return _autoReturnMessageEnabled; +} + +QString Identity::ident() const { + return _ident; +} + +QString Identity::kickReason() const { + return _kickReason; +} + +QString Identity::partReason() const +{return _partReason;} + +QString Identity::quitReason() const { + return _quitReason; +} + +/*** setters ***/ + +// NOTE: DO NOT USE ON SYNCHRONIZED OBJECTS! +void Identity::setId(IdentityId _id) { + _identityId = _id; + setObjectName(QString::number(id())); + //emit idSet(id); +} void Identity::setIdentityName(const QString &identityName) { _identityName = identityName; @@ -124,15 +214,102 @@ void Identity::setReturnMessage(const QString &message) { emit returnMessageSet(message); } +void Identity::setAwayNickEnabled(bool enabled) { + _awayNickEnabled = enabled; + emit awayNickEnabledSet(enabled); +} + +void Identity::setAwayReasonEnabled(bool enabled) { + _awayReasonEnabled = enabled; + emit awayReasonEnabledSet(enabled); +} + +void Identity::setReturnMessageEnabled(bool enabled) { + _returnMessageEnabled = enabled; + emit returnMessageEnabledSet(enabled); +} + +void Identity::setAutoAwayEnabled(bool enabled) { + _autoAwayEnabled = enabled; + emit autoAwayEnabledSet(enabled); +} + +void Identity::setAutoAwayTime(int time) { + _autoAwayTime = time; + emit autoAwayTimeSet(time); +} + +void Identity::setAutoAwayReason(const QString & reason) { + _autoAwayReason = reason; + emit autoAwayReasonSet(reason); +} + +void Identity::setAutoAwayReasonEnabled(bool enabled) { + _autoAwayReasonEnabled = enabled; + emit autoAwayReasonEnabledSet(enabled); +} + +void Identity::setAutoReturnMessage(const QString & message) { + _autoReturnMessage = message; + emit autoReturnMessageSet(message); +} + +void Identity::setAutoReturnMessageEnabled(bool enabled) { + _autoReturnMessageEnabled = enabled; + emit autoReturnMessageEnabledSet(enabled); +} + +void Identity::setIdent(const QString & ident) { + _ident = ident; + emit identSet(ident); +} + +void Identity::setKickReason(const QString & reason) { + _kickReason = reason; + emit kickReasonSet(reason); +} + +void Identity::setPartReason(const QString & reason) { + _partReason = reason; + emit partReasonSet(reason); +} + +void Identity::setQuitReason(const QString & reason) { + _quitReason = reason; + emit quitReasonSet(reason); +} + +/*** ***/ + void Identity::update(const Identity &other) { - for(int idx = 0; idx < metaObject()->propertyCount(); idx++) { - QMetaProperty metaProp = metaObject()->property(metaObject()->propertyOffset() + idx); +for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(); idx++) { + QMetaProperty metaProp = metaObject()->property(idx); Q_ASSERT(metaProp.isValid()); if(this->property(metaProp.name()) != other.property(metaProp.name())) { setProperty(metaProp.name(), other.property(metaProp.name())); } } } +#include +bool Identity::operator==(const Identity &other) { + for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(); idx++) { + QMetaProperty metaProp = metaObject()->property(idx); + Q_ASSERT(metaProp.isValid()); + QVariant v1 = this->property(metaProp.name()); + QVariant v2 = other.property(metaProp.name()); //qDebug() << v1 << v2; + // QVariant cannot compare custom types, so we need to check for this case + if(QString(v1.typeName()) == "IdentityId") { + if(v1.value() != v2.value()) return false; + } else { + if(v1 != v2) return false; + } + } + return true; +} + +bool Identity::operator!=(const Identity &other) { + return !(*this == other); +} /////////////////////////////// @@ -144,8 +321,21 @@ QDataStream &operator<<(QDataStream &out, const Identity &id) { i["RealName"] = id.realName(); i["Nicks"] = id.nicks(); i["AwayNick"] = id.awayNick(); + i["AwayNickEnabled"] = id.awayNickEnabled(); i["AwayReason"] = id.awayReason(); + i["AwayReasonEnabled"] = id.awayReasonEnabled(); i["ReturnMessage"] = id.returnMessage(); + i["ReturnMessageEnabled"] = id.returnMessageEnabled(); + i["AutoAwayEnabled"] = id.autoAwayEnabled(); + i["AutoAwayTime"] = id.autoAwayTime(); + i["AutoAwayReason"] = id.autoAwayReason(); + i["AutoAwayReasonEnabled"] = id.autoAwayReasonEnabled(); + i["AutoReturnMessage"] = id.autoReturnMessage(); + i["AutoReturnMessageEnabled"] = id.autoReturnMessageEnabled(); + i["Ident"] = id.ident(); + i["KickReason"] = id.kickReason(); + i["PartReason"] = id.partReason(); + i["QuitReason"] = id.quitReason(); out << i; return out; } @@ -158,7 +348,21 @@ QDataStream &operator>>(QDataStream &in, Identity &id) { id.setRealName(i["RealName"].toString()); id.setNicks(i["Nicks"].toStringList()); id.setAwayNick(i["AwayNick"].toString()); + id.setAwayNickEnabled(i["AwayNickEnabled"].toBool()); id.setAwayReason(i["AwayReason"].toString()); + id.setAwayReasonEnabled(i["AwayReasonEnabled"].toBool()); id.setReturnMessage(i["ReturnMessage"].toString()); + id.setReturnMessageEnabled(i["ReturnMessageEnabled"].toBool()); + id.setAutoAwayEnabled(i["AutoAwayEnabled"].toBool()); + id.setAutoAwayTime(i["AutoAwayTime"].toInt()); + id.setAutoAwayReason(i["AutoAwayReason"].toString()); + id.setAutoAwayReasonEnabled(i["AutoAwayReasonEnabled"].toBool()); + id.setAutoReturnMessage(i["AutoReturnMessage"].toString()); + id.setAutoReturnMessageEnabled(i["AutoReturnMessageEnabled"].toBool()); + id.setIdent(i["Ident"].toString()); + id.setKickReason(i["KickReason"].toString()); + id.setPartReason(i["PartReason"].toString()); + id.setQuitReason(i["QuitReason"].toString()); return in; } + diff --git a/src/common/identity.h b/src/common/identity.h index 66d7153e..3db8a282 100644 --- a/src/common/identity.h +++ b/src/common/identity.h @@ -31,48 +31,106 @@ class Identity : public QObject { Q_OBJECT - Q_PROPERTY(IdentityId identityId READ id STORED false) - Q_PROPERTY(QString identityName READ identityName WRITE setIdentityName STORED false) - Q_PROPERTY(QString realName READ realName WRITE setRealName STORED false) - Q_PROPERTY(QStringList nicks READ nicks WRITE setNicks STORED false) - Q_PROPERTY(QString awayNick READ awayNick WRITE setAwayNick STORED false) - Q_PROPERTY(QString awayReason READ awayReason WRITE setAwayReason STORED false) - Q_PROPERTY(QString returnMessage READ returnMessage WRITE setReturnMessage STORED false) - //Q_PROPERTY( + Q_PROPERTY(IdentityId identityId READ id WRITE setId STORED false); + Q_PROPERTY(QString identityName READ identityName WRITE setIdentityName STORED false); + Q_PROPERTY(QString realName READ realName WRITE setRealName STORED false); + Q_PROPERTY(QStringList nicks READ nicks WRITE setNicks STORED false); + Q_PROPERTY(QString awayNick READ awayNick WRITE setAwayNick STORED false); + Q_PROPERTY(bool awayNickEnabled READ awayNickEnabled WRITE setAwayNickEnabled STORED false); + Q_PROPERTY(QString awayReason READ awayReason WRITE setAwayReason STORED false); + Q_PROPERTY(bool awayReasonEnabled READ awayReasonEnabled WRITE setAwayReasonEnabled STORED false); + Q_PROPERTY(QString returnMessage READ returnMessage WRITE setReturnMessage STORED false); + Q_PROPERTY(bool returnMessageEnabled READ returnMessageEnabled WRITE setReturnMessageEnabled STORED false); + Q_PROPERTY(bool autoAwayEnabled READ autoAwayEnabled WRITE setAutoAwayEnabled STORED false); + Q_PROPERTY(int autoAwayTime READ autoAwayTime WRITE setAutoAwayTime STORED false); + Q_PROPERTY(QString autoAwayReason READ autoAwayReason WRITE setAutoAwayReason STORED false); + Q_PROPERTY(bool autoAwayReasonEnabled READ autoAwayReasonEnabled WRITE setAutoAwayReasonEnabled STORED false); + Q_PROPERTY(QString autoReturnMessage READ autoReturnMessage WRITE setAutoReturnMessage STORED false); + Q_PROPERTY(bool autoReturnMessageEnabled READ autoReturnMessageEnabled WRITE setAutoReturnMessageEnabled STORED false); + Q_PROPERTY(QString ident READ ident WRITE setIdent STORED false); + Q_PROPERTY(QString kickReason READ kickReason WRITE setKickReason STORED false); + Q_PROPERTY(QString partReason READ partReason WRITE setPartReason STORED false); + Q_PROPERTY(QString quitReason READ quitReason WRITE setQuitReason STORED false); public: - Identity(IdentityId id = -1, QObject *parent = 0); + Identity(IdentityId id = 0, QObject *parent = 0); Identity(const Identity &other, QObject *parent = 0); void setToDefaults(); + bool operator==(const Identity &other); + bool operator!=(const Identity &other); + + bool isValid() const; + IdentityId id() const; QString identityName() const; QString realName() const; QStringList nicks() const; QString awayNick() const; + bool awayNickEnabled() const; QString awayReason() const; + bool awayReasonEnabled() const; QString returnMessage() const; + bool returnMessageEnabled() const; + bool autoAwayEnabled() const; + int autoAwayTime() const; + QString autoAwayReason() const; + bool autoAwayReasonEnabled() const; + QString autoReturnMessage() const; + bool autoReturnMessageEnabled() const; + QString ident() const; + QString kickReason() const; + QString partReason() const; + QString quitReason() const; bool initialized() const; void setInitialized(); public slots: + void setId(IdentityId id); void setIdentityName(const QString &name); void setRealName(const QString &realName); void setNicks(const QStringList &nicks); void setAwayNick(const QString &awayNick); + void setAwayNickEnabled(bool enabled); void setAwayReason(const QString &awayReason); + void setAwayReasonEnabled(bool enabled); void setReturnMessage(const QString &returnMessage); + void setReturnMessageEnabled(bool enabled); + void setAutoAwayEnabled(bool enabled); + void setAutoAwayTime(int time); + void setAutoAwayReason(const QString &reason); + void setAutoAwayReasonEnabled(bool enabled); + void setAutoReturnMessage(const QString &message); + void setAutoReturnMessageEnabled(bool enabled); + void setIdent(const QString &ident); + void setKickReason(const QString &reason); + void setPartReason(const QString &reason); + void setQuitReason(const QString &reason); void update(const Identity &other); signals: + void idSet(IdentityId id); void identityNameSet(const QString &name); void realNameSet(const QString &realName); void nicksSet(const QStringList &nicks); void awayNickSet(const QString &awayNick); + void awayNickEnabledSet(bool); void awayReasonSet(const QString &awayReason); + void awayReasonEnabledSet(bool); void returnMessageSet(const QString &returnMessage); + void returnMessageEnabledSet(bool); + void autoAwayEnabledSet(bool); + void autoAwayTimeSet(int); + void autoAwayReasonSet(const QString &); + void autoAwayReasonEnabledSet(bool); + void autoReturnMessageSet(const QString &); + void autoReturnMessageEnabledSet(bool); + void identSet(const QString &); + void kickReasonSet(const QString &); + void partReasonSet(const QString &); + void quitReasonSet(const QString &); void updatedRemotely(); @@ -81,7 +139,19 @@ class Identity : public QObject { IdentityId _identityId; QString _identityName, _realName; QStringList _nicks; - QString _awayNick, _awayReason, _returnMessage; + QString _awayNick; + bool _awayNickEnabled; + QString _awayReason; + bool _awayReasonEnabled; + QString _returnMessage; + bool _returnMessageEnabled; + bool _autoAwayEnabled; + int _autoAwayTime; + QString _autoAwayReason; + bool _autoAwayReasonEnabled; + QString _autoReturnMessage; + bool _autoReturnMessageEnabled; + QString _ident, _kickReason, _partReason, _quitReason; void init(); diff --git a/src/common/main.cpp b/src/common/main.cpp index 5251acde..7fa59aaa 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -22,6 +22,7 @@ #include "identity.h" #include "settings.h" #include +#include #include #if defined BUILD_CORE @@ -106,7 +107,9 @@ int main(int argc, char **argv) { #ifndef BUILD_CORE QtUi *gui = new QtUi(); Client::init(gui); - gui->init(); + // init gui only after the event loop has started + QTimer::singleShot(0, gui, SLOT(init())); + //gui->init(); #endif #ifndef BUILD_QTUI diff --git a/src/common/signalproxy.cpp b/src/common/signalproxy.cpp index 5393cff3..03861d36 100644 --- a/src/common/signalproxy.cpp +++ b/src/common/signalproxy.cpp @@ -253,6 +253,7 @@ void SignalProxy::removePeerBySender() { // OK we're brutal here... but since it's a private slot we know what we've got connected to it... QIODevice *ioDev = (QIODevice *)(sender()); removePeer(ioDev); + qDebug() << "Client disconnected."; } void SignalProxy::objectRenamed(QString oldname, QString newname) { diff --git a/src/common/types.h b/src/common/types.h index 05fdf2cf..b0dd0d13 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -28,7 +28,8 @@ typedef uint UserId; //!< Identifies a core user. typedef uint MsgId; //!< Identifies a message. typedef uint BufferId; //!< Identifies a buffer. typedef uint NetworkId; //!< Identifies an IRC Network. -typedef quint32 IdentityId; //!< Identifies an identity. +// IdentityId must be signed! +typedef qint32 IdentityId; //!< Identifies an identity. //! Base class for exceptions. struct Exception { diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index cffb3757..cd75f660 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -46,30 +46,27 @@ CoreSession::CoreSession(UserId uid, Storage *_storage, QObject *parent) CoreUserSettings s(user); sessionData = s.sessionData(); -/* - CoreSettings cs; - foreach(QString id, cs.localChildKeys(QString("Identities/%1").arg(user))) { - Identity *i = new Identity(cs.localValue(QString("Identities/%1/%2").arg(user).arg(id)).value(), this); - if(i->id() < 1) { +#ifdef SPUTDEV + foreach(IdentityId id, s.identityIds()) { + Identity *i = new Identity(s.identity(id), this); + if(!i->isValid()) { qDebug() << QString("Invalid identity!"); + delete i; continue; } if(_identities.contains(i->id())) { qDebug() << "Duplicate identity, ignoring!"; + delete i; continue; } - qDebug() << "loaded identity" << id; _identities[i->id()] = i; } - s.endGroup(); - mutex.unlock(); if(!_identities.count()) { Identity i(1); i.setToDefaults(); - //_identities[i->id()] = i; - createOrUpdateIdentity(i); + createIdentity(i); } - */ +#endif p->attachSlot(SIGNAL(requestNetworkStates()), this, SLOT(serverStateRequested())); p->attachSlot(SIGNAL(requestConnect(QString)), this, SLOT(connectToNetwork(QString))); @@ -85,8 +82,8 @@ CoreSession::CoreSession(UserId uid, Storage *_storage, QObject *parent) p->attachSignal(this, SIGNAL(identityCreated(const Identity &))); p->attachSignal(this, SIGNAL(identityRemoved(IdentityId))); - p->attachSlot(SIGNAL(createIdentity(const Identity &)), this, SLOT(createOrUpdateIdentity(const Identity &))); - p->attachSlot(SIGNAL(updateIdentity(const Identity &)), this, SLOT(createOrUpdateIdentity(const Identity &))); + p->attachSlot(SIGNAL(createIdentity(const Identity &)), this, SLOT(createIdentity(const Identity &))); + p->attachSlot(SIGNAL(updateIdentity(const Identity &)), this, SLOT(updateIdentity(const Identity &))); p->attachSlot(SIGNAL(removeIdentity(IdentityId)), this, SLOT(removeIdentity(IdentityId))); initScriptEngine(); @@ -300,27 +297,39 @@ void CoreSession::scriptRequest(QString script) { emit scriptResult(scriptEngine->evaluate(script).toString()); } -void CoreSession::createOrUpdateIdentity(const Identity &id) { +void CoreSession::createIdentity(const Identity &id) { + // find free ID + int i; + for(i = 1; i <= _identities.count(); i++) { + if(!_identities.keys().contains(i)) break; + } + //qDebug() << "found free id" << i; + Identity *newId = new Identity(id, this); + newId->setId(i); + _identities[i] = newId; + signalProxy()->synchronize(newId); + CoreUserSettings s(user); + s.storeIdentity(*newId); + emit identityCreated(i); +} + +void CoreSession::updateIdentity(const Identity &id) { if(!_identities.contains(id.id())) { - // create new - _identities[id.id()] = new Identity(id, this); - signalProxy()->synchronize(_identities[id.id()]); - emit identityCreated(id.id()); - } else { - // update - _identities[id.id()]->update(id); + qWarning() << "Update request for unknown identity received!"; + return; } -/* - CoreSettings s; - s.beginGroup(QString("Identities/%1").arg(user)); - s.setValue(QString::number(id.id()), QVariant::fromValue(*_identities[id.id()])); - s.endGroup();*/ + _identities[id.id()]->update(id); + + CoreUserSettings s(user); + s.storeIdentity(id); } void CoreSession::removeIdentity(IdentityId id) { Identity *i = _identities.take(id); if(i) { emit identityRemoved(id); + CoreUserSettings s(user); + s.removeIdentity(id); i->deleteLater(); } } diff --git a/src/core/coresession.h b/src/core/coresession.h index 32e34ec5..2f457012 100644 --- a/src/core/coresession.h +++ b/src/core/coresession.h @@ -72,10 +72,15 @@ public slots: void sendBacklog(BufferInfo, QVariant, QVariant); void msgFromGui(BufferInfo, QString message); - //! Create or update an identity and propagate the changes to the clients. - /** \param identity The identity to be created/updated. + //! Create an identity and propagate the changes to the clients. + /** \param identity The identity to be created. */ - void createOrUpdateIdentity(const Identity &identity); + void createIdentity(const Identity &identity); + + //! Update an identity and propagate the changes to the clients. + /** \param identity The identity to be updated. + */ + void updateIdentity(const Identity &identity); //! Remove identity and propagate that fact to the clients. /** \param identity The identity to be removed. diff --git a/src/core/coresettings.h b/src/core/coresettings.h index 551a971b..0e204d11 100644 --- a/src/core/coresettings.h +++ b/src/core/coresettings.h @@ -41,4 +41,4 @@ class CoreSettings : public Settings { }; -#endif /*CORESETTINGS_H_*/ +#endif /*_CORESETTINGS_H_*/ diff --git a/src/core/coreusersettings.cpp b/src/core/coreusersettings.cpp index 49a98374..277b7ad7 100644 --- a/src/core/coreusersettings.cpp +++ b/src/core/coreusersettings.cpp @@ -25,8 +25,29 @@ CoreUserSettings::CoreUserSettings(UserId uid) : CoreSettings(QString("CoreUser/ } +void CoreUserSettings::storeIdentity(const Identity &identity) { + setLocalValue(QString("Identities/%1").arg(identity.id()), QVariant::fromValue(identity)); +} + +void CoreUserSettings::removeIdentity(const Identity &identity) { + removeLocalKey(QString("Identities/%1").arg(identity.id())); +} +Identity CoreUserSettings::identity(IdentityId id) { + QVariant v = localValue(QString("Identities/%1").arg(id)); + if(qVariantCanConvert(v)) { + return v.value(); + } + return Identity(); +} +QList CoreUserSettings::identityIds() { + QList res; + foreach(QString id, localChildKeys("Identities")) { + res << id.toUInt(); + } + return res; +} QVariantMap CoreUserSettings::sessionData() { QVariantMap res; diff --git a/src/core/coreusersettings.h b/src/core/coreusersettings.h index 4a8621d8..eee2e573 100644 --- a/src/core/coreusersettings.h +++ b/src/core/coreusersettings.h @@ -32,9 +32,11 @@ class CoreUserSettings : public CoreSettings { public: CoreUserSettings(UserId user); - void setIdentity(const Identity &identity); - Identity identity(IdentityId id); + void storeIdentity(const Identity &identity); + void removeIdentity(const Identity &identity); + Identity identity(IdentityId id); + QList identityIds(); private: // this stuff should only be accessed by CoreSession! diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 672938df..d7c3bbac 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -123,7 +123,9 @@ void MainWin::init() { ui.menuViews->addAction(dock->toggleViewAction()); - //showSettingsDlg(); +#ifdef SPUTDEV + showSettingsDlg(); +#endif } @@ -180,7 +182,7 @@ void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, view->setFilteredModel(model, mode, nets); Client::networkModel()->synchronizeView(view); dock->setWidget(view); - + addDockWidget(Qt::LeftDockWidgetArea, dock); ui.menuViews->addAction(dock->toggleViewAction()); @@ -189,8 +191,9 @@ void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, void MainWin::setupSettingsDlg() { settingsDlg->registerSettingsPage(new FontsSettingsPage(settingsDlg)); +#ifdef SPUTDEV settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg)); - +#endif } void MainWin::connectedToCore() { diff --git a/src/qtui/qtui.h b/src/qtui/qtui.h index 93e94576..f6f1db5b 100644 --- a/src/qtui/qtui.h +++ b/src/qtui/qtui.h @@ -36,11 +36,14 @@ class QtUi : public AbstractUi { public: QtUi(); ~QtUi(); - void init(); + //void init(); AbstractUiMsg *layoutMsg(const Message &); static QtUiStyle *style(); + public slots: + void init(); + protected slots: void connectedToCore(); void disconnectedFromCore(); diff --git a/src/qtui/settingsdlg.cpp b/src/qtui/settingsdlg.cpp index 66a646bc..6c7d24a4 100644 --- a/src/qtui/settingsdlg.cpp +++ b/src/qtui/settingsdlg.cpp @@ -22,6 +22,7 @@ SettingsDlg::SettingsDlg(QWidget *parent) : QDialog(parent) { ui.setupUi(this); + _currentPage = 0; //ui.settingsFrame->setWidgetResizable(true); //ui.settingsFrame->setWidget(ui.settingsStack); @@ -31,10 +32,14 @@ SettingsDlg::SettingsDlg(QWidget *parent) : QDialog(parent) { connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); } +SettingsPage *SettingsDlg::currentPage() const { + return _currentPage; +} void SettingsDlg::registerSettingsPage(SettingsPage *sp) { sp->setParent(ui.settingsStack); ui.settingsStack->addWidget(sp); + connect(sp, SIGNAL(changed(bool)), this, SLOT(setButtonStates())); QTreeWidgetItem *cat; QList cats = ui.settingsTree->findItems(sp->category(), Qt::MatchExactly); @@ -51,12 +56,17 @@ void SettingsDlg::registerSettingsPage(SettingsPage *sp) { } void SettingsDlg::selectPage(const QString &cat, const QString &title) { - QWidget *w = pages[QString("%1$%2").arg(cat, title)]; - Q_ASSERT(w); - ui.settingsStack->setCurrentWidget(w); + SettingsPage *sp = pages[QString("%1$%2").arg(cat, title)]; + Q_ASSERT(sp); // FIXME allow for invalid settings pages + ui.settingsStack->setCurrentWidget(sp); + _currentPage = sp; + setButtonStates(); } void SettingsDlg::itemSelected() { + // Check if we have changed anything... + // TODO + QList items = ui.settingsTree->selectedItems(); if(!items.count()) { return; @@ -70,11 +80,17 @@ void SettingsDlg::itemSelected() { } } +void SettingsDlg::setButtonStates() { + SettingsPage *sp = currentPage(); + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(sp && sp->hasChanged()); + ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(sp && sp->hasChanged()); + ui.buttonBox->button(QDialogButtonBox::Reset)->setEnabled(sp && sp->hasChanged()); +} + void SettingsDlg::buttonClicked(QAbstractButton *button) { switch(ui.buttonBox->standardButton(button)) { case QDialogButtonBox::Ok: - applyChanges(); - accept(); + if(applyChanges()) accept(); break; case QDialogButtonBox::Apply: applyChanges(); @@ -93,12 +109,16 @@ void SettingsDlg::buttonClicked(QAbstractButton *button) { } } -void SettingsDlg::applyChanges() { - foreach(SettingsPage *page, pages.values()) { - page->save(); +bool SettingsDlg::applyChanges() { + if(!currentPage()) return false; + if(currentPage()->aboutToSave()) { + currentPage()->save(); + return true; } + return false; } +// TODO add messagebox void SettingsDlg::reload() { SettingsPage *page = qobject_cast(ui.settingsStack->currentWidget()); if(page) page->load(); diff --git a/src/qtui/settingsdlg.h b/src/qtui/settingsdlg.h index d3cc96d1..ca15811d 100644 --- a/src/qtui/settingsdlg.h +++ b/src/qtui/settingsdlg.h @@ -33,19 +33,23 @@ class SettingsDlg : public QDialog { void registerSettingsPage(SettingsPage *); void unregisterSettingsPage(SettingsPage *); + SettingsPage *currentPage() const; + public slots: void selectPage(const QString &category, const QString &title); private slots: void itemSelected(); void buttonClicked(QAbstractButton *); - void applyChanges(); + bool applyChanges(); void reload(); void loadDefaults(); + void setButtonStates(); private: Ui::SettingsDlg ui; + SettingsPage *_currentPage; QHash pages; }; diff --git a/src/qtui/settingspages/createidentitydlg.ui b/src/qtui/settingspages/createidentitydlg.ui new file mode 100644 index 00000000..522f09f0 --- /dev/null +++ b/src/qtui/settingspages/createidentitydlg.ui @@ -0,0 +1,143 @@ + + CreateIdentityDlg + + + Qt::WindowModal + + + + 0 + 0 + 399 + 135 + + + + Create New Identity + + + + + + + + Identity name: + + + + + + + + + + + + Create blank identity + + + true + + + + + + + + + Duplicate: + + + + + + + false + + + + 0 + 0 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + CreateIdentityDlg + accept() + + + 222 + 127 + + + 157 + 134 + + + + + buttonBox + rejected() + CreateIdentityDlg + reject() + + + 290 + 127 + + + 286 + 134 + + + + + duplicateIdentity + toggled(bool) + identityList + setEnabled(bool) + + + 55 + 80 + + + 166 + 84 + + + + + diff --git a/src/qtui/settingspages/identitiessettingspage.cpp b/src/qtui/settingspages/identitiessettingspage.cpp index 49796b04..2817b84b 100644 --- a/src/qtui/settingspages/identitiessettingspage.cpp +++ b/src/qtui/settingspages/identitiessettingspage.cpp @@ -18,6 +18,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include + #include "identitiessettingspage.h" #include "client.h" @@ -28,28 +30,358 @@ IdentitiesSettingsPage::IdentitiesSettingsPage(QWidget *parent) ui.setupUi(this); setEnabled(false); // need a core connection! connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), this, SLOT(coreConnectionStateChanged(bool))); + connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(clientIdentityCreated(IdentityId))); + connect(Client::instance(), SIGNAL(identityRemoved(IdentityId)), this, SLOT(clientIdentityRemoved(IdentityId))); + + currentId = 0; + + // We need to know whenever the state of input widgets changes... + //connect(ui.identityList, SIGNAL(editTextChanged(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.realName, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.nicknameList, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(widgetHasChanged())); + connect(ui.awayNick, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.awayNickEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.awayReason, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.awayReasonEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.returnMessage, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.returnMessageEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.autoAwayEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.autoAwayTime, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged())); + connect(ui.autoAwayReason, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.autoAwayReasonEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.autoReturnMessage, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.autoReturnMessageEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.ident, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.kickReason, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.partReason, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.quitReason, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); } void IdentitiesSettingsPage::coreConnectionStateChanged(bool state) { - //this->setEnabled(state); + this->setEnabled(state); if(state) { load(); + } else { + // reset + currentId = 0; } } -bool IdentitiesSettingsPage::hasChanged() const { - return true; -} - void IdentitiesSettingsPage::save() { + setEnabled(false); + QList toCreate, toUpdate; + // we need to remove our temporarily created identities. + // these are going to be re-added after the core has propagated them back... + for(QHash::iterator i = identities.begin(); i != identities.end(); ++i) { + if((*i)->id() < 0) { + Identity *temp = *i; + i = identities.erase(i); + toCreate.append(temp); + ui.identityList->removeItem(ui.identityList->findData(temp->id())); + } else { + if(**i != *Client::identity((*i)->id())) { + toUpdate.append(*i); + } + } + } + SaveIdentitiesDlg dlg(toCreate, toUpdate, deletedIdentities, this); + int ret = dlg.exec(); + if(ret == QDialog::Rejected) { + // canceled -> reload everything to be safe + load(); + } + foreach(Identity *id, toCreate) { + id->deleteLater(); + } + changeState(false); + setEnabled(true); } void IdentitiesSettingsPage::load() { - + currentId = 0; + foreach(Identity *identity, identities.values()) { + identity->deleteLater(); + } + identities.clear(); + deletedIdentities.clear(); + changedIdentities.clear(); + ui.identityList->clear(); + foreach(IdentityId id, Client::identityIds()) { + clientIdentityCreated(id); + } + changeState(false); } void IdentitiesSettingsPage::defaults() { + // TODO implement bool hasDefaults() +} + +void IdentitiesSettingsPage::widgetHasChanged() { + bool changed = testHasChanged(); + if(changed != hasChanged()) changeState(changed); +} + +bool IdentitiesSettingsPage::testHasChanged() { + if(deletedIdentities.count()) return true; + if(currentId < 0) { + return true; // new identity + } else { + changedIdentities.removeAll(currentId); + Identity temp(currentId, this); + saveToIdentity(&temp); + if(temp != *identities[currentId]) changedIdentities.append(currentId); + return changedIdentities.count(); + } +} + +bool IdentitiesSettingsPage::aboutToSave() { + saveToIdentity(identities[currentId]); + QList errors; + foreach(Identity *id, identities.values()) { + if(id->identityName().isEmpty()) errors.append(1); + if(!id->nicks().count()) errors.append(2); + if(id->realName().isEmpty()) errors.append(3); + if(id->ident().isEmpty()) errors.append(4); + } + if(!errors.count()) return true; + QString error(tr("The following problems need to be corrected before your changes can be applied:
    ")); + if(errors.contains(1)) error += tr("
  • All identities need an identity name set
  • "); + if(errors.contains(2)) error += tr("
  • Every identity needs at least one nickname defined
  • "); + if(errors.contains(3)) error += tr("
  • You need to specify a real name for every identity
  • "); + if(errors.contains(4)) error += tr("
  • You need to specify an ident for every identity
  • "); + error += tr("
"); + QMessageBox::warning(this, tr("One or more identities are invalid"), error); + return false; +} + +void IdentitiesSettingsPage::clientIdentityCreated(IdentityId id) { + insertIdentity(new Identity(*Client::identity(id), this)); + connect(Client::identity(id), SIGNAL(updatedRemotely()), this, SLOT(clientIdentityUpdated())); +} + +void IdentitiesSettingsPage::clientIdentityUpdated() { + Identity *identity = qobject_cast(sender()); + if(!identity) { + qWarning() << "Invalid identity to update!"; + return; + } + if(!identities.contains(identity->id())) { + qWarning() << "Unknown identity to update:" << identity->identityName(); + return; + } + identities[identity->id()]->update(*identity); + ui.identityList->setItemText(ui.identityList->findData(identity->id()), identity->identityName()); + if(identity->id() == currentId) displayIdentity(identity, true); +} + +void IdentitiesSettingsPage::clientIdentityRemoved(IdentityId id) { + if(identities.contains(id)) { + removeIdentity(identities[id]); + changedIdentities.removeAll(id); + deletedIdentities.removeAll(id); + } +} + +void IdentitiesSettingsPage::insertIdentity(Identity *identity) { + IdentityId id = identity->id(); + identities[id] = identity; + if(id == 1) { + // default identity is always the first one! + ui.identityList->insertItem(0, identity->identityName(), id); + } else { + QString name = identity->identityName(); + for(int j = 0; j < ui.identityList->count(); j++) { + if((j>0 || ui.identityList->itemData(0).toInt() != 1) && name.localeAwareCompare(ui.identityList->itemText(j)) < 0) { + ui.identityList->insertItem(j, name, id); + widgetHasChanged(); + return; + } + } + // append + ui.identityList->insertItem(ui.identityList->count(), name, id); + widgetHasChanged(); + } +} + +void IdentitiesSettingsPage::removeIdentity(Identity *id) { + ui.identityList->removeItem(ui.identityList->findData(id->id())); + identities.remove(id->id()); + id->deleteLater(); + widgetHasChanged(); +} + +void IdentitiesSettingsPage::on_identityList_currentIndexChanged(int index) { + if(index < 0) { + //ui.identityList->setEditable(false); + displayIdentity(0); + } else { + IdentityId id = ui.identityList->itemData(index).toInt(); + if(identities.contains(id)) displayIdentity(identities[id]); + ui.deleteIdentity->setEnabled(id != 1); // default identity cannot be deleted + //ui.identityList->setEditable(id != 1); // ...or renamed + } +} + +void IdentitiesSettingsPage::displayIdentity(Identity *id, bool dontsave) { + if(currentId != 0 && !dontsave && identities.contains(currentId)) { + saveToIdentity(identities[currentId]); + } + if(id) { + currentId = id->id(); + ui.realName->setText(id->realName()); + ui.nicknameList->clear(); + ui.nicknameList->addItems(id->nicks()); + //for(int i = 0; i < ui.nicknameList->count(); i++) { + // ui.nicknameList->item(i)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled); + //} + if(ui.nicknameList->count()) ui.nicknameList->setCurrentRow(0); + ui.awayNick->setText(id->awayNick()); + ui.awayNickEnabled->setChecked(id->awayNickEnabled()); + ui.awayReason->setText(id->awayReason()); + ui.awayReasonEnabled->setChecked(id->awayReasonEnabled()); + ui.returnMessage->setText(id->returnMessage()); + ui.returnMessageEnabled->setChecked(id->returnMessageEnabled()); + ui.autoAwayEnabled->setChecked(id->autoAwayEnabled()); + ui.autoAwayTime->setValue(id->autoAwayTime()); + ui.autoAwayReason->setText(id->autoAwayReason()); + ui.autoAwayReasonEnabled->setChecked(id->autoAwayReasonEnabled()); + ui.autoReturnMessage->setText(id->autoReturnMessage()); + ui.autoReturnMessageEnabled->setChecked(id->autoReturnMessageEnabled()); + ui.ident->setText(id->ident()); + ui.kickReason->setText(id->kickReason()); + ui.partReason->setText(id->partReason()); + ui.quitReason->setText(id->quitReason()); + } +} + +void IdentitiesSettingsPage::saveToIdentity(Identity *id) { + id->setIdentityName(ui.identityList->currentText()); + id->setRealName(ui.realName->text()); + QStringList nicks; + for(int i = 0; i < ui.nicknameList->count(); i++) { + nicks << ui.nicknameList->item(i)->text(); + } + id->setNicks(nicks); + id->setAwayNick(ui.awayNick->text()); + id->setAwayNickEnabled(ui.awayNickEnabled->isChecked()); + id->setAwayReason(ui.awayReason->text()); + id->setAwayReasonEnabled(ui.awayReasonEnabled->isChecked()); + id->setReturnMessage(ui.returnMessage->text()); + id->setReturnMessageEnabled(ui.returnMessageEnabled->isChecked()); + id->setAutoAwayEnabled(ui.autoAwayEnabled->isChecked()); + id->setAutoAwayTime(ui.autoAwayTime->value()); + id->setAutoAwayReason(ui.autoAwayReason->text()); + id->setAutoAwayReasonEnabled(ui.autoAwayReasonEnabled->isChecked()); + id->setAutoReturnMessage(ui.autoReturnMessage->text()); + id->setAutoReturnMessageEnabled(ui.autoReturnMessageEnabled->isChecked()); + id->setIdent(ui.ident->text()); + id->setKickReason(ui.kickReason->text()); + id->setPartReason(ui.partReason->text()); + id->setQuitReason(ui.quitReason->text()); +} + +void IdentitiesSettingsPage::on_addIdentity_clicked() { + CreateIdentityDlg dlg(ui.identityList->model(), this); + if(dlg.exec() == QDialog::Accepted) { + // find a free (negative) ID + IdentityId id; + for(id = 1; id <= identities.count(); id++) { + if(!identities.keys().contains(-id)) break; + } + id *= -1; + Identity *newId = new Identity(id, this); + if(dlg.duplicateId() != 0) { + // duplicate + newId->update(*identities[dlg.duplicateId()]); + newId->setId(id); + } + newId->setIdentityName(dlg.identityName()); + identities[id] = newId; + insertIdentity(newId); + ui.identityList->setCurrentIndex(ui.identityList->findData(id)); + widgetHasChanged(); + } +} + +void IdentitiesSettingsPage::on_deleteIdentity_clicked() { + Identity *id = identities[currentId]; + int ret = QMessageBox::question(this, tr("Delete Identity?"), + tr("Do you really want to delete identity \"%1\"?").arg(id->identityName()), + QMessageBox::Yes|QMessageBox::No, QMessageBox::No); + if(ret != QMessageBox::Yes) return; + if(id->id() > 0) deletedIdentities.append(id->id()); + removeIdentity(id); +} + +void IdentitiesSettingsPage::on_identityList_editTextChanged(const QString &text) { + ui.identityList->setItemText(ui.identityList->currentIndex(), text); +} + +/*****************************************************************************************/ + +CreateIdentityDlg::CreateIdentityDlg(QAbstractItemModel *model, QWidget *parent) : QDialog(parent) { + ui.setupUi(this); + + ui.identityList->setModel(model); // now we use the identity list of the main page... Trolltech <3 + on_identityName_textChanged(""); // disable ok button :) +} + +QString CreateIdentityDlg::identityName() const { + return ui.identityName->text(); +} + +IdentityId CreateIdentityDlg::duplicateId() const { + if(!ui.duplicateIdentity->isChecked()) return 0; + if(ui.identityList->currentIndex() >= 0) { + return ui.identityList->itemData(ui.identityList->currentIndex()).toInt(); + } + return 0; +} + +void CreateIdentityDlg::on_identityName_textChanged(const QString &text) { + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(text.count()); + +} + +/*********************************************************************************************/ + +SaveIdentitiesDlg::SaveIdentitiesDlg(QList tocreate, QList toupdate, QList toremove, QWidget *parent) + : QDialog(parent), toCreate(tocreate), toUpdate(toupdate), toRemove(toremove) { + ui.setupUi(this); + numevents = toCreate.count() + toUpdate.count() + toRemove.count(); + rcvevents = 0; + if(numevents) { + ui.progressBar->setMaximum(numevents); + ui.progressBar->setValue(0); + + connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(clientEvent())); + connect(Client::instance(), SIGNAL(identityRemoved(IdentityId)), this, SLOT(clientEvent())); + + foreach(Identity *id, toCreate) { + Client::createIdentity(*id); + } + foreach(Identity *id, toUpdate) { + const Identity *cid = Client::identity(id->id()); + if(!cid) { + qWarning() << "Invalid client identity!"; + numevents--; + continue; + } + connect(cid, SIGNAL(updatedRemotely()), this, SLOT(clientEvent())); + Client::updateIdentity(*id); + } + foreach(IdentityId id, toRemove) { + Client::removeIdentity(id); + } + } else { + qWarning() << "Sync dialog called without stuff to change!"; + accept(); + } +} +void SaveIdentitiesDlg::clientEvent() { + ui.progressBar->setValue(++rcvevents); + if(rcvevents >= numevents) accept(); } diff --git a/src/qtui/settingspages/identitiessettingspage.h b/src/qtui/settingspages/identitiessettingspage.h index ea43c8c4..0e21662a 100644 --- a/src/qtui/settingspages/identitiessettingspage.h +++ b/src/qtui/settingspages/identitiessettingspage.h @@ -21,9 +21,14 @@ #ifndef _IDENTITIESSETTINGSPAGE_H_ #define _IDENTITIESSETTINGSPAGE_H_ +#include "identity.h" #include "settingspage.h" #include "ui_identitiessettingspage.h" +#include "ui_createidentitydlg.h" +#include "ui_saveidentitiesdlg.h" + +class QAbstractItemModel; class IdentitiesSettingsPage : public SettingsPage { Q_OBJECT @@ -31,7 +36,7 @@ class IdentitiesSettingsPage : public SettingsPage { public: IdentitiesSettingsPage(QWidget *parent = 0); - bool hasChanged() const; + bool aboutToSave(); public slots: void save(); @@ -40,10 +45,68 @@ class IdentitiesSettingsPage : public SettingsPage { private slots: void coreConnectionStateChanged(bool); + void clientIdentityCreated(IdentityId); + void clientIdentityUpdated(); + void clientIdentityRemoved(IdentityId); + + void on_identityList_currentIndexChanged(int index); + void on_identityList_editTextChanged(const QString &); + + void on_addIdentity_clicked(); + void on_deleteIdentity_clicked(); + + void widgetHasChanged(); private: Ui::IdentitiesSettingsPage ui; + QHash identities; + IdentityId currentId; + + QList changedIdentities; // for setting the widget changed state + QList deletedIdentities; + + void insertIdentity(Identity *identity); + void removeIdentity(Identity *identity); + void displayIdentity(Identity *, bool dontsave = false); + void saveToIdentity(Identity *); + + bool testHasChanged(); +}; + +class CreateIdentityDlg : public QDialog { + Q_OBJECT + + public: + CreateIdentityDlg(QAbstractItemModel *model, QWidget *parent = 0); + + QString identityName() const; + IdentityId duplicateId() const; + + private slots: + void on_identityName_textChanged(const QString &text); + + private: + Ui::CreateIdentityDlg ui; +}; + +class SaveIdentitiesDlg : public QDialog { + Q_OBJECT + + public: + SaveIdentitiesDlg(QList toCreate, QList toUpdate, QList toRemove, QWidget *parent = 0); + + private slots: + void clientEvent(); + + private: + Ui::SaveIdentitiesDlg ui; + + QList toCreate, toUpdate; + QList toRemove; + + int numevents, rcvevents; + }; #endif diff --git a/src/qtui/settingspages/identitiessettingspage.ui b/src/qtui/settingspages/identitiessettingspage.ui index 19bb198f..fdd03e7a 100644 --- a/src/qtui/settingspages/identitiessettingspage.ui +++ b/src/qtui/settingspages/identitiessettingspage.ui @@ -16,7 +16,14 @@ - + + + QComboBox::InsertAtBottom + + + true + + @@ -37,22 +44,6 @@ - - - - ... - - - :/22x22/actions/oxygen/22x22/actions/user-properties.png - - - - 22 - 22 - - - - @@ -316,30 +307,42 @@ 6 - + + + false + + - + Away Reason - + + + false + + - + Return Message - + + + false + + - + Away Nick @@ -348,7 +351,7 @@ - + Auto Away @@ -444,21 +447,21 @@ 6 - + Return Message - + Away Reason - + @@ -585,5 +588,86 @@ - + + + awayNickEnabled + toggled(bool) + awayNick + setEnabled(bool) + + + 47 + 85 + + + 185 + 90 + + + + + awayReasonEnabled + toggled(bool) + awayReason + setEnabled(bool) + + + 57 + 120 + + + 177 + 123 + + + + + returnMessageEnabled + toggled(bool) + returnMessage + setEnabled(bool) + + + 85 + 154 + + + 240 + 160 + + + + + autoAwayReasonEnabled + toggled(bool) + autoAwayReason + setEnabled(bool) + + + 107 + 262 + + + 186 + 264 + + + + + autoReturnMessageEnabled + toggled(bool) + autoReturnMessage + setEnabled(bool) + + + 122 + 292 + + + 204 + 299 + + + + diff --git a/src/qtui/settingspages/saveidentitiesdlg.ui b/src/qtui/settingspages/saveidentitiesdlg.ui new file mode 100644 index 00000000..c0b33038 --- /dev/null +++ b/src/qtui/settingspages/saveidentitiesdlg.ui @@ -0,0 +1,124 @@ + + SaveIdentitiesDlg + + + + 0 + 0 + 246 + 104 + + + + Sync With Core + + + + + + Syncing data with core, please wait... + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + 0 + + + 0 + + + false + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Abort + + + :/22x22/actions/oxygen/22x22/actions/dialog-cancel.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + abort + clicked() + SaveIdentitiesDlg + reject() + + + 122 + 85 + + + 122 + 51 + + + + + diff --git a/src/qtui/settingspages/settingspages.pri b/src/qtui/settingspages/settingspages.pri index 8aec6ed3..2e007c9d 100644 --- a/src/qtui/settingspages/settingspages.pri +++ b/src/qtui/settingspages/settingspages.pri @@ -4,4 +4,4 @@ SETTINGSPAGES = fonts identities SP_SRCS = SP_HDRS = -SP_FRMS = +SP_FRMS = createidentitydlg.ui saveidentitiesdlg.ui diff --git a/src/uisupport/settingspage.cpp b/src/uisupport/settingspage.cpp index dd29e7e5..8b8e423a 100644 --- a/src/uisupport/settingspage.cpp +++ b/src/uisupport/settingspage.cpp @@ -34,11 +34,22 @@ QString SettingsPage::title() const { return _title; } +bool SettingsPage::hasChanged() const { + return _changed; +} + +bool SettingsPage::aboutToSave() { + return true; +} + void SettingsPage::changed() { - _changed = true; - emit changed(true); + changeState(true); } void SettingsPage::changeState(bool hasChanged) { - if(hasChanged != _changed) emit changed(hasChanged); + if(hasChanged != _changed) { + _changed = hasChanged; + emit changed(hasChanged); + } } + diff --git a/src/uisupport/settingspage.h b/src/uisupport/settingspage.h index 926d4d71..2d73e823 100644 --- a/src/uisupport/settingspage.h +++ b/src/uisupport/settingspage.h @@ -33,7 +33,13 @@ class SettingsPage : public QWidget { virtual QString category() const; virtual QString title() const; - virtual bool hasChanged() const = 0; + bool hasChanged() const; + + //! Called immediately before save() is called. + /** Derived classes should return false if saving is not possible (e.g. the current settings are invalid). + * \return false, if the SettingsPage cannot be saved in its current state. + */ + virtual bool aboutToSave(); public slots: virtual void save() = 0; @@ -41,7 +47,7 @@ class SettingsPage : public QWidget { virtual void defaults() = 0; protected slots: - //! Calling this slot is equivalent to emitting changed(true). + //! Calling this slot is equivalent to calling changeState(true). void changed(); protected: @@ -49,6 +55,7 @@ class SettingsPage : public QWidget { void changeState(bool hasChanged = true); signals: + //! Emitted whenever the widget state changes. void changed(bool hasChanged); private: -- 2.20.1