-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
65 lines (51 loc) · 2.08 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <QTimer>
#include <QProcess>
#include "ancs.h"
int main(int argc, char *argv[])
{
//QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));
QCoreApplication a(argc, argv);
QBluetoothLocalDevice localDevice;
ANCS ancs;
if (localDevice.hostMode() == QBluetoothLocalDevice::HostPoweredOff)
{
QTextStream(stdout) << "Bluetooth Device Powered Off" << endl;
return -1;
}
QTextStream(stdout) << "Discoverable as " << localDevice.name() << endl;
QTextStream(stdout) << "Note: If this has been changed, iOS may have cached the name as something else" << endl;
QObject::connect(&localDevice, &QBluetoothLocalDevice::error, [&](QBluetoothLocalDevice::Error error){
QTextStream(stdout) << "Local Device Error: " << error << endl;
ancs.stop();
a.exit(-1);
});
QObject::connect(&localDevice, &QBluetoothLocalDevice::hostModeStateChanged, [&](QBluetoothLocalDevice::HostMode state){
if (state == QBluetoothLocalDevice::HostPoweredOff)
{
QTextStream(stdout) << "Bluetooth Radio turned off." << endl;
ancs.stop();
a.exit(-1);
}
});
QObject::connect(&ancs, &ANCS::finished, &a, &QCoreApplication::exit);
QObject::connect(&ancs, &ANCS::newNotification, [&](const ANCSNotification& notification) {
if (notification.getAppIdentifier().find("SMS") != std::string::npos)
{
QStringList args;
args.append(notification.getTitle().c_str());
args.append(notification.getMessage().c_str());
args.append("--icon=mail-unread");
QProcess::execute("notify-send", args);
}
if (notification.getAppIdentifier().find("mobilephone") != std::string::npos)
{
QStringList args;
args.append(notification.getTitle().c_str());
args.append("Incoming call...");
args.append("--icon=phone");
QProcess::execute("notify-send", args);
}
});
QTimer::singleShot(0, &ancs, &ANCS::start);
return a.exec();
}