2 * Copyright (C) 2011 Lukáš Karas <lukas.karas@centrum.cz>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "main-window.h"
24 // TODO: change tray icon related with global status
26 MainWindow::MainWindow(QApplication
*app
, QObject
*parent
) :
31 _minimizeAction(NULL
),
32 _maximizeAction(NULL
),
36 QIcon icon
= QIcon(":/declarative/img/status-online.png");
37 qDebug() << "SessionModel: tray sizes:" << icon
.availableSizes();
40 setWindowTitle("Makneto Mobile");
42 if (QSystemTrayIcon::isSystemTrayAvailable()) {
45 _trayIconMenu
= new QMenu(this);
46 _trayIconMenu
->addAction(_minimizeAction
);
47 _trayIconMenu
->addAction(_maximizeAction
);
48 _trayIconMenu
->addAction(_restoreAction
);
49 _trayIconMenu
->addSeparator();
50 _trayIconMenu
->addAction(_quitAction
);
52 _trayIcon
= new QSystemTrayIcon(icon
, this);
53 _trayIcon
->setContextMenu(_trayIconMenu
);
55 _trayIcon
->setToolTip("Makneto");
59 connect(_trayIcon
, SIGNAL(activated(QSystemTrayIcon::ActivationReason
)),
60 this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason
)));
63 qWarning() << "MainWindow: This environment doesn't support QSystemTrayIcon";
66 _app
->setQuitOnLastWindowClosed(true);
67 if (_app
->quitOnLastWindowClosed()) {
68 qDebug() << "MainWindow: will quit on close";
72 void MainWindow::createActions() {
73 _minimizeAction
= new QAction(tr("Mi&nimize"), this);
74 connect(_minimizeAction
, SIGNAL(triggered()), this, SLOT(hide()));
76 _maximizeAction
= new QAction(tr("Ma&ximize"), this);
77 connect(_maximizeAction
, SIGNAL(triggered()), this, SLOT(showMaximized()));
79 _restoreAction
= new QAction(tr("&Restore"), this);
80 connect(_restoreAction
, SIGNAL(triggered()), this, SLOT(showNormal()));
82 _quitAction
= new QAction(tr("&Quit"), this);
83 connect(_quitAction
, SIGNAL(triggered()), qApp
, SLOT(quit()));
86 void MainWindow::closeEvent(QCloseEvent
*event
) {
87 if (_trayIcon
&& _trayIcon
->isVisible()) {
88 qWarning() << "MainWindow: The program will keep running in the system tray.";
89 qWarning() << "MainWindow: To terminate the program, choose Quit in the context menu of the system tray entry.";
93 qWarning() << "MainWindow: Close window and exit.";
98 void MainWindow::toggleVisibility(){
100 _geometry
= saveGeometry();
101 setVisible(!isVisible());
103 restoreGeometry(_geometry
);
106 void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason
) {
108 case QSystemTrayIcon::Trigger
:
109 case QSystemTrayIcon::DoubleClick
:
112 case QSystemTrayIcon::MiddleClick
:
119 MainWindow::~MainWindow() {
121 _trayIcon
->deleteLater();
123 _trayIconMenu
->deleteLater();
125 _minimizeAction
->deleteLater();
127 _maximizeAction
->deleteLater();
129 _restoreAction
->deleteLater();
131 _quitAction
->deleteLater();
134 #include "main-window.moc"