LCOV - code coverage report
Current view: top level - Accounts - auth-data.cpp (source / functions) Hit Total Coverage
Test: Code Coverage Lines: 22 22 100.0 %
Date: 2013-04-26 Functions: 8 8 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 4 50.0 %

           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) 2012 Canonical Ltd.
       6                 :            :  *
       7                 :            :  * Contact: Alberto Mardegan <alberto.mardegan@canonical.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 "auth-data.h"
      25                 :            : #include "utils.h"
      26                 :            : 
      27                 :            : #undef signals
      28                 :            : #include <libaccounts-glib/ag-auth-data.h>
      29                 :            : #include <QtDebug>
      30                 :            : #include <QtGlobal>
      31                 :            : 
      32                 :            : 
      33                 :            : using namespace Accounts;
      34                 :            : 
      35                 :            : namespace Accounts {
      36                 :            : /*!
      37                 :            :  * @class AuthData
      38                 :            :  * @headerfile auth-data.h Accounts/AuthData
      39                 :            :  *
      40                 :            :  * @brief Information for account authentication.
      41                 :            :  *
      42                 :            :  * @details The AuthData class holds information on the authentication
      43                 :            :  * parameters used by an account. It is an implicitly shared object which can
      44                 :            :  * be created with the AccountService::authData method.
      45                 :            :  */
      46                 :            : }; // namespace
      47                 :            : 
      48                 :          2 : AuthData::AuthData(AgAuthData *authData):
      49                 :          2 :     m_authData(ag_auth_data_ref(authData))
      50                 :            : {
      51                 :          2 : }
      52                 :            : 
      53                 :            : /*!
      54                 :            :  * Copy constructor. Copying an AuthData object is very cheap, because the data
      55                 :            :  * is shared among copies.
      56                 :            :  */
      57                 :          2 : AuthData::AuthData(const AuthData &other):
      58                 :          2 :     m_authData(ag_auth_data_ref(other.m_authData))
      59                 :            : {
      60                 :          2 : }
      61                 :            : 
      62                 :            : /*!
      63                 :            :  * Destructor.
      64                 :            :  */
      65                 :          5 : AuthData::~AuthData()
      66                 :            : {
      67                 :          4 :     ag_auth_data_unref(m_authData);
      68                 :          4 :     m_authData = 0;
      69                 :          5 : }
      70                 :            : 
      71                 :            : /*!
      72                 :            :  * @return The ID of the credentials associated with this account.
      73                 :            :  */
      74                 :          2 : uint AuthData::credentialsId() const
      75                 :            : {
      76                 :          2 :     return ag_auth_data_get_credentials_id(m_authData);
      77                 :            : }
      78                 :            : 
      79                 :            : /*!
      80                 :            :  * Get the authentication method which must be used when logging in with this
      81                 :            :  * account.
      82                 :            :  * @return The authentication method.
      83                 :            :  */
      84                 :          2 : QString AuthData::method() const
      85                 :            : {
      86                 :          2 :     return UTF8(ag_auth_data_get_method(m_authData));
      87                 :            : }
      88                 :            : 
      89                 :            : /*!
      90                 :            :  * Get the authentication mechanism which must be used when logging in with
      91                 :            :  * this account.
      92                 :            :  * @return The authentication mechanism.
      93                 :            :  */
      94                 :          2 : QString AuthData::mechanism() const
      95                 :            : {
      96                 :          2 :     return UTF8(ag_auth_data_get_mechanism(m_authData));
      97                 :            : }
      98                 :            : 
      99                 :            : /*!
     100                 :            :  * Get the dictionary of authentication parameters which must be used when
     101                 :            :  * logging in with this account.
     102                 :            :  * @return The authentication parameters.
     103                 :            :  */
     104                 :          4 : QVariantMap AuthData::parameters() const
     105                 :            : {
     106                 :            :     GVariant *glibParameters;
     107                 :            : 
     108                 :          4 :     glibParameters = ag_auth_data_get_login_parameters(m_authData, NULL);
     109         [ -  + ]:          4 :     if (glibParameters == 0) return QVariantMap();
     110                 :            : 
     111                 :          4 :     QVariant variant = gVariantToQVariant(glibParameters);
     112         [ -  + ]:          4 :     if (!variant.isValid()) return QVariantMap();
     113                 :            : 
     114                 :          4 :     return variant.toMap();
     115                 :            : }

Generated by: LCOV version 1.9