accounts-qt  1.13
application.cpp
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 "application.h"
25 #include "service.h"
26 
27 #undef signals
28 #include <libaccounts-glib/ag-application.h>
29 
30 using namespace Accounts;
31 
32 namespace Accounts {
43 }; // namespace
44 
45 Application::Application(AgApplication *application):
46  m_application(application)
47 {
48 }
49 
54  m_application(0)
55 {
56 }
57 
63  m_application(other.m_application)
64 {
65  if (m_application != 0)
66  ag_application_ref(m_application);
67 }
68 
69 Application &Application::operator=(const Application &other)
70 {
71  if (m_application == other.m_application) return *this;
72  if (m_application != 0)
73  ag_application_unref(m_application);
74  m_application = other.m_application;
75  if (m_application != 0)
76  ag_application_ref(m_application);
77  return *this;
78 }
79 
84 {
85  if (m_application != 0) {
86  ag_application_unref(m_application);
87  m_application = 0;
88  }
89 }
90 
96 {
97  return m_application != 0;
98 }
99 
105 QString Application::name() const
106 {
107  if (Q_UNLIKELY(!isValid())) return QString();
108  return UTF8(ag_application_get_name(m_application));
109 }
110 
116 {
117  QString name;
118  GDesktopAppInfo *info =
119  ag_application_get_desktop_app_info(m_application);
120  if (Q_LIKELY(info)) {
121  name = UTF8(g_app_info_get_display_name(G_APP_INFO(info)));
122  g_object_unref(info);
123  }
124  return name;
125 }
126 
132 {
133  return UTF8(ag_application_get_description(m_application));
134 }
135 
140 QString Application::iconName() const
141 {
142  QString iconName;
143  GDesktopAppInfo *info =
144  ag_application_get_desktop_app_info(m_application);
145  if (Q_LIKELY(info)) {
146  gchar *gIconName = g_desktop_app_info_get_string(info, "Icon");
147  if (Q_LIKELY(gIconName)) {
148  iconName = UTF8(gIconName);
149  g_free(gIconName);
150  }
151  g_object_unref(info);
152  }
153  return iconName;
154 }
155 
161 {
162  QString filePath;
163  GDesktopAppInfo *info =
164  ag_application_get_desktop_app_info(m_application);
165  if (Q_LIKELY(info)) {
166  filePath = UTF8(g_desktop_app_info_get_filename(info));
167  g_object_unref(info);
168  }
169  return filePath;
170 }
171 
177 QString Application::trCatalog() const
178 {
179  return UTF8(ag_application_get_i18n_domain(m_application));
180 }
181 
187 QString Application::serviceUsage(const Service &service) const
188 {
189  return UTF8(ag_application_get_service_usage(m_application,
190  service.service()));
191 }
QString iconName() const
Get the icon name of the application.
QString description() const
Get the description of the application.
QString desktopFilePath() const
Get the .desktop file associated with this application.
Application()
Construct an invalid application.
Definition: application.cpp:53
QString serviceUsage(const Service &service) const
Get the description from the application XML file, for the specified service; if not found...
Representation of an account service.
Definition: service.h:48
QString name() const
Get the unique ID of the application.
bool isValid() const
Check whether this object represents an Application.
Definition: application.cpp:95
QString displayName() const
Get the display name of the application.
Information on the client applications of libaccounts.
Definition: application.h:40
QString trCatalog() const
Get the translation catalog for the texts returned by the methods of this class.
~Application()
Destructor.
Definition: application.cpp:83