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