-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.cpp
More file actions
70 lines (58 loc) · 1.88 KB
/
Copy pathsettings.cpp
File metadata and controls
70 lines (58 loc) · 1.88 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
59
60
61
62
63
64
65
66
67
68
69
70
#include "settings.h"
#include "app_constants.h"
#include <QDebug>
#define KEY_ADAPTER_ADDRESS "adapter-address"
#define KEY_AUTO_COPY "auto-copy-clipboard"
Settings::Settings(QObject *parent)
: QObject(parent),
settings_storage_(ORG_NAME, APP_NAME),
current_settings_()
{
reloadSettingsOrDefaults();
}
const QString Settings::adapterAddress() const
{
return current_settings_.adapter_address;
}
bool Settings::autoCopyCode() const
{
return current_settings_.auto_copy_clipboard;
}
const settings_type Settings::settings() const
{
return current_settings_;
}
void Settings::setAdapterAddress(const QString &address)
{
if (current_settings_.adapter_address != address) {
current_settings_.adapter_address = address;
emit settingsChanged(current_settings_);
}
}
void Settings::setAutoCopyCode(const bool enabled)
{
if (current_settings_.auto_copy_clipboard != enabled) {
current_settings_.auto_copy_clipboard = enabled;
emit settingsChanged(current_settings_);
}
}
void Settings::updateSettings(const settings_type &new_settings)
{
if (new_settings != current_settings_) {
qDebug() << "Settings have been changed: " << new_settings.adapter_address << ", " << new_settings.auto_copy_clipboard;
current_settings_ = settings_type(new_settings);
emit settingsChanged(current_settings_);
}
}
void Settings::saveSettings()
{
settings_storage_.setValue(KEY_ADAPTER_ADDRESS, current_settings_.adapter_address);
settings_storage_.setValue(KEY_AUTO_COPY, current_settings_.auto_copy_clipboard);
}
void Settings::reloadSettingsOrDefaults()
{
struct settings_type new_settings;
new_settings.adapter_address = settings_storage_.value(KEY_ADAPTER_ADDRESS, "").toString();
new_settings.auto_copy_clipboard = settings_storage_.value(KEY_AUTO_COPY, false).toBool();
updateSettings(new_settings);
}