# # # patch "src/view/dialogs/KeyManagement.cpp" # from [1a77eaf7d6772c2fca16d0ecc28a3fabcca92131] # to [445609b72e2b33032823410e5652602aa350677c] # # patch "src/view/dialogs/KeyManagement.h" # from [01b2a2e75eb75d51b9a9d9107242b457019ff924] # to [1c8c59a3e48915e5486e582b3410c3fecc9340a2] # ============================================================ --- src/view/dialogs/KeyManagement.cpp 1a77eaf7d6772c2fca16d0ecc28a3fabcca92131 +++ src/view/dialogs/KeyManagement.cpp 445609b72e2b33032823410e5652602aa350677c @@ -20,55 +20,45 @@ #include "KeyManagement.h" #include "GenerateKeypair.h" -#include "Monotone.h" +#include "MonotoneManager.h" +#include "Guitone.h" #include #include #include -#include -KeyManagement::KeyManagement(QWidget* parent) - : Dialog(parent) +KeyManagement::KeyManagement(QWidget * parent, const DatabaseFile & db) + : Dialog(parent), databaseFile(db) { setupUi(this); - Dialog::init(); - + Dialog::init(); + // OSX sheet-alike dialog setWindowFlags(Qt::Sheet); - - model = new Keys(this); + + model = new Keys(this, databaseFile); keyList->setModel(model); - - if (!model->readKeys()) - { - QMessageBox::critical( - this, - tr("Unable to execute command"), - tr("Unable to execute '%1' - maybe another command is still running?").arg("keys"), - QMessageBox::Ok - ); - QTimer::singleShot(0, this, SLOT(reject())); - return; - } - + connect( generateKey, SIGNAL(clicked()), - this, SLOT(generateKeypair()) + this, SIGNAL(generateKeypair()) ); - + popupMenu = new QMenu(this); - - QAction * act = new QAction(tr("Copy key name to clipboard"), this); - connect(act, SIGNAL(triggered()), this, SLOT(copyKeyNameToClipboard())); + + QAction * act = new QAction(tr("Copy key name to clipboard"), this); + connect(act, SIGNAL(triggered()), this, SLOT(copyKeyNameToClipboard())); popupMenu->addAction(act); - - act = new QAction(tr("Copy public key hash to clipboard"), this); - connect(act, SIGNAL(triggered()), this, SLOT(copyPubkeyHashToClipboard())); + + act = new QAction(tr("Copy public key hash to clipboard"), this); + connect(act, SIGNAL(triggered()), this, SLOT(copyPubkeyHashToClipboard())); popupMenu->addAction(act); - - act = new QAction(tr("Copy public key data to clipboard"), this); - connect(act, SIGNAL(triggered()), this, SLOT(copyPubkeyDataToClipboard())); + + act = new QAction(tr("Copy public key data to clipboard"), this); + connect(act, SIGNAL(triggered()), this, SLOT(copyPubkeyDataToClipboard())); popupMenu->addAction(act); + + readKeys(); } KeyManagement::~KeyManagement() @@ -78,44 +68,26 @@ KeyManagement::~KeyManagement() delete popupMenu; } -// TODO: maybe we want to make the keypair generating dialog a small expanding -// widget inside the main dialog? -void KeyManagement::generateKeypair() +void KeyManagement::readKeys() { - // we need to hide the current dialog otherwise we can't show the next - // dialog as sheet on OSX (its apparently not possible to have more than - // one sheet opened for a main window at a time) - hide(); - - // the sheet must be rooted to the main window otherwise - // a plain dialog is displayed - GenerateKeypair dlg(parentWidget()); - - // if the key was successfully created, reload the key list - if (dlg.execDocumentModal() == QDialog::Accepted) - { - model->readKeys(); - } - - // show the keys dialog again - show(); + model->readKeys(); } void KeyManagement::contextMenuEvent(QContextMenuEvent* ev) { - QItemSelectionModel* selection = keyList->selectionModel(); + QItemSelectionModel * selection = keyList->selectionModel(); QList indexList = selection->selectedIndexes(); if (indexList.size() == 0) return; - + popupMenu->exec(mapToGlobal(ev->pos())); } Key * KeyManagement::getKeyFromSelection() const { - QItemSelectionModel* selection = keyList->selectionModel(); + QItemSelectionModel * selection = keyList->selectionModel(); QList indexList = selection->selectedIndexes(); // we're only interested in the first column's internal pointer - return static_cast(indexList[0].internalPointer()); + return static_cast(indexList[0].internalPointer()); } void KeyManagement::copyKeyNameToClipboard() @@ -132,9 +104,28 @@ void KeyManagement::copyPubkeyHashToClip clipboard->setText(key->public_hash); } +//! \todo should be converted to automate pubkey, if available void KeyManagement::copyPubkeyDataToClipboard() { - // FIXME: no automate pubkey available yet - C("Not implemented"); + Key * key = getKeyFromSelection(); + QClipboard * clipboard = QApplication::clipboard(); + + QStringList args; + QByteArray output; + args << "-d" << databaseFile << "pubkey" << key->name; + + if (!APP->manager()->singleRun(args, output)) + { + QMessageBox::critical( + this, + tr("Couldn't query public key data"), + tr("Failed to query public key data for key \"%1\".") + .arg(key->name), + QMessageBox::Ok + ); + return; + } + + clipboard->setText(QString::fromUtf8(output)); } ============================================================ --- src/view/dialogs/KeyManagement.h 01b2a2e75eb75d51b9a9d9107242b457019ff924 +++ src/view/dialogs/KeyManagement.h 1c8c59a3e48915e5486e582b3410c3fecc9340a2 @@ -30,21 +30,26 @@ class KeyManagement : public Dialog, pri class KeyManagement : public Dialog, private Ui::KeyManagement { - Q_OBJECT - + Q_OBJECT public: - KeyManagement(QWidget*); - ~KeyManagement(); - void contextMenuEvent(QContextMenuEvent* ev); - + KeyManagement(QWidget *, const DatabaseFile &); + ~KeyManagement(); + void contextMenuEvent(QContextMenuEvent *); + +public slots: + void readKeys(); + +signals: + void generateKeypair(); + private: Key * getKeyFromSelection() const; Keys * model; QMenu * popupMenu; - + DatabaseFile databaseFile; + private slots: - void generateKeypair(); void copyKeyNameToClipboard(); void copyPubkeyHashToClipboard(); void copyPubkeyDataToClipboard();