ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CkbSettings Class Reference

#include <src/ckb/ckbsettings.h>

+ Collaboration diagram for CkbSettings:

Public Member Functions

 CkbSettings ()
 
 CkbSettings (const QString &basePath, bool eraseExisting=false)
 
 CkbSettings (QSettings &settings)
 
 ~CkbSettings ()
 
void beginGroup (const QString &prefix)
 
void endGroup ()
 
QStringList childGroups () const
 
QStringList childKeys () const
 
bool contains (const QString &key) const
 
bool containsGroup (const QString &group)
 
QVariant value (const QString &key, const QVariant &defaultValue=QVariant()) const
 
void setValue (const QString &key, const QVariant &value)
 
void remove (const QString &key)
 

Static Public Member Functions

static QVariant get (const QString &key, const QVariant &defaultValue=QVariant())
 
static void set (const QString &key, const QVariant &value)
 
static bool isBusy ()
 
static void cleanUp ()
 

Private Member Functions

QString pwd () const
 
QString pwd (const QString &key) const
 

Private Attributes

QSettings * backing
 
QStringList groups
 
QStringList removeCache
 
QMap< QString, QVariant > writeCache
 

Detailed Description

Definition at line 11 of file ckbsettings.h.

Constructor & Destructor Documentation

CkbSettings::CkbSettings ( )

Definition at line 61 of file ckbsettings.cpp.

61  :
63 }
QSettings * backing
Definition: ckbsettings.h:46
static QSettings * globalSettings()
Definition: ckbsettings.cpp:27
CkbSettings::CkbSettings ( const QString &  basePath,
bool  eraseExisting = false 
)

Definition at line 65 of file ckbsettings.cpp.

References beginGroup().

65  :
67  if(basePath.isEmpty()){
68  if(eraseExisting)
69  qDebug() << "CkbSettings created with basePath = \"\" and eraseExisting = true. This is a mistake.";
70  return;
71  }
72  if(eraseExisting)
73  remove(basePath);
74  beginGroup(basePath);
75 }
QSettings * backing
Definition: ckbsettings.h:46
void beginGroup(const QString &prefix)
Definition: ckbsettings.cpp:81
static QSettings * globalSettings()
Definition: ckbsettings.cpp:27

+ Here is the call graph for this function:

CkbSettings::CkbSettings ( QSettings &  settings)

Definition at line 77 of file ckbsettings.cpp.

77  :
78  backing(&settings) {
79 }
QSettings * backing
Definition: ckbsettings.h:46
CkbSettings::~CkbSettings ( )

Definition at line 145 of file ckbsettings.cpp.

References backing, removeCache, and writeCache.

145  {
146  if(removeCache.isEmpty() && writeCache.isEmpty())
147  return;
148  // Save the settings from the settings thread.
149  // They have to be saved from that thread specifically to avoid performance issues
151  writer->moveToThread(globalThread);
152  QObject::staticMetaObject.invokeMethod(writer, "run", Qt::QueuedConnection);
153 }
QSettings * backing
Definition: ckbsettings.h:46
static QThread * globalThread
Definition: ckbsettings.cpp:9
QMap< QString, QVariant > writeCache
Definition: ckbsettings.h:49
QStringList removeCache
Definition: ckbsettings.h:48

Member Function Documentation

void CkbSettings::beginGroup ( const QString &  prefix)

Definition at line 81 of file ckbsettings.cpp.

References groups.

Referenced by CkbSettings(), KbAnim::save(), and SGroup::SGroup().

81  {
82  groups.append(prefix);
83 }
QStringList groups
Definition: ckbsettings.h:47

+ Here is the caller graph for this function:

QStringList CkbSettings::childGroups ( ) const

Definition at line 89 of file ckbsettings.cpp.

References backing, current, lockMutex, and pwd().

Referenced by containsGroup(), and GradientDialog::GradientDialog().

89  {
90  QString current = pwd();
91  lockMutex;
92  if(!current.isEmpty())
93  backing->beginGroup(current);
94  QStringList res = backing->childGroups();
95  if(!current.isEmpty())
96  backing->endGroup();
97  return res;
98 }
rgb * current
Definition: main.c:46
QSettings * backing
Definition: ckbsettings.h:46
#define lockMutex
Definition: ckbsettings.cpp:15
QString pwd() const
Definition: ckbsettings.h:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QStringList CkbSettings::childKeys ( ) const

Definition at line 100 of file ckbsettings.cpp.

References backing, current, lockMutex, and pwd().

Referenced by GradientDialog::GradientDialog(), KbAnim::KbAnim(), KbBind::load(), KbLight::load(), and KbBind::loadGlobalRemap().

