From 10c70da34595b0ada0519bcc8e8b8be0cd4282cb Mon Sep 17 00:00:00 2001 From: ubbo Date: Thu, 3 Nov 2011 21:28:11 +0000 Subject: first tray with minimal functionality - close ;-) git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@597 34ebc366-c3a9-4b3c-9f84-69acf7962910 --- gpg4usb.pro | 2 ++ gpg4usb.qrc | 5 +++++ main.cpp | 2 ++ mainwindow.cpp | 25 +++++++++++++++++++++++++ mainwindow.h | 9 +++++++++ 5 files changed, 43 insertions(+) create mode 100644 gpg4usb.qrc diff --git a/gpg4usb.pro b/gpg4usb.pro index 9132d37..1c17f92 100644 --- a/gpg4usb.pro +++ b/gpg4usb.pro @@ -60,6 +60,8 @@ SOURCES += attachments.cpp \ RC_FILE = gpg4usb.rc +RESOURCES = gpg4usb.qrc + # comment out line below for static building LIBS += -lgpgme \ -lgpg-error \ diff --git a/gpg4usb.qrc b/gpg4usb.qrc new file mode 100644 index 0000000..2629f0f --- /dev/null +++ b/gpg4usb.qrc @@ -0,0 +1,5 @@ + + + release/icons/keymgmt.png + + diff --git a/main.cpp b/main.cpp index 57ae4b8..2619f8e 100644 --- a/main.cpp +++ b/main.cpp @@ -25,6 +25,8 @@ int main(int argc, char *argv[]) { + Q_INIT_RESOURCE(gpg4usb); + QApplication app(argc, argv); // get application path diff --git a/mainwindow.cpp b/mainwindow.cpp index 8e03bfd..8c42c06 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -54,6 +54,7 @@ MainWindow::MainWindow() createToolBars(); createStatusBar(); createDockWindows(); + createTrayIcon(); mKeyList->addMenuAction(appendSelectedKeysAct); mKeyList->addMenuAction(copyMailAddressToClipboardAct); @@ -72,6 +73,7 @@ MainWindow::MainWindow() edit->curTextPage()->setFocus(); this->setWindowTitle(qApp->applicationName()); this->show(); + trayIcon->show(); // Show wizard, if the don't show wizard message box wasn't checked // and keylist doesn't contain a private key @@ -466,6 +468,29 @@ void MainWindow::createDockWindows() } } +void MainWindow::createTrayIcon() { + + trayIconMenu = new QMenu(this); + trayIconMenu->addAction(quitAct); + + trayIcon = new QSystemTrayIcon(this); + + QIcon icon(":/tray.png"); + trayIcon->setIcon(icon); + /*QByteArray category = qgetenv("SNI_CATEGORY"); + if (!category.isEmpty()) { + trayIcon->setProperty("_qt_sni_category", QString::fromLocal8Bit(category)); + }*/ + trayIcon->setProperty("_qt_sni_category", qApp->applicationDirPath() + "/tmp"); + trayIcon->setContextMenu(trayIconMenu); + //showTrayMessage("tray is ready", "no further text"); +} + +void MainWindow::showTrayMessage(QString title, QString body) { + //QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(":/icons/exit.png"); + trayIcon->showMessage(title, body, QSystemTrayIcon::Information, 10000); +} + void MainWindow::createAttachmentDock() { if (attachmentDockCreated) { return; diff --git a/mainwindow.h b/mainwindow.h index f2281a1..21939e0 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -192,6 +192,12 @@ private: */ void createDockWindows(); + /** + * @details Create icon for system tray + */ + void createTrayIcon(); + void showTrayMessage(QString title, QString body); + /** * @details Create attachment-dockwindow. */ @@ -234,6 +240,9 @@ private: QDockWidget *attachmentDock; /** Attachment Dock */ QDialog *genkeyDialog; /** Dialog for key generation */ + QSystemTrayIcon *trayIcon; + QMenu *trayIconMenu; + QAction *newTabAct; /** Action to create new tab */ QAction *switchTabUpAct; /** Action to switch tab up*/ QAction *switchTabDownAct; /** Action to switch tab down */ -- cgit v1.2.3