accounts-qt  0.31
service-type.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 "service-type.h"
25 
26 #include <libaccounts-glib/ag-manager.h>
27 #include <libaccounts-glib/ag-service-type.h>
28 #include "manager.h"
29 #include <QtDebug>
30 #include <QtGlobal>
31 
32 
33 using namespace Accounts;
34 
35 ServiceType::ServiceType(AgServiceType *serviceType)
36  : m_serviceType(serviceType)
37 {
38  TRACE();
39  ag_service_type_ref(m_serviceType);
40 }
41 
42 ServiceType::~ServiceType()
43 {
44  TRACE();
45  ag_service_type_unref(m_serviceType);
46  m_serviceType = 0;
47 }
48 
49 QString ServiceType::name() const
50 {
51  return UTF8(ag_service_type_get_name(m_serviceType));
52 }
53 
54 QString ServiceType::displayName() const
55 {
56  const gchar *id;
57 
58  /* libaccounts-glib returns the display name untranslated. */
59  id = ag_service_type_get_display_name(m_serviceType);
60  if (id != NULL) {
61  return qtTrId(id);
62  } else {
63  return QString();
64  }
65 }
66 
67 QString ServiceType::trCatalog() const
68 {
69  return ASCII(ag_service_type_get_i18n_domain(m_serviceType));
70 }
71 
72 QString ServiceType::iconName() const
73 {
74  return ASCII(ag_service_type_get_icon_name(m_serviceType));
75 }
76 
77 const QDomDocument ServiceType::domDocument() const
78 {
79  if (doc.isNull()) {
80  const gchar *data;
81  gsize len;
82 
83  ag_service_type_get_file_contents(m_serviceType, &data, &len);
84 
85  QString errorStr;
86  int errorLine;
87  int errorColumn;
88  if (!doc.setContent(QByteArray(data, len), true,
89  &errorStr, &errorLine, &errorColumn)) {
90  QString message(ASCII("Parse error reading serviceType file "
91  "at line %1, column %2:\n%3"));
92  message.arg(errorLine).arg(errorColumn).arg(errorStr);
93  qWarning() << __PRETTY_FUNCTION__ << message;
94  return QDomDocument();
95  }
96  }
97 
98  return doc;
99 }
100