1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*
* 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(mCtx, mIconPath);
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();
}
|