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 emit sendregistration();
67 //close(); //using close() hides popup-window which reports error from server
70 // Next 6 functions can be removed if Settingsdialog is implemented without
71 // own copy of username, password & email
72 void SettingsDialog::setRegUserName(QString username)
74 this->regUsername = username;
77 void SettingsDialog::setRegPassword(QString password)
79 this->regPassword = password;
82 void SettingsDialog::setRegEmail(QString email)
84 this->regEmail = email;
87 QString SettingsDialog::getRegUserName()
89 return this->regUsername;
92 QString SettingsDialog::getRegPassword()
94 return this->regPassword;
97 QString SettingsDialog::getRegEmail()
99 return this->regEmail;
105 void SettingsDialog::on_setUserPushButton_clicked()
107 if (!ui->setUserPushButton->text().compare("Log out"))
109 ui->setUserUsernameLineEdit->setDisabled(false);
110 ui->setUserPasswordLineEdit->setDisabled(false);
111 //ui->setUserUsernameLineEdit->setText("");
112 //ui->setUserPasswordLineEdit->setText("");
113 ui->setUserUsernameLineEdit->clear();
114 ui->setUserPasswordLineEdit->clear();
115 this->username = ui->setUserUsernameLineEdit->text();
116 this->password = ui->setUserPasswordLineEdit->text();
117 ui->setUserPushButton->setText("Log in");
118 saveLogin( this->username, this->password);
123 this->username = ui->setUserUsernameLineEdit->text();
124 this->password = ui->setUserPasswordLineEdit->text();
125 saveLogin( this->username, this->password);
126 ui->setUserPushButton->setText("Log out");
128 if(this->username.compare(""))
130 emit userNameChanged();
131 //ui->setUserPushButton->setText("Log out");
136 QMessageBox::about(this, "Username field is empty", "Set username and log in again");
137 ui->setUserPushButton->setText("Log in");
140 // Save these also to usersettings
141 //saveLogin( this->username, this->password);
146 // Set "Set/Change User" button text
147 if (this->username.length() > 0)
149 ui->setUserPushButton->setText("Log out");
152 { // Username "cleared"
153 ui->setUserPushButton->setText("Log in");
156 emit userNameChanged();
158 //close(); //using close() hides popup-window which reports error from server
161 // Next 4 functions can be removed if Settingsdialog is implemented without
162 // own copy of username & password
163 void SettingsDialog::setUserName(QString username)
165 this->username = username;
168 void SettingsDialog::setPassword(QString password)
170 this->password = password;
173 QString SettingsDialog::getUserName()
175 return this->username;
178 QString SettingsDialog::getPassword()
180 return this->password;
183 void SettingsDialog::setLabelInfoToUser(QString infoText)
185 this->ui->labelInfoToUser->setText(infoText);
188 void SettingsDialog::usernameOk(bool isOk)
192 ui->setUserPushButton->setText("Log out");
193 ui->setUserUsernameLineEdit->setDisabled(true);
194 ui->setUserPasswordLineEdit->setDisabled(true);
199 ui->setUserPushButton->setText("Log in");
200 ui->setUserUsernameLineEdit->clear();
201 ui->setUserPasswordLineEdit->clear();
202 this->username = ui->setUserUsernameLineEdit->text();
203 this->password = ui->setUserPasswordLineEdit->text();
204 saveLogin( this->username, this->password);