File: auth-data.cpp

package info (click to toggle)
libaccounts-qt 1.13%2B20150813-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 604 kB
  • ctags: 388
  • sloc: cpp: 3,291; xml: 75; makefile: 36; sh: 14
file content (116 lines) | stat: -rw-r--r-- 2,992 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* vi: set et sw=4 ts=4 cino=t0,(0: */
/*
 * This file is part of libaccounts-qt
 *
 * Copyright (C) 2012 Canonical Ltd.
 *
 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

#include "auth-data.h"
#include "utils.h"

#undef signals
#include <libaccounts-glib/ag-auth-data.h>
#include <QtDebug>
#include <QtGlobal>


using namespace Accounts;

namespace Accounts {
/*!
 * @class AuthData
 * @headerfile auth-data.h Accounts/AuthData
 *
 * @brief Information for account authentication.
 *
 * @details The AuthData class holds information on the authentication
 * parameters used by an account. It is an implicitly shared object which can
 * be created with the AccountService::authData method.
 */
}; // namespace

AuthData::AuthData(AgAuthData *authData):
    m_authData(ag_auth_data_ref(authData))
{
}

/*!
 * Copy constructor. Copying an AuthData object is very cheap, because the data
 * is shared among copies.
 */
AuthData::AuthData(const AuthData &other):
    m_authData(ag_auth_data_ref(other.m_authData))
{
}

/*!
 * Destructor.
 */
AuthData::~AuthData()
{
    ag_auth_data_unref(m_authData);
    m_authData = 0;
}

/*!
 * @return The ID of the credentials associated with this account.
 */
uint AuthData::credentialsId() const
{
    return ag_auth_data_get_credentials_id(m_authData);
}

/*!
 * Get the authentication method which must be used when logging in with this
 * account.
 * @return The authentication method.
 */
QString AuthData::method() const
{
    return UTF8(ag_auth_data_get_method(m_authData));
}

/*!
 * Get the authentication mechanism which must be used when logging in with
 * this account.
 * @return The authentication mechanism.
 */
QString AuthData::mechanism() const
{
    return UTF8(ag_auth_data_get_mechanism(m_authData));
}

/*!
 * Get the dictionary of authentication parameters which must be used when
 * logging in with this account.
 * @return The authentication parameters.
 */
QVariantMap AuthData::parameters() const
{
    GVariant *glibParameters;

    glibParameters = ag_auth_data_get_login_parameters(m_authData, NULL);
    if (glibParameters == 0) return QVariantMap();

    QVariant variant = gVariantToQVariant(glibParameters);
    g_variant_unref(glibParameters);
    if (!variant.isValid()) return QVariantMap();

    return variant.toMap();
}