accounts-qt  0.31
service.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 "account.h"
25 #include "manager.h"
26 
27 #include <libaccounts-glib/ag-manager.h>
28 #include <libaccounts-glib/ag-account.h>
29 #include <libaccounts-glib/ag-service.h>
30 #include <QtDebug>
31 
32 
33 using namespace Accounts;
34 
35 Service::Service(AgService *service)
36  : m_service(service)
37 {
38  TRACE();
39  ag_service_ref(m_service);
40 }
41 
42 Service::~Service()
43 {
44  TRACE();
45 
46  ag_service_unref(m_service);
47  m_service = 0;
48 }
49 
50 QString Service::name() const
51 {
52  return UTF8(ag_service_get_name(m_service));
53 }
54 
55 QString Service::displayName() const
56 {
57  return UTF8(ag_service_get_display_name(m_service));
58 }
59 
60 QString Service::serviceType() const
61 {
62  return ASCII(ag_service_get_service_type(m_service));
63 }
64 
65 QString Service::provider() const
66 {
67  return UTF8(ag_service_get_provider(m_service));
68 }
69 
70 QString Service::iconName() const
71 {
72  return ASCII(ag_service_get_icon_name(m_service));
73 }
74 
75 QXmlStreamReader *Service::xmlStreamReader() const
76 {
77  const gchar *data;
78  gsize offset;
79 
80  ag_service_get_file_contents(m_service, &data, &offset);
81  if (data)
82  data += offset;
83 
84  QXmlStreamReader *reader = new QXmlStreamReader(QByteArray(data));
85 
86  /* Read the startDocument token */
87  if (reader->readNext() != QXmlStreamReader::StartDocument)
88  {
89  delete reader;
90  return NULL;
91  }
92 
93  return reader;
94 }
95 
96 const QDomDocument Service::domDocument() const
97 {
98  if (doc.isNull())
99  {
100  const gchar *data;
101 
102  ag_service_get_file_contents(m_service, &data, NULL);
103 
104  QString errorStr;
105  int errorLine;
106  int errorColumn;
107  if (!doc.setContent(QByteArray(data), true,
108  &errorStr, &errorLine, &errorColumn))
109  {
110  QString message(ASCII("Parse error reading account service file "
111  "at line %1, column %2:\n%3"));
112  message.arg(errorLine).arg(errorColumn).arg(errorStr);
113  qWarning() << __PRETTY_FUNCTION__ << message;
114  return QDomDocument();
115  }
116  }
117 
118  return doc;
119 }
120 
121 AgService *Service::service() const
122 {
123  return m_service;
124 }
125