]> vaikene.ee Git - evaf/blobdiff - src/apps/PswGen/GUI/gui.cpp
Fixed a conflict where our forward declaration did not match the actual declaration...
[evaf] / src / apps / PswGen / GUI / gui.cpp
index 34bd2f0028d89e69de8a8f51337257d492c70466..5ebbf105d35de903c65b4f70beda24baad01afec 100644 (file)
@@ -21,6 +21,7 @@
 #include "version.h"
 
 #include "Generator/iGenerator"
+#include "Storage/iStorage"
 
 #include <Common/Globals>
 #include <Common/iLogger>
@@ -40,10 +41,13 @@ 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)
     , mGenerator(0)
+    , mStorage(0)
 {
     setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__));
 
@@ -62,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");
@@ -79,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);
@@ -100,7 +115,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);
 
@@ -156,14 +171,27 @@ 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()
 {
     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);
+    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()