1 | #include "vcsettingswidget.h" |
---|
2 | |
---|
3 | #include <QString> |
---|
4 | #include <QMessageBox> |
---|
5 | |
---|
6 | #include <StdExceptions.h> |
---|
7 | |
---|
8 | #include "../business/BCAccount.h" |
---|
9 | |
---|
10 | namespace SwisscomXtraZone { |
---|
11 | |
---|
12 | VCSettingsWidget::VCSettingsWidget(QWidget* parent /* = 0 */) |
---|
13 | : IAccountSettingsWidget(parent) |
---|
14 | { |
---|
15 | ui.setupUi(this); |
---|
16 | } |
---|
17 | |
---|
18 | |
---|
19 | void VCSettingsWidget::loadFromAccount(IAccount* account) { |
---|
20 | BCAccount* account_; |
---|
21 | try { |
---|
22 | account_ = dynamic_cast<BCAccount*>(account); |
---|
23 | } catch (...) { |
---|
24 | throw new EException("Invalid account given!"); |
---|
25 | } |
---|
26 | |
---|
27 | ui.edtUsername->setText(account_->username()); |
---|
28 | ui.edtPassword->setText(account_->password()); |
---|
29 | } |
---|
30 | |
---|
31 | void VCSettingsWidget::saveToAccount(IAccount* account) { |
---|
32 | BCAccount* account_; |
---|
33 | try { |
---|
34 | // TODO: this gives no error... |
---|
35 | account_ = dynamic_cast<BCAccount*>(account); |
---|
36 | } catch (...) { |
---|
37 | throw new EException("Invalid account given!"); |
---|
38 | } |
---|
39 | |
---|
40 | account_->setUsername(ui.edtUsername->text()); |
---|
41 | account_->setPassword(ui.edtPassword->text()); |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | bool VCSettingsWidget::validate() { |
---|
46 | QString errorMsg = ""; |
---|
47 | |
---|
48 | QString username = ui.edtUsername->text().remove(QChar(' ')); |
---|
49 | QString password = ui.edtPassword->text(); |
---|
50 | |
---|
51 | if (username.contains(QRegExp("[^\\d]")) || (username.length() != 10)) { |
---|
52 | errorMsg += tr("The mobile number should be of the form 0791234567.") + "\n"; |
---|
53 | } |
---|
54 | |
---|
55 | if (password.isEmpty()) { |
---|
56 | errorMsg += tr("Your password can't be empty.") + "\n"; |
---|
57 | } |
---|
58 | |
---|
59 | errorMsg.chop(1); // Remove last "\n" |
---|
60 | |
---|
61 | if (errorMsg != "") { |
---|
62 | QMessageBox::warning(this, tr("Swisscom Xtra Zone Account"), errorMsg, QMessageBox::Ok, QMessageBox::Ok); |
---|
63 | } |
---|
64 | return errorMsg == ""; |
---|
65 | } |
---|
66 | |
---|
67 | } |
---|