|
0 |
/*
|
|
1 |
* gmenu-desktopappinfo.c
|
|
2 |
* Copyright (C) 2020 Lars Mueller <cobinja@yahoo.de>
|
|
3 |
*
|
|
4 |
* This library is free software; you can redistribute it and/or
|
|
5 |
* modify it under the terms of the GNU Lesser General Public
|
|
6 |
* License as published by the Free Software Foundation; either
|
|
7 |
* version 2 of the License, or (at your option) any later version.
|
|
8 |
*
|
|
9 |
* This library is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12 |
* Lesser General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU Lesser General Public
|
|
15 |
* License along with this library; if not, write to the
|
|
16 |
* Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
17 |
* Boston, MA 02110, USA.
|
|
18 |
*/
|
|
19 |
|
|
20 |
#include "gmenu-desktopappinfo.h"
|
|
21 |
#include <gio/gdesktopappinfo.h>
|
|
22 |
|
|
23 |
struct _GMenuDesktopAppInfo
|
|
24 |
{
|
|
25 |
GObject parent_instance;
|
|
26 |
|
|
27 |
GDesktopAppInfo *super_appinfo;
|
|
28 |
gchar *desktop_id;
|
|
29 |
gboolean is_flatpak;
|
|
30 |
gchar *startup_wm_class;
|
|
31 |
gchar *flatpak_app_id;
|
|
32 |
};
|
|
33 |
|
|
34 |
// This function sets desktop id and startup wm class and adds ":flatpak" for flatpak apps
|
|
35 |
static void
|
|
36 |
update_app_data (GMenuDesktopAppInfo *info)
|
|
37 |
{
|
|
38 |
const gchar *exec;
|
|
39 |
const gchar *id;
|
|
40 |
const gchar *startup_wm_class;
|
|
41 |
|
|
42 |
g_free (info->desktop_id);
|
|
43 |
info->desktop_id = NULL;
|
|
44 |
|
|
45 |
g_free (info->startup_wm_class);
|
|
46 |
info->startup_wm_class = NULL;
|
|
47 |
|
|
48 |
g_free (info->flatpak_app_id);
|
|
49 |
info->flatpak_app_id = NULL;
|
|
50 |
|
|
51 |
if (info->super_appinfo != NULL)
|
|
52 |
{
|
|
53 |
exec = g_app_info_get_executable (G_APP_INFO (info->super_appinfo));
|
|
54 |
id = g_app_info_get_id (G_APP_INFO (info->super_appinfo));
|
|
55 |
startup_wm_class = g_desktop_app_info_get_startup_wm_class (info->super_appinfo);
|
|
56 |
|
|
57 |
if (strstr (exec, "flatpak") || strstr (exec, "bwrap"))
|
|
58 |
{
|
|
59 |
info->desktop_id = g_strconcat (id, GMENU_DESKTOPAPPINFO_FLATPAK_SUFFIX, NULL);
|
|
60 |
if (startup_wm_class)
|
|
61 |
{
|
|
62 |
info->startup_wm_class = g_strconcat (startup_wm_class, GMENU_DESKTOPAPPINFO_FLATPAK_SUFFIX, NULL);
|
|
63 |
}
|
|
64 |
|
|
65 |
// if (g_desktop_app_info_has_key (info->super_appinfo, "X-Flatpak"))
|
|
66 |
// {
|
|
67 |
info->flatpak_app_id = g_desktop_app_info_get_string (info->super_appinfo, "X-Flatpak");
|
|
68 |
// }
|
|
69 |
|
|
70 |
info->is_flatpak = TRUE;
|
|
71 |
} else {
|
|
72 |
info->desktop_id = g_strdup (id);
|
|
73 |
info->is_flatpak = FALSE;
|
|
74 |
info->startup_wm_class = g_strdup (startup_wm_class);
|
|
75 |
}
|
|
76 |
}
|
|
77 |
}
|
|
78 |
|
|
79 |
static GAppInfo *
|
|
80 |
gmenu_desktopappinfo_dup (GAppInfo *appinfo)
|
|
81 |
{
|
|
82 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
83 |
GMenuDesktopAppInfo *new_info;
|
|
84 |
|
|
85 |
new_info = g_object_new (GMENU_TYPE_DESKTOPAPPINFO, NULL);
|
|
86 |
|
|
87 |
new_info->super_appinfo = G_DESKTOP_APP_INFO (g_app_info_dup(G_APP_INFO(info->super_appinfo)));
|
|
88 |
|
|
89 |
update_app_data (new_info);
|
|
90 |
|
|
91 |
return G_APP_INFO (new_info);
|
|
92 |
}
|
|
93 |
|
|
94 |
static gboolean
|
|
95 |
gmenu_desktopappinfo_equal (GAppInfo *appinfo1,
|
|
96 |
GAppInfo *appinfo2)
|
|
97 |
{
|
|
98 |
GMenuDesktopAppInfo *info1 = GMENU_DESKTOPAPPINFO (appinfo1);
|
|
99 |
GMenuDesktopAppInfo *info2 = GMENU_DESKTOPAPPINFO (appinfo2);
|
|
100 |
|
|
101 |
if (info1->desktop_id == NULL ||
|
|
102 |
info2->desktop_id == NULL)
|
|
103 |
return info1 == info2;
|
|
104 |
|
|
105 |
return strcmp (info1->desktop_id, info2->desktop_id) == 0;
|
|
106 |
}
|
|
107 |
|
|
108 |
static const char *
|
|
109 |
gmenu_desktopappinfo_get_id (GAppInfo *appinfo)
|
|
110 |
{
|
|
111 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
112 |
|
|
113 |
return info->desktop_id;
|
|
114 |
}
|
|
115 |
|
|
116 |
static const char *
|
|
117 |
gmenu_desktopappinfo_get_name (GAppInfo *appinfo)
|
|
118 |
{
|
|
119 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
120 |
return g_app_info_get_name (G_APP_INFO(info->super_appinfo));
|
|
121 |
}
|
|
122 |
|
|
123 |
static const char *
|
|
124 |
gmenu_desktopappinfo_get_description (GAppInfo *appinfo)
|
|
125 |
{
|
|
126 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
127 |
return g_app_info_get_description (G_APP_INFO(info->super_appinfo));
|
|
128 |
}
|
|
129 |
|
|
130 |
static const char *
|
|
131 |
gmenu_desktopappinfo_get_executable (GAppInfo *appinfo)
|
|
132 |
{
|
|
133 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
134 |
return g_app_info_get_executable (G_APP_INFO(info->super_appinfo));
|
|
135 |
}
|
|
136 |
|
|
137 |
static GIcon *
|
|
138 |
gmenu_desktopappinfo_get_icon (GAppInfo *appinfo)
|
|
139 |
{
|
|
140 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
141 |
return g_app_info_get_icon (G_APP_INFO(info->super_appinfo));
|
|
142 |
}
|
|
143 |
|
|
144 |
static gboolean
|
|
145 |
gmenu_desktopappinfo_launch (GAppInfo *appinfo, GList *files, GAppLaunchContext *launch_context, GError **error)
|
|
146 |
{
|
|
147 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
148 |
return g_app_info_launch (G_APP_INFO(info->super_appinfo), files, launch_context, error);
|
|
149 |
}
|
|
150 |
|
|
151 |
static gboolean
|
|
152 |
gmenu_desktopappinfo_supports_uris (GAppInfo *appinfo)
|
|
153 |
{
|
|
154 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
155 |
return g_app_info_supports_uris (G_APP_INFO(info->super_appinfo));
|
|
156 |
}
|
|
157 |
|
|
158 |
static gboolean
|
|
159 |
gmenu_desktopappinfo_supports_files (GAppInfo *appinfo)
|
|
160 |
{
|
|
161 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
162 |
return g_app_info_supports_files (G_APP_INFO(info->super_appinfo));
|
|
163 |
}
|
|
164 |
|
|
165 |
static gboolean
|
|
166 |
gmenu_desktopappinfo_launch_uris (GAppInfo *appinfo,
|
|
167 |
GList *uris,
|
|
168 |
GAppLaunchContext *launch_context,
|
|
169 |
GError **error)
|
|
170 |
{
|
|
171 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
172 |
return g_app_info_launch_uris (G_APP_INFO(info->super_appinfo), uris, launch_context, error);
|
|
173 |
}
|
|
174 |
|
|
175 |
static gboolean
|
|
176 |
gmenu_desktopappinfo_should_show (GAppInfo *appinfo)
|
|
177 |
{
|
|
178 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
179 |
return g_app_info_should_show (G_APP_INFO(info->super_appinfo));
|
|
180 |
}
|
|
181 |
|
|
182 |
static gboolean
|
|
183 |
gmenu_desktopappinfo_set_as_default_for_type (GAppInfo *appinfo,
|
|
184 |
const char *content_type,
|
|
185 |
GError **error)
|
|
186 |
{
|
|
187 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
188 |
return g_app_info_set_as_default_for_type (G_APP_INFO(info->super_appinfo), content_type, error);
|
|
189 |
}
|
|
190 |
|
|
191 |
static gboolean
|
|
192 |
gmenu_desktopappinfo_set_as_default_for_extension (GAppInfo *appinfo,
|
|
193 |
const char *extension,
|
|
194 |
GError **error)
|
|
195 |
{
|
|
196 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
197 |
return g_app_info_set_as_default_for_extension (G_APP_INFO(info->super_appinfo), extension, error);
|
|
198 |
}
|
|
199 |
|
|
200 |
static gboolean
|
|
201 |
gmenu_desktopappinfo_add_supports_type (GAppInfo *appinfo,
|
|
202 |
const char *content_type,
|
|
203 |
GError **error)
|
|
204 |
{
|
|
205 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
206 |
return g_app_info_add_supports_type (G_APP_INFO(info->super_appinfo), content_type, error);
|
|
207 |
}
|
|
208 |
|
|
209 |
static gboolean
|
|
210 |
gmenu_desktopappinfo_can_remove_supports_type (GAppInfo *appinfo)
|
|
211 |
{
|
|
212 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
213 |
return g_app_info_can_remove_supports_type (G_APP_INFO(info->super_appinfo));
|
|
214 |
}
|
|
215 |
|
|
216 |
static gboolean
|
|
217 |
gmenu_desktopappinfo_remove_supports_type (GAppInfo *appinfo,
|
|
218 |
const char *content_type,
|
|
219 |
GError **error)
|
|
220 |
{
|
|
221 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
222 |
return g_app_info_remove_supports_type (G_APP_INFO(info->super_appinfo), content_type, error);
|
|
223 |
}
|
|
224 |
|
|
225 |
static gboolean
|
|
226 |
gmenu_desktopappinfo_can_delete (GAppInfo *appinfo)
|
|
227 |
{
|
|
228 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
229 |
return g_app_info_can_delete (G_APP_INFO(info->super_appinfo));
|
|
230 |
}
|
|
231 |
|
|
232 |
static gboolean
|
|
233 |
gmenu_desktopappinfo_delete (GAppInfo *appinfo)
|
|
234 |
{
|
|
235 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
236 |
return g_app_info_delete (G_APP_INFO(info->super_appinfo));
|
|
237 |
}
|
|
238 |
|
|
239 |
static const char *
|
|
240 |
gmenu_desktopappinfo_get_commandline (GAppInfo *appinfo)
|
|
241 |
{
|
|
242 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
243 |
return g_app_info_get_commandline (G_APP_INFO(info->super_appinfo));
|
|
244 |
}
|
|
245 |
|
|
246 |
static const char *
|
|
247 |
gmenu_desktopappinfo_get_display_name (GAppInfo *appinfo)
|
|
248 |
{
|
|
249 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
250 |
return g_app_info_get_display_name (G_APP_INFO(info->super_appinfo));
|
|
251 |
}
|
|
252 |
|
|
253 |
static gboolean
|
|
254 |
gmenu_desktopappinfo_set_as_last_used_for_type (GAppInfo *appinfo,
|
|
255 |
const char *content_type,
|
|
256 |
GError **error)
|
|
257 |
{
|
|
258 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
259 |
return g_app_info_set_as_last_used_for_type (G_APP_INFO(info->super_appinfo), content_type, error);
|
|
260 |
}
|
|
261 |
|
|
262 |
static const char **
|
|
263 |
gmenu_desktopappinfo_get_supported_types (GAppInfo *appinfo)
|
|
264 |
{
|
|
265 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
266 |
return g_app_info_get_supported_types (G_APP_INFO(info->super_appinfo));
|
|
267 |
}
|
|
268 |
|
|
269 |
static void
|
|
270 |
gmenu_desktopappinfo_interface_init (GAppInfoIface *iface)
|
|
271 |
{
|
|
272 |
iface->dup = gmenu_desktopappinfo_dup;
|
|
273 |
iface->equal = gmenu_desktopappinfo_equal;
|
|
274 |
iface->get_id = gmenu_desktopappinfo_get_id;
|
|
275 |
iface->get_name = gmenu_desktopappinfo_get_name;
|
|
276 |
iface->get_description = gmenu_desktopappinfo_get_description;
|
|
277 |
iface->get_executable = gmenu_desktopappinfo_get_executable;
|
|
278 |
iface->get_icon = gmenu_desktopappinfo_get_icon;
|
|
279 |
iface->launch = gmenu_desktopappinfo_launch;
|
|
280 |
iface->supports_uris = gmenu_desktopappinfo_supports_uris;
|
|
281 |
iface->supports_files = gmenu_desktopappinfo_supports_files;
|
|
282 |
iface->launch_uris = gmenu_desktopappinfo_launch_uris;
|
|
283 |
iface->should_show = gmenu_desktopappinfo_should_show;
|
|
284 |
iface->set_as_default_for_type = gmenu_desktopappinfo_set_as_default_for_type;
|
|
285 |
iface->set_as_default_for_extension = gmenu_desktopappinfo_set_as_default_for_extension;
|
|
286 |
iface->add_supports_type = gmenu_desktopappinfo_add_supports_type;
|
|
287 |
iface->can_remove_supports_type = gmenu_desktopappinfo_can_remove_supports_type;
|
|
288 |
iface->remove_supports_type = gmenu_desktopappinfo_remove_supports_type;
|
|
289 |
iface->can_delete = gmenu_desktopappinfo_can_delete;
|
|
290 |
iface->do_delete = gmenu_desktopappinfo_delete;
|
|
291 |
iface->get_commandline = gmenu_desktopappinfo_get_commandline;
|
|
292 |
iface->get_display_name = gmenu_desktopappinfo_get_display_name;
|
|
293 |
iface->set_as_last_used_for_type = gmenu_desktopappinfo_set_as_last_used_for_type;
|
|
294 |
iface->get_supported_types = gmenu_desktopappinfo_get_supported_types;
|
|
295 |
}
|
|
296 |
|
|
297 |
G_DEFINE_TYPE_WITH_CODE (GMenuDesktopAppInfo, gmenu_desktopappinfo, G_TYPE_OBJECT,
|
|
298 |
G_IMPLEMENT_INTERFACE (G_TYPE_APP_INFO, gmenu_desktopappinfo_interface_init))
|
|
299 |
|
|
300 |
static void
|
|
301 |
gmenu_desktopappinfo_init (GMenuDesktopAppInfo *info)
|
|
302 |
{
|
|
303 |
info->super_appinfo = NULL;
|
|
304 |
info->desktop_id = NULL;
|
|
305 |
info->flatpak_app_id = NULL;
|
|
306 |
info->startup_wm_class = NULL;
|
|
307 |
}
|
|
308 |
|
|
309 |
static void
|
|
310 |
gmenu_desktopappinfo_finalize (GObject *object)
|
|
311 |
{
|
|
312 |
/* TODO: Add deinitalization code here */
|
|
313 |
|
|
314 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (object);
|
|
315 |
|
|
316 |
g_free (info->desktop_id);
|
|
317 |
g_free (info->startup_wm_class);
|
|
318 |
g_free (info->flatpak_app_id);
|
|
319 |
|
|
320 |
if (info->super_appinfo)
|
|
321 |
g_object_unref (info->super_appinfo);
|
|
322 |
}
|
|
323 |
|
|
324 |
static void
|
|
325 |
gmenu_desktopappinfo_class_init (GMenuDesktopAppInfoClass *klass)
|
|
326 |
{
|
|
327 |
GObjectClass* object_class = G_OBJECT_CLASS (klass);
|
|
328 |
|
|
329 |
object_class->finalize = gmenu_desktopappinfo_finalize;
|
|
330 |
}
|
|
331 |
|
|
332 |
/**
|
|
333 |
* gmenu_desktopappinfo_new:
|
|
334 |
* @desktop_id: the desktop file id
|
|
335 |
*
|
|
336 |
* This is currently unused in Cinnamon and does not make sense here
|
|
337 |
* because the desktop id as used here is not necessarily unique
|
|
338 |
*
|
|
339 |
* Returns: (nullable): %NULL
|
|
340 |
*/
|
|
341 |
GMenuDesktopAppInfo*
|
|
342 |
gmenu_desktopappinfo_new (const char *desktop_id)
|
|
343 |
{
|
|
344 |
return NULL;
|
|
345 |
}
|
|
346 |
|
|
347 |
/**
|
|
348 |
* gmenu_desktopappinfo_new_from_filename:
|
|
349 |
* @filename: (type filename): the path of a desktop file, in the GLib
|
|
350 |
* filename encoding
|
|
351 |
*
|
|
352 |
* Creates a new #GMenuDesktopAppInfo.
|
|
353 |
*
|
|
354 |
* Returns: (nullable): a new #GMenuDesktopAppInfo or %NULL on error.
|
|
355 |
**/
|
|
356 |
GMenuDesktopAppInfo*
|
|
357 |
gmenu_desktopappinfo_new_from_filename (gchar *filename)
|
|
358 |
{
|
|
359 |
GMenuDesktopAppInfo *info = NULL;
|
|
360 |
|
|
361 |
info = g_object_new (GMENU_TYPE_DESKTOPAPPINFO, NULL);
|
|
362 |
info->super_appinfo = g_desktop_app_info_new_from_filename (filename);
|
|
363 |
|
|
364 |
if (info->super_appinfo)
|
|
365 |
{
|
|
366 |
update_app_data (info);
|
|
367 |
return info;
|
|
368 |
} else {
|
|
369 |
g_object_unref (info);
|
|
370 |
return NULL;
|
|
371 |
}
|
|
372 |
}
|
|
373 |
|
|
374 |
/**
|
|
375 |
* gmenu_desktopappinfo_new_from_keyfile:
|
|
376 |
* @key_file: an opened #GKeyFile
|
|
377 |
*
|
|
378 |
* Creates a new #GMenuDesktopAppInfo.
|
|
379 |
*
|
|
380 |
* Returns: (nullable): a new #GMenuDesktopAppInfo or %NULL on error.
|
|
381 |
**/
|
|
382 |
GMenuDesktopAppInfo*
|
|
383 |
gmenu_desktopappinfo_new_from_keyfile (GKeyFile *keyfile)
|
|
384 |
{
|
|
385 |
GMenuDesktopAppInfo *info = NULL;
|
|
386 |
|
|
387 |
info = g_object_new (GMENU_TYPE_DESKTOPAPPINFO, NULL);
|
|
388 |
info->super_appinfo = g_desktop_app_info_new_from_keyfile (keyfile);
|
|
389 |
|
|
390 |
if (info->super_appinfo)
|
|
391 |
{
|
|
392 |
update_app_data (info);
|
|
393 |
return info;
|
|
394 |
} else {
|
|
395 |
g_object_unref (info);
|
|
396 |
return NULL;
|
|
397 |
}
|
|
398 |
}
|
|
399 |
|
|
400 |
/**
|
|
401 |
* gmenu_desktopappinfo_get_filename:
|
|
402 |
* @appinfo: a #MenuGDesktopAppInfo
|
|
403 |
*
|
|
404 |
* When @info was created from a known filename, return it. In some
|
|
405 |
* situations such as the #GMenuDesktopAppInfo returned from
|
|
406 |
* gmenu_desktopappinfo_new_from_keyfile(), this function will return %NULL.
|
|
407 |
*
|
|
408 |
* Returns: (type filename): The full path to the file for @info,
|
|
409 |
* or %NULL if not known.
|
|
410 |
* Since: 2.24
|
|
411 |
*/
|
|
412 |
const char * gmenu_desktopappinfo_get_filename (GMenuDesktopAppInfo *appinfo)
|
|
413 |
{
|
|
414 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
415 |
return g_desktop_app_info_get_filename (info->super_appinfo);
|
|
416 |
}
|
|
417 |
|
|
418 |
/**
|
|
419 |
* gmenu_desktopappinfo_get_generic_name:
|
|
420 |
* @appinfo: a #MenuGDesktopAppInfo
|
|
421 |
*
|
|
422 |
* Gets the generic name from the destkop file.
|
|
423 |
*
|
|
424 |
* Returns: The value of the GenericName key
|
|
425 |
*/
|
|
426 |
const char * gmenu_desktopappinfo_get_generic_name (GMenuDesktopAppInfo *appinfo)
|
|
427 |
{
|
|
428 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
429 |
return g_desktop_app_info_get_generic_name (info->super_appinfo);
|
|
430 |
}
|
|
431 |
|
|
432 |
/**
|
|
433 |
* gmenu_desktopappinfo_get_categories:
|
|
434 |
* @appinfo: a #GMenuDesktopAppInfo
|
|
435 |
*
|
|
436 |
* Gets the categories from the desktop file.
|
|
437 |
*
|
|
438 |
* Returns: The unparsed Categories key from the desktop file;
|
|
439 |
* i.e. no attempt is made to split it by ';' or validate it.
|
|
440 |
*/
|
|
441 |
const char * gmenu_desktopappinfo_get_categories (GMenuDesktopAppInfo *appinfo)
|
|
442 |
{
|
|
443 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
444 |
return g_desktop_app_info_get_categories (info->super_appinfo);
|
|
445 |
}
|
|
446 |
|
|
447 |
/**
|
|
448 |
* gmenu_desktopappinfo_get_keywords:
|
|
449 |
* @appinfo: a #GMenuDesktopAppInfo
|
|
450 |
*
|
|
451 |
* Gets the keywords from the desktop file.
|
|
452 |
*
|
|
453 |
* Returns: (transfer none): The value of the Keywords key
|
|
454 |
*/
|
|
455 |
const char * const *gmenu_desktopappinfo_get_keywords (GMenuDesktopAppInfo *appinfo)
|
|
456 |
{
|
|
457 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
458 |
return g_desktop_app_info_get_keywords (info->super_appinfo);
|
|
459 |
}
|
|
460 |
|
|
461 |
/**
|
|
462 |
* gmenu_desktopappinfo_get_nodisplay:
|
|
463 |
* @appinfo: a #GMenuDesktopAppInfo
|
|
464 |
*
|
|
465 |
* Gets the value of the NoDisplay key, which helps determine if the
|
|
466 |
* application info should be shown in menus. See
|
|
467 |
* #G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY and g_app_info_should_show().
|
|
468 |
*
|
|
469 |
* Returns: The value of the NoDisplay key
|
|
470 |
*/
|
|
471 |
gboolean gmenu_desktopappinfo_get_nodisplay (GMenuDesktopAppInfo *appinfo)
|
|
472 |
{
|
|
473 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
474 |
return g_desktop_app_info_get_nodisplay (info->super_appinfo);
|
|
475 |
}
|
|
476 |
|
|
477 |
/**
|
|
478 |
* gmenu_desktopappinfo_get_show_in:
|
|
479 |
* @appinfo: a #GMenuDesktopAppInfo
|
|
480 |
* @desktop_env: (nullable): a string specifying a desktop name
|
|
481 |
*
|
|
482 |
* Checks if the application info should be shown in menus that list available
|
|
483 |
* applications for a specific name of the desktop, based on the
|
|
484 |
* `OnlyShowIn` and `NotShowIn` keys.
|
|
485 |
*
|
|
486 |
* @desktop_env should typically be given as %NULL, in which case the
|
|
487 |
* `XDG_CURRENT_DESKTOP` environment variable is consulted. If you want
|
|
488 |
* to override the default mechanism then you may specify @desktop_env,
|
|
489 |
* but this is not recommended.
|
|
490 |
*
|
|
491 |
* Note that g_app_info_should_show() for @info will include this check (with
|
|
492 |
* %NULL for @desktop_env) as well as additional checks.
|
|
493 |
*
|
|
494 |
* Returns: %TRUE if the @info should be shown in @desktop_env according to the
|
|
495 |
* `OnlyShowIn` and `NotShowIn` keys, %FALSE
|
|
496 |
* otherwise.
|
|
497 |
*/
|
|
498 |
gboolean gmenu_desktopappinfo_get_show_in (GMenuDesktopAppInfo *appinfo, const gchar *desktop_env)
|
|
499 |
{
|
|
500 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
501 |
return g_desktop_app_info_get_show_in (info->super_appinfo, desktop_env);
|
|
502 |
}
|
|
503 |
|
|
504 |
/**
|
|
505 |
* gmenu_desktopappinfo_get_startup_wm_class:
|
|
506 |
* @appinfo: a #GMenuDesktopAppInfo that supports startup notify
|
|
507 |
*
|
|
508 |
* Retrieves the StartupWMClass field from @info. This represents the
|
|
509 |
* WM_CLASS property of the main window of the application, if launched
|
|
510 |
* through @info.
|
|
511 |
*
|
|
512 |
* Note: The returned value contain the suffix ":flatpak" if @info specifies a flatpak app
|
|
513 |
* and if the desktop file has a StartupWMClass
|
|
514 |
*
|
|
515 |
* Returns: (transfer none): the startup WM class, or %NULL if none is set
|
|
516 |
* in the desktop file.
|
|
517 |
*/
|
|
518 |
const char * gmenu_desktopappinfo_get_startup_wm_class (GMenuDesktopAppInfo *appinfo)
|
|
519 |
{
|
|
520 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
521 |
|
|
522 |
return info->startup_wm_class;
|
|
523 |
}
|
|
524 |
|
|
525 |
/**
|
|
526 |
* gmenu_desktopappinfo_get_is_hidden:
|
|
527 |
* @appinfo: a #GMenuDesktopAppInfo.
|
|
528 |
*
|
|
529 |
* A desktop file is hidden if the Hidden key in it is
|
|
530 |
* set to True.
|
|
531 |
*
|
|
532 |
* Returns: %TRUE if hidden, %FALSE otherwise.
|
|
533 |
**/
|
|
534 |
gboolean gmenu_desktopappinfo_get_is_hidden (GMenuDesktopAppInfo *appinfo)
|
|
535 |
{
|
|
536 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
537 |
return g_desktop_app_info_get_is_hidden (info->super_appinfo);
|
|
538 |
}
|
|
539 |
|
|
540 |
/**
|
|
541 |
* gmenu_desktopappinfo_has_key:
|
|
542 |
* @appinfo: a #GMenuDesktopAppInfo
|
|
543 |
* @key: the key to look up
|
|
544 |
*
|
|
545 |
* Returns whether @key exists in the "Desktop Entry" group
|
|
546 |
* of the keyfile backing @info.
|
|
547 |
*
|
|
548 |
* Returns: %TRUE if the @key exists
|
|
549 |
*/
|
|
550 |
gboolean gmenu_desktopappinfo_has_key (GMenuDesktopAppInfo *appinfo, const char *key)
|
|
551 |
{
|
|
552 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
553 |
return g_desktop_app_info_has_key (info->super_appinfo, key);
|
|
554 |
}
|
|
555 |
|
|
556 |
/**
|
|
557 |
* gmenu_desktopappinfo_get_string:
|
|
558 |
* @appinfo: a #GMenuDesktopAppInfo
|
|
559 |
* @key: the key to look up
|
|
560 |
*
|
|
561 |
* Looks up a string value in the keyfile backing @info.
|
|
562 |
*
|
|
563 |
* The @key is looked up in the "Desktop Entry" group.
|
|
564 |
*
|
|
565 |
* Returns: a newly allocated string, or %NULL if the key
|
|
566 |
* is not found
|
|
567 |
*/
|
|
568 |
char * gmenu_desktopappinfo_get_string (GMenuDesktopAppInfo *appinfo, const char *key)
|
|
569 |
{
|
|
570 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
571 |
return g_desktop_app_info_get_string (info->super_appinfo, key);
|
|
572 |
}
|
|
573 |
|
|
574 |
/**
|
|
575 |
* gmenu_desktopappinfo_get_locale_string:
|
|
576 |
* @appinfo: a #GMenuDesktopAppInfo
|
|
577 |
* @key: the key to look up
|
|
578 |
*
|
|
579 |
* Looks up a localized string value in the keyfile backing @info
|
|
580 |
* translated to the current locale.
|
|
581 |
*
|
|
582 |
* The @key is looked up in the "Desktop Entry" group.
|
|
583 |
*
|
|
584 |
* Returns: (nullable): a newly allocated string, or %NULL if the key
|
|
585 |
* is not found
|
|
586 |
*/
|
|
587 |
char * gmenu_desktopappinfo_get_locale_string (GMenuDesktopAppInfo *appinfo, const char *key)
|
|
588 |
{
|
|
589 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
590 |
return g_desktop_app_info_get_locale_string (info->super_appinfo, key);
|
|
591 |
}
|
|
592 |
|
|
593 |
/**
|
|
594 |
* gmenu_desktopappinfo_get_boolean:
|
|
595 |
* @appinfo: a #GMenuDesktopAppInfo
|
|
596 |
* @key: the key to look up
|
|
597 |
*
|
|
598 |
* Looks up a boolean value in the keyfile backing @info.
|
|
599 |
*
|
|
600 |
* The @key is looked up in the "Desktop Entry" group.
|
|
601 |
*
|
|
602 |
* Returns: the boolean value, or %FALSE if the key
|
|
603 |
* is not found
|
|
604 |
*/
|
|
605 |
gboolean gmenu_desktopappinfo_get_boolean (GMenuDesktopAppInfo *appinfo, const char *key)
|
|
606 |
{
|
|
607 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
608 |
return g_desktop_app_info_get_boolean (info->super_appinfo, key);
|
|
609 |
}
|
|
610 |
|
|
611 |
/**
|
|
612 |
* gmenu_desktopappinfo_list_actions:
|
|
613 |
* @appinfo: a #GMenuDesktopAppInfo
|
|
614 |
*
|
|
615 |
* Returns the list of "additional application actions" supported on the
|
|
616 |
* desktop file, as per the desktop file specification.
|
|
617 |
*
|
|
618 |
* As per the specification, this is the list of actions that are
|
|
619 |
* explicitly listed in the "Actions" key of the [Desktop Entry] group.
|
|
620 |
*
|
|
621 |
* Returns: (array zero-terminated=1) (element-type utf8) (transfer none): a list of strings, always non-%NULL
|
|
622 |
**/
|
|
623 |
const gchar * const * gmenu_desktopappinfo_list_actions (GMenuDesktopAppInfo *appinfo)
|
|
624 |
{
|
|
625 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
626 |
return g_desktop_app_info_list_actions (info->super_appinfo);
|
|
627 |
}
|
|
628 |
|
|
629 |
/**
|
|
630 |
* gmenu_desktopappinfo_launch_action:
|
|
631 |
* @appinfo: a #GMenuDesktopAppInfo
|
|
632 |
* @action_name: the name of the action as from
|
|
633 |
* g_desktop_app_info_list_actions()
|
|
634 |
* @launch_context: (nullable): a #GAppLaunchContext
|
|
635 |
*
|
|
636 |
* Activates the named application action.
|
|
637 |
*
|
|
638 |
* You may only call this function on action names that were
|
|
639 |
* returned from g_desktop_app_info_list_actions().
|
|
640 |
*
|
|
641 |
* Note that if the main entry of the desktop file indicates that the
|
|
642 |
* application supports startup notification, and @launch_context is
|
|
643 |
* non-%NULL, then startup notification will be used when activating the
|
|
644 |
* action (and as such, invocation of the action on the receiving side
|
|
645 |
* must signal the end of startup notification when it is completed).
|
|
646 |
* This is the expected behaviour of applications declaring additional
|
|
647 |
* actions, as per the desktop file specification.
|
|
648 |
*
|
|
649 |
* As with g_app_info_launch() there is no way to detect failures that
|
|
650 |
* occur while using this function.
|
|
651 |
*/
|
|
652 |
void gmenu_desktopappinfo_launch_action (GMenuDesktopAppInfo *appinfo, const gchar *action_name, GAppLaunchContext *launch_context)
|
|
653 |
{
|
|
654 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
655 |
g_desktop_app_info_launch_action (info->super_appinfo, action_name, launch_context);
|
|
656 |
}
|
|
657 |
|
|
658 |
/**
|
|
659 |
* gmenu_desktopappinfo_get_action_name:
|
|
660 |
* @appinfo: a #GMenuDesktopAppInfo
|
|
661 |
* @action_name: the name of the action as from
|
|
662 |
* gmenu_desktopappinfo_list_actions()
|
|
663 |
*
|
|
664 |
* Gets the user-visible display name of the "additional application
|
|
665 |
* action" specified by @action_name.
|
|
666 |
*
|
|
667 |
* This corresponds to the "Name" key within the keyfile group for the
|
|
668 |
* action.
|
|
669 |
*
|
|
670 |
* Returns: (transfer full): the locale-specific action name
|
|
671 |
*
|
|
672 |
* Since: 2.38
|
|
673 |
*/
|
|
674 |
gchar * gmenu_desktopappinfo_get_action_name (GMenuDesktopAppInfo *appinfo, const gchar *action_name)
|
|
675 |
{
|
|
676 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
677 |
return g_desktop_app_info_get_action_name (info->super_appinfo, action_name);
|
|
678 |
}
|
|
679 |
|
|
680 |
/**
|
|
681 |
* gmenu_desktopappinfo_launch_uris_as_manager:
|
|
682 |
* @appinfo: a #GMenuDesktopAppInfo
|
|
683 |
* @uris: (element-type utf8): List of URIs
|
|
684 |
* @launch_context: (nullable): a #GAppLaunchContext
|
|
685 |
* @spawn_flags: #GSpawnFlags, used for each process
|
|
686 |
* @user_setup: (scope async) (nullable): a #GSpawnChildSetupFunc, used once
|
|
687 |
* for each process.
|
|
688 |
* @user_setup_data: (closure user_setup) (nullable): User data for @user_setup
|
|
689 |
* @pid_callback: (scope call) (nullable): Callback for child processes
|
|
690 |
* @pid_callback_data: (closure pid_callback) (nullable): User data for @callback
|
|
691 |
* @error: return location for a #GError, or %NULL
|
|
692 |
*
|
|
693 |
* This function performs the equivalent of g_app_info_launch_uris(),
|
|
694 |
* but is intended primarily for operating system components that
|
|
695 |
* launch applications. Ordinary applications should use
|
|
696 |
* g_app_info_launch_uris().
|
|
697 |
*
|
|
698 |
* If the application is launched via GSpawn, then @spawn_flags, @user_setup
|
|
699 |
* and @user_setup_data are used for the call to g_spawn_async().
|
|
700 |
* Additionally, @pid_callback (with @pid_callback_data) will be called to
|
|
701 |
* inform about the PID of the created process. See g_spawn_async_with_pipes()
|
|
702 |
* for information on certain parameter conditions that can enable an
|
|
703 |
* optimized posix_spawn() codepath to be used.
|
|
704 |
*
|
|
705 |
* If application launching occurs via some other mechanism (eg: D-Bus
|
|
706 |
* activation) then @spawn_flags, @user_setup, @user_setup_data,
|
|
707 |
* @pid_callback and @pid_callback_data are ignored.
|
|
708 |
*
|
|
709 |
* Returns: %TRUE on successful launch, %FALSE otherwise.
|
|
710 |
*/
|
|
711 |
gboolean gmenu_desktopappinfo_launch_uris_as_manager (GMenuDesktopAppInfo *appinfo,
|
|
712 |
GList *uris,
|
|
713 |
GAppLaunchContext *launch_context,
|
|
714 |
GSpawnFlags spawn_flags,
|
|
715 |
GSpawnChildSetupFunc user_setup,
|
|
716 |
gpointer user_setup_data,
|
|
717 |
GDesktopAppLaunchCallback pid_callback,
|
|
718 |
gpointer pid_callback_data,
|
|
719 |
GError **error)
|
|
720 |
{
|
|
721 |
GMenuDesktopAppInfo *info = GMENU_DESKTOPAPPINFO (appinfo);
|
|
722 |
return g_desktop_app_info_launch_uris_as_manager (info->super_appinfo,
|
|
723 |
uris,
|
|
724 |
launch_context,
|
|
725 |
spawn_flags,
|
|
726 |
user_setup,
|
|
727 |
user_setup_data,
|
|
728 |
pid_callback,
|
|
729 |
pid_callback_data,
|
|
730 |
error);
|
|
731 |
}
|
|
732 |
|
|
733 |
/**
|
|
734 |
* gmenu_desktopappinfo_get_is_flatpak:
|
|
735 |
* @appinfo: a #GMenuMenuDesktopAppInfo
|
|
736 |
*
|
|
737 |
* Returns: %TRUE if @info specifies a flatpak app, %FALSE otherwise
|
|
738 |
*/
|
|
739 |
gboolean gmenu_desktopappinfo_get_is_flatpak (GMenuDesktopAppInfo *appinfo)
|
|
740 |
{
|
|
741 |
return appinfo->is_flatpak;
|
|
742 |
}
|
|
743 |
|
|
744 |
/**
|
|
745 |
* gmenu_desktopappinfo_get_flatpak_app_id:
|
|
746 |
* @appinfo: a #GMenuMenuDesktopAppInfo
|
|
747 |
*
|
|
748 |
* This function looks up the "X-Flatpak" key of the [Desktop Entry] group,
|
|
749 |
* which contains the Flatpak App ID
|
|
750 |
*
|
|
751 |
* Returns: (nullable): the flatpak app id or %NULL
|
|
752 |
*/
|
|
753 |
const char *
|
|
754 |
gmenu_desktopappinfo_get_flatpak_app_id (GMenuDesktopAppInfo *appinfo)
|
|
755 |
{
|
|
756 |
return appinfo->flatpak_app_id;
|
|
757 |
}
|