accounts-qt  0.31
service.cpp
Go to the documentation of this file.
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-2010 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 #include <libaccounts-glib/ag-manager.h>
00028 #include <libaccounts-glib/ag-account.h>
00029 #include <libaccounts-glib/ag-service.h>
00030 #include <QtDebug>
00031 
00032 
00033 using namespace Accounts;
00034 
00035 Service::Service(AgService *service)
00036     : m_service(service)
00037 {
00038     TRACE();
00039     ag_service_ref(m_service);
00040 }
00041 
00042 Service::~Service()
00043 {
00044     TRACE();
00045 
00046     ag_service_unref(m_service);
00047     m_service = 0;
00048 }
00049 
00050 QString Service::name() const
00051 {
00052     return UTF8(ag_service_get_name(m_service));
00053 }
00054 
00055 QString Service::displayName() const
00056 {
00057     return UTF8(ag_service_get_display_name(m_service));
00058 }
00059 
00060 QString Service::serviceType() const
00061 {
00062     return ASCII(ag_service_get_service_type(m_service));
00063 }
00064 
00065 QString Service::provider() const
00066 {
00067     return UTF8(ag_service_get_provider(m_service));
00068 }
00069 
00070 QString Service::iconName() const
00071 {
00072     return ASCII(ag_service_get_icon_name(m_service));
00073 }
00074 
00075 QXmlStreamReader *Service::xmlStreamReader() const
00076 {
00077     const gchar *data;
00078     gsize offset;
00079 
00080     ag_service_get_file_contents(m_service, &data, &offset);
00081     if (data)
00082         data += offset;
00083 
00084     QXmlStreamReader *reader = new QXmlStreamReader(QByteArray(data));
00085 
00086     /* Read the startDocument token */
00087     if (reader->readNext() != QXmlStreamReader::StartDocument)
00088     {
00089         delete reader;
00090         return NULL;
00091     }
00092 
00093     return reader;
00094 }
00095 
00096 const QDomDocument Service::domDocument() const
00097 {
00098     if (doc.isNull())
00099     {
00100         const gchar *data;
00101 
00102         ag_service_get_file_contents(m_service, &data, NULL);
00103 
00104         QString errorStr;
00105         int errorLine;
00106         int errorColumn;
00107         if (!doc.setContent(QByteArray(data), true,
00108                             &errorStr, &errorLine, &errorColumn))
00109         {
00110             QString message(ASCII("Parse error reading account service file "
00111                                   "at line %1, column %2:\n%3"));
00112             message.arg(errorLine).arg(errorColumn).arg(errorStr);
00113             qWarning() << __PRETTY_FUNCTION__ << message;
00114             return QDomDocument();
00115         }
00116     }
00117 
00118     return doc;
00119 }
00120 
00121 AgService *Service::service() const
00122 {
00123     return m_service;
00124 }
00125