Bugfix: accelerate send result.
[speedfreak] / Client / settingsdialog.cpp
1 /*
2  * SettingsDialog class
3  *
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
7  */
8
9 #include "settingsdialog.h"
10 #include "ui_settingsdialog.h"
11 #include "usersettings.h"
12
13 SettingsDialog::SettingsDialog(QWidget *parent) :
14     QDialog(parent),
15     ui(new Ui::SettingsDialog)
16 {
17     ui->setupUi(this);
18     this->setWindowTitle("Settings");
19     this->ui->regEMailLineEdit->setText("@");
20     instructionsDialog = new InstructionsDialog;
21
22     if (loginSaved())
23     {
24         QString uName, pWord;
25
26         getLoginInfo( &uName, &pWord);
27         this->username = uName;
28         this->password = pWord;
29
30         ui->setUserPasswordLineEdit->setText(this->password);
31         ui->setUserUsernameLineEdit->setText(this->username);
32
33         // Already someone as user - change button text to "Change"
34         ui->setUserPushButton->setText("Change user");
35     }
36 }
37
38 SettingsDialog::~SettingsDialog()
39 {
40     delete ui;
41 }
42
43 void SettingsDialog::changeEvent(QEvent *e)
44 {
45     QDialog::changeEvent(e);
46     switch (e->type()) {
47     case QEvent::LanguageChange:
48         ui->retranslateUi(this);
49         break;
50     default:
51         break;
52     }
53 }
54
55 //
56 // Help
57 //
58 void SettingsDialog::on_pushButtonHelp_clicked()
59 {
60     instructionsDialog->show();
61 }
62
63 //
64 // Registrate
65 //
66 void SettingsDialog::on_registratePushButton_clicked()
67 {
68     // Send username, password and email to SpeedFreak server
69     this->regUsername = ui->regUserNameLineEdit->text();
70     this->regPassword = ui->regPasswordLineEdit->text();
71     this->regEmail = ui->regEMailLineEdit->text();
72
73     emit sendregistration();
74
75     //close();      //using close() hides popup-window which reports error from server
76 }
77
78 // Next 6 functions can be removed if Settingsdialog is implemented without
79 // own copy of username, password & email
80 void SettingsDialog::setRegUserName(QString username)
81 {
82     this->regUsername = username;
83 }
84
85 void SettingsDialog::setRegPassword(QString password)
86 {
87     this->regPassword = password;
88 }
89
90 void SettingsDialog::setRegEmail(QString email)
91 {
92     this->regEmail = email;
93 }
94
95 QString SettingsDialog::getRegUserName()
96 {
97     return this->regUsername;
98 }
99
100 QString SettingsDialog::getRegPassword()
101 {
102     return this->regPassword;
103 }
104
105 QString SettingsDialog::getRegEmail()
106 {
107     return this->regEmail;
108 }
109
110 //
111 // Set / Change user
112 //
113 void SettingsDialog::on_setUserPushButton_clicked()
114 {
115     this->username = ui->setUserUsernameLineEdit->text();
116     this->password = ui->setUserPasswordLineEdit->text();
117
118     // Save these also to usersettings
119     saveLogin( this->username, this->password);
120
121     // Set "Set/Change User" button text
122     if (this->username.length() > 0)
123     {
124         ui->setUserPushButton->setText("Change user");
125     }
126     else
127     {   // Username "cleared"
128         ui->setUserPushButton->setText("Set user");
129     }
130
131     emit userNameChanged();
132
133     //close();  //using close() hides popup-window which reports error from server
134 }
135
136 // Next 4 functions can be removed if Settingsdialog is implemented without
137 // own copy of username & password
138 void SettingsDialog::setUserName(QString username)
139 {
140     this->username = username;
141 }
142
143 void SettingsDialog::setPassword(QString password)
144 {
145     this->password = password;
146 }
147
148 QString SettingsDialog::getUserName()
149 {
150     return this->username;
151 }
152
153 QString SettingsDialog::getPassword()
154 {
155     return this->password;
156 }
157
158 void SettingsDialog::setLabelInfoToUser(QString infoText)
159 {
160     this->ui->labelInfoToUser->setText(infoText);
161 }