diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2015-06-09 00:54:24 +0200 |
---|---|---|
committer | Anne Jan Brouwer <brouwer@annejan.com> | 2015-06-09 00:54:24 +0200 |
commit | d3aacf860dc387fe9960a1f8cafc217d1d4bbe89 (patch) | |
tree | 64631057aeed852b33f94dc09f92c3c68953da81 | |
parent | 4f6be82d7ed9fbfdf57c02639f99cd1d5a5a7467 (diff) |
trying old trayicon code
-rw-r--r-- | mainwindow.cpp | 17 | ||||
-rw-r--r-- | mainwindow.h | 4 | ||||
-rw-r--r-- | qtpass.pro | 6 | ||||
-rw-r--r-- | trayicon.cpp | 84 | ||||
-rw-r--r-- | trayicon.h | 39 |
5 files changed, 148 insertions, 2 deletions
diff --git a/mainwindow.cpp b/mainwindow.cpp index 00454f20..e625d124 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -37,6 +37,8 @@ MainWindow::MainWindow(QWidget *parent) : ui->statusBar->showMessage(tr("Welcome to QtPass %1").arg(VERSION), 2000); firstRun = true; startupPhase = true; + + initTrayIcon(); } /** @@ -1106,3 +1108,18 @@ void MainWindow::on_profileBox_currentIndexChanged(QString name) ui->treeView->setRootIndex(proxyModel.mapFromSource(model.setRootPath(passStore))); } + +void MainWindow::initTrayIcon() +{ + if(QSystemTrayIcon::isSystemTrayAvailable() == true) { + // Setup tray icon + this->tray = new trayIcon(this); + if(tray == NULL){ + qDebug() << "Allocating tray icon failed."; + exit(1); + } + qDebug() << "Ehm.."; + } else { + qDebug() << "Whut?"; + } +} diff --git a/mainwindow.h b/mainwindow.h index 5aafd89c..dbef6d5f 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -8,6 +8,7 @@ #include <QQueue> #include <QSettings> #include "storemodel.h" +#include "trayicon.h" #if SINGLE_APP #include "singleapplication.h" #else @@ -102,6 +103,7 @@ private: QHash<QString, QString> profiles; QString profile; bool startupPhase; + trayIcon *tray; void updateText(); void executePass(QString, QString = QString()); void executeWrapper(QString, QString, QString = QString()); @@ -119,6 +121,8 @@ private: void mountWebDav(); void updateEnv(); void updateProfileBox(); + void initTrayIcon(); + }; #endif // MAINWINDOW_H @@ -29,7 +29,8 @@ SOURCES += main.cpp\ util.cpp \ usersdialog.cpp \ keygendialog.cpp \ - progressindicator.cpp + progressindicator.cpp \ + trayicon.cpp HEADERS += mainwindow.h \ dialog.h \ @@ -37,7 +38,8 @@ HEADERS += mainwindow.h \ util.h \ usersdialog.h \ keygendialog.h \ - progressindicator.h + progressindicator.h \ + trayicon.h FORMS += mainwindow.ui \ dialog.ui \ diff --git a/trayicon.cpp b/trayicon.cpp new file mode 100644 index 00000000..452560fa --- /dev/null +++ b/trayicon.cpp @@ -0,0 +1,84 @@ +#include "trayicon.h" + +trayIcon::trayIcon(QMainWindow *parent) +{ + parentwin = parent; + + createActions(); + createTrayIcon(); + + sysTrayIcon->setIcon(QIcon(":/artwork/logo.png")); + + sysTrayIcon->show(); + + QObject::connect(sysTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); + +} + +void trayIcon::setVisible(bool visible) +{ + if(visible == true) { + parentwin->show(); + } else { + parentwin->hide(); + } +} + +void trayIcon::createActions() +{ + minimizeAction = new QAction(tr("Mi&nimize"), this); + connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); + + maximizeAction = new QAction(tr("Ma&ximize"), this); + connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized())); + + restoreAction = new QAction(tr("&Restore"), this); + connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal())); + + quitAction = new QAction(tr("&Quit"), this); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); +} + + +void trayIcon::createTrayIcon() +{ + trayIconMenu = new QMenu(this); + trayIconMenu->addAction(minimizeAction); + trayIconMenu->addAction(maximizeAction); + trayIconMenu->addAction(restoreAction); + trayIconMenu->addSeparator(); + trayIconMenu->addAction(quitAction); + + sysTrayIcon = new QSystemTrayIcon(this); + sysTrayIcon->setContextMenu(trayIconMenu); +} + +void trayIcon::showHideParent() +{ + if(parentwin->isVisible() == true) { + parentwin->hide(); + } else { + parentwin->show(); + } +} + +void trayIcon::iconActivated(QSystemTrayIcon::ActivationReason reason) +{ + switch (reason) { + case QSystemTrayIcon::Trigger: + case QSystemTrayIcon::DoubleClick: + showHideParent(); + break; + case QSystemTrayIcon::MiddleClick: + showMessage("test", "test msg", 1000); + break; + default: + ; + } +} + +void trayIcon::showMessage(QString title, QString msg, int time) +{ + sysTrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, time); +} diff --git a/trayicon.h b/trayicon.h new file mode 100644 index 00000000..3daa8dfe --- /dev/null +++ b/trayicon.h @@ -0,0 +1,39 @@ +#ifndef TRAYICON_H +#define TRAYICON_H + +#include <QApplication> +#include <QMenu> +#include <QAction> +#include <QMainWindow> +#include <QSystemTrayIcon> +#include <QWidget> + +class trayIcon : public QWidget +{ + Q_OBJECT +public: + explicit trayIcon(QMainWindow *parent); + void showMessage(QString title, QString msg, int time); + void setVisible(bool visible); + +signals: + +public slots: + void showHideParent(); + void iconActivated(QSystemTrayIcon::ActivationReason reason); + +private: + void createActions(); + void createTrayIcon(); + + QAction *minimizeAction; + QAction *maximizeAction; + QAction *restoreAction; + QAction *quitAction; + + QSystemTrayIcon *sysTrayIcon; + QMenu *trayIconMenu; + QMainWindow *parentwin; +}; + +#endif // TRAYICON_H |