QAlphaCloud  0.0.1
Qt bindings for Alpha Cloud
configuration.h
1 /*
2  * SPDX-FileCopyrightText: 2023 Kai Uwe Broulik <ghqalpha@broulik.de>
3  * SPDX-License-Identifier: LGPL-2.1-or-later
4  */
5 
6 #pragma once
7 
8 #include <QObject>
9 #include <QString>
10 #include <QUrl>
11 
12 #include <memory>
13 
14 #include "qalphacloud.h"
15 
16 #include "qalphacloud_export.h"
17 
18 class QIODevice;
19 class QSettings;
20 
21 namespace QAlphaCloud
22 {
23 
24 class ConfigurationPrivate;
25 
40 class QALPHACLOUD_EXPORT Configuration : public QObject
41 {
42  Q_OBJECT
43 
49  Q_PROPERTY(QUrl apiUrl READ apiUrl WRITE setApiUrl RESET resetApiUrl NOTIFY apiUrlChanged)
50 
51 
56  Q_PROPERTY(QString appId READ appId WRITE setAppId NOTIFY appIdChanged)
57 
58 
61  Q_PROPERTY(QString appSecret READ appSecret WRITE setAppSecret NOTIFY appSecretChanged)
62 
63 
70  Q_PROPERTY(int requestTimeout READ requestTimeout WRITE setRequestTimeout RESET resetRequestTimeout NOTIFY requestTimeoutChanged)
71 
72 
77  Q_PROPERTY(bool valid READ valid NOTIFY validChanged)
78 
79 public:
87  explicit Configuration(QObject *parent = nullptr);
88  ~Configuration() override;
89 
96  static Configuration *defaultConfiguration(QObject *parent = nullptr);
97 
107  static QString defaultConfigurationPath();
108 
109  Q_REQUIRED_RESULT QUrl apiUrl() const;
110  void setApiUrl(const QUrl &apiUrl);
114  void resetApiUrl();
115  Q_SIGNAL void apiUrlChanged(const QUrl &apiUrl);
116 
117  Q_REQUIRED_RESULT QString appId() const;
118  void setAppId(const QString &appId);
119  Q_SIGNAL void appIdChanged(const QString &appId);
120 
121  Q_REQUIRED_RESULT QString appSecret() const;
122  void setAppSecret(const QString &appSecret);
123  Q_SIGNAL void appSecretChanged(const QString &appSecret);
124 
125  Q_REQUIRED_RESULT int requestTimeout() const;
126  void setRequestTimeout(int requestTimeout);
127  void resetRequestTimeout();
128  Q_SIGNAL void requestTimeoutChanged(int requestTimeout);
129 
130  bool valid() const;
131  Q_SIGNAL void validChanged(bool valid);
132 
133 public Q_SLOTS:
134 
140  bool loadFromFile(const QString &path);
141  // TODO QSettings doesn't support reading from QIODevice :-(
142  // bool loadFromDevice(QIODevice *device);
148  bool loadFromSettings(QSettings *settings);
155  bool loadDefault();
156 
157 private:
158  std::unique_ptr<ConfigurationPrivate> const d;
159 };
160 
161 } // namespace QAlphaCloud
API configuration.
Definition: configuration.h:41
Utility namespace.
Definition: apirequest.cpp:24