100  {
101  QString current = pwd();
102  lockMutex;
103  if(!current.isEmpty())
104  backing->beginGroup(current);
105  QStringList res = backing->childKeys();
106  if(!current.isEmpty())
107  backing->endGroup();
108  return res;
109 }
rgb * current
Definition: main.c:46
QSettings * backing
Definition: ckbsettings.h:46
#define lockMutex
Definition: ckbsettings.cpp:15
QString pwd() const
Definition: ckbsettings.h:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CkbSettings::cleanUp ( )
static

Definition at line 46 of file ckbsettings.cpp.

References _globalSettings, cacheWritesInProgress(), and globalThread.

Referenced by MainWindow::cleanup().

46  {
47  if(!_globalSettings)
48  return;
49  // Wait for all writers to finish
50  while(cacheWritesInProgress.load() > 0)
51  QThread::yieldCurrentThread();
52  // Stop thread and delete objects
53  globalThread->quit();
54  globalThread->wait();
55  delete globalThread;
56  delete _globalSettings;
57  globalThread = 0;
58  _globalSettings = 0;
59 }
QAtomicInt cacheWritesInProgress(0)
static QThread * globalThread
Definition: ckbsettings.cpp:9
static QSettings * _globalSettings
Definition: ckbsettings.cpp:8

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool CkbSettings::contains ( const QString &  key) const

Definition at line 111 of file ckbsettings.cpp.

References backing, lockMutex, and pwd().

Referenced by KbMode::KbMode(), KbProfile::KbProfile(), and KbPerf::load().

111  {
112  lockMutex;
113  return backing->contains(pwd(key));
114 }
QSettings * backing
Definition: ckbsettings.h:46
Definition: keymap.h:49
#define lockMutex
Definition: ckbsettings.cpp:15
QString pwd() const
Definition: ckbsettings.h:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool CkbSettings::containsGroup ( const QString &  group)

Definition at line 116 of file ckbsettings.cpp.

References childGroups().

Referenced by KbPerf::load().

116  {
117  QStringList components = group.split("/");
118  if(components.length() > 1){
119  // Find sub-group
120  SGroup group(*this, components[0]);
121  return containsGroup(QStringList(components.mid(1)).join('/'));
122  }
123  return childGroups().contains(group);
124 }
bool containsGroup(const QString &group)
QStringList childGroups() const
Definition: ckbsettings.cpp:89

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CkbSettings::endGroup ( )

Definition at line 85 of file ckbsettings.cpp.

References groups.

Referenced by KbAnim::save(), and SGroup::~SGroup().

85  {
86  groups.removeLast();
87 }
QStringList groups
Definition: ckbsettings.h:47

+ Here is the caller graph for this function:

QVariant CkbSettings::get ( const QString &  key,
const QVariant &  defaultValue = QVariant() 
)
static

Definition at line 155 of file ckbsettings.cpp.

References globalCache, globalSettings(), lockMutexCache, and lockMutexStatic2.

Referenced by MainWindow::closeEvent(), KbLightWidget::KbLightWidget(), MainWindow::MainWindow(), AutoRun::once(), and MainWindow::timerTick().

155  {
156  // Store these settings in a memory cache
158  if(globalCache.contains(key))
159  return globalCache.value(key);
160  // If it wasn't found in the memory cache, look for it in QSettings
162  QSettings* settings = globalSettings();
163  return globalCache[key] = settings->value(key, defaultValue);
164 }
Definition: keymap.h:49
static QSettings * globalSettings()
Definition: ckbsettings.cpp:27
static QMap< QString, QVariant > globalCache
Definition: ckbsettings.cpp:12
#define lockMutexCache
Definition: ckbsettings.cpp:18
#define lockMutexStatic2
Definition: ckbsettings.cpp:17

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool CkbSettings::isBusy ( )
static

Definition at line 42 of file ckbsettings.cpp.

References cacheWritesInProgress().

Referenced by Kb::autoSave(), and ExtraSettingsWidget::pollUpdates().

42  {
43  return cacheWritesInProgress.load() > 0;
44 }
QAtomicInt cacheWritesInProgress(0)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString CkbSettings::pwd ( ) const
inlineprivate

Definition at line 51 of file ckbsettings.h.

References groups.

Referenced by childGroups(), childKeys(), contains(), remove(), setValue(), and value().

51 { return groups.join("/"); }
QStringList groups
Definition: ckbsettings.h:47

+ Here is the caller graph for this function:

QString CkbSettings::pwd ( const QString &  key) const
inlineprivate

Definition at line 52 of file ckbsettings.h.

References groups, and pwd().

Referenced by pwd().

