]> vaikene.ee Git - evaf/blobdiff - src/apps/PswGen/GUI/gui.cpp
Changed the position of master password and name fields.
[evaf] / src / apps / PswGen / GUI / gui.cpp
index dad6f691c75df8418d82e71175856f23add5e4d3..965d70ea7b4052fdf2f6b59f8faa269dc9634413 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");
@@ -75,25 +82,31 @@ bool Module::init(QString const & args)
     v->addLayout(g);
     g->setColumnStretch(2, 2);
 
-    QLabel * l = new QLabel(tr("Web site or application &name:", VER_MODULE_NAME_STR));
+    QLabel * l = new QLabel(tr("Master &password:", VER_MODULE_NAME_STR));
     l->setAlignment(Qt::AlignRight);
     g->addWidget(l, 0, 0);
 
-    wName = new QLineEdit;
-    l->setBuddy(wName);
-    connect(wName, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
-    g->addWidget(wName, 0, 1, 1, 2);
-    win->widget()->setFocusProxy(wName);
-
-    l = new QLabel(tr("Master &password:", VER_MODULE_NAME_STR));
-    l->setAlignment(Qt::AlignRight);
-    g->addWidget(l, 1, 0);
-
     wMasterPassword = new QLineEdit;
     l->setBuddy(wMasterPassword);
     connect(wMasterPassword, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
     wMasterPassword->setEchoMode(QLineEdit::Password);
-    g->addWidget(wMasterPassword, 1, 1, 1, 2);
+    g->addWidget(wMasterPassword, 0, 1, 1, 2);
+
+    l = new QLabel(tr("Web site or application &name:", VER_MODULE_NAME_STR));
+    l->setAlignment(Qt::AlignRight);
+    g->addWidget(l, 1, 0);
+
+    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, 1, 1, 1, 2);
+    win->widget()->setFocusProxy(wName);
 
     l = new QLabel(tr("&Length of the password:", VER_MODULE_NAME_STR));
     l->setAlignment(Qt::AlignRight);
@@ -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()