accounts-qt  0.31
provider.cpp
Go to the documentation of this file.
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-2010 Nokia Corporation.
6  *
7  * Contact: Alberto Mardegan <alberto.mardegan@nokia.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * version 2.1 as published by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  */
23 
24 #include "provider.h"
25 #include "accountscommon.h"
26 
27 #include <libaccounts-glib/ag-provider.h>
28 
29 
30 using namespace Accounts;
31 
32 Provider::Provider(AgProvider *provider)
33  : m_provider(provider)
34 {
35  TRACE();
36  ag_provider_ref(m_provider);
37 }
38 
39 Provider::~Provider()
40 {
41  TRACE();
42 
43  ag_provider_unref(m_provider);
44  m_provider = 0;
45 }
46 
47 QString Provider::name() const
48 {
49  return UTF8(ag_provider_get_name(m_provider));
50 }
51 
52 QString Provider::displayName() const
53 {
54  return UTF8(ag_provider_get_display_name(m_provider));
55 }
56 
57 const QDomDocument Provider::domDocument() const
58 {
59  if (doc.isNull())
60  {
61  const gchar *data;
62 
63  ag_provider_get_file_contents(m_provider, &data);
64 
65  QString errorStr;
66  int errorLine;
67  int errorColumn;
68  if (!doc.setContent(QByteArray(data), true,
69  &errorStr, &errorLine, &errorColumn))
70  {
71  QString message(ASCII("Parse error reading account provider file "
72  "at line %1, column %2:\n%3"));
73  message.arg(errorLine).arg(errorColumn).arg(errorStr);
74  qWarning() << __PRETTY_FUNCTION__ << message;
75  return QDomDocument();
76  }
77  }
78 
79  return doc;
80 }
81 
82 AgProvider *Provider::provider() const
83 {
84  return m_provider;
85 }
86