2 * @file PswGen/Storage/module.h
3 * @brief Implementation of the iStorage interface
6 * Copyright (c) 2011-2012 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>
32 #include <QtSql/QSqlDatabase>
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 & parent
) 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 /// Database connection
132 /// List of name/data pairs
133 QMap
<QString
, QExplicitlySharedDataPointer
<Storage::Data
> > mData
;
139 * Creates database tables if necessary
140 * @return True if ok; false if failed
145 * Upgrades database tables if necessary
146 * @return True if ok; false if failed
148 * This function checks if database tables need to upgraded and
149 * performs the upgrade without a loss of data if possible.
150 * Returns false if upgrade is not possible or fails.
152 bool upgradeTables();
155 * Loads data from the database
156 * @return True if ok; false if failed
162 } // namespace eVaf::PswGen::Storage::Internal
165 } // namespace eVaf::PswGen::Storage
166 } // namespace eVaf::PswGen