Settings dialog changed. Log in/Log out functionality improved.
[speedfreak] / Client / settingsdialog.cpp
index e19e4e6..ab584e9 100644 (file)
@@ -1,5 +1,15 @@
+/*
+ * 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
+ */
+
 #include "settingsdialog.h"
 #include "ui_settingsdialog.h"
+#include "usersettings.h"
+#include <QMessageBox>
 
 SettingsDialog::SettingsDialog(QWidget *parent) :
     QDialog(parent),
@@ -7,8 +17,22 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
 {
     ui->setupUi(this);
     this->setWindowTitle("Settings");
-    this->ui->regEMailLineEdit->setText("@meili.fi");
-    instructionsDialog = new InstructionsDialog;
+    this->ui->regEMailLineEdit->setText("@");
+
+    if (loginSaved())
+    {
+        QString uName, pWord;
+
+        getLoginInfo( &uName, &pWord);
+        this->username = uName;
+        this->password = pWord;
+
+        ui->setUserPasswordLineEdit->setText(this->password);
+        ui->setUserUsernameLineEdit->setText(this->username);
+
+        // Already someone as user - change button text to "Change"
+        ui->setUserPushButton->setText("Log out");
+    }
 }
 
 SettingsDialog::~SettingsDialog()
@@ -29,14 +53,6 @@ void SettingsDialog::changeEvent(QEvent *e)
 }
 
 //
-// Help
-//
-void SettingsDialog::on_pushButtonHelp_clicked()
-{
-    instructionsDialog->show();
-}
-
-//
 // Registrate
 //
 void SettingsDialog::on_registratePushButton_clicked()
@@ -48,7 +64,7 @@ void SettingsDialog::on_registratePushButton_clicked()
 
     emit sendregistration();
 
-    close();
+    //close();      //using close() hides popup-window which reports error from server
 }
 
 // Next 6 functions can be removed if Settingsdialog is implemented without
@@ -88,11 +104,58 @@ 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);
+
+
+
+    /*
+    // Set "Set/Change User" button text
+    if (this->username.length() > 0)
+    {
+        ui->setUserPushButton->setText("Log out");
+    }
+    else
+    {   // Username "cleared"
+        ui->setUserPushButton->setText("Log in");
+    }
 
     emit userNameChanged();
-    close();
+    */
+    //close();  //using close() hides popup-window which reports error from server
 }
 
 // Next 4 functions can be removed if Settingsdialog is implemented without
@@ -117,3 +180,24 @@ QString SettingsDialog::getPassword()
     return this->password;
 }
 
+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();
+    }
+}