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