File: provider.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 (203 lines) | stat: -rw-r--r-- 5,083 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* vi: set et sw=4 ts=4 cino=t0,(0: */
/*
 * This file is part of libaccounts-qt
 *
 * Copyright (C) 2009-2011 Nokia Corporation.
 * Copyright (C) 2012-2014 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 "provider.h"

#undef signals
#include <libaccounts-glib/ag-provider.h>


using namespace Accounts;

namespace Accounts {
/*!
 * @class Provider
 * @headerfile provider.h Accounts/Provider
 *
 * @brief Representation of an account provider.
 *
 * @details The Provider object represents an account provider. It can be used
 * to retrieve some basic properties of the provider (such as the name) and to
 * get access to the contents of the XML file which defines it.
 */
}; // namespace

Provider::Provider(AgProvider *provider, ReferenceMode mode):
    m_provider(provider)
{
    if (m_provider != 0 && mode == AddReference)
        ag_provider_ref(m_provider);
}

/*!
 * Construct an invalid provider.
 */
Provider::Provider():
    m_provider(0)
{
}

/*!
 * Copy constructor. Copying a Provider object is very cheap, because the
 * data is shared among copies.
 */
Provider::Provider(const Provider &other):
    m_provider(other.m_provider)
{
    if (m_provider != 0)
        ag_provider_ref(m_provider);
}

Provider &Provider::operator=(const Provider &other)
{
    if (m_provider == other.m_provider) return *this;
    if (m_provider != 0)
        ag_provider_unref(m_provider);
    m_provider = other.m_provider;
    if (m_provider != 0)
        ag_provider_ref(m_provider);
    return *this;
}

Provider::~Provider()
{
    if (m_provider != 0) {
        ag_provider_unref(m_provider);
        m_provider = 0;
    }
}

/*!
 * Check whether this object represents a Provider.
 * @return true if the Provider is a valid one.
 */
bool Provider::isValid() const
{
    return m_provider != 0;
}

/*!
 * Get the name of the provider. This can be used as a unique identifier for
 * this provider.
 * @return The unique name of the provider.
 */
QString Provider::name() const
{
    if (Q_UNLIKELY(!isValid())) return QString();
    return UTF8(ag_provider_get_name(m_provider));
}

/*!
 * Get the display name of the provider, untranslated.
 * @return The display name of the provider.
 */
QString Provider::displayName() const
{
    return UTF8(ag_provider_get_display_name(m_provider));
}

/*!
 * Get the description of the provider, untranslated.
 * @return The description of the provider.
 */
QString Provider::description() const
{
    return UTF8(ag_provider_get_description(m_provider));
}

/*!
 * Get the name of the account plugin associated with the provider.
 * Some platforms might find it useful to store plugin names in the provider
 * XML files, especially when the same plugin can work for different providers.
 * @return The plugin name.
 */
QString Provider::pluginName() const
{
    return UTF8(ag_provider_get_plugin_name(m_provider));
}

/*!
 * @return The name of the translation catalog, which can be used to
 * translate the displayName().
 */
QString Provider::trCatalog() const
{
    return ASCII(ag_provider_get_i18n_domain(m_provider));
}

/*!
 * @return The provider icon name.
 */
QString Provider::iconName() const
{
    return ASCII(ag_provider_get_icon_name(m_provider));
}

/*!
 * @return A regular expression pattern which matches all the internet domains
 * in which this type of account can be used.
 */
QString Provider::domainsRegExp() const
{
    return UTF8(ag_provider_get_domains_regex(m_provider));
}

/*!
 * @return Whether the provider supports creating one account at most.
 */
bool Provider::isSingleAccount() const
{
    return ag_provider_get_single_account(m_provider);
}

/*!
 * @return The DOM of the whole XML provider file.
 */
const QDomDocument Provider::domDocument() const
{
    const gchar *data;

    ag_provider_get_file_contents(m_provider, &data);

    QDomDocument doc;
    QString errorStr;
    int errorLine;
    int errorColumn;
    if (!doc.setContent(QByteArray(data), true,
                        &errorStr, &errorLine, &errorColumn))
    {
        QString message(ASCII("Parse error reading account provider file "
                              "at line %1, column %2:\n%3"));
        message.arg(errorLine).arg(errorColumn).arg(errorStr);
        qWarning() << __PRETTY_FUNCTION__ << message;
    }

    return doc;
}

AgProvider *Provider::provider() const
{
    return m_provider;
}