← Back to team overview

mira-dev team mailing list archive

[Branch ~mira-dev/mira/trunk] Rev 204: Add NewUserDialog h/cpp files

 

------------------------------------------------------------
revno: 204
committer: Alan Alvarez <aalvarez@xxxxxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2010-05-09 10:28:10 -0400
message:
  Add NewUserDialog h/cpp files
added:
  mira-client/include/gui/qt/NewUserDialog.h
  mira-client/src/gui/qt/NewUserDialog.cpp


--
lp:mira/trunk
https://code.launchpad.net/~mira-dev/mira/trunk

Your team Mira Core Development Team is subscribed to branch lp:mira/trunk.
To unsubscribe from this branch go to https://code.launchpad.net/~mira-dev/mira/trunk/+edit-subscription
=== added file 'mira-client/include/gui/qt/NewUserDialog.h'
--- mira-client/include/gui/qt/NewUserDialog.h	1970-01-01 00:00:00 +0000
+++ mira-client/include/gui/qt/NewUserDialog.h	2010-05-09 14:28:10 +0000
@@ -0,0 +1,54 @@
+#ifndef __MIRACLIENT_GUI_NEWUSERDIALOG_H
+#define __MIRACLIENT_GUI_NEWUSERDIALOG_H
+
+#include <QLineEdit>
+#include <QDialog>
+#include <QLabel>
+#include <QFormLayout>
+#include <QGroupBox>
+#include <QPushButton>
+
+namespace miraclient
+{
+
+namespace gui
+{
+
+class NewUserDialog : public QDialog
+{
+    Q_OBJECT
+
+     public:
+         explicit NewUserDialog(QWidget *parent = 0);
+         ~NewUserDialog() {}
+
+         void loginFailed(const QString& error_message);
+
+     private slots:
+         void sendCommand();
+         void cancel();
+         void checkIfComplete();
+
+     private:
+         QVBoxLayout *m_mainLayout;
+         QFormLayout *m_formLayout;
+         QFormLayout *m_buttonsLayout;
+         QGroupBox   *m_newUserGroupBox;
+
+         QLineEdit   *m_usernameLineEdit;
+         QLineEdit   *m_emailLineEdit;
+         QLineEdit   *m_firstNameLineEdit;
+         QLineEdit   *m_lastNameLineEdit;
+         QLineEdit   *m_passwordLineEdit;
+         QLineEdit   *m_password2LineEdit;
+
+
+         QPushButton *m_createButton;
+         QPushButton *m_cancelButton;
+};
+
+} // namespace gui
+
+} // namespace miraclient
+
+#endif // __MIRACLIENT_GUI_NEWUSERDIALOG_H

