1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "identitiessettingspage.h"
23 #include <QDesktopServices>
24 #include <QDragEnterEvent>
26 #include <QFileDialog>
27 #include <QInputDialog>
28 #include <QMessageBox>
31 #include "iconloader.h"
32 #include "signalproxy.h"
34 IdentitiesSettingsPage::IdentitiesSettingsPage(QWidget *parent)
35 : SettingsPage(tr("General"), tr("Identities"), parent),
40 ui.renameIdentity->setIcon(BarIcon("edit-rename"));
41 ui.addIdentity->setIcon(BarIcon("list-add-user"));
42 ui.deleteIdentity->setIcon(BarIcon("list-remove-user"));
43 ui.addNick->setIcon(SmallIcon("list-add"));
44 ui.deleteNick->setIcon(SmallIcon("edit-delete"));
45 ui.renameNick->setIcon(SmallIcon("edit-rename"));
46 ui.nickUp->setIcon(SmallIcon("go-up"));
47 ui.nickDown->setIcon(SmallIcon("go-down"));
49 setEnabled(Client::isConnected()); // need a core connection!
51 connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), this, SLOT(coreConnectionStateChanged(bool)));
52 connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(clientIdentityCreated(IdentityId)));
53 connect(Client::instance(), SIGNAL(identityRemoved(IdentityId)), this, SLOT(clientIdentityRemoved(IdentityId)));
57 // We need to know whenever the state of input widgets changes...
58 //connect(ui.identityList, SIGNAL(editTextChanged(const QString &)), this, SLOT(widgetHasChanged()));
59 connect(ui.realName, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
60 connect(ui.nicknameList, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(widgetHasChanged()));
61 connect(ui.awayNick, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
62 connect(ui.awayNickEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
63 connect(ui.awayReason, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
64 connect(ui.awayReasonEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
65 connect(ui.autoAwayEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
66 connect(ui.autoAwayTime, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
67 connect(ui.autoAwayReason, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
68 connect(ui.autoAwayReasonEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
69 connect(ui.detachAwayEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
70 connect(ui.detachAwayReason, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
71 connect(ui.detachAwayReasonEnabled, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
72 connect(ui.ident, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
73 connect(ui.kickReason, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
74 connect(ui.partReason, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
75 connect(ui.quitReason, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
77 connect(ui.nicknameList, SIGNAL(itemSelectionChanged()), this, SLOT(setWidgetStates()));
79 // we would need this if we enabled drag and drop in the nicklist...
80 //connect(ui.nicknameList, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(setWidgetStates()));
81 //connect(ui.nicknameList->model(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(nicklistHasChanged()));
83 ui.sslKeyGroupBox->setAcceptDrops(true);
84 ui.sslKeyGroupBox->installEventFilter(this);
85 ui.sslCertGroupBox->setAcceptDrops(true);
86 ui.sslCertGroupBox->installEventFilter(this);
89 void IdentitiesSettingsPage::setWidgetStates() {
90 if(ui.nicknameList->selectedItems().count()) {
91 ui.renameNick->setEnabled(true);
92 ui.nickUp->setEnabled(ui.nicknameList->row(ui.nicknameList->selectedItems()[0]) > 0);
93 ui.nickDown->setEnabled(ui.nicknameList->row(ui.nicknameList->selectedItems()[0]) < ui.nicknameList->count()-1);
95 ui.renameNick->setDisabled(true);
96 ui.nickUp->setDisabled(true);
97 ui.nickDown->setDisabled(true);
99 ui.deleteNick->setEnabled(ui.nicknameList->count() > 1);
102 void IdentitiesSettingsPage::coreConnectionStateChanged(bool connected) {
103 setEnabled(connected);
106 if(Client::signalProxy()->isSecure())
107 ui.keyAndCertSettings->setCurrentIndex(2);
109 ui.keyAndCertSettings->setCurrentIndex(1);
111 ui.keyAndCertSettings->setCurrentIndex(0);
120 void IdentitiesSettingsPage::save() {
122 QList<CertIdentity *> toCreate, toUpdate;
123 // we need to remove our temporarily created identities.
124 // these are going to be re-added after the core has propagated them back...
125 QHash<IdentityId, CertIdentity *>::iterator i = identities.begin();
126 while(i != identities.end()) {
128 CertIdentity *temp = *i;
129 i = identities.erase(i);
130 toCreate.append(temp);
131 ui.identityList->removeItem(ui.identityList->findData(temp->id().toInt()));
133 if(**i != *Client::identity((*i)->id()) || (*i)->isDirty()) {
139 SaveIdentitiesDlg dlg(toCreate, toUpdate, deletedIdentities, this);
140 int ret = dlg.exec();
141 if(ret == QDialog::Rejected) {
142 // canceled -> reload everything to be safe
145 foreach(Identity *id, toCreate) {
148 changedIdentities.clear();
149 deletedIdentities.clear();
150 setChangedState(false);
154 void IdentitiesSettingsPage::load() {
156 foreach(Identity *identity, identities.values()) {
157 identity->deleteLater();
160 deletedIdentities.clear();
161 changedIdentities.clear();
162 ui.identityList->clear();
163 foreach(IdentityId id, Client::identityIds()) {
164 clientIdentityCreated(id);
166 setChangedState(false);
169 void IdentitiesSettingsPage::widgetHasChanged() {
170 bool changed = testHasChanged();
171 if(changed != hasChanged()) setChangedState(changed);
174 bool IdentitiesSettingsPage::testHasChanged() {
175 if(deletedIdentities.count()) return true;
177 return true; // new identity
180 changedIdentities.removeAll(currentId);
181 CertIdentity temp(currentId, this);
182 saveToIdentity(&temp);
183 temp.setIdentityName(identities[currentId]->identityName());
184 if(temp != *Client::identity(currentId) || temp.isDirty())
185 changedIdentities.append(currentId);
187 return changedIdentities.count();
191 bool IdentitiesSettingsPage::aboutToSave() {
192 saveToIdentity(identities[currentId]);
194 foreach(Identity *id, identities.values()) {
195 if(id->identityName().isEmpty()) errors.append(1);
196 if(!id->nicks().count()) errors.append(2);
197 if(id->realName().isEmpty()) errors.append(3);
198 if(id->ident().isEmpty()) errors.append(4);
200 if(!errors.count()) return true;
201 QString error(tr("<b>The following problems need to be corrected before your changes can be applied:</b><ul>"));
202 if(errors.contains(1)) error += tr("<li>All identities need an identity name set</li>");
203 if(errors.contains(2)) error += tr("<li>Every identity needs at least one nickname defined</li>");
204 if(errors.contains(3)) error += tr("<li>You need to specify a real name for every identity</li>");
205 if(errors.contains(4)) error += tr("<li>You need to specify an ident for every identity</li>");
206 error += tr("</ul>");
207 QMessageBox::warning(this, tr("One or more identities are invalid"), error);
211 void IdentitiesSettingsPage::clientIdentityCreated(IdentityId id) {
212 CertIdentity *identity = new CertIdentity(*Client::identity(id), this);
213 identity->enableEditSsl(_editSsl);
214 insertIdentity(identity);
215 connect(identity, SIGNAL(sslSettingsUpdated()), this, SLOT(clientIdentityUpdated()));
216 connect(Client::identity(id), SIGNAL(updatedRemotely()), this, SLOT(clientIdentityUpdated()));
219 void IdentitiesSettingsPage::clientIdentityUpdated() {
220 const Identity *clientIdentity = qobject_cast<Identity *>(sender());
221 if(!clientIdentity) {
222 qWarning() << "Invalid identity to update!";
225 if(!identities.contains(clientIdentity->id())) {
226 qWarning() << "Unknown identity to update:" << clientIdentity->identityName();
230 CertIdentity *identity = identities[clientIdentity->id()];
232 if(identity->identityName() != clientIdentity->identityName())
233 renameIdentity(identity->id(), clientIdentity->identityName());
235 identity->update(*clientIdentity);
237 if(identity->id() == currentId)
238 displayIdentity(identity, true);
241 void IdentitiesSettingsPage::clientIdentityRemoved(IdentityId id) {
242 if(identities.contains(id)) {
243 removeIdentity(identities[id]);
244 changedIdentities.removeAll(id);
245 deletedIdentities.removeAll(id);
249 void IdentitiesSettingsPage::insertIdentity(CertIdentity *identity) {
250 IdentityId id = identity->id();
251 identities[id] = identity;
253 // default identity is always the first one!
254 ui.identityList->insertItem(0, identity->identityName(), id.toInt());
256 QString name = identity->identityName();
257 for(int j = 0; j < ui.identityList->count(); j++) {
258 if((j>0 || ui.identityList->itemData(0).toInt() != 1) && name.localeAwareCompare(ui.identityList->itemText(j)) < 0) {
259 ui.identityList->insertItem(j, name, id.toInt());
265 ui.identityList->insertItem(ui.identityList->count(), name, id.toInt());
270 void IdentitiesSettingsPage::renameIdentity(IdentityId id, const QString &newName) {
271 Identity *identity = identities[id];
272 ui.identityList->setItemText(ui.identityList->findData(identity->id().toInt()), newName);
273 identity->setIdentityName(newName);
276 void IdentitiesSettingsPage::removeIdentity(Identity *id) {
277 identities.remove(id->id());
278 ui.identityList->removeItem(ui.identityList->findData(id->id().toInt()));
279 changedIdentities.removeAll(id->id());
280 if(currentId == id->id()) currentId = 0;
285 void IdentitiesSettingsPage::on_identityList_currentIndexChanged(int index) {
287 //ui.identityList->setEditable(false);
290 IdentityId id = ui.identityList->itemData(index).toInt();
291 if(identities.contains(id)) displayIdentity(identities[id]);
292 ui.deleteIdentity->setEnabled(id != 1); // default identity cannot be deleted
293 ui.renameIdentity->setEnabled(id != 1); // ...or renamed
297 void IdentitiesSettingsPage::displayIdentity(CertIdentity *id, bool dontsave) {
298 if(currentId != 0 && !dontsave && identities.contains(currentId)) {
299 saveToIdentity(identities[currentId]);
302 currentId = id->id();
303 ui.realName->setText(id->realName());
304 ui.nicknameList->clear();
305 ui.nicknameList->addItems(id->nicks());
306 //for(int i = 0; i < ui.nicknameList->count(); i++) {
307 // ui.nicknameList->item(i)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled);
309 if(ui.nicknameList->count()) ui.nicknameList->setCurrentRow(0);
310 ui.awayNick->setText(id->awayNick());
311 ui.awayNickEnabled->setChecked(id->awayNickEnabled());
312 ui.awayReason->setText(id->awayReason());
313 ui.awayReasonEnabled->setChecked(id->awayReasonEnabled());
314 ui.autoAwayEnabled->setChecked(id->autoAwayEnabled());
315 ui.autoAwayTime->setValue(id->autoAwayTime());
316 ui.autoAwayReason->setText(id->autoAwayReason());
317 ui.autoAwayReasonEnabled->setChecked(id->autoAwayReasonEnabled());
318 ui.detachAwayEnabled->setChecked(id->detachAwayEnabled());
319 ui.detachAwayReason->setText(id->detachAwayReason());
320 ui.detachAwayReasonEnabled->setChecked(id->detachAwayReasonEnabled());
321 ui.ident->setText(id->ident());
322 ui.kickReason->setText(id->kickReason());
323 ui.partReason->setText(id->partReason());
324 ui.quitReason->setText(id->quitReason());
325 showKeyState(id->sslKey());
326 showCertState(id->sslCert());
330 void IdentitiesSettingsPage::saveToIdentity(CertIdentity *id) {
331 id->setRealName(ui.realName->text());
333 for(int i = 0; i < ui.nicknameList->count(); i++) {
334 nicks << ui.nicknameList->item(i)->text();
337 id->setAwayNick(ui.awayNick->text());
338 id->setAwayNickEnabled(ui.awayNickEnabled->isChecked());
339 id->setAwayReason(ui.awayReason->text());
340 id->setAwayReasonEnabled(ui.awayReasonEnabled->isChecked());
341 id->setAutoAwayEnabled(ui.autoAwayEnabled->isChecked());
342 id->setAutoAwayTime(ui.autoAwayTime->value());
343 id->setAutoAwayReason(ui.autoAwayReason->text());
344 id->setAutoAwayReasonEnabled(ui.autoAwayReasonEnabled->isChecked());
345 id->setDetachAwayEnabled(ui.detachAwayEnabled->isChecked());
346 id->setDetachAwayReason(ui.detachAwayReason->text());
347 id->setDetachAwayReasonEnabled(ui.detachAwayReasonEnabled->isChecked());
348 id->setIdent(ui.ident->text());
349 id->setKickReason(ui.kickReason->text());
350 id->setPartReason(ui.partReason->text());
351 id->setQuitReason(ui.quitReason->text());
352 id->setSslKey(QSslKey(ui.keyTypeLabel->property("sslKey").toByteArray(), (QSsl::KeyAlgorithm)(ui.keyTypeLabel->property("sslKeyType").toInt())));
353 id->setSslCert(QSslCertificate(ui.certOrgLabel->property("sslCert").toByteArray()));
356 void IdentitiesSettingsPage::on_addIdentity_clicked() {
357 CreateIdentityDlg dlg(ui.identityList->model(), this);
358 if(dlg.exec() == QDialog::Accepted) {
359 // find a free (negative) ID
361 for(id = 1; id <= identities.count(); id++) {
362 if(!identities.keys().contains(-id.toInt())) break;
365 CertIdentity *newId = new CertIdentity(id, this);
366 newId->enableEditSsl(_editSsl);
367 if(dlg.duplicateId() != 0) {
369 newId->update(*identities[dlg.duplicateId()]);
372 newId->setIdentityName(dlg.identityName());
373 identities[id] = newId;
374 insertIdentity(newId);
375 ui.identityList->setCurrentIndex(ui.identityList->findData(id.toInt()));
380 void IdentitiesSettingsPage::on_deleteIdentity_clicked() {
381 Identity *id = identities[currentId];
382 int ret = QMessageBox::question(this, tr("Delete Identity?"),
383 tr("Do you really want to delete identity \"%1\"?").arg(id->identityName()),
384 QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
385 if(ret != QMessageBox::Yes) return;
386 if(id->id() > 0) deletedIdentities.append(id->id());
391 void IdentitiesSettingsPage::on_renameIdentity_clicked() {
392 QString oldName = identities[currentId]->identityName();
394 QString name = QInputDialog::getText(this, tr("Rename Identity"),
395 tr("Please enter a new name for the identity \"%1\"!").arg(oldName),
396 QLineEdit::Normal, oldName, &ok);
397 if(ok && !name.isEmpty()) {
398 renameIdentity(currentId, name);
403 void IdentitiesSettingsPage::on_addNick_clicked() {
404 QStringList existing;
405 for(int i = 0; i < ui.nicknameList->count(); i++) existing << ui.nicknameList->item(i)->text();
406 NickEditDlg dlg(QString(), existing, this);
407 if(dlg.exec() == QDialog::Accepted) {
408 ui.nicknameList->addItem(dlg.nick());
409 ui.nicknameList->setCurrentRow(ui.nicknameList->count()-1);
415 void IdentitiesSettingsPage::on_deleteNick_clicked() {
416 // no confirmation, since a nickname is really nothing hard to recreate
417 if(ui.nicknameList->selectedItems().count()) {
418 delete ui.nicknameList->takeItem(ui.nicknameList->row(ui.nicknameList->selectedItems()[0]));
419 ui.nicknameList->setCurrentRow(qMin(ui.nicknameList->currentRow()+1, ui.nicknameList->count()-1));
425 void IdentitiesSettingsPage::on_renameNick_clicked() {
426 if(!ui.nicknameList->selectedItems().count()) return;
427 QString old = ui.nicknameList->selectedItems()[0]->text();
428 QStringList existing;
429 for(int i = 0; i < ui.nicknameList->count(); i++) existing << ui.nicknameList->item(i)->text();
430 NickEditDlg dlg(old, existing, this);
431 if(dlg.exec() == QDialog::Accepted) {
432 ui.nicknameList->selectedItems()[0]->setText(dlg.nick());
437 void IdentitiesSettingsPage::on_nickUp_clicked() {
438 if(!ui.nicknameList->selectedItems().count()) return;
439 int row = ui.nicknameList->row(ui.nicknameList->selectedItems()[0]);
441 ui.nicknameList->insertItem(row-1, ui.nicknameList->takeItem(row));
442 ui.nicknameList->setCurrentRow(row-1);
448 void IdentitiesSettingsPage::on_nickDown_clicked() {
449 if(!ui.nicknameList->selectedItems().count()) return;
450 int row = ui.nicknameList->row(ui.nicknameList->selectedItems()[0]);
451 if(row < ui.nicknameList->count()-1) {
452 ui.nicknameList->insertItem(row+1, ui.nicknameList->takeItem(row));
453 ui.nicknameList->setCurrentRow(row+1);
459 void IdentitiesSettingsPage::on_continueUnsecured_clicked() {
462 QHash<IdentityId, CertIdentity *>::iterator idIter;
463 for(idIter = identities.begin(); idIter != identities.end(); idIter++) {
464 idIter.value()->enableEditSsl();
467 ui.keyAndCertSettings->setCurrentIndex(2);
470 bool IdentitiesSettingsPage::eventFilter(QObject *watched, QEvent *event) {
471 bool isCert = (watched == ui.sslCertGroupBox);
472 switch(event->type()) {
473 case QEvent::DragEnter:
474 sslDragEnterEvent(static_cast<QDragEnterEvent *>(event));
477 sslDropEvent(static_cast<QDropEvent *>(event), isCert);
484 void IdentitiesSettingsPage::sslDragEnterEvent(QDragEnterEvent *event) {
485 if(event->mimeData()->hasFormat("text/uri-list") || event->mimeData()->hasFormat("text/uri")) {
486 event->setDropAction(Qt::CopyAction);
491 void IdentitiesSettingsPage::sslDropEvent(QDropEvent *event, bool isCert) {
493 if(event->mimeData()->hasFormat("text/uri-list"))
494 rawUris = event->mimeData()->data("text/uri-list");
496 rawUris = event->mimeData()->data("text/uri");
498 QTextStream uriStream(rawUris);
499 QString filename = QUrl(uriStream.readLine()).toLocalFile();
502 QSslCertificate cert = certByFilename(filename);
506 QSslKey key = keyByFilename(filename);
514 void IdentitiesSettingsPage::on_clearOrLoadKeyButton_clicked() {
517 if(ui.keyTypeLabel->property("sslKey").toByteArray().isEmpty())
518 key = keyByFilename(QFileDialog::getOpenFileName(this, tr("Load a Key"), QDesktopServices::storageLocation(QDesktopServices::HomeLocation)));
524 QSslKey IdentitiesSettingsPage::keyByFilename(const QString &filename) {
527 QFile keyFile(filename);
528 keyFile.open(QIODevice::ReadOnly);
529 QByteArray keyRaw = keyFile.read(2 << 20);
532 for(int i = 0; i < 2; i++) {
533 for(int j = 0; j < 2; j++) {
534 key = QSslKey(keyRaw, (QSsl::KeyAlgorithm)j, (QSsl::EncodingFormat)i);
543 void IdentitiesSettingsPage::showKeyState(const QSslKey &key) {
545 ui.keyTypeLabel->setText(tr("No Key loaded"));
546 ui.clearOrLoadKeyButton->setText(tr("Load"));
548 switch(key.algorithm()) {
550 ui.keyTypeLabel->setText(tr("RSA"));
553 ui.keyTypeLabel->setText(tr("DSA"));
556 ui.keyTypeLabel->setText(tr("No Key Loaded"));
558 ui.clearOrLoadKeyButton->setText(tr("Clear"));
560 ui.keyTypeLabel->setProperty("sslKey", key.toPem());
561 ui.keyTypeLabel->setProperty("sslKeyType", (int)key.algorithm());
564 void IdentitiesSettingsPage::on_clearOrLoadCertButton_clicked() {
565 QSslCertificate cert;
567 if(ui.certOrgLabel->property("sslCert").toByteArray().isEmpty())
568 cert = certByFilename(QFileDialog::getOpenFileName(this, tr("Load a Certificate"), QDesktopServices::storageLocation(QDesktopServices::HomeLocation)));
574 QSslCertificate IdentitiesSettingsPage::certByFilename(const QString &filename) {
575 QSslCertificate cert;
576 QFile certFile(filename);
577 certFile.open(QIODevice::ReadOnly);
578 QByteArray certRaw = certFile.read(2 << 20);
581 for(int i = 0; i < 2; i++) {
582 cert = QSslCertificate(certRaw, (QSsl::EncodingFormat)i);
589 void IdentitiesSettingsPage::showCertState(const QSslCertificate &cert) {
590 if(!cert.isValid()) {
591 ui.certOrgLabel->setText(tr("No Certificate loaded"));
592 ui.certCNameLabel->setText(tr("No Certificate loaded"));
593 ui.clearOrLoadCertButton->setText(tr("Load"));
595 ui.certOrgLabel->setText(cert.subjectInfo(QSslCertificate::Organization));
596 ui.certCNameLabel->setText(cert.subjectInfo(QSslCertificate::CommonName));
597 ui.clearOrLoadCertButton->setText(tr("Clear"));
599 ui.certOrgLabel->setProperty("sslCert", cert.toPem());
602 /*****************************************************************************************/
604 CreateIdentityDlg::CreateIdentityDlg(QAbstractItemModel *model, QWidget *parent)
609 ui.identityList->setModel(model); // now we use the identity list of the main page... Trolltech <3
610 on_identityName_textChanged(""); // disable ok button :)
613 QString CreateIdentityDlg::identityName() const {
614 return ui.identityName->text();
617 IdentityId CreateIdentityDlg::duplicateId() const {
618 if(!ui.duplicateIdentity->isChecked()) return 0;
619 if(ui.identityList->currentIndex() >= 0) {
620 return ui.identityList->itemData(ui.identityList->currentIndex()).toInt();
625 void CreateIdentityDlg::on_identityName_textChanged(const QString &text) {
626 ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(text.count());
630 /*********************************************************************************************/
632 SaveIdentitiesDlg::SaveIdentitiesDlg(const QList<CertIdentity *> &toCreate, const QList<CertIdentity *> &toUpdate, const QList<IdentityId> &toRemove, QWidget *parent)
636 ui.abort->setIcon(SmallIcon("dialog-cancel"));
638 numevents = toCreate.count() + toUpdate.count() + toRemove.count();
641 ui.progressBar->setMaximum(numevents);
642 ui.progressBar->setValue(0);
644 connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(clientEvent()));
645 connect(Client::instance(), SIGNAL(identityRemoved(IdentityId)), this, SLOT(clientEvent()));
647 foreach(CertIdentity *id, toCreate) {
648 Client::createIdentity(*id);
650 foreach(CertIdentity *id, toUpdate) {
651 const Identity *cid = Client::identity(id->id());
653 qWarning() << "Invalid client identity!";
657 connect(cid, SIGNAL(updatedRemotely()), this, SLOT(clientEvent()));
658 Client::updateIdentity(id->id(), id->toVariantMap());
659 id->requestUpdateSslSettings();
661 foreach(IdentityId id, toRemove) {
662 Client::removeIdentity(id);
665 qWarning() << "Sync dialog called without stuff to change!";
670 void SaveIdentitiesDlg::clientEvent() {
671 ui.progressBar->setValue(++rcvevents);
672 if(rcvevents >= numevents) accept();
675 /*************************************************************************************************/
677 NickEditDlg::NickEditDlg(const QString &old, const QStringList &exist, QWidget *parent)
678 : QDialog(parent), oldNick(old), existing(exist) {
681 // define a regexp for valid nicknames
682 // TODO: add max nicklength according to ISUPPORT
683 QString letter = "A-Za-z";
684 QString special = "\x5b-\x60\x7b-\x7d";
685 QRegExp rx(QString("[%1%2][%1%2\\d-]*").arg(letter, special));
686 ui.nickEdit->setValidator(new QRegExpValidator(rx, ui.nickEdit));
689 setWindowTitle(tr("Add Nickname"));
690 on_nickEdit_textChanged(""); // disable ok button
691 } else ui.nickEdit->setText(old);
694 QString NickEditDlg::nick() const {
695 return ui.nickEdit->text();
699 void NickEditDlg::on_nickEdit_textChanged(const QString &text) {
700 ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text));