]> vaikene.ee Git - evaf/blobdiff - src/apps/PswGen/GUI/gui.cpp
Warning fixes and copyright update.
[evaf] / src / apps / PswGen / GUI / gui.cpp
index 50eaca11a541c2acb0a89ec8d7e832cc24156320..2a030894bd9873915afd2637ea8aa89ddf91b9a0 100644 (file)
@@ -3,7 +3,7 @@
  * @brief GUI for the PswGen application
  * @author Enar Vaikene
  *
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
  *
  * This file is part of the eVaf C++ cross-platform application development framework.
  *
@@ -18,7 +18,6 @@
  */
 
 #include "gui.h"
-#include "version.h"
 
 #include "Generator/iGenerator"
 #include "Storage/iStorage"
 #include <Common/iLogger>
 #include <Common/iRegistry>
 #include <SdiWindow/iSdiWindow>
+#include <Gui/Panel>
 
-#include <QtGui>
+#include <QtWidgets>
 
 
-using namespace eVaf;
-
 VER_EXPORT_VERSION_INFO()
-Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, PswGen::GUI::Module)
 
 
 //-------------------------------------------------------------------
 
+using namespace eVaf;
 using namespace eVaf::PswGen::GUI;
 
 int const Module::DefaultPasswordLength = 16;
@@ -46,8 +44,8 @@ int const Module::DefaultPasswordLength = 16;
 Module::Module()
     : Plugins::iPlugin()
     , mReady(false)
-    , mGenerator(0)
-    , mStorage(0)
+    , mGenerator(nullptr)
+    , mStorage(nullptr)
 {
     setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__));
 
@@ -61,10 +59,10 @@ Module::~Module()
 
 bool Module::init(QString const & args)
 {
-    Q_UNUSED(args);
+    Q_UNUSED(args)
 
     // Get the iGenerator interface
-    EVAF_TEST_X((mGenerator = evafQueryInterface<PswGen::iGenerator>("iGenerator")), "No 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");
@@ -73,10 +71,13 @@ bool Module::init(QString const & args)
 
     // 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");
+    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);
@@ -106,26 +107,37 @@ bool Module::init(QString const & args)
     }
     connect(wName, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
     g->addWidget(wName, 1, 1, 1, 2);
-    win->widget()->setFocusProxy(wName);
+    panel->setFocusProxy(wName);
 
-    l = new QLabel(tr("&Length of the password:", VER_MODULE_NAME_STR));
+    l = new QLabel(tr("&Suffix:", VER_MODULE_NAME_STR));
     l->setAlignment(Qt::AlignRight);
     g->addWidget(l, 2, 0);
 
+    wSuffix = new QLineEdit;
+    l->setBuddy(wSuffix);
+    g->addWidget(wSuffix, 2, 1, 1, 2);
+
+    l = new QLabel(tr("&Length of the password:", VER_MODULE_NAME_STR));
+    l->setAlignment(Qt::AlignRight);
+    g->addWidget(l, 3, 0);
+
     wLength = new QSpinBox;
     l->setBuddy(wLength);
     wLength->setRange(0, mGenerator->maxLength());
     wLength->setValue(DefaultPasswordLength);
     wLength->setSpecialValueText(tr("Maximum", VER_MODULE_NAME_STR));
-    g->addWidget(wLength, 2, 1);
+    g->addWidget(wLength, 3, 1);
+
+    wAlNum = new QCheckBox(tr("&Alpha-Numeric only", VER_MODULE_NAME_STR));
+    g->addWidget(wAlNum, 3, 2);
 
     l = new QLabel(tr("Password:"));
     l->setAlignment(Qt::AlignRight);
-    g->addWidget(l, 3, 0);
+    g->addWidget(l, 4, 0);
 
     wPassword = new QLineEdit;
     wPassword->setReadOnly(true);
-    g->addWidget(wPassword, 3, 1, 1, 2);
+    g->addWidget(wPassword, 4, 1, 1, 2);
 
     v->addStretch();
 
@@ -144,15 +156,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;
 
@@ -173,8 +185,11 @@ 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)
+        if (data) {
             wLength->setValue(data->length());
+            wSuffix->setText(data->suffix());
+            wAlNum->setChecked(data->flags() & uint(iGenerator::ALPHANUMERIC));
+        }
     }
 }
 
@@ -182,14 +197,27 @@ void Module::generateClicked()
 {
     if (wMasterPassword->text().isEmpty() || wName->text().isEmpty())
         return;
-    wPassword->setText(mGenerator->generatePassword(wName->text(), wMasterPassword->text(), wLength->value()));
+    uint flags = 0;
+    if (wAlNum->isChecked())
+        flags |= iGenerator::ALPHANUMERIC;
+    wPassword->setText(mGenerator->generatePassword(wName->text() + wSuffix->text(),
+                                                    wMasterPassword->text(),
+                                                    wLength->value(),
+                                                    flags));
     wCopy->setEnabled(true);
     if (mStorage) {
         QExplicitlySharedDataPointer<PswGen::Storage::Data> data = mStorage->query(wName->text());
-        if (!data)
-            data = new Storage::Data(wName->text(), wLength->value());
-        else
+        if (!data) {
+            data = new Storage::Data(wName->text(), wSuffix->text(), wLength->value());
+        }
+        else {
+            data->setSuffix(wSuffix->text());
             data->setLength(wLength->value());
+            if (wAlNum->isChecked())
+                data->setFlags(data->flags() | iGenerator::ALPHANUMERIC);
+            else
+                data->setFlags(data->flags() & ~uint(iGenerator::ALPHANUMERIC));
+        }
         mStorage->save(wName->text(), data);
     }
 }