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 coreConnectionStateChanged(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()));
84 ui.sslKeyGroupBox->setAcceptDrops(true);
85 ui.sslKeyGroupBox->installEventFilter(this);
86 ui.sslCertGroupBox->setAcceptDrops(true);
87 ui.sslCertGroupBox->installEventFilter(this);
91 void IdentitiesSettingsPage::setWidgetStates() {
92 if(ui.nicknameList->selectedItems().count()) {
93 ui.renameNick->setEnabled(true);
94 ui.nickUp->setEnabled(ui.nicknameList->row(ui.nicknameList->selectedItems()[0]) > 0);
95 ui.nickDown->setEnabled(ui.nicknameList->row(ui.nicknameList->selectedItems()[0]) < ui.nicknameList->count()-1);
97 ui.renameNick->setDisabled(true);
98 ui.nickUp->setDisabled(true);
99 ui.nickDown->setDisabled(true);
101 ui.deleteNick->setEnabled(ui.nicknameList->count() > 1);
104 void IdentitiesSettingsPage::coreConnectionStateChanged(bool connected) {
105 setEnabled(connected);
108 if(Client::signalProxy()->isSecure()) {
109 ui.keyAndCertSettings->setCurrentIndex(2);
112 ui.keyAndCertSettings->setCurrentIndex(1);
116 ui.keyAndCertSettings->setCurrentIndex(0);
125 void IdentitiesSettingsPage::save() {
127 QList<CertIdentity *> toCreate, toUpdate;
128 // we need to remove our temporarily created identities.
129 // these are going to be re-added after the core has propagated them back...
130 QHash<IdentityId, CertIdentity *>::iterator i = identities.begin();
131 while(i != identities.end()) {
133 CertIdentity *temp = *i;
134 i = identities.erase(i);
135 toCreate.append(temp);
136 ui.identityList->removeItem(ui.identityList->findData(temp->id().toInt()));
138 if(**i != *Client::identity((*i)->id()) || (*i)->isDirty()) {
144 SaveIdentitiesDlg dlg(toCreate, toUpdate, deletedIdentities, this);
145 int ret = dlg.exec();
146 if(ret == QDialog::Rejected) {
147 // canceled -> reload everything to be safe
150 foreach(Identity *id, toCreate) {
153 changedIdentities.clear();
154 deletedIdentities.clear();
155 setChangedState(false);
159 void IdentitiesSettingsPage::load() {
161 foreach(Identity *identity, identities.values()) {
162 identity->deleteLater();
165 deletedIdentities.clear();
166 changedIdentities.clear();
167 ui.identityList->clear();
168 foreach(IdentityId id, Client::identityIds()) {
169 clientIdentityCreated(id);
171 setChangedState(false);
174 void IdentitiesSettingsPage::widgetHasChanged() {
175 bool changed = testHasChanged();
176 if(changed != hasChanged()) setChangedState(changed);
179 bool IdentitiesSettingsPage::testHasChanged() {
180 if(deletedIdentities.count()) return true;
182 return true; // new identity
185 changedIdentities.removeAll(currentId);
186 CertIdentity temp(currentId, this);
187 saveToIdentity(&temp);
188 temp.setIdentityName(identities[currentId]->identityName());
189 if(temp != *Client::identity(currentId) || temp.isDirty())
190 changedIdentities.append(currentId);
192 return changedIdentities.count();
196 bool IdentitiesSettingsPage::aboutToSave() {
197 saveToIdentity(identities[currentId]);
199 foreach(Identity *id, identities.values()) {
200 if(id->identityName().isEmpty()) errors.append(1);
201 if(!id->nicks().count()) errors.append(2);
202 if(id->realName().isEmpty()) errors.append(3);
203 if(id->ident().isEmpty()) errors.append(4);
205 if(!errors.count()) return true;
206 QString error(tr("<b>The following problems need to be corrected before your changes can be applied:</b><ul>"));
207 if(errors.contains(1)) error += tr("<li>All identities need an identity name set</li>");
208 if(errors.contains(2)) error += tr("<li>Every identity needs at least one nickname defined</li>");
209 if(errors.contains(3)) error += tr("<li>You need to specify a real name for every identity</li>");
210 if(errors.contains(4)) error += tr("<li>You need to specify an ident for every identity</li>");
211 error += tr("</ul>");
212 QMessageBox::warning(this, tr("One or more identities are invalid"), error);
216 void IdentitiesSettingsPage::clientIdentityCreated(IdentityId id) {
217 CertIdentity *identity = new CertIdentity(*Client::identity(id), this);
219 identity->enableEditSsl(_editSsl);
221 insertIdentity(identity);
223 connect(identity, SIGNAL(sslSettingsUpdated()), this, SLOT(clientIdentityUpdated()));
225 connect(Client::identity(id), SIGNAL(updatedRemotely()), this, SLOT(clientIdentityUpdated()));
228 void IdentitiesSettingsPage::clientIdentityUpdated() {
229 const Identity *clientIdentity = qobject_cast<Identity *>(sender());
230 if(!clientIdentity) {
231 qWarning() << "Invalid identity to update!";
234 if(!identities.contains(clientIdentity->id())) {
235 qWarning() << "Unknown identity to update:" << clientIdentity->identityName();
239 CertIdentity *identity = identities[clientIdentity->id()];
241 if(identity->identityName() != clientIdentity->identityName())
242 renameIdentity(identity->id(), clientIdentity->identityName());
244 identity->copyFrom(*clientIdentity);
246 if(identity->id() == currentId)
247 displayIdentity(identity, true);
250 void IdentitiesSettingsPage::clientIdentityRemoved(IdentityId id) {
251 if(identities.contains(id)) {
252 removeIdentity(identities[id]);
253 changedIdentities.removeAll(id);
254 deletedIdentities.removeAll(id);
258 void IdentitiesSettingsPage::insertIdentity(CertIdentity *identity) {
259 IdentityId id = identity->id();
260 identities[id] = identity;
262 // default identity is always the first one!
263 ui.identityList->insertItem(0, identity->identityName(), id.toInt());
265 QString name = identity->identityName();
266 for(int j = 0; j < ui.identityList->count(); j++) {
267 if((j>0 || ui.identityList->itemData(0).toInt() != 1) && name.localeAwareCompare(ui.identityList->itemText(j)) < 0) {
268 ui.identityList->insertItem(j, name, id.toInt());
274 ui.identityList->insertItem(ui.identityList->count(), name, id.toInt());
279 void IdentitiesSettingsPage::renameIdentity(IdentityId id, const QString &newName) {
280 Identity *identity = identities[id];
281 ui.identityList->setItemText(ui.identityList->findData(identity->id().toInt()), newName);
282 identity->setIdentityName(newName);
285 void IdentitiesSettingsPage::removeIdentity(Identity *id) {
286 identities.remove(id->id());
287 ui.identityList->removeItem(ui.identityList->findData(id->id().toInt()));
288 changedIdentities.removeAll(id->id());
289 if(currentId == id->id()) currentId = 0;
294 void IdentitiesSettingsPage::on_identityList_currentIndexChanged(int index) {
296 //ui.identityList->setEditable(false);
299 IdentityId id = ui.identityList->itemData(index).toInt();
300 if(identities.contains(id)) displayIdentity(identities[id]);
301 ui.deleteIdentity->setEnabled(id != 1); // default identity cannot be deleted
302 ui.renameIdentity->setEnabled(id != 1); // ...or renamed
306 void IdentitiesSettingsPage::displayIdentity(CertIdentity *id, bool dontsave) {
307 if(currentId != 0 && !dontsave && identities.contains(currentId)) {
308 saveToIdentity(identities[currentId]);
311 currentId = id->id();
312 ui.realName->setText(id->realName());
313 ui.nicknameList->clear();
314 ui.nicknameList->addItems(id->nicks());
315 //for(int i = 0; i < ui.nicknameList->count(); i++) {
316 // ui.nicknameList->item(i)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled);
318 if(ui.nicknameList->count()) ui.nicknameList->setCurrentRow(0);
319 ui.awayNick->setText(id->awayNick());
320 ui.awayNickEnabled->setChecked(id->awayNickEnabled());
321 ui.awayReason->setText(id->awayReason());
322 ui.awayReasonEnabled->setChecked(id->awayReasonEnabled());
323 ui.autoAwayEnabled->setChecked(id->autoAwayEnabled());
324 ui.autoAwayTime->setValue(id->autoAwayTime());
325 ui.autoAwayReason->setText(id->autoAwayReason());
326 ui.autoAwayReasonEnabled->setChecked(id->autoAwayReasonEnabled());
327 ui.detachAwayEnabled->setChecked(id->detachAwayEnabled());
328 ui.detachAwayReason->setText(id->detachAwayReason());
329 ui.detachAwayReasonEnabled->setChecked(id->detachAwayReasonEnabled());
330 ui.ident->setText(id->ident());
331 ui.kickReason->setText(id->kickReason());
332 ui.partReason->setText(id->partReason());
333 ui.quitReason->setText(id->quitReason());
335 showKeyState(id->sslKey());
336 showCertState(id->sslCert());
341 void IdentitiesSettingsPage::saveToIdentity(CertIdentity *id) {
342 id->setRealName(ui.realName->text());
344 for(int i = 0; i < ui.nicknameList->count(); i++) {
345 nicks << ui.nicknameList->item(i)->text();
348 id->setAwayNick(ui.awayNick->text());
349 id->setAwayNickEnabled(ui.awayNickEnabled->isChecked());
350 id->setAwayReason(ui.awayReason->text());
351 id->setAwayReasonEnabled(ui.awayReasonEnabled->isChecked());
352 id->setAutoAwayEnabled(ui.autoAwayEnabled->isChecked());
353 id->setAutoAwayTime(ui.autoAwayTime->value());
354 id->setAutoAwayReason(ui.autoAwayReason->text());
355 id->setAutoAwayReasonEnabled(ui.autoAwayReasonEnabled->isChecked());
356 id->setDetachAwayEnabled(ui.detachAwayEnabled->isChecked());
357 id->setDetachAwayReason(ui.detachAwayReason->text());
358 id->setDetachAwayReasonEnabled(ui.detachAwayReasonEnabled->isChecked());
359 id->setIdent(ui.ident->text());
360 id->setKickReason(ui.kickReason->text());
361 id->setPartReason(ui.partReason->text());
362 id->setQuitReason(ui.quitReason->text());
364 id->setSslKey(QSslKey(ui.keyTypeLabel->property("sslKey").toByteArray(), (QSsl::KeyAlgorithm)(ui.keyTypeLabel->property("sslKeyType").toInt())));
365 id->setSslCert(QSslCertificate(ui.certOrgLabel->property("sslCert").toByteArray()));
369 void IdentitiesSettingsPage::on_addIdentity_clicked() {
370 CreateIdentityDlg dlg(ui.identityList->model(), this);
371 if(dlg.exec() == QDialog::Accepted) {
372 // find a free (negative) ID
374 for(id = 1; id <= identities.count(); id++) {
375 if(!identities.keys().contains(-id.toInt())) break;
378 CertIdentity *newId = new CertIdentity(id, this);
380 newId->enableEditSsl(_editSsl);
382 if(dlg.duplicateId() != 0) {
384 newId->copyFrom(*identities[dlg.duplicateId()]);
387 newId->setIdentityName(dlg.identityName());
388 identities[id] = newId;
389 insertIdentity(newId);
390 ui.identityList->setCurrentIndex(ui.identityList->findData(id.toInt()));
395 void IdentitiesSettingsPage::on_deleteIdentity_clicked() {
396 Identity *id = identities[currentId];
397 int ret = QMessageBox::question(this, tr("Delete Identity?"),
398 tr("Do you really want to delete identity \"%1\"?").arg(id->identityName()),
399 QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
400 if(ret != QMessageBox::Yes) return;
401 if(id->id() > 0) deletedIdentities.append(id->id());
406 void IdentitiesSettingsPage::on_renameIdentity_clicked() {
407 QString oldName = identities[currentId]->identityName();
409 QString name = QInputDialog::getText(this, tr("Rename Identity"),
410 tr("Please enter a new name for the identity \"%1\"!").arg(oldName),
411 QLineEdit::Normal, oldName, &ok);
412 if(ok && !name.isEmpty()) {
413 renameIdentity(currentId, name);
418 void IdentitiesSettingsPage::on_addNick_clicked() {
419 QStringList existing;
420 for(int i = 0; i < ui.nicknameList->count(); i++) existing << ui.nicknameList->item(i)->text();
421 NickEditDlg dlg(QString(), existing, this);
422 if(dlg.exec() == QDialog::Accepted) {
423 ui.nicknameList->addItem(dlg.nick());
424 ui.nicknameList->setCurrentRow(ui.nicknameList->count()-1);
430 void IdentitiesSettingsPage::on_deleteNick_clicked() {
431 // no confirmation, since a nickname is really nothing hard to recreate
432 if(ui.nicknameList->selectedItems().count()) {
433 delete ui.nicknameList->takeItem(ui.nicknameList->row(ui.nicknameList->selectedItems()[0]));
434 ui.nicknameList->setCurrentRow(qMin(ui.nicknameList->currentRow()+1, ui.nicknameList->count()-1));
440 void IdentitiesSettingsPage::on_renameNick_clicked() {
441 if(!ui.nicknameList->selectedItems().count()) return;
442 QString old = ui.nicknameList->selectedItems()[0]->text();
443 QStringList existing;
444 for(int i = 0; i < ui.nicknameList->count(); i++) existing << ui.nicknameList->item(i)->text();
445 NickEditDlg dlg(old, existing, this);
446 if(dlg.exec() == QDialog::Accepted) {
447 ui.nicknameList->selectedItems()[0]->setText(dlg.nick());
452 void IdentitiesSettingsPage::on_nickUp_clicked() {
453 if(!ui.nicknameList->selectedItems().count()) return;
454 int row = ui.nicknameList->row(ui.nicknameList->selectedItems()[0]);
456 ui.nicknameList->insertItem(row-1, ui.nicknameList->takeItem(row));
457 ui.nicknameList->setCurrentRow(row-1);
463 void IdentitiesSettingsPage::on_nickDown_clicked() {
464 if(!ui.nicknameList->selectedItems().count()) return;
465 int row = ui.nicknameList->row(ui.nicknameList->selectedItems()[0]);
466 if(row < ui.nicknameList->count()-1) {
467 ui.nicknameList->insertItem(row+1, ui.nicknameList->takeItem(row));
468 ui.nicknameList->setCurrentRow(row+1);
475 void IdentitiesSettingsPage::on_continueUnsecured_clicked() {
478 QHash<IdentityId, CertIdentity *>::iterator idIter;
479 for(idIter = identities.begin(); idIter != identities.end(); idIter++) {
480 idIter.value()->enableEditSsl();
483 ui.keyAndCertSettings->setCurrentIndex(2);
486 bool IdentitiesSettingsPage::eventFilter(QObject *watched, QEvent *event) {
487 bool isCert = (watched == ui.sslCertGroupBox);
488 switch(event->type()) {
489 case QEvent::DragEnter:
490 sslDragEnterEvent(static_cast<QDragEnterEvent *>(event));
493 sslDropEvent(static_cast<QDropEvent *>(event), isCert);
500 void IdentitiesSettingsPage::sslDragEnterEvent(QDragEnterEvent *event) {
501 if(event->mimeData()->hasFormat("text/uri-list") || event->mimeData()->hasFormat("text/uri")) {
502 event->setDropAction(Qt::CopyAction);
507 void IdentitiesSettingsPage::sslDropEvent(QDropEvent *event, bool isCert) {
509 if(event->mimeData()->hasFormat("text/uri-list"))
510 rawUris = event->mimeData()->data("text/uri-list");
512 rawUris = event->mimeData()->data("text/uri");
514 QTextStream uriStream(rawUris);
515 QString filename = QUrl(uriStream.readLine()).toLocalFile();
518 QSslCertificate cert = certByFilename(filename);
522 QSslKey key = keyByFilename(filename);
530 void IdentitiesSettingsPage::on_clearOrLoadKeyButton_clicked() {
533 if(ui.keyTypeLabel->property("sslKey").toByteArray().isEmpty())
534 key = keyByFilename(QFileDialog::getOpenFileName(this, tr("Load a Key"), QDesktopServices::storageLocation(QDesktopServices::HomeLocation)));
540 QSslKey IdentitiesSettingsPage::keyByFilename(const QString &filename) {
543 QFile keyFile(filename);
544 keyFile.open(QIODevice::ReadOnly);
545 QByteArray keyRaw = keyFile.read(2 << 20);
548 for(int i = 0; i < 2; i++) {
549 for(int j = 0; j < 2; j++) {
550 key = QSslKey(keyRaw, (QSsl::KeyAlgorithm)j, (QSsl::EncodingFormat)i);
559 void IdentitiesSettingsPage::showKeyState(const QSslKey &key) {
561 ui.keyTypeLabel->setText(tr("No Key loaded"));
562 ui.clearOrLoadKeyButton->setText(tr("Load"));
564 switch(key.algorithm()) {
566 ui.keyTypeLabel->setText(tr("RSA"));
569 ui.keyTypeLabel->setText(tr("DSA"));
572 ui.keyTypeLabel->setText(tr("No Key Loaded"));
574 ui.clearOrLoadKeyButton->setText(tr("Clear"));
576 ui.keyTypeLabel->setProperty("sslKey", key.toPem());
577 ui.keyTypeLabel->setProperty("sslKeyType", (int)key.algorithm());
580 void IdentitiesSettingsPage::on_clearOrLoadCertButton_clicked() {
581 QSslCertificate cert;
583 if(ui.certOrgLabel->property("sslCert").toByteArray().isEmpty())
584 cert = certByFilename(QFileDialog::getOpenFileName(this, tr("Load a Certificate"), QDesktopServices::storageLocation(QDesktopServices::HomeLocation)));
590 QSslCertificate IdentitiesSettingsPage::certByFilename(const QString &filename) {
591 QSslCertificate cert;
592 QFile certFile(filename);
593 certFile.open(QIODevice::ReadOnly);
594 QByteArray certRaw = certFile.read(2 << 20);
597 for(int i = 0; i < 2; i++) {
598 cert = QSslCertificate(certRaw, (QSsl::EncodingFormat)i);
605 void IdentitiesSettingsPage::showCertState(const QSslCertificate &cert) {
606 if(!cert.isValid()) {
607 ui.certOrgLabel->setText(tr("No Certificate loaded"));
608 ui.certCNameLabel->setText(tr("No Certificate loaded"));
609 ui.clearOrLoadCertButton->setText(tr("Load"));
611 ui.certOrgLabel->setText(cert.subjectInfo(QSslCertificate::Organization));
612 ui.certCNameLabel->setText(cert.subjectInfo(QSslCertificate::CommonName));
613 ui.clearOrLoadCertButton->setText(tr("Clear"));
615 ui.certOrgLabel->setProperty("sslCert", cert.toPem());
619 /*****************************************************************************************/
621 CreateIdentityDlg::CreateIdentityDlg(QAbstractItemModel *model, QWidget *parent)
626 ui.identityList->setModel(model); // now we use the identity list of the main page... Trolltech <3
627 on_identityName_textChanged(""); // disable ok button :)
630 QString CreateIdentityDlg::identityName() const {
631 return ui.identityName->text();
634 IdentityId CreateIdentityDlg::duplicateId() const {
635 if(!ui.duplicateIdentity->isChecked()) return 0;
636 if(ui.identityList->currentIndex() >= 0) {
637 return ui.identityList->itemData(ui.identityList->currentIndex()).toInt();
642 void CreateIdentityDlg::on_identityName_textChanged(const QString &text) {
643 ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(text.count());
647 /*********************************************************************************************/
649 SaveIdentitiesDlg::SaveIdentitiesDlg(const QList<CertIdentity *> &toCreate, const QList<CertIdentity *> &toUpdate, const QList<IdentityId> &toRemove, QWidget *parent)
653 ui.abort->setIcon(SmallIcon("dialog-cancel"));
655 numevents = toCreate.count() + toUpdate.count() + toRemove.count();
658 ui.progressBar->setMaximum(numevents);
659 ui.progressBar->setValue(0);
661 connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(clientEvent()));
662 connect(Client::instance(), SIGNAL(identityRemoved(IdentityId)), this, SLOT(clientEvent()));
664 foreach(CertIdentity *id, toCreate) {
665 Client::createIdentity(*id);
667 foreach(CertIdentity *id, toUpdate) {
668 const Identity *cid = Client::identity(id->id());
670 qWarning() << "Invalid client identity!";
674 connect(cid, SIGNAL(updatedRemotely()), this, SLOT(clientEvent()));
675 Client::updateIdentity(id->id(), id->toVariantMap());
677 id->requestUpdateSslSettings();
680 foreach(IdentityId id, toRemove) {
681 Client::removeIdentity(id);
684 qWarning() << "Sync dialog called without stuff to change!";
689 void SaveIdentitiesDlg::clientEvent() {
690 ui.progressBar->setValue(++rcvevents);
691 if(rcvevents >= numevents) accept();
694 /*************************************************************************************************/
696 NickEditDlg::NickEditDlg(const QString &old, const QStringList &exist, QWidget *parent)
697 : QDialog(parent), oldNick(old), existing(exist) {
700 // define a regexp for valid nicknames
701 // TODO: add max nicklength according to ISUPPORT
702 QString letter = "A-Za-z";
703 QString special = "\x5b-\x60\x7b-\x7d";
704 QRegExp rx(QString("[%1%2][%1%2\\d-]*").arg(letter, special));
705 ui.nickEdit->setValidator(new QRegExpValidator(rx, ui.nickEdit));
708 setWindowTitle(tr("Add Nickname"));
709 on_nickEdit_textChanged(""); // disable ok button
710 } else ui.nickEdit->setText(old);
713 QString NickEditDlg::nick() const {
714 return ui.nickEdit->text();
718 void NickEditDlg::on_nickEdit_textChanged(const QString &text) {
719 ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text));