]>
vaikene.ee Git - evaf/blob - src/apps/PswGen/GUI/gui.cpp
2 * @file PswGen/GUI/gui.cpp
3 * @brief GUI for the PswGen application
6 * Copyright (c) 2011 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
23 #include "Generator/iGenerator"
25 #include <Common/Globals>
26 #include <Common/iLogger>
27 #include <Common/iRegistry>
28 #include <SdiWindow/iSdiWindow>
35 VER_EXPORT_VERSION_INFO()
36 Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR
, PswGen::GUI::Module
)
39 //-------------------------------------------------------------------
41 using namespace eVaf::PswGen::GUI
;
43 int const Module::DefaultPasswordLength
= 16;
50 setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR
).arg(__FUNCTION__
));
52 EVAF_INFO("%s created", qPrintable(objectName()));
57 EVAF_INFO("%s destroyed", qPrintable(objectName()));
60 bool Module::init(QString
const & args
)
64 // Get the iGenerator interface
65 EVAF_TEST_X((mGenerator
= evafQueryInterface
<PswGen::iGenerator
>("iGenerator")), "No iGenerator interface");
67 // Get the main window interface and fill it with the widgets
68 SdiWindow::iSdiWindow
* win
= evafQueryInterface
<SdiWindow::iSdiWindow
>("iSdiWindow");
69 EVAF_TEST_X(win
, "No iSdiWindow interface");
71 QVBoxLayout
* v
= new QVBoxLayout
;
72 win
->widget()->setLayout(v
);
74 QGridLayout
* g
= new QGridLayout
;
76 g
->setColumnStretch(2, 2);
78 QLabel
* l
= new QLabel(tr("Web site or application &name:", VER_MODULE_NAME_STR
));
79 l
->setAlignment(Qt::AlignRight
);
80 g
->addWidget(l
, 0, 0);
82 wName
= new QLineEdit
;
84 connect(wName
, SIGNAL(textChanged(QString
)), this, SLOT(textChanged(QString
)));
85 g
->addWidget(wName
, 0, 1, 1, 2);
86 win
->widget()->setFocusProxy(wName
);
88 l
= new QLabel(tr("Master &password:", VER_MODULE_NAME_STR
));
89 l
->setAlignment(Qt::AlignRight
);
90 g
->addWidget(l
, 1, 0);
92 wMasterPassword
= new QLineEdit
;
93 l
->setBuddy(wMasterPassword
);
94 connect(wMasterPassword
, SIGNAL(textChanged(QString
)), this, SLOT(textChanged(QString
)));
95 wMasterPassword
->setEchoMode(QLineEdit::Password
);
96 g
->addWidget(wMasterPassword
, 1, 1, 1, 2);
98 l
= new QLabel(tr("&Length of the password:", VER_MODULE_NAME_STR
));
99 l
->setAlignment(Qt::AlignRight
);
100 g
->addWidget(l
, 2, 0);
102 wLength
= new QSpinBox
;
103 l
->setBuddy(wLength
);
104 wLength
->setRange(0, mGenerator
->maxLength());
105 wLength
->setValue(DefaultPasswordLength
);
106 wLength
->setSpecialValueText(tr("Maximum", VER_MODULE_NAME_STR
));
107 g
->addWidget(wLength
, 2, 1);
109 l
= new QLabel(tr("Password:"));
110 l
->setAlignment(Qt::AlignRight
);
111 g
->addWidget(l
, 3, 0);
113 wPassword
= new QLineEdit
;
114 wPassword
->setReadOnly(true);
115 g
->addWidget(wPassword
, 3, 1, 1, 2);
119 QHBoxLayout
* h
= new QHBoxLayout
;
123 wGenerate
= new QPushButton(tr("&Generate", VER_MODULE_NAME_STR
));
124 wGenerate
->setDisabled(true);
125 wGenerate
->setDefault(true);
126 connect(wGenerate
, SIGNAL(clicked()), this, SLOT(generateClicked()));
127 h
->addWidget(wGenerate
);
129 wCopy
= new QPushButton(tr("&Copy to Clipboard", VER_MODULE_NAME_STR
));
130 wCopy
->setDisabled(true);
131 connect(wCopy
, SIGNAL(clicked()), this, SLOT(copyClicked()));
134 QAction
* a
= new QAction(win
->widget());
135 a
->setShortcut(Qt::Key_Return
);
136 connect(a
, SIGNAL(triggered()), this, SLOT(generateClicked()));
137 win
->widget()->addAction(a
);
139 a
= new QAction(win
->widget());
140 a
->setShortcut(Qt::Key_Escape
);
141 connect(a
, SIGNAL(triggered()), qApp
, SLOT(quit()));
142 win
->widget()->addAction(a
);
146 EVAF_INFO("%s initialized", qPrintable(objectName()));
155 EVAF_INFO("%s finalized", qPrintable(objectName()));
158 void Module::textChanged(QString
const &)
160 wGenerate
->setDisabled(wMasterPassword
->text().isEmpty() || wName
->text().isEmpty());
163 void Module::generateClicked()
165 if (wMasterPassword
->text().isEmpty() || wName
->text().isEmpty())
167 wPassword
->setText(mGenerator
->generatePassword(wName
->text(), wMasterPassword
->text(), wLength
->value()));
168 wCopy
->setEnabled(true);
171 void Module::copyClicked()
173 QClipboard
* clipboard
= QApplication::clipboard();
175 clipboard
->setText(wPassword
->text());