accounts-qt: Accounts/application.cpp Source File

accounts-qt 1.17

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-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
30using namespace Accounts;
31
32namespace Accounts {
43}; // namespace
44
45 Application::Application(AgApplication *application):
46 m_application(application)
47{
48}
49
53Application::Application():
54 m_application(nullptr)
55{
56}
57
62 Application::Application(const Application &other):
63 m_application(other.m_application)
64{
65 if (m_application != nullptr)
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 != nullptr)
73 ag_application_unref(m_application);
74 m_application = other.m_application;
75 if (m_application != nullptr)
76 ag_application_ref(m_application);
77 return *this;
78}
79
83Application::~Application()
84{
85 if (m_application != nullptr) {
86 ag_application_unref(m_application);
87 m_application = nullptr;
88 }
89}
90
95 bool Application::isValid() const
96{
97 return m_application != nullptr;
98}
99
105QString Application::name() const
106{
107 if (Q_UNLIKELY(!isValid())) return QString();
108 return UTF8(ag_application_get_name(m_application));
109}
110
115QString Application::displayName() const
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
131QString Application::description() const
132{
133 return UTF8(ag_application_get_description(m_application));
134}
135
140QString 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
160QString Application::desktopFilePath() const
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
177QString Application::trCatalog() const
178{
179 return UTF8(ag_application_get_i18n_domain(m_application));
180}
181
187 bool Application::supportsService(const Service &service) const
188{
189 return ag_application_supports_service(m_application,
190 service.service());
191}
192
198QString Application::serviceUsage(const Service &service) const
199{
200 return UTF8(ag_application_get_service_usage(m_application,
201 service.service()));
202}
203
204AgApplication *Application::application() const
205{
206 return m_application;
207}
Accounts::Application
Information on the client applications of libaccounts.
Definition: application.h:42
Accounts::Application::isValid
bool isValid() const
Check whether this object represents an Application.
Definition: application.cpp:95
Accounts::Application::~Application
~Application()
Destructor.
Definition: application.cpp:83
Accounts::Application::name
QString name() const
Get the unique ID of the application.
Definition: application.cpp:105
Accounts::Application::desktopFilePath
QString desktopFilePath() const
Get the .desktop file associated with this application.
Definition: application.cpp:160
Accounts::Application::iconName
QString iconName() const
Get the icon name of the application.
Definition: application.cpp:140
Accounts::Application::displayName
QString displayName() const
Get the display name of the application.
Definition: application.cpp:115
Accounts::Application::description
QString description() const
Get the description of the application.
Definition: application.cpp:131
Accounts::Application::supportsService
bool supportsService(const Service &service) const
Check whether the application supports the given service.
Definition: application.cpp:187
Accounts::Application::serviceUsage
QString serviceUsage(const Service &service) const
Get the description from the application XML file, for the specified service; if not found,...
Definition: application.cpp:198
Accounts::Application::trCatalog
QString trCatalog() const
Get the translation catalog for the texts returned by the methods of this class.
Definition: application.cpp:177
Accounts::Application::Application
Application()
Construct an invalid application.
Definition: application.cpp:53
Accounts::Service
Representation of an account service.
Definition: service.h:49