libquentier  0.8.0
The library for rich desktop clients of Evernote service
ApplicationSettings.h
1 /*
2  * Copyright 2016-2025 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 #pragma once
20 
21 #include <quentier/types/Account.h>
22 
23 #include <QSettings>
24 
25 #include <string_view>
26 
27 namespace quentier::utility {
28 
34 class QUENTIER_EXPORT ApplicationSettings :
35  public QSettings,
36  public utility::Printable
37 {
38  Q_OBJECT
39 public:
49  explicit ApplicationSettings(const QString & settingsName = {});
50 
62  explicit ApplicationSettings(
63  const Account & account, const QString & settingsName = {});
64 
82  const Account & account, const char * settingsName,
83  int settingsNameSize = -1);
84 
98  ApplicationSettings(const Account & account, std::string_view settingsName);
99 
103  ~ApplicationSettings() override;
104 
109  struct ArrayCloser
110  {
111  ArrayCloser(ApplicationSettings & settings) : m_settings(settings) {}
112 
113  ~ArrayCloser()
114  {
115  m_settings.endArray();
116  m_settings.sync();
117  }
118 
119  ApplicationSettings & m_settings;
120  };
121 
126  struct GroupCloser
127  {
128  GroupCloser(ApplicationSettings & settings) : m_settings(settings) {}
129 
130  ~GroupCloser()
131  {
132  m_settings.endGroup();
133  m_settings.sync();
134  }
135 
136  ApplicationSettings & m_settings;
137  };
138 
145  void beginGroup(const QString & prefix);
146 
157  void beginGroup(const char * prefix, int size = -1);
158 
168  void beginGroup(std::string_view prefix);
169 
177  [[nodiscard]] int beginReadArray(const QString & prefix);
178 
189  [[nodiscard]] int beginReadArray(const char * prefix, int size = -1);
190 
198  [[nodiscard]] int beginReadArray(std::string_view prefix);
199 
210  void beginWriteArray(const QString & prefix, int arraySize = -1);
211 
226  void beginWriteArray(
227  const char * prefix, int arraySize = -1, int prefixSize = -1);
228 
240  void beginWriteArray(std::string_view prefix, int arraySize = -1);
241 
249  [[nodiscard]] bool contains(const QString & key) const;
250 
262  [[nodiscard]] bool contains(const char * key, int size = -1) const;
263 
272  [[nodiscard]] bool contains(std::string_view key) const;
273 
280  void remove(const QString & key);
281 
292  void remove(const char * key, int size = -1);
293 
301  void remove(std::string_view key);
302 
310  void setValue(const QString & key, const QVariant & value);
311 
323  void setValue(const char * key, const QVariant & value, int keySize = -1);
324 
333  void setValue(std::string_view key, const QVariant & value);
334 
345  [[nodiscard]] QVariant value(
346  const QString & key, const QVariant & defaultValue = {}) const;
347 
362  [[nodiscard]] QVariant value(
363  const char * key, const QVariant & defaultValue = {},
364  int keySize = -1) const;
365 
377  [[nodiscard]] QVariant value(
378  std::string_view key, const QVariant & defaultValue = {}) const;
379 
380  // utility::Printable
381  QTextStream & print(QTextStream & strm) const override;
382 
383 private:
384  Q_DISABLE_COPY(ApplicationSettings)
385 };
386 
387 } // namespace quentier::utility
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:37
Definition: ApplicationSettings.h:27
Definition: ApplicationSettings.h:126
Definition: ApplicationSettings.h:109
The ApplicationSettings class enhances the functionality of QSettings, in particular it simplifies th...
Definition: ApplicationSettings.h:34