X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fidentitiessettingspage.cpp;h=a5ec4f940214d95068cac872d8e13fbe68eb52c2;hb=48189e18131e2366eb2790b37f3b6412292f2d6c;hp=c9cb1f122477dc18952448718b70621b964c7383;hpb=2e6dc76ae100a6b8e1b1661e422995f90083500e;p=quassel.git diff --git a/src/qtui/settingspages/identitiessettingspage.cpp b/src/qtui/settingspages/identitiessettingspage.cpp index c9cb1f12..a5ec4f94 100644 --- a/src/qtui/settingspages/identitiessettingspage.cpp +++ b/src/qtui/settingspages/identitiessettingspage.cpp @@ -24,12 +24,23 @@ #include "identitiessettingspage.h" #include "client.h" +#include "iconloader.h" IdentitiesSettingsPage::IdentitiesSettingsPage(QWidget *parent) : SettingsPage(tr("General"), tr("Identities"), parent) { ui.setupUi(this); - setEnabled(false); // need a core connection! + ui.renameIdentity->setIcon(BarIcon("edit-rename")); + ui.addIdentity->setIcon(BarIcon("list-add-user")); + ui.deleteIdentity->setIcon(BarIcon("list-remove-user")); + ui.addNick->setIcon(SmallIcon("list-add")); + ui.deleteNick->setIcon(SmallIcon("edit-delete")); + ui.renameNick->setIcon(SmallIcon("edit-rename")); + ui.nickUp->setIcon(SmallIcon("go-up")); + ui.nickDown->setIcon(SmallIcon("go-down")); + + setEnabled(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))); connect(Client::instance(), SIGNAL(identityRemoved(IdentityId)), this, SLOT(clientIdentityRemoved(IdentityId))); @@ -44,19 +55,40 @@ IdentitiesSettingsPage::IdentitiesSettingsPage(QWidget *parent) 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.detachAwayEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.detachAwayReason, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.detachAwayReasonEnabled, 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())); + connect(ui.nicknameList, SIGNAL(itemSelectionChanged()), this, SLOT(setWidgetStates())); + + // we would need this if we enabled drag and drop in the nicklist... + //connect(ui.nicknameList, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(setWidgetStates())); + //connect(ui.nicknameList->model(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(nicklistHasChanged())); + +} + +void IdentitiesSettingsPage::setWidgetStates() { + if(ui.nicknameList->selectedItems().count()) { + ui.renameNick->setEnabled(true); + ui.nickUp->setEnabled(ui.nicknameList->row(ui.nicknameList->selectedItems()[0]) > 0); + ui.nickDown->setEnabled(ui.nicknameList->row(ui.nicknameList->selectedItems()[0]) < ui.nicknameList->count()-1); + } else { + ui.renameNick->setDisabled(true); + ui.nickUp->setDisabled(true); + ui.nickDown->setDisabled(true); + } + ui.deleteNick->setEnabled(ui.nicknameList->count() > 1); + + // FIXME this is until stuff has been implemented + ui.detachAwayEnabled->setEnabled(false); } void IdentitiesSettingsPage::coreConnectionStateChanged(bool state) { @@ -80,7 +112,7 @@ void IdentitiesSettingsPage::save() { Identity *temp = *i; i = identities.erase(i); toCreate.append(temp); - ui.identityList->removeItem(ui.identityList->findData(temp->id())); + ui.identityList->removeItem(ui.identityList->findData(temp->id().toInt())); } else { if(**i != *Client::identity((*i)->id())) { toUpdate.append(*i); @@ -99,7 +131,7 @@ void IdentitiesSettingsPage::save() { } changedIdentities.clear(); deletedIdentities.clear(); - changeState(false); + setChangedState(false); setEnabled(true); } @@ -115,16 +147,12 @@ void IdentitiesSettingsPage::load() { foreach(IdentityId id, Client::identityIds()) { clientIdentityCreated(id); } - changeState(false); -} - -void IdentitiesSettingsPage::defaults() { - // TODO implement bool hasDefaults() + setChangedState(false); } void IdentitiesSettingsPage::widgetHasChanged() { bool changed = testHasChanged(); - if(changed != hasChanged()) changeState(changed); + if(changed != hasChanged()) setChangedState(changed); } bool IdentitiesSettingsPage::testHasChanged() { @@ -165,7 +193,6 @@ 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())); } @@ -198,32 +225,33 @@ void IdentitiesSettingsPage::insertIdentity(Identity *identity) { identities[id] = identity; if(id == 1) { // default identity is always the first one! - ui.identityList->insertItem(0, identity->identityName(), id); + ui.identityList->insertItem(0, identity->identityName(), id.toInt()); } 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); + ui.identityList->insertItem(j, name, id.toInt()); widgetHasChanged(); return; } } // append - ui.identityList->insertItem(ui.identityList->count(), name, id); + ui.identityList->insertItem(ui.identityList->count(), name, id.toInt()); widgetHasChanged(); } } void IdentitiesSettingsPage::renameIdentity(IdentityId id, const QString &newName) { Identity *identity = identities[id]; - ui.identityList->setItemText(ui.identityList->findData(identity->id()), newName); + ui.identityList->setItemText(ui.identityList->findData(identity->id().toInt()), newName); identity->setIdentityName(newName); } void IdentitiesSettingsPage::removeIdentity(Identity *id) { identities.remove(id->id()); - ui.identityList->removeItem(ui.identityList->findData(id->id())); + ui.identityList->removeItem(ui.identityList->findData(id->id().toInt())); changedIdentities.removeAll(id->id()); + if(currentId == id->id()) currentId = 0; id->deleteLater(); widgetHasChanged(); } @@ -257,14 +285,13 @@ void IdentitiesSettingsPage::displayIdentity(Identity *id, bool dontsave) { 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.detachAwayEnabled->setChecked(id->detachAwayEnabled()); + ui.detachAwayReason->setText(id->detachAwayReason()); + ui.detachAwayReasonEnabled->setChecked(id->detachAwayReasonEnabled()); ui.ident->setText(id->ident()); ui.kickReason->setText(id->kickReason()); ui.partReason->setText(id->partReason()); @@ -283,14 +310,13 @@ void IdentitiesSettingsPage::saveToIdentity(Identity *id) { 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->setDetachAwayEnabled(ui.detachAwayEnabled->isChecked()); + id->setDetachAwayReason(ui.detachAwayReason->text()); + id->setDetachAwayReasonEnabled(ui.detachAwayReasonEnabled->isChecked()); id->setIdent(ui.ident->text()); id->setKickReason(ui.kickReason->text()); id->setPartReason(ui.partReason->text()); @@ -303,9 +329,9 @@ void IdentitiesSettingsPage::on_addIdentity_clicked() { // find a free (negative) ID IdentityId id; for(id = 1; id <= identities.count(); id++) { - if(!identities.keys().contains(-id)) break; + if(!identities.keys().contains(-id.toInt())) break; } - id *= -1; + id = -id.toInt(); Identity *newId = new Identity(id, this); if(dlg.duplicateId() != 0) { // duplicate @@ -315,7 +341,7 @@ void IdentitiesSettingsPage::on_addIdentity_clicked() { newId->setIdentityName(dlg.identityName()); identities[id] = newId; insertIdentity(newId); - ui.identityList->setCurrentIndex(ui.identityList->findData(id)); + ui.identityList->setCurrentIndex(ui.identityList->findData(id.toInt())); widgetHasChanged(); } } @@ -335,7 +361,7 @@ 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), + tr("Please enter a new name for the identity \"%1\"!").arg(oldName), QLineEdit::Normal, oldName, &ok); if(ok && !name.isEmpty()) { renameIdentity(currentId, name); @@ -343,6 +369,62 @@ void IdentitiesSettingsPage::on_renameIdentity_clicked() { } } +void IdentitiesSettingsPage::on_addNick_clicked() { + QStringList existing; + for(int i = 0; i < ui.nicknameList->count(); i++) existing << ui.nicknameList->item(i)->text(); + NickEditDlg dlg(QString(), existing, this); + if(dlg.exec() == QDialog::Accepted) { + ui.nicknameList->addItem(dlg.nick()); + ui.nicknameList->setCurrentRow(ui.nicknameList->count()-1); + setWidgetStates(); + widgetHasChanged(); + } +} + +void IdentitiesSettingsPage::on_deleteNick_clicked() { + // no confirmation, since a nickname is really nothing hard to recreate + if(ui.nicknameList->selectedItems().count()) { + delete ui.nicknameList->takeItem(ui.nicknameList->row(ui.nicknameList->selectedItems()[0])); + ui.nicknameList->setCurrentRow(qMin(ui.nicknameList->currentRow()+1, ui.nicknameList->count()-1)); + setWidgetStates(); + widgetHasChanged(); + } +} + +void IdentitiesSettingsPage::on_renameNick_clicked() { + if(!ui.nicknameList->selectedItems().count()) return; + QString old = ui.nicknameList->selectedItems()[0]->text(); + QStringList existing; + for(int i = 0; i < ui.nicknameList->count(); i++) existing << ui.nicknameList->item(i)->text(); + NickEditDlg dlg(old, existing, this); + if(dlg.exec() == QDialog::Accepted) { + ui.nicknameList->selectedItems()[0]->setText(dlg.nick()); + } + +} + +void IdentitiesSettingsPage::on_nickUp_clicked() { + if(!ui.nicknameList->selectedItems().count()) return; + int row = ui.nicknameList->row(ui.nicknameList->selectedItems()[0]); + if(row > 0) { + ui.nicknameList->insertItem(row-1, ui.nicknameList->takeItem(row)); + ui.nicknameList->setCurrentRow(row-1); + setWidgetStates(); + widgetHasChanged(); + } +} + +void IdentitiesSettingsPage::on_nickDown_clicked() { + if(!ui.nicknameList->selectedItems().count()) return; + int row = ui.nicknameList->row(ui.nicknameList->selectedItems()[0]); + if(row < ui.nicknameList->count()-1) { + ui.nicknameList->insertItem(row+1, ui.nicknameList->takeItem(row)); + ui.nicknameList->setCurrentRow(row+1); + setWidgetStates(); + widgetHasChanged(); + } +} + /*****************************************************************************************/ CreateIdentityDlg::CreateIdentityDlg(QAbstractItemModel *model, QWidget *parent) : QDialog(parent) { @@ -371,9 +453,11 @@ void CreateIdentityDlg::on_identityName_textChanged(const QString &text) { /*********************************************************************************************/ -SaveIdentitiesDlg::SaveIdentitiesDlg(QList tocreate, QList toupdate, QList toremove, QWidget *parent) - : QDialog(parent), toCreate(tocreate), toUpdate(toupdate), toRemove(toremove) { +SaveIdentitiesDlg::SaveIdentitiesDlg(const QList &toCreate, const QList &toUpdate, const QList &toRemove, QWidget *parent) + : QDialog(parent) { //, toCreate(tocreate), toUpdate(toupdate), toRemove(toremove) { ui.setupUi(this); + ui.abort->setIcon(SmallIcon("dialog-cancel")); + numevents = toCreate.count() + toUpdate.count() + toRemove.count(); rcvevents = 0; if(numevents) { @@ -394,7 +478,7 @@ SaveIdentitiesDlg::SaveIdentitiesDlg(QList tocreate, QListid(), id->toVariantMap()); } foreach(IdentityId id, toRemove) { Client::removeIdentity(id); @@ -409,3 +493,34 @@ void SaveIdentitiesDlg::clientEvent() { ui.progressBar->setValue(++rcvevents); if(rcvevents >= numevents) accept(); } + +/*************************************************************************************************/ + +NickEditDlg::NickEditDlg(const QString &old, const QStringList &exist, QWidget *parent) + : QDialog(parent), oldNick(old), existing(exist) { + ui.setupUi(this); + + // define a regexp for valid nicknames + // TODO: add max nicklength according to ISUPPORT + QString letter = "A-Za-z"; + QString special = "\x5b-\x60\x7b-\x7d"; + QRegExp rx(QString("[%1%2][%1%2\\d-]*").arg(letter, special)); + ui.nickEdit->setValidator(new QRegExpValidator(rx, ui.nickEdit)); + if(old.isEmpty()) { + // new nick + setWindowTitle(tr("Add Nickname")); + on_nickEdit_textChanged(""); // disable ok button + } else ui.nickEdit->setText(old); +} + +QString NickEditDlg::nick() const { + return ui.nickEdit->text(); + +} + +void NickEditDlg::on_nickEdit_textChanged(const QString &text) { + ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text)); +} + + +