-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_app.cpp
More file actions
58 lines (50 loc) · 1.86 KB
/
Copy pathmain_app.cpp
File metadata and controls
58 lines (50 loc) · 1.86 KB
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
#include "main_app.h"
#include "app_constants.h"
#include <QCoreApplication>
#include <QDebug>
MainApp::MainApp(QObject *parent)
: QObject(parent),
settings_(new Settings()),
dashboard_(new Dashboard(settings_)),
bt_service_(new BluetoothService())
{
connect(settings_, &Settings::settingsChanged, this, &MainApp::on_configurationChanged);
connect(dashboard_, &Dashboard::quit, this, &MainApp::on_quit);
connect(dashboard_, &Dashboard::discoverableChanged, bt_service_, &BluetoothService::setDiscoverable);
connect(bt_service_, &BluetoothService::codeReceived, dashboard_, &Dashboard::newCode);
connect(bt_service_, &BluetoothService::started, dashboard_, &Dashboard::setBtServiceStarted);
connect(bt_service_, &BluetoothService::stopped, dashboard_, &Dashboard::setBtServiceStopped);
connect(bt_service_, &BluetoothService::bindFailed, dashboard_, &Dashboard::setBtServiceStopped);
}
void MainApp::start()
{
dashboard_->start();
QString addr = settings_->settings().adapter_address;
if (!addr.isEmpty()) {
bt_service_->start(addr);
}
}
void MainApp::on_configurationChanged(const settings_type &new_settings)
{
qDebug() << "Changed configuration: "
<< new_settings.adapter_address << ", "
<< new_settings.auto_copy_clipboard;
if (new_settings.adapter_address != bt_service_->adapterAddress()) {
qDebug() << "Need to restart bt service";
bt_service_->restart(new_settings.adapter_address);
}
}
void MainApp::on_quit()
{
bt_service_->terminate();
bt_service_->deleteLater();
dashboard_->deleteLater();
settings_->deleteLater();
qApp->quit();
}
void MainApp::setOrganizationFields()
{
QCoreApplication::setOrganizationName(ORG_NAME);
QCoreApplication::setOrganizationDomain(ORG_NAME);
QCoreApplication::setApplicationName(APP_NAME);
}