Just testing...one header added to UI_design document.
[speedfreak] / Client / settingsdialog.cpp
index b619576..a50a681 100644 (file)
@@ -1,23 +1,27 @@
 /*
  * SettingsDialog class
  *
- * @author     Olavi Pulkkinen <olavi.pulkkinen@fudeco.com>
- * @copyright  (c) 2010 Speed Freak team
- * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @author      Olavi Pulkkinen <olavi.pulkkinen@fudeco.com>
+ * @author      Toni Jussila    <toni.jussila@fudeco.com>
+ * @copyright   (c) 2010 Speed Freak team
+ * @license     http://opensource.org/licenses/gpl-license.php GNU Public License
  */
 
 #include "settingsdialog.h"
 #include "ui_settingsdialog.h"
 #include "usersettings.h"
+#include <QMessageBox>
+#include <QDebug>
 
 SettingsDialog::SettingsDialog(QWidget *parent) :
-    QDialog(parent),
-    ui(new Ui::SettingsDialog)
+    QDialog(parent), ui(new Ui::SettingsDialog)
 {
     ui->setupUi(this);
+
+    helpSettingsDialog = NULL;
+
     this->setWindowTitle("Settings");
     this->ui->regEMailLineEdit->setText("@");
-    instructionsDialog = new InstructionsDialog;
 
     if (loginSaved())
     {
@@ -27,11 +31,18 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
         this->username = uName;
         this->password = pWord;
 
+        // Set line edit
         ui->setUserPasswordLineEdit->setText(this->password);
         ui->setUserUsernameLineEdit->setText(this->username);
+        ui->setUserPasswordLineEdit->setDisabled(1); // Disable because user logged
+        ui->setUserUsernameLineEdit->setDisabled(1); // Disable because user logged
 
         // Already someone as user - change button text to "Change"
-        ui->setUserPushButton->setText("Change user");
+        ui->setUserPushButton->setText("Log out");
+
+        // Button settings
+        ui->pushButtonInfo->setAutoFillBackground(true);
+        ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
     }
 }
 
@@ -53,14 +64,6 @@ void SettingsDialog::changeEvent(QEvent *e)
 }
 
 //
-// Help
-//
-void SettingsDialog::on_pushButtonHelp_clicked()
-{
-    instructionsDialog->show();
-}
-
-//
 // Registrate
 //
 void SettingsDialog::on_registratePushButton_clicked()
@@ -70,7 +73,15 @@ void SettingsDialog::on_registratePushButton_clicked()
     this->regPassword = ui->regPasswordLineEdit->text();
     this->regEmail = ui->regEMailLineEdit->text();
 
-    emit sendregistration();
+    if (this->regUsername.compare("") && this->regPassword.compare("") && this->regEmail.compare("") && this->regEmail.compare("@"))
+    {
+        emit sendregistration();
+
+    }
+    else
+    {
+        QMessageBox::about(this, "One or more of the fields is empty", "Set username (3-12 characters), password (at least 6 characters) and valid email address");
+    }
 
     //close();      //using close() hides popup-window which reports error from server
 }
@@ -112,24 +123,57 @@ QString SettingsDialog::getRegEmail()
 //
 void SettingsDialog::on_setUserPushButton_clicked()
 {
-    this->username = ui->setUserUsernameLineEdit->text();
-    this->password = ui->setUserPasswordLineEdit->text();
+    if (!ui->setUserPushButton->text().compare("Log out"))
+    {
+        ui->setUserUsernameLineEdit->setDisabled(false);
+        ui->setUserPasswordLineEdit->setDisabled(false);
+        //ui->setUserUsernameLineEdit->setText("");
+        //ui->setUserPasswordLineEdit->setText("");
+        ui->setUserUsernameLineEdit->clear();
+        ui->setUserPasswordLineEdit->clear();
+        this->username = ui->setUserUsernameLineEdit->text();
+        this->password = ui->setUserPasswordLineEdit->text();
+        ui->setUserPushButton->setText("Log in");
+        saveLogin( this->username, this->password);
+        emit logout();
+    }
+    else
+    {
+        this->username = ui->setUserUsernameLineEdit->text();
+        this->password = ui->setUserPasswordLineEdit->text();
+        saveLogin( this->username, this->password);
+        ui->setUserPushButton->setText("Log out");
 
+        if(this->username.compare(""))
+        {
+            emit userNameChanged();
+            //ui->setUserPushButton->setText("Log out");
+        }
+
+        else
+        {
+            QMessageBox::about(this, "Username field is empty", "Set username and log in again");
+            ui->setUserPushButton->setText("Log in");
+        }
+    }
     // Save these also to usersettings
-    saveLogin( this->username, this->password);
+    //saveLogin( this->username, this->password);
+
 
+
+    /*
     // Set "Set/Change User" button text
     if (this->username.length() > 0)
     {
-        ui->setUserPushButton->setText("Change user");
+        ui->setUserPushButton->setText("Log out");
     }
     else
     {   // Username "cleared"
-        ui->setUserPushButton->setText("Set user");
+        ui->setUserPushButton->setText("Log in");
     }
 
     emit userNameChanged();
-
+    */
     //close();  //using close() hides popup-window which reports error from server
 }
 
@@ -159,3 +203,56 @@ void SettingsDialog::setLabelInfoToUser(QString infoText)
 {
     this->ui->labelInfoToUser->setText(infoText);
 }
+
+void SettingsDialog::usernameOk(bool isOk)
+{
+    if (isOk)
+    {
+        ui->setUserPushButton->setText("Log out");
+        ui->setUserUsernameLineEdit->setDisabled(true);
+        ui->setUserPasswordLineEdit->setDisabled(true);
+    }
+
+    else
+    {
+        ui->setUserPushButton->setText("Log in");
+        ui->setUserUsernameLineEdit->clear();
+        ui->setUserPasswordLineEdit->clear();
+        this->username = ui->setUserUsernameLineEdit->text();
+        this->password = ui->setUserPasswordLineEdit->text();
+        saveLogin( this->username, this->password);
+    }
+}
+
+void SettingsDialog::clearRegisterLineEdits()
+{
+    ui->regEMailLineEdit->setText("@");
+    ui->regPasswordLineEdit->setText("");
+    ui->regUserNameLineEdit->setText("");
+}
+
+/**
+  * This slot function called when ever info button clicked.
+  */
+void SettingsDialog::on_pushButtonInfo_clicked()
+{
+    if(!helpSettingsDialog)
+    {
+        helpSettingsDialog = new HelpSettingsDialog;
+    }
+    connect(helpSettingsDialog, SIGNAL(rejected()), this, SLOT(killHelpDialog()));
+    helpSettingsDialog->show();
+}
+
+/**
+  * This slot function called when ever dialog rejected.
+  */
+void SettingsDialog::killHelpDialog()
+{
+    if(helpSettingsDialog)
+    {
+        qDebug() << "__Settings kill: helpSettingsDialog";
+        delete helpSettingsDialog;
+        helpSettingsDialog = NULL;
+    }
+}