=== added file 'mira-client/src/gui/qt/NewUserDialog.cpp'
--- mira-client/src/gui/qt/NewUserDialog.cpp	1970-01-01 00:00:00 +0000
+++ mira-client/src/gui/qt/NewUserDialog.cpp	2010-05-09 14:28:10 +0000
@@ -0,0 +1,101 @@
+#include "NewUserDialog.h"
+
+#include <QMessageBox>
+#include "Application.h"
+#include <QRegExpValidator>
+
+namespace miraclient
+{
+
+namespace gui
+{
+
+NewUserDialog::NewUserDialog(QWidget* parent)
+{
+    setWindowTitle(tr("New User"));
+
+    resize(400, 200);
+
+    m_mainLayout = new QVBoxLayout(this);
+
+    m_newUserGroupBox = new QGroupBox();
+    m_newUserGroupBox->setTitle("User Information");
+
+    m_formLayout = new QFormLayout(m_newUserGroupBox);
+
+    m_usernameLineEdit = new QLineEdit(m_newUserGroupBox);
+    m_usernameLineEdit->setValidator(new QRegExpValidator(QRegExp("[\\w]+"), 0));
+    connect(m_usernameLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(checkIfComplete()));
+    m_formLayout->addRow(tr("&Username:"), m_usernameLineEdit);
+
+    m_emailLineEdit = new QLineEdit(m_newUserGroupBox);
+    connect(m_emailLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(checkIfComplete()));
+    m_formLayout->addRow(tr("&E-Mail:"), m_emailLineEdit);
+
+    m_passwordLineEdit = new QLineEdit(m_newUserGroupBox);
+    m_passwordLineEdit->setValidator(new QRegExpValidator(QRegExp("[\\w]+"), 0));
+    m_passwordLineEdit->setEchoMode(QLineEdit::Password);
+    connect(m_passwordLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(checkIfComplete()));
+    m_formLayout->addRow(tr("&Password:"), m_passwordLineEdit);
+
+    m_password2LineEdit = new QLineEdit(m_newUserGroupBox);
+    m_password2LineEdit->setValidator(new QRegExpValidator(QRegExp("[\\w]+"), 0));
+    m_password2LineEdit->setEchoMode(QLineEdit::Password);
+    connect(m_password2LineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(checkIfComplete()));
+    m_formLayout->addRow(tr("&Confirm Password:"), m_password2LineEdit);
+
+    m_firstNameLineEdit = new QLineEdit(m_newUserGroupBox);
+    m_firstNameLineEdit->setValidator(new QRegExpValidator(QRegExp("[\\w]+"), 0));
+    connect(m_firstNameLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(checkIfComplete()));
+    m_formLayout->addRow(tr("&First Name:"), m_firstNameLineEdit);
+
+    m_lastNameLineEdit = new QLineEdit(m_newUserGroupBox);
+    m_lastNameLineEdit->setValidator(new QRegExpValidator(QRegExp("[\\w]+"), 0));
+    connect(m_lastNameLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(checkIfComplete()));
+    m_formLayout->addRow(tr("&Last Name:"), m_lastNameLineEdit);
+
+    m_mainLayout->addWidget(m_newUserGroupBox);
+
+    m_buttonsLayout = new QFormLayout();
+    m_createButton = new QPushButton(tr("Create User"), this);
+    connect(m_createButton, SIGNAL(clicked()), this, SLOT(sendCommand()));
+    m_createButton->setEnabled(false);
+    m_cancelButton  = new QPushButton(tr("Cancel"), this);
+    connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+    m_buttonsLayout->addRow(m_createButton, m_cancelButton);
+    m_buttonsLayout->setFormAlignment(Qt::AlignRight);
+    m_mainLayout->addItem(m_buttonsLayout);
+
+    m_mainLayout->addLayout(m_buttonsLayout);
+}
+
+void NewUserDialog::checkIfComplete()
+{
+  if ( m_usernameLineEdit->text().isEmpty() || m_emailLineEdit->text().isEmpty() || m_passwordLineEdit->text().isEmpty() ||
+       m_password2LineEdit->text().isEmpty() || m_firstNameLineEdit->text().isEmpty() )
+    m_createButton->setDisabled(true);
+  else
+    m_createButton->setEnabled(true);
+}
+
+void NewUserDialog::cancel()
+{
+    reject();
+}
+
+void NewUserDialog::sendCommand()
+{
+    if (m_passwordLineEdit->text() != m_password2LineEdit->text())
+    {
+        QMessageBox::warning(this, "Passwords don't match", "The Password and confirm Password fields do not match. Make sure you have entered the same password in both fields", QMessageBox::Ok);
+        return;
+    }
+
+    QString message = QString("NU %1 %2 %3 %4 %5").arg(m_usernameLineEdit->text()).arg(m_emailLineEdit->text()).arg(m_passwordLineEdit->text()).arg(m_firstNameLineEdit->text()).arg(m_lastNameLineEdit->text());
+    Application::get_client()->send(message.toStdString());
+    accept();
+}
+
+} // namespace gui
+
+} // namespace miraclient