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;
23 this->setWindowTitle("Settings");
24 this->ui->regEMailLineEdit->setText("@");
30 getLoginInfo( &uName, &pWord);
31 this->username = uName;
32 this->password = pWord;
35 ui->setUserPasswordLineEdit->setText(this->password);
36 ui->setUserUsernameLineEdit->setText(this->username);
37 ui->setUserPasswordLineEdit->setDisabled(1); // Disable because user logged
38 ui->setUserUsernameLineEdit->setDisabled(1); // Disable because user logged
40 // Already someone as user - change button text to "Change"
41 ui->setUserPushButton->setText("Log out");
44 ui->pushButtonInfo->setAutoFillBackground(true);
45 ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
49 SettingsDialog::~SettingsDialog()
54 void SettingsDialog::changeEvent(QEvent *e)
56 QDialog::changeEvent(e);
58 case QEvent::LanguageChange:
59 ui->retranslateUi(this);
69 void SettingsDialog::on_registratePushButton_clicked()
71 // Send username, password and email to SpeedFreak server
72 this->regUsername = ui->regUserNameLineEdit->text();
73 this->regPassword = ui->regPasswordLineEdit->text();
74 this->regEmail = ui->regEMailLineEdit->text();
76 if (this->regUsername.compare("") && this->regPassword.compare("") && this->regEmail.compare("") && this->regEmail.compare("@"))
78 emit sendregistration();
83 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");
86 //close(); //using close() hides popup-window which reports error from server
89 // Next 6 functions can be removed if Settingsdialog is implemented without
90 // own copy of username, password & email
91 void SettingsDialog::setRegUserName(QString username)
93 this->regUsername = username;
96 void SettingsDialog::setRegPassword(QString password)
98 this->regPassword = password;
101 void SettingsDialog::setRegEmail(QString email)
103 this->regEmail = email;
106 QString SettingsDialog::getRegUserName()
108 return this->regUsername;
111 QString SettingsDialog::getRegPassword()
113 return this->regPassword;
116 QString SettingsDialog::getRegEmail()
118 return this->regEmail;
124 void SettingsDialog::on_setUserPushButton_clicked()
126 if (!ui->setUserPushButton->text().compare("Log out"))
128 ui->setUserUsernameLineEdit->setDisabled(false);
129 ui->setUserPasswordLineEdit->setDisabled(false);
130 //ui->setUserUsernameLineEdit->setText("");
131 //ui->setUserPasswordLineEdit->setText("");
132 ui->setUserUsernameLineEdit->clear();
133 ui->setUserPasswordLineEdit->clear();
134 this->username = ui->setUserUsernameLineEdit->text();
135 this->password = ui->setUserPasswordLineEdit->text();
136 ui->setUserPushButton->setText("Log in");
137 saveLogin( this->username, this->password);
142 this->username = ui->setUserUsernameLineEdit->text();
143 this->password = ui->setUserPasswordLineEdit->text();
144 saveLogin( this->username, this->password);
145 ui->setUserPushButton->setText("Log out");
147 if(this->username.compare(""))
149 emit userNameChanged();
150 //ui->setUserPushButton->setText("Log out");
155 QMessageBox::about(this, "Username field is empty", "Set username and log in again");
156 ui->setUserPushButton->setText("Log in");
159 // Save these also to usersettings
160 //saveLogin( this->username, this->password);
165 // Set "Set/Change User" button text
166 if (this->username.length() > 0)
168 ui->setUserPushButton->setText("Log out");
171 { // Username "cleared"
172 ui->setUserPushButton->setText("Log in");
175 emit userNameChanged();
177 //close(); //using close() hides popup-window which reports error from server
180 // Next 4 functions can be removed if Settingsdialog is implemented without
181 // own copy of username & password
182 void SettingsDialog::setUserName(QString username)
184 this->username = username;
187 void SettingsDialog::setPassword(QString password)
189 this->password = password;
192 QString SettingsDialog::getUserName()
194 return this->username;
197 QString SettingsDialog::getPassword()
199 return this->password;
202 void SettingsDialog::setLabelInfoToUser(QString infoText)
204 this->ui->labelInfoToUser->setText(infoText);
207 void SettingsDialog::usernameOk(bool isOk)
211 ui->setUserPushButton->setText("Log out");
212 ui->setUserUsernameLineEdit->setDisabled(true);
213 ui->setUserPasswordLineEdit->setDisabled(true);
218 ui->setUserPushButton->setText("Log in");
219 ui->setUserUsernameLineEdit->clear();
220 ui->setUserPasswordLineEdit->clear();
221 this->username = ui->setUserUsernameLineEdit->text();
222 this->password = ui->setUserPasswordLineEdit->text();
223 saveLogin( this->username, this->password);
227 void SettingsDialog::clearRegisterLineEdits()
229 ui->regEMailLineEdit->setText("@");
230 ui->regPasswordLineEdit->setText("");
231 ui->regUserNameLineEdit->setText("");
235 * This slot function called when ever info button clicked.
237 void SettingsDialog::on_pushButtonInfo_clicked()
239 if(!helpSettingsDialog)
241 helpSettingsDialog = new HelpSettingsDialog;
243 connect(helpSettingsDialog, SIGNAL(rejected()), this, SLOT(killHelpDialog()));
244 helpSettingsDialog->show();
248 * This slot function called when ever dialog rejected.
250 void SettingsDialog::killHelpDialog()
252 if(helpSettingsDialog)
254 qDebug() << "__Settings kill: helpSettingsDialog";
255 delete helpSettingsDialog;
256 helpSettingsDialog = NULL;