+#ifdef HAVE_SSL
+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);
+}
+
+bool IdentitiesSettingsPage::eventFilter(QObject *watched, QEvent *event) {
+ bool isCert = (watched == ui.sslCertGroupBox);
+ switch(event->type()) {
+ case QEvent::DragEnter:
+ sslDragEnterEvent(static_cast<QDragEnterEvent *>(event));
+ return true;
+ case QEvent::Drop:
+ sslDropEvent(static_cast<QDropEvent *>(event), isCert);
+ return true;
+ default:
+ return false;
+ }
+}
+
+void IdentitiesSettingsPage::sslDragEnterEvent(QDragEnterEvent *event) {
+ if(event->mimeData()->hasFormat("text/uri-list") || event->mimeData()->hasFormat("text/uri")) {
+ event->setDropAction(Qt::CopyAction);
+ event->accept();
+ }
+}
+
+void IdentitiesSettingsPage::sslDropEvent(QDropEvent *event, bool isCert) {
+ QByteArray rawUris;
+ if(event->mimeData()->hasFormat("text/uri-list"))
+ rawUris = event->mimeData()->data("text/uri-list");
+ else
+ rawUris = event->mimeData()->data("text/uri");
+
+ QTextStream uriStream(rawUris);
+ QString filename = QUrl(uriStream.readLine()).toLocalFile();
+
+ if(isCert) {
+ QSslCertificate cert = certByFilename(filename);
+ if(cert.isValid())
+ showCertState(cert);
+ } else {
+ QSslKey key = keyByFilename(filename);
+ if(!key.isNull())
+ showKeyState(key);
+ }
+ event->accept();
+ widgetHasChanged();
+}
+
+void IdentitiesSettingsPage::on_clearOrLoadKeyButton_clicked() {
+ QSslKey key;
+
+ if(ui.keyTypeLabel->property("sslKey").toByteArray().isEmpty())
+ key = keyByFilename(QFileDialog::getOpenFileName(this, tr("Load a Key"), QDesktopServices::storageLocation(QDesktopServices::HomeLocation)));
+
+ showKeyState(key);
+ widgetHasChanged();
+}
+
+QSslKey IdentitiesSettingsPage::keyByFilename(const QString &filename) {
+ QSslKey key;
+
+ QFile keyFile(filename);
+ 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 returnKey;
+ }
+ }
+ returnKey:
+ return key;
+}
+
+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())
+ cert = certByFilename(QFileDialog::getOpenFileName(this, tr("Load a Certificate"), QDesktopServices::storageLocation(QDesktopServices::HomeLocation)));
+
+ showCertState(cert);
+ widgetHasChanged();
+}
+
+QSslCertificate IdentitiesSettingsPage::certByFilename(const QString &filename) {
+ QSslCertificate cert;
+ QFile certFile(filename);
+ 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;
+ }
+ return cert;
+}
+
+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());
+ }
+#endif //HAVE_SSL
+