-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
44 lines (35 loc) · 1.1 KB
/
main.cpp
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
#include "qaudioswitcher.h"
#include <QApplication>
#include <QtDBus/QtDBus>
#include <QMessageBox>
#include <QString>
#define SERVICE_NAME "com.zergiu.QAudioSwitcher.SwitchAudio"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
auto bus = QDBusConnection::sessionBus();
if(!bus.isConnected()) {
QMessageBox dialog;
dialog.critical(NULL,"Error","Cannot connect to DBus");
return 1;
}
if (!bus.registerService(SERVICE_NAME)) {
auto lastError = bus.lastError();
if(lastError.type() == QDBusError::NoError) return 1;
QString msg;
msg.append("DBus register error: ");
msg.append(lastError.type());
msg.append(",");
msg.append(lastError.name());
msg.append(",");
msg.append(lastError.message());
QMessageBox dialog;
dialog.critical(NULL,"Error",msg);
return 1;
}
QAudioSwitcher w;
//ExportScriptableSlots
QDBusConnection::sessionBus().registerObject("/", &w, QDBusConnection::ExportScriptableSlots);
w.hide();
return a.exec();
}