~mardy/online-accounts-api/sasl-1519330

« back to all changes in this revision

Viewing changes to src/lib/OnlineAccounts/account_info.h

  • Committer: Alberto Mardegan
  • Date: 2015-04-28 17:01:03 UTC
  • mfrom: (5.1.30 qt-api-impl)
  • Revision ID: alberto.mardegan@canonical.com-20150428170103-9hty50555f6e7uz6
Qt client API implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of libOnlineAccounts
 
3
 *
 
4
 * Copyright (C) 2015 Canonical Ltd.
 
5
 *
 
6
 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
 
7
 *
 
8
 * This program is free software: you can redistribute it and/or modify it
 
9
 * under the terms of the GNU Lesser General Public License version 3, as
 
10
 * published by the Free Software Foundation.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
14
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
15
 * PURPOSE.  See the GNU Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public License
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
#ifndef ONLINE_ACCOUNTS_ACCOUNT_INFO_H
 
22
#define ONLINE_ACCOUNTS_ACCOUNT_INFO_H
 
23
 
 
24
#include <QVariantMap>
 
25
 
 
26
#include "dbus_constants.h"
 
27
#include "global.h"
 
28
 
 
29
class QDBusArgument;
 
30
 
 
31
namespace OnlineAccounts {
 
32
 
 
33
class AccountInfo {
 
34
public:
 
35
    enum ChangeType {
 
36
        Enabled,
 
37
        Disabled,
 
38
        Updated,
 
39
    };
 
40
    AccountInfo(): accountId(0) {}
 
41
    AccountInfo(AccountId accountId, const QVariantMap &details):
 
42
        accountId(accountId), details(details) {}
 
43
 
 
44
    AccountId id() const { return accountId; }
 
45
    QString displayName() const {
 
46
        return details.value(ONLINE_ACCOUNTS_INFO_KEY_DISPLAY_NAME).toString();
 
47
    }
 
48
    QString service() const {
 
49
        return details.value(ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID).toString();
 
50
    }
 
51
    AuthenticationMethod authenticationMethod() const {
 
52
        return AuthenticationMethod(details.value(ONLINE_ACCOUNTS_INFO_KEY_AUTH_METHOD).toInt());
 
53
    }
 
54
    ChangeType changeType() const {
 
55
        switch (details.value(ONLINE_ACCOUNTS_INFO_KEY_CHANGE_TYPE).toUInt()) {
 
56
        case ONLINE_ACCOUNTS_INFO_CHANGE_ENABLED: return Enabled;
 
57
        case ONLINE_ACCOUNTS_INFO_CHANGE_DISABLED: return Disabled;
 
58
        default: return Updated;
 
59
        }
 
60
    }
 
61
 
 
62
    QVariant setting(const QString &key) const {
 
63
        return details.value(ONLINE_ACCOUNTS_INFO_KEY_SETTINGS + key);
 
64
    }
 
65
 
 
66
    AccountInfo stripMetadata() const {
 
67
        AccountInfo stripped = *this;
 
68
        stripped.details.remove(ONLINE_ACCOUNTS_INFO_KEY_CHANGE_TYPE);
 
69
        return stripped;
 
70
    }
 
71
 
 
72
    bool operator==(const AccountInfo &other) const {
 
73
        return accountId == other.accountId && details == other.details;
 
74
    }
 
75
 
 
76
    bool operator!=(const AccountInfo &other) const {
 
77
        return !(*this == other);
 
78
    }
 
79
 
 
80
private:
 
81
    friend QDBusArgument &operator<<(QDBusArgument &, const AccountInfo &);
 
82
    friend const QDBusArgument &operator>>(const QDBusArgument &, AccountInfo &);
 
83
    AccountId accountId;
 
84
    QVariantMap details;
 
85
};
 
86
 
 
87
QDBusArgument &operator<<(QDBusArgument &argument, const AccountInfo &info);
 
88
const QDBusArgument &operator>>(const QDBusArgument &argument, AccountInfo &info);
 
89
 
 
90
} //namespace
 
91
 
 
92
Q_DECLARE_METATYPE(OnlineAccounts::AccountInfo)
 
93
 
 
94
#endif // ONLINE_ACCOUNTS_ACCOUNT_INFO_H