Commit | Line | Data |
---|---|---|
15c988f7 JB |
1 | #include "mainapplication.h" |
2 | ||
3 | #include <QDebug> | |
4 | #include <QCoreApplication> | |
5 | ||
6 | MainApplication::MainApplication(QObject *parent) : | |
7 | QObject(parent) | |
8 | { | |
9 | raopService = new RaopService(0); | |
10 | dnssdService = new DnssdService(0); | |
11 | trayIconMenu = new QMenu(0); | |
12 | ||
13 | quitAction = new QAction(tr("&Quit"), trayIconMenu); | |
14 | connect(quitAction, SIGNAL(triggered()), this, SIGNAL(quitRequested())); | |
15 | trayIconMenu->addAction(quitAction); | |
16 | ||
17 | // Construct the actual system tray icon | |
18 | trayIcon = new QSystemTrayIcon(this); | |
19 | trayIcon->setContextMenu(trayIconMenu); | |
20 | trayIcon->setIcon(QIcon(":icons/airtv.svg")); | |
21 | } | |
22 | ||
23 | MainApplication::~MainApplication() | |
24 | { | |
25 | trayIcon->setContextMenu(0); | |
26 | delete trayIconMenu; | |
27 | delete raopService; | |
28 | } | |
29 | ||
30 | bool MainApplication::start() | |
31 | { | |
32 | // Initialize the service | |
33 | bool initSuccess = false; | |
34 | initSuccess = raopService->init(10, &m_callbacks); | |
35 | if(!initSuccess) { | |
36 | qDebug() << "Error initializing raop service"; | |
37 | return false; | |
38 | } | |
39 | initSuccess &= dnssdService->init(); | |
40 | if(!initSuccess) { | |
41 | qDebug() << "Error initializing dnssd service"; | |
42 | return false; | |
43 | } | |
44 | ||
45 | char chwaddr[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB }; | |
46 | QByteArray hwaddr(chwaddr, sizeof(chwaddr)); | |
47 | ||
48 | raopService->start(5000, hwaddr); | |
49 | dnssdService->registerRaop("Shairplay", 5000, hwaddr); | |
50 | trayIcon->show(); | |
51 | return true; | |
52 | } | |
53 | ||
54 | void MainApplication::stop() | |
55 | { | |
56 | dnssdService->unregisterRaop(); | |
57 | raopService->stop(); | |
58 | trayIcon->hide(); | |
59 | } | |
60 | ||
61 | void MainApplication::aboutToQuit() | |
62 | { | |
63 | this->stop(); | |
64 | } |