4 * @author Olavi Pulkkinen <olavi.pulkkinen@fudeco.com>
5 * @author Toni Jussila <toni.jussila@fudeco.com>
6 * @copyright (c) 2010 Speed Freak team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 #include "settingsdialog.h"
11 #include "ui_settingsdialog.h"
12 #include "usersettings.h"
13 #include <QMessageBox>
16 SettingsDialog::SettingsDialog(QWidget *parent) :
17 QDialog(parent), ui(new Ui::SettingsDialog)
21 helpSettingsDialog = NULL;
24 this->setWindowTitle("Settings");
25 this->ui->regEMailLineEdit->setText("@");
27 ui->pushButtonProfile->setDisabled(true);
33 getLoginInfo( &uName, &pWord);
34 this->username = uName;
35 this->password = pWord;
38 ui->setUserPasswordLineEdit->setText(this->password);
39 ui->setUserUsernameLineEdit->setText(this->username);
40 ui->setUserPasswordLineEdit->setDisabled(1); // Disable because user logged
41 ui->setUserUsernameLineEdit->setDisabled(1); // Disable because user logged
43 // Already someone as user - change button text to "Change"
44 ui->setUserPushButton->setText("Log out");
47 ui->pushButtonInfo->setAutoFillBackground(true);
48 ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
49 ui->pushButtonProfile->setDisabled(false);
52 ui->pushButtonInfo->setAutoFillBackground(true);
53 ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
56 SettingsDialog::~SettingsDialog()
61 void SettingsDialog::changeEvent(QEvent *e)
63 QDialog::changeEvent(e);
65 case QEvent::LanguageChange:
66 ui->retranslateUi(this);
76 void SettingsDialog::on_registratePushButton_clicked()
78 // Send username, password and email to SpeedFreak server
79 this->regUsername = ui->regUserNameLineEdit->text();
80 this->regPassword = ui->regPasswordLineEdit->text();
81 this->regEmail = ui->regEMailLineEdit->text();
83 if (this->regUsername.compare("") && this->regPassword.compare("") && this->regEmail.compare("") && this->regEmail.compare("@"))
85 emit sendregistration();
90 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");
93 //close(); //using close() hides popup-window which reports error from server
96 // Next 6 functions can be removed if Settingsdialog is implemented without
97 // own copy of username, password & email
98 void SettingsDialog::setRegUserName(QString username)
100 this->regUsername = username;
103 void SettingsDialog::setRegPassword(QString password)
105 this->regPassword = password;
108 void SettingsDialog::setRegEmail(QString email)
110 this->regEmail = email;
113 QString SettingsDialog::getRegUserName()
115 return this->regUsername;
118 QString SettingsDialog::getRegPassword()
120 return this->regPassword;
123 QString SettingsDialog::getRegEmail()
125 return this->regEmail;
131 void SettingsDialog::on_setUserPushButton_clicked()
133 if (!ui->setUserPushButton->text().compare("Log out"))
135 ui->setUserUsernameLineEdit->setDisabled(false);
136 ui->setUserPasswordLineEdit->setDisabled(false);
137 //ui->setUserUsernameLineEdit->setText("");
138 //ui->setUserPasswordLineEdit->setText("");
139 ui->setUserUsernameLineEdit->clear();
140 ui->setUserPasswordLineEdit->clear();
141 this->username = ui->setUserUsernameLineEdit->text();
142 this->password = ui->setUserPasswordLineEdit->text();
143 ui->setUserPushButton->setText("Log in");
144 saveLogin( this->username, this->password);
145 ui->pushButtonProfile->setDisabled(true);
150 this->username = ui->setUserUsernameLineEdit->text();
151 this->password = ui->setUserPasswordLineEdit->text();
152 saveLogin( this->username, this->password);
153 ui->setUserPushButton->setText("Log out");
155 if(this->username.compare(""))
157 emit userNameChanged();
158 //ui->setUserPushButton->setText("Log out");
163 QMessageBox::about(this, "Username field is empty", "Set username and log in again");
164 ui->setUserPushButton->setText("Log in");
167 // Save these also to usersettings
168 //saveLogin( this->username, this->password);
173 // Set "Set/Change User" button text
174 if (this->username.length() > 0)
176 ui->setUserPushButton->setText("Log out");
179 { // Username "cleared"
180 ui->setUserPushButton->setText("Log in");
183 emit userNameChanged();
185 //close(); //using close() hides popup-window which reports error from server
188 // Next 4 functions can be removed if Settingsdialog is implemented without
189 // own copy of username & password
190 void SettingsDialog::setUserName(QString username)
192 this->username = username;
195 void SettingsDialog::setPassword(QString password)
197 this->password = password;
200 QString SettingsDialog::getUserName()
202 return this->username;
205 QString SettingsDialog::getPassword()
207 return this->password;
210 void SettingsDialog::setLabelInfoToUser(QString infoText)
212 this->ui->labelInfoToUser->setText(infoText);
215 void SettingsDialog::usernameOk(bool isOk)
219 ui->setUserPushButton->setText("Log out");
220 ui->setUserUsernameLineEdit->setDisabled(true);
221 ui->setUserPasswordLineEdit->setDisabled(true);
222 ui->pushButtonProfile->setDisabled(false);
227 ui->setUserPushButton->setText("Log in");
228 ui->setUserUsernameLineEdit->clear();
229 ui->setUserPasswordLineEdit->clear();
230 this->username = ui->setUserUsernameLineEdit->text();
231 this->password = ui->setUserPasswordLineEdit->text();
232 saveLogin( this->username, this->password);
233 ui->pushButtonProfile->setDisabled(true);
237 void SettingsDialog::clearRegisterLineEdits()
239 ui->regEMailLineEdit->setText("@");
240 ui->regPasswordLineEdit->setText("");
241 ui->regUserNameLineEdit->setText("");
245 * This slot function called when ever info button clicked.
247 void SettingsDialog::on_pushButtonInfo_clicked()
249 if(!helpSettingsDialog)
251 helpSettingsDialog = new HelpSettingsDialog;
253 connect(helpSettingsDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
254 helpSettingsDialog->show();
258 * This slot function called when ever dialog rejected.
260 void SettingsDialog::killDialog()
262 if(helpSettingsDialog)
264 qDebug() << "__Settings kill: helpSettingsDialog";
265 delete helpSettingsDialog;
266 helpSettingsDialog = NULL;
270 qDebug() << "__Settings kill: profileDialog";
271 delete profileDialog;
272 profileDialog = NULL;
277 * This slot function called when ever profile button clicked.
278 * Open profile dialog.
280 void SettingsDialog::on_pushButtonProfile_clicked()
284 profileDialog = new ProfileDialog(this);
286 connect(profileDialog, SIGNAL(saveprofile()), this, SLOT(saveProfile()));
287 connect(profileDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
288 profileDialog->show();
291 void SettingsDialog::saveProfile()