52 { return pwd() + (groups.isEmpty() ? "" : "/") + key; }
QStringList groups
Definition: ckbsettings.h:47
Definition: keymap.h:49
QString pwd() const
Definition: ckbsettings.h:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CkbSettings::remove ( const QString &  key)

Definition at line 141 of file ckbsettings.cpp.

References pwd(), and removeCache.

Referenced by SettingsWidget::SettingsWidget().

141  {
142  removeCache.append(pwd(key));
143 }
Definition: keymap.h:49
QString pwd() const
Definition: ckbsettings.h:51
QStringList removeCache
Definition: ckbsettings.h:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CkbSettings::set ( const QString &  key,
const QVariant &  value 
)
static

Definition at line 166 of file ckbsettings.cpp.

References globalCache, globalSettings(), lockMutexCache, lockMutexStatic, and value().

Referenced by MainWindow::closeEvent(), AutoRun::enable(), AutoRun::isEnabled(), SettingsWidget::on_autoFWBox_clicked(), ExtraSettingsWidget::on_delayBox_clicked(), ExtraSettingsWidget::on_ditherBox_clicked(), SettingsWidget::on_layoutBox_activated(), ExtraSettingsWidget::on_mAccelBox_clicked(), ExtraSettingsWidget::on_sAccelBox_clicked(), KbLightWidget::on_showAnimBox_clicked(), ExtraSettingsWidget::on_sSpeedBox_valueChanged(), ExtraSettingsWidget::on_trayBox_clicked(), MPerfWidget::on_xyBox_clicked(), and ExtraSettingsWidget::pollUpdates().

166  {
167  {
169  if(globalCache.value(key) == value)
170  return;
171  globalCache[key] = value;
172  }
174  globalSettings()->setValue(key, value);
175 }
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: keymap.h:49
static QSettings * globalSettings()
Definition: ckbsettings.cpp:27
static QMap< QString, QVariant > globalCache
Definition: ckbsettings.cpp:12
#define lockMutexStatic
Definition: ckbsettings.cpp:16
#define lockMutexCache
Definition: ckbsettings.cpp:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CkbSettings::setValue ( const QString &  key,
const QVariant &  value 
)

Definition at line 131 of file ckbsettings.cpp.

References globalCache, lockMutexCache, pwd(), value(), and writeCache.

Referenced by ExtraSettingsWidget::on_fpsBox_valueChanged(), KbProfile::save(), KbPerf::save(), KbAnim::save(), KbBind::save(), KbMode::save(), KbLight::save(), Kb::save(), KbBind::saveGlobalRemap(), SettingsWidget::SettingsWidget(), and GradientDialog::~GradientDialog().

131  {
132  // Cache the write values, save them when the object is destroyed
133  QString realKey = pwd(key);
134  writeCache[realKey] = value;
135  // Update global cache if needed
137  if(globalCache.contains(realKey))
138  globalCache[realKey] = value;
139 }
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: keymap.h:49
QMap< QString, QVariant > writeCache
Definition: ckbsettings.h:49
static QMap< QString, QVariant > globalCache
Definition: ckbsettings.cpp:12
#define lockMutexCache
Definition: ckbsettings.cpp:18
QString pwd() const
Definition: ckbsettings.h:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QVariant CkbSettings::value ( const QString &  key,
const QVariant &  defaultValue = QVariant() 
) const

Definition at line 126 of file ckbsettings.cpp.

References backing, lockMutex, and pwd().

Referenced by ExtraSettingsWidget::ExtraSettingsWidget(), GradientDialog::GradientDialog(), KbAnim::KbAnim(), KbMode::KbMode(), KbProfile::KbProfile(), KbPerf::load(), KbBind::load(), KbLight::load(), Kb::load(), KbBind::loadGlobalRemap(), set(), SettingsWidget::SettingsWidget(), and setValue().

126  {
127  lockMutex;
128  return backing->value(pwd(key), defaultValue);
129 }
QSettings * backing
Definition: ckbsettings.h:46
Definition: keymap.h:49
#define lockMutex
Definition: ckbsettings.cpp:15
QString pwd() const
Definition: ckbsettings.h:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

QSettings* CkbSettings::backing
private

Definition at line 46 of file ckbsettings.h.

Referenced by childGroups(), childKeys(), contains(), value(), and ~CkbSettings().

QStringList CkbSettings::groups
private

Definition at line 47 of file ckbsettings.h.

Referenced by beginGroup(), endGroup(), and pwd().

QStringList CkbSettings::removeCache
private

Definition at line 48 of file ckbsettings.h.

Referenced by remove(), and ~CkbSettings().

QMap<QString, QVariant> CkbSettings::writeCache
private

Definition at line 49 of file ckbsettings.h.

Referenced by setValue(), and ~CkbSettings().


The documentation for this class was generated from the following files: