Branch data Line data Source code
1 : : /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 : : /*
3 : : * This file is part of libaccounts-qt
4 : : *
5 : : * Copyright (C) 2012 Canonical Ltd.
6 : : *
7 : : * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
8 : : *
9 : : * This library is free software; you can redistribute it and/or
10 : : * modify it under the terms of the GNU Lesser General Public License
11 : : * version 2.1 as published by the Free Software Foundation.
12 : : *
13 : : * This library is distributed in the hope that it will be useful, but
14 : : * WITHOUT ANY WARRANTY; without even the implied warranty of
15 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : : * Lesser General Public License for more details.
17 : : *
18 : : * You should have received a copy of the GNU Lesser General Public
19 : : * License along with this library; if not, write to the Free Software
20 : : * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 : : * 02110-1301 USA
22 : : */
23 : :
24 : : #include "auth-data.h"
25 : : #include "utils.h"
26 : :
27 : : #undef signals
28 : : #include <libaccounts-glib/ag-auth-data.h>
29 : : #include <QtDebug>
30 : : #include <QtGlobal>
31 : :
32 : :
33 : : using namespace Accounts;
34 : :
35 : : namespace Accounts {
36 : : /*!
37 : : * @class AuthData
38 : : * @headerfile auth-data.h Accounts/AuthData
39 : : *
40 : : * @brief Information for account authentication.
41 : : *
42 : : * @details The AuthData class holds information on the authentication
43 : : * parameters used by an account. It is an implicitly shared object which can
44 : : * be created with the AccountService::authData method.
45 : : */
46 : : }; // namespace
47 : :
48 : 1 : AuthData::AuthData(AgAuthData *authData):
49 : 1 : m_authData(ag_auth_data_ref(authData))
50 : : {
51 : 1 : }
52 : :
53 : : /*!
54 : : * Copy constructor. Copying an AuthData object is very cheap, because the data
55 : : * is shared among copies.
56 : : */
57 : 0 : AuthData::AuthData(const AuthData &other):
58 : 0 : m_authData(ag_auth_data_ref(other.m_authData))
59 : : {
60 : 0 : }
61 : :
62 : : /*!
63 : : * Destructor.
64 : : */
65 : 1 : AuthData::~AuthData()
66 : : {
67 : 1 : ag_auth_data_unref(m_authData);
68 : 1 : m_authData = 0;
69 : 1 : }
70 : :
71 : : /*!
72 : : * @return The ID of the credentials associated with this account.
73 : : */
74 : 1 : uint AuthData::credentialsId() const
75 : : {
76 : 1 : return ag_auth_data_get_credentials_id(m_authData);
77 : : }
78 : :
79 : : /*!
80 : : * Get the authentication method which must be used when logging in with this
81 : : * account.
82 : : * @return The authentication method.
83 : : */
84 : 1 : QString AuthData::method() const
85 : : {
86 : 1 : return UTF8(ag_auth_data_get_method(m_authData));
87 : : }
88 : :
89 : : /*!
90 : : * Get the authentication mechanism which must be used when logging in with
91 : : * this account.
92 : : * @return The authentication mechanism.
93 : : */
94 : 1 : QString AuthData::mechanism() const
95 : : {
96 : 1 : return UTF8(ag_auth_data_get_mechanism(m_authData));
97 : : }
98 : :
99 : : /*!
100 : : * Get the dictionary of authentication parameters which must be used when
101 : : * logging in with this account.
102 : : * @return The authentication parameters.
103 : : */
104 : 1 : QVariantMap AuthData::parameters() const
105 : : {
106 : : QVariantMap params;
107 : : GHashTable *glib_parameters;
108 : : GHashTableIter iter;
109 : : const gchar *key;
110 : : const GValue *value;
111 : :
112 : 1 : glib_parameters = ag_auth_data_get_parameters(m_authData);
113 [ + - ]: 1 : if (glib_parameters == 0) return params;
114 : :
115 : 1 : g_hash_table_iter_init(&iter, glib_parameters);
116 [ + + ]: 5 : while (g_hash_table_iter_next(&iter, (gpointer*)&key, (gpointer*)&value)) {
117 : 4 : params.insert(UTF8(key), gvalueToVariant(value));
118 : : }
119 : : return params;
120 : : }
|