LCOV - code coverage report
Current view: top level - Accounts - application.cpp (source / functions) Hit Total Coverage
Test: Code Coverage Lines: 64 64 100.0 %
Date: 2024-03-31 17:38:26 Functions: 15 15 100.0 %
Legend: Lines: hit not hit

          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-2016 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 "application.h"
      25             : #include "service.h"
      26             : 
      27             : #undef signals
      28             : #include <libaccounts-glib.h>
      29             : 
      30             : using namespace Accounts;
      31             : 
      32             : namespace Accounts {
      33             : /*!
      34             :  * @class Application
      35             :  * @headerfile application.h Accounts/Application
      36             :  *
      37             :  * @brief Information on the client applications of libaccounts.
      38             :  *
      39             :  * @details The Application structure holds information on the client
      40             :  * applications registered with libaccounts.
      41             :  * It is instantiated by Manager::application() and Manager::applicationList().
      42             :  */
      43             : }; // namespace
      44             : 
      45           4 : Application::Application(AgApplication *application):
      46           4 :     m_application(application)
      47             : {
      48           4 : }
      49             : 
      50             : /*!
      51             :  * Construct an invalid application.
      52             :  */
      53           1 : Application::Application():
      54           1 :     m_application(nullptr)
      55             : {
      56           1 : }
      57             : 
      58             : /*!
      59             :  * Copy constructor. Copying an Application object is very cheap, because the
      60             :  * data is shared among copies.
      61             :  */
      62           3 : Application::Application(const Application &other):
      63           3 :     m_application(other.m_application)
      64             : {
      65           3 :     if (m_application != nullptr)
      66           2 :         ag_application_ref(m_application);
      67           3 : }
      68             : 
      69           1 : Application &Application::operator=(const Application &other)
      70             : {
      71           1 :     if (m_application == other.m_application) return *this;
      72           1 :     if (m_application != nullptr)
      73           1 :         ag_application_unref(m_application);
      74           1 :     m_application = other.m_application;
      75           1 :     if (m_application != nullptr)
      76           1 :         ag_application_ref(m_application);
      77           1 :     return *this;
      78             : }
      79             : 
      80             : /*!
      81             :  * Destructor.
      82             :  */
      83          16 : Application::~Application()
      84             : {
      85           8 :     if (m_application != nullptr) {
      86           6 :         ag_application_unref(m_application);
      87           6 :         m_application = nullptr;
      88             :     }
      89           8 : }
      90             : 
      91             : /*!
      92             :  * Check whether this object represents an Application.
      93             :  * @return true if the Application is a valid one.
      94             :  */
      95           7 : bool Application::isValid() const
      96             : {
      97           7 :     return m_application != nullptr;
      98             : }
      99             : 
     100             : /*!
     101             :  * Get the unique ID of the application. This is the name of the .application
     102             :  * file minus the .application suffix.
     103             :  * @return The application unique ID.
     104             :  */
     105           3 : QString Application::name() const
     106             : {
     107           3 :     if (Q_UNLIKELY(!isValid())) return QString();
     108           3 :     return UTF8(ag_application_get_name(m_application));
     109             : }
     110             : 
     111             : /*!
     112             :  * Get the display name of the application.
     113             :  * @return The application display name.
     114             :  */
     115           1 : QString Application::displayName() const
     116             : {
     117           1 :     QString name;
     118             :     GDesktopAppInfo *info =
     119           1 :         ag_application_get_desktop_app_info(m_application);
     120           1 :     if (Q_LIKELY(info)) {
     121           1 :         name = UTF8(g_app_info_get_display_name(G_APP_INFO(info)));
     122           1 :         g_object_unref(info);
     123             :     }
     124           1 :     return name;
     125             : }
     126             : 
     127             : /*!
     128             :  * Get the description of the application.
     129             :  * @return The application description.
     130             :  */
     131           2 : QString Application::description() const
     132             : {
     133           2 :     return UTF8(ag_application_get_description(m_application));
     134             : }
     135             : 
     136             : /*!
     137             :  * Get the icon name of the application.
     138             :  * @return The application icon name.
     139             :  */
     140           1 : QString Application::iconName() const
     141             : {
     142           1 :     QString iconName;
     143             :     GDesktopAppInfo *info =
     144           1 :         ag_application_get_desktop_app_info(m_application);
     145           1 :     if (Q_LIKELY(info)) {
     146           1 :         gchar *gIconName = g_desktop_app_info_get_string(info, "Icon");
     147           1 :         if (Q_LIKELY(gIconName)) {
     148           1 :             iconName = UTF8(gIconName);
     149           1 :             g_free(gIconName);
     150             :         }
     151           1 :         g_object_unref(info);
     152             :     }
     153           1 :     return iconName;
     154             : }
     155             : 
     156             : /*!
     157             :  * Get the .desktop file associated with this application.
     158             :  * @return The full path to the .desktop file.
     159             :  */
     160           1 : QString Application::desktopFilePath() const
     161             : {
     162           1 :     QString filePath;
     163             :     GDesktopAppInfo *info =
     164           1 :         ag_application_get_desktop_app_info(m_application);
     165           1 :     if (Q_LIKELY(info)) {
     166           1 :         filePath = UTF8(g_desktop_app_info_get_filename(info));
     167           1 :         g_object_unref(info);
     168             :     }
     169           1 :     return filePath;
     170             : }
     171             : 
     172             : /*!
     173             :  * Get the translation catalog for the texts returned by the methods of this
     174             :  * class.
     175             :  * @return The translation catalog name.
     176             :  */
     177           1 : QString Application::trCatalog() const
     178             : {
     179           1 :     return UTF8(ag_application_get_i18n_domain(m_application));
     180             : }
     181             : 
     182             : /*!
     183             :  * Check whether the application supports the given service.
     184             :  * @param service Instance of a Service.
     185             :  * @return whether the service is supported by this application.
     186             :  */
     187           2 : bool Application::supportsService(const Service &service) const
     188             : {
     189           2 :     return ag_application_supports_service(m_application,
     190           2 :                                            service.service());
     191             : }
     192             : 
     193             : /*!
     194             :  * Get the description from the application XML file, for the specified
     195             :  * service; if not found, get the service-type description instead.
     196             :  * @return Usage description of the service.
     197             :  */
     198           2 : QString Application::serviceUsage(const Service &service) const
     199             : {
     200           2 :     return UTF8(ag_application_get_service_usage(m_application,
     201             :                                                  service.service()));
     202             : }
     203             : 
     204           1 : AgApplication *Application::application() const
     205             : {
     206           1 :     return m_application;
     207             : }

Generated by: LCOV version 1.13