4 * @author Olavi Pulkkinen <olavi.pulkkinen@fudeco.com>
5 * @copyright (c) 2010 Speed Freak team
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 #include "settingsdialog.h"
10 #include "ui_settingsdialog.h"
11 #include "usersettings.h"
12 #include <QMessageBox>
14 SettingsDialog::SettingsDialog(QWidget *parent) :
16 ui(new Ui::SettingsDialog)
19 this->setWindowTitle("Settings");
20 this->ui->regEMailLineEdit->setText("@");
26 getLoginInfo( &uName, &pWord);
27 this->username = uName;
28 this->password = pWord;
30 ui->setUserPasswordLineEdit->setText(this->password);
31 ui->setUserUsernameLineEdit->setText(this->username);
33 // Already someone as user - change button text to "Change"
34 ui->setUserPushButton->setText("Log out");
38 SettingsDialog::~SettingsDialog()
43 void SettingsDialog::changeEvent(QEvent *e)
45 QDialog::changeEvent(e);
47 case QEvent::LanguageChange:
48 ui->retranslateUi(this);
58 void SettingsDialog::on_registratePushButton_clicked()
60 // Send username, password and email to SpeedFreak server
61 this->regUsername = ui->regUserNameLineEdit->text();
62 this->regPassword = ui->regPasswordLineEdit->text();
63 this->regEmail = ui->regEMailLineEdit->text();
65 if (this->regUsername.compare("") && this->regPassword.compare("") && this->regEmail.compare("") && this->regEmail.compare("@"))
67 emit sendregistration();
72 QMessageBox::about(this, "One or more of the fields is empty", "Set username (3-12 characters), password (at least 6 characters) and valid email address");
75 //close(); //using close() hides popup-window which reports error from server
78 // Next 6 functions can be removed if Settingsdialog is implemented without
79 // own copy of username, password & email
80 void SettingsDialog::setRegUserName(QString username)
82 this->regUsername = username;
85 void SettingsDialog::setRegPassword(QString password)
87 this->regPassword = password;
90 void SettingsDialog::setRegEmail(QString email)
92 this->regEmail = email;
95 QString SettingsDialog::getRegUserName()
97 return this->regUsername;
100 QString SettingsDialog::getRegPassword()
102 return this->regPassword;
105 QString SettingsDialog::getRegEmail()
107 return this->regEmail;
113 void SettingsDialog::on_setUserPushButton_clicked()
115 if (!ui->setUserPushButton->text().compare("Log out"))
117 ui->setUserUsernameLineEdit->setDisabled(false);
118 ui->setUserPasswordLineEdit->setDisabled(false);
119 //ui->setUserUsernameLineEdit->setText("");
120 //ui->setUserPasswordLineEdit->setText("");
121 ui->setUserUsernameLineEdit->clear();
122 ui->setUserPasswordLineEdit->clear();
123 this->username = ui->setUserUsernameLineEdit->text();
124 this->password = ui->setUserPasswordLineEdit->text();
125 ui->setUserPushButton->setText("Log in");
126 saveLogin( this->username, this->password);
131 this->username = ui->setUserUsernameLineEdit->text();
132 this->password = ui->setUserPasswordLineEdit->text();
133 saveLogin( this->username, this->password);
134 ui->setUserPushButton->setText("Log out");
136 if(this->username.compare(""))
138 emit userNameChanged();
139 //ui->setUserPushButton->setText("Log out");
144 QMessageBox::about(this, "Username field is empty", "Set username and log in again");
145 ui->setUserPushButton->setText("Log in");
148 // Save these also to usersettings
149 //saveLogin( this->username, this->password);
154 // Set "Set/Change User" button text
155 if (this->username.length() > 0)
157 ui->setUserPushButton->setText("Log out");
160 { // Username "cleared"
161 ui->setUserPushButton->setText("Log in");
164 emit userNameChanged();
166 //close(); //using close() hides popup-window which reports error from server
169 // Next 4 functions can be removed if Settingsdialog is implemented without
170 // own copy of username & password
171 void SettingsDialog::setUserName(QString username)
173 this->username = username;
176 void SettingsDialog::setPassword(QString password)
178 this->password = password;
181 QString SettingsDialog::getUserName()
183 return this->username;
186 QString SettingsDialog::getPassword()
188 return this->password;
191 void SettingsDialog::setLabelInfoToUser(QString infoText)
193 this->ui->labelInfoToUser->setText(infoText);
196 void SettingsDialog::usernameOk(bool isOk)
200 ui->setUserPushButton->setText("Log out");
201 ui->setUserUsernameLineEdit->setDisabled(true);
202 ui->setUserPasswordLineEdit->setDisabled(true);
207 ui->setUserPushButton->setText("Log in");
208 ui->setUserUsernameLineEdit->clear();
209 ui->setUserPasswordLineEdit->clear();
210 this->username = ui->setUserUsernameLineEdit->text();
211 this->password = ui->setUserPasswordLineEdit->text();
212 saveLogin( this->username, this->password);