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();
+
}
#include <QUrl>
#include <QSettings>
#include <QDebug>
+#include "usersettings.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(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()));
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)");
*/
void MainWindow::clientUserLogin()
{
+ connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
httpClient->checkLogin();
}
accstart = NULL;
}
}
+
+void MainWindow::setUsernameToMainPanel()
+{
+ if (loginSaved())
+ {
+ this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
+ }
+ else
+ {
+ this->setWindowTitle("SpeedFreak - Not logged");
+ }
+}
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include "usersettings.h"
+#include <QMessageBox>
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(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");
}
}
//
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
}
{
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();
+ }
+}