~ci-train-bot/online-accounts-api/online-accounts-api-ubuntu-xenial-landing-033

« back to all changes in this revision

Viewing changes to src/lib/OnlineAccounts/authentication_data.cpp

  • 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
#include "authentication_data_p.h"
 
22
 
 
23
#include <QDBusMetaType>
 
24
#include "dbus_constants.h"
 
25
 
 
26
using namespace OnlineAccounts;
 
27
 
 
28
AuthenticationDataPrivate::AuthenticationDataPrivate(AuthenticationMethod method):
 
29
    m_method(method),
 
30
    m_interactive(true),
 
31
    m_invalidateCachedReply(false)
 
32
{
 
33
}
 
34
 
 
35
AuthenticationData::AuthenticationData(AuthenticationDataPrivate *priv):
 
36
    d(priv)
 
37
{
 
38
}
 
39
 
 
40
AuthenticationData::AuthenticationData(const AuthenticationData &other):
 
41
    d(other.d)
 
42
{
 
43
}
 
44
 
 
45
AuthenticationData::~AuthenticationData()
 
46
{
 
47
}
 
48
 
 
49
AuthenticationMethod AuthenticationData::method() const
 
50
{
 
51
    return d->m_method;
 
52
}
 
53
 
 
54
void AuthenticationData::setInteractive(bool interactive)
 
55
{
 
56
    d->m_interactive = interactive;
 
57
}
 
58
 
 
59
bool AuthenticationData::interactive() const
 
60
{
 
61
    return d->m_interactive;
 
62
}
 
63
 
 
64
void AuthenticationData::invalidateCachedReply()
 
65
{
 
66
    d->m_invalidateCachedReply = true;
 
67
}
 
68
 
 
69
bool AuthenticationData::mustInvalidateCachedReply() const
 
70
{
 
71
    return d->m_invalidateCachedReply;
 
72
}
 
73
 
 
74
/* OAuth 2.0 */
 
75
 
 
76
OAuth2Data::OAuth2Data():
 
77
    AuthenticationData(new AuthenticationDataPrivate(AuthenticationMethodOAuth2))
 
78
{
 
79
    qDBusRegisterMetaType<QList<QByteArray>>();
 
80
}
 
81
 
 
82
void OAuth2Data::setClientId(const QByteArray &id)
 
83
{
 
84
    d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CLIENT_ID] = id;
 
85
}
 
86
 
 
87
QByteArray OAuth2Data::clientId() const
 
88
{
 
89
    return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CLIENT_ID].toByteArray();
 
90
}
 
91
 
 
92
void OAuth2Data::setClientSecret(const QByteArray &secret)
 
93
{
 
94
    d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CLIENT_SECRET] = secret;
 
95
}
 
96
 
 
97
QByteArray OAuth2Data::clientSecret() const
 
98
{
 
99
    return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CLIENT_SECRET].toByteArray();
 
100
}
 
101
 
 
102
void OAuth2Data::setScopes(const QList<QByteArray> &scopes)
 
103
{
 
104
    d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_SCOPES] = QVariant::fromValue(scopes);
 
105
}
 
106
 
 
107
QList<QByteArray> OAuth2Data::scopes() const
 
108
{
 
109
    return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_SCOPES].value<QList<QByteArray> >();
 
110
}
 
111
 
 
112
/* OAuth 1.0a */
 
113
 
 
114
OAuth1Data::OAuth1Data():
 
115
    AuthenticationData(new AuthenticationDataPrivate(AuthenticationMethodOAuth1))
 
116
{
 
117
}
 
118
 
 
119
void OAuth1Data::setConsumerKey(const QByteArray &key)
 
120
{
 
121
    d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_KEY] = key;
 
122
}
 
123
 
 
124
QByteArray OAuth1Data::consumerKey() const
 
125
{
 
126
    return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_KEY].toByteArray();
 
127
}
 
128
 
 
129
void OAuth1Data::setConsumerSecret(const QByteArray &secret)
 
130
{
 
131
    d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_SECRET] = secret;
 
132
}
 
133
 
 
134
QByteArray OAuth1Data::consumerSecret() const
 
135
{
 
136
    return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_SECRET].toByteArray();
 
137
}
 
138
 
 
139
/* Password */
 
140
 
 
141
PasswordData::PasswordData():
 
142
    AuthenticationData(new AuthenticationDataPrivate(AuthenticationMethodPassword))
 
143
{
 
144
}