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