libquentier  0.5.0
The library for rich desktop clients of Evernote service
ApplicationSettings.h
1 /*
2  * Copyright 2016-2020 Dmitry Ivanov
3  *
4  * This file is part of libquentier
5  *
6  * libquentier is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, version 3 of the License.
9  *
10  * libquentier is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libquentier. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef LIB_QUENTIER_UTILITY_APPLICATION_SETTINGS_H
20 #define LIB_QUENTIER_UTILITY_APPLICATION_SETTINGS_H
21 
22 #include <quentier/types/Account.h>
23 
24 #include <QSettings>
25 
26 namespace quentier {
27 
33 class QUENTIER_EXPORT ApplicationSettings : public QSettings, public Printable
34 {
35  Q_OBJECT
36 public:
41 
54  const Account & account, const QString & settingsName = {});
55 
73  const Account & account, const char * settingsName,
74  const int settingsNameSize = -1);
75 
79  virtual ~ApplicationSettings() override;
80 
81 public:
86  struct ArrayCloser
87  {
88  ArrayCloser(ApplicationSettings & settings) : m_settings(settings) {}
89 
90  ~ArrayCloser()
91  {
92  m_settings.endArray();
93  m_settings.sync();
94  }
95 
96  ApplicationSettings & m_settings;
97  };
98 
103  struct GroupCloser
104  {
105  GroupCloser(ApplicationSettings & settings) : m_settings(settings) {}
106 
107  ~GroupCloser()
108  {
109  m_settings.endGroup();
110  m_settings.sync();
111  }
112 
113  ApplicationSettings & m_settings;
114  };
115 
116 public:
123  void beginGroup(const QString & prefix);
124 
135  void beginGroup(const char * prefix, const int size = -1);
136 
144  int beginReadArray(const QString & prefix);
145 
156  int beginReadArray(const char * prefix, const int size = -1);
157 
168  void beginWriteArray(const QString & prefix, const int arraySize = -1);
169 
184  void beginWriteArray(
185  const char * prefix, const int arraySize = -1,
186  const int prefixSize = -1);
187 
195  bool contains(const QString & key) const;
196 
208  bool contains(const char * key, const int size = -1) const;
209 
216  void remove(const QString & key);
217 
228  void remove(const char * key, const int size = -1);
229 
237  void setValue(const QString & key, const QVariant & value);
238 
250  void setValue(
251  const char * key, const QVariant & value, const int keySize = -1);
252 
263  QVariant value(
264  const QString & key, const QVariant & defaultValue = {}) const;
265 
280  QVariant value(
281  const char * key,
282  const QVariant & defaultValue = {},
283  const int keySize = -1) const;
284 
285 public:
286  virtual QTextStream & print(QTextStream & strm) const override;
287 
288 private:
289  Q_DISABLE_COPY(ApplicationSettings)
290 };
291 
292 } // namespace quentier
293 
294 #endif // LIB_QUENTIER_UTILITY_APPLICATION_SETTINGS_H
Definition: DecryptedTextManager.h:26
The Printable class is the interface for Quentier&#39;s internal classes which should be able to write th...
Definition: Printable.h:37
The Account class encapsulates some details about the account: its name, whether it is local or synch...
Definition: Account.h:38
The ApplicationSettings class enhances the functionality of QSettings, in particular it simplifies th...
Definition: ApplicationSettings.h:33
Definition: ApplicationSettings.h:86
Definition: ApplicationSettings.h:103