diff options
Diffstat (limited to 'src/maingui/pwgui.cpp')
-rw-r--r-- | src/maingui/pwgui.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/maingui/pwgui.cpp b/src/maingui/pwgui.cpp new file mode 100644 index 0000000..635ca42 --- /dev/null +++ b/src/maingui/pwgui.cpp @@ -0,0 +1,97 @@ +#include "pwgui.h" +#include "ui_pwgui.h" +#include <QMessageBox> +#include <QTimer> +#include <QDialog> +#include <unistd.h> + +#define BUFLEN 400 + +// ____________________________________________________________________________ +PwGui::PwGui(QWidget *parent) : + QDialog(parent), + ui(new Ui::PwGui), + cancelled(true) +{ + // Initialize UI + initializeUI(user); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(on_accept())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(on_reject())); +} + +// ____________________________________________________________________________ +PwGui::~PwGui() +{ + delete ui; +} + +const QString PwGui::getUser() const +{ + return ui->lineEditUser->text(); +} + +const QString PwGui::getPassword() const +{ + return ui->lineEditPass->text(); +} + +// ____________________________________________________________________________ +void PwGui::initializeUI(char *user) +{ + ui->setupUi(this); + this->setWindowModality(Qt::ApplicationModal); + // Put always on top + this->setWindowFlags(Qt::Dialog | Qt::WindowStaysOnTopHint); + + // Prefill username + if (user != NULL) { + ui->lineEditUser->setText(QString::fromUtf8(user)); + } + + // Protect password from being seen + ui->lineEditPass->setEchoMode(QLineEdit::Password); + ui->lineEditPass->setInputMethodHints(ui->lineEditPass->inputMethodHints() | Qt::ImhNoAutoUppercase); + + /* Main Window properties */ + + // center dialog on screen center + QRect desktopRect = QApplication::desktop()->screenGeometry(this); + this->move( desktopRect.width()/2-this->width()/2, + desktopRect.height()/2-this->height()/2 ); +} + +// ____________________________________________________________________________ +void PwGui::on_accept() +{ + cancelled = false; + this->close(); +} + +// ____________________________________________________________________________ +void PwGui::on_reject() +{ + this->close(); +} + +void PwGui::keyPressEvent(QKeyEvent * e) +{ + if(e->key() != Qt::Key_Escape) { + QMainWindow::keyPressEvent(e); + return; + } + this->close(); +} + +void PwGui::hideEvent(QHideEvent * e) +{ + this->close(); +} + +int PwGui::exec() { + cancelled = true; + this->show(); + this->showNormal(); + this->raise(); + this->activateWindow(); + return QDialog::exec(); +} |