# # # rename "guitone/res/dialogs/KeyManagment.ui" # to "guitone/res/dialogs/key_management.ui" # # rename "guitone/src/view/dialogs/KeyManagment.cpp" # to "guitone/src/view/dialogs/KeyManagement.cpp" # # rename "guitone/src/view/dialogs/KeyManagment.h" # to "guitone/src/view/dialogs/KeyManagement.h" # # add_file "guitone/src/model/Keys.cpp" # content [2868d3db8852fafe2471388840bfafb1dafcabd2] # # add_file "guitone/src/model/Keys.h" # content [fa48cbbf52ba7b888166849c0db3d1094a6cfa71] # # patch "guitone/guitone.pro" # from [48b6b4edd159d5211be15bdf4cc30754bb91a5e3] # to [83d543d1ffc79f75e37533000e233f47953227d4] # # patch "guitone/res/dialogs/key_management.ui" # from [76beb68dee089fc0b60df5d2f304c17269916d56] # to [3506120945aedbed88014c179992e12288b2c18e] # # patch "guitone/src/view/Guitone.cpp" # from [2ea7d8be74a7a599ca71f805361489c09338089b] # to [c007d15ec51b0c5d16ffa9ee5d4b308ee3bf5c84] # # patch "guitone/src/view/Guitone.h" # from [5316c0616305cfa923a5d039a9f994a77245cba0] # to [da337e9ca2767bc6458a7933a8c4786b712fcb22] # # patch "guitone/src/view/dialogs/KeyManagement.cpp" # from [e6b7fc996f3623f4f9933b7a79c93f76520423cf] # to [d370e0b83f27bb75d78dc4f352e6766f9e307a4a] # # patch "guitone/src/view/dialogs/KeyManagement.h" # from [266ae02b3462ef2a06e2d0529f1699d2c4767963] # to [7e7ae87bdbf2c21c29d2cecd726fdcede80bc353] # ============================================================ --- guitone/src/model/Keys.cpp 2868d3db8852fafe2471388840bfafb1dafcabd2 +++ guitone/src/model/Keys.cpp 2868d3db8852fafe2471388840bfafb1dafcabd2 @@ -0,0 +1,233 @@ +/*************************************************************************** + * Copyright (C) 2006 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "Keys.h" +#include "../monotone/Monotone.h" +#include "../util/StanzaParser.h" + +Keys::Keys(QObject *parent) + : AutomateCommand(parent) +{ + keys = new KeyList(); +} + +Keys::~Keys() +{ + keys->clear(); + delete keys; +} + +bool Keys::readKeys() +{ + keys->clear(); + reset(); + + QStringList cmd; + cmd << "keys"; + + Monotone *mtn = Monotone::singleton(); + + return mtn->triggerCommand(this, cmd); +} + +void Keys::parseOutput(AutomateCommand *caller) +{ + // if not we are the caller, omit the parsing + if (caller != this) return; + + StanzaParser* parser = new StanzaParser(AutomateCommand::data); + StanzaList list = parser->getStanzas(); + + for (int i=0, size = list.size(); i < size; ++i) + { + Stanza stanza = list.at(i); + + Key key; + bool isItem = false; + + for (int j=0, size2 = stanza.size(); j < size2; j++) + { + StanzaEntry entry = stanza.at(j); + + // we're now only interested in stanzas starting with a "name" entry + if (j == 0 && entry.sym != "name") break; + + isItem = true; + + if (entry.sym == "name") + { + Q_ASSERT(entry.vals.size() == 1); + key.name = entry.vals.at(0); + continue; + } + + if (entry.sym == "public_hash") + { + Q_ASSERT(entry.vals.size() == 1); + key.public_hash = entry.vals.at(0); + continue; + } + + if (entry.sym == "private_hash") + { + Q_ASSERT(entry.vals.size() == 1); + key.private_hash = entry.vals.at(0); + continue; + } + + if (entry.sym == "public_location") + { + for (int k=0, size3 = entry.vals.size(); k < size3; k++) + { + if (entry.vals.at(k) == "database") + { + key.public_locations |= Key::Database; + continue; + } + + if (entry.vals.at(k) == "keystore") + { + key.public_locations |= Key::Keystore; + continue; + } + + qWarning( + "Keys::parseOutput(): Unknown key location '%s'.", + qPrintable(entry.vals.at(k)) + ); + } + continue; + } + + if (entry.sym == "private_location") + { + for (int k=0, size3 = entry.vals.size(); k < size3; k++) + { + if (entry.vals.at(k) == "database") + { + key.private_locations |= Key::Database; + continue; + } + + if (entry.vals.at(k) == "keystore") + { + key.private_locations |= Key::Keystore; + continue; + } + + qWarning( + "Keys::parseOutput(): Unknown key location '%s'.", + qPrintable(entry.vals.at(k)) + ); + } + continue; + } + + qWarning("Keys::parseOutput(): Unknown symbol %s.", qPrintable(entry.sym)); + } + + // check if we really processed an item entry + if (!isItem) continue; + keys->append(key); + } + + reset(); + emit keysRead(); +} + +int Keys::columnCount(const QModelIndex &parent) const +{ + return 5; +} + +QVariant Keys::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + { + return QVariant(); + } + + if (role != Qt::DisplayRole) + { + return QVariant(); + } + + int row = index.row(); + if (row >= keys->size()) return QVariant(); + + Key key = keys->at(row); + + switch (index.column()) + { + case 0: return QVariant(key.name); + case 1: return QVariant(key.public_hash); + case 2: return QVariant(key.private_hash); + case 3: return QVariant(getLocationString(key.public_locations)); + case 4: return QVariant(getLocationString(key.private_locations)); + } + + return QVariant(); +} + +QString Keys::getLocationString(int loc) +{ + QStringList str; + if (loc & Key::Database == Key::Database) + str << tr("Database"); + if (loc & Key::Keystore == Key::Keystore) + str << tr("Keystore"); + return str.join(", "); +} + +Qt::ItemFlags Keys::flags(const QModelIndex &index) const +{ + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QVariant Keys::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + switch (section) + { + case 0: return QVariant(tr("Name")); + case 1: return QVariant(tr("Public Hash")); + case 2: return QVariant(tr("Private Hash")); + case 3: return QVariant(tr("Public Locations")); + case 4: return QVariant(tr("Private Locations")); + } + } + return QVariant(); +} + +int Keys::rowCount(const QModelIndex& parent) const +{ + return keys->size(); +} + +QModelIndex Keys::index(int row, int column, const QModelIndex& parent) const +{ + return hasIndex(row, column, parent) ? createIndex(row, column, 0) : QModelIndex(); +} + +QModelIndex Keys::parent(const QModelIndex& index) const +{ + return QModelIndex(); +} ============================================================ --- guitone/src/model/Keys.h fa48cbbf52ba7b888166849c0db3d1094a6cfa71 +++ guitone/src/model/Keys.h fa48cbbf52ba7b888166849c0db3d1094a6cfa71 @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (C) 2006 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef KEYS_H +#define KEYS_H + +#include "AutomateCommand.h" + +typedef struct { + static const int Database = 1; + static const int Keystore = 2; + QString name; + QString public_hash; + QString private_hash; + int public_locations; + int private_locations; +} Key; +typedef QList KeyList; + +class Keys : public AutomateCommand +{ + Q_OBJECT +public: + Keys(QObject*); + virtual ~Keys(); + + // needed Qt Model methods + QVariant data(const QModelIndex&, int) const; + Qt::ItemFlags flags(const QModelIndex&) const; + QVariant headerData(int, Qt::Orientation, int) const; + QModelIndex index(int, int, const QModelIndex&) const; + QModelIndex parent(const QModelIndex&) const; + int rowCount(const QModelIndex&) const; + int columnCount(const QModelIndex&) const; + +public slots: + bool readKeys(); + +signals: + void keysRead(); + +private: + void parseOutput(AutomateCommand*); + QString getLocationString(int); + KeyList * keys; +}; + +#endif ============================================================ --- guitone/guitone.pro 48b6b4edd159d5211be15bdf4cc30754bb91a5e3 +++ guitone/guitone.pro 83d543d1ffc79f75e37533000e233f47953227d4 @@ -16,7 +16,7 @@ HEADERS += src/view/Guitone.h \ src/view/dialogs/Preferences.h \ src/view/dialogs/AncestryGraph.h \ src/view/dialogs/FileDiff.h \ - src/view/dialogs/KeyManagment.h \ + src/view/dialogs/KeyManagement.h \ src/monotone/Monotone.h \ src/model/AutomateCommand.h \ src/model/Inventory.h \ @@ -29,6 +29,7 @@ HEADERS += src/view/Guitone.h \ src/model/ContentDiff.h \ src/model/GetFile.h \ src/model/GetFileProxyModel.h \ + src/model/Keys.h \ src/util/IconProvider.h \ src/util/StanzaParser.h \ src/util/Settings.h \ @@ -45,7 +46,7 @@ SOURCES += src/view/Guitone.cpp \ src/view/dialogs/Preferences.cpp \ src/view/dialogs/AncestryGraph.cpp \ src/view/dialogs/FileDiff.cpp \ - src/view/dialogs/KeyManagment.cpp \ + src/view/dialogs/KeyManagement.cpp \ src/monotone/Monotone.cpp \ src/model/AutomateCommand.cpp \ src/model/Inventory.cpp \ @@ -58,6 +59,7 @@ SOURCES += src/view/Guitone.cpp \ src/model/ContentDiff.cpp \ src/model/GetFile.cpp \ src/model/GetFileProxyModel.cpp \ + src/model/Keys.cpp \ src/util/IconProvider.cpp \ src/util/StanzaParser.cpp \ src/util/Settings.cpp \ @@ -68,7 +70,7 @@ FORMS += res/dialogs/switch_workspace. res/dialogs/preferences.ui \ res/dialogs/ancestry_graph.ui \ res/dialogs/file_diff.ui \ - res/dialogs/KeyManagment.ui + res/dialogs/key_management.ui UI_DIR = src/view/dialogs OBJECTS_DIR = tmp MOC_DIR = tmp ============================================================ --- guitone/res/dialogs/KeyManagment.ui 76beb68dee089fc0b60df5d2f304c17269916d56 +++ guitone/res/dialogs/key_management.ui 3506120945aedbed88014c179992e12288b2c18e @@ -1,52 +1,25 @@ - - - - KeyManagment - + KeyManagement + 0 0 - 587 + 609 433 - Key Managment + Key Management - + 9 6 - - - - - Hash - - - - - Name - - - - - Pub Loc - - - - - Priv Loc - - - - - + 0 @@ -55,107 +28,99 @@ 6 - - - Generate - - - - - - - Remove - - - - - - - - - Qt::Vertical - - - - 20 - 131 - - - - - - - - 0 - - - 6 - - - - - Qt::Horizontal - - + + - 131 - 31 + 400 + 0 - - - - - - OK + + false + + false + - - - Cancel + + + 0 - + + 6 + + + + + Generate Keypair + + + + + + + Show signed Revisions + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Close + + + + - + + + TreeView + QTreeView +
../TreeView.h
+
+
+ + keyList + closeButton + generateKey + showSignedRevisions + - okButton + closeButton clicked() - KeyManagment + KeyManagement accept() - 278 - 253 + 523 + 24 - 96 - 254 + 293 + 216 - - cancelButton - clicked() - KeyManagment - reject() - - - 369 - 253 - - - 179 - 282 - - -
============================================================ --- guitone/src/view/Guitone.cpp 2ea7d8be74a7a599ca71f805361489c09338089b +++ guitone/src/view/Guitone.cpp c007d15ec51b0c5d16ffa9ee5d4b308ee3bf5c84 @@ -30,7 +30,7 @@ #include "../view/dialogs/SwitchWorkspaceRevision.h" #include "../view/dialogs/Preferences.h" #include "../view/dialogs/AncestryGraph.h" -#include "../view/dialogs/KeyManagment.h" +#include "../view/dialogs/KeyManagement.h" #include "../util/Settings.h" #include @@ -116,16 +116,14 @@ Guitone::Guitone() SLOT(openAncestryGraphDialog()), Qt::CTRL + Qt::Key_A ); - /* - // Disabled until we see any functionality there... + menu->addAction( - tr("&Key Managment"), + tr("&Key Management"), this, - SLOT(openKeyManagmentDialog()), + SLOT(openKeyManagementDialog()), Qt::CTRL + Qt::Key_K ); - */ - + menu = menuBar()->addMenu(tr("&Help")); menu->addAction( tr("About &Qt"), @@ -394,8 +392,8 @@ void Guitone::openAncestryGraphDialog() dialog.exec(); } -void Guitone::openKeyManagmentDialog() +void Guitone::openKeyManagementDialog() { - KeyManagment dialog(this); + KeyManagement dialog(this); dialog.exec(); } ============================================================ --- guitone/src/view/Guitone.h 5316c0616305cfa923a5d039a9f994a77245cba0 +++ guitone/src/view/Guitone.h da337e9ca2767bc6458a7933a8c4786b712fcb22 @@ -49,7 +49,7 @@ private slots: void openSwitchWorkspaceRevisionDialog(); void openPreferencesDialog(); void openAncestryGraphDialog(); - void openKeyManagmentDialog(); + void openKeyManagementDialog(); private: void closeEvent(QCloseEvent *); ============================================================ --- guitone/src/view/dialogs/KeyManagment.cpp e6b7fc996f3623f4f9933b7a79c93f76520423cf +++ guitone/src/view/dialogs/KeyManagement.cpp d370e0b83f27bb75d78dc4f352e6766f9e307a4a @@ -18,19 +18,21 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "KeyManagment.h" +#include "KeyManagement.h" #include "../../util/Settings.h" #include "../../monotone/Monotone.h" -KeyManagment::KeyManagment(QWidget* parent) +KeyManagement::KeyManagement(QWidget* parent) : QDialog(parent) { setupUi(this); + + model = new Keys(this); + keyList->setModel(model); + + // FIXME: error handling! + model->readKeys(); } -KeyManagment::~KeyManagment() {} +KeyManagement::~KeyManagement() {} -void KeyManagment::accept() -{ - done(0); -} ============================================================ --- guitone/src/view/dialogs/KeyManagment.h 266ae02b3462ef2a06e2d0529f1699d2c4767963 +++ guitone/src/view/dialogs/KeyManagement.h 7e7ae87bdbf2c21c29d2cecd726fdcede80bc353 @@ -18,21 +18,22 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef KEYMANAGMENT_H -#define KEYMANAGMENT_H +#ifndef KEYMANAGEMENT_H +#define KEYMANAGEMENT_H -#include "ui_KeyManagment.h" +#include "../../model/Keys.h" +#include "ui_key_management.h" -class KeyManagment : public QDialog, private Ui::KeyManagment +class KeyManagement : public QDialog, private Ui::KeyManagement { Q_OBJECT public: - KeyManagment(QWidget*); - ~KeyManagment(); + KeyManagement(QWidget*); + ~KeyManagement(); -private slots: - void accept(); +private: + Keys * model; }; #endif