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>
17 * Constructor of this class
19 SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog)
23 helpSettingsDialog = NULL;
24 registerDialog = NULL;
25 this->setWindowTitle("Settings");
31 getLoginInfo( &uName, &pWord);
32 this->username = uName;
33 this->password = pWord;
36 ui->setUserPasswordLineEdit->setText(this->password);
37 ui->setUserUsernameLineEdit->setText(this->username);
38 ui->setUserPasswordLineEdit->setDisabled(1); // Disable because user logged
39 ui->setUserUsernameLineEdit->setDisabled(1); // Disable because user logged
41 // Already someone as user - change button text to "Change"
42 ui->setUserPushButton->setText("Log out");
45 ui->pushButtonProfile->setAutoFillBackground(true);
46 ui->pushButtonProfile->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
47 ui->pushButtonProfile->setDisabled(false);
48 ui->pushButtonProfile->setVisible(false);
51 ui->pushButtonInfo->setAutoFillBackground(true);
52 ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
53 ui->pushButtonProfile->setVisible(false);
57 * Destructor of this class
59 SettingsDialog::~SettingsDialog()
67 void SettingsDialog::changeEvent(QEvent *e)
69 QDialog::changeEvent(e);
71 case QEvent::LanguageChange:
72 ui->retranslateUi(this);
80 * This slot function called when ever "register new user" -button clicked.
82 void SettingsDialog::on_registratePushButton_clicked()
86 registerDialog = new RegisterDialog(this);
88 connect(registerDialog, SIGNAL(registrate()), this, SLOT(registrate()));
89 connect(registerDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
90 registerDialog->show();
96 void SettingsDialog::on_setUserPushButton_clicked()
98 if (!ui->setUserPushButton->text().compare("Log out"))
100 ui->setUserUsernameLineEdit->setDisabled(false);
101 ui->setUserPasswordLineEdit->setDisabled(false);
102 //ui->setUserUsernameLineEdit->setText("");
103 //ui->setUserPasswordLineEdit->setText("");
104 ui->setUserUsernameLineEdit->clear();
105 ui->setUserPasswordLineEdit->clear();
106 this->username = ui->setUserUsernameLineEdit->text();
107 this->password = ui->setUserPasswordLineEdit->text();
108 ui->setUserPushButton->setText("Log in");
109 saveLogin( this->username, this->password);
110 ui->pushButtonProfile->setDisabled(true);
115 this->username = ui->setUserUsernameLineEdit->text();
116 this->password = ui->setUserPasswordLineEdit->text();
117 saveLogin( this->username, this->password);
118 ui->setUserPushButton->setText("Log out");
120 if(this->username.compare(""))
122 emit userNameChanged();
123 //ui->setUserPushButton->setText("Log out");
128 QMessageBox::about(this, "Username field is empty", "Set username and log in again");
129 ui->setUserPushButton->setText("Log in");
132 // Save these also to usersettings
133 //saveLogin( this->username, this->password);
136 // Set "Set/Change User" button text
137 if (this->username.length() > 0)
139 ui->setUserPushButton->setText("Log out");
142 { // Username "cleared"
143 ui->setUserPushButton->setText("Log in");
146 emit userNameChanged();
148 //close(); //using close() hides popup-window which reports error from server
151 // Next 4 functions can be removed if Settingsdialog is implemented without
152 // own copy of username & password
156 void SettingsDialog::setUserName(QString username)
158 this->username = username;
164 void SettingsDialog::setPassword(QString password)
166 this->password = password;
172 QString SettingsDialog::getUserName()
174 return this->username;
180 QString SettingsDialog::getPassword()
182 return this->password;
188 void SettingsDialog::setLabelInfoToUser(QString infoText)
190 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);
203 ui->pushButtonProfile->setDisabled(false);
208 ui->setUserPushButton->setText("Log in");
209 ui->setUserPasswordLineEdit->clear();
212 saveLogin( this->username, this->password);
213 ui->pushButtonProfile->setDisabled(true);
218 * This slot function called when ever info button clicked.
220 void SettingsDialog::on_pushButtonInfo_clicked()
222 if(!helpSettingsDialog)
224 helpSettingsDialog = new HelpSettingsDialog;
226 connect(helpSettingsDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
227 helpSettingsDialog->show();
231 * This slot function called when ever dialog rejected.
233 void SettingsDialog::killDialog()
235 if(helpSettingsDialog)
237 qDebug() << "__Settings kill: helpSettingsDialog";
238 delete helpSettingsDialog;
239 helpSettingsDialog = NULL;
243 qDebug() << "__Settings kill: registerDialog";
244 delete registerDialog;
245 registerDialog = NULL;
250 * This slot function called when
252 void SettingsDialog::registrate()
254 emit sendregistration();