Commit | Line | Data |
---|---|---|
2340bcd3 JVH |
1 | #include "mainapplication.h" |
2 | ||
3 | #include <QDebug> | |
7cd4f0d4 | 4 | #include <QCoreApplication> |
2340bcd3 JVH |
5 | |
6 | MainApplication::MainApplication(QObject *parent) : | |
7 | QObject(parent) | |
8 | { | |
9 | raopService = new RaopService(0); | |
9434b30c | 10 | dnssdService = new DnssdService(0); |
2340bcd3 JVH |
11 | trayIconMenu = new QMenu(0); |
12 | ||
2340bcd3 JVH |
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 | ||
7cd4f0d4 | 30 | bool MainApplication::start() |
2340bcd3 | 31 | { |
7cd4f0d4 VR |
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 | ||
9434b30c JVH |
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); | |
2340bcd3 | 50 | trayIcon->show(); |
7cd4f0d4 | 51 | return true; |
2340bcd3 JVH |
52 | } |
53 | ||
54 | void MainApplication::stop() | |
55 | { | |
9434b30c | 56 | dnssdService->unregisterRaop(); |
2340bcd3 JVH |
57 | raopService->stop(); |
58 | trayIcon->hide(); | |
59 | } | |
60 | ||
61 | void MainApplication::aboutToQuit() | |
62 | { | |
63 | this->stop(); | |
64 | } |