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
51 Q_INTERFACES(eVaf::Plugins::iPlugin
)
59 virtual bool init(QString
const & args
);
63 virtual bool isReady() const { return mReady
; }
68 /// Flag indicating that the module is ready
71 /// iStorage interface instance
72 Internal::StorageImpl
* mStorage
;
80 * iStorage interface implementation.
82 * Implements the iStorage interface using a simple file storage.
85 class StorageImpl
: public QAbstractListModel
, public iStorage
88 Q_INTERFACES(eVaf::PswGen::iStorage
)
94 virtual ~StorageImpl();
104 virtual bool save(QString
const & name
, QExplicitlySharedDataPointer
<Storage::Data
> data
);
106 virtual QExplicitlySharedDataPointer
<Storage::Data
> query(QString
const & name
) const;
108 virtual QAbstractItemModel
* autoCompletionModel() { return this; }
111 QAbstractListModel methods
114 virtual int rowCount(QModelIndex
const & parent
) const { return mData
.count(); }
116 virtual QVariant
data(QModelIndex
const & index
, int role
= Qt::DisplayRole
) const;
121 /// Name of the database connection
122 static char const * const DbConnectionName
;
124 /// Name of the database file without path
125 static char const * const DbName
;
127 /// Database connection
130 /// List of name/data pairs
131 QMap
<QString
, QExplicitlySharedDataPointer
<Storage::Data
> > mData
;
137 * Creates database tables if necessary
138 * @return True if ok; false if failed
143 * Loads data from the database
144 * @return True if ok; false if failed
150 } // namespace eVaf::PswGen::Storage::Internal
153 } // namespace eVaf::PswGen::Storage
154 } // namespace eVaf::PswGen