From: Enar Väikene Date: Fri, 22 Jul 2011 13:53:00 +0000 (+0300) Subject: Modified the PswGen application to follow the tutorial. X-Git-Url: https://vaikene.ee/gitweb/gitweb.cgi?a=commitdiff_plain;h=3352f7acc232104985807b9f470cb12bcb2b47c2;hp=1d2a1e80abac012e9755cd23b264e3e099ccc3f5;p=evaf Modified the PswGen application to follow the tutorial. --- diff --git a/src/apps/PswGen/GUI/gui.cpp b/src/apps/PswGen/GUI/gui.cpp index 34bd2f0..dad6f69 100644 --- a/src/apps/PswGen/GUI/gui.cpp +++ b/src/apps/PswGen/GUI/gui.cpp @@ -40,6 +40,8 @@ Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, PswGen::GUI::Module) using namespace eVaf::PswGen::GUI; +int const Module::DefaultPasswordLength = 16; + Module::Module() : Plugins::iPlugin() , mReady(false) @@ -100,7 +102,7 @@ bool Module::init(QString const & args) wLength = new QSpinBox; l->setBuddy(wLength); wLength->setRange(0, mGenerator->maxLength()); - wLength->setValue(PswGen::iGenerator::DEFAULT_LENGTH); + wLength->setValue(DefaultPasswordLength); wLength->setSpecialValueText(tr("Maximum", VER_MODULE_NAME_STR)); g->addWidget(wLength, 2, 1); @@ -162,7 +164,7 @@ void Module::generateClicked() { if (wMasterPassword->text().isEmpty() || wName->text().isEmpty()) return; - wPassword->setText(mGenerator->generatePassword(wName->text().toLatin1().constData(), wMasterPassword->text().toLatin1().constData(), wLength->value())); + wPassword->setText(mGenerator->generatePassword(wName->text(), wMasterPassword->text(), wLength->value())); wCopy->setEnabled(true); } diff --git a/src/apps/PswGen/GUI/gui.h b/src/apps/PswGen/GUI/gui.h index e9607e4..6f04019 100644 --- a/src/apps/PswGen/GUI/gui.h +++ b/src/apps/PswGen/GUI/gui.h @@ -70,6 +70,8 @@ private slots: private: // Members + static int const DefaultPasswordLength; + /// Flag indicating that the module is ready bool mReady; diff --git a/src/apps/PswGen/Generator/CMakeLists.txt b/src/apps/PswGen/Generator/CMakeLists.txt index ffaba79..dbf88ef 100644 --- a/src/apps/PswGen/Generator/CMakeLists.txt +++ b/src/apps/PswGen/Generator/CMakeLists.txt @@ -16,13 +16,13 @@ set(eVaf_LIBRARIES CommonLib PluginsLib) # Source files set(SRCS - generator.cpp + module.cpp ) # Header files for the meta-object compiler set(MOC_HDRS igenerator.h - generator.h + module.h ) # Version info resource file for Windows builds diff --git a/src/apps/PswGen/Generator/igenerator.h b/src/apps/PswGen/Generator/igenerator.h index d5122f2..a702167 100644 --- a/src/apps/PswGen/Generator/igenerator.h +++ b/src/apps/PswGen/Generator/igenerator.h @@ -23,6 +23,7 @@ #include "lib.h" #include +#include namespace eVaf { namespace PswGen { @@ -39,7 +40,7 @@ class PSWGEN_GENERATOR_EXPORT iGenerator : public QObject public: /// Interface constructor - iGenerator() {} + iGenerator() : QObject() {} /// Empty virtual destructor virtual ~iGenerator() {} @@ -51,18 +52,11 @@ public: ALPHANUMERIC = 0x01 ///< Generated password contains only alphanumeric characters }; - /** - * Default length of the generated password - */ - enum { - DEFAULT_LENGTH = 16 - }; - /** * Generates a strong password * @param name Name of the password * @param masterPassword Master password - * @param length Length of the password + * @param length Length of the password (if zero, then uses the max length) * @param flags Flags for the generator * @return Generated password * @@ -75,7 +69,7 @@ public: * * Optional flags can be used to fine-tune the generator. */ - virtual QString generatePassword(char const * const name, char const * const masterPassword, int length = DEFAULT_LENGTH, uint flags = 0) = 0; + virtual QString generatePassword(QString const & name, QString const & masterPassword, int length, uint flags = 0) const = 0; /** * Returns the maximum length of generated passwords diff --git a/src/apps/PswGen/Generator/generator.cpp b/src/apps/PswGen/Generator/module.cpp similarity index 77% rename from src/apps/PswGen/Generator/generator.cpp rename to src/apps/PswGen/Generator/module.cpp index 01f1a93..27354f5 100644 --- a/src/apps/PswGen/Generator/generator.cpp +++ b/src/apps/PswGen/Generator/module.cpp @@ -1,5 +1,5 @@ /** - * @file PswGen/Generator/generator.cpp + * @file PswGen/Generator/module.cpp * @brief Implementation of the iGenerator interface * @author Enar Vaikene * @@ -17,7 +17,7 @@ * Agreement provided with the Software. */ -#include "generator.h" +#include "module.h" #include "version.h" #include @@ -25,6 +25,9 @@ #include +VER_EXPORT_VERSION_INFO() +Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, eVaf::PswGen::Generator::Module) + using namespace eVaf; using namespace eVaf::PswGen; using namespace eVaf::PswGen::Generator; @@ -33,7 +36,6 @@ using namespace eVaf::PswGen::Generator; Module::Module() : Plugins::iPlugin() - , mReady(false) { setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__)); @@ -49,15 +51,10 @@ Module::~Module() EVAF_INFO("%s destroyed", qPrintable(objectName())); } -bool Module::init(const QString & args) +bool Module::init(QString const & args) { Q_UNUSED(args); - if (!mGenerator->init()) - return false; - - mReady = true; - EVAF_INFO("%s initialized", qPrintable(objectName())); return true; @@ -65,10 +62,6 @@ bool Module::init(const QString & args) void Module::done() { - mReady = false; - - mGenerator->done(); - EVAF_INFO("%s finalized", qPrintable(objectName())); } @@ -92,20 +85,10 @@ GeneratorImpl::~GeneratorImpl() EVAF_INFO("%s destroyed", qPrintable(objectName())); } -bool GeneratorImpl::init() -{ - EVAF_INFO("%s initialized", qPrintable(objectName())); - - return true; -} - -void GeneratorImpl::done() +QString GeneratorImpl::generatePassword(QString const & name, QString const & masterPassword, int length, uint flags) const { - EVAF_INFO("%s finalized", qPrintable(objectName())); -} + Q_UNUSED(flags); -QString GeneratorImpl::generatePassword(char const * const name, char const * const masterPassword, int length, uint flags) -{ QByteArray inputString = QString("%1%2").arg(name).arg(masterPassword).toLatin1(); QCryptographicHash hash(QCryptographicHash::Md5); hash.addData(inputString); @@ -115,9 +98,3 @@ QString GeneratorImpl::generatePassword(char const * const name, char const * co else return result; } - - -//------------------------------------------------------------------- - -VER_EXPORT_VERSION_INFO() -Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, Module) diff --git a/src/apps/PswGen/Generator/generator.h b/src/apps/PswGen/Generator/module.h similarity index 77% rename from src/apps/PswGen/Generator/generator.h rename to src/apps/PswGen/Generator/module.h index 3c3096f..a1be474 100644 --- a/src/apps/PswGen/Generator/generator.h +++ b/src/apps/PswGen/Generator/module.h @@ -1,5 +1,5 @@ /** - * @file PswGen/Generator/generator.h + * @file PswGen/Generator/module.h * @brief Implementation of the iGenerator interface * @author Enar Vaikene * @@ -17,14 +17,15 @@ * Agreement provided with the Software. */ -#ifndef __PSWGEN_GENERATOR_GENERATOR_H -# define __PSWGEN_GENERATOR_GENERATOR_H +#ifndef __PSWGEN_GENERATOR_MODULE_H +# define __PSWGEN_GENERATOR_MODULE_H #include "igenerator.h" #include #include +#include namespace eVaf { namespace PswGen { @@ -34,68 +35,66 @@ namespace Generator { /// Internal implementation of the Generator module namespace Internal { + class GeneratorImpl; +} // namespace eVaf::PswGen::Generator::Internal /** - * iGenerator interface implementation. - * - * Implements the iGenerator interface using MD5 cryptographic hashes. + * Module implementing the iGenerator interface. */ - -class GeneratorImpl : public iGenerator +class Module : public Plugins::iPlugin { Q_OBJECT public: - GeneratorImpl(); + Module(); - virtual ~GeneratorImpl(); + virtual ~Module(); - bool init(); + virtual bool init(QString const & args); - void done(); + virtual void done(); - virtual QString generatePassword(char const * const name, char const * const masterPassword, int length = iGenerator::DEFAULT_LENGTH, uint flags = 0); + virtual bool isReady() const { return true; } - virtual int maxLength() const { return 24; } + +private: // Members + + /// iGenerator interface instance + Internal::GeneratorImpl * mGenerator; }; -} // namespace eVaf::PswGen::Generator::Internal + +namespace Internal { /** - * Module implementing the iGenerator interface. + * iGenerator interface implementation. + * + * Implements the iGenerator interface using MD5 cryptographic hashes. */ -class Module : public Plugins::iPlugin + +class GeneratorImpl : public iGenerator { Q_OBJECT public: - Module(); - - virtual ~Module(); - - virtual bool init(const QString & args); - - virtual void done(); - - virtual bool isReady() const { return mReady; } - + GeneratorImpl(); -private: // Members + virtual ~GeneratorImpl(); - /// Flag indicating that the module is ready - bool mReady; + virtual QString generatePassword(QString const & name, QString const & masterPassword, int length, uint flags = 0) const; - /// iGenerator interface instance - Internal::GeneratorImpl * mGenerator; + virtual int maxLength() const { return 24; } }; +} // namespace eVaf::PswGen::Generator::Internal + } // namespace eVaf::PswGen::Generator } // namespace eVaf::PswGen } // namespace eVaf -#endif // generator.h +#endif // module.h