aboutsummaryrefslogtreecommitdiffstats
path: root/keymgmt.cpp
diff options
context:
space:
mode:
authorubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2008-09-29 17:12:22 +0000
committerubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2008-09-29 17:12:22 +0000
commit2c251e90452a5eca7e14eafb9c51192f3493fc9f (patch)
tree384907b829e2a56d6e31014046b75ac329ad5091 /keymgmt.cpp
parentmoved keydelete-action from keylist to gpgwin (diff)
downloadgpg4usb-2c251e90452a5eca7e14eafb9c51192f3493fc9f.tar.gz
gpg4usb-2c251e90452a5eca7e14eafb9c51192f3493fc9f.zip
added key management window
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@177 34ebc366-c3a9-4b3c-9f84-69acf7962910
Diffstat (limited to 'keymgmt.cpp')
-rwxr-xr-xkeymgmt.cpp131
1 files changed, 131 insertions, 0 deletions
diff --git a/keymgmt.cpp b/keymgmt.cpp
new file mode 100755
index 0000000..d666bf1
--- /dev/null
+++ b/keymgmt.cpp
@@ -0,0 +1,131 @@
+/*
+ * keymgmt.cpp
+ *
+ * Copyright 2008 gpg4usb-team <[email protected]>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <QtGui>
+
+#include "keymgmt.h"
+#include "keyutils.h"
+
+KeyMgmt::KeyMgmt(GpgME::Context *ctx, QString iconpath)
+{
+ mCtx = ctx;
+ mIconPath = iconpath;
+ resize(640, 400);
+
+ /* the list of Keys available*/
+ m_keyList = new KeyList();
+ m_keyList->setIconPath(mIconPath);
+ m_keyList->setContext(mCtx);
+ m_keyList->setColumnWidth(2,250);
+ m_keyList->setColumnWidth(3,250);
+ setCentralWidget(m_keyList);
+ createActions();
+ createMenus();
+ createToolBars();
+ setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
+ setIconSize(QSize(32, 32));
+
+ setWindowTitle(tr("Keymanagement"));
+ m_keyList->addMenuAction(deleteSelectedKeysAct);
+}
+
+void KeyMgmt::createActions()
+{
+ closeAct = new QAction(tr("&Close Key Management"), this);
+ closeAct->setShortcut(tr("Ctrl+Q"));
+ closeAct->setIcon(QIcon(mIconPath + "exit.png"));
+ closeAct->setStatusTip(tr("Close Key Management"));
+ connect(closeAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ importKeyFromFileAct = new QAction(tr("Import Key From &File"), this);
+ importKeyFromFileAct->setIcon(QIcon(mIconPath + "importkey_editor.png"));
+ importKeyFromFileAct->setStatusTip(tr("Import New Key From File"));
+ connect(importKeyFromFileAct, SIGNAL(triggered()), this, SLOT(importKeyFromFile()));
+
+ importKeyFromClipboardAct = new QAction(tr("Import Key From &Clipboard"), this);
+ importKeyFromClipboardAct->setIcon(QIcon(mIconPath + "importkey_editor.png"));
+ importKeyFromClipboardAct->setStatusTip(tr("Import New Key From Clipboard"));
+ connect(importKeyFromClipboardAct, SIGNAL(triggered()), this, SLOT(importKeyFromClipboard()));
+
+ deleteSelectedKeysAct = new QAction(tr("Delete Selected Key(s)"), this);
+ deleteSelectedKeysAct->setStatusTip(tr("Delete the Selected keys"));
+ connect(deleteSelectedKeysAct, SIGNAL(triggered()), this, SLOT(deleteSelectedKeys()));
+
+ deleteCheckedKeysAct = new QAction(tr("Delete Checked Key(s)"), this);
+ deleteCheckedKeysAct->setStatusTip(tr("Delete the Checked keys"));
+ deleteCheckedKeysAct->setIcon(QIcon(mIconPath + "button_cancel.png"));
+ connect(deleteCheckedKeysAct, SIGNAL(triggered()), this, SLOT(deleteCheckedKeys()));
+}
+
+void KeyMgmt::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&Quit"));
+ fileMenu->addAction(closeAct);
+ keyMenu = menuBar()->addMenu(tr("&Key"));
+ keyMenu->addAction(importKeyFromFileAct);
+ keyMenu->addAction(importKeyFromClipboardAct);
+ keyMenu->addSeparator();
+ keyMenu->addAction(deleteCheckedKeysAct);
+}
+
+void KeyMgmt::createToolBars()
+{
+ QToolBar *keyToolBar = addToolBar(tr("Crypt"));
+ keyToolBar->addAction(importKeyFromFileAct);
+ keyToolBar->addAction(importKeyFromClipboardAct);
+ keyToolBar->addSeparator();
+ keyToolBar->addAction(deleteCheckedKeysAct);
+}
+
+void KeyMgmt::importKeyFromFile()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open Key"), "", tr("Key Files") + " (*.asc *.txt);;All Files (*.*)");
+ if (! fileName.isNull()) {
+ QFile file;
+ file.setFileName(fileName);
+ if (!file.open(QIODevice::ReadOnly)) {
+ qDebug() << tr("couldn't open file: ") + fileName;
+ }
+ QByteArray inBuffer = file.readAll();
+
+ mCtx->importKey(inBuffer);
+ m_keyList->refresh();
+ }
+}
+
+void KeyMgmt::importKeyFromClipboard()
+{
+ QClipboard *cb = QApplication::clipboard();
+ mCtx->importKey(cb->text(QClipboard::Clipboard).toAscii());
+ m_keyList->refresh();
+}
+
+void KeyMgmt::deleteSelectedKeys()
+{
+ mCtx->deleteKeys(m_keyList->getSelected());
+ m_keyList->refresh();
+}
+
+void KeyMgmt::deleteCheckedKeys()
+{
+ mCtx->deleteKeys(m_keyList->getChecked());
+ m_keyList->refresh();
+}