LCOV - code coverage report
Current view: top level - Accounts - service.cpp (source / functions) Hit Total Coverage
Test: Code Coverage Lines: 63 66 95.5 %
Date: 2013-04-26 Functions: 16 16 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 20 26 76.9 %

           Branch data     Line data    Source code
       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-2011 Nokia Corporation.
       6                 :            :  * Copyright (C) 2012 Canonical Ltd.
       7                 :            :  * Copyright (C) 2012 Intel Corporation.
       8                 :            :  *
       9                 :            :  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
      10                 :            :  * Contact: Jussi Laako <jussi.laako@linux.intel.com>
      11                 :            :  *
      12                 :            :  * This library is free software; you can redistribute it and/or
      13                 :            :  * modify it under the terms of the GNU Lesser General Public License
      14                 :            :  * version 2.1 as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * This library is distributed in the hope that it will be useful, but
      17                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      19                 :            :  * Lesser General Public License for more details.
      20                 :            :  *
      21                 :            :  * You should have received a copy of the GNU Lesser General Public
      22                 :            :  * License along with this library; if not, write to the Free Software
      23                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
      24                 :            :  * 02110-1301 USA
      25                 :            :  */
      26                 :            : 
      27                 :            : #include "service.h"
      28                 :            : 
      29                 :            : #undef signals
      30                 :            : #include <libaccounts-glib/ag-service.h>
      31                 :            : 
      32                 :            : using namespace Accounts;
      33                 :            : 
      34                 :            : namespace Accounts {
      35                 :            : /*!
      36                 :            :  * @class Service
      37                 :            :  * @headerfile service.h Accounts/Service
      38                 :            :  *
      39                 :            :  * @brief Representation of an account service.
      40                 :            :  *
      41                 :            :  * @details The Service object represents an account service. It can be used to
      42                 :            :  * retrieve some basic properties of the service (such as name, type and
      43                 :            :  * provider) and to get access to the contents of the XML file which defines
      44                 :            :  * it.
      45                 :            :  */
      46                 :            : }; // namespace
      47                 :            : 
      48                 :         26 : Service::Service(AgService *service, ReferenceMode mode):
      49                 :            :     m_service(service),
      50                 :         26 :     m_tags(0)
      51                 :            : {
      52 [ +  + ][ +  + ]:         26 :     if (m_service != 0 && mode == AddReference)
      53                 :          3 :         ag_service_ref(m_service);
      54                 :         26 : }
      55                 :            : 
      56                 :            : /*!
      57                 :            :  * Construct an invalid service.
      58                 :            :  */
      59                 :          7 : Service::Service():
      60                 :            :     m_service(0),
      61                 :          7 :     m_tags(0)
      62                 :            : {
      63                 :          7 : }
      64                 :            : 
      65                 :            : /*!
      66                 :            :  * Copy constructor. Copying a Service object is very cheap, because the
      67                 :            :  * data is shared among copies.
      68                 :            :  */
      69                 :          7 : Service::Service(const Service &other):
      70                 :            :     m_service(other.m_service),
      71                 :          7 :     m_tags(0)
      72                 :            : {
      73         [ +  - ]:          7 :     if (m_service != 0)
      74                 :          7 :         ag_service_ref(m_service);
      75                 :          7 : }
      76                 :            : 
      77                 :          2 : Service &Service::operator=(const Service &other)
      78                 :            : {
      79         [ +  - ]:          2 :     if (m_service == other.m_service) return *this;
      80         [ +  - ]:          2 :     if (m_service != 0)
      81                 :          2 :         ag_service_unref(m_service);
      82                 :          2 :     m_service = other.m_service;
      83         [ +  + ]:          2 :     if (m_service != 0)
      84                 :          2 :         ag_service_ref(m_service);
      85                 :            :     return *this;
      86                 :            : }
      87                 :            : 
      88                 :         40 : Service::~Service()
      89                 :            : {
      90         [ +  + ]:         40 :     if (m_service != 0) {
      91                 :         30 :         ag_service_unref(m_service);
      92                 :         30 :         m_service = 0;
      93                 :            :     }
      94         [ +  + ]:         40 :     if (m_tags != 0) {
      95         [ +  - ]:          1 :         delete m_tags;
      96                 :          1 :         m_tags = 0;
      97                 :            :     }
      98                 :         40 : }
      99                 :            : 
     100                 :            : /*!
     101                 :            :  * Check whether this object represents a Service.
     102                 :            :  * @return true if the Service is a valid one.
     103                 :            :  */
     104                 :         39 : bool Service::isValid() const
     105                 :            : {
     106                 :         39 :     return m_service != 0;
     107                 :            : }
     108                 :            : 
     109                 :            : /*!
     110                 :            :  * Get the name of the service. This can be used as a unique identifier for
     111                 :            :  * this service.
     112                 :            :  * @return The unique name of the service.
     113                 :            :  */
     114                 :          4 : QString Service::name() const
     115                 :            : {
     116                 :          4 :     return UTF8(ag_service_get_name(m_service));
     117                 :            : }
     118                 :            : 
     119                 :            : /*!
     120                 :            :  * Get the display name of the service, untranslated.
     121                 :            :  * @return The display name of the service.
     122                 :            :  */
     123                 :          1 : QString Service::displayName() const
     124                 :            : {
     125                 :          1 :     return UTF8(ag_service_get_display_name(m_service));
     126                 :            : }
     127                 :            : 
     128                 :            : /*!
     129                 :            :  * Get the service type ID of the service.
     130                 :            :  * @return The service type of the service.
     131                 :            :  */
     132                 :          1 : QString Service::serviceType() const
     133                 :            : {
     134                 :          1 :     return ASCII(ag_service_get_service_type(m_service));
     135                 :            : }
     136                 :            : 
     137                 :            : /*!
     138                 :            :  * @return The translation catalog of the service.
     139                 :            :  */
     140                 :          1 : QString Service::trCatalog() const
     141                 :            : {
     142                 :          1 :     return ASCII(ag_service_get_i18n_domain(m_service));
     143                 :            : }
     144                 :            : 
     145                 :            : /*!
     146                 :            :  * Get the provider ID of the service.
     147                 :            :  * @return The provider of the service.
     148                 :            :  */
     149                 :          1 : QString Service::provider() const
     150                 :            : {
     151                 :          1 :     return UTF8(ag_service_get_provider(m_service));
     152                 :            : }
     153                 :            : 
     154                 :            : /*!
     155                 :            :  * Get the icon name for this service.
     156                 :            :  * @return The icon name.
     157                 :            :  */
     158                 :          1 : QString Service::iconName() const
     159                 :            : {
     160                 :          1 :     return ASCII(ag_service_get_icon_name(m_service));
     161                 :            : }
     162                 :            : 
     163                 :            : /*!
     164                 :            :  * Check if this service has a tag.
     165                 :            :  *
     166                 :            :  * @param tag Tag to look for
     167                 :            :  *
     168                 :            :  * @return Service has the tag?
     169                 :            :  */
     170                 :          3 : bool Service::hasTag(const QString &tag) const
     171                 :            : {
     172                 :          3 :     return ag_service_has_tag(m_service, tag.toUtf8().constData());
     173                 :            : }
     174                 :            : 
     175                 :            : /*!
     176                 :            :  * Return all tags of the service as a set.
     177                 :            :  *
     178                 :            :  * @return Set of tags
     179                 :            :  */
     180                 :          2 : QSet<QString> Service::tags() const
     181                 :            : {
     182         [ +  + ]:          2 :     if (m_tags)
     183                 :          1 :         return *m_tags;
     184                 :            : 
     185                 :          1 :     m_tags = new QSet<QString>;
     186                 :          1 :     GList *list = ag_service_get_tags(m_service);
     187                 :            :     GList *iter = list;
     188         [ +  + ]:          3 :     while (iter != NULL) {
     189                 :          2 :         m_tags->insert(UTF8(reinterpret_cast<const gchar *> (iter->data)));
     190         [ +  - ]:          2 :         iter = g_list_next(iter);
     191                 :            :     }
     192                 :          1 :     g_list_free(list);
     193                 :          2 :     return *m_tags;
     194                 :            : }
     195                 :            : 
     196                 :            : /*!
     197                 :            :  * Get the contents of the service XML file.
     198                 :            :  * @return The DOM of the whole XML service file
     199                 :            :  */
     200                 :          1 : const QDomDocument Service::domDocument() const
     201                 :            : {
     202                 :            :     const gchar *data;
     203                 :            : 
     204                 :          1 :     ag_service_get_file_contents(m_service, &data, NULL);
     205                 :            : 
     206                 :          1 :     QDomDocument doc;
     207                 :            :     QString errorStr;
     208                 :            :     int errorLine;
     209                 :            :     int errorColumn;
     210         [ -  + ]:          1 :     if (!doc.setContent(QByteArray(data), true,
     211                 :          1 :                         &errorStr, &errorLine, &errorColumn))
     212                 :            :     {
     213                 :            :         QString message(ASCII("Parse error reading account service file "
     214                 :          0 :                               "at line %1, column %2:\n%3"));
     215                 :          0 :         message.arg(errorLine).arg(errorColumn).arg(errorStr);
     216                 :          0 :         qWarning() << __PRETTY_FUNCTION__ << message;
     217                 :            :     }
     218                 :          1 :     return doc;
     219                 :            : }
     220                 :            : 
     221                 :         21 : AgService *Service::service() const
     222                 :            : {
     223                 :         21 :     return m_service;
     224                 :         20 : }
     225                 :            : 

Generated by: LCOV version 1.9