aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2008-08-10 12:03:28 +0000
committerubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2008-08-10 12:03:28 +0000
commitdf453aa37f68ca6e4df9a73fb0c9529f9009d274 (patch)
tree8a6315cfa464d5273ed1abb66954ee3e65993ba9
parentuse absolute path to application for finding bin/gpg / bin\gpg.exe (diff)
downloadgpg4usb-df453aa37f68ca6e4df9a73fb0c9529f9009d274.tar.gz
gpg4usb-df453aa37f68ca6e4df9a73fb0c9529f9009d274.zip
some source-beatyfying with astyle, use absolute path to find icons
git-svn-id: http://cpunk.de/svn/src/gpg4usb@120 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r--context.cpp1
-rw-r--r--gpgwin.cpp628
-rw-r--r--gpgwin.h99
-rw-r--r--keylist.cpp110
-rw-r--r--keylist.h6
-rw-r--r--main.cpp41
6 files changed, 453 insertions, 432 deletions
diff --git a/context.cpp b/context.cpp
index bfcc1df..dd864bf 100644
--- a/context.cpp
+++ b/context.cpp
@@ -42,7 +42,6 @@ namespace GpgME {
/** get current dir */
QString appPath = qApp->applicationDirPath();
- qDebug() << "path" << appPath;
/** The function `gpgme_check_version' must be called before any other
* function in the library, because it initializes the thread support
diff --git a/gpgwin.cpp b/gpgwin.cpp
index 0c9bb59..b01ea90 100644
--- a/gpgwin.cpp
+++ b/gpgwin.cpp
@@ -36,361 +36,369 @@
#include "gpgwin.h"
- GpgWin::GpgWin()
- {
- myCtx = new GpgME::Context();
+GpgWin::GpgWin()
+{
+ myCtx = new GpgME::Context();
+
+ /* get path were app was started */
+ QString appPath = qApp->applicationDirPath();
+ iconPath = appPath + "/icons/";
- edit = new QPlainTextEdit();
- setCentralWidget(edit);
+ edit = new QPlainTextEdit();
+ setCentralWidget(edit);
- /* the list of Keys available*/
- m_keyList = new KeyList();
- m_keyList->setContext(myCtx);
+ /* the list of Keys available*/
+ m_keyList = new KeyList();
+ m_keyList->setContext(myCtx);
+ m_keyList->setIconPath(iconPath);
- createActions();
- createMenus();
- createToolBars();
- createStatusBar();
- createDockWindows();
+ createActions();
+ createMenus();
+ createToolBars();
+ createStatusBar();
+ createDockWindows();
- setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
- setIconSize(QSize(32, 32));
- setCurrentFile("");
+ setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
+ setIconSize(QSize(32, 32));
+ setCurrentFile("");
}
void GpgWin::createActions()
- {
+{
/** Main Menu
*/
- openAct = new QAction(tr("&Open..."), this);
- openAct->setIcon(QIcon("icons/fileopen.png"));
- openAct->setShortcut(tr("Ctrl+O"));
- openAct->setStatusTip(tr("Open an existing file"));
- connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
-
- saveAct = new QAction(tr("&Save"), this);
- saveAct->setIcon(QIcon("icons/filesave.png"));
- saveAct->setShortcut(tr("Ctrl+S"));
- saveAct->setStatusTip(tr("Save the current File"));
- connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
-
- saveAsAct = new QAction(tr("Save &As"), this);
- saveAsAct->setIcon(QIcon("icons/filesaveas.png"));
- //saveAsAct->setShortcut(tr("Ctrl+A"));
- saveAsAct->setStatusTip(tr("Save the current File as..."));
- connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
-
- printAct = new QAction(tr("&Print"), this);
- printAct->setIcon(QIcon("icons/fileprint.png"));
- printAct->setShortcut(tr("Ctrl+P"));
- printAct->setStatusTip(tr("Print Document"));
- connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
-
- quitAct = new QAction(tr("&Quit"), this);
- quitAct->setShortcut(tr("Ctrl+Q"));
- quitAct->setIcon(QIcon("icons/exit.png"));
- quitAct->setStatusTip(tr("Quit Program"));
- connect(quitAct, SIGNAL(triggered()), this, SLOT(close()));
-
- /** Edit Menu
- */
- pasteAct = new QAction(tr("&Paste"), this);
- pasteAct->setIcon(QIcon("icons/button_paste.png"));
- pasteAct->setShortcut(tr("Ctrl+V"));
- pasteAct->setStatusTip(tr("Paste Text From Clipboard"));
- connect(pasteAct, SIGNAL(triggered()), edit, SLOT(paste()));
-
- cutAct = new QAction(tr("Cu&t"), this);
- cutAct->setIcon(QIcon("icons/button_cut.png"));
- cutAct->setShortcut(tr("Ctrl+X"));
- cutAct->setStatusTip(tr("Cut the current selection's contents to the "
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setIcon(QIcon(iconPath + "fileopen.png"));
+ openAct->setShortcut(tr("Ctrl+O"));
+ openAct->setStatusTip(tr("Open an existing file"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAct = new QAction(tr("&Save"), this);
+ saveAct->setIcon(QIcon(iconPath + "filesave.png"));
+ saveAct->setShortcut(tr("Ctrl+S"));
+ saveAct->setStatusTip(tr("Save the current File"));
+ connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
+
+ saveAsAct = new QAction(tr("Save &As"), this);
+ saveAsAct->setIcon(QIcon(iconPath + "filesaveas.png"));
+ saveAsAct->setStatusTip(tr("Save the current File as..."));
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+ printAct = new QAction(tr("&Print"), this);
+ printAct->setIcon(QIcon(iconPath + "fileprint.png"));
+ printAct->setShortcut(tr("Ctrl+P"));
+ printAct->setStatusTip(tr("Print Document"));
+ connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
+
+ quitAct = new QAction(tr("&Quit"), this);
+ quitAct->setShortcut(tr("Ctrl+Q"));
+ quitAct->setIcon(QIcon(iconPath + "exit.png"));
+ quitAct->setStatusTip(tr("Quit Program"));
+ connect(quitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ /** Edit Menu
+ */
+ pasteAct = new QAction(tr("&Paste"), this);
+ pasteAct->setIcon(QIcon(iconPath + "button_paste.png"));
+ pasteAct->setShortcut(tr("Ctrl+V"));
+ pasteAct->setStatusTip(tr("Paste Text From Clipboard"));
+ connect(pasteAct, SIGNAL(triggered()), edit, SLOT(paste()));
+
+ cutAct = new QAction(tr("Cu&t"), this);
+ cutAct->setIcon(QIcon(iconPath + "button_cut.png"));
+ cutAct->setShortcut(tr("Ctrl+X"));
+ cutAct->setStatusTip(tr("Cut the current selection's contents to the "
+ "clipboard"));
+ connect(cutAct, SIGNAL(triggered()), edit, SLOT(cut()));
+
+ copyAct = new QAction(tr("&Copy"), this);
+ copyAct->setIcon(QIcon(iconPath + "button_copy.png"));
+ copyAct->setShortcut(tr("Ctrl+C"));
+ copyAct->setStatusTip(tr("Copy the current selection's contents to the "
"clipboard"));
- connect(cutAct, SIGNAL(triggered()), edit, SLOT(cut()));
-
- copyAct = new QAction(tr("&Copy"), this);
- copyAct->setIcon(QIcon("icons/button_copy.png"));
- copyAct->setShortcut(tr("Ctrl+C"));
- copyAct->setStatusTip(tr("Copy the current selection's contents to the "
- "clipboard"));
- connect(copyAct, SIGNAL(triggered()), edit, SLOT(copy()));
-
- selectallAct = new QAction(tr("Select &All"), this);
- selectallAct->setIcon(QIcon("icons/edit.png"));
- selectallAct->setShortcut(tr("Ctrl+A"));
- selectallAct->setStatusTip(tr("Select the whole text"));
- connect(selectallAct, SIGNAL(triggered()), edit, SLOT(selectAll()));
-
- /** Crypt Menu
- */
- encryptAct = new QAction(tr("&Encrypt"), this);
- encryptAct->setIcon(QIcon("icons/encrypted.png"));
- encryptAct->setShortcut(tr("Ctrl+E"));
- encryptAct->setStatusTip(tr("Encrypt Message"));
- connect(encryptAct, SIGNAL(triggered()), this, SLOT(encrypt()));
-
- decryptAct = new QAction(tr("&Decrypt"), this);
- decryptAct->setIcon(QIcon("icons/decrypted.png"));
- decryptAct->setShortcut(tr("Ctrl+D"));
- decryptAct->setStatusTip(tr("Decrypt Message"));
- connect(decryptAct, SIGNAL(triggered()), this, SLOT(decrypt()));
-
- importKeyFromFileAct = new QAction(tr("&Import Key From File"), this);
- importKeyFromFileAct->setIcon(QIcon("icons/kgpg_import.png"));
- importKeyFromFileAct->setShortcut(tr("Ctrl+I"));
- importKeyFromFileAct->setStatusTip(tr("Import New Key From File"));
- connect(importKeyFromFileAct, SIGNAL(triggered()), this, SLOT(importKeyFromFile()));
-
- importKeyFromEditAct = new QAction(tr("Import Key From &Editor"), this);
- importKeyFromEditAct->setIcon(QIcon("icons/importkey_editor.png"));
- importKeyFromEditAct->setStatusTip(tr("Import New Key From Editor"));
- connect(importKeyFromEditAct, SIGNAL(triggered()), this, SLOT(importKeyFromEdit()));
-
- /** About Menu
- */
- aboutAct = new QAction(tr("&About"), this);
- aboutAct->setIcon(QIcon("icons/help.png"));
- aboutAct->setStatusTip(tr("Show the application's About box"));
- connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+ connect(copyAct, SIGNAL(triggered()), edit, SLOT(copy()));
+
+ selectallAct = new QAction(tr("Select &All"), this);
+ selectallAct->setIcon(QIcon(iconPath + "edit.png"));
+ selectallAct->setShortcut(tr("Ctrl+A"));
+ selectallAct->setStatusTip(tr("Select the whole text"));
+ connect(selectallAct, SIGNAL(triggered()), edit, SLOT(selectAll()));
+
+ /** Crypt Menu
+ */
+ encryptAct = new QAction(tr("&Encrypt"), this);
+ encryptAct->setIcon(QIcon(iconPath + "encrypted.png"));
+ encryptAct->setShortcut(tr("Ctrl+E"));
+ encryptAct->setStatusTip(tr("Encrypt Message"));
+ connect(encryptAct, SIGNAL(triggered()), this, SLOT(encrypt()));
+
+ decryptAct = new QAction(tr("&Decrypt"), this);
+ decryptAct->setIcon(QIcon(iconPath + "decrypted.png"));
+ decryptAct->setShortcut(tr("Ctrl+D"));
+ decryptAct->setStatusTip(tr("Decrypt Message"));
+ connect(decryptAct, SIGNAL(triggered()), this, SLOT(decrypt()));
+
+ importKeyFromFileAct = new QAction(tr("&Import Key From File"), this);
+ importKeyFromFileAct->setIcon(QIcon(iconPath + "kgpg_import.png"));
+ importKeyFromFileAct->setShortcut(tr("Ctrl+I"));
+ importKeyFromFileAct->setStatusTip(tr("Import New Key From File"));
+ connect(importKeyFromFileAct, SIGNAL(triggered()), this, SLOT(importKeyFromFile()));
+
+ importKeyFromEditAct = new QAction(tr("Import Key From &Editor"), this);
+ importKeyFromEditAct->setIcon(QIcon(iconPath + "importkey_editor.png"));
+ importKeyFromEditAct->setStatusTip(tr("Import New Key From Editor"));
+ connect(importKeyFromEditAct, SIGNAL(triggered()), this, SLOT(importKeyFromEdit()));
+
+ /** About Menu
+ */
+ aboutAct = new QAction(tr("&About"), this);
+ aboutAct->setIcon(QIcon(iconPath + "help.png"));
+ aboutAct->setStatusTip(tr("Show the application's About box"));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
}
void GpgWin::createMenus()
- {
- fileMenu = menuBar()->addMenu(tr("&File"));
- fileMenu->addAction(openAct);
- fileMenu->addAction(saveAct);
- fileMenu->addAction(saveAsAct);
- fileMenu->addAction(printAct);
- fileMenu->addSeparator();
- fileMenu->addAction(quitAct);
-
- fileMenu = menuBar()->addMenu(tr("&Edit"));
- fileMenu->addAction(copyAct);
- fileMenu->addAction(cutAct);
- fileMenu->addAction(pasteAct);
- fileMenu->addAction(selectallAct);
-
- fileMenu = menuBar()->addMenu(tr("&Crypt"));
- fileMenu->addAction(encryptAct);
- fileMenu->addAction(decryptAct);
- fileMenu->addSeparator();
- fileMenu->addAction(importKeyFromFileAct);
- fileMenu->addAction(importKeyFromEditAct);
-
- fileMenu = menuBar()->addMenu(tr("&Help"));
- fileMenu->addAction(aboutAct);
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(saveAct);
+ fileMenu->addAction(saveAsAct);
+ fileMenu->addAction(printAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(quitAct);
+
+ fileMenu = menuBar()->addMenu(tr("&Edit"));
+ fileMenu->addAction(copyAct);
+ fileMenu->addAction(cutAct);
+ fileMenu->addAction(pasteAct);
+ fileMenu->addAction(selectallAct);
+
+ fileMenu = menuBar()->addMenu(tr("&Crypt"));
+ fileMenu->addAction(encryptAct);
+ fileMenu->addAction(decryptAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(importKeyFromFileAct);
+ fileMenu->addAction(importKeyFromEditAct);
+
+ fileMenu = menuBar()->addMenu(tr("&Help"));
+ fileMenu->addAction(aboutAct);
}
void GpgWin::createToolBars()
- {
- fileToolBar = addToolBar(tr("File"));
- fileToolBar->addAction(encryptAct);
- fileToolBar->addAction(decryptAct);
-
- editToolBar = addToolBar(tr("Edit"));
- editToolBar->addAction(copyAct);
- editToolBar->addAction(pasteAct);
- editToolBar->addAction(selectallAct);
+{
+ fileToolBar = addToolBar(tr("File"));
+ fileToolBar->addAction(encryptAct);
+ fileToolBar->addAction(decryptAct);
+
+ editToolBar = addToolBar(tr("Edit"));
+ editToolBar->addAction(copyAct);
+ editToolBar->addAction(pasteAct);
+ editToolBar->addAction(selectallAct);
}
- void GpgWin::createStatusBar()
- {
- statusBar()->showMessage(tr("Ready"));
- }
+void GpgWin::createStatusBar()
+{
+ statusBar()->showMessage(tr("Ready"));
+}
void GpgWin::createDockWindows()
{
- QDockWidget *dock = new QDockWidget(tr("Encrypt for:"), this);
- dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
- addDockWidget(Qt::RightDockWidgetArea, dock);
- dock->setWidget(m_keyList);
+ QDockWidget *dock = new QDockWidget(tr("Encrypt for:"), this);
+ dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+ addDockWidget(Qt::RightDockWidgetArea, dock);
+ dock->setWidget(m_keyList);
+}
+
+void GpgWin::closeEvent(QCloseEvent *event)
+{
+ if (maybeSave()) {
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+
+void GpgWin::open()
+{
+ if (maybeSave()) {
+ QString fileName = QFileDialog::getOpenFileName(this);
+ if (!fileName.isEmpty())
+ loadFile(fileName);
+ }
+}
+
+bool GpgWin::save()
+{
+ if (curFile.isEmpty()) {
+ return saveAs();
+ } else {
+ return saveFile(curFile);
+ }
}
- void GpgWin::closeEvent(QCloseEvent *event)
- {
- if (maybeSave()) {
- event->accept();
- } else {
- event->ignore();
- }
- }
+bool GpgWin::saveAs()
+{
+ QString fileName = QFileDialog::getSaveFileName(this);
+ if (fileName.isEmpty())
+ return false;
+
+ return saveFile(fileName);
+}
- void GpgWin::open()
+void GpgWin::loadFile(const QString &fileName)
{
- if (maybeSave()) {
- QString fileName = QFileDialog::getOpenFileName(this);
- if (!fileName.isEmpty())
- loadFile(fileName);
- }
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("Application"),
+ tr("Cannot read file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QTextStream in(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ edit->setPlainText(in.readAll());
+ QApplication::restoreOverrideCursor();
+
+ setCurrentFile(fileName);
+ statusBar()->showMessage(tr("File loaded"), 2000);
}
- bool GpgWin::save()
- {
- if (curFile.isEmpty()) {
- return saveAs();
- } else {
- return saveFile(curFile);
- }
- }
-
- bool GpgWin::saveAs()
- {
- QString fileName = QFileDialog::getSaveFileName(this);
- if (fileName.isEmpty())
- return false;
-
- return saveFile(fileName);
- }
-
- void GpgWin::loadFile(const QString &fileName)
- {
- QFile file(fileName);
- if (!file.open(QFile::ReadOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("Application"),
- tr("Cannot read file %1:\n%2.")
- .arg(fileName)
- .arg(file.errorString()));
- return;
- }
-
- QTextStream in(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
- edit->setPlainText(in.readAll());
- QApplication::restoreOverrideCursor();
-
- setCurrentFile(fileName);
- statusBar()->showMessage(tr("File loaded"), 2000);
- }
-
- void GpgWin::setCurrentFile(const QString &fileName)
- {
- curFile = fileName;
- edit->document()->setModified(false);
- setWindowModified(false);
-
- QString shownName;
- if (curFile.isEmpty())
- shownName = tr("untitled.txt");
- else
- shownName = strippedName(curFile);
-
- setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("gpg4usb")));
- }
-
- QString GpgWin::strippedName(const QString &fullFileName)
- {
- return QFileInfo(fullFileName).fileName();
- }
-
- bool GpgWin::maybeSave()
- {
- if (edit->document()->isModified()) {
- QMessageBox::StandardButton ret;
- ret = QMessageBox::warning(this, tr("Application"),
- tr("The document has been modified.\nDo you want to save your changes?"),
- QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
- if (ret == QMessageBox::Save)
- return save();
- else if (ret == QMessageBox::Cancel)
- return false;
- }
- return true;
- }
+void GpgWin::setCurrentFile(const QString &fileName)
+{
+ curFile = fileName;
+ edit->document()->setModified(false);
+ setWindowModified(false);
+
+ QString shownName;
+ if (curFile.isEmpty())
+ shownName = tr("untitled.txt");
+ else
+ shownName = strippedName(curFile);
+
+ setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("gpg4usb")));
+}
+
+QString GpgWin::strippedName(const QString &fullFileName)
+{
+ return QFileInfo(fullFileName).fileName();
+}
+
+bool GpgWin::maybeSave()
+{
+ if (edit->document()->isModified()) {
+ QMessageBox::StandardButton ret;
+ ret = QMessageBox::warning(this, tr("Application"),
+ tr("The document has been modified.\nDo you want to save your changes?"),
+ QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+ if (ret == QMessageBox::Save)
+ return save();
+ else if (ret == QMessageBox::Cancel)
+ return false;
+ }
+ return true;
+}
bool GpgWin::saveFile(const QString &fileName)
- {
- /*QString fileName = QFileDialog::getSaveFileName(this,
- tr("Choose a file name"), ".",
- tr("Text (*.txt)","All (*)"));
- if (fileName.isEmpty())
- return false;*/
- QFile file(fileName);
- if (!file.open(QFile::WriteOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("File"),
- tr("Cannot write file %1:\n%2.")
- .arg(fileName)
- .arg(file.errorString()));
- return false;
- }
- QTextStream out(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
- out << edit->toPlainText();
- QApplication::restoreOverrideCursor();
- statusBar()->showMessage(tr("Saved '%1'").arg(fileName), 2000);
- return true;
- }
-
-void GpgWin::print(){
- #ifndef QT_NO_PRINTER
- QTextDocument *document = edit->document();
- QPrinter printer;
-
- QPrintDialog *dlg = new QPrintDialog(&printer, this);
- if (dlg->exec() != QDialog::Accepted)
- return;
-
- document->print(&printer);
-
- statusBar()->showMessage(tr("Ready"), 2000);
- #endif
- }
-
-void GpgWin::about(){
+{
+ /*QString fileName = QFileDialog::getSaveFileName(this,
+ tr("Choose a file name"), ".",
+ tr("Text (*.txt)","All (*)"));
+ if (fileName.isEmpty())
+ return false;*/
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("File"),
+ tr("Cannot write file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return false;
+ }
+ QTextStream out(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ out << edit->toPlainText();
+ QApplication::restoreOverrideCursor();
+ statusBar()->showMessage(tr("Saved '%1'").arg(fileName), 2000);
+ return true;
+}
+
+void GpgWin::print()
+{
+#ifndef QT_NO_PRINTER
+ QTextDocument *document = edit->document();
+ QPrinter printer;
+
+ QPrintDialog *dlg = new QPrintDialog(&printer, this);
+ if (dlg->exec() != QDialog::Accepted)
+ return;
+
+ document->print(&printer);
+
+ statusBar()->showMessage(tr("Ready"), 2000);
+#endif
+}
+
+void GpgWin::about()
+{
QMessageBox::about(this, tr("About gpg4usb"),
- tr("<center>This Application allows you to do simple<br>"
- "encryption/decryption of your text-files.<br>"
- "It's licensed under the GPL v2.0<br><br>"
- "<b>Developer:</b><br>"
- "Bene, Heimer, Juergen, Nils, Ubbo<br><br>"
- "If you have any questions and/or<br>"
- "suggestions, contact us at<br>"
- "gpg4usb at cpunk.de</a><br><br>"
- "or feel free to meet us in our channel at<br>"
- "gpg4usb at conference.jabber.ccc.de<br><br>"
- "and always remember:<br>"
- "cpunk is NOT a bot...</center>"));
- }
-
- void GpgWin::encrypt(){
+ tr("<center>This Application allows you to do simple<br>"
+ "encryption/decryption of your text-files.<br>"
+ "It's licensed under the GPL v2.0<br><br>"
+ "<b>Developer:</b><br>"
+ "Bene, Heimer, Juergen, Nils, Ubbo<br><br>"
+ "If you have any questions and/or<br>"
+ "suggestions, contact us at<br>"
+ "gpg4usb at cpunk.de</a><br><br>"
+ "or feel free to meet us in our channel at<br>"
+ "gpg4usb at conference.jabber.ccc.de<br><br>"
+ "and always remember:<br>"
+ "cpunk is NOT a bot...</center>"));
+}
+
+void GpgWin::encrypt()
+{
QList<QString> *uidList = m_keyList->getChecked();
QByteArray *tmp = new QByteArray();
if ( myCtx->encrypt(uidList, edit->toPlainText().toAscii(), tmp) ) {
- QString *tmp2 = new QString(*tmp);
- edit->setPlainText(*tmp2);
+ QString *tmp2 = new QString(*tmp);
+ edit->setPlainText(*tmp2);
}
- }
+}
- void GpgWin::decrypt(){
+void GpgWin::decrypt()
+{
QByteArray *tmp = new QByteArray();
myCtx->decrypt(edit->toPlainText().toAscii(), tmp);
- if(!tmp->isEmpty()){
- QString *tmp2 = new QString(*tmp);
- edit->setPlainText(*tmp2);
+ if (!tmp->isEmpty()){
+ QString *tmp2 = new QString(*tmp);
+ edit->setPlainText(*tmp2);
}
- }
+}
- void GpgWin::importKeyFromEdit(){
+void GpgWin::importKeyFromEdit()
+{
myCtx->importKey(edit->toPlainText().toAscii());
m_keyList->refresh();
- }
-
-
- void GpgWin::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();
- myCtx->importKey(inBuffer);
- m_keyList->refresh();
- }
+void GpgWin::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();
+
+ myCtx->importKey(inBuffer);
+ m_keyList->refresh();
+ }
}
diff --git a/gpgwin.h b/gpgwin.h
index 5d3ea27..975c87a 100644
--- a/gpgwin.h
+++ b/gpgwin.h
@@ -29,58 +29,59 @@ class QMenu;
class QPlainTextEdit;
class GpgWin : public QMainWindow
- {
- Q_OBJECT
+{
+ Q_OBJECT
- public:
- GpgWin();
+public:
+ GpgWin();
- protected:
- void closeEvent(QCloseEvent *event);
+protected:
+ void closeEvent(QCloseEvent *event);
- public slots:
- void encrypt();
- void decrypt();
- void importKeyFromFile();
- void importKeyFromEdit();
- void print();
- void about();
- bool save();
- bool saveAs();
- void open();
+public slots:
+ void encrypt();
+ void decrypt();
+ void importKeyFromFile();
+ void importKeyFromEdit();
+ void print();
+ void about();
+ bool save();
+ bool saveAs();
+ void open();
- private:
- void createActions();
- void createMenus();
- void createToolBars();
- void createStatusBar();
- void createDockWindows();
- bool saveFile(const QString &fileName);
- void loadFile(const QString &fileName);
- void setCurrentFile(const QString &fileName);
- bool maybeSave();
- QString strippedName(const QString &fullFileName);
+private:
+ void createActions();
+ void createMenus();
+ void createToolBars();
+ void createStatusBar();
+ void createDockWindows();
+ bool saveFile(const QString &fileName);
+ void loadFile(const QString &fileName);
+ void setCurrentFile(const QString &fileName);
+ bool maybeSave();
+ QString strippedName(const QString &fullFileName);
- QPlainTextEdit *edit;
- QMenu *fileMenu;
- QToolBar *fileToolBar;
- QToolBar *editToolBar;
- QAction *openAct;
- QAction *saveAct;
- QAction *saveAsAct;
- QAction *printAct;
- QAction *quitAct;
- QAction *encryptAct;
- QAction *decryptAct;
- QAction *importKeyFromFileAct;
- QAction *importKeyFromEditAct;
- QAction *copyAct;
- QAction *cutAct;
- QAction *pasteAct;
- QAction *selectallAct;
- QAction *aboutAct;
+ QPlainTextEdit *edit;
+ QMenu *fileMenu;
+ QToolBar *fileToolBar;
+ QToolBar *editToolBar;
+ QAction *openAct;
+ QAction *saveAct;
+ QAction *saveAsAct;
+ QAction *printAct;
+ QAction *quitAct;
+ QAction *encryptAct;
+ QAction *decryptAct;
+ QAction *importKeyFromFileAct;
+ QAction *importKeyFromEditAct;
+ QAction *copyAct;
+ QAction *cutAct;
+ QAction *pasteAct;
+ QAction *selectallAct;
+ QAction *aboutAct;
- QString curFile;
- KeyList *m_keyList;
- GpgME::Context *myCtx;
- };
+ QString curFile;
+ KeyList *m_keyList;
+ GpgME::Context *myCtx;
+ QString iconPath;
+};
diff --git a/keylist.cpp b/keylist.cpp
index 28e1376..9580bb7 100644
--- a/keylist.cpp
+++ b/keylist.cpp
@@ -1,7 +1,3 @@
-
-#include <QWidget>
-#include <QVBoxLayout>
-#include <QListWidgetItem>
/*
* keylist.cpp
*
@@ -22,13 +18,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
+#include <QWidget>
+#include <QVBoxLayout>
+#include <QListWidgetItem>
#include <QLabel>
#include <QMessageBox>
#include <QtGui>
#include "keylist.h"
KeyList::KeyList(QWidget *parent)
- : QWidget(parent)
+ : QWidget(parent)
{
m_keyList = new QListWidget();
m_idList = new QList<QString>();
@@ -44,76 +43,87 @@ KeyList::KeyList(QWidget *parent)
}
-void KeyList::setContext(GpgME::Context *ctx) {
- m_ctx = ctx;
- refresh();
+void KeyList::setContext(GpgME::Context *ctx)
+{
+ m_ctx = ctx;
+ refresh();
+}
+
+void KeyList::setIconPath( QString path )
+{
+ this->iconPath = path;
}
void KeyList::contextMenuEvent(QContextMenuEvent *event)
{
- QMenu menu(this);
- menu.addAction(deleteKeyAct);
- menu.exec(event->globalPos());
+ QMenu menu(this);
+ menu.addAction(deleteKeyAct);
+ menu.exec(event->globalPos());
}
-void KeyList::refresh() {
- m_keyList->clear();
- m_idList->clear();
+void KeyList::refresh()
+{
+ m_keyList->clear();
+ m_idList->clear();
- GpgKeyList keys = m_ctx->listKeys();
- GpgKeyList::iterator it = keys.begin();
- while (it != keys.end()) {
- QListWidgetItem *tmp = new QListWidgetItem(
+ GpgKeyList keys = m_ctx->listKeys();
+ GpgKeyList::iterator it = keys.begin();
+ while (it != keys.end()) {
+ QListWidgetItem *tmp = new QListWidgetItem(
it->name + " <" + it->email +">"
- );
- tmp->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
- tmp->setCheckState( Qt::Unchecked );
- if(it->privkey == 1) tmp->setIcon(QIcon("icons/kgpg_key2.png"));
- m_keyList->addItem(tmp);
-
- *m_idList << QString(it->id);
- it++;
- }
+ );
+ tmp->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
+ tmp->setCheckState( Qt::Unchecked );
+ if (it->privkey == 1) tmp->setIcon(QIcon(iconPath + "kgpg_key2.png"));
+ m_keyList->addItem(tmp);
+
+ *m_idList << QString(it->id);
+ it++;
+ }
}
-QList<QString>* KeyList::getChecked() {
- QList<QString> *ret = new QList<QString>();
- for (int i = 0; i < m_keyList->count(); i++) {
- if (m_keyList->item(i)->checkState() == Qt::Checked) {
- *ret << m_idList->at(i);
+QList<QString>* KeyList::getChecked()
+{
+ QList<QString> *ret = new QList<QString>();
+ for (int i = 0; i < m_keyList->count(); i++) {
+ if (m_keyList->item(i)->checkState() == Qt::Checked) {
+ *ret << m_idList->at(i);
+ }
}
- }
- return ret;
+ return ret;
}
-QList<QString>* KeyList::getSelected() {
- QList<QString> *ret = new QList<QString>();
- for (int i = 0; i < m_keyList->count(); i++) {
- if (m_keyList->item(i)->isSelected() == 1) {
- *ret << m_idList->at(i);
+QList<QString>* KeyList::getSelected()
+{
+ QList<QString> *ret = new QList<QString>();
+ for (int i = 0; i < m_keyList->count(); i++) {
+ if (m_keyList->item(i)->isSelected() == 1) {
+ *ret << m_idList->at(i);
+ }
}
- }
- return ret;
+ return ret;
}
-void KeyList::deleteKeys() {
+void KeyList::deleteKeys()
+{
- m_ctx->deleteKeys(getChecked());
- refresh();
+ m_ctx->deleteKeys(getChecked());
+ refresh();
}
-void KeyList::deleteKey() {
+void KeyList::deleteKey()
+{
- m_ctx->deleteKeys(getSelected());
- refresh();
+ m_ctx->deleteKeys(getSelected());
+ refresh();
}
void KeyList::createActions()
{
- deleteKeyAct = new QAction(tr("Delete Key"), this);
- deleteKeyAct->setStatusTip(tr("Delete the selected keys"));
- connect(deleteKeyAct, SIGNAL(triggered()), this, SLOT(deleteKey()));
+ deleteKeyAct = new QAction(tr("Delete Key"), this);
+ deleteKeyAct->setStatusTip(tr("Delete the selected keys"));
+ connect(deleteKeyAct, SIGNAL(triggered()), this, SLOT(deleteKey()));
}
diff --git a/keylist.h b/keylist.h
index e50df64..ac4cdcd 100644
--- a/keylist.h
+++ b/keylist.h
@@ -32,10 +32,11 @@ class KeyList : public QWidget
public slots:
void deleteKeys();
void deleteKey();
-
+
public:
KeyList(QWidget *parent = 0);
void setContext(GpgME::Context *ctx);
+ void setIconPath(QString iconPath);
QList<QString>* getChecked();
QList<QString>* getSelected();
void refresh();
@@ -47,8 +48,9 @@ class KeyList : public QWidget
QPushButton *m_deleteButton;
QAction *deleteKeyAct;
void createActions();
+ QString iconPath;
+
-
protected:
void contextMenuEvent(QContextMenuEvent *event);
};
diff --git a/main.cpp b/main.cpp
index b441688..09bb977 100644
--- a/main.cpp
+++ b/main.cpp
@@ -22,29 +22,30 @@
#include <QApplication>
#include "gpgwin.h"
- int main(int argc, char *argv[])
- {
+int main(int argc, char *argv[])
+{
#ifndef _WIN32
- // do not use GPG_AGENTS like seahorse, because they may save
- // a password an pc's not owned by user
- unsetenv("GPG_AGENT_INFO");
+ // do not use GPG_AGENTS like seahorse, because they may save
+ // a password an pc's not owned by user
+ unsetenv("GPG_AGENT_INFO");
#endif
- QApplication app(argc, argv);
-
- //internationalize
- QString locale = QLocale::system().name();
- QTranslator translator;
- translator.load(QString("ts/gpg4usb_") + locale );
- app.installTranslator(&translator);
-
- GpgWin *window = new GpgWin();
- window->resize(800, 450);
-
- window->show();
-
- return app.exec();
- }
+
+ QApplication app(argc, argv);
+
+ //internationalize
+ QString locale = QLocale::system().name();
+ QTranslator translator;
+ translator.load(QString("ts/gpg4usb_") + locale );
+ app.installTranslator(&translator);
+
+ GpgWin *window = new GpgWin();
+ window->resize(800, 450);
+
+ window->show();
+
+ return app.exec();
+}