X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=blobdiff_plain;ds=inline;f=src%2Fapps%2FPswGen%2FGUI%2Fgui.cpp;h=1ced109fa27cb869ec691d7568d3c0378dd8cb79;hb=388264abc0442ea0e4c6dca6812cb755053c79d5;hp=dad6f691c75df8418d82e71175856f23add5e4d3;hpb=3352f7acc232104985807b9f470cb12bcb2b47c2;p=evaf
diff --git a/src/apps/PswGen/GUI/gui.cpp b/src/apps/PswGen/GUI/gui.cpp
index dad6f69..1ced109 100644
--- a/src/apps/PswGen/GUI/gui.cpp
+++ b/src/apps/PswGen/GUI/gui.cpp
@@ -21,23 +21,24 @@
#include "version.h"
#include "Generator/iGenerator"
+#include "Storage/iStorage"
#include
#include
#include
#include
+#include
#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;
@@ -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,36 +66,50 @@ 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");
+ Gui::Panel * panel = new Gui::Panel;
+ win->addPanel("PswGen", panel);
+
QVBoxLayout * v = new QVBoxLayout;
- win->widget()->setLayout(v);
+ panel->setLayout(v);
QGridLayout * g = new QGridLayout;
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);
+ panel->setFocusProxy(wName);
l = new QLabel(tr("&Length of the password:", VER_MODULE_NAME_STR));
l->setAlignment(Qt::AlignRight);
@@ -131,15 +147,15 @@ bool Module::init(QString const & args)
connect(wCopy, SIGNAL(clicked()), this, SLOT(copyClicked()));
h->addWidget(wCopy);
- QAction * a = new QAction(win->widget());
+ QAction * a = new QAction(panel);
a->setShortcut(Qt::Key_Return);
connect(a, SIGNAL(triggered()), this, SLOT(generateClicked()));
- win->widget()->addAction(a);
+ panel->addAction(a);
- a = new QAction(win->widget());
+ a = new QAction(panel);
a->setShortcut(Qt::Key_Escape);
connect(a, SIGNAL(triggered()), qApp, SLOT(quit()));
- win->widget()->addAction(a);
+ panel->addAction(a);
mReady = true;
@@ -158,6 +174,11 @@ 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()
@@ -166,6 +187,14 @@ void Module::generateClicked()
return;
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()