File: application.cpp

package info (click to toggle)
libaccounts-qt 1.17-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 636 kB
  • sloc: cpp: 3,286; makefile: 23; sh: 8
file content (207 lines) | stat: -rw-r--r-- 5,487 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* vi: set et sw=4 ts=4 cino=t0,(0: */
/*
 * This file is part of libaccounts-qt
 *
 * Copyright (C) 2012-2016 Canonical Ltd.
 *
 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

#include "application.h"
#include "service.h"

#undef signals
#include <libaccounts-glib.h>

using namespace Accounts;

namespace Accounts {
/*!
 * @class Application
 * @headerfile application.h Accounts/Application
 *
 * @brief Information on the client applications of libaccounts.
 *
 * @details The Application structure holds information on the client
 * applications registered with libaccounts.
 * It is instantiated by Manager::application() and Manager::applicationList().
 */
}; // namespace

Application::Application(AgApplication *application):
    m_application(application)
{
}

/*!
 * Construct an invalid application.
 */
Application::Application():
    m_application(nullptr)
{
}

/*!
 * Copy constructor. Copying an Application object is very cheap, because the
 * data is shared among copies.
 */
Application::Application(const Application &other):
    m_application(other.m_application)
{
    if (m_application != nullptr)
        ag_application_ref(m_application);
}

Application &Application::operator=(const Application &other)
{
    if (m_application == other.m_application) return *this;
    if (m_application != nullptr)
        ag_application_unref(m_application);
    m_application = other.m_application;
    if (m_application != nullptr)
        ag_application_ref(m_application);
    return *this;
}

/*!
 * Destructor.
 */
Application::~Application()
{
    if (m_application != nullptr) {
        ag_application_unref(m_application);
        m_application = nullptr;
    }
}

/*!
 * Check whether this object represents an Application.
 * @return true if the Application is a valid one.
 */
bool Application::isValid() const
{
    return m_application != nullptr;
}

/*!
 * Get the unique ID of the application. This is the name of the .application
 * file minus the .application suffix.
 * @return The application unique ID.
 */
QString Application::name() const
{
    if (Q_UNLIKELY(!isValid())) return QString();
    return UTF8(ag_application_get_name(m_application));
}

/*!
 * Get the display name of the application.
 * @return The application display name.
 */
QString Application::displayName() const
{
    QString name;
    GDesktopAppInfo *info =
        ag_application_get_desktop_app_info(m_application);
    if (Q_LIKELY(info)) {
        name = UTF8(g_app_info_get_display_name(G_APP_INFO(info)));
        g_object_unref(info);
    }
    return name;
}

/*!
 * Get the description of the application.
 * @return The application description.
 */
QString Application::description() const
{
    return UTF8(ag_application_get_description(m_application));
}

/*!
 * Get the icon name of the application.
 * @return The application icon name.
 */
QString Application::iconName() const
{
    QString iconName;
    GDesktopAppInfo *info =
        ag_application_get_desktop_app_info(m_application);
    if (Q_LIKELY(info)) {
        gchar *gIconName = g_desktop_app_info_get_string(info, "Icon");
        if (Q_LIKELY(gIconName)) {
            iconName = UTF8(gIconName);
            g_free(gIconName);
        }
        g_object_unref(info);
    }
    return iconName;
}

/*!
 * Get the .desktop file associated with this application.
 * @return The full path to the .desktop file.
 */
QString Application::desktopFilePath() const
{
    QString filePath;
    GDesktopAppInfo *info =
        ag_application_get_desktop_app_info(m_application);
    if (Q_LIKELY(info)) {
        filePath = UTF8(g_desktop_app_info_get_filename(info));
        g_object_unref(info);
    }
    return filePath;
}

/*!
 * Get the translation catalog for the texts returned by the methods of this
 * class.
 * @return The translation catalog name.
 */
QString Application::trCatalog() const
{
    return UTF8(ag_application_get_i18n_domain(m_application));
}

/*!
 * Check whether the application supports the given service.
 * @param service Instance of a Service.
 * @return whether the service is supported by this application.
 */
bool Application::supportsService(const Service &service) const
{
    return ag_application_supports_service(m_application,
                                           service.service());
}

/*!
 * Get the description from the application XML file, for the specified
 * service; if not found, get the service-type description instead.
 * @return Usage description of the service.
 */
QString Application::serviceUsage(const Service &service) const
{
    return UTF8(ag_application_get_service_usage(m_application,
                                                 service.service()));
}

AgApplication *Application::application() const
{
    return m_application;
}