-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();
- }
-}
-
-void IdentitiesSettingsPage::on_continueUnsecured_clicked() {
- _editSsl = true;
-
- QHash<IdentityId, CertIdentity *>::iterator idIter;
- for(idIter = identities.begin(); idIter != identities.end(); idIter++) {
- idIter.value()->enableEditSsl();
- }
-
- ui.keyAndCertSettings->setCurrentIndex(2);
-}
-
-void IdentitiesSettingsPage::on_clearOrLoadKeyButton_clicked() {
- QSslKey key;
-
- if(ui.keyTypeLabel->property("sslKey").toByteArray().isEmpty()) {
- QString keyFileName = QFileDialog::getOpenFileName(this, tr("Load a Key"), QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
- QFile keyFile(keyFileName);
- keyFile.open(QIODevice::ReadOnly);
- QByteArray keyRaw = keyFile.read(2 << 20);
- keyFile.close();
-
- for(int i = 0; i < 2; i++) {
- for(int j = 0; j < 2; j++) {
- key = QSslKey(keyRaw, (QSsl::KeyAlgorithm)j, (QSsl::EncodingFormat)i);
- if(!key.isNull())
- goto showKey;
- }
- }
- }
-
- showKey:
- showKeyState(key);
- widgetHasChanged();
-}
-
-void IdentitiesSettingsPage::showKeyState(const QSslKey &key) {
- if(key.isNull()) {
- ui.keyTypeLabel->setText(tr("No Key loaded"));
- ui.clearOrLoadKeyButton->setText(tr("Load"));
- } else {
- switch(key.algorithm()) {
- case QSsl::Rsa:
- ui.keyTypeLabel->setText(tr("RSA"));
- break;
- case QSsl::Dsa:
- ui.keyTypeLabel->setText(tr("DSA"));
- break;
- default:
- ui.keyTypeLabel->setText(tr("No Key Loaded"));
- }
- ui.clearOrLoadKeyButton->setText(tr("Clear"));
- }
- ui.keyTypeLabel->setProperty("sslKey", key.toPem());
- ui.keyTypeLabel->setProperty("sslKeyType", (int)key.algorithm());
-}
-
-void IdentitiesSettingsPage::on_clearOrLoadCertButton_clicked() {
- QSslCertificate cert;
-
- if(ui.certOrgLabel->property("sslCert").toByteArray().isEmpty()) {
- QString certFileName = QFileDialog::getOpenFileName(this, tr("Load a Certificate"), QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
- QFile certFile(certFileName);
- certFile.open(QIODevice::ReadOnly);
- QByteArray certRaw = certFile.read(2 << 20);
- certFile.close();
-
- for(int i = 0; i < 2; i++) {
- cert = QSslCertificate(certRaw, (QSsl::EncodingFormat)i);
- if(cert.isValid())
- break;
- }
- }
-
- showCertState(cert);
- widgetHasChanged();
-}
-
-void IdentitiesSettingsPage::showCertState(const QSslCertificate &cert) {
- if(!cert.isValid()) {
- ui.certOrgLabel->setText(tr("No Certificate loaded"));
- ui.certCNameLabel->setText(tr("No Certificate loaded"));
- ui.clearOrLoadCertButton->setText(tr("Load"));
- } else {
- ui.certOrgLabel->setText(cert.subjectInfo(QSslCertificate::Organization));
- ui.certCNameLabel->setText(cert.subjectInfo(QSslCertificate::CommonName));
- ui.clearOrLoadCertButton->setText(tr("Clear"));
- }
- ui.certOrgLabel->setProperty("sslCert", cert.toPem());
- }
-