X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=blobdiff_plain;f=src%2Fapps%2FPswGen%2FGUI%2Fgui.cpp;h=f29c4aee6b7620e88ad003474ff4cdbe4ca5bbd6;hb=1a37b3e0faf24936a4b0626b76c08043963a8190;hp=34bd2f0028d89e69de8a8f51337257d492c70466;hpb=473db85d79d6d89b7b8fe617346efa3e94c66cd9;p=evaf
diff --git a/src/apps/PswGen/GUI/gui.cpp b/src/apps/PswGen/GUI/gui.cpp
index 34bd2f0..f29c4ae 100644
--- a/src/apps/PswGen/GUI/gui.cpp
+++ b/src/apps/PswGen/GUI/gui.cpp
@@ -21,6 +21,7 @@
#include "version.h"
#include "Generator/iGenerator"
+#include "Storage/iStorage"
#include
#include
@@ -30,20 +31,22 @@
#include
-using namespace eVaf;
-
VER_EXPORT_VERSION_INFO()
-Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, PswGen::GUI::Module)
+Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, eVaf::PswGen::GUI::Module)
//-------------------------------------------------------------------
+using namespace eVaf;
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 +65,11 @@ bool Module::init(QString const & args)
// Get the iGenerator interface
EVAF_TEST_X((mGenerator = evafQueryInterface("iGenerator")), "No iGenerator interface");
+ // Get the iStorage interface (can be null)
+ mStorage = evafQueryInterface("iStorage");
+ if (!mStorage)
+ EVAF_WARNING("No iStorage interface");
+
// Get the main window interface and fill it with the widgets
SdiWindow::iSdiWindow * win = evafQueryInterface("iSdiWindow");
EVAF_TEST_X(win, "No iSdiWindow interface");
@@ -73,25 +81,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);
@@ -100,7 +114,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 +170,27 @@ void Module::done()
void Module::textChanged(QString const &)
{
wGenerate->setDisabled(wMasterPassword->text().isEmpty() || wName->text().isEmpty());
+ if (!wName->text().isEmpty() && mStorage) {
+ QExplicitlySharedDataPointer 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 data = mStorage->query(wName->text());
+ if (!data)
+ data = new Storage::Data(wName->text(), wLength->value());
+ else
+ data->setLength(wLength->value());
+ mStorage->save(wName->text(), data);
+ }
}
void Module::copyClicked()