/** * @file PswGen/Storage/istorage.h * @brief Interface for password storage modules * @author Enar Vaikene * * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * * This file can be used under the terms of the GNU General Public License * version 3.0 as published by the Free Software Foundation and appearing in * the file LICENSE included in the packaging of this file. Please review the * the following information to ensure the GNU General Public License version * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. * * Alternatively, this file may be used in accordance with the Commercial License * Agreement provided with the Software. */ #ifndef __PSWGEN_STORAGE_ISTORAGE_H # define __PSWGEN_STORAGE_ISTORAGE_H #include #include #include #include class QAbstractItemModel; namespace eVaf { namespace PswGen { namespace Storage { /** * Data stored for every password. */ class Data : public QSharedData { public: Data(QString const & name) : QSharedData() , mModified(false) , mName(name) , mSuffix() , mLength(0) , mFlags(0) {} Data(QString const & name, QString const & suffix, int l, uint f = 0) : QSharedData() , mModified(false) , mName(name) , mSuffix(suffix) , mLength(l) , mFlags(f) {} /// Name of the password inline QString const & name() const { return mName; } /// Optional suffix added to the name inline QString const & suffix() const { return mSuffix; } void setSuffix(QString const & suffix) { if (suffix != mSuffix) { mSuffix = suffix; mModified = true; } } /// Length of the generated password inline int length() const { return mLength; } inline void setLength(int value) { if (mLength != value) { mLength = value; mModified = true; } } /// Optional flags for the password generator inline uint flags() const { return mFlags; } inline void setFlags(uint value) { if (mFlags != value) { mFlags = value; mModified = true; } } /// Flag indicating that some fields are modified bool modified() const { return mModified; } /// Resets the modified flag void reset() { mModified = false; } private: bool mModified; QString mName; QString mSuffix; int mLength; uint mFlags; }; } // eVaf::PswGen::Storage /** * Password storage interface. * * This interface is used to store options that were used to generate strong passwords. */ struct iStorage { /** * Empty virtual destructor */ ~iStorage() {} /** * Saves the data record * @param name Name of the password * @param data Data for the password * @return True if ok; false if failed */ virtual bool save(QString const & name, QExplicitlySharedDataPointer data) = 0; /** * Returns a data record by the name * @param name Name of the password * @return Shared data pointer of the stored data record or invalid if not found */ virtual QExplicitlySharedDataPointer query(QString const & name) const = 0; /** * Returns an item model with the names of all the stored passwords * * This function returns an item model with the names of all the stored passwords. Use the item * model for auto completion. */ virtual QAbstractItemModel * autoCompletionModel() = 0; }; } // namespace eVaf::PswGen } // namespace eVaf Q_DECLARE_INTERFACE(eVaf::PswGen::iStorage, "eVaf.PswGen.iStorage/1.0") #endif // istorage.h