diff options
author | nils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2013-10-15 20:52:19 +0000 |
---|---|---|
committer | nils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2013-10-15 20:52:19 +0000 |
commit | e9a4bc3eda5dd0bd9c47efae8bac168846403e3d (patch) | |
tree | ebb4f8d2446aaf12fe951687112115298e0bcb91 | |
parent | add keyinforow qml widget (diff) | |
download | gpg4usb-e9a4bc3eda5dd0bd9c47efae8bac168846403e3d.tar.gz gpg4usb-e9a4bc3eda5dd0bd9c47efae8bac168846403e3d.zip |
keydetails widget in qml working
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@1061 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r-- | gpgcontext.cpp | 92 | ||||
-rw-r--r-- | gpgcontext.h | 8 | ||||
-rw-r--r-- | mainwindow.cpp | 36 | ||||
-rw-r--r-- | mainwindow.h | 1 | ||||
-rw-r--r-- | qml/KeyInfoRow.qml | 2 | ||||
-rw-r--r-- | qml/keydetails.qml | 157 | ||||
-rw-r--r-- | qmlpage.cpp | 42 | ||||
-rw-r--r-- | qmlpage.h | 8 | ||||
-rw-r--r-- | textedit.cpp | 4 | ||||
-rw-r--r-- | textedit.h | 3 |
10 files changed, 271 insertions, 82 deletions
diff --git a/gpgcontext.cpp b/gpgcontext.cpp index 4ec3e5a..bb4d7ca 100644 --- a/gpgcontext.cpp +++ b/gpgcontext.cpp @@ -29,7 +29,7 @@ #include <windows.h> #include <unistd.h> /* contains read/write */ #endif - +class QMessageBox; namespace GpgME { @@ -218,6 +218,96 @@ sigTimeMessage(const QString &sigtime) } +void GpgContext::exportKeyToFile(const QStringList &keyList) +{ + if (keyList.size() < 1) return; + + QStringList expopts; + KGpgExport *exp = new KGpgExport(this, keyList, expopts); + connect(exp, SIGNAL(done(int)), SLOT(slotExportKeyToFileReady(int))); + exp->start(); +} + +void GpgContext::slotExportKeyToFileReady(int result) +{ + KGpgExport *exp = qobject_cast<KGpgExport *>(sender()); + Q_ASSERT(exp != NULL); + + if (result == KGpgTransaction::TS_OK) { + GpgKey key = this->getKeyById(exp->getKeyIds().first()); + + QString fileString = key.name + " " + key.email + "(" + key.id+ ")_pub.asc"; + + QString fileName = QFileDialog::getSaveFileName(NULL, tr("Export Key To File"), fileString, tr("Key Files") + " (*.asc *.txt);;All Files (*)"); + QFile file(fileName); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + return; + QTextStream stream(&file); + QByteArray keyArray = exp->getOutputData(); + qDebug() << *keyArray; + stream << keyArray; + file.close(); + //emit statusBarChanged(QString(tr("key(s) exported"))); + } else { + //KMessageBox::sorry(this, i18n("Your public key could not be exported\nCheck the key.")); + qDebug() << "Your public key could not be exported\nCheck the key."; + } + + exp->deleteLater(); +} + +void GpgContext::exportPrivateKey(const QString &keyid) +{ + // Show a information box with explanation about private key + int ret = QMessageBox::information(NULL, tr("Exporting private Key"), + tr("You are about to export your private key.\n" + "This is NOT your public key, so don't give it away.\n" + "Make sure you keep it save." + "Do you really want to export your private key?"), + QMessageBox::Cancel | QMessageBox::Ok); + + // export key, if ok was clicked + if (ret == QMessageBox::Ok) { + /* QByteArray *keyArray = new QByteArray(); + mCtx->exportSecretKey(*keyid, keyArray); + KgpgCore::KgpgKey key = mCtx->getKeyDetails(*keyid); + QString fileString = key.name() + " " + key.email() + "(" + key.id()+ ")_pub_sec.asc"; + QString fileName = QFileDialog::getSaveFileName(this, tr("Export Key To File"), fileString, tr("Key Files") + " (*.asc *.txt);;All Files (*)"); + QFile file(fileName); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + QMessageBox::critical(0,tr("Export error"),tr("Couldn't open %1 for writing").arg(fileName)); + return; + } + QTextStream stream(&file); + stream << *keyArray; + file.close(); + delete keyArray;*/ + KgpgCore::KgpgKey key = this->getKeyDetails(keyid); + QString fileString = key.name() + " " + key.email() + "(" + key.id()+ ")_pub_sec.asc"; + + QString fileName = QFileDialog::getSaveFileName(NULL, tr("Export Key To File"), fileString, tr("Key Files") + " (*.asc *.txt);;All Files (*)"); + + QStringList expopts; + expopts.append(QLatin1String( "--armor" )); + KGpgExport *exp = new KGpgExport(this, QStringList() << keyid, fileName, expopts, true); + connect(exp, SIGNAL(done(int)), SLOT(slotExportPrivateKeyDone(int))); + exp->start(); + } +} + +void GpgContext::slotExportPrivateKeyDone(int result) { + KGpgExport *exp = qobject_cast<KGpgExport *>(sender()); + Q_ASSERT(exp != NULL); + + if (result == KGpgTransaction::TS_OK) { + qDebug() << "export seems ok"; + } else { + qDebug() << "Your key could not be exported\nCheck the key."; + } + + exp->deleteLater(); +} + QString GpgContext::getReport(const QStringList &log) { QString result; diff --git a/gpgcontext.h b/gpgcontext.h index 86b988a..6857c2c 100644 --- a/gpgcontext.h +++ b/gpgcontext.h @@ -27,8 +27,10 @@ #include <errno.h> #include <QLinkedList> #include <QtGui> + #include "kgpg/core/kgpgkey.h" #include "kgpg/transactions/kgpgverify.h" +#include "kgpg/transactions/kgpgexport.h" QT_BEGIN_NAMESPACE class QMessageBox; @@ -36,6 +38,7 @@ class sstream; class QApplication; class QByteArray; class QString; +class QFileDialog; QT_END_NAMESPACE class GpgKey @@ -126,6 +129,9 @@ public: GpgKey getKeyByFpr(QString fpr); GpgKey getKeyById(QString id); + void exportKeyToFile(const QStringList &keyList); + void exportPrivateKey(const QString &keyid); + void emitKeyDBChanged(); /** @@ -146,6 +152,8 @@ signals: private slots: void slotRefreshKeyList(); + void slotExportKeyToFileReady(int result); + void slotExportPrivateKeyDone(int result); private: QByteArray mPasswordCache; diff --git a/mainwindow.cpp b/mainwindow.cpp index c498379..d3777a0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1183,39 +1183,7 @@ void MainWindow::slotCopyMailAddressToClipboard() void MainWindow::slotExportKeyToFile() { - QStringList expopts; - KGpgExport *exp = new KGpgExport(this, *mKeyList->getChecked(), expopts); - connect(exp, SIGNAL(done(int)), SLOT(slotExportKeyToFileReady(int))); - exp->start(); -} - -void MainWindow::slotExportKeyToFileReady(int result) -{ - KGpgExport *exp = qobject_cast<KGpgExport *>(sender()); - Q_ASSERT(exp != NULL); - - if (result == KGpgTransaction::TS_OK) { - - GpgKey key = mCtx->getKeyById(exp->getKeyIds().first()); - - QString fileString = key.name + " " + key.email + "(" + key.id+ ")_pub.asc"; - - QString fileName = QFileDialog::getSaveFileName(this, tr("Export Key To File"), fileString, tr("Key Files") + " (*.asc *.txt);;All Files (*)"); - QFile file(fileName); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) - return; - QTextStream stream(&file); - QByteArray keyArray = exp->getOutputData(); - qDebug() << *keyArray; - stream << keyArray; - file.close(); - //emit statusBarChanged(QString(tr("key(s) exported"))); - } else { - //KMessageBox::sorry(this, i18n("Your public key could not be exported\nCheck the key.")); - qDebug() << "Your public key could not be exported\nCheck the key."; - } - - exp->deleteLater(); + mCtx->exportKeyToFile(*mKeyList->getChecked()); } void MainWindow::slotExportKeyToClipboard() @@ -1258,7 +1226,7 @@ void MainWindow::slotShowKeyDetails() KgpgCore::KgpgKey key = mCtx->getKeyDetails(mKeyList->getSelected()->first()); if (key.id() != "") { // TODO: get qml working here ;-) - edit->slotNewQMLTab(tr("Key: ") + key.name(), key); + edit->slotNewQMLTab(tr("Key: ") + key.name(), mCtx, key); new KeyDetailsDialog(mCtx, key, this); } diff --git a/mainwindow.h b/mainwindow.h index 8ba5499..058d488 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -178,7 +178,6 @@ private slots: * @details Export checked keys to file. */ void slotExportKeyToFile(); - void slotExportKeyToFileReady(int result); /** * @details Export checked keys to clipboard. diff --git a/qml/KeyInfoRow.qml b/qml/KeyInfoRow.qml index a1108dd..4b959d8 100644 --- a/qml/KeyInfoRow.qml +++ b/qml/KeyInfoRow.qml @@ -17,7 +17,7 @@ Rectangle { Text { id: valueText - x: 50 + x: 150 y: 0 text: value } diff --git a/qml/keydetails.qml b/qml/keydetails.qml index 141904f..1a1517f 100644 --- a/qml/keydetails.qml +++ b/qml/keydetails.qml @@ -10,10 +10,14 @@ Rectangle { signal clicked + signal exportPrivateKeyClicked + signal exportPublicKeyClicked + anchors.fill: parent property alias tf1Text: tf1.text property alias tf2Text: tf2.text + property string keyid: keymap.id // property keyid : "" // property email : "" @@ -39,33 +43,34 @@ Rectangle { } KeyInfoRow { - x: 119 - y: 54 + x: 144 + y: 281 // qsTr() for internationalisation, like tr() - key: qsTr("id:") - value: id + key: qsTr("keyid:") + value: keymap.id } KeyInfoRow { - x: 119 - y: 75 + x: 144 + y: 103 key: qsTr("email:") - value: email + value: keymap.email } KeyInfoRow { - x: 119 - y: 96 + x: 144 + y: 79 key: qsTr("name:") - value: name + value: keymap.name } KeyInfoRow { - x: 119 - y: 117 + x: 144 + y: 189 key: qsTr("keysize") - value: key.size() / key.encyptionSize() - } + value: keymap.size + "/" + keymap.encryptionSize + } + Image { @@ -88,31 +93,22 @@ Rectangle { } TextField { - x: 119 - y: 155 + x: 237 + y: 651 id: tf1 text: "some text" } - /* Button { - x: 246 - y: 155 - text: "ok" - onClicked: { - console.log("ok clicked, text: " + tf1.text) - } - }*/ - TextField { - x: 119 - y: 188 + x: 237 + y: 684 id: tf2 text: "some other text" } Button { - x: 246 - y: 188 + x: 364 + y: 684 text: "ok" onClicked: { console.log("ok clicked, text: " + tf1.text) @@ -121,6 +117,109 @@ Rectangle { } } + Text { + id: text1 + x: 137 + y: 54 + text: qsTr("Owner") + font.bold: true + font.pixelSize: 12 + } + + KeyInfoRow { + id: comment + x: 144 + y: 126 + key: qsTr("Comment") + value: keymap.comment + } + + Text { + id: text2 + x: 137 + y: 163 + text: qsTr("Keydetails") + font.pixelSize: 12 + font.bold: true + } + + KeyInfoRow { + id: creation + x: 144 + y: 258 + key: qsTr("Created on") + value: keymap.creationDate + } + + Text { + id: fingerprintLabel + x: 137 + y: 326 + text: qsTr("Fingerprint") + font.pixelSize: 12 + font.bold: true + } + + TextEdit { + id: fingerprint + x: 145 + y: 346 + text: keymap.fingerprint + font.pixelSize: 12 + readOnly: true + + } + + KeyInfoRow { + id: expiration + x: 144 + y: 212 + key: qsTr("Expires on") + value: keymap.expirationDate + } + + KeyInfoRow { + id: type + x: 144 + y: 235 + key: qsTr("Algorithm") + value: keymap.algorithm + "/" + keymap.encryptionAlgorithm + } + + Button { + id: exportPublicKeyButton + x: 144 + y: 392 + text: qsTr("Export public key") + onClicked: { + keydetails.exportPublicKeyClicked(); + } + + } + + Button { + id: exportPrivateKeyButton + x: 316 + y: 392 + text: qsTr("Export private key") + onClicked: { + keydetails.exportPrivateKeyClicked(); + } + visible: keymap.isSecret + } + + Button { + id: copyFingerprintButton + x: 401 + y: 341 + text: qsTr("copy") + onClicked: { + fingerprint.selectAll(); + fingerprint.copy(); + fingerprint.deselect(); + } + } + diff --git a/qmlpage.cpp b/qmlpage.cpp index 64a8640..e1c21a3 100644 --- a/qmlpage.cpp +++ b/qmlpage.cpp @@ -4,10 +4,11 @@ #include <QDebug> #include <QGraphicsObject> #include <QDeclarativeProperty> +#include <QDeclarativePropertyMap> +#include "kgpg/core/convert.h" - -QMLPage::QMLPage(KgpgCore::KgpgKey key, QWidget *parent) : - QWidget(parent) +QMLPage::QMLPage(GpgME::GpgContext *ctx, KgpgCore::KgpgKey key, QWidget *parent) : + QWidget(parent), mCtx(ctx) { // http://harmattan-dev.nokia.com/docs/library/html/qt4/qml-integration.html @@ -27,19 +28,31 @@ QMLPage::QMLPage(KgpgCore::KgpgKey key, QWidget *parent) : qmlView->setSource(QUrl("qrc:/qml/keydetails.qml")); - /* - or: http://xizhizhu.blogspot.de/2010/10/hybrid-application-using-qml-and-qt-c.html - DeclarativePropertyMap map; - map.insert("key1", "value1"); - map.insert("key2", "value2"); - context->setContextProperty("map", &map); - */ + //or: http://xizhizhu.blogspot.de/2010/10/hybrid-application-using-qml-and-qt-c.html + QDeclarativePropertyMap keymap; + keymap.insert("id", key.id()); + keymap.insert("email", key.email()); + keymap.insert("name", key.name()); + keymap.insert("comment", key.comment()); + keymap.insert("size", key.size()); + keymap.insert("encryptionSize", key.encryptionSize()); + keymap.insert("algorithm",KgpgCore::Convert::toString(key.algorithm())); + keymap.insert("encryptionAlgorithm", KgpgCore::Convert::toString(key.encryptionAlgorithm())); + keymap.insert("creationDate", KgpgCore::Convert::toString(key.creationDate().date())); + keymap.insert("expirationDate",KgpgCore::Convert::toString(key.expirationDate().date())); + keymap.insert("fingerprint",key.fingerprintBeautified()); + keymap.insert("isSecret",ctx->isSecretKey(key.id())); + context->setContextProperty("keymap", &keymap); + + // http://stackoverflow.com/questions/5947455/connecting-qml-signals-to-qt obj = qmlView->rootObject(); connect( obj, SIGNAL(clicked()), this, SLOT(qmlClicked())); + connect( obj, SIGNAL(exportPublicKeyClicked()), this, SLOT(slotExportPublicKey())); + connect( obj, SIGNAL(exportPrivateKeyClicked()), this, SLOT(slotExportPrivateKey())); QHBoxLayout *mainLayout = new QHBoxLayout(this); mainLayout->setSpacing(0); @@ -58,3 +71,12 @@ void QMLPage::qmlClicked() { qDebug() << "text2 "<< obj->property("tf2Text"); } +void QMLPage::slotExportPublicKey() { + QString id=obj->property("keyid").toString(); + mCtx->exportKeyToFile(QStringList(id)); +} + +void QMLPage::slotExportPrivateKey() { + QString id=obj->property("keyid").toString(); + mCtx->exportPrivateKey(id); +} @@ -5,6 +5,7 @@ #include <QDeclarativeContext> #include <QGraphicsObject> #include "kgpg/core/kgpgkey.h" +#include "gpgcontext.h" class QMLPage : public QWidget { @@ -12,15 +13,16 @@ class QMLPage : public QWidget Q_OBJECT public: - QMLPage(KgpgCore::KgpgKey key, QWidget *parent = 0); + QMLPage(GpgME::GpgContext *ctx, KgpgCore::KgpgKey key, QWidget *parent = 0); public slots: void qmlClicked(); - + void slotExportPublicKey(); + void slotExportPrivateKey(); private: QDeclarativeContext *context; QGraphicsObject *obj; - + GpgME::GpgContext *mCtx; }; #endif // QMLPAGE_H diff --git a/textedit.cpp b/textedit.cpp index ca2a904..3f743a0 100644 --- a/textedit.cpp +++ b/textedit.cpp @@ -66,8 +66,8 @@ void TextEdit::slotNewHelpTab(QString title, QString path) } -void TextEdit::slotNewQMLTab(QString title, KgpgCore::KgpgKey key) { - QMLPage *page = new QMLPage(key); +void TextEdit::slotNewQMLTab(QString title, GpgME::GpgContext *ctx, KgpgCore::KgpgKey key) { + QMLPage *page = new QMLPage(ctx, key); // todo: should parent also be given? tabWidget->addTab(page, title); tabWidget->setCurrentIndex(tabWidget->count() - 1); @@ -26,6 +26,7 @@ #include "helppage.h" #include "quitdialog.h" #include "kgpg/core/kgpgkey.h" +#include "gpgcontext.h" QT_BEGIN_NAMESPACE class QDebug; @@ -148,7 +149,7 @@ public slots: */ void slotNewHelpTab(QString title, QString path); - void slotNewQMLTab(QString title, KgpgCore::KgpgKey key); + void slotNewQMLTab(QString title, GpgME::GpgContext *ctx, KgpgCore::KgpgKey key); /** * @details put a * in front of current tabs title, if current textedit is modified |