source: SMSSender/lib/libdatatypes/src/abstract/abstractloginaccount.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: 2.0 KB
Line 
1#include "abstractloginaccount.h"
2
3QString const LoginAccount::Status::Login  = QObject::tr("Logging in");
4QString const LoginAccount::Status::Logout = QObject::tr("Logging out");
5
6AbstractLoginAccount::AbstractLoginAccount(IStorageOfficer* storageOfficer, IValidator* validator)
7    : AbstractAccount(storageOfficer, validator)
8
9    , username_("")
10    , password_("")
11
12    , loggedIn_(false)
13{
14    eventMapper_ = new SLoginAccountEventMapper(this);
15}
16
17SLoginAccountEventMapper* AbstractLoginAccount::eventMapper() const {
18    return eventMapper_;
19}
20ILoginAccountEvents* AbstractLoginAccount::accountEvents() const {
21    return static_cast<ILoginAccountEvents*>(eventMapper());
22}
23
24
25QString AbstractLoginAccount::username() const {
26    return username_;
27}
28
29void AbstractLoginAccount::setUsername(const QString& username){
30    SET_IF_DIFFERENT(username_, username.trimmed());
31    emit accountEvents()->dataChanged();
32}
33
34QString AbstractLoginAccount::password() const {
35    return password_;
36}
37
38void AbstractLoginAccount::setPassword(const QString& password) {
39    SET_IF_DIFFERENT(password_, password);
40    emit accountEvents()->dataChanged();
41}
42
43
44
45void AbstractLoginAccount::setLoggedIn(bool newLoggedIn) {
46    SET_IF_DIFFERENT(loggedIn_, newLoggedIn);
47    (loggedIn_) ? emit accountEvents()->loggedIn() : emit accountEvents()->loggedOut();
48}
49
50bool AbstractLoginAccount::isLoggedIn() {
51    return loggedIn_;
52}
53
54void AbstractLoginAccount::login() {
55    // If the account has been uninitialized, all saved sessions have to be cleared
56    if (!isInitialized())
57        logout(true);
58
59    if (isLoggedIn()) {
60        if (stillLoggedIn()) {
61            return;
62        } else {
63            logout(true);
64        }
65    }
66
67    doLogin();
68    setLoggedIn(true);
69}
70
71void AbstractLoginAccount::logout(bool FORCE /* = false */) {
72    if ((!gateway()->stayLoggedIn() || FORCE) && isLoggedIn()) {
73        try {
74            doLogout();
75            setLoggedIn(false);
76        } catch (...) {
77            setLoggedIn(false);
78            throw;
79        }
80    }
81}
Note: See TracBrowser for help on using the repository browser.