X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fidentitiessettingspage.cpp;h=de7a02b47e31d97dab59b8ba47666c811ac3452f;hb=d37bdc91c5474603e1417c2cd9c40c02e1ad5ee6;hp=4f87c833b8f9aade27591c2e1cf86828556f657f;hpb=0324c701d9cc8c656e6188b4e102e19e05c98201;p=quassel.git diff --git a/src/qtui/settingspages/identitiessettingspage.cpp b/src/qtui/settingspages/identitiessettingspage.cpp index 4f87c833..de7a02b4 100644 --- a/src/qtui/settingspages/identitiessettingspage.cpp +++ b/src/qtui/settingspages/identitiessettingspage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,11 +20,12 @@ #include "identitiessettingspage.h" -#include -#include #include +#include +#include +#include +#include #include -#include #include "client.h" #include "iconloader.h" @@ -45,7 +46,7 @@ IdentitiesSettingsPage::IdentitiesSettingsPage(QWidget *parent) ui.nickUp->setIcon(SmallIcon("go-up")); ui.nickDown->setIcon(SmallIcon("go-down")); - setEnabled(Client::isConnected()); // need a core connection! + coreConnectionStateChanged(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))); @@ -75,18 +76,16 @@ IdentitiesSettingsPage::IdentitiesSettingsPage(QWidget *parent) connect(ui.nicknameList, SIGNAL(itemSelectionChanged()), this, SLOT(setWidgetStates())); -#ifdef HAVE_SSL - if(Client::signalProxy()->isSecure()) - ui.keyAndCertSettings->setCurrentIndex(2); - else - ui.keyAndCertSettings->setCurrentIndex(1); -#else - ui.keyAndCertSettings->setCurrentIndex(0); -#endif - // 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())); + +#ifdef HAVE_SSL + ui.sslKeyGroupBox->setAcceptDrops(true); + ui.sslKeyGroupBox->installEventFilter(this); + ui.sslCertGroupBox->setAcceptDrops(true); + ui.sslCertGroupBox->installEventFilter(this); +#endif } void IdentitiesSettingsPage::setWidgetStates() { @@ -102,9 +101,20 @@ void IdentitiesSettingsPage::setWidgetStates() { ui.deleteNick->setEnabled(ui.nicknameList->count() > 1); } -void IdentitiesSettingsPage::coreConnectionStateChanged(bool state) { - this->setEnabled(state); - if(state) { +void IdentitiesSettingsPage::coreConnectionStateChanged(bool connected) { + setEnabled(connected); + if(connected) { +#ifdef HAVE_SSL + if(Client::signalProxy()->isSecure()) { + ui.keyAndCertSettings->setCurrentIndex(2); + _editSsl = true; + } else { + ui.keyAndCertSettings->setCurrentIndex(1); + _editSsl = false; + } +#else + ui.keyAndCertSettings->setCurrentIndex(0); +#endif load(); } else { // reset @@ -205,9 +215,13 @@ bool IdentitiesSettingsPage::aboutToSave() { void IdentitiesSettingsPage::clientIdentityCreated(IdentityId id) { CertIdentity *identity = new CertIdentity(*Client::identity(id), this); +#ifdef HAVE_SSL identity->enableEditSsl(_editSsl); +#endif insertIdentity(identity); +#ifdef HAVE_SSL connect(identity, SIGNAL(sslSettingsUpdated()), this, SLOT(clientIdentityUpdated())); +#endif connect(Client::identity(id), SIGNAL(updatedRemotely()), this, SLOT(clientIdentityUpdated())); } @@ -227,7 +241,7 @@ void IdentitiesSettingsPage::clientIdentityUpdated() { if(identity->identityName() != clientIdentity->identityName()) renameIdentity(identity->id(), clientIdentity->identityName()); - identity->update(*clientIdentity); + identity->copyFrom(*clientIdentity); if(identity->id() == currentId) displayIdentity(identity, true); @@ -317,8 +331,10 @@ void IdentitiesSettingsPage::displayIdentity(CertIdentity *id, bool dontsave) { ui.kickReason->setText(id->kickReason()); ui.partReason->setText(id->partReason()); ui.quitReason->setText(id->quitReason()); +#ifdef HAVE_SSL showKeyState(id->sslKey()); showCertState(id->sslCert()); +#endif } } @@ -344,8 +360,10 @@ void IdentitiesSettingsPage::saveToIdentity(CertIdentity *id) { id->setKickReason(ui.kickReason->text()); id->setPartReason(ui.partReason->text()); id->setQuitReason(ui.quitReason->text()); +#ifdef HAVE_SSL id->setSslKey(QSslKey(ui.keyTypeLabel->property("sslKey").toByteArray(), (QSsl::KeyAlgorithm)(ui.keyTypeLabel->property("sslKeyType").toInt()))); id->setSslCert(QSslCertificate(ui.certOrgLabel->property("sslCert").toByteArray())); +#endif } void IdentitiesSettingsPage::on_addIdentity_clicked() { @@ -358,10 +376,12 @@ void IdentitiesSettingsPage::on_addIdentity_clicked() { } id = -id.toInt(); CertIdentity *newId = new CertIdentity(id, this); +#ifdef HAVE_SSL newId->enableEditSsl(_editSsl); +#endif if(dlg.duplicateId() != 0) { // duplicate - newId->update(*identities[dlg.duplicateId()]); + newId->copyFrom(*identities[dlg.duplicateId()]); newId->setId(id); } newId->setIdentityName(dlg.identityName()); @@ -451,6 +471,7 @@ void IdentitiesSettingsPage::on_nickDown_clicked() { } } +#ifdef HAVE_SSL void IdentitiesSettingsPage::on_continueUnsecured_clicked() { _editSsl = true; @@ -462,30 +483,79 @@ void IdentitiesSettingsPage::on_continueUnsecured_clicked() { 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(event)); + return true; + case QEvent::Drop: + sslDropEvent(static_cast(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()) { - 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; - } - } - } + if(ui.keyTypeLabel->property("sslKey").toByteArray().isEmpty()) + key = keyByFilename(QFileDialog::getOpenFileName(this, tr("Load a Key"), QDesktopServices::storageLocation(QDesktopServices::HomeLocation))); - showKey: 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")); @@ -499,7 +569,7 @@ void IdentitiesSettingsPage::showKeyState(const QSslKey &key) { ui.keyTypeLabel->setText(tr("DSA")); break; default: - ui.keyTypeLabel->setText(tr("No Key Loaded")); + ui.keyTypeLabel->setText(tr("No Key loaded")); } ui.clearOrLoadKeyButton->setText(tr("Clear")); } @@ -510,24 +580,28 @@ void IdentitiesSettingsPage::showKeyState(const QSslKey &key) { 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; - } - } + 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")); @@ -540,6 +614,7 @@ void IdentitiesSettingsPage::showCertState(const QSslCertificate &cert) { } ui.certOrgLabel->setProperty("sslCert", cert.toPem()); } +#endif //HAVE_SSL /*****************************************************************************************/ @@ -598,7 +673,9 @@ SaveIdentitiesDlg::SaveIdentitiesDlg(const QList &toCreate, cons } connect(cid, SIGNAL(updatedRemotely()), this, SLOT(clientEvent())); Client::updateIdentity(id->id(), id->toVariantMap()); +#ifdef HAVE_SSL id->requestUpdateSslSettings(); +#endif } foreach(IdentityId id, toRemove) { Client::removeIdentity(id);