LCOV - code coverage report
Current view: top level - Accounts - provider.cpp (source / functions) Hit Total Coverage
Test: Code Coverage Lines: 40 46 87.0 %
Date: 2013-04-26 Functions: 11 12 91.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 14 71.4 %

           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                 :            :  *
       8                 :            :  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
       9                 :            :  *
      10                 :            :  * This library is free software; you can redistribute it and/or
      11                 :            :  * modify it under the terms of the GNU Lesser General Public License
      12                 :            :  * version 2.1 as published by the Free Software Foundation.
      13                 :            :  *
      14                 :            :  * This library is distributed in the hope that it will be useful, but
      15                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      17                 :            :  * Lesser General Public License for more details.
      18                 :            :  *
      19                 :            :  * You should have received a copy of the GNU Lesser General Public
      20                 :            :  * License along with this library; if not, write to the Free Software
      21                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
      22                 :            :  * 02110-1301 USA
      23                 :            :  */
      24                 :            : 
      25                 :            : #include "provider.h"
      26                 :            : 
      27                 :            : #undef signals
      28                 :            : #include <libaccounts-glib/ag-provider.h>
      29                 :            : 
      30                 :            : 
      31                 :            : using namespace Accounts;
      32                 :            : 
      33                 :            : namespace Accounts {
      34                 :            : /*!
      35                 :            :  * @class Provider
      36                 :            :  * @headerfile provider.h Accounts/Provider
      37                 :            :  *
      38                 :            :  * @brief Representation of an account provider.
      39                 :            :  *
      40                 :            :  * @details The Provider object represents an account provider. It can be used
      41                 :            :  * to retrieve some basic properties of the provider (such as the name) and to
      42                 :            :  * get access to the contents of the XML file which defines it.
      43                 :            :  */
      44                 :            : }; // namespace
      45                 :            : 
      46                 :          3 : Provider::Provider(AgProvider *provider, ReferenceMode mode):
      47                 :          3 :     m_provider(provider)
      48                 :            : {
      49 [ +  - ][ -  + ]:          3 :     if (m_provider != 0 && mode == AddReference)
      50                 :          0 :         ag_provider_ref(m_provider);
      51                 :          3 : }
      52                 :            : 
      53                 :            : /*!
      54                 :            :  * Construct an invalid provider.
      55                 :            :  */
      56                 :          1 : Provider::Provider():
      57                 :          1 :     m_provider(0)
      58                 :            : {
      59                 :          1 : }
      60                 :            : 
      61                 :            : /*!
      62                 :            :  * Copy constructor. Copying a Provider object is very cheap, because the
      63                 :            :  * data is shared among copies.
      64                 :            :  */
      65                 :          2 : Provider::Provider(const Provider &other):
      66                 :          2 :     m_provider(other.m_provider)
      67                 :            : {
      68         [ +  - ]:          2 :     if (m_provider != 0)
      69                 :          2 :         ag_provider_ref(m_provider);
      70                 :          2 : }
      71                 :            : 
      72                 :          3 : Provider &Provider::operator=(const Provider &other)
      73                 :            : {
      74         [ +  + ]:          3 :     if (m_provider == other.m_provider) return *this;
      75         [ +  + ]:          2 :     if (m_provider != 0)
      76                 :          1 :         ag_provider_unref(m_provider);
      77                 :          2 :     m_provider = other.m_provider;
      78         [ +  + ]:          2 :     if (m_provider != 0)
      79                 :          3 :         ag_provider_ref(m_provider);
      80                 :            :     return *this;
      81                 :            : }
      82                 :            : 
      83                 :          6 : Provider::~Provider()
      84                 :            : {
      85                 :          6 :     ag_provider_unref(m_provider);
      86                 :          6 :     m_provider = 0;
      87                 :          6 : }
      88                 :            : 
      89                 :            : /*!
      90                 :            :  * Check whether this object represents a Provider.
      91                 :            :  * @return true if the Provider is a valid one.
      92                 :            :  */
      93                 :          3 : bool Provider::isValid() const
      94                 :            : {
      95                 :          3 :     return m_provider != 0;
      96                 :            : }
      97                 :            : 
      98                 :            : /*!
      99                 :            :  * Get the name of the provider. This can be used as a unique identifier for
     100                 :            :  * this provider.
     101                 :            :  * @return The unique name of the provider.
     102                 :            :  */
     103                 :          1 : QString Provider::name() const
     104                 :            : {
     105                 :          1 :     return UTF8(ag_provider_get_name(m_provider));
     106                 :            : }
     107                 :            : 
     108                 :            : /*!
     109                 :            :  * Get the display name of the provider, untranslated.
     110                 :            :  * @return The display name of the provider.
     111                 :            :  */
     112                 :          5 : QString Provider::displayName() const
     113                 :            : {
     114                 :          5 :     return UTF8(ag_provider_get_display_name(m_provider));
     115                 :            : }
     116                 :            : 
     117                 :            : /*!
     118                 :            :  * @return The name of the translation catalog, which can be used to
     119                 :            :  * translate the displayName().
     120                 :            :  */
     121                 :          1 : QString Provider::trCatalog() const
     122                 :            : {
     123                 :          1 :     return ASCII(ag_provider_get_i18n_domain(m_provider));
     124                 :            : }
     125                 :            : 
     126                 :            : /*!
     127                 :            :  * @return The provider icon name.
     128                 :            :  */
     129                 :          1 : QString Provider::iconName() const
     130                 :            : {
     131                 :          1 :     return ASCII(ag_provider_get_icon_name(m_provider));
     132                 :            : }
     133                 :            : 
     134                 :            : /*!
     135                 :            :  * @return The DOM of the whole XML provider file.
     136                 :            :  */
     137                 :          1 : const QDomDocument Provider::domDocument() const
     138                 :            : {
     139                 :            :     const gchar *data;
     140                 :            : 
     141                 :          1 :     ag_provider_get_file_contents(m_provider, &data);
     142                 :            : 
     143                 :          1 :     QDomDocument doc;
     144                 :            :     QString errorStr;
     145                 :            :     int errorLine;
     146                 :            :     int errorColumn;
     147         [ -  + ]:          1 :     if (!doc.setContent(QByteArray(data), true,
     148                 :          1 :                         &errorStr, &errorLine, &errorColumn))
     149                 :            :     {
     150                 :            :         QString message(ASCII("Parse error reading account provider file "
     151                 :          0 :                               "at line %1, column %2:\n%3"));
     152                 :          0 :         message.arg(errorLine).arg(errorColumn).arg(errorStr);
     153                 :          0 :         qWarning() << __PRETTY_FUNCTION__ << message;
     154                 :            :     }
     155                 :            : 
     156                 :          1 :     return doc;
     157                 :            : }
     158                 :            : 
     159                 :          0 : AgProvider *Provider::provider() const
     160                 :            : {
     161                 :          0 :     return m_provider;
     162                 :          2 : }
     163                 :            : 

Generated by: LCOV version 1.9