summaryrefslogtreecommitdiff
path: root/client/ProxyClientApp.cpp
blob: 8f06473a84bdeb4c108d291abc31867c8be25d8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

#include <QMenu>
#include <QMessageBox>

#include "client.h"
#include "Dialog.h"
#include "ProxyClientApp.h"

ProxyClientApp::ProxyClientApp(int &argc, char *argv[]): QApplication(argc, argv)
{
	if (!QSystemTrayIcon::isSystemTrayAvailable())
	{
		Logger::Fatal("No system tray available! Terminating.\n");
        return;
	}
	
	/* create system tray menu */
	QMenu *trayMenu = new QMenu;
	QAction *showAction = new QAction(tr("&Show"), this);
	showAction->setStatusTip(tr("Open dialog to choose a proxy"));
	connect(showAction, SIGNAL(triggered()), this, SLOT(showProxyDialog()));
	QAction *quitAction = new QAction(tr("&Quit"), this);
	quitAction->setStatusTip(tr("Close this application"));
	connect(quitAction, SIGNAL(triggered()), this, SLOT(quitApp()));
	trayMenu->addAction(showAction);
	trayMenu->addAction(quitAction);
	
	QIcon *icon = new QIcon(":/icon.png");
	trayIcon = new QSystemTrayIcon(*icon);
	connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
			this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
	trayIcon->setContextMenu(trayMenu);
	trayIcon->show();
	delete icon;
	
	QApplication::setQuitOnLastWindowClosed(false);
}

void ProxyClientApp::trayActivated(QSystemTrayIcon::ActivationReason reason)
{
	if (reason == QSystemTrayIcon::DoubleClick)
	{
		showProxyDialog();
	}
}

void ProxyClientApp::showProxyDialog()
{
	Logger::Trace("Creating proxy dialog.\n");
	ProxyDialog *dialog = new ProxyDialog();
	dialog->show();
}

void ProxyClientApp::quitApp()
{
	Logger::Info("Terminating\n");
        trayIcon->hide();
	QApplication::exit(0);
}