From: Janne Änäkkälä Date: Tue, 20 Apr 2010 11:17:42 +0000 (+0300) Subject: Settings dialog changed. Log in/Log out functionality improved. X-Git-Tag: help~12 X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=commitdiff_plain;h=fc6980e03ca04773cb927560e46afc7193639894 Settings dialog changed. Log in/Log out functionality improved. --- diff --git a/Client/httpclient.cpp b/Client/httpclient.cpp index 547f3b8..a71c104 100644 --- a/Client/httpclient.cpp +++ b/Client/httpclient.cpp @@ -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(); + } diff --git a/Client/httpclient.h b/Client/httpclient.h index 672a5a3..0f4283f 100644 --- a/Client/httpclient.h +++ b/Client/httpclient.h @@ -30,6 +30,9 @@ private: MainWindow *myMainw; QNetworkAccessManager *netManager; +signals: + void loginOK(); + public slots: void requestRegistration(); void checkLogin(); diff --git a/Client/mainwindow.cpp b/Client/mainwindow.cpp index 4f32eee..7706106 100644 --- a/Client/mainwindow.cpp +++ b/Client/mainwindow.cpp @@ -14,6 +14,7 @@ #include #include #include +#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"); + } +} diff --git a/Client/mainwindow.h b/Client/mainwindow.h index 7619e24..4a99582 100644 --- a/Client/mainwindow.h +++ b/Client/mainwindow.h @@ -71,6 +71,7 @@ private slots: void setCategoryCompoBox(); void showTop10(); void killDialog(); + void setUsernameToMainPanel(); }; diff --git a/Client/settingsdialog.cpp b/Client/settingsdialog.cpp index 3ded2bb..ab584e9 100644 --- a/Client/settingsdialog.cpp +++ b/Client/settingsdialog.cpp @@ -9,6 +9,7 @@ #include "settingsdialog.h" #include "ui_settingsdialog.h" #include "usersettings.h" +#include 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(); + } +} diff --git a/Client/settingsdialog.h b/Client/settingsdialog.h index 8263515..cb69f3c 100644 --- a/Client/settingsdialog.h +++ b/Client/settingsdialog.h @@ -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); diff --git a/Client/settingsdialog.ui b/Client/settingsdialog.ui index a136090..255eea9 100644 --- a/Client/settingsdialog.ui +++ b/Client/settingsdialog.ui @@ -41,7 +41,7 @@ - Set User + Log in diff --git a/Client/usersettings.cpp b/Client/usersettings.cpp index 20046cc..be95562 100644 --- a/Client/usersettings.cpp +++ b/Client/usersettings.cpp @@ -71,7 +71,7 @@ bool loginSaved() myLogin.readLoginSettings( &userName, &password); - if (userName.length() > 0) + if (userName.compare("")) { return true; }