source: SMSSender/common/persistence/impl/encryptedstoragehelper_base.h @ 414:4f6018bd5487

Last change on this file since 414:4f6018bd5487 was 414:4f6018bd5487, checked in by Sämy Zehnder <saemy.zehnder@…>, 6 years ago
  • Adds missing export flags to classes.
  • Adds missing includes to smartphone-base.pro.
  • Removes obsolote uic parameters from frontend-gui.pro.
File size: 4.1 KB
Line 
1/*
2 smssender - A frontend for fast and easy SMS sending over different gateways.
3 Copyright (C) 2007-2014, gorrión. See http://smssender.gorrion.ch
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18#ifndef COMMON_PERSISTENCE_IMPL_ENCRYPTEDSTORAGEHELPER_BASE_H
19#define COMMON_PERSISTENCE_IMPL_ENCRYPTEDSTORAGEHELPER_BASE_H
20
21#include <QScopedPointer>
22
23#include "common/global.h"
24#include "common/persistence/imainstorage.h"
25#include "common/persistence/istoragehelper.h"
26
27namespace Persistence {
28
29class BaseEncryptedMainStorage : public IMainStorage {
30public:
31    explicit BaseEncryptedMainStorage(IMainStorage *mainStorage, const QString &encryptionKey)
32        : m_mainStorage(mainStorage)
33        , m_encryptionKey(encryptionKey)
34    {}
35
36    inline QVariant readValue(const QString &_namespace, const QString &key, const QVariant &defaultValue = QVariant()) { return m_mainStorage->readValue(_namespace, key, defaultValue); }
37    inline bool readBool(const QString &_namespace, const QString &key, bool defaultValue = false) { return m_mainStorage->readBool(_namespace, key, defaultValue); }
38    inline int readInt(const QString &_namespace, const QString &key, int defaultValue = 0) { return m_mainStorage->readInt(_namespace, key, defaultValue); }
39    inline QString readString(const QString &_namespace, const QString &key, const QString &defaultValue = QString()) { return m_mainStorage->readString(_namespace, key, defaultValue); }
40    inline QString readEncryptedString(const QString &_namespace, const QString &key, const QString &password, const QString &defaultValue) { return m_mainStorage->readEncryptedString(_namespace, key, password, defaultValue); }
41    inline QString readEncryptedString(const QString &_namespace, const QString &key, const QString &defaultValue) { return readEncryptedString(_namespace, key, m_encryptionKey, defaultValue); }
42
43    inline void writeValue(const QString &_namespace, const QString &key, const QVariant &value) { m_mainStorage->writeValue(_namespace, key, value); }
44    inline void writeBool(const QString &_namespace, const QString &key, bool value) { m_mainStorage->writeBool(_namespace, key, value); }
45    inline void writeInt(const QString &_namespace, const QString &key, int value) { m_mainStorage->writeInt(_namespace, key, value); }
46    inline void writeString(const QString &_namespace, const QString &key, const QString &value) { m_mainStorage->writeString(_namespace, key, value); }
47    inline void writeEncryptedString(const QString &_namespace, const QString &key, const QString &password, const QString &value) { m_mainStorage->writeEncryptedString(_namespace, key, password, value); }
48    inline void writeEncryptedString(const QString &_namespace, const QString &key, const QString &value) { writeEncryptedString(_namespace, key, m_encryptionKey, value); }
49
50    inline void removeValue(const QString &_namespace, const QString &key) { m_mainStorage->removeValue(_namespace, key); }
51    inline void removeValues(const QString &_namespace) { m_mainStorage->removeValues(_namespace); }
52
53protected:
54    inline void init(const QSqlDatabase &db) { Q_UNUSED(db); Q_ASSERT(false); }
55    inline QSqlDatabase database() { Q_ASSERT(false); return QSqlDatabase(); }
56
57    IMainStorage * const m_mainStorage;
58
59private:
60    const QString m_encryptionKey;
61};
62
63class COMMON_EXPORT EncryptedStorageHelper : public IStorageHelper {
64public:
65    EncryptedStorageHelper(IMainStorage *storage, const QString &encryptionKey);
66
67protected:
68    BaseEncryptedMainStorage *storage() const;
69
70private:
71    QScopedPointer<BaseEncryptedMainStorage> m_storage;
72};
73
74}
75
76#endif // COMMON_PERSISTENCE_IMPL_ENCRYPTEDSTORAGEHELPER_BASE_H
Note: See TracBrowser for help on using the repository browser.