-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqsharedsettings.cpp
More file actions
91 lines (73 loc) · 2.01 KB
/
qsharedsettings.cpp
File metadata and controls
91 lines (73 loc) · 2.01 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "qsharedsettings.h"
QSharedSettings::QSharedSettings(const QString &organization, const QString &application, QObject *parent)
: QSettings(organization, application, parent)
{
initialize();
}
QSharedSettings::QSharedSettings(Scope scope, const QString &organization, const QString &application, QObject *parent)
: QSettings(scope, organization, application, parent)
{
initialize();
}
QSharedSettings::QSharedSettings(Format format, Scope scope, const QString &organization, const QString &application, QObject *parent)
: QSettings(format, scope, organization, application, parent)
{
initialize();
}
QSharedSettings::QSharedSettings(const QString &fileName, Format format, QObject *parent)
: QSettings(fileName, format, parent)
{
initialize();
}
QSharedSettings::QSharedSettings(QObject *parent)
: QSettings(parent)
{
initialize();
}
void QSharedSettings::initialize()
{
// initialize the qmap
checkSettings();
connect(&m_pollingTimer, SIGNAL(timeout()), this, SLOT(checkSettings()) );
// start the polling timer
m_pollingTimer.start(1000);
}
QSharedSettings::~QSharedSettings()
{
// end the polling timer?
m_pollingTimer.stop();
// free the qmap?
}
// private slot
void QSharedSettings::checkSettings()
{
sync();
QStringList changedKeys = allKeys();
// Check each stored key,value
for(QList<QString> storedKeys = m_storedSettings.keys(); storedKeys.size() > 0; storedKeys.removeFirst()) {
QString k = storedKeys.first();
if(!changedKeys.contains(k)) {
// it's been removed
changedKeys.append(k);
m_storedSettings.remove(k);
}
else if(m_storedSettings.value(k) == value(k) ) {
// it's not been changed
changedKeys.removeAll(k);
}
else {
// update the stored value
m_storedSettings[k] = value(k);
}
}
// Store any new settings
for(int i = 0; i < changedKeys.size(); i++) {
QString k = changedKeys[i];
if(!m_storedSettings.contains(k) && contains(k)) {
m_storedSettings[k] = value(k);
}
}
if(changedKeys.size() > 0) {
emit settingsChanged(changedKeys);
}
}