From: Manuel Nickschas Date: Tue, 8 Jan 2008 22:32:31 +0000 (+0000) Subject: _Almost_ finished the identity dialog (which is still not used and not visible yet... X-Git-Tag: 0.2.0-alpha1~239 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=2e6dc76ae100a6b8e1b1661e422995f90083500e _Almost_ finished the identity dialog (which is still not used and not visible yet ;-). What a bugfixing orgy that was until I had sorted out all the issues with managing, syncing and editing identities in both client and server... now only some more tweaks and tests, and that baby should be outta house! Committing just in case -- commit early, commit often... --- diff --git a/Quassel.kdevelop.filelist b/Quassel.kdevelop.filelist index 9f4e17e9..64f0c642 100644 --- a/Quassel.kdevelop.filelist +++ b/Quassel.kdevelop.filelist @@ -180,6 +180,7 @@ src/qtui/settingspages/identitiessettingspage.cpp src/qtui/settingspages/identitiessettingspage.h src/qtui/settingspages/identitiessettingspage.ui src/qtui/settingspages/networkssettingspage.ui +src/qtui/settingspages/saveidentitiesdlg.ui src/qtui/settingspages/servereditdlg.ui src/qtui/settingspages/settingspages.pri src/qtui/topicwidget.cpp diff --git a/src/client/client.cpp b/src/client/client.cpp index 55fccf23..fe848448 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -387,10 +387,6 @@ void Client::syncToCore(const QVariant &coreState) { // create identities foreach(QVariant vid, sessionState["Identities"].toList()) { 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/identity.cpp b/src/common/identity.cpp index a45eb757..b69f8987 100644 --- a/src/common/identity.cpp +++ b/src/common/identity.cpp @@ -60,7 +60,7 @@ void Identity::init() { } void Identity::setToDefaults() { - setIdentityName(tr("Default Identity")); + setIdentityName(tr("")); setRealName(tr("Quassel IRC User")); QStringList n; n << QString("quassel%1").arg(qrand() & 0xff); // FIXME provide more sensible default nicks @@ -81,7 +81,6 @@ void Identity::setToDefaults() { 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 { @@ -296,8 +295,8 @@ bool Identity::operator==(const Identity &other) { 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 + QVariant v2 = other.property(metaProp.name()); // qDebug() << v1 << v2; + // QVariant cannot compare custom types, so we need to check for this special case if(QString(v1.typeName()) == "IdentityId") { if(v1.value() != v2.value()) return false; } else { diff --git a/src/common/syncableobject.h b/src/common/syncableobject.h index 78838618..4ce8c91d 100644 --- a/src/common/syncableobject.h +++ b/src/common/syncableobject.h @@ -46,7 +46,7 @@ class SyncableObject : public QObject { virtual QVariantMap toVariantMap(); //! Initialize the object's state from a given QVariantMap. - /** \see toVarianMap() for important information concerning this method. + /** \see toVariantMap() for important information concerning this method. */ virtual void fromVariantMap(const QVariantMap &map); diff --git a/src/core/core.cpp b/src/core/core.cpp index 0f007d35..66d1d37b 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -140,7 +140,7 @@ bool Core::initStorage(QVariantMap dbSettings, bool setup) { return configured = storage->init(dbSettings); } - + bool Core::initStorage(QVariantMap dbSettings) { return initStorage(dbSettings, false); } @@ -254,7 +254,7 @@ void Core::clientHasData() { return; } } - blockSizes[socket] = bsize = 0; // FIXME blockSizes aufräum0rn! + blockSizes[socket] = bsize = 0; // FIXME blockSizes aufr�um0rn! } // FIXME: no longer called, since connection handling is now in SignalProxy diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 92eeafe3..bbe4a1f8 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -18,6 +18,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#define SPUTDEV + #include "coresession.h" #include "server.h" @@ -50,13 +52,13 @@ CoreSession::CoreSession(UserId uid, Storage *_storage, QObject *parent) foreach(IdentityId id, s.identityIds()) { Identity *i = new Identity(s.identity(id), this); if(!i->isValid()) { - qDebug() << QString("Invalid identity! Removing..."); + qWarning() << QString("Invalid identity! Removing..."); s.removeIdentity(id); delete i; continue; } if(_identities.contains(i->id())) { - qDebug() << "Duplicate identity, ignoring!"; + qWarning() << "Duplicate identity, ignoring!"; delete i; continue; } @@ -65,6 +67,7 @@ CoreSession::CoreSession(UserId uid, Storage *_storage, QObject *parent) if(!_identities.count()) { Identity i(1); i.setToDefaults(); + i.setIdentityName(tr("Default Identity")); createIdentity(i); } #endif @@ -297,7 +300,7 @@ void CoreSession::initScriptEngine() { void CoreSession::scriptRequest(QString script) { emit scriptResult(scriptEngine->evaluate(script).toString()); } - +#include void CoreSession::createIdentity(const Identity &id) { // find free ID int i; @@ -311,7 +314,7 @@ void CoreSession::createIdentity(const Identity &id) { signalProxy()->synchronize(newId); CoreUserSettings s(user); s.storeIdentity(*newId); - emit identityCreated(i); + emit identityCreated(*newId); } void CoreSession::updateIdentity(const Identity &id) { diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 0feeb63e..47e44e53 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -17,6 +17,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +//#define SPUTDEV #include "mainwin.h" @@ -154,7 +155,6 @@ void MainWin::setupMenus() { connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities())); connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg())); connect(ui.actionDebug_Console, SIGNAL(triggered()), this, SLOT(showDebugConsole())); - //ui.actionSettingsDlg->setEnabled(false); connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt())); } diff --git a/src/qtui/settingspages/identitiessettingspage.cpp b/src/qtui/settingspages/identitiessettingspage.cpp index 2817b84b..c9cb1f12 100644 --- a/src/qtui/settingspages/identitiessettingspage.cpp +++ b/src/qtui/settingspages/identitiessettingspage.cpp @@ -18,6 +18,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include #include #include "identitiessettingspage.h" @@ -73,7 +74,8 @@ void IdentitiesSettingsPage::save() { 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) { + QHash::iterator i = identities.begin(); + while(i != identities.end()) { if((*i)->id() < 0) { Identity *temp = *i; i = identities.erase(i); @@ -83,6 +85,7 @@ void IdentitiesSettingsPage::save() { if(**i != *Client::identity((*i)->id())) { toUpdate.append(*i); } + ++i; } } SaveIdentitiesDlg dlg(toCreate, toUpdate, deletedIdentities, this); @@ -94,9 +97,10 @@ void IdentitiesSettingsPage::save() { foreach(Identity *id, toCreate) { id->deleteLater(); } + changedIdentities.clear(); + deletedIdentities.clear(); changeState(false); setEnabled(true); - } void IdentitiesSettingsPage::load() { @@ -128,10 +132,13 @@ bool IdentitiesSettingsPage::testHasChanged() { if(currentId < 0) { return true; // new identity } else { - changedIdentities.removeAll(currentId); - Identity temp(currentId, this); - saveToIdentity(&temp); - if(temp != *identities[currentId]) changedIdentities.append(currentId); + if(currentId != 0) { + changedIdentities.removeAll(currentId); + Identity temp(currentId, this); + saveToIdentity(&temp); + temp.setIdentityName(identities[currentId]->identityName()); + if(temp != *Client::identity(currentId)) changedIdentities.append(currentId); + } return changedIdentities.count(); } } @@ -158,21 +165,23 @@ bool IdentitiesSettingsPage::aboutToSave() { void IdentitiesSettingsPage::clientIdentityCreated(IdentityId id) { insertIdentity(new Identity(*Client::identity(id), this)); + Identity *i = identities[id]; connect(Client::identity(id), SIGNAL(updatedRemotely()), this, SLOT(clientIdentityUpdated())); } void IdentitiesSettingsPage::clientIdentityUpdated() { - Identity *identity = qobject_cast(sender()); - if(!identity) { + const Identity *clientIdentity = qobject_cast(sender()); + if(!clientIdentity) { qWarning() << "Invalid identity to update!"; return; } - if(!identities.contains(identity->id())) { - qWarning() << "Unknown identity to update:" << identity->identityName(); + if(!identities.contains(clientIdentity->id())) { + qWarning() << "Unknown identity to update:" << clientIdentity->identityName(); return; } - identities[identity->id()]->update(*identity); - ui.identityList->setItemText(ui.identityList->findData(identity->id()), identity->identityName()); + Identity *identity = identities[clientIdentity->id()]; + if(identity->identityName() != clientIdentity->identityName()) renameIdentity(identity->id(), clientIdentity->identityName()); + identity->update(*clientIdentity); if(identity->id() == currentId) displayIdentity(identity, true); } @@ -205,9 +214,16 @@ void IdentitiesSettingsPage::insertIdentity(Identity *identity) { } } +void IdentitiesSettingsPage::renameIdentity(IdentityId id, const QString &newName) { + Identity *identity = identities[id]; + ui.identityList->setItemText(ui.identityList->findData(identity->id()), newName); + identity->setIdentityName(newName); +} + void IdentitiesSettingsPage::removeIdentity(Identity *id) { - ui.identityList->removeItem(ui.identityList->findData(id->id())); identities.remove(id->id()); + ui.identityList->removeItem(ui.identityList->findData(id->id())); + changedIdentities.removeAll(id->id()); id->deleteLater(); widgetHasChanged(); } @@ -220,7 +236,7 @@ void IdentitiesSettingsPage::on_identityList_currentIndexChanged(int index) { 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 + ui.renameIdentity->setEnabled(id != 1); // ...or renamed } } @@ -257,7 +273,6 @@ void IdentitiesSettingsPage::displayIdentity(Identity *id, bool dontsave) { } 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++) { @@ -312,11 +327,20 @@ void IdentitiesSettingsPage::on_deleteIdentity_clicked() { QMessageBox::Yes|QMessageBox::No, QMessageBox::No); if(ret != QMessageBox::Yes) return; if(id->id() > 0) deletedIdentities.append(id->id()); + currentId = 0; removeIdentity(id); } -void IdentitiesSettingsPage::on_identityList_editTextChanged(const QString &text) { - ui.identityList->setItemText(ui.identityList->currentIndex(), text); +void IdentitiesSettingsPage::on_renameIdentity_clicked() { + QString oldName = identities[currentId]->identityName(); + bool ok = false; + QString name = QInputDialog::getText(this, tr("Rename Identity"), + tr("Please enter a new name for the identity \"%1\":").arg(oldName), + QLineEdit::Normal, oldName, &ok); + if(ok && !name.isEmpty()) { + renameIdentity(currentId, name); + widgetHasChanged(); + } } /*****************************************************************************************/ diff --git a/src/qtui/settingspages/identitiessettingspage.h b/src/qtui/settingspages/identitiessettingspage.h index 0e21662a..294d646e 100644 --- a/src/qtui/settingspages/identitiessettingspage.h +++ b/src/qtui/settingspages/identitiessettingspage.h @@ -50,10 +50,10 @@ class IdentitiesSettingsPage : public SettingsPage { void clientIdentityRemoved(IdentityId); void on_identityList_currentIndexChanged(int index); - void on_identityList_editTextChanged(const QString &); void on_addIdentity_clicked(); void on_deleteIdentity_clicked(); + void on_renameIdentity_clicked(); void widgetHasChanged(); @@ -68,6 +68,7 @@ class IdentitiesSettingsPage : public SettingsPage { void insertIdentity(Identity *identity); void removeIdentity(Identity *identity); + void renameIdentity(IdentityId id, const QString &newName); void displayIdentity(Identity *, bool dontsave = false); void saveToIdentity(Identity *); diff --git a/src/qtui/settingspages/identitiessettingspage.ui b/src/qtui/settingspages/identitiessettingspage.ui index fdd03e7a..92f18b28 100644 --- a/src/qtui/settingspages/identitiessettingspage.ui +++ b/src/qtui/settingspages/identitiessettingspage.ui @@ -5,8 +5,8 @@ 0 0 - 422 - 380 + 431 + 398 @@ -25,6 +25,22 @@ + + + + ... + + + :/22x22/actions/oxygen/22x22/actions/edit-rename.png + + + + 22 + 22 + + + + @@ -105,7 +121,61 @@ - + + + + 0 + 0 + + + + &Add... + + + :/16x16/actions/oxygen/16x16/actions/list-add.png + + + + 16 + 16 + + + + + + + + + 0 + 0 + + + + De&lete + + + :/16x16/actions/oxygen/16x16/actions/edit-delete.png + + + + + + + + 0 + 0 + + + + Re&name... + + + :/16x16/actions/oxygen/16x16/actions/edit-rename.png + + + + + 6 @@ -122,139 +192,53 @@ 0 - - - - 0 - 0 - - - - &Add... - - - :/16x16/actions/oxygen/16x16/actions/list-add.png + + + Qt::Horizontal - + - 16 - 16 + 0 + 20 - + - - - - 0 - 0 - + + + Move upwards in list - Re&name... + ... - :/16x16/actions/oxygen/16x16/actions/edit-rename.png + :/16x16/actions/oxygen/16x16/actions/go-up.png - - - - 0 - 0 - + + + Move downwards in list - De&lete + ... - :/16x16/actions/oxygen/16x16/actions/edit-delete.png + :/16x16/actions/oxygen/16x16/actions/go-down.png - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 0 - 20 - - - - - - - - Move upwards in list - - - ... - - - :/16x16/actions/oxygen/16x16/actions/go-up.png - - - - - - - Move downwards in list - - - ... - - - :/16x16/actions/oxygen/16x16/actions/go-down.png - - - - - - - Qt::Horizontal - - - - 0 - 20 - - - - - - - Qt::Vertical + Qt::Horizontal - 20 - 0 + 0 + 20 @@ -268,8 +252,8 @@ - 20 - 40 + 124 + 76