X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Fsettingsdialog.cpp;h=6c5c8a8b4c75891ec8ac0ed61dcc0d19a3ef9f3c;hp=e19e4e67afe1fa48a098b28faf2295044b9978d8;hb=59a7180931986f4d9420f6b4f1beb85f078fd309;hpb=9bcfcd7c2bf5ae2071d8d9d0d2242ab97789f78e diff --git a/Client/settingsdialog.cpp b/Client/settingsdialog.cpp index e19e4e6..6c5c8a8 100644 --- a/Client/settingsdialog.cpp +++ b/Client/settingsdialog.cpp @@ -1,21 +1,69 @@ +/* + * SettingsDialog class + * + * @author Olavi Pulkkinen + * @author Toni Jussila + * @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 +#include -SettingsDialog::SettingsDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::SettingsDialog) +/** + * Constructor of this class + */ +SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog) { ui->setupUi(this); + + helpSettingsDialog = NULL; + registerDialog = NULL; this->setWindowTitle("Settings"); - this->ui->regEMailLineEdit->setText("@meili.fi"); - instructionsDialog = new InstructionsDialog; + + if (loginSaved()) + { + QString uName, pWord; + + getLoginInfo( &uName, &pWord); + 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->pushButtonProfile->setAutoFillBackground(true); + ui->pushButtonProfile->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); + ui->pushButtonProfile->setDisabled(false); + ui->pushButtonProfile->setVisible(false); + } + // Button settings + ui->pushButtonInfo->setAutoFillBackground(true); + ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); + ui->pushButtonProfile->setVisible(false); } +/** + * Destructor of this class + */ SettingsDialog::~SettingsDialog() { delete ui; } +/** + * + */ void SettingsDialog::changeEvent(QEvent *e) { QDialog::changeEvent(e); @@ -28,92 +76,193 @@ void SettingsDialog::changeEvent(QEvent *e) } } -// -// Help -// -void SettingsDialog::on_pushButtonHelp_clicked() +/** + * This slot function called when ever "register new user" -button clicked. + */ +void SettingsDialog::on_registratePushButton_clicked() { - instructionsDialog->show(); + if(!registerDialog) + { + registerDialog = new RegisterDialog(this); + } + connect(registerDialog, SIGNAL(registrate()), this, SLOT(registrate())); + connect(registerDialog, SIGNAL(rejected()), this, SLOT(killDialog())); + registerDialog->show(); } -// -// Registrate -// -void SettingsDialog::on_registratePushButton_clicked() +/** + * Set / Change user + */ +void SettingsDialog::on_setUserPushButton_clicked() { - // Send username, password and email to SpeedFreak server - this->regUsername = ui->regUserNameLineEdit->text(); - this->regPassword = ui->regPasswordLineEdit->text(); - this->regEmail = ui->regEMailLineEdit->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); + ui->pushButtonProfile->setDisabled(true); + emit logout(); + } + else + { + this->username = ui->setUserUsernameLineEdit->text(); + this->password = ui->setUserPasswordLineEdit->text(); + saveLogin( this->username, this->password); + ui->setUserPushButton->setText("Log out"); - emit sendregistration(); + if(this->username.compare("")) + { + emit userNameChanged(); + //ui->setUserPushButton->setText("Log out"); + } - close(); -} + 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); -// Next 6 functions can be removed if Settingsdialog is implemented without -// own copy of username, password & email -void SettingsDialog::setRegUserName(QString username) -{ - this->regUsername = username; -} + /* + // Set "Set/Change User" button text + if (this->username.length() > 0) + { + ui->setUserPushButton->setText("Log out"); + } + else + { // Username "cleared" + ui->setUserPushButton->setText("Log in"); + } -void SettingsDialog::setRegPassword(QString password) -{ - this->regPassword = password; + emit userNameChanged(); + */ + //close(); //using close() hides popup-window which reports error from server } -void SettingsDialog::setRegEmail(QString email) +// Next 4 functions can be removed if Settingsdialog is implemented without +// own copy of username & password +/** + * Set username. + * + * @param QString username + */ +void SettingsDialog::setUserName(QString username) { - this->regEmail = email; + this->username = username; } -QString SettingsDialog::getRegUserName() +/** + * Set password. + * + * @param QString password + */ +void SettingsDialog::setPassword(QString password) { - return this->regUsername; + this->password = password; } -QString SettingsDialog::getRegPassword() +/** + * Get username. + * + * @return QString username + */ +QString SettingsDialog::getUserName() { - return this->regPassword; + return this->username; } -QString SettingsDialog::getRegEmail() +/** + * Get password. + * + * @return QString password + */ +QString SettingsDialog::getPassword() { - return this->regEmail; + return this->password; } -// -// Set / Change user -// -void SettingsDialog::on_setUserPushButton_clicked() +/** + * Set label info to user. + * + * @param QString info text + */ +void SettingsDialog::setLabelInfoToUser(QString infoText) { - this->username = ui->setUserUsernameLineEdit->text(); - this->password = ui->setUserPasswordLineEdit->text(); - - emit userNameChanged(); - close(); + this->ui->labelInfoToUser->setText(infoText); } -// Next 4 functions can be removed if Settingsdialog is implemented without -// own copy of username & password -void SettingsDialog::setUserName(QString username) +/** + * is username ok. + * + * @param bool is OK + */ +void SettingsDialog::usernameOk(bool isOk) { - this->username = username; + if (isOk) + { + ui->setUserPushButton->setText("Log out"); + ui->setUserUsernameLineEdit->setDisabled(true); + ui->setUserPasswordLineEdit->setDisabled(true); + ui->pushButtonProfile->setDisabled(false); + } + + else + { + ui->setUserPushButton->setText("Log in"); + ui->setUserPasswordLineEdit->clear(); + this->username = ""; + this->password = ""; + saveLogin( this->username, this->password); + ui->pushButtonProfile->setDisabled(true); + } } -void SettingsDialog::setPassword(QString password) +/** + * This slot function called when ever info button clicked. + */ +void SettingsDialog::on_pushButtonInfo_clicked() { - this->password = password; + if(!helpSettingsDialog) + { + helpSettingsDialog = new HelpSettingsDialog; + } + connect(helpSettingsDialog, SIGNAL(rejected()), this, SLOT(killDialog())); + helpSettingsDialog->show(); } -QString SettingsDialog::getUserName() +/** + * This slot function called when ever dialog rejected. + */ +void SettingsDialog::killDialog() { - return this->username; + if(helpSettingsDialog) + { + qDebug() << "__Settings kill: helpSettingsDialog"; + delete helpSettingsDialog; + helpSettingsDialog = NULL; + } + if(registerDialog) + { + qDebug() << "__Settings kill: registerDialog"; + delete registerDialog; + registerDialog = NULL; + } } -QString SettingsDialog::getPassword() +/** + * This slot function called when + * emit sendregistration singnal + */ +void SettingsDialog::registrate() { - return this->password; + emit sendregistration(); } -