2 * @file PswGen/Storage/module.h
3 * @brief Implementation of the iStorage interface
6 * Copyright (c) 2011-2019 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
20 #ifndef __PSWGEN_STORAGE_MODULE_H
21 # define __PSWGEN_STORAGE_MODULE_H
26 #include <Plugins/iPlugin>
30 #include <QAbstractListModel>
38 /// Module that stores options for strong passwords
41 /// Internal implementation of the Storage module
44 } // namespace eVaf::PswGen::Storage::Internal
47 * Module implementing the iStorage interface.
49 class Module
: public Plugins::iPlugin
52 Q_INTERFACES(eVaf::Plugins::iPlugin
)
53 Q_PLUGIN_METADATA(IID VER_MODULE_NAME_STR
)
61 virtual bool init(QString
const & args
);
65 virtual bool isReady() const { return mReady
; }
70 /// Flag indicating that the module is ready
73 /// iStorage interface instance
74 Internal::StorageImpl
* mStorage
;
82 * iStorage interface implementation.
84 * Implements the iStorage interface using a simple file storage.
87 class StorageImpl
: public QAbstractListModel
, public iStorage
90 Q_INTERFACES(eVaf::PswGen::iStorage
)
96 virtual ~StorageImpl();
106 virtual bool save(QString
const & name
, QExplicitlySharedDataPointer
<Storage::Data
> data
);
108 virtual QExplicitlySharedDataPointer
<Storage::Data
> query(QString
const & name
) const;
110 virtual QAbstractItemModel
* autoCompletionModel() { return this; }
113 QAbstractListModel methods
116 virtual int rowCount(QModelIndex
const &) const { return mData
.count(); }
118 virtual QVariant
data(QModelIndex
const & index
, int role
= Qt::DisplayRole
) const;
123 /// Name of the database connection
124 static char const * const DbConnectionName
;
126 /// Name of the database file without path
127 static char const * const DbName
;
129 /// List of name/data pairs
130 QMap
<QString
, QExplicitlySharedDataPointer
<Storage::Data
> > mData
;
136 * Creates database tables if necessary
137 * @return True if ok; false if failed
139 bool createTables(QSqlDatabase
& db
);
142 * Upgrades database tables if necessary
143 * @return True if ok; false if failed
145 * This function checks if database tables need to upgraded and
146 * performs the upgrade without a loss of data if possible.
147 * Returns false if upgrade is not possible or fails.
149 bool upgradeTables(QSqlDatabase
& db
);
152 * Loads data from the database
153 * @return True if ok; false if failed
155 bool loadData(QSqlDatabase
& db
);
159 } // namespace eVaf::PswGen::Storage::Internal
162 } // namespace eVaf::PswGen::Storage
163 } // namespace eVaf::PswGen