]> vaikene.ee Git - evaf/blob - src/apps/PswGen/Storage/istorage.h
Added the PswStorage module.
[evaf] / src / apps / PswGen / Storage / istorage.h
1 /**
2 * @file PswGen/Storage/istorage.h
3 * @brief Interface for password storage modules
4 * @author Enar Vaikene
5 *
6 * Copyright (c) 2011 Enar Vaikene
7 *
8 * This file is part of the eVaf C++ cross-platform application development framework.
9 *
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.
15 *
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
18 */
19
20 #ifndef __PSWGEN_STORAGE_ISTORAGE_H
21 # define __PSWGEN_STORAGE_ISTORAGE_H
22
23 #include "lib.h"
24
25 #include <QObject>
26 #include <QString>
27 #include <QSharedData>
28 #include <QExplicitlySharedDataPointer>
29
30 class QAbstractItemModel;
31
32 namespace eVaf {
33 namespace PswGen {
34
35 namespace Storage {
36
37 /**
38 * Data stored for every password.
39 */
40 class PSWGEN_STORAGE_EXPORT Data : public QSharedData
41 {
42 public:
43
44 Data()
45 : QSharedData()
46 , mModified(false)
47 , mLength(0)
48 , mFlags(0)
49 {}
50
51 Data(int l, uint f = 0)
52 : QSharedData()
53 , mModified(false)
54 , mLength(l)
55 , mFlags(f)
56 {}
57
58 /// Length of the generated password
59 inline int length() const { return mLength; }
60 inline void setLength(int value)
61 {
62 if (mLength != value) {
63 mLength = value;
64 mModified = true;
65 }
66 }
67
68 /// Optional flags for the password generator
69 inline uint flags() const { return mFlags; }
70 inline void setFlags(uint value)
71 {
72 if (mFlags != value) {
73 mFlags = value;
74 mModified = true;
75 }
76 }
77
78 /// Flag indicating that some fields are modified
79 bool modified() const { return mModified; }
80
81 /// Resets the modified flag
82 void reset() { mModified = false; }
83
84
85 private:
86
87 bool mModified;
88 int mLength;
89 uint mFlags;
90
91 };
92
93 } // eVaf::PswGen::Storage
94
95 /**
96 * Password storage interface.
97 *
98 * This interface is used to store options that were used to generate strong passwords.
99 */
100 struct iStorage
101 {
102
103 /**
104 * Saves the data record
105 * @param name Name of the password
106 * @param data Data for the password
107 * @return True if ok; false if failed
108 */
109 virtual bool save(QString const & name, QExplicitlySharedDataPointer<Storage::Data> data) = 0;
110
111 /**
112 * Returns a data record by the name
113 * @param name Name of the password
114 * @return Shared data pointer of the stored data record or invalid if not found
115 */
116 virtual QExplicitlySharedDataPointer<Storage::Data> query(QString const & name) const = 0;
117
118 /**
119 * Returns an item model with the names of all the stored passwords
120 *
121 * This function returns an item model with the names of all the stored passwords. Use the item
122 * model for auto completion.
123 */
124 virtual QAbstractItemModel * autoCompletionModel() = 0;
125
126 };
127
128 } // namespace eVaf::PswGen
129 } // namespace eVaf
130
131 Q_DECLARE_INTERFACE(eVaf::PswGen::iStorage, "eVaf.PswGen.iStorage/1.0")
132
133 #endif // istorage.h