1 /*
2   TrayIcon.cpp
3 
4   This file is part of Charm, a task-based time tracking application.
5 
6   Copyright (C) 2014-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
7 
8   Author: Frank Osterfeld <frank.osterfeld@kdab.com>
9 
10   This program is free software; you can redistribute it and/or modify
11   it under the terms of the GNU General Public License as published by
12   the Free Software Foundation, either version 2 of the License, or
13   (at your option) any later version.
14 
15   This program is distributed in the hope that it will be useful,
16   but WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   GNU General Public License for more details.
19 
20   You should have received a copy of the GNU General Public License
21   along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 */
23 
24 #include "TrayIcon.h"
25 
26 #include "ApplicationCore.h"
27 
TrayIcon(QObject * parent)28 TrayIcon::TrayIcon(QObject *parent)
29     : QSystemTrayIcon(parent)
30 {
31     connect(this, &QSystemTrayIcon::activated, this, &TrayIcon::slotActivated);
32 }
33 
~TrayIcon()34 TrayIcon::~TrayIcon()
35 {
36 }
37 
slotActivated(QSystemTrayIcon::ActivationReason reason)38 void TrayIcon::slotActivated(QSystemTrayIcon::ActivationReason reason)
39 {
40     switch (reason) {
41     case QSystemTrayIcon::Context:
42         // show context menu
43         // m_systrayContextMenu.show();
44         break;
45     case QSystemTrayIcon::Trigger: //(single click)
46     case QSystemTrayIcon::DoubleClick:
47 #ifndef Q_OS_OSX
48         ApplicationCore::instance().showMainWindow(ApplicationCore::ShowMode::ShowAndRaise);
49 #endif
50         break;
51     case QSystemTrayIcon::MiddleClick:
52         // TODO: Start task?
53         ApplicationCore::instance().slotStopAllTasks();
54         break;
55     case QSystemTrayIcon::Unknown:
56     default:
57         break;
58     }
59 }
60