QtPass  1.2.1
Multi-platform GUI for pass, the standard unix password manager.
trayicon.cpp
Go to the documentation of this file.
1 #include "trayicon.h"
2 
8 TrayIcon::TrayIcon(QMainWindow *parent) {
9  parentwin = parent;
10 
11  createActions();
12  createTrayIcon();
13 
14  sysTrayIcon->setIcon(
15  QIcon::fromTheme("qtpass-tray", QIcon(":/artwork/icon.png")));
16 
17  sysTrayIcon->show();
18 
19  QObject::connect(sysTrayIcon,
20  SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
21  SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
22 }
23 
28 void TrayIcon::setVisible(bool visible) {
29  if (visible == true)
30  parentwin->show();
31  else
32  parentwin->hide();
33 }
34 
38 void TrayIcon::createActions() {
39  showAction = new QAction(tr("&Show"), this);
40  connect(showAction, SIGNAL(triggered()), parentwin, SLOT(show()));
41  hideAction = new QAction(tr("&Hide"), this);
42  connect(hideAction, SIGNAL(triggered()), parentwin, SLOT(hide()));
43 
44  minimizeAction = new QAction(tr("Mi&nimize"), this);
45  connect(minimizeAction, SIGNAL(triggered()), parentwin,
46  SLOT(showMinimized()));
47  maximizeAction = new QAction(tr("Ma&ximize"), this);
48  connect(maximizeAction, SIGNAL(triggered()), parentwin,
49  SLOT(showMaximized()));
50  restoreAction = new QAction(tr("&Restore"), this);
51  connect(restoreAction, SIGNAL(triggered()), parentwin, SLOT(showNormal()));
52 
53  quitAction = new QAction(tr("&Quit"), this);
54  connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
55 }
56 
60 void TrayIcon::createTrayIcon() {
61  trayIconMenu = new QMenu(this);
62  trayIconMenu->addAction(showAction);
63  trayIconMenu->addAction(hideAction);
64  trayIconMenu->addAction(minimizeAction);
65  trayIconMenu->addAction(maximizeAction);
66  trayIconMenu->addAction(restoreAction);
67  trayIconMenu->addSeparator();
68  trayIconMenu->addAction(quitAction);
69 
70  sysTrayIcon = new QSystemTrayIcon(this);
71  sysTrayIcon->setContextMenu(trayIconMenu);
72 }
73 
78  if (parentwin->isVisible() == true)
79  parentwin->hide();
80  else
81  parentwin->show();
82 }
83 
88 void TrayIcon::iconActivated(QSystemTrayIcon::ActivationReason reason) {
89  switch (reason) {
90  case QSystemTrayIcon::Trigger:
91  case QSystemTrayIcon::DoubleClick:
93  break;
94  case QSystemTrayIcon::MiddleClick:
95  showMessage("test", "test msg", 1000);
96  break;
97  default: {};
98  }
99 }
100 
107 void TrayIcon::showMessage(QString title, QString msg, int time) {
108  sysTrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, time);
109 }
void setVisible(bool visible)
TrayIcon::setVisible show or hide the icon.
Definition: trayicon.cpp:28
TrayIcon(QMainWindow *parent)
TrayIcon::TrayIcon use a (system) tray icon with a nice QtPass logo on it (currently) only Quits...
Definition: trayicon.cpp:8
void showMessage(QString title, QString msg, int time)
TrayIcon::showMessage show a systray message for notification.
Definition: trayicon.cpp:107
void iconActivated(QSystemTrayIcon::ActivationReason reason)
TrayIcon::iconActivated you clicked on the trayicon.
Definition: trayicon.cpp:88
void showHideParent()
TrayIcon::showHideParent toggle app visibility.
Definition: trayicon.cpp:77