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:
46  ApplicationSettings(const QString & settingsName = {});
47 
60  const Account & account, const QString & settingsName = {});
61 
79  const Account & account, const char * settingsName,
80  const int settingsNameSize = -1);
81 
85  virtual ~ApplicationSettings() override;
86 
87 public:
92  struct ArrayCloser
93  {
94  ArrayCloser(ApplicationSettings & settings) : m_settings(settings) {}
95 
96  ~ArrayCloser()
97  {
98  m_settings.endArray();
99  m_settings.sync();
100  }
101 
102  ApplicationSettings & m_settings;
103  };
104 
109  struct GroupCloser
110  {
111  GroupCloser(ApplicationSettings & settings) : m_settings(settings) {}
112 
113  ~GroupCloser()
114  {
115  m_settings.endGroup();
116  m_settings.sync();
117  }
118 
119  ApplicationSettings & m_settings;
120  };
121 
122 public:
129  void beginGroup(const QString & prefix);
130 
141  void beginGroup(const char * prefix, const int size = -1);
142 
150  int beginReadArray(const QString & prefix);
151 
162  int beginReadArray(const char * prefix, const int size = -1);
163 
174  void beginWriteArray(const QString & prefix, const int arraySize = -1);
175 
190  void beginWriteArray(
191  const char * prefix, const int arraySize = -1,
192  const int prefixSize = -1);
193 
201  bool contains(const QString & key) const;
202 
214  bool contains(const char * key, const int size = -1) const;
215 
222  void remove(const QString & key);
223 
234  void remove(const char * key, const int size = -1);
235 
243  void setValue(const QString & key, const QVariant & value);
244 
256  void setValue(
257  const char * key, const QVariant & value, const int keySize = -1);
258 
269  QVariant value(
270  const QString & key, const QVariant & defaultValue = {}) const;
271 
286  QVariant value(
287  const char * key, const QVariant & defaultValue = {},
288  const int keySize = -1) const;
289 
290 public:
291  virtual QTextStream & print(QTextStream & strm) const override;
292 
293 private:
294  Q_DISABLE_COPY(ApplicationSettings)
295 };
296 
297 } // namespace quentier
298 
299 #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:92
Definition: ApplicationSettings.h:109