Settings dialog changed. Log in/Log out functionality improved.
authorJanne Änäkkälä <janne.anakkala@fudeco.com>
Tue, 20 Apr 2010 11:17:42 +0000 (14:17 +0300)
committerJanne Änäkkälä <janne.anakkala@fudeco.com>
Tue, 20 Apr 2010 11:17:42 +0000 (14:17 +0300)
Client/httpclient.cpp
Client/httpclient.h
Client/mainwindow.cpp
Client/mainwindow.h
Client/settingsdialog.cpp
Client/settingsdialog.h
Client/settingsdialog.ui
Client/usersettings.cpp

index 547f3b8..a71c104 100644 (file)
@@ -312,13 +312,18 @@ void HttpClient::ackOfLogin()
     if(errorcode != 0) {
         qDebug() <<  "errorcode:" << errorcode << reply->errorString();
         QMessageBox::about(myMainw->settingsDialog, "Server does not recognize your username. Please registrate.",reply->errorString());
+        myMainw->settingsDialog->usernameOk(false);
     }
     else {
         qDebug() <<  "errorcode:" << errorcode << reply->errorString();
         QMessageBox::about(myMainw->settingsDialog, "Server reply to login", "User login " + reply->readAll());
+        // here signal emit to mainwindow for username setting to main panel
+        emit loginOK();
+        myMainw->settingsDialog->usernameOk(true);
+        myMainw->settingsDialog->close();    
     }
 
-    myMainw->settingsDialog->close();
+
 }
 
 
index 672a5a3..0f4283f 100644 (file)
@@ -30,6 +30,9 @@ private:
     MainWindow *myMainw;
     QNetworkAccessManager *netManager;
 
+signals:
+    void loginOK();
+
 public slots:
     void requestRegistration();
     void checkLogin();
index 4f32eee..7706106 100644 (file)
@@ -14,6 +14,7 @@
 #include <QUrl>
 #include <QSettings>
 #include <QDebug>
+#include "usersettings.h"
 
 MainWindow::MainWindow(QWidget *parent) :
     QMainWindow(parent),
@@ -36,6 +37,7 @@ MainWindow::MainWindow(QWidget *parent) :
     settingsDialog = new SettingsDialog;
     connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(clientRegUserToServer()));
     connect(settingsDialog,SIGNAL(userNameChanged()),this,SLOT(clientUserLogin()));
+    connect(settingsDialog, SIGNAL(logout()), this, SLOT(setUsernameToMainPanel()));
 
     httpClient = new HttpClient(this);
     connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
@@ -46,6 +48,8 @@ MainWindow::MainWindow(QWidget *parent) :
     welcomeDialog = new WelcomeDialog;
     welcomeDialog->show();
 
+    this->setUsernameToMainPanel();
+
     //Button settings
     ui->pushButtonAccelerate->setAutoFillBackground(true);
     ui->pushButtonAccelerate->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
@@ -225,6 +229,7 @@ void MainWindow::clientRegUserToServer()
   */
 void MainWindow::clientUserLogin()
 {
+    connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
     httpClient->checkLogin();
 }
 
@@ -268,3 +273,15 @@ void MainWindow::killDialog()
         accstart = NULL;
     }
 }
+
+void MainWindow::setUsernameToMainPanel()
+{
+    if (loginSaved())
+    {
+        this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
+    }
+    else
+    {
+        this->setWindowTitle("SpeedFreak - Not logged");
+    }
+}
index 7619e24..4a99582 100644 (file)
@@ -71,6 +71,7 @@ private slots:
     void setCategoryCompoBox();
     void showTop10();
     void killDialog();
+    void setUsernameToMainPanel();
 
 };
 
index 3ded2bb..ab584e9 100644 (file)
@@ -9,6 +9,7 @@
 #include "settingsdialog.h"
 #include "ui_settingsdialog.h"
 #include "usersettings.h"
+#include <QMessageBox>
 
 SettingsDialog::SettingsDialog(QWidget *parent) :
     QDialog(parent),
@@ -30,7 +31,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
         ui->setUserUsernameLineEdit->setText(this->username);
 
         // Already someone as user - change button text to "Change"
-        ui->setUserPushButton->setText("Change user");
+        ui->setUserPushButton->setText("Log out");
     }
 }
 
@@ -103,24 +104,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
 }
 
@@ -150,3 +184,20 @@ 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();
+    }
+}
index 8263515..cb69f3c 100644 (file)
@@ -33,10 +33,12 @@ public:
     QString getUserName();
     QString getPassword();
     void setLabelInfoToUser(QString infoText);
+    void usernameOk(bool isOk);
 
 signals:
     void sendregistration();
     void userNameChanged();
+    void logout();
 
 protected:
     void changeEvent(QEvent *e);
index a136090..255eea9 100644 (file)
@@ -41,7 +41,7 @@
     </rect>
    </property>
    <property name="text">
-    <string> Set User</string>
+    <string>Log in</string>
    </property>
   </widget>
   <widget class="QLabel" name="registrateLabel">
index 20046cc..be95562 100644 (file)
@@ -71,7 +71,7 @@ bool loginSaved()
 
     myLogin.readLoginSettings( &userName, &password);
 
-    if (userName.length() > 0)
+    if (userName.compare(""))
     {
         return true;
     }