libaccounts-qt  1.1
service.cpp
00001 /* vi: set et sw=4 ts=4 cino=t0,(0: */
00002 /*
00003  * This file is part of libaccounts-qt
00004  *
00005  * Copyright (C) 2009-2011 Nokia Corporation.
00006  *
00007  * Contact: Alberto Mardegan <alberto.mardegan@nokia.com>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public License
00011  * version 2.1 as published by the Free Software Foundation.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  */
00023 
00024 #include "account.h"
00025 #include "manager.h"
00026 
00027 #undef signals
00028 #include <libaccounts-glib/ag-manager.h>
00029 #include <libaccounts-glib/ag-account.h>
00030 #include <libaccounts-glib/ag-service.h>
00031 #include <QtDebug>
00032 
00033 
00034 using namespace Accounts;
00035 
00036 namespace Accounts {
00048 }; // namespace
00049 
00050 Service::Service(AgService *service)
00051     : m_service(service)
00052 {
00053     TRACE();
00054     ag_service_ref(m_service);
00055 }
00056 
00057 Service::~Service()
00058 {
00059     TRACE();
00060 
00061     ag_service_unref(m_service);
00062     m_service = 0;
00063 }
00064 
00065 QString Service::name() const
00066 {
00067     return UTF8(ag_service_get_name(m_service));
00068 }
00069 
00070 QString Service::displayName() const
00071 {
00072     return UTF8(ag_service_get_display_name(m_service));
00073 }
00074 
00075 QString Service::serviceType() const
00076 {
00077     return ASCII(ag_service_get_service_type(m_service));
00078 }
00079 
00083 QString Service::trCatalog() const
00084 {
00085     return ASCII(ag_service_get_i18n_domain(m_service));
00086 }
00087 
00088 QString Service::provider() const
00089 {
00090     return UTF8(ag_service_get_provider(m_service));
00091 }
00092 
00096 QString Service::iconName() const
00097 {
00098     return ASCII(ag_service_get_icon_name(m_service));
00099 }
00100 
00101 QXmlStreamReader *Service::xmlStreamReader() const
00102 {
00103     const gchar *data;
00104     gsize offset;
00105 
00106     ag_service_get_file_contents(m_service, &data, &offset);
00107     if (data)
00108         data += offset;
00109 
00110     QXmlStreamReader *reader = new QXmlStreamReader(QByteArray(data));
00111 
00112     /* Read the startDocument token */
00113     if (reader->readNext() != QXmlStreamReader::StartDocument)
00114     {
00115         delete reader;
00116         return NULL;
00117     }
00118 
00119     return reader;
00120 }
00121 
00125 const QDomDocument Service::domDocument() const
00126 {
00127     if (doc.isNull())
00128     {
00129         const gchar *data;
00130 
00131         ag_service_get_file_contents(m_service, &data, NULL);
00132 
00133         QString errorStr;
00134         int errorLine;
00135         int errorColumn;
00136         if (!doc.setContent(QByteArray(data), true,
00137                             &errorStr, &errorLine, &errorColumn))
00138         {
00139             QString message(ASCII("Parse error reading account service file "
00140                                   "at line %1, column %2:\n%3"));
00141             message.arg(errorLine).arg(errorColumn).arg(errorStr);
00142             qWarning() << __PRETTY_FUNCTION__ << message;
00143             return QDomDocument();
00144         }
00145     }
00146 
00147     return doc;
00148 }
00149 
00150 AgService *Service::service() const
00151 {
00152     return m_service;
00153 }
00154