accounts-qt  1.16
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/ag-provider.h>
29 
30 
31 using namespace Accounts;
32 
33 namespace Accounts {
44 }; // namespace
45 
46 Provider::Provider(AgProvider *provider, ReferenceMode mode):
47  m_provider(provider)
48 {
49  if (m_provider != nullptr && mode == AddReference)
50  ag_provider_ref(m_provider);
51 }
52 
57  m_provider(nullptr)
58 {
59 }
60 
66  m_provider(other.m_provider)
67 {
68  if (m_provider != nullptr)
69  ag_provider_ref(m_provider);
70 }
71 
72 Provider &Provider::operator=(const Provider &other)
73 {
74  if (m_provider == other.m_provider) return *this;
75  if (m_provider != nullptr)
76  ag_provider_unref(m_provider);
77  m_provider = other.m_provider;
78  if (m_provider != nullptr)
79  ag_provider_ref(m_provider);
80  return *this;
81 }
82 
83 Provider::~Provider()
84 {
85  if (m_provider != nullptr) {
86  ag_provider_unref(m_provider);
87  m_provider = nullptr;
88  }
89 }
90 
95 bool Provider::isValid() const
96 {
97  return m_provider != nullptr;
98 }
99 
105 QString Provider::name() const
106 {
107  if (Q_UNLIKELY(!isValid())) return QString();
108  return UTF8(ag_provider_get_name(m_provider));
109 }
110 
115 QString Provider::displayName() const
116 {
117  return UTF8(ag_provider_get_display_name(m_provider));
118 }
119 
124 QString Provider::description() const
125 {
126  return UTF8(ag_provider_get_description(m_provider));
127 }
128 
135 QString Provider::pluginName() const
136 {
137  return UTF8(ag_provider_get_plugin_name(m_provider));
138 }
139 
144 QString Provider::trCatalog() const
145 {
146  return ASCII(ag_provider_get_i18n_domain(m_provider));
147 }
148 
152 QString Provider::iconName() const
153 {
154  return ASCII(ag_provider_get_icon_name(m_provider));
155 }
156 
161 QString Provider::domainsRegExp() const
162 {
163  return UTF8(ag_provider_get_domains_regex(m_provider));
164 }
165 
170 {
171  return ag_provider_get_single_account(m_provider);
172 }
173 
177 const QDomDocument Provider::domDocument() const
178 {
179  const gchar *data;
180 
181  ag_provider_get_file_contents(m_provider, &data);
182 
183  QDomDocument doc;
184  QString errorStr;
185  int errorLine;
186  int errorColumn;
187  if (!doc.setContent(QByteArray(data), true,
188  &errorStr, &errorLine, &errorColumn))
189  {
190  QString message(QStringLiteral("Parse error reading account provider file "
191  "at line %1, column %2:\n%3"));
192  message = message.arg(errorLine).arg(errorColumn).arg(errorStr);
193  qWarning() << __PRETTY_FUNCTION__ << message;
194  }
195 
196  return doc;
197 }
198 
199 AgProvider *Provider::provider() const
200 {
201  return m_provider;
202 }
203 
Accounts::Provider::isValid
bool isValid() const
Check whether this object represents a Provider.
Definition: provider.cpp:95
Accounts::Provider::domainsRegExp
QString domainsRegExp() const
Definition: provider.cpp:161
Accounts::Provider::isSingleAccount
bool isSingleAccount() const
Definition: provider.cpp:169
Accounts::Provider::description
QString description() const
Get the description of the provider, untranslated.
Definition: provider.cpp:124
Accounts::Provider::trCatalog
QString trCatalog() const
Definition: provider.cpp:144
Accounts::Provider::Provider
Provider()
Construct an invalid provider.
Definition: provider.cpp:56
Accounts::Provider::name
QString name() const
Get the name of the provider.
Definition: provider.cpp:105
Accounts::Provider
Representation of an account provider.
Definition: provider.h:49
Accounts::Provider::displayName
QString displayName() const
Get the display name of the provider, untranslated.
Definition: provider.cpp:115
Accounts::Provider::domDocument
const QDomDocument domDocument() const
Definition: provider.cpp:177
Accounts::Provider::iconName
QString iconName() const
Definition: provider.cpp:152
Accounts::Provider::pluginName
QString pluginName() const
Get the name of the account plugin associated with the provider.
Definition: provider.cpp:135