QtPass 1.4.0
Multi-platform GUI for pass, the standard unix password manager.
Loading...
Searching...
No Matches
trayicon.cpp
Go to the documentation of this file.
1#include "trayicon.h"
2#include <QAction>
3#include <QApplication>
4#include <QMainWindow>
5#include <QMenu>
6
7#ifdef QT_DEBUG
8#include "debughelper.h"
9#endif
10
16TrayIcon::TrayIcon(QMainWindow *parent)
17 : showAction(nullptr), hideAction(nullptr), minimizeAction(nullptr),
18 maximizeAction(nullptr), restoreAction(nullptr), quitAction(nullptr),
19 sysTrayIcon(nullptr), trayIconMenu(nullptr), isAllocated(false) {
20 parentwin = parent;
21
22 if (QSystemTrayIcon::isSystemTrayAvailable()) {
23 createActions();
24 createTrayIcon();
25
26 sysTrayIcon->setIcon(
27 QIcon::fromTheme("qtpass-tray", QIcon(":/artwork/icon.png")));
28
29 sysTrayIcon->show();
30
31 QObject::connect(sysTrayIcon, &QSystemTrayIcon::activated, this,
33
34 isAllocated = true;
35 }
36#ifdef QT_DEBUG
37 else {
38 dbg() << "No tray icon for this OS possibly also not show options?";
39 }
40#endif
41}
42
47void TrayIcon::setVisible(bool visible) {
48 if (visible)
49 parentwin->show();
50 else
51 parentwin->hide();
52}
53
57bool TrayIcon::getIsAllocated() { return isAllocated; }
58
62void TrayIcon::createActions() {
63 showAction = new QAction(tr("&Show"), this);
64 connect(showAction, &QAction::triggered, parentwin, &QWidget::show);
65 hideAction = new QAction(tr("&Hide"), this);
66 connect(hideAction, &QAction::triggered, parentwin, &QWidget::hide);
67
68 minimizeAction = new QAction(tr("Mi&nimize"), this);
69 connect(minimizeAction, &QAction::triggered, parentwin,
70 &QWidget::showMinimized);
71 maximizeAction = new QAction(tr("Ma&ximize"), this);
72 connect(maximizeAction, &QAction::triggered, parentwin,
73 &QWidget::showMaximized);
74 restoreAction = new QAction(tr("&Restore"), this);
75 connect(restoreAction, &QAction::triggered, parentwin, &QWidget::showNormal);
76
77 quitAction = new QAction(tr("&Quit"), this);
78 connect(quitAction, &QAction::triggered, qApp, &QApplication::quit);
79}
80
84void TrayIcon::createTrayIcon() {
85 trayIconMenu = new QMenu(this);
86 trayIconMenu->addAction(showAction);
87 trayIconMenu->addAction(hideAction);
88 trayIconMenu->addAction(minimizeAction);
89 trayIconMenu->addAction(maximizeAction);
90 trayIconMenu->addAction(restoreAction);
91 trayIconMenu->addSeparator();
92 trayIconMenu->addAction(quitAction);
93
94 sysTrayIcon = new QSystemTrayIcon(this);
95 sysTrayIcon->setContextMenu(trayIconMenu);
96}
97
102 if (parentwin->isVisible())
103 parentwin->hide();
104 else
105 parentwin->show();
106}
107
112void TrayIcon::iconActivated(QSystemTrayIcon::ActivationReason reason) {
113 switch (reason) {
114 case QSystemTrayIcon::Trigger:
115 case QSystemTrayIcon::DoubleClick:
117 break;
118 case QSystemTrayIcon::MiddleClick:
119 showMessage("test", "test msg", 1000);
120 break;
121 default: {
122 }
123 }
124}
125
132void TrayIcon::showMessage(const QString &title, const QString &msg, int time) {
133 sysTrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, time);
134}
void showHideParent()
TrayIcon::showHideParent toggle app visibility.
Definition: trayicon.cpp:101
void iconActivated(QSystemTrayIcon::ActivationReason reason)
TrayIcon::iconActivated you clicked on the trayicon.
Definition: trayicon.cpp:112
void showMessage(const QString &title, const QString &msg, int time)
TrayIcon::showMessage show a systray message for notification.
Definition: trayicon.cpp:132
TrayIcon(QMainWindow *parent)
TrayIcon::TrayIcon use a (system) tray icon with a nice QtPass logo on it (currently) only Quits.
Definition: trayicon.cpp:16
bool getIsAllocated()
TrayIcon::getIsAllocated return if TrayIcon is allocated.
Definition: trayicon.cpp:57
void setVisible(bool visible)
TrayIcon::setVisible show or hide the icon.
Definition: trayicon.cpp:47
#define dbg()
Definition: debughelper.h:7