accounts-qt: Accounts/provider.cpp Source File

accounts-qt 1.17

provider.cpp
1/* vi: set et sw=4 ts=4 cino=t0,(0: */
2/*
3 * This file is part of libaccounts-qt
4 *
5 * Copyright (C) 2009-2011 Nokia Corporation.
6 * Copyright (C) 2012-2016 Canonical Ltd.
7 *
8 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * version 2.1 as published by the Free Software Foundation.
13 *
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 */
24
25#include "provider.h"
26
27#undef signals
28#include <libaccounts-glib.h>
29
30
31using namespace Accounts;
32
33namespace Accounts {
44}; // namespace
45
46 Provider::Provider(AgProvider *provider, ReferenceMode mode):
47 m_provider(provider),
48 m_tags(nullptr)
49{
50 if (m_provider != nullptr && mode == AddReference)
51 ag_provider_ref(m_provider);
52}
53
57Provider::Provider():
58 m_provider(nullptr),
59 m_tags(nullptr)
60{
61}
62
67 Provider::Provider(const Provider &other):
68 m_provider(other.m_provider),
69 m_tags(nullptr)
70{
71 if (m_provider != nullptr)
72 ag_provider_ref(m_provider);
73}
74
75 Provider &Provider::operator=(const Provider &other)
76{
77 if (m_provider == other.m_provider) return *this;
78 if (m_provider != nullptr)
79 ag_provider_unref(m_provider);
80 m_provider = other.m_provider;
81 if (m_provider != nullptr)
82 ag_provider_ref(m_provider);
83 return *this;
84}
85
86Provider::~Provider()
87{
88 if (m_provider != nullptr) {
89 ag_provider_unref(m_provider);
90 m_provider = nullptr;
91 }
92 if (m_tags != nullptr) {
93 delete m_tags;
94 m_tags = nullptr;
95 }
96}
97
102 bool Provider::isValid() const
103{
104 return m_provider != nullptr;
105}
106
112QString Provider::name() const
113{
114 if (Q_UNLIKELY(!isValid())) return QString();
115 return UTF8(ag_provider_get_name(m_provider));
116}
117
122QString Provider::displayName() const
123{
124 return UTF8(ag_provider_get_display_name(m_provider));
125}
126
131QString Provider::description() const
132{
133 return UTF8(ag_provider_get_description(m_provider));
134}
135
142QString Provider::pluginName() const
143{
144 return UTF8(ag_provider_get_plugin_name(m_provider));
145}
146
151QString Provider::trCatalog() const
152{
153 return ASCII(ag_provider_get_i18n_domain(m_provider));
154}
155
159QString Provider::iconName() const
160{
161 return ASCII(ag_provider_get_icon_name(m_provider));
162}
163
168QString Provider::domainsRegExp() const
169{
170 return UTF8(ag_provider_get_domains_regex(m_provider));
171}
172
176 bool Provider::isSingleAccount() const
177{
178 return ag_provider_get_single_account(m_provider);
179}
180
188 bool Provider::hasTag(const QString &tag) const
189{
190 if (!m_tags) {
191 // Retrieve the tags
192 tags();
193 }
194
195 return m_tags->contains(tag);
196}
197
203QSet<QString> Provider::tags() const
204{
205 if (m_tags)
206 return *m_tags;
207
208 m_tags = new QSet<QString>;
209 GList *list = ag_provider_get_tags(m_provider);
210 GList *iter = list;
211 while (iter != NULL) {
212 m_tags->insert(UTF8(reinterpret_cast<const gchar *> (iter->data)));
213 iter = g_list_next(iter);
214 }
215 g_list_free(list);
216 return *m_tags;
217}
218
222 const QDomDocument Provider::domDocument() const
223{
224 const gchar *data;
225
226 ag_provider_get_file_contents(m_provider, &data);
227
228 QDomDocument doc;
229 QString errorStr;
230 int errorLine;
231 int errorColumn;
232 if (!doc.setContent(QByteArray(data), true,
233 &errorStr, &errorLine, &errorColumn))
234 {
235 QString message(QStringLiteral("Parse error reading account provider file "
236 "at line %1, column %2:\n%3"));
237 message = message.arg(errorLine).arg(errorColumn).arg(errorStr);
238 qWarning() << __PRETTY_FUNCTION__ << message;
239 }
240
241 return doc;
242}
243
244AgProvider *Provider::provider() const
245{
246 return m_provider;
247}
248
Accounts::Provider
Representation of an account provider.
Definition: provider.h:49
Accounts::Provider::Provider
Provider()
Construct an invalid provider.
Definition: provider.cpp:57
Accounts::Provider::pluginName
QString pluginName() const
Get the name of the account plugin associated with the provider.
Definition: provider.cpp:142
Accounts::Provider::tags
QSet< QString > tags() const
Return all tags of the provider as a set.
Definition: provider.cpp:203
Accounts::Provider::isSingleAccount
bool isSingleAccount() const
Definition: provider.cpp:176
Accounts::Provider::domainsRegExp
QString domainsRegExp() const
Definition: provider.cpp:168
Accounts::Provider::isValid
bool isValid() const
Check whether this object represents a Provider.
Definition: provider.cpp:102
Accounts::Provider::name
QString name() const
Get the name of the provider.
Definition: provider.cpp:112
Accounts::Provider::iconName
QString iconName() const
Definition: provider.cpp:159
Accounts::Provider::displayName
QString displayName() const
Get the display name of the provider, untranslated.
Definition: provider.cpp:122
Accounts::Provider::description
QString description() const
Get the description of the provider, untranslated.
Definition: provider.cpp:131
Accounts::Provider::hasTag
bool hasTag(const QString &tag) const
Check if this provider has a tag.
Definition: provider.cpp:188
Accounts::Provider::trCatalog
QString trCatalog() const
Definition: provider.cpp:151
Accounts::Provider::domDocument
const QDomDocument domDocument() const
Definition: provider.cpp:222