accounts-qt  1.14
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-2014 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 #if QT_VERSION < QT_VERSION_CHECK(5 ,0 ,0)
31 #define QStringLiteral QString::fromUtf8
32 #endif
33 
34 using namespace Accounts;
35 
36 namespace Accounts {
47 }; // namespace
48 
49 Provider::Provider(AgProvider *provider, ReferenceMode mode):
50  m_provider(provider)
51 {
52  if (m_provider != 0 && mode == AddReference)
53  ag_provider_ref(m_provider);
54 }
55 
60  m_provider(0)
61 {
62 }
63 
69  m_provider(other.m_provider)
70 {
71  if (m_provider != 0)
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 != 0)
79  ag_provider_unref(m_provider);
80  m_provider = other.m_provider;
81  if (m_provider != 0)
82  ag_provider_ref(m_provider);
83  return *this;
84 }
85 
86 Provider::~Provider()
87 {
88  if (m_provider != 0) {
89  ag_provider_unref(m_provider);
90  m_provider = 0;
91  }
92 }
93 
98 bool Provider::isValid() const
99 {
100  return m_provider != 0;
101 }
102 
108 QString Provider::name() const
109 {
110  if (Q_UNLIKELY(!isValid())) return QString();
111  return UTF8(ag_provider_get_name(m_provider));
112 }
113 
118 QString Provider::displayName() const
119 {
120  return UTF8(ag_provider_get_display_name(m_provider));
121 }
122 
127 QString Provider::description() const
128 {
129  return UTF8(ag_provider_get_description(m_provider));
130 }
131 
138 QString Provider::pluginName() const
139 {
140  return UTF8(ag_provider_get_plugin_name(m_provider));
141 }
142 
147 QString Provider::trCatalog() const
148 {
149  return ASCII(ag_provider_get_i18n_domain(m_provider));
150 }
151 
155 QString Provider::iconName() const
156 {
157  return ASCII(ag_provider_get_icon_name(m_provider));
158 }
159 
164 QString Provider::domainsRegExp() const
165 {
166  return UTF8(ag_provider_get_domains_regex(m_provider));
167 }
168 
173 {
174  return ag_provider_get_single_account(m_provider);
175 }
176 
180 const QDomDocument Provider::domDocument() const
181 {
182  const gchar *data;
183 
184  ag_provider_get_file_contents(m_provider, &data);
185 
186  QDomDocument doc;
187  QString errorStr;
188  int errorLine;
189  int errorColumn;
190  if (!doc.setContent(QByteArray(data), true,
191  &errorStr, &errorLine, &errorColumn))
192  {
193  QString message(QStringLiteral("Parse error reading account provider file "
194  "at line %1, column %2:\n%3"));
195  message = message.arg(errorLine).arg(errorColumn).arg(errorStr);
196  qWarning() << __PRETTY_FUNCTION__ << message;
197  }
198 
199  return doc;
200 }
201 
202 AgProvider *Provider::provider() const
203 {
204  return m_provider;
205 }
206 
bool isValid() const
Check whether this object represents a Provider.
Definition: provider.cpp:98
const QDomDocument domDocument() const
Definition: provider.cpp:180
QString pluginName() const
Get the name of the account plugin associated with the provider.
Definition: provider.cpp:138
Representation of an account provider.
Definition: provider.h:48
QString domainsRegExp() const
Definition: provider.cpp:164
QString description() const
Get the description of the provider, untranslated.
Definition: provider.cpp:127
QString iconName() const
Definition: provider.cpp:155
QString trCatalog() const
Definition: provider.cpp:147
Provider()
Construct an invalid provider.
Definition: provider.cpp:59
QString name() const
Get the name of the provider.
Definition: provider.cpp:108
bool isSingleAccount() const
Definition: provider.cpp:172
QString displayName() const
Get the display name of the provider, untranslated.
Definition: provider.cpp:118