]> vaikene.ee Git - evaf/commitdiff
Added support for the iStorage interface.
authorEnar Väikene <enar@vaikene.net>
Tue, 26 Jul 2011 12:09:42 +0000 (15:09 +0300)
committerEnar Väikene <enar@vaikene.net>
Tue, 26 Jul 2011 12:09:42 +0000 (15:09 +0300)
Non-sensitive data for password generator is stored using the iStorage interface.
The name field uses an auto-completer with data from the Storage module.

src/apps/PswGen/GUI/CMakeLists.txt
src/apps/PswGen/GUI/gui.cpp
src/apps/PswGen/GUI/gui.h

index fceaa2ec0636aa37327b9f63ee6fb400f245743e..060625bea3be6402d0aa3a2fc3ebcebf43fb5851 100644 (file)
@@ -4,14 +4,11 @@ set(TARGET PswGui)
 # Qt modules
 include(${QT_USE_FILE})
 
-# Needed for exporting/importing symbols
-add_definitions(-DPSWGEN_GUI_LIBRARY)
-
 # Include files
 include_directories(${eVaf_INCLUDE})
 
 # Required eVaf libraries
-set(eVaf_LIBRARIES CommonLib PluginsLib SdiWindow PswGen)
+set(eVaf_LIBRARIES CommonLib PluginsLib SdiWindow)
 
 # Source files
 set(SRCS
index dad6f691c75df8418d82e71175856f23add5e4d3..5ebbf105d35de903c65b4f70beda24baad01afec 100644 (file)
@@ -21,6 +21,7 @@
 #include "version.h"
 
 #include "Generator/iGenerator"
+#include "Storage/iStorage"
 
 #include <Common/Globals>
 #include <Common/iLogger>
@@ -46,6 +47,7 @@ Module::Module()
     : Plugins::iPlugin()
     , mReady(false)
     , mGenerator(0)
+    , mStorage(0)
 {
     setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__));
 
@@ -64,6 +66,11 @@ bool Module::init(QString const & args)
     // Get the iGenerator interface
     EVAF_TEST_X((mGenerator = evafQueryInterface<PswGen::iGenerator>("iGenerator")), "No iGenerator interface");
 
+    // Get the iStorage interface (can be null)
+    mStorage = evafQueryInterface<PswGen::iStorage>("iStorage");
+    if (!mStorage)
+        EVAF_WARNING("No iStorage interface");
+
     // Get the main window interface and fill it with the widgets
     SdiWindow::iSdiWindow * win = evafQueryInterface<SdiWindow::iSdiWindow>("iSdiWindow");
     EVAF_TEST_X(win, "No iSdiWindow interface");
@@ -81,6 +88,12 @@ bool Module::init(QString const & args)
 
     wName = new QLineEdit;
     l->setBuddy(wName);
+    if (mStorage) {
+        QCompleter * completer = new QCompleter(wName);
+        completer->setModel(mStorage->autoCompletionModel());
+        completer->setCompletionMode(QCompleter::InlineCompletion);
+        wName->setCompleter(completer);
+    }
     connect(wName, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
     g->addWidget(wName, 0, 1, 1, 2);
     win->widget()->setFocusProxy(wName);
@@ -158,6 +171,11 @@ void Module::done()
 void Module::textChanged(QString const &)
 {
     wGenerate->setDisabled(wMasterPassword->text().isEmpty() || wName->text().isEmpty());
+    if (!wName->text().isEmpty() && mStorage) {
+        QExplicitlySharedDataPointer<PswGen::Storage::Data> data = mStorage->query(wName->text());
+        if (data)
+            wLength->setValue(data->length());
+    }
 }
 
 void Module::generateClicked()
@@ -166,6 +184,14 @@ void Module::generateClicked()
         return;
     wPassword->setText(mGenerator->generatePassword(wName->text(), wMasterPassword->text(), wLength->value()));
     wCopy->setEnabled(true);
+    if (mStorage) {
+        QExplicitlySharedDataPointer<PswGen::Storage::Data> data = mStorage->query(wName->text());
+        if (!data)
+            data = new Storage::Data(wLength->value());
+        else
+            data->setLength(wLength->value());
+        mStorage->save(wName->text(), data);
+    }
 }
 
 void Module::copyClicked()
index 6f04019a849c0bc8e4c87946a120e21f91c6d5ee..359034289e53f39e5f2e3a7bf62d6fc8ab1c37a2 100644 (file)
@@ -32,6 +32,7 @@ class QPushButton;
 namespace eVaf {
 namespace PswGen {
     class iGenerator;
+    class iStorage;
 namespace GUI {
 
 /**
@@ -78,6 +79,9 @@ private: // Members
     /// The iGenerator interface
     eVaf::PswGen::iGenerator * mGenerator;
 
+    /// The iStorage interface (can be null)
+    eVaf::PswGen::iStorage * mStorage;
+
     /// Widgets on the screen
     QLineEdit * wName;
     QLineEdit * wMasterPassword;