accounts-qt  1.2
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 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  TRACE();
50  if (m_provider != 0 && mode == AddReference)
51  ag_provider_ref(m_provider);
52 }
53 
58  m_provider(0)
59 {
60 }
61 
67  m_provider(other.m_provider)
68 {
69  if (m_provider != 0)
70  ag_provider_ref(m_provider);
71 }
72 
73 Provider &Provider::operator=(const Provider &other)
74 {
75  if (m_provider == other.m_provider) return *this;
76  if (m_provider != 0)
77  ag_provider_unref(m_provider);
78  m_provider = other.m_provider;
79  if (m_provider != 0)
80  ag_provider_ref(m_provider);
81  return *this;
82 }
83 
84 Provider::~Provider()
85 {
86  TRACE();
87 
88  ag_provider_unref(m_provider);
89  m_provider = 0;
90 }
91 
96 bool Provider::isValid() const
97 {
98  return m_provider != 0;
99 }
100 
106 QString Provider::name() const
107 {
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::trCatalog() const
125 {
126  return ASCII(ag_provider_get_i18n_domain(m_provider));
127 }
128 
132 QString Provider::iconName() const
133 {
134  return ASCII(ag_provider_get_icon_name(m_provider));
135 }
136 
140 const QDomDocument Provider::domDocument() const
141 {
142  const gchar *data;
143 
144  ag_provider_get_file_contents(m_provider, &data);
145 
146  QDomDocument doc;
147  QString errorStr;
148  int errorLine;
149  int errorColumn;
150  if (!doc.setContent(QByteArray(data), true,
151  &errorStr, &errorLine, &errorColumn))
152  {
153  QString message(ASCII("Parse error reading account provider file "
154  "at line %1, column %2:\n%3"));
155  message.arg(errorLine).arg(errorColumn).arg(errorStr);
156  qWarning() << __PRETTY_FUNCTION__ << message;
157  }
158 
159  return doc;
160 }
161 
162 AgProvider *Provider::provider() const
163 {
164  return m_provider;
165 }
166