Profile dialog development
[speedfreak] / Client / settingsdialog.cpp
index ab584e9..cf6e26d 100644 (file)
@@ -1,24 +1,31 @@
 /*
  * 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;
+    profileDialog = NULL;
+
     this->setWindowTitle("Settings");
     this->ui->regEMailLineEdit->setText("@");
 
+    ui->pushButtonProfile->setDisabled(true);
+
     if (loginSaved())
     {
         QString uName, pWord;
@@ -27,12 +34,23 @@ 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("Log out");
+
+        // Button settings
+        ui->pushButtonInfo->setAutoFillBackground(true);
+        ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
+        ui->pushButtonProfile->setDisabled(false);
     }
+
+    ui->pushButtonInfo->setAutoFillBackground(true);
+    ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
 }
 
 SettingsDialog::~SettingsDialog()
@@ -62,7 +80,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
 }
@@ -116,6 +142,7 @@ void SettingsDialog::on_setUserPushButton_clicked()
         this->password = ui->setUserPasswordLineEdit->text();
         ui->setUserPushButton->setText("Log in");
         saveLogin( this->username, this->password);
+        ui->pushButtonProfile->setDisabled(true);
         emit logout();
     }
     else
@@ -192,6 +219,7 @@ void SettingsDialog::usernameOk(bool isOk)
         ui->setUserPushButton->setText("Log out");
         ui->setUserUsernameLineEdit->setDisabled(true);
         ui->setUserPasswordLineEdit->setDisabled(true);
+        ui->pushButtonProfile->setDisabled(false);
     }
 
     else
@@ -199,5 +227,68 @@ void SettingsDialog::usernameOk(bool isOk)
         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);
+        ui->pushButtonProfile->setDisabled(true);
     }
 }
+
+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(killDialog()));
+    helpSettingsDialog->show();
+}
+
+/**
+  * This slot function called when ever dialog rejected.
+  */
+void SettingsDialog::killDialog()
+{
+    if(helpSettingsDialog)
+    {
+        qDebug() << "__Settings kill: helpSettingsDialog";
+        delete helpSettingsDialog;
+        helpSettingsDialog = NULL;
+    }
+    if(profileDialog)
+    {
+        qDebug() << "__Settings kill: profileDialog";
+        delete profileDialog;
+        profileDialog = NULL;
+    }
+}
+
+/**
+  * This slot function called when ever profile button clicked.
+  * Open profile dialog.
+  */
+void SettingsDialog::on_pushButtonProfile_clicked()
+{
+    if(!profileDialog)
+    {
+        profileDialog = new ProfileDialog(this);
+    }
+    connect(profileDialog, SIGNAL(saveprofile()), this, SLOT(saveProfile()));
+    connect(profileDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
+    profileDialog->show();
+}
+
+void SettingsDialog::saveProfile()
+{
+    emit saveprofile();
+}