source: SMSSender/gateways/SwisscomXtraZone/src/ui/vcsettingswidget.cpp @ 71:415b45c71663

3.0
Last change on this file since 71:415b45c71663 was 71:415b45c71663, checked in by Sämy Zehnder <saemy.zehnder@…>, 12 years ago
  • Reorganized all the libraries. libinterfaces and libgateways are removed now and libdatatypes contains now all these files.
File size: 1.6 KB
Line 
1#include "vcsettingswidget.h"
2
3#include <QString>
4#include <QMessageBox>
5
6#include <stdexceptions.h>
7
8#include "business/BCAccount.h"
9
10namespace SwisscomXtraZone {
11
12VCSettingsWidget::VCSettingsWidget(QWidget* parent /* = 0 */)
13    : IAccountSettingsWidget(parent)
14{
15    ui.setupUi(this);
16}
17
18
19void 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
31void 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
45bool 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}
Note: See TracBrowser for help on using the repository browser.