2 * @file PswGen/Storage/module.h
3 * @brief Implementation of the iStorage interface
6 * Copyright (c) 2011 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
25 #include <Plugins/iPlugin>
29 #include <QAbstractListModel>
31 #include <QtSql/QSqlDatabase>
37 /// Module that stores options for strong passwords
40 /// Internal implementation of the Storage module
43 } // namespace eVaf::PswGen::Storage::Internal
46 * Module implementing the iStorage interface.
48 class Module
: public Plugins::iPlugin
58 virtual bool init(QString
const & args
);
62 virtual bool isReady() const { return mReady
; }
67 /// Flag indicating that the module is ready
70 /// iStorage interface instance
71 Internal::StorageImpl
* mStorage
;
79 * iStorage interface implementation.
81 * Implements the iStorage interface using a simple file storage.
84 class StorageImpl
: public QAbstractListModel
, public iStorage
87 Q_INTERFACES(eVaf::PswGen::iStorage
)
93 virtual ~StorageImpl();
103 virtual bool save(QString
const & name
, QExplicitlySharedDataPointer
<Storage::Data
> data
);
105 virtual QExplicitlySharedDataPointer
<Storage::Data
> query(QString
const & name
) const;
107 virtual QAbstractItemModel
* autoCompletionModel() { return this; }
110 QAbstractListModel methods
113 virtual int rowCount(QModelIndex
const & parent
) const { return mData
.count(); }
115 virtual QVariant
data(QModelIndex
const & index
, int role
= Qt::DisplayRole
) const;
120 /// Name of the database connection
121 static char const * const DbConnectionName
;
123 /// Name of the database file without path
124 static char const * const DbName
;
126 /// Database connection
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
142 * Loads data from the database
143 * @return True if ok; false if failed
149 } // namespace eVaf::PswGen::Storage::Internal
152 } // namespace eVaf::PswGen::Storage
153 } // namespace eVaf::PswGen