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