File indexing completed on 2024-12-22 04:57:52

0001 /*
0002     SPDX-License-Identifier: BSD-2-Clause
0003 */
0004 
0005 #pragma once
0006 
0007 #include <QSettings>
0008 #include <QString>
0009 
0010 #include "o2/o0abstractstore.h"
0011 #include "o2/o0simplecrypt.h"
0012 
0013 /// Persistent storage for authentication tokens, using QSettings.
0014 class O0SettingsStore : public O0AbstractStore
0015 {
0016     Q_OBJECT
0017 
0018 public:
0019     /// Constructor
0020     explicit O0SettingsStore(const QString &encryptionKey, QObject *parent = nullptr);
0021 
0022     /// Construct with an explicit QSettings instance
0023     explicit O0SettingsStore(QSettings *settings, const QString &encryptionKey, QObject *parent = nullptr);
0024 
0025     /// Group key prefix
0026     Q_PROPERTY(QString groupKey READ groupKey WRITE setGroupKey NOTIFY groupKeyChanged)
0027     QString groupKey() const;
0028     void setGroupKey(const QString &groupKey);
0029 
0030     /// Get a string value for a key
0031     QString value(const QString &key, const QString &defaultValue = QString()) override;
0032 
0033     /// Set a string value for a key
0034     void setValue(const QString &key, const QString &value) override;
0035 
0036 Q_SIGNALS:
0037     // Property change signals
0038     void groupKeyChanged();
0039 
0040 protected:
0041     QSettings *settings_ = nullptr;
0042     QString groupKey_;
0043     O0SimpleCrypt crypt_;
0044 };