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;
31 ui->setUserPasswordLineEdit->setText(this->password);
32 ui->setUserUsernameLineEdit->setText(this->username);
33 ui->setUserPasswordLineEdit->setDisabled(1); // Disable because user logged
34 ui->setUserUsernameLineEdit->setDisabled(1); // Disable because user logged
36 // Already someone as user - change button text to "Change"
37 ui->setUserPushButton->setText("Log out");
41 SettingsDialog::~SettingsDialog()
46 void SettingsDialog::changeEvent(QEvent *e)
48 QDialog::changeEvent(e);
50 case QEvent::LanguageChange:
51 ui->retranslateUi(this);
61 void SettingsDialog::on_registratePushButton_clicked()
63 // Send username, password and email to SpeedFreak server
64 this->regUsername = ui->regUserNameLineEdit->text();
65 this->regPassword = ui->regPasswordLineEdit->text();
66 this->regEmail = ui->regEMailLineEdit->text();
68 if (this->regUsername.compare("") && this->regPassword.compare("") && this->regEmail.compare("") && this->regEmail.compare("@"))
70 emit sendregistration();
75 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");
78 //close(); //using close() hides popup-window which reports error from server
81 // Next 6 functions can be removed if Settingsdialog is implemented without
82 // own copy of username, password & email
83 void SettingsDialog::setRegUserName(QString username)
85 this->regUsername = username;
88 void SettingsDialog::setRegPassword(QString password)
90 this->regPassword = password;
93 void SettingsDialog::setRegEmail(QString email)
95 this->regEmail = email;
98 QString SettingsDialog::getRegUserName()
100 return this->regUsername;
103 QString SettingsDialog::getRegPassword()
105 return this->regPassword;
108 QString SettingsDialog::getRegEmail()
110 return this->regEmail;
116 void SettingsDialog::on_setUserPushButton_clicked()
118 if (!ui->setUserPushButton->text().compare("Log out"))
120 ui->setUserUsernameLineEdit->setDisabled(false);
121 ui->setUserPasswordLineEdit->setDisabled(false);
122 //ui->setUserUsernameLineEdit->setText("");
123 //ui->setUserPasswordLineEdit->setText("");
124 ui->setUserUsernameLineEdit->clear();
125 ui->setUserPasswordLineEdit->clear();
126 this->username = ui->setUserUsernameLineEdit->text();
127 this->password = ui->setUserPasswordLineEdit->text();
128 ui->setUserPushButton->setText("Log in");
129 saveLogin( this->username, this->password);
134 this->username = ui->setUserUsernameLineEdit->text();
135 this->password = ui->setUserPasswordLineEdit->text();
136 saveLogin( this->username, this->password);
137 ui->setUserPushButton->setText("Log out");
139 if(this->username.compare(""))
141 emit userNameChanged();
142 //ui->setUserPushButton->setText("Log out");
147 QMessageBox::about(this, "Username field is empty", "Set username and log in again");
148 ui->setUserPushButton->setText("Log in");
151 // Save these also to usersettings
152 //saveLogin( this->username, this->password);
157 // Set "Set/Change User" button text
158 if (this->username.length() > 0)
160 ui->setUserPushButton->setText("Log out");
163 { // Username "cleared"
164 ui->setUserPushButton->setText("Log in");
167 emit userNameChanged();
169 //close(); //using close() hides popup-window which reports error from server
172 // Next 4 functions can be removed if Settingsdialog is implemented without
173 // own copy of username & password
174 void SettingsDialog::setUserName(QString username)
176 this->username = username;
179 void SettingsDialog::setPassword(QString password)
181 this->password = password;
184 QString SettingsDialog::getUserName()
186 return this->username;
189 QString SettingsDialog::getPassword()
191 return this->password;
194 void SettingsDialog::setLabelInfoToUser(QString infoText)
196 this->ui->labelInfoToUser->setText(infoText);
199 void SettingsDialog::usernameOk(bool isOk)
203 ui->setUserPushButton->setText("Log out");
204 ui->setUserUsernameLineEdit->setDisabled(true);
205 ui->setUserPasswordLineEdit->setDisabled(true);
210 ui->setUserPushButton->setText("Log in");
211 ui->setUserUsernameLineEdit->clear();
212 ui->setUserPasswordLineEdit->clear();
213 this->username = ui->setUserUsernameLineEdit->text();
214 this->password = ui->setUserPasswordLineEdit->text();
215 saveLogin( this->username, this->password);