2007-11-26 17:13:05 +01:00
|
|
|
|
/* GIO - GLib Input, Output and Streaming Library
|
2011-05-02 05:02:53 +02:00
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
|
* Copyright (C) 2006-2007 Red Hat, Inc.
|
|
|
|
|
* Copyright © 2007 Ryan Lortie
|
|
|
|
|
*
|
2022-05-18 10:12:45 +02:00
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
2017-05-27 18:21:30 +02:00
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2007-11-26 17:13:05 +01:00
|
|
|
|
*
|
|
|
|
|
* 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
|
2014-01-23 12:58:29 +01:00
|
|
|
|
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2007-11-26 17:13:05 +01:00
|
|
|
|
*
|
|
|
|
|
* Author: Alexander Larsson <alexl@redhat.com>
|
2013-04-29 22:37:55 +02:00
|
|
|
|
* Ryan Lortie <desrt@desrt.ca>
|
2007-11-26 17:13:05 +01:00
|
|
|
|
*/
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* Prelude {{{1 */
|
|
|
|
|
|
2008-06-22 17:10:51 +02:00
|
|
|
|
#include "config.h"
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2019-05-27 20:50:09 +02:00
|
|
|
|
/* For the #GDesktopAppInfoLookup macros; since macro deprecation is implemented
|
|
|
|
|
* in the preprocessor, we need to define this before including glib.h*/
|
2020-07-27 16:40:13 +02:00
|
|
|
|
#ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
|
2019-05-27 20:50:09 +02:00
|
|
|
|
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
2020-07-27 16:40:13 +02:00
|
|
|
|
#endif
|
2019-05-27 20:50:09 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2007-12-27 05:23:57 +01:00
|
|
|
|
#ifdef HAVE_CRT_EXTERNS_H
|
|
|
|
|
#include <crt_externs.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
#include "gcontenttypeprivate.h"
|
|
|
|
|
#include "gdesktopappinfo.h"
|
2013-01-25 18:05:26 +01:00
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
|
#include "glib-unix.h"
|
|
|
|
|
#endif
|
2008-07-01 08:32:35 +02:00
|
|
|
|
#include "gfile.h"
|
2007-11-26 17:13:05 +01:00
|
|
|
|
#include "gioerror.h"
|
|
|
|
|
#include "gthemedicon.h"
|
|
|
|
|
#include "gfileicon.h"
|
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
#include "glibintl.h"
|
2022-07-14 17:43:57 +02:00
|
|
|
|
#include "glib-private.h"
|
2008-01-29 16:11:54 +01:00
|
|
|
|
#include "giomodule-priv.h"
|
2008-07-01 08:32:35 +02:00
|
|
|
|
#include "gappinfo.h"
|
2013-09-25 15:19:43 +02:00
|
|
|
|
#include "gappinfoprivate.h"
|
2015-01-12 20:59:35 +01:00
|
|
|
|
#include "glocalfilemonitor.h"
|
2022-10-31 16:56:23 +01:00
|
|
|
|
#include "gutilsprivate.h"
|
2007-11-28 13:39:07 +01:00
|
|
|
|
|
2017-05-06 20:22:38 +02:00
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
|
#include "gdocumentportal.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-12-18 03:52:11 +01:00
|
|
|
|
/**
|
2023-10-25 14:11:07 +02:00
|
|
|
|
* GDesktopAppInfo:
|
2010-05-09 05:28:17 +02:00
|
|
|
|
*
|
2023-10-25 14:11:07 +02:00
|
|
|
|
* `GDesktopAppInfo` is an implementation of [iface@Gio.AppInfo] based on
|
2007-12-18 03:52:11 +01:00
|
|
|
|
* desktop files.
|
2010-05-09 05:28:17 +02:00
|
|
|
|
*
|
2014-02-09 08:07:26 +01:00
|
|
|
|
* Note that `<gio/gdesktopappinfo.h>` belongs to the UNIX-specific
|
2014-02-06 02:17:46 +01:00
|
|
|
|
* GIO interfaces, thus you have to use the `gio-unix-2.0.pc` pkg-config
|
|
|
|
|
* file when using it.
|
2008-12-31 08:47:19 +01:00
|
|
|
|
*/
|
2007-12-18 03:52:11 +01:00
|
|
|
|
|
2010-05-09 05:28:17 +02:00
|
|
|
|
#define DEFAULT_APPLICATIONS_GROUP "Default Applications"
|
|
|
|
|
#define ADDED_ASSOCIATIONS_GROUP "Added Associations"
|
|
|
|
|
#define REMOVED_ASSOCIATIONS_GROUP "Removed Associations"
|
2007-11-26 17:13:05 +01:00
|
|
|
|
#define MIME_CACHE_GROUP "MIME Cache"
|
2011-04-27 17:34:23 +02:00
|
|
|
|
#define GENERIC_NAME_KEY "GenericName"
|
2009-11-18 23:37:47 +01:00
|
|
|
|
#define FULL_NAME_KEY "X-GNOME-FullName"
|
2011-12-19 14:52:10 +01:00
|
|
|
|
#define KEYWORDS_KEY "Keywords"
|
2012-04-05 23:26:12 +02:00
|
|
|
|
#define STARTUP_WM_CLASS_KEY "StartupWMClass"
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2011-04-26 21:08:54 +02:00
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_FILENAME
|
|
|
|
|
};
|
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
static void g_desktop_app_info_iface_init (GAppInfoIface *iface);
|
|
|
|
|
static gboolean g_desktop_app_info_ensure_saved (GDesktopAppInfo *info,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
GError **error);
|
2021-12-13 22:43:44 +01:00
|
|
|
|
static gboolean g_desktop_app_info_load_file (GDesktopAppInfo *self);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
struct _GDesktopAppInfo
|
|
|
|
|
{
|
|
|
|
|
GObject parent_instance;
|
|
|
|
|
|
|
|
|
|
char *desktop_id;
|
|
|
|
|
char *filename;
|
2013-04-29 22:37:55 +02:00
|
|
|
|
char *app_id;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2012-11-17 00:22:45 +01:00
|
|
|
|
GKeyFile *keyfile;
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
char *name;
|
2011-04-27 17:34:23 +02:00
|
|
|
|
char *generic_name;
|
2009-11-18 23:37:47 +01:00
|
|
|
|
char *fullname;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
char *comment;
|
|
|
|
|
char *icon_name;
|
|
|
|
|
GIcon *icon;
|
2011-10-13 22:33:21 +02:00
|
|
|
|
char **keywords;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
char **only_show_in;
|
|
|
|
|
char **not_show_in;
|
|
|
|
|
char *try_exec;
|
|
|
|
|
char *exec;
|
|
|
|
|
char *binary;
|
|
|
|
|
char *path;
|
2011-04-15 21:52:33 +02:00
|
|
|
|
char *categories;
|
2012-04-05 23:26:12 +02:00
|
|
|
|
char *startup_wm_class;
|
2012-04-14 19:34:00 +02:00
|
|
|
|
char **mime_types;
|
2013-07-11 18:46:59 +02:00
|
|
|
|
char **actions;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
guint nodisplay : 1;
|
|
|
|
|
guint hidden : 1;
|
|
|
|
|
guint terminal : 1;
|
|
|
|
|
guint startup_notify : 1;
|
2009-02-26 15:59:16 +01:00
|
|
|
|
guint no_fuse : 1;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
};
|
|
|
|
|
|
2010-12-15 17:56:22 +01:00
|
|
|
|
typedef enum {
|
|
|
|
|
UPDATE_MIME_NONE = 1 << 0,
|
|
|
|
|
UPDATE_MIME_SET_DEFAULT = 1 << 1,
|
|
|
|
|
UPDATE_MIME_SET_NON_DEFAULT = 1 << 2,
|
|
|
|
|
UPDATE_MIME_REMOVE = 1 << 3,
|
|
|
|
|
UPDATE_MIME_SET_LAST_USED = 1 << 4,
|
|
|
|
|
} UpdateMimeFlags;
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GDesktopAppInfo, g_desktop_app_info, G_TYPE_OBJECT,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_APP_INFO, g_desktop_app_info_iface_init))
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* DesktopFileDir implementation {{{1 */
|
|
|
|
|
|
2013-07-24 23:48:37 +02:00
|
|
|
|
typedef struct
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2019-10-11 22:33:47 +02:00
|
|
|
|
gatomicrefcount ref_count;
|
2013-07-24 23:48:37 +02:00
|
|
|
|
gchar *path;
|
2014-09-09 19:58:38 +02:00
|
|
|
|
gchar *alternatively_watching;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
gboolean is_config;
|
|
|
|
|
gboolean is_setup;
|
2015-01-12 20:59:35 +01:00
|
|
|
|
GFileMonitor *monitor;
|
2013-07-27 22:04:56 +02:00
|
|
|
|
GHashTable *app_names;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
GHashTable *mime_tweaks;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
GHashTable *memory_index;
|
2013-11-15 20:40:37 +01:00
|
|
|
|
GHashTable *memory_implementations;
|
2013-07-24 23:48:37 +02:00
|
|
|
|
} DesktopFileDir;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
static GPtrArray *desktop_file_dirs = NULL;
|
2018-12-13 18:01:19 +01:00
|
|
|
|
static const gchar *desktop_file_dirs_config_dir = NULL;
|
2019-10-11 22:33:47 +02:00
|
|
|
|
static DesktopFileDir *desktop_file_dir_user_config = NULL; /* (owned) */
|
|
|
|
|
static DesktopFileDir *desktop_file_dir_user_data = NULL; /* (owned) */
|
2013-07-27 22:04:56 +02:00
|
|
|
|
static GMutex desktop_file_dir_lock;
|
2022-07-14 13:02:51 +02:00
|
|
|
|
static const gchar *gio_launch_desktop_path = NULL;
|
2013-07-27 22:04:56 +02:00
|
|
|
|
|
|
|
|
|
/* Monitor 'changed' signal handler {{{2 */
|
|
|
|
|
static void desktop_file_dir_reset (DesktopFileDir *dir);
|
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
static DesktopFileDir *
|
|
|
|
|
desktop_file_dir_ref (DesktopFileDir *dir)
|
|
|
|
|
{
|
|
|
|
|
g_atomic_ref_count_inc (&dir->ref_count);
|
|
|
|
|
|
|
|
|
|
return dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_unref (DesktopFileDir *dir)
|
|
|
|
|
{
|
|
|
|
|
if (g_atomic_ref_count_dec (&dir->ref_count))
|
|
|
|
|
{
|
|
|
|
|
desktop_file_dir_reset (dir);
|
|
|
|
|
g_free (dir->path);
|
|
|
|
|
g_free (dir);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-09 19:58:38 +02:00
|
|
|
|
/*< internal >
|
|
|
|
|
* desktop_file_dir_get_alternative_dir:
|
|
|
|
|
* @dir: a #DesktopFileDir
|
|
|
|
|
*
|
|
|
|
|
* Gets the "alternative" directory to monitor in case the path
|
|
|
|
|
* doesn't exist.
|
|
|
|
|
*
|
|
|
|
|
* If the path exists this will return NULL, otherwise it will return a
|
|
|
|
|
* parent directory of the path.
|
|
|
|
|
*
|
|
|
|
|
* This is used to avoid inotify on a non-existent directory (which
|
|
|
|
|
* results in polling).
|
|
|
|
|
*
|
|
|
|
|
* See https://bugzilla.gnome.org/show_bug.cgi?id=522314 for more info.
|
|
|
|
|
*/
|
|
|
|
|
static gchar *
|
|
|
|
|
desktop_file_dir_get_alternative_dir (DesktopFileDir *dir)
|
|
|
|
|
{
|
|
|
|
|
gchar *parent;
|
|
|
|
|
|
|
|
|
|
/* If the directory itself exists then we need no alternative. */
|
|
|
|
|
if (g_access (dir->path, R_OK | X_OK) == 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* Otherwise, try the parent directories until we find one. */
|
|
|
|
|
parent = g_path_get_dirname (dir->path);
|
|
|
|
|
|
|
|
|
|
while (g_access (parent, R_OK | X_OK) != 0)
|
|
|
|
|
{
|
|
|
|
|
gchar *tmp = parent;
|
|
|
|
|
|
|
|
|
|
parent = g_path_get_dirname (tmp);
|
|
|
|
|
|
|
|
|
|
/* If somehow we get to '/' or '.' then just stop... */
|
|
|
|
|
if (g_str_equal (parent, tmp))
|
|
|
|
|
{
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_changed (GFileMonitor *monitor,
|
|
|
|
|
GFile *file,
|
|
|
|
|
GFile *other_file,
|
|
|
|
|
GFileMonitorEvent event_type,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
DesktopFileDir *dir = user_data;
|
2014-09-09 19:58:38 +02:00
|
|
|
|
gboolean do_nothing = FALSE;
|
2013-07-27 22:04:56 +02:00
|
|
|
|
|
|
|
|
|
/* We are not interested in receiving notifications forever just
|
|
|
|
|
* because someone asked about one desktop file once.
|
|
|
|
|
*
|
|
|
|
|
* After we receive the first notification, reset the dir, destroying
|
|
|
|
|
* the monitor. We will take this as a hint, next time that we are
|
|
|
|
|
* asked, that we need to check if everything is up to date.
|
2014-09-09 19:58:38 +02:00
|
|
|
|
*
|
|
|
|
|
* If this is a notification for a parent directory (because the
|
|
|
|
|
* desktop directory didn't exist) then we shouldn't fire the signal
|
|
|
|
|
* unless something actually changed.
|
2013-07-27 22:04:56 +02:00
|
|
|
|
*/
|
|
|
|
|
g_mutex_lock (&desktop_file_dir_lock);
|
|
|
|
|
|
2014-09-09 19:58:38 +02:00
|
|
|
|
if (dir->alternatively_watching)
|
|
|
|
|
{
|
|
|
|
|
gchar *alternative_dir;
|
|
|
|
|
|
|
|
|
|
alternative_dir = desktop_file_dir_get_alternative_dir (dir);
|
|
|
|
|
do_nothing = alternative_dir && g_str_equal (dir->alternatively_watching, alternative_dir);
|
|
|
|
|
g_free (alternative_dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!do_nothing)
|
|
|
|
|
desktop_file_dir_reset (dir);
|
2013-07-27 22:04:56 +02:00
|
|
|
|
|
|
|
|
|
g_mutex_unlock (&desktop_file_dir_lock);
|
2013-09-25 15:19:43 +02:00
|
|
|
|
|
|
|
|
|
/* Notify anyone else who may be interested */
|
2014-09-09 19:58:38 +02:00
|
|
|
|
if (!do_nothing)
|
|
|
|
|
g_app_info_monitor_fire ();
|
2013-07-27 22:04:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Internal utility functions {{{2 */
|
|
|
|
|
|
|
|
|
|
/*< internal >
|
|
|
|
|
* desktop_file_dir_app_name_is_masked:
|
|
|
|
|
* @dir: a #DesktopFileDir
|
|
|
|
|
* @app_name: an application ID
|
|
|
|
|
*
|
|
|
|
|
* Checks if @app_name is masked for @dir.
|
|
|
|
|
*
|
|
|
|
|
* An application is masked if a similarly-named desktop file exists in
|
|
|
|
|
* a desktop file directory with higher precedence. Masked desktop
|
|
|
|
|
* files should be ignored.
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
|
|
|
|
desktop_file_dir_app_name_is_masked (DesktopFileDir *dir,
|
|
|
|
|
const gchar *app_name)
|
|
|
|
|
{
|
2019-10-11 22:33:47 +02:00
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < desktop_file_dirs->len; i++)
|
2013-07-27 22:04:56 +02:00
|
|
|
|
{
|
2019-10-11 22:33:47 +02:00
|
|
|
|
DesktopFileDir *i_dir = g_ptr_array_index (desktop_file_dirs, i);
|
2013-07-27 22:04:56 +02:00
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
if (dir == i_dir)
|
|
|
|
|
return FALSE;
|
|
|
|
|
if (i_dir->app_names && g_hash_table_contains (i_dir->app_names, app_name))
|
2013-07-27 22:04:56 +02:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-05 00:38:18 +01:00
|
|
|
|
/* Not much to go on from https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
|
|
|
|
|
* so validate it as a non-empty alphanumeric ASCII string with `-` and `_` allowed.
|
|
|
|
|
*
|
|
|
|
|
* Validation is important as the desktop IDs are used to construct filenames,
|
|
|
|
|
* and may be set by an unprivileged caller if running in a setuid program. */
|
|
|
|
|
static gboolean
|
|
|
|
|
validate_xdg_desktop (const gchar *desktop)
|
|
|
|
|
{
|
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; desktop[i] != '\0'; i++)
|
|
|
|
|
if (desktop[i] != '-' && desktop[i] != '_' &&
|
|
|
|
|
!g_ascii_isalnum (desktop[i]))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-09 15:29:03 +01:00
|
|
|
|
static char **
|
|
|
|
|
get_valid_current_desktops (const char *value)
|
|
|
|
|
{
|
|
|
|
|
char **tmp;
|
|
|
|
|
gsize i;
|
|
|
|
|
GPtrArray *valid_desktops;
|
|
|
|
|
|
|
|
|
|
if (value == NULL)
|
|
|
|
|
value = g_getenv ("XDG_CURRENT_DESKTOP");
|
|
|
|
|
if (value == NULL)
|
|
|
|
|
value = "";
|
|
|
|
|
|
|
|
|
|
tmp = g_strsplit (value, G_SEARCHPATH_SEPARATOR_S, 0);
|
|
|
|
|
valid_desktops = g_ptr_array_new_full (g_strv_length (tmp) + 1, g_free);
|
|
|
|
|
for (i = 0; tmp[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
if (validate_xdg_desktop (tmp[i]))
|
|
|
|
|
g_ptr_array_add (valid_desktops, tmp[i]);
|
|
|
|
|
else
|
|
|
|
|
g_free (tmp[i]);
|
|
|
|
|
}
|
|
|
|
|
g_ptr_array_add (valid_desktops, NULL);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
tmp = (char **) g_ptr_array_steal (valid_desktops, NULL);
|
|
|
|
|
g_ptr_array_unref (valid_desktops);
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
static const gchar * const *
|
|
|
|
|
get_lowercase_current_desktops (void)
|
|
|
|
|
{
|
|
|
|
|
static gchar **result;
|
|
|
|
|
|
2023-09-12 08:59:52 +02:00
|
|
|
|
if (g_once_init_enter_pointer (&result))
|
2014-04-09 14:44:18 +02:00
|
|
|
|
{
|
2021-01-09 15:29:03 +01:00
|
|
|
|
char **tmp = get_valid_current_desktops (NULL);
|
|
|
|
|
gsize i, j;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
2021-01-09 15:29:03 +01:00
|
|
|
|
for (i = 0; tmp[i]; i++)
|
2014-04-09 14:44:18 +02:00
|
|
|
|
{
|
2021-01-09 15:29:03 +01:00
|
|
|
|
/* Convert to lowercase. */
|
|
|
|
|
for (j = 0; tmp[i][j]; j++)
|
|
|
|
|
tmp[i][j] = g_ascii_tolower (tmp[i][j]);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-12 08:59:52 +02:00
|
|
|
|
g_once_init_leave_pointer (&result, tmp);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (const gchar **) result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 14:57:50 +02:00
|
|
|
|
static const gchar * const *
|
|
|
|
|
get_current_desktops (const gchar *value)
|
|
|
|
|
{
|
|
|
|
|
static gchar **result;
|
|
|
|
|
|
2023-09-12 08:59:52 +02:00
|
|
|
|
if (g_once_init_enter_pointer (&result))
|
2014-05-08 14:57:50 +02:00
|
|
|
|
{
|
2021-01-09 15:29:03 +01:00
|
|
|
|
char **tmp = get_valid_current_desktops (value);
|
2014-05-08 14:57:50 +02:00
|
|
|
|
|
2023-09-12 08:59:52 +02:00
|
|
|
|
g_once_init_leave_pointer (&result, tmp);
|
2014-05-08 14:57:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (const gchar **) result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
/*< internal >
|
|
|
|
|
* add_to_table_if_appropriate:
|
|
|
|
|
* @apps: a string to GDesktopAppInfo hash table
|
|
|
|
|
* @app_name: the name of the application
|
|
|
|
|
* @info: a #GDesktopAppInfo, or NULL
|
|
|
|
|
*
|
|
|
|
|
* If @info is non-%NULL and non-hidden, then add it to @apps, using
|
|
|
|
|
* @app_name as a key.
|
|
|
|
|
*
|
|
|
|
|
* If @info is non-%NULL then this function will consume the passed-in
|
|
|
|
|
* reference.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
add_to_table_if_appropriate (GHashTable *apps,
|
|
|
|
|
const gchar *app_name,
|
|
|
|
|
GDesktopAppInfo *info)
|
|
|
|
|
{
|
|
|
|
|
if (!info)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (info->hidden)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (info);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (info->desktop_id);
|
|
|
|
|
info->desktop_id = g_strdup (app_name);
|
|
|
|
|
|
|
|
|
|
g_hash_table_insert (apps, g_strdup (info->desktop_id), info);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 04:51:48 +01:00
|
|
|
|
enum
|
|
|
|
|
{
|
2014-03-02 15:38:51 +01:00
|
|
|
|
DESKTOP_KEY_Exec,
|
2013-11-06 04:51:48 +01:00
|
|
|
|
DESKTOP_KEY_GenericName,
|
|
|
|
|
DESKTOP_KEY_Keywords,
|
|
|
|
|
DESKTOP_KEY_Name,
|
|
|
|
|
DESKTOP_KEY_X_GNOME_FullName,
|
|
|
|
|
|
|
|
|
|
N_DESKTOP_KEYS
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const gchar desktop_key_match_category[N_DESKTOP_KEYS] = {
|
|
|
|
|
/* Note: lower numbers are a better match.
|
|
|
|
|
*
|
|
|
|
|
* In case we want two keys to match at the same level, we can just
|
|
|
|
|
* use the same number for the two different keys.
|
|
|
|
|
*/
|
|
|
|
|
[DESKTOP_KEY_Name] = 1,
|
2014-03-02 15:38:51 +01:00
|
|
|
|
[DESKTOP_KEY_Exec] = 2,
|
|
|
|
|
[DESKTOP_KEY_Keywords] = 3,
|
|
|
|
|
[DESKTOP_KEY_GenericName] = 4,
|
2023-10-03 12:58:40 +02:00
|
|
|
|
[DESKTOP_KEY_X_GNOME_FullName] = 5
|
2013-11-06 04:51:48 +01:00
|
|
|
|
};
|
|
|
|
|
|
2022-12-06 04:24:45 +01:00
|
|
|
|
typedef enum {
|
|
|
|
|
/* Lower numbers have higher priority.
|
2023-09-25 04:29:53 +02:00
|
|
|
|
* Prefix match should put before substring match, independently of
|
|
|
|
|
* category relevance, i.e. a prefix match in 'Keyword' category will
|
|
|
|
|
* come before a substring match in a more relevant category like 'Name'.
|
2022-12-06 04:24:45 +01:00
|
|
|
|
*/
|
|
|
|
|
MATCH_TYPE_PREFIX = 1,
|
|
|
|
|
MATCH_TYPE_SUBSTRING = 2
|
|
|
|
|
} MatchType;
|
|
|
|
|
|
2018-04-23 19:50:45 +02:00
|
|
|
|
/* Common prefix commands to ignore from Exec= lines */
|
2020-06-12 15:02:30 +02:00
|
|
|
|
const char * const exec_key_match_blocklist[] = {
|
2018-04-23 19:50:45 +02:00
|
|
|
|
"bash",
|
|
|
|
|
"env",
|
|
|
|
|
"flatpak",
|
|
|
|
|
"gjs",
|
|
|
|
|
"pkexec",
|
|
|
|
|
"python",
|
|
|
|
|
"python2",
|
|
|
|
|
"python3",
|
|
|
|
|
"sh",
|
|
|
|
|
"wine",
|
|
|
|
|
"wine64",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-06 04:51:48 +01:00
|
|
|
|
static gchar *
|
|
|
|
|
desktop_key_get_name (guint key_id)
|
|
|
|
|
{
|
|
|
|
|
switch (key_id)
|
|
|
|
|
{
|
2014-03-02 15:38:51 +01:00
|
|
|
|
case DESKTOP_KEY_Exec:
|
|
|
|
|
return "Exec";
|
2013-11-06 04:51:48 +01:00
|
|
|
|
case DESKTOP_KEY_GenericName:
|
2014-09-04 15:39:19 +02:00
|
|
|
|
return GENERIC_NAME_KEY;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
case DESKTOP_KEY_Keywords:
|
2014-09-04 15:39:19 +02:00
|
|
|
|
return KEYWORDS_KEY;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
case DESKTOP_KEY_Name:
|
|
|
|
|
return "Name";
|
|
|
|
|
case DESKTOP_KEY_X_GNOME_FullName:
|
2014-09-04 15:39:19 +02:00
|
|
|
|
return FULL_NAME_KEY;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Search global state {{{2
|
|
|
|
|
*
|
|
|
|
|
* We only ever search under a global lock, so we can use (and reuse)
|
|
|
|
|
* some global data to reduce allocations made while searching.
|
|
|
|
|
*
|
|
|
|
|
* In short, we keep around arrays of results that we expand as needed
|
|
|
|
|
* (and never shrink).
|
|
|
|
|
*
|
|
|
|
|
* static_token_results: this is where we append the results for each
|
|
|
|
|
* token within a given desktop directory, as we handle it (which is
|
|
|
|
|
* a union of all matches for this term)
|
|
|
|
|
*
|
|
|
|
|
* static_search_results: this is where we build the complete results
|
|
|
|
|
* for a single directory (which is an intersection of the matches
|
|
|
|
|
* found for each term)
|
|
|
|
|
*
|
|
|
|
|
* static_total_results: this is where we build the complete results
|
|
|
|
|
* across all directories (which is a union of the matches found in
|
|
|
|
|
* each directory)
|
|
|
|
|
*
|
|
|
|
|
* The app_names that enter these tables are always pointer-unique (in
|
|
|
|
|
* the sense that string equality is the same as pointer equality).
|
|
|
|
|
* This can be guaranteed for two reasons:
|
|
|
|
|
*
|
|
|
|
|
* - we mask appids so that a given appid will only ever appear within
|
|
|
|
|
* the highest-precedence directory that contains it. We never
|
|
|
|
|
* return search results from a lower-level directory if a desktop
|
|
|
|
|
* file exists in a higher-level one.
|
|
|
|
|
*
|
|
|
|
|
* - within a given directory, the string is unique because it's the
|
|
|
|
|
* key in the hashtable of all app_ids for that directory.
|
|
|
|
|
*
|
|
|
|
|
* We perform a merging of the results in merge_token_results(). This
|
|
|
|
|
* works by ordering the two lists and moving through each of them (at
|
|
|
|
|
* the same time) looking for common elements, rejecting uncommon ones.
|
|
|
|
|
* "Order" here need not mean any particular thing, as long as it is
|
|
|
|
|
* some order. Because of the uniqueness of our strings, we can use
|
|
|
|
|
* pointer order. That's what's going on in compare_results() below.
|
|
|
|
|
*/
|
|
|
|
|
struct search_result
|
|
|
|
|
{
|
|
|
|
|
const gchar *app_name;
|
|
|
|
|
gint category;
|
2022-12-06 04:24:45 +01:00
|
|
|
|
gint match_type;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct search_result *static_token_results;
|
|
|
|
|
static gint static_token_results_size;
|
|
|
|
|
static gint static_token_results_allocated;
|
|
|
|
|
static struct search_result *static_search_results;
|
|
|
|
|
static gint static_search_results_size;
|
|
|
|
|
static gint static_search_results_allocated;
|
|
|
|
|
static struct search_result *static_total_results;
|
|
|
|
|
static gint static_total_results_size;
|
|
|
|
|
static gint static_total_results_allocated;
|
|
|
|
|
|
|
|
|
|
/* And some functions for performing nice operations against it */
|
|
|
|
|
static gint
|
|
|
|
|
compare_results (gconstpointer a,
|
|
|
|
|
gconstpointer b)
|
|
|
|
|
{
|
|
|
|
|
const struct search_result *ra = a;
|
|
|
|
|
const struct search_result *rb = b;
|
|
|
|
|
|
|
|
|
|
if (ra->app_name < rb->app_name)
|
2022-12-06 04:24:45 +01:00
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2013-11-06 04:51:48 +01:00
|
|
|
|
else if (ra->app_name > rb->app_name)
|
2022-12-06 04:24:45 +01:00
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2013-11-06 04:51:48 +01:00
|
|
|
|
else
|
2022-12-06 04:24:45 +01:00
|
|
|
|
{
|
2023-09-25 04:29:53 +02:00
|
|
|
|
/* We prioritize prefix matches over category relevance e.g. a prefix match in 'Keyword'
|
|
|
|
|
* category is better than a substring match in a more relevance category like 'Name'.
|
|
|
|
|
*/
|
|
|
|
|
if (ra->match_type != rb->match_type)
|
2022-12-06 04:24:45 +01:00
|
|
|
|
return ra->match_type - rb->match_type;
|
|
|
|
|
|
|
|
|
|
return ra->category - rb->category;
|
|
|
|
|
}
|
2013-11-06 04:51:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
compare_categories (gconstpointer a,
|
|
|
|
|
gconstpointer b)
|
|
|
|
|
{
|
|
|
|
|
const struct search_result *ra = a;
|
|
|
|
|
const struct search_result *rb = b;
|
|
|
|
|
|
2023-09-25 04:29:53 +02:00
|
|
|
|
/* We prioritize prefix matches over category relevance e.g. a prefix match in 'Keyword'
|
|
|
|
|
* category is better than a substring match in a more relevance category like 'Name'.
|
2022-12-06 04:24:45 +01:00
|
|
|
|
*/
|
2023-09-25 04:29:53 +02:00
|
|
|
|
if (ra->match_type != rb->match_type)
|
2022-12-06 04:24:45 +01:00
|
|
|
|
return ra->match_type - rb->match_type;
|
|
|
|
|
|
2013-11-06 04:51:48 +01:00
|
|
|
|
return ra->category - rb->category;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
add_token_result (const gchar *app_name,
|
2022-12-06 04:24:45 +01:00
|
|
|
|
guint16 category,
|
|
|
|
|
guint16 match_type)
|
2013-11-06 04:51:48 +01:00
|
|
|
|
{
|
|
|
|
|
if G_UNLIKELY (static_token_results_size == static_token_results_allocated)
|
|
|
|
|
{
|
|
|
|
|
static_token_results_allocated = MAX (16, static_token_results_allocated * 2);
|
|
|
|
|
static_token_results = g_renew (struct search_result, static_token_results, static_token_results_allocated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static_token_results[static_token_results_size].app_name = app_name;
|
|
|
|
|
static_token_results[static_token_results_size].category = category;
|
2022-12-06 04:24:45 +01:00
|
|
|
|
static_token_results[static_token_results_size].match_type = match_type;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
static_token_results_size++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
merge_token_results (gboolean first)
|
|
|
|
|
{
|
2016-12-02 11:03:16 +01:00
|
|
|
|
if (static_token_results_size != 0)
|
|
|
|
|
qsort (static_token_results, static_token_results_size, sizeof (struct search_result), compare_results);
|
2013-11-06 04:51:48 +01:00
|
|
|
|
|
|
|
|
|
/* If this is the first token then we are basically merging a list with
|
|
|
|
|
* itself -- we only perform de-duplication.
|
|
|
|
|
*
|
|
|
|
|
* If this is not the first token then we are doing a real merge.
|
|
|
|
|
*/
|
|
|
|
|
if (first)
|
|
|
|
|
{
|
|
|
|
|
const gchar *last_name = NULL;
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
/* We must de-duplicate, but we do so by taking the best category
|
|
|
|
|
* in each case.
|
|
|
|
|
*
|
|
|
|
|
* The final list can be as large as the input here, so make sure
|
|
|
|
|
* we have enough room (even if it's too much room).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if G_UNLIKELY (static_search_results_allocated < static_token_results_size)
|
|
|
|
|
{
|
|
|
|
|
static_search_results_allocated = static_token_results_allocated;
|
|
|
|
|
static_search_results = g_renew (struct search_result,
|
|
|
|
|
static_search_results,
|
|
|
|
|
static_search_results_allocated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < static_token_results_size; i++)
|
|
|
|
|
{
|
|
|
|
|
/* The list is sorted so that the best match for a given id
|
|
|
|
|
* will be at the front, so once we have copied an id, skip
|
|
|
|
|
* the rest of the entries for the same id.
|
|
|
|
|
*/
|
|
|
|
|
if (static_token_results[i].app_name == last_name)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
last_name = static_token_results[i].app_name;
|
|
|
|
|
|
|
|
|
|
static_search_results[static_search_results_size++] = static_token_results[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const gchar *last_name = NULL;
|
|
|
|
|
gint i, j = 0;
|
|
|
|
|
gint k = 0;
|
|
|
|
|
|
|
|
|
|
/* We only ever remove items from the results list, so no need to
|
|
|
|
|
* resize to ensure that we have enough room.
|
|
|
|
|
*/
|
|
|
|
|
for (i = 0; i < static_token_results_size; i++)
|
|
|
|
|
{
|
|
|
|
|
if (static_token_results[i].app_name == last_name)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
last_name = static_token_results[i].app_name;
|
|
|
|
|
|
|
|
|
|
/* Now we only want to have a result in static_search_results
|
|
|
|
|
* if we already have it there *and* we have it in
|
|
|
|
|
* static_token_results as well. The category will be the
|
|
|
|
|
* lesser of the two.
|
|
|
|
|
*
|
|
|
|
|
* Skip past the results in static_search_results that are not
|
|
|
|
|
* going to be matches.
|
|
|
|
|
*/
|
|
|
|
|
while (k < static_search_results_size &&
|
|
|
|
|
static_search_results[k].app_name < static_token_results[i].app_name)
|
|
|
|
|
k++;
|
|
|
|
|
|
|
|
|
|
if (k < static_search_results_size &&
|
|
|
|
|
static_search_results[k].app_name == static_token_results[i].app_name)
|
|
|
|
|
{
|
|
|
|
|
/* We have a match.
|
|
|
|
|
*
|
|
|
|
|
* Category should be the worse of the two (ie:
|
|
|
|
|
* numerically larger).
|
2022-12-06 04:24:45 +01:00
|
|
|
|
*
|
|
|
|
|
* Match type should also be the worse, so if an app has two
|
|
|
|
|
* prefix matches it will has higher priority than one prefix
|
|
|
|
|
* matches and one substring matches, for example, LibreOffice
|
|
|
|
|
* Writer should be higher priority than LibreOffice Draw with
|
|
|
|
|
* `lib w`.
|
|
|
|
|
*
|
|
|
|
|
* (This ignores the difference between partly prefix matches and
|
|
|
|
|
* all substring matches, however most time we just focus on exact
|
|
|
|
|
* prefix matches, who cares the 10th-20th search results?)
|
2013-11-06 04:51:48 +01:00
|
|
|
|
*/
|
|
|
|
|
static_search_results[j].app_name = static_search_results[k].app_name;
|
|
|
|
|
static_search_results[j].category = MAX (static_search_results[k].category,
|
|
|
|
|
static_token_results[i].category);
|
2022-12-06 04:24:45 +01:00
|
|
|
|
static_search_results[j].match_type = MAX (static_search_results[k].match_type,
|
|
|
|
|
static_token_results[i].match_type);
|
2013-11-06 04:51:48 +01:00
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static_search_results_size = j;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Clear it out for next time... */
|
|
|
|
|
static_token_results_size = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
reset_total_search_results (void)
|
|
|
|
|
{
|
|
|
|
|
static_total_results_size = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sort_total_search_results (void)
|
|
|
|
|
{
|
2016-12-02 11:03:16 +01:00
|
|
|
|
if (static_total_results_size != 0)
|
|
|
|
|
qsort (static_total_results, static_total_results_size, sizeof (struct search_result), compare_categories);
|
2013-11-06 04:51:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
merge_directory_results (void)
|
|
|
|
|
{
|
|
|
|
|
if G_UNLIKELY (static_total_results_size + static_search_results_size > static_total_results_allocated)
|
|
|
|
|
{
|
|
|
|
|
static_total_results_allocated = MAX (16, static_total_results_allocated);
|
|
|
|
|
while (static_total_results_allocated < static_total_results_size + static_search_results_size)
|
|
|
|
|
static_total_results_allocated *= 2;
|
|
|
|
|
static_total_results = g_renew (struct search_result, static_total_results, static_total_results_allocated);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-02 13:52:35 +02:00
|
|
|
|
if (static_search_results_size != 0)
|
2016-12-02 11:03:16 +01:00
|
|
|
|
memcpy (static_total_results + static_total_results_size,
|
|
|
|
|
static_search_results,
|
|
|
|
|
static_search_results_size * sizeof (struct search_result));
|
2013-11-06 04:51:48 +01:00
|
|
|
|
|
|
|
|
|
static_total_results_size += static_search_results_size;
|
|
|
|
|
|
|
|
|
|
/* Clear it out for next time... */
|
|
|
|
|
static_search_results_size = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
/* Support for unindexed DesktopFileDirs {{{2 */
|
|
|
|
|
static void
|
|
|
|
|
get_apps_from_dir (GHashTable **apps,
|
|
|
|
|
const char *dirname,
|
|
|
|
|
const char *prefix)
|
|
|
|
|
{
|
|
|
|
|
const char *basename;
|
|
|
|
|
GDir *dir;
|
|
|
|
|
|
|
|
|
|
dir = g_dir_open (dirname, 0, NULL);
|
|
|
|
|
|
|
|
|
|
if (dir == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
while ((basename = g_dir_read_name (dir)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
|
|
filename = g_build_filename (dirname, basename, NULL);
|
|
|
|
|
|
|
|
|
|
if (g_str_has_suffix (basename, ".desktop"))
|
|
|
|
|
{
|
|
|
|
|
gchar *app_name;
|
|
|
|
|
|
|
|
|
|
app_name = g_strconcat (prefix, basename, NULL);
|
|
|
|
|
|
|
|
|
|
if (*apps == NULL)
|
|
|
|
|
*apps = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
|
|
|
|
|
|
|
|
|
g_hash_table_insert (*apps, app_name, g_strdup (filename));
|
|
|
|
|
}
|
|
|
|
|
else if (g_file_test (filename, G_FILE_TEST_IS_DIR))
|
|
|
|
|
{
|
|
|
|
|
gchar *subprefix;
|
|
|
|
|
|
|
|
|
|
subprefix = g_strconcat (prefix, basename, "-", NULL);
|
|
|
|
|
get_apps_from_dir (apps, filename, subprefix);
|
|
|
|
|
g_free (subprefix);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_dir_close (dir);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
gchar **additions;
|
|
|
|
|
gchar **removals;
|
|
|
|
|
gchar **defaults;
|
|
|
|
|
} UnindexedMimeTweaks;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
free_mime_tweaks (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
UnindexedMimeTweaks *tweaks = data;
|
|
|
|
|
|
|
|
|
|
g_strfreev (tweaks->additions);
|
|
|
|
|
g_strfreev (tweaks->removals);
|
|
|
|
|
g_strfreev (tweaks->defaults);
|
|
|
|
|
|
|
|
|
|
g_slice_free (UnindexedMimeTweaks, tweaks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static UnindexedMimeTweaks *
|
|
|
|
|
desktop_file_dir_unindexed_get_tweaks (DesktopFileDir *dir,
|
|
|
|
|
const gchar *mime_type)
|
|
|
|
|
{
|
|
|
|
|
UnindexedMimeTweaks *tweaks;
|
|
|
|
|
gchar *unaliased_type;
|
|
|
|
|
|
|
|
|
|
unaliased_type = _g_unix_content_type_unalias (mime_type);
|
2014-09-04 19:17:27 +02:00
|
|
|
|
tweaks = g_hash_table_lookup (dir->mime_tweaks, unaliased_type);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
if (tweaks == NULL)
|
|
|
|
|
{
|
|
|
|
|
tweaks = g_slice_new0 (UnindexedMimeTweaks);
|
|
|
|
|
g_hash_table_insert (dir->mime_tweaks, unaliased_type, tweaks);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
g_free (unaliased_type);
|
|
|
|
|
|
|
|
|
|
return tweaks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* consumes 'to_add' */
|
|
|
|
|
static void
|
|
|
|
|
expand_strv (gchar ***strv_ptr,
|
|
|
|
|
gchar **to_add,
|
2020-06-12 15:02:30 +02:00
|
|
|
|
gchar * const *blocklist)
|
2014-04-09 14:44:18 +02:00
|
|
|
|
{
|
|
|
|
|
guint strv_len, add_len;
|
|
|
|
|
gchar **strv;
|
|
|
|
|
guint i, j;
|
|
|
|
|
|
|
|
|
|
if (!*strv_ptr)
|
|
|
|
|
{
|
|
|
|
|
*strv_ptr = to_add;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strv = *strv_ptr;
|
|
|
|
|
strv_len = g_strv_length (strv);
|
|
|
|
|
add_len = g_strv_length (to_add);
|
|
|
|
|
strv = g_renew (gchar *, strv, strv_len + add_len + 1);
|
|
|
|
|
|
|
|
|
|
for (i = 0; to_add[i]; i++)
|
|
|
|
|
{
|
2020-06-12 15:02:30 +02:00
|
|
|
|
/* Don't add blocklisted strings */
|
|
|
|
|
if (blocklist)
|
|
|
|
|
for (j = 0; blocklist[j]; j++)
|
|
|
|
|
if (g_str_equal (to_add[i], blocklist[j]))
|
2014-04-09 14:44:18 +02:00
|
|
|
|
goto no_add;
|
|
|
|
|
|
|
|
|
|
/* Don't add duplicates already in the list */
|
2014-04-15 20:10:39 +02:00
|
|
|
|
for (j = 0; j < strv_len; j++)
|
2014-04-09 14:44:18 +02:00
|
|
|
|
if (g_str_equal (to_add[i], strv[j]))
|
|
|
|
|
goto no_add;
|
|
|
|
|
|
|
|
|
|
strv[strv_len++] = to_add[i];
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
no_add:
|
|
|
|
|
g_free (to_add[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strv[strv_len] = NULL;
|
|
|
|
|
*strv_ptr = strv;
|
|
|
|
|
|
|
|
|
|
g_free (to_add);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_unindexed_read_mimeapps_list (DesktopFileDir *dir,
|
|
|
|
|
const gchar *filename,
|
|
|
|
|
const gchar *added_group,
|
|
|
|
|
gboolean tweaks_permitted)
|
|
|
|
|
{
|
|
|
|
|
UnindexedMimeTweaks *tweaks;
|
|
|
|
|
char **desktop_file_ids;
|
|
|
|
|
GKeyFile *key_file;
|
|
|
|
|
gchar **mime_types;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
key_file = g_key_file_new ();
|
|
|
|
|
if (!g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, NULL))
|
|
|
|
|
{
|
|
|
|
|
g_key_file_free (key_file);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mime_types = g_key_file_get_keys (key_file, added_group, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if G_UNLIKELY (mime_types != NULL && !tweaks_permitted)
|
|
|
|
|
{
|
|
|
|
|
g_warning ("%s contains a [%s] group, but it is not permitted here. Only the non-desktop-specific "
|
|
|
|
|
"mimeapps.list file may add or remove associations.", filename, added_group);
|
|
|
|
|
g_strfreev (mime_types);
|
|
|
|
|
mime_types = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mime_types != NULL)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; mime_types[i] != NULL; i++)
|
|
|
|
|
{
|
|
|
|
|
desktop_file_ids = g_key_file_get_string_list (key_file, added_group, mime_types[i], NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (desktop_file_ids)
|
|
|
|
|
{
|
|
|
|
|
tweaks = desktop_file_dir_unindexed_get_tweaks (dir, mime_types[i]);
|
|
|
|
|
expand_strv (&tweaks->additions, desktop_file_ids, tweaks->removals);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_strfreev (mime_types);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-04 15:39:19 +02:00
|
|
|
|
mime_types = g_key_file_get_keys (key_file, REMOVED_ASSOCIATIONS_GROUP, NULL, NULL);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
if G_UNLIKELY (mime_types != NULL && !tweaks_permitted)
|
|
|
|
|
{
|
|
|
|
|
g_warning ("%s contains a [%s] group, but it is not permitted here. Only the non-desktop-specific "
|
2014-09-04 15:39:19 +02:00
|
|
|
|
"mimeapps.list file may add or remove associations.", filename, REMOVED_ASSOCIATIONS_GROUP);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
g_strfreev (mime_types);
|
|
|
|
|
mime_types = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mime_types != NULL)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; mime_types[i] != NULL; i++)
|
|
|
|
|
{
|
2014-09-04 15:39:19 +02:00
|
|
|
|
desktop_file_ids = g_key_file_get_string_list (key_file, REMOVED_ASSOCIATIONS_GROUP, mime_types[i], NULL, NULL);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
if (desktop_file_ids)
|
|
|
|
|
{
|
|
|
|
|
tweaks = desktop_file_dir_unindexed_get_tweaks (dir, mime_types[i]);
|
|
|
|
|
expand_strv (&tweaks->removals, desktop_file_ids, tweaks->additions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_strfreev (mime_types);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-04 15:39:19 +02:00
|
|
|
|
mime_types = g_key_file_get_keys (key_file, DEFAULT_APPLICATIONS_GROUP, NULL, NULL);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
if (mime_types != NULL)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; mime_types[i] != NULL; i++)
|
|
|
|
|
{
|
2014-09-04 15:39:19 +02:00
|
|
|
|
desktop_file_ids = g_key_file_get_string_list (key_file, DEFAULT_APPLICATIONS_GROUP, mime_types[i], NULL, NULL);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
if (desktop_file_ids)
|
|
|
|
|
{
|
|
|
|
|
tweaks = desktop_file_dir_unindexed_get_tweaks (dir, mime_types[i]);
|
|
|
|
|
expand_strv (&tweaks->defaults, desktop_file_ids, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_strfreev (mime_types);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_key_file_free (key_file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_unindexed_read_mimeapps_lists (DesktopFileDir *dir)
|
|
|
|
|
{
|
|
|
|
|
const gchar * const *desktops;
|
|
|
|
|
gchar *filename;
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
dir->mime_tweaks = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_mime_tweaks);
|
|
|
|
|
|
2020-06-12 15:02:30 +02:00
|
|
|
|
/* We process in order of precedence, using a blocklisting approach to
|
2014-04-09 14:44:18 +02:00
|
|
|
|
* avoid recording later instructions that conflict with ones we found
|
|
|
|
|
* earlier.
|
|
|
|
|
*
|
|
|
|
|
* We first start with the XDG_CURRENT_DESKTOP files, in precedence
|
|
|
|
|
* order.
|
|
|
|
|
*/
|
|
|
|
|
desktops = get_lowercase_current_desktops ();
|
|
|
|
|
for (i = 0; desktops[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
filename = g_strdup_printf ("%s/%s-mimeapps.list", dir->path, desktops[i]);
|
2014-09-04 15:39:19 +02:00
|
|
|
|
desktop_file_dir_unindexed_read_mimeapps_list (dir, filename, ADDED_ASSOCIATIONS_GROUP, FALSE);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
g_free (filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Next, the non-desktop-specific mimeapps.list */
|
|
|
|
|
filename = g_strdup_printf ("%s/mimeapps.list", dir->path);
|
2014-09-04 15:39:19 +02:00
|
|
|
|
desktop_file_dir_unindexed_read_mimeapps_list (dir, filename, ADDED_ASSOCIATIONS_GROUP, TRUE);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
g_free (filename);
|
|
|
|
|
|
|
|
|
|
/* The remaining files are only checked for in directories that might
|
|
|
|
|
* contain desktop files (ie: not the config dirs).
|
|
|
|
|
*/
|
|
|
|
|
if (dir->is_config)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* We have 'defaults.list' which was only ever understood by GLib. It
|
|
|
|
|
* exists widely, but it has never been part of any spec and it should
|
|
|
|
|
* be treated as deprecated. This will be removed in a future
|
|
|
|
|
* version.
|
|
|
|
|
*/
|
|
|
|
|
filename = g_strdup_printf ("%s/defaults.list", dir->path);
|
2014-10-15 04:14:01 +02:00
|
|
|
|
desktop_file_dir_unindexed_read_mimeapps_list (dir, filename, ADDED_ASSOCIATIONS_GROUP, FALSE);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
g_free (filename);
|
|
|
|
|
|
|
|
|
|
/* Finally, the mimeinfo.cache, which is just a cached copy of what we
|
|
|
|
|
* would find in the MimeTypes= lines of all of the desktop files.
|
|
|
|
|
*/
|
|
|
|
|
filename = g_strdup_printf ("%s/mimeinfo.cache", dir->path);
|
2014-09-04 15:39:19 +02:00
|
|
|
|
desktop_file_dir_unindexed_read_mimeapps_list (dir, filename, MIME_CACHE_GROUP, TRUE);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
g_free (filename);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_unindexed_init (DesktopFileDir *dir)
|
|
|
|
|
{
|
2014-04-09 14:44:18 +02:00
|
|
|
|
if (!dir->is_config)
|
|
|
|
|
get_apps_from_dir (&dir->app_names, dir->path, "");
|
|
|
|
|
|
|
|
|
|
desktop_file_dir_unindexed_read_mimeapps_lists (dir);
|
2013-07-27 22:04:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 22:43:44 +01:00
|
|
|
|
static GDesktopAppInfo *
|
|
|
|
|
g_desktop_app_info_new_from_filename_unlocked (const char *filename)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = NULL;
|
|
|
|
|
|
|
|
|
|
info = g_object_new (G_TYPE_DESKTOP_APP_INFO, "filename", filename, NULL);
|
|
|
|
|
|
|
|
|
|
if (!g_desktop_app_info_load_file (info))
|
|
|
|
|
g_clear_object (&info);
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
static GDesktopAppInfo *
|
|
|
|
|
desktop_file_dir_unindexed_get_app (DesktopFileDir *dir,
|
|
|
|
|
const gchar *desktop_id)
|
|
|
|
|
{
|
|
|
|
|
const gchar *filename;
|
|
|
|
|
|
|
|
|
|
filename = g_hash_table_lookup (dir->app_names, desktop_id);
|
|
|
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2021-12-13 22:43:44 +01:00
|
|
|
|
return g_desktop_app_info_new_from_filename_unlocked (filename);
|
2013-07-27 22:04:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_unindexed_get_all (DesktopFileDir *dir,
|
|
|
|
|
GHashTable *apps)
|
|
|
|
|
{
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
gpointer app_name;
|
|
|
|
|
gpointer filename;
|
|
|
|
|
|
|
|
|
|
if (dir->app_names == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, dir->app_names);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &app_name, &filename))
|
|
|
|
|
{
|
|
|
|
|
if (desktop_file_dir_app_name_is_masked (dir, app_name))
|
|
|
|
|
continue;
|
|
|
|
|
|
2021-12-13 22:43:44 +01:00
|
|
|
|
add_to_table_if_appropriate (apps, app_name, g_desktop_app_info_new_from_filename_unlocked (filename));
|
2013-07-27 22:04:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-24 23:48:37 +02:00
|
|
|
|
|
2013-11-06 04:51:48 +01:00
|
|
|
|
typedef struct _MemoryIndexEntry MemoryIndexEntry;
|
|
|
|
|
typedef GHashTable MemoryIndex;
|
|
|
|
|
|
|
|
|
|
struct _MemoryIndexEntry
|
|
|
|
|
{
|
|
|
|
|
const gchar *app_name; /* pointer to the hashtable key */
|
|
|
|
|
gint match_category;
|
|
|
|
|
MemoryIndexEntry *next;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
memory_index_entry_free (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
MemoryIndexEntry *mie = data;
|
|
|
|
|
|
|
|
|
|
while (mie)
|
|
|
|
|
{
|
|
|
|
|
MemoryIndexEntry *next = mie->next;
|
|
|
|
|
|
|
|
|
|
g_slice_free (MemoryIndexEntry, mie);
|
|
|
|
|
mie = next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
memory_index_add_token (MemoryIndex *mi,
|
|
|
|
|
const gchar *token,
|
|
|
|
|
gint match_category,
|
|
|
|
|
const gchar *app_name)
|
|
|
|
|
{
|
|
|
|
|
MemoryIndexEntry *mie, *first;
|
|
|
|
|
|
|
|
|
|
mie = g_slice_new (MemoryIndexEntry);
|
|
|
|
|
mie->app_name = app_name;
|
|
|
|
|
mie->match_category = match_category;
|
|
|
|
|
|
|
|
|
|
first = g_hash_table_lookup (mi, token);
|
|
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
|
{
|
|
|
|
|
mie->next = first->next;
|
|
|
|
|
first->next = mie;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mie->next = NULL;
|
|
|
|
|
g_hash_table_insert (mi, g_strdup (token), mie);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
memory_index_add_string (MemoryIndex *mi,
|
|
|
|
|
const gchar *string,
|
|
|
|
|
gint match_category,
|
|
|
|
|
const gchar *app_name)
|
|
|
|
|
{
|
|
|
|
|
gchar **tokens, **alternates;
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
tokens = g_str_tokenize_and_fold (string, NULL, &alternates);
|
|
|
|
|
|
|
|
|
|
for (i = 0; tokens[i]; i++)
|
|
|
|
|
memory_index_add_token (mi, tokens[i], match_category, app_name);
|
|
|
|
|
|
|
|
|
|
for (i = 0; alternates[i]; i++)
|
|
|
|
|
memory_index_add_token (mi, alternates[i], match_category, app_name);
|
|
|
|
|
|
|
|
|
|
g_strfreev (alternates);
|
|
|
|
|
g_strfreev (tokens);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MemoryIndex *
|
|
|
|
|
memory_index_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_hash_table_new_full (g_str_hash, g_str_equal, g_free, memory_index_entry_free);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_unindexed_setup_search (DesktopFileDir *dir)
|
|
|
|
|
{
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
gpointer app, path;
|
|
|
|
|
|
|
|
|
|
dir->memory_index = memory_index_new ();
|
2013-11-15 20:40:37 +01:00
|
|
|
|
dir->memory_implementations = memory_index_new ();
|
2013-11-06 04:51:48 +01:00
|
|
|
|
|
|
|
|
|
/* Nothing to search? */
|
|
|
|
|
if (dir->app_names == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, dir->app_names);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &app, &path))
|
|
|
|
|
{
|
|
|
|
|
GKeyFile *key_file;
|
|
|
|
|
|
|
|
|
|
if (desktop_file_dir_app_name_is_masked (dir, app))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
key_file = g_key_file_new ();
|
|
|
|
|
|
|
|
|
|
if (g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, NULL) &&
|
|
|
|
|
!g_key_file_get_boolean (key_file, "Desktop Entry", "Hidden", NULL))
|
|
|
|
|
{
|
|
|
|
|
/* Index the interesting keys... */
|
2013-11-15 20:40:37 +01:00
|
|
|
|
gchar **implements;
|
2020-11-17 10:56:00 +01:00
|
|
|
|
gsize i;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (desktop_key_match_category); i++)
|
|
|
|
|
{
|
2014-03-02 15:38:51 +01:00
|
|
|
|
const gchar *value;
|
|
|
|
|
gchar *raw;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
|
|
|
|
|
if (!desktop_key_match_category[i])
|
|
|
|
|
continue;
|
|
|
|
|
|
2014-03-02 15:38:51 +01:00
|
|
|
|
raw = g_key_file_get_locale_string (key_file, "Desktop Entry", desktop_key_get_name (i), NULL, NULL);
|
|
|
|
|
value = raw;
|
|
|
|
|
|
|
|
|
|
if (i == DESKTOP_KEY_Exec && raw != NULL)
|
|
|
|
|
{
|
|
|
|
|
/* Special handling: only match basename of first field */
|
|
|
|
|
gchar *space;
|
|
|
|
|
gchar *slash;
|
|
|
|
|
|
|
|
|
|
/* Remove extra arguments, if any */
|
|
|
|
|
space = raw + strcspn (raw, " \t\n"); /* IFS */
|
|
|
|
|
*space = '\0';
|
|
|
|
|
|
|
|
|
|
/* Skip the pathname, if any */
|
|
|
|
|
if ((slash = strrchr (raw, '/')))
|
|
|
|
|
value = slash + 1;
|
2018-04-23 19:50:45 +02:00
|
|
|
|
|
2020-06-12 15:02:30 +02:00
|
|
|
|
/* Don't match on blocklisted binaries like interpreters */
|
|
|
|
|
if (g_strv_contains (exec_key_match_blocklist, value))
|
2018-04-23 19:50:45 +02:00
|
|
|
|
value = NULL;
|
2014-03-02 15:38:51 +01:00
|
|
|
|
}
|
2013-11-06 04:51:48 +01:00
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
memory_index_add_string (dir->memory_index, value, desktop_key_match_category[i], app);
|
|
|
|
|
|
2014-03-02 15:38:51 +01:00
|
|
|
|
g_free (raw);
|
2013-11-06 04:51:48 +01:00
|
|
|
|
}
|
2013-11-15 20:40:37 +01:00
|
|
|
|
|
|
|
|
|
/* Make note of the Implements= line */
|
|
|
|
|
implements = g_key_file_get_string_list (key_file, "Desktop Entry", "Implements", NULL, NULL);
|
|
|
|
|
for (i = 0; implements && implements[i]; i++)
|
|
|
|
|
memory_index_add_token (dir->memory_implementations, implements[i], 0, app);
|
|
|
|
|
g_strfreev (implements);
|
2013-11-06 04:51:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_key_file_free (key_file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_unindexed_search (DesktopFileDir *dir,
|
|
|
|
|
const gchar *search_token)
|
|
|
|
|
{
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
gpointer key, value;
|
|
|
|
|
|
2022-12-29 16:57:53 +01:00
|
|
|
|
g_assert (search_token != NULL);
|
|
|
|
|
|
2013-11-06 04:51:48 +01:00
|
|
|
|
if (!dir->memory_index)
|
|
|
|
|
desktop_file_dir_unindexed_setup_search (dir);
|
|
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, dir->memory_index);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
|
{
|
|
|
|
|
MemoryIndexEntry *mie = value;
|
2022-12-06 04:24:45 +01:00
|
|
|
|
const char *p;
|
|
|
|
|
MatchType match_type;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
|
2022-12-06 04:24:45 +01:00
|
|
|
|
/* strstr(haystack, needle) returns haystack if needle is empty, so if
|
|
|
|
|
* needle is not empty and return value equals to haystack means a prefix
|
|
|
|
|
* match.
|
|
|
|
|
*/
|
|
|
|
|
p = strstr (key, search_token);
|
|
|
|
|
if (p == NULL)
|
2013-11-06 04:51:48 +01:00
|
|
|
|
continue;
|
2022-12-29 16:57:53 +01:00
|
|
|
|
else if (p == key && *search_token != '\0')
|
2022-12-06 04:24:45 +01:00
|
|
|
|
match_type = MATCH_TYPE_PREFIX;
|
|
|
|
|
else
|
|
|
|
|
match_type = MATCH_TYPE_SUBSTRING;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
|
|
|
|
|
while (mie)
|
|
|
|
|
{
|
2022-12-06 04:24:45 +01:00
|
|
|
|
add_token_result (mie->app_name, mie->match_category, match_type);
|
2013-11-06 04:51:48 +01:00
|
|
|
|
mie = mie->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
static gboolean
|
|
|
|
|
array_contains (GPtrArray *array,
|
|
|
|
|
const gchar *str)
|
|
|
|
|
{
|
2020-11-17 10:57:21 +01:00
|
|
|
|
guint i;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < array->len; i++)
|
|
|
|
|
if (g_str_equal (array->pdata[i], str))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_unindexed_mime_lookup (DesktopFileDir *dir,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
GPtrArray *hits,
|
2020-06-12 15:02:30 +02:00
|
|
|
|
GPtrArray *blocklist)
|
2014-04-09 14:44:18 +02:00
|
|
|
|
{
|
|
|
|
|
UnindexedMimeTweaks *tweaks;
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
tweaks = g_hash_table_lookup (dir->mime_tweaks, mime_type);
|
|
|
|
|
|
|
|
|
|
if (!tweaks)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (tweaks->additions)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; tweaks->additions[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
gchar *app_name = tweaks->additions[i];
|
|
|
|
|
|
|
|
|
|
if (!desktop_file_dir_app_name_is_masked (dir, app_name) &&
|
2020-06-12 15:02:30 +02:00
|
|
|
|
!array_contains (blocklist, app_name) && !array_contains (hits, app_name))
|
2015-04-02 23:17:35 +02:00
|
|
|
|
g_ptr_array_add (hits, app_name);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tweaks->removals)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; tweaks->removals[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
gchar *app_name = tweaks->removals[i];
|
|
|
|
|
|
|
|
|
|
if (!desktop_file_dir_app_name_is_masked (dir, app_name) &&
|
2020-06-12 15:02:30 +02:00
|
|
|
|
!array_contains (blocklist, app_name) && !array_contains (hits, app_name))
|
|
|
|
|
g_ptr_array_add (blocklist, app_name);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_unindexed_default_lookup (DesktopFileDir *dir,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
GPtrArray *results)
|
|
|
|
|
{
|
|
|
|
|
UnindexedMimeTweaks *tweaks;
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
tweaks = g_hash_table_lookup (dir->mime_tweaks, mime_type);
|
|
|
|
|
|
|
|
|
|
if (!tweaks || !tweaks->defaults)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (i = 0; tweaks->defaults[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
gchar *app_name = tweaks->defaults[i];
|
|
|
|
|
|
|
|
|
|
if (!array_contains (results, app_name))
|
2015-04-02 23:17:35 +02:00
|
|
|
|
g_ptr_array_add (results, app_name);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-15 20:40:37 +01:00
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_unindexed_get_implementations (DesktopFileDir *dir,
|
|
|
|
|
GList **results,
|
|
|
|
|
const gchar *interface)
|
|
|
|
|
{
|
|
|
|
|
MemoryIndexEntry *mie;
|
|
|
|
|
|
|
|
|
|
if (!dir->memory_index)
|
|
|
|
|
desktop_file_dir_unindexed_setup_search (dir);
|
|
|
|
|
|
|
|
|
|
for (mie = g_hash_table_lookup (dir->memory_implementations, interface); mie; mie = mie->next)
|
|
|
|
|
*results = g_list_prepend (*results, g_strdup (mie->app_name));
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* DesktopFileDir "API" {{{2 */
|
|
|
|
|
|
|
|
|
|
/*< internal >
|
2019-10-11 22:33:47 +02:00
|
|
|
|
* desktop_file_dir_new:
|
2013-07-27 21:08:58 +02:00
|
|
|
|
* @data_dir: an XDG_DATA_DIR
|
|
|
|
|
*
|
2019-10-11 22:33:47 +02:00
|
|
|
|
* Creates a #DesktopFileDir for the corresponding @data_dir.
|
2013-07-27 21:08:58 +02:00
|
|
|
|
*/
|
2019-10-11 22:33:47 +02:00
|
|
|
|
static DesktopFileDir *
|
|
|
|
|
desktop_file_dir_new (const gchar *data_dir)
|
2013-07-24 23:48:37 +02:00
|
|
|
|
{
|
2019-10-11 22:33:47 +02:00
|
|
|
|
DesktopFileDir *dir = g_new0 (DesktopFileDir, 1);
|
2013-07-24 23:48:37 +02:00
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
g_atomic_ref_count_init (&dir->ref_count);
|
|
|
|
|
dir->path = g_build_filename (data_dir, "applications", NULL);
|
2013-07-24 23:48:37 +02:00
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
return g_steal_pointer (&dir);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
2013-07-24 23:48:37 +02:00
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
/*< internal >
|
2019-10-11 22:33:47 +02:00
|
|
|
|
* desktop_file_dir_new_for_config:
|
2014-04-09 14:44:18 +02:00
|
|
|
|
* @config_dir: an XDG_CONFIG_DIR
|
|
|
|
|
*
|
2019-10-11 22:33:47 +02:00
|
|
|
|
* Just the same as desktop_file_dir_new() except that it does not
|
2014-04-09 14:44:18 +02:00
|
|
|
|
* add the "applications" directory. It also marks the directory as
|
|
|
|
|
* config-only, which prevents us from attempting to find desktop files
|
|
|
|
|
* here.
|
|
|
|
|
*/
|
2019-10-11 22:33:47 +02:00
|
|
|
|
static DesktopFileDir *
|
|
|
|
|
desktop_file_dir_new_for_config (const gchar *config_dir)
|
2014-04-09 14:44:18 +02:00
|
|
|
|
{
|
2019-10-11 22:33:47 +02:00
|
|
|
|
DesktopFileDir *dir = g_new0 (DesktopFileDir, 1);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
g_atomic_ref_count_init (&dir->ref_count);
|
|
|
|
|
dir->path = g_strdup (config_dir);
|
|
|
|
|
dir->is_config = TRUE;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
return g_steal_pointer (&dir);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
/*< internal >
|
|
|
|
|
* desktop_file_dir_reset:
|
|
|
|
|
* @dir: a #DesktopFileDir
|
|
|
|
|
*
|
|
|
|
|
* Cleans up @dir, releasing most resources that it was using.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_reset (DesktopFileDir *dir)
|
|
|
|
|
{
|
2014-09-09 19:58:38 +02:00
|
|
|
|
if (dir->alternatively_watching)
|
|
|
|
|
{
|
|
|
|
|
g_free (dir->alternatively_watching);
|
|
|
|
|
dir->alternatively_watching = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
if (dir->monitor)
|
|
|
|
|
{
|
|
|
|
|
g_signal_handlers_disconnect_by_func (dir->monitor, desktop_file_dir_changed, dir);
|
2019-10-11 23:19:29 +02:00
|
|
|
|
g_file_monitor_cancel (dir->monitor);
|
2013-07-27 22:04:56 +02:00
|
|
|
|
g_object_unref (dir->monitor);
|
|
|
|
|
dir->monitor = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dir->app_names)
|
|
|
|
|
{
|
|
|
|
|
g_hash_table_unref (dir->app_names);
|
|
|
|
|
dir->app_names = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 04:51:48 +01:00
|
|
|
|
if (dir->memory_index)
|
|
|
|
|
{
|
|
|
|
|
g_hash_table_unref (dir->memory_index);
|
|
|
|
|
dir->memory_index = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
if (dir->mime_tweaks)
|
|
|
|
|
{
|
|
|
|
|
g_hash_table_unref (dir->mime_tweaks);
|
|
|
|
|
dir->mime_tweaks = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-15 20:40:37 +01:00
|
|
|
|
if (dir->memory_implementations)
|
|
|
|
|
{
|
|
|
|
|
g_hash_table_unref (dir->memory_implementations);
|
|
|
|
|
dir->memory_implementations = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
dir->is_setup = FALSE;
|
|
|
|
|
}
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
static void
|
|
|
|
|
closure_notify_cb (gpointer data,
|
|
|
|
|
GClosure *closure)
|
|
|
|
|
{
|
|
|
|
|
DesktopFileDir *dir = data;
|
|
|
|
|
desktop_file_dir_unref (dir);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
/*< internal >
|
|
|
|
|
* desktop_file_dir_init:
|
|
|
|
|
* @dir: a #DesktopFileDir
|
|
|
|
|
*
|
|
|
|
|
* Does initial setup for @dir
|
|
|
|
|
*
|
|
|
|
|
* You should only call this if @dir is not already setup.
|
|
|
|
|
*/
|
2013-07-24 23:48:37 +02:00
|
|
|
|
static void
|
2013-07-27 22:04:56 +02:00
|
|
|
|
desktop_file_dir_init (DesktopFileDir *dir)
|
|
|
|
|
{
|
2014-09-09 19:58:38 +02:00
|
|
|
|
const gchar *watch_dir;
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
g_assert (!dir->is_setup);
|
|
|
|
|
|
2014-09-09 19:58:38 +02:00
|
|
|
|
g_assert (!dir->alternatively_watching);
|
2013-07-27 22:04:56 +02:00
|
|
|
|
g_assert (!dir->monitor);
|
2014-09-09 19:58:38 +02:00
|
|
|
|
|
|
|
|
|
dir->alternatively_watching = desktop_file_dir_get_alternative_dir (dir);
|
|
|
|
|
watch_dir = dir->alternatively_watching ? dir->alternatively_watching : dir->path;
|
|
|
|
|
|
|
|
|
|
/* There is a very thin race here if the watch_dir has been _removed_
|
|
|
|
|
* between when we checked for it and when we establish the watch.
|
|
|
|
|
* Removes probably don't happen in usual operation, and even if it
|
|
|
|
|
* does (and we catch the unlikely race), the only degradation is that
|
|
|
|
|
* we will fall back to polling.
|
|
|
|
|
*/
|
2015-01-12 20:59:35 +01:00
|
|
|
|
dir->monitor = g_local_file_monitor_new_in_worker (watch_dir, TRUE, G_FILE_MONITOR_NONE,
|
2019-10-11 22:33:47 +02:00
|
|
|
|
desktop_file_dir_changed,
|
|
|
|
|
desktop_file_dir_ref (dir),
|
|
|
|
|
closure_notify_cb, NULL);
|
2013-07-27 22:04:56 +02:00
|
|
|
|
|
|
|
|
|
desktop_file_dir_unindexed_init (dir);
|
|
|
|
|
|
|
|
|
|
dir->is_setup = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*< internal >
|
|
|
|
|
* desktop_file_dir_get_app:
|
|
|
|
|
* @dir: a DesktopFileDir
|
|
|
|
|
* @desktop_id: the desktop ID to load
|
|
|
|
|
*
|
|
|
|
|
* Creates the #GDesktopAppInfo for the given @desktop_id if it exists
|
|
|
|
|
* within @dir, even if it is hidden.
|
|
|
|
|
*
|
|
|
|
|
* This function does not check if @desktop_id would be masked by a
|
|
|
|
|
* directory with higher precedence. The caller must do so.
|
|
|
|
|
*/
|
|
|
|
|
static GDesktopAppInfo *
|
|
|
|
|
desktop_file_dir_get_app (DesktopFileDir *dir,
|
|
|
|
|
const gchar *desktop_id)
|
|
|
|
|
{
|
|
|
|
|
if (!dir->app_names)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return desktop_file_dir_unindexed_get_app (dir, desktop_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*< internal >
|
|
|
|
|
* desktop_file_dir_get_all:
|
|
|
|
|
* @dir: a DesktopFileDir
|
|
|
|
|
* @apps: a #GHashTable<string, GDesktopAppInfo>
|
|
|
|
|
*
|
|
|
|
|
* Loads all desktop files in @dir and adds them to @apps, careful to
|
|
|
|
|
* ensure we don't add any files masked by a similarly-named file in a
|
|
|
|
|
* higher-precedence directory.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_get_all (DesktopFileDir *dir,
|
|
|
|
|
GHashTable *apps)
|
|
|
|
|
{
|
|
|
|
|
desktop_file_dir_unindexed_get_all (dir, apps);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
/*< internal >
|
|
|
|
|
* desktop_file_dir_mime_lookup:
|
|
|
|
|
* @dir: a #DesktopFileDir
|
|
|
|
|
* @mime_type: the mime type to look up
|
|
|
|
|
* @hits: the array to store the hits
|
2020-06-12 15:02:30 +02:00
|
|
|
|
* @blocklist: the array to store the blocklist
|
2014-04-09 14:44:18 +02:00
|
|
|
|
*
|
|
|
|
|
* Does a lookup of a mimetype against one desktop file directory,
|
2020-06-12 15:02:30 +02:00
|
|
|
|
* recording any hits and blocklisting and "Removed" associations (so
|
2014-04-09 14:44:18 +02:00
|
|
|
|
* later directories don't record them as hits).
|
|
|
|
|
*
|
2020-06-12 15:02:30 +02:00
|
|
|
|
* The items added to @hits are duplicated, but the ones in @blocklist
|
|
|
|
|
* are weak pointers. This facilitates simply freeing the blocklist
|
2014-04-09 14:44:18 +02:00
|
|
|
|
* (which is only used for internal bookkeeping) but using the pdata of
|
|
|
|
|
* @hits as the result of the operation.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_mime_lookup (DesktopFileDir *dir,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
GPtrArray *hits,
|
2020-06-12 15:02:30 +02:00
|
|
|
|
GPtrArray *blocklist)
|
2014-04-09 14:44:18 +02:00
|
|
|
|
{
|
2020-06-12 15:02:30 +02:00
|
|
|
|
desktop_file_dir_unindexed_mime_lookup (dir, mime_type, hits, blocklist);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*< internal >
|
|
|
|
|
* desktop_file_dir_default_lookup:
|
|
|
|
|
* @dir: a #DesktopFileDir
|
|
|
|
|
* @mime_type: the mime type to look up
|
|
|
|
|
* @results: an array to store the results in
|
|
|
|
|
*
|
|
|
|
|
* Collects the "default" applications for a given mime type from @dir.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_default_lookup (DesktopFileDir *dir,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
GPtrArray *results)
|
|
|
|
|
{
|
|
|
|
|
desktop_file_dir_unindexed_default_lookup (dir, mime_type, results);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 04:51:48 +01:00
|
|
|
|
/*< internal >
|
|
|
|
|
* desktop_file_dir_search:
|
2014-04-09 14:44:18 +02:00
|
|
|
|
* @dir: a #DesktopFileDir
|
2013-11-06 04:51:48 +01:00
|
|
|
|
* @term: a normalised and casefolded search term
|
|
|
|
|
*
|
|
|
|
|
* Finds the names of applications in @dir that match @term.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_search (DesktopFileDir *dir,
|
|
|
|
|
const gchar *search_token)
|
|
|
|
|
{
|
|
|
|
|
desktop_file_dir_unindexed_search (dir, search_token);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-15 20:40:37 +01:00
|
|
|
|
static void
|
|
|
|
|
desktop_file_dir_get_implementations (DesktopFileDir *dir,
|
|
|
|
|
GList **results,
|
|
|
|
|
const gchar *interface)
|
|
|
|
|
{
|
|
|
|
|
desktop_file_dir_unindexed_get_implementations (dir, results, interface);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
/* Lock/unlock and global setup API {{{2 */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dirs_lock (void)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2020-11-17 10:59:52 +01:00
|
|
|
|
guint i;
|
2018-12-13 18:01:19 +01:00
|
|
|
|
const gchar *user_config_dir = g_get_user_config_dir ();
|
2013-07-27 22:04:56 +02:00
|
|
|
|
|
|
|
|
|
g_mutex_lock (&desktop_file_dir_lock);
|
|
|
|
|
|
2018-12-13 18:01:19 +01:00
|
|
|
|
/* If the XDG dirs configuration has changed (expected only during tests),
|
|
|
|
|
* clear and reload the state. */
|
2019-10-11 22:33:47 +02:00
|
|
|
|
if (desktop_file_dirs_config_dir != NULL &&
|
|
|
|
|
g_strcmp0 (desktop_file_dirs_config_dir, user_config_dir) != 0)
|
2018-12-13 18:01:19 +01:00
|
|
|
|
{
|
|
|
|
|
g_debug ("%s: Resetting desktop app info dirs from %s to %s",
|
|
|
|
|
G_STRFUNC, desktop_file_dirs_config_dir, user_config_dir);
|
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
g_ptr_array_set_size (desktop_file_dirs, 0);
|
|
|
|
|
g_clear_pointer (&desktop_file_dir_user_config, desktop_file_dir_unref);
|
|
|
|
|
g_clear_pointer (&desktop_file_dir_user_data, desktop_file_dir_unref);
|
2018-12-13 18:01:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
if (desktop_file_dirs == NULL || desktop_file_dirs->len == 0)
|
2013-07-24 23:48:37 +02:00
|
|
|
|
{
|
2014-04-09 14:44:18 +02:00
|
|
|
|
const char * const *dirs;
|
2013-07-24 23:48:37 +02:00
|
|
|
|
gint i;
|
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
if (desktop_file_dirs == NULL)
|
|
|
|
|
desktop_file_dirs = g_ptr_array_new_with_free_func ((GDestroyNotify) desktop_file_dir_unref);
|
2013-07-24 23:48:37 +02:00
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
/* First, the configs. Highest priority: the user's ~/.config */
|
2019-10-11 22:33:47 +02:00
|
|
|
|
desktop_file_dir_user_config = desktop_file_dir_new_for_config (user_config_dir);
|
|
|
|
|
g_ptr_array_add (desktop_file_dirs, desktop_file_dir_ref (desktop_file_dir_user_config));
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
/* Next, the system configs (/etc/xdg, and so on). */
|
|
|
|
|
dirs = g_get_system_config_dirs ();
|
|
|
|
|
for (i = 0; dirs[i]; i++)
|
2019-10-11 22:33:47 +02:00
|
|
|
|
g_ptr_array_add (desktop_file_dirs, desktop_file_dir_new_for_config (dirs[i]));
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
/* Now the data. Highest priority: the user's ~/.local/share/applications */
|
2019-10-11 22:33:47 +02:00
|
|
|
|
desktop_file_dir_user_data = desktop_file_dir_new (g_get_user_data_dir ());
|
|
|
|
|
g_ptr_array_add (desktop_file_dirs, desktop_file_dir_ref (desktop_file_dir_user_data));
|
2013-07-24 23:48:37 +02:00
|
|
|
|
|
|
|
|
|
/* Following that, XDG_DATA_DIRS/applications, in order */
|
2014-04-09 14:44:18 +02:00
|
|
|
|
dirs = g_get_system_data_dirs ();
|
|
|
|
|
for (i = 0; dirs[i]; i++)
|
2019-10-11 22:33:47 +02:00
|
|
|
|
g_ptr_array_add (desktop_file_dirs, desktop_file_dir_new (dirs[i]));
|
2013-07-24 23:48:37 +02:00
|
|
|
|
|
2018-12-13 18:01:19 +01:00
|
|
|
|
/* The list of directories will never change after this, unless
|
|
|
|
|
* g_get_user_config_dir() changes due to %G_TEST_OPTION_ISOLATE_DIRS. */
|
|
|
|
|
desktop_file_dirs_config_dir = user_config_dir;
|
2013-07-24 23:48:37 +02:00
|
|
|
|
}
|
2013-07-27 22:04:56 +02:00
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
for (i = 0; i < desktop_file_dirs->len; i++)
|
|
|
|
|
if (!((DesktopFileDir *) g_ptr_array_index (desktop_file_dirs, i))->is_setup)
|
|
|
|
|
desktop_file_dir_init (g_ptr_array_index (desktop_file_dirs, i));
|
2013-07-27 22:04:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
desktop_file_dirs_unlock (void)
|
|
|
|
|
{
|
|
|
|
|
g_mutex_unlock (&desktop_file_dir_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-04-09 14:44:18 +02:00
|
|
|
|
desktop_file_dirs_invalidate_user_config (void)
|
2013-07-27 22:04:56 +02:00
|
|
|
|
{
|
2014-04-09 14:44:18 +02:00
|
|
|
|
g_mutex_lock (&desktop_file_dir_lock);
|
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
if (desktop_file_dir_user_config != NULL)
|
|
|
|
|
desktop_file_dir_reset (desktop_file_dir_user_config);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
g_mutex_unlock (&desktop_file_dir_lock);
|
2013-07-27 22:04:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-04-09 14:44:18 +02:00
|
|
|
|
desktop_file_dirs_invalidate_user_data (void)
|
2013-07-27 22:04:56 +02:00
|
|
|
|
{
|
|
|
|
|
g_mutex_lock (&desktop_file_dir_lock);
|
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
if (desktop_file_dir_user_data != NULL)
|
|
|
|
|
desktop_file_dir_reset (desktop_file_dir_user_data);
|
2013-07-27 22:04:56 +02:00
|
|
|
|
|
|
|
|
|
g_mutex_unlock (&desktop_file_dir_lock);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* GDesktopAppInfo implementation {{{1 */
|
|
|
|
|
/* GObject implementation {{{2 */
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static void
|
|
|
|
|
g_desktop_app_info_finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info;
|
|
|
|
|
|
|
|
|
|
info = G_DESKTOP_APP_INFO (object);
|
|
|
|
|
|
|
|
|
|
g_free (info->desktop_id);
|
|
|
|
|
g_free (info->filename);
|
2012-11-17 00:22:45 +01:00
|
|
|
|
|
|
|
|
|
if (info->keyfile)
|
|
|
|
|
g_key_file_unref (info->keyfile);
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_free (info->name);
|
2011-04-27 17:34:23 +02:00
|
|
|
|
g_free (info->generic_name);
|
2009-11-18 23:37:47 +01:00
|
|
|
|
g_free (info->fullname);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_free (info->comment);
|
|
|
|
|
g_free (info->icon_name);
|
|
|
|
|
if (info->icon)
|
|
|
|
|
g_object_unref (info->icon);
|
2011-10-13 22:33:21 +02:00
|
|
|
|
g_strfreev (info->keywords);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_strfreev (info->only_show_in);
|
|
|
|
|
g_strfreev (info->not_show_in);
|
|
|
|
|
g_free (info->try_exec);
|
|
|
|
|
g_free (info->exec);
|
|
|
|
|
g_free (info->binary);
|
|
|
|
|
g_free (info->path);
|
2011-04-15 21:52:33 +02:00
|
|
|
|
g_free (info->categories);
|
2012-04-05 23:26:12 +02:00
|
|
|
|
g_free (info->startup_wm_class);
|
2012-04-14 19:34:00 +02:00
|
|
|
|
g_strfreev (info->mime_types);
|
2013-04-29 22:37:55 +02:00
|
|
|
|
g_free (info->app_id);
|
2013-07-11 18:46:59 +02:00
|
|
|
|
g_strfreev (info->actions);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
G_OBJECT_CLASS (g_desktop_app_info_parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-26 21:08:54 +02:00
|
|
|
|
static void
|
2013-07-27 21:08:58 +02:00
|
|
|
|
g_desktop_app_info_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2011-04-26 21:08:54 +02:00
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *self = G_DESKTOP_APP_INFO (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_FILENAME:
|
|
|
|
|
self->filename = g_value_dup_string (value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-11-17 00:22:45 +01:00
|
|
|
|
g_desktop_app_info_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2011-04-26 21:08:54 +02:00
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *self = G_DESKTOP_APP_INFO (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_FILENAME:
|
|
|
|
|
g_value_set_string (value, self->filename);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static void
|
|
|
|
|
g_desktop_app_info_class_init (GDesktopAppInfoClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2011-04-26 21:08:54 +02:00
|
|
|
|
gobject_class->get_property = g_desktop_app_info_get_property;
|
|
|
|
|
gobject_class->set_property = g_desktop_app_info_set_property;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
gobject_class->finalize = g_desktop_app_info_finalize;
|
2011-04-26 21:08:54 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2012-04-02 17:16:35 +02:00
|
|
|
|
* GDesktopAppInfo:filename:
|
2011-04-26 21:08:54 +02:00
|
|
|
|
*
|
|
|
|
|
* The origin filename of this #GDesktopAppInfo
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_FILENAME,
|
2023-04-28 01:59:26 +02:00
|
|
|
|
g_param_spec_string ("filename", NULL, NULL, NULL,
|
2011-04-26 21:08:54 +02:00
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_desktop_app_info_init (GDesktopAppInfo *local)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* Construction... {{{2 */
|
|
|
|
|
|
|
|
|
|
/*< internal >
|
|
|
|
|
* binary_from_exec:
|
|
|
|
|
* @exec: an exec line
|
|
|
|
|
*
|
|
|
|
|
* Returns the first word in an exec line (ie: the binary name).
|
|
|
|
|
*
|
|
|
|
|
* If @exec is " progname --foo %F" then returns "progname".
|
|
|
|
|
*/
|
2008-01-29 15:07:07 +01:00
|
|
|
|
static char *
|
|
|
|
|
binary_from_exec (const char *exec)
|
|
|
|
|
{
|
2008-01-30 12:27:02 +01:00
|
|
|
|
const char *p, *start;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
p = exec;
|
|
|
|
|
while (*p == ' ')
|
|
|
|
|
p++;
|
|
|
|
|
start = p;
|
|
|
|
|
while (*p != ' ' && *p != 0)
|
|
|
|
|
p++;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
return g_strndup (start, p - start);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 22:43:44 +01:00
|
|
|
|
/*< internal >
|
|
|
|
|
* g_desktop_app_info_get_desktop_id_for_filename
|
|
|
|
|
* @self: #GDesktopAppInfo to get desktop id of
|
|
|
|
|
*
|
|
|
|
|
* Tries to find the desktop ID for a particular `.desktop` filename, as per the
|
|
|
|
|
* [Desktop Entry Specification](https://specifications.freedesktop.org/desktop-
|
|
|
|
|
* entry-spec/desktop-entry-spec-latest.html#desktop-file-id).
|
|
|
|
|
*
|
|
|
|
|
* Returns: desktop id or basename if filename is unknown.
|
|
|
|
|
*/
|
|
|
|
|
static char *
|
|
|
|
|
g_desktop_app_info_get_desktop_id_for_filename (GDesktopAppInfo *self)
|
|
|
|
|
{
|
|
|
|
|
guint i;
|
|
|
|
|
gchar *desktop_id = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (self->filename != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < desktop_file_dirs->len; i++)
|
|
|
|
|
{
|
|
|
|
|
DesktopFileDir *dir = g_ptr_array_index (desktop_file_dirs, i);
|
|
|
|
|
GHashTable *app_names;
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
gpointer key, value;
|
|
|
|
|
|
|
|
|
|
app_names = dir->app_names;
|
|
|
|
|
|
|
|
|
|
if (!app_names)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, app_names);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp (value, self->filename))
|
|
|
|
|
{
|
|
|
|
|
desktop_id = g_strdup (key);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (desktop_id)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!desktop_id)
|
|
|
|
|
desktop_id = g_path_get_basename (self->filename);
|
|
|
|
|
|
|
|
|
|
return g_steal_pointer (&desktop_id);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-26 21:08:54 +02:00
|
|
|
|
static gboolean
|
2013-07-27 21:08:58 +02:00
|
|
|
|
g_desktop_app_info_load_from_keyfile (GDesktopAppInfo *info,
|
|
|
|
|
GKeyFile *key_file)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
char *start_group;
|
|
|
|
|
char *type;
|
|
|
|
|
char *try_exec;
|
2012-05-04 23:51:35 +02:00
|
|
|
|
char *exec;
|
2022-10-31 16:56:23 +01:00
|
|
|
|
char *path;
|
2013-04-29 22:37:55 +02:00
|
|
|
|
gboolean bus_activatable;
|
2011-04-26 21:08:54 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
start_group = g_key_file_get_start_group (key_file);
|
|
|
|
|
if (start_group == NULL || strcmp (start_group, G_KEY_FILE_DESKTOP_GROUP) != 0)
|
|
|
|
|
{
|
|
|
|
|
g_free (start_group);
|
2011-04-26 21:08:54 +02:00
|
|
|
|
return FALSE;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
g_free (start_group);
|
|
|
|
|
|
|
|
|
|
type = g_key_file_get_string (key_file,
|
|
|
|
|
G_KEY_FILE_DESKTOP_GROUP,
|
|
|
|
|
G_KEY_FILE_DESKTOP_KEY_TYPE,
|
|
|
|
|
NULL);
|
|
|
|
|
if (type == NULL || strcmp (type, G_KEY_FILE_DESKTOP_TYPE_APPLICATION) != 0)
|
|
|
|
|
{
|
|
|
|
|
g_free (type);
|
2011-04-26 21:08:54 +02:00
|
|
|
|
return FALSE;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
g_free (type);
|
|
|
|
|
|
2022-10-31 16:56:23 +01:00
|
|
|
|
path = g_key_file_get_string (key_file,
|
|
|
|
|
G_KEY_FILE_DESKTOP_GROUP,
|
|
|
|
|
G_KEY_FILE_DESKTOP_KEY_PATH, NULL);
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
try_exec = g_key_file_get_string (key_file,
|
|
|
|
|
G_KEY_FILE_DESKTOP_GROUP,
|
|
|
|
|
G_KEY_FILE_DESKTOP_KEY_TRY_EXEC,
|
|
|
|
|
NULL);
|
2008-04-16 18:48:23 +02:00
|
|
|
|
if (try_exec && try_exec[0] != '\0')
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
char *t;
|
2022-11-01 00:31:58 +01:00
|
|
|
|
/* Use the desktop file path (if any) as working dir to search program */
|
2023-02-13 17:12:07 +01:00
|
|
|
|
t = GLIB_PRIVATE_CALL (g_find_program_for_path) (try_exec, NULL, path);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
if (t == NULL)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
2022-10-31 16:56:23 +01:00
|
|
|
|
g_free (path);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
g_free (try_exec);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_free (t);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-04 23:51:35 +02:00
|
|
|
|
exec = g_key_file_get_string (key_file,
|
|
|
|
|
G_KEY_FILE_DESKTOP_GROUP,
|
|
|
|
|
G_KEY_FILE_DESKTOP_KEY_EXEC,
|
|
|
|
|
NULL);
|
|
|
|
|
if (exec && exec[0] != '\0')
|
|
|
|
|
{
|
|
|
|
|
gint argc;
|
|
|
|
|
char **argv;
|
|
|
|
|
if (!g_shell_parse_argv (exec, &argc, &argv, NULL))
|
|
|
|
|
{
|
2022-10-31 16:56:23 +01:00
|
|
|
|
g_free (path);
|
2012-05-04 23:51:35 +02:00
|
|
|
|
g_free (exec);
|
|
|
|
|
g_free (try_exec);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char *t;
|
2022-01-31 15:48:58 +01:00
|
|
|
|
|
|
|
|
|
/* Since @exec is not an empty string, there must be at least one
|
|
|
|
|
* argument, so dereferencing argv[0] should return non-NULL. */
|
|
|
|
|
g_assert (argc > 0);
|
2022-11-01 00:31:58 +01:00
|
|
|
|
/* Use the desktop file path (if any) as working dir to search program */
|
2023-02-13 17:12:07 +01:00
|
|
|
|
t = GLIB_PRIVATE_CALL (g_find_program_for_path) (argv[0], NULL, path);
|
2012-05-04 23:51:35 +02:00
|
|
|
|
g_strfreev (argv);
|
|
|
|
|
|
|
|
|
|
if (t == NULL)
|
|
|
|
|
{
|
2022-10-31 16:56:23 +01:00
|
|
|
|
g_free (path);
|
2012-05-04 23:51:35 +02:00
|
|
|
|
g_free (exec);
|
|
|
|
|
g_free (try_exec);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
g_free (t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
info->name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
|
2011-04-27 17:34:23 +02:00
|
|
|
|
info->generic_name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, GENERIC_NAME_KEY, NULL, NULL);
|
2009-11-18 23:37:47 +01:00
|
|
|
|
info->fullname = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, FULL_NAME_KEY, NULL, NULL);
|
2011-10-13 22:33:21 +02:00
|
|
|
|
info->keywords = g_key_file_get_locale_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP, KEYWORDS_KEY, NULL, NULL, NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
info->comment = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
|
|
|
|
|
info->nodisplay = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, NULL) != FALSE;
|
|
|
|
|
info->icon_name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL, NULL);
|
|
|
|
|
info->only_show_in = g_key_file_get_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, NULL, NULL);
|
|
|
|
|
info->not_show_in = g_key_file_get_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, NULL, NULL);
|
|
|
|
|
info->try_exec = try_exec;
|
2012-05-04 23:51:35 +02:00
|
|
|
|
info->exec = exec;
|
2022-10-31 16:56:23 +01:00
|
|
|
|
info->path = g_steal_pointer (&path);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
info->terminal = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL) != FALSE;
|
|
|
|
|
info->startup_notify = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY, NULL) != FALSE;
|
2009-02-26 15:59:16 +01:00
|
|
|
|
info->no_fuse = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, "X-GIO-NoFuse", NULL) != FALSE;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
info->hidden = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_HIDDEN, NULL) != FALSE;
|
2011-04-15 21:52:33 +02:00
|
|
|
|
info->categories = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_CATEGORIES, NULL);
|
2012-04-05 23:26:12 +02:00
|
|
|
|
info->startup_wm_class = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, STARTUP_WM_CLASS_KEY, NULL);
|
2012-04-14 19:34:00 +02:00
|
|
|
|
info->mime_types = g_key_file_get_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_MIME_TYPE, NULL, NULL);
|
2013-04-29 22:37:55 +02:00
|
|
|
|
bus_activatable = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE, NULL);
|
2013-07-11 18:46:59 +02:00
|
|
|
|
info->actions = g_key_file_get_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ACTIONS, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
/* Remove the special-case: no Actions= key just means 0 extra actions */
|
|
|
|
|
if (info->actions == NULL)
|
|
|
|
|
info->actions = g_new0 (gchar *, 0 + 1);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
info->icon = NULL;
|
|
|
|
|
if (info->icon_name)
|
|
|
|
|
{
|
|
|
|
|
if (g_path_is_absolute (info->icon_name))
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
|
|
file = g_file_new_for_path (info->icon_name);
|
|
|
|
|
info->icon = g_file_icon_new (file);
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
else
|
2008-11-28 09:28:39 +01:00
|
|
|
|
{
|
|
|
|
|
char *p;
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* Work around a common mistake in desktop files */
|
2008-11-28 09:28:39 +01:00
|
|
|
|
if ((p = strrchr (info->icon_name, '.')) != NULL &&
|
|
|
|
|
(strcmp (p, ".png") == 0 ||
|
|
|
|
|
strcmp (p, ".xpm") == 0 ||
|
2013-07-27 21:08:58 +02:00
|
|
|
|
strcmp (p, ".svg") == 0))
|
2008-11-28 09:28:39 +01:00
|
|
|
|
*p = 0;
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
info->icon = g_themed_icon_new (info->icon_name);
|
2008-11-28 09:28:39 +01:00
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
if (info->exec)
|
2008-01-29 15:07:07 +01:00
|
|
|
|
info->binary = binary_from_exec (info->exec);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-09-15 18:26:38 +02:00
|
|
|
|
if (info->path && info->path[0] == '\0')
|
|
|
|
|
{
|
|
|
|
|
g_free (info->path);
|
2008-09-16 11:13:19 +02:00
|
|
|
|
info->path = NULL;
|
2008-09-15 18:26:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-03 16:02:08 +02:00
|
|
|
|
/* Can only be DBusActivatable if we know the filename, which means
|
|
|
|
|
* that this won't work for the load-from-keyfile case.
|
|
|
|
|
*/
|
|
|
|
|
if (bus_activatable && info->filename)
|
2013-04-29 22:37:55 +02:00
|
|
|
|
{
|
|
|
|
|
gchar *basename;
|
|
|
|
|
gchar *last_dot;
|
|
|
|
|
|
|
|
|
|
basename = g_path_get_basename (info->filename);
|
|
|
|
|
last_dot = strrchr (basename, '.');
|
|
|
|
|
|
|
|
|
|
if (last_dot && g_str_equal (last_dot, ".desktop"))
|
|
|
|
|
{
|
|
|
|
|
*last_dot = '\0';
|
|
|
|
|
|
2016-04-12 17:06:11 +02:00
|
|
|
|
if (g_dbus_is_name (basename) && basename[0] != ':')
|
2013-04-29 22:37:55 +02:00
|
|
|
|
info->app_id = g_strdup (basename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (basename);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 22:43:44 +01:00
|
|
|
|
if (info->filename)
|
|
|
|
|
info->desktop_id = g_desktop_app_info_get_desktop_id_for_filename (info);
|
|
|
|
|
|
2012-11-17 00:22:45 +01:00
|
|
|
|
info->keyfile = g_key_file_ref (key_file);
|
|
|
|
|
|
2011-04-26 21:08:54 +02:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
g_desktop_app_info_load_file (GDesktopAppInfo *self)
|
|
|
|
|
{
|
|
|
|
|
GKeyFile *key_file;
|
|
|
|
|
gboolean retval = FALSE;
|
2012-11-17 00:22:45 +01:00
|
|
|
|
|
2011-04-26 21:08:54 +02:00
|
|
|
|
g_return_val_if_fail (self->filename != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
key_file = g_key_file_new ();
|
2012-11-17 00:22:45 +01:00
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
if (g_key_file_load_from_file (key_file, self->filename, G_KEY_FILE_NONE, NULL))
|
|
|
|
|
retval = g_desktop_app_info_load_from_keyfile (self, key_file);
|
2011-04-26 21:08:54 +02:00
|
|
|
|
|
2012-11-17 00:22:45 +01:00
|
|
|
|
g_key_file_unref (key_file);
|
2011-04-26 21:08:54 +02:00
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_new_from_keyfile:
|
|
|
|
|
* @key_file: an opened #GKeyFile
|
2012-11-17 00:22:45 +01:00
|
|
|
|
*
|
2011-04-26 21:08:54 +02:00
|
|
|
|
* Creates a new #GDesktopAppInfo.
|
|
|
|
|
*
|
2018-05-04 02:00:00 +02:00
|
|
|
|
* Returns: (nullable): a new #GDesktopAppInfo or %NULL on error.
|
2011-04-26 21:08:54 +02:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.18
|
|
|
|
|
**/
|
|
|
|
|
GDesktopAppInfo *
|
|
|
|
|
g_desktop_app_info_new_from_keyfile (GKeyFile *key_file)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info;
|
|
|
|
|
|
|
|
|
|
info = g_object_new (G_TYPE_DESKTOP_APP_INFO, NULL);
|
|
|
|
|
info->filename = NULL;
|
2021-12-13 22:43:44 +01:00
|
|
|
|
|
|
|
|
|
desktop_file_dirs_lock ();
|
|
|
|
|
|
2011-04-26 21:08:54 +02:00
|
|
|
|
if (!g_desktop_app_info_load_from_keyfile (info, key_file))
|
2021-12-13 22:43:44 +01:00
|
|
|
|
g_clear_object (&info);
|
|
|
|
|
|
|
|
|
|
desktop_file_dirs_unlock ();
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-02 18:23:23 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_new_from_filename:
|
2016-06-04 17:53:42 +02:00
|
|
|
|
* @filename: (type filename): the path of a desktop file, in the GLib
|
|
|
|
|
* filename encoding
|
2013-07-27 21:08:58 +02:00
|
|
|
|
*
|
2008-07-02 18:23:23 +02:00
|
|
|
|
* Creates a new #GDesktopAppInfo.
|
|
|
|
|
*
|
2018-05-04 02:00:00 +02:00
|
|
|
|
* Returns: (nullable): a new #GDesktopAppInfo or %NULL on error.
|
2008-07-02 18:23:23 +02:00
|
|
|
|
**/
|
|
|
|
|
GDesktopAppInfo *
|
|
|
|
|
g_desktop_app_info_new_from_filename (const char *filename)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = NULL;
|
|
|
|
|
|
2021-12-13 22:43:44 +01:00
|
|
|
|
desktop_file_dirs_lock ();
|
|
|
|
|
|
|
|
|
|
info = g_desktop_app_info_new_from_filename_unlocked (filename);
|
|
|
|
|
|
|
|
|
|
desktop_file_dirs_unlock ();
|
|
|
|
|
|
2008-07-02 18:23:23 +02:00
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_new:
|
2007-12-12 13:19:02 +01:00
|
|
|
|
* @desktop_id: the desktop file id
|
2009-01-19 23:58:38 +01:00
|
|
|
|
*
|
2013-07-27 21:08:58 +02:00
|
|
|
|
* Creates a new #GDesktopAppInfo based on a desktop file id.
|
|
|
|
|
*
|
|
|
|
|
* A desktop file id is the basename of the desktop file, including the
|
|
|
|
|
* .desktop extension. GIO is looking for a desktop file with this name
|
2014-02-06 02:17:46 +01:00
|
|
|
|
* in the `applications` subdirectories of the XDG
|
2014-02-06 01:32:41 +01:00
|
|
|
|
* data directories (i.e. the directories specified in the `XDG_DATA_HOME`
|
|
|
|
|
* and `XDG_DATA_DIRS` environment variables). GIO also supports the
|
|
|
|
|
* prefix-to-subdirectory mapping that is described in the
|
2014-02-06 03:23:28 +01:00
|
|
|
|
* [Menu Spec](http://standards.freedesktop.org/menu-spec/latest/)
|
|
|
|
|
* (i.e. a desktop id of kde-foo.desktop will match
|
2014-02-06 02:17:46 +01:00
|
|
|
|
* `/usr/share/applications/kde/foo.desktop`).
|
2013-07-27 21:08:58 +02:00
|
|
|
|
*
|
2018-05-04 02:00:00 +02:00
|
|
|
|
* Returns: (nullable): a new #GDesktopAppInfo, or %NULL if no desktop
|
|
|
|
|
* file with that id exists.
|
2009-01-19 23:58:38 +01:00
|
|
|
|
*/
|
2007-11-26 17:13:05 +01:00
|
|
|
|
GDesktopAppInfo *
|
2007-12-10 19:51:21 +01:00
|
|
|
|
g_desktop_app_info_new (const char *desktop_id)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2013-07-27 22:04:56 +02:00
|
|
|
|
GDesktopAppInfo *appinfo = NULL;
|
|
|
|
|
guint i;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
desktop_file_dirs_lock ();
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
for (i = 0; i < desktop_file_dirs->len; i++)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2019-10-11 22:33:47 +02:00
|
|
|
|
appinfo = desktop_file_dir_get_app (g_ptr_array_index (desktop_file_dirs, i), desktop_id);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
if (appinfo)
|
|
|
|
|
break;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
2012-11-17 00:22:45 +01:00
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
desktop_file_dirs_unlock ();
|
|
|
|
|
|
|
|
|
|
if (appinfo == NULL)
|
|
|
|
|
return NULL;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2013-05-01 02:39:26 +02:00
|
|
|
|
g_free (appinfo->desktop_id);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
appinfo->desktop_id = g_strdup (desktop_id);
|
|
|
|
|
|
2007-12-10 19:51:21 +01:00
|
|
|
|
if (g_desktop_app_info_get_is_hidden (appinfo))
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
g_object_unref (appinfo);
|
|
|
|
|
appinfo = NULL;
|
|
|
|
|
}
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return appinfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GAppInfo *
|
|
|
|
|
g_desktop_app_info_dup (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
GDesktopAppInfo *new_info;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
new_info = g_object_new (G_TYPE_DESKTOP_APP_INFO, NULL);
|
|
|
|
|
|
|
|
|
|
new_info->filename = g_strdup (info->filename);
|
|
|
|
|
new_info->desktop_id = g_strdup (info->desktop_id);
|
2012-11-17 00:22:45 +01:00
|
|
|
|
|
|
|
|
|
if (info->keyfile)
|
|
|
|
|
new_info->keyfile = g_key_file_ref (info->keyfile);
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
new_info->name = g_strdup (info->name);
|
2011-04-27 17:34:23 +02:00
|
|
|
|
new_info->generic_name = g_strdup (info->generic_name);
|
2009-11-18 23:37:47 +01:00
|
|
|
|
new_info->fullname = g_strdup (info->fullname);
|
2011-10-13 22:33:21 +02:00
|
|
|
|
new_info->keywords = g_strdupv (info->keywords);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
new_info->comment = g_strdup (info->comment);
|
|
|
|
|
new_info->nodisplay = info->nodisplay;
|
|
|
|
|
new_info->icon_name = g_strdup (info->icon_name);
|
2009-05-04 21:32:35 +02:00
|
|
|
|
if (info->icon)
|
|
|
|
|
new_info->icon = g_object_ref (info->icon);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
new_info->only_show_in = g_strdupv (info->only_show_in);
|
|
|
|
|
new_info->not_show_in = g_strdupv (info->not_show_in);
|
|
|
|
|
new_info->try_exec = g_strdup (info->try_exec);
|
|
|
|
|
new_info->exec = g_strdup (info->exec);
|
|
|
|
|
new_info->binary = g_strdup (info->binary);
|
|
|
|
|
new_info->path = g_strdup (info->path);
|
2013-04-29 22:37:55 +02:00
|
|
|
|
new_info->app_id = g_strdup (info->app_id);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
new_info->hidden = info->hidden;
|
|
|
|
|
new_info->terminal = info->terminal;
|
|
|
|
|
new_info->startup_notify = info->startup_notify;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return G_APP_INFO (new_info);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* GAppInfo interface implementation functions {{{2 */
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static gboolean
|
|
|
|
|
g_desktop_app_info_equal (GAppInfo *appinfo1,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
GAppInfo *appinfo2)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info1 = G_DESKTOP_APP_INFO (appinfo1);
|
|
|
|
|
GDesktopAppInfo *info2 = G_DESKTOP_APP_INFO (appinfo2);
|
|
|
|
|
|
|
|
|
|
if (info1->desktop_id == NULL ||
|
|
|
|
|
info2->desktop_id == NULL)
|
2008-02-01 13:02:52 +01:00
|
|
|
|
return info1 == info2;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
return strcmp (info1->desktop_id, info2->desktop_id) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
g_desktop_app_info_get_id (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
|
|
|
|
|
return info->desktop_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
g_desktop_app_info_get_name (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
|
|
|
|
|
if (info->name == NULL)
|
|
|
|
|
return _("Unnamed");
|
|
|
|
|
return info->name;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-18 23:37:47 +01:00
|
|
|
|
static const char *
|
|
|
|
|
g_desktop_app_info_get_display_name (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
|
|
|
|
|
if (info->fullname == NULL)
|
|
|
|
|
return g_desktop_app_info_get_name (appinfo);
|
|
|
|
|
return info->fullname;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_is_hidden:
|
2007-12-12 13:19:02 +01:00
|
|
|
|
* @info: a #GDesktopAppInfo.
|
|
|
|
|
*
|
|
|
|
|
* A desktop file is hidden if the Hidden key in it is
|
|
|
|
|
* set to True.
|
|
|
|
|
*
|
2013-07-27 21:08:58 +02:00
|
|
|
|
* Returns: %TRUE if hidden, %FALSE otherwise.
|
2007-11-26 17:13:05 +01:00
|
|
|
|
**/
|
|
|
|
|
gboolean
|
2007-12-10 19:51:21 +01:00
|
|
|
|
g_desktop_app_info_get_is_hidden (GDesktopAppInfo *info)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
return info->hidden;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-14 00:11:31 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_filename:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
*
|
|
|
|
|
* When @info was created from a known filename, return it. In some
|
|
|
|
|
* situations such as the #GDesktopAppInfo returned from
|
|
|
|
|
* g_desktop_app_info_new_from_keyfile(), this function will return %NULL.
|
|
|
|
|
*
|
2020-10-18 10:15:54 +02:00
|
|
|
|
* Returns: (nullable) (type filename): The full path to the file for @info,
|
2016-06-04 17:53:42 +02:00
|
|
|
|
* or %NULL if not known.
|
2010-03-14 00:11:31 +01:00
|
|
|
|
* Since: 2.24
|
|
|
|
|
*/
|
|
|
|
|
const char *
|
|
|
|
|
g_desktop_app_info_get_filename (GDesktopAppInfo *info)
|
|
|
|
|
{
|
|
|
|
|
return info->filename;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static const char *
|
|
|
|
|
g_desktop_app_info_get_description (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return info->comment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
g_desktop_app_info_get_executable (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return info->binary;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-29 00:16:45 +01:00
|
|
|
|
static const char *
|
|
|
|
|
g_desktop_app_info_get_commandline (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-11-29 00:16:45 +01:00
|
|
|
|
return info->exec;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static GIcon *
|
|
|
|
|
g_desktop_app_info_get_icon (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
|
|
|
|
|
return info->icon;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-15 21:52:33 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_categories:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
*
|
2011-05-02 05:02:53 +02:00
|
|
|
|
* Gets the categories from the desktop file.
|
|
|
|
|
*
|
2020-10-18 10:15:54 +02:00
|
|
|
|
* Returns: (nullable): The unparsed Categories key from the desktop file;
|
2011-05-02 05:02:53 +02:00
|
|
|
|
* i.e. no attempt is made to split it by ';' or validate it.
|
2011-04-15 21:52:33 +02:00
|
|
|
|
*/
|
|
|
|
|
const char *
|
2011-05-02 05:02:53 +02:00
|
|
|
|
g_desktop_app_info_get_categories (GDesktopAppInfo *info)
|
2011-04-15 21:52:33 +02:00
|
|
|
|
{
|
|
|
|
|
return info->categories;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-13 22:33:21 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_keywords:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
*
|
|
|
|
|
* Gets the keywords from the desktop file.
|
|
|
|
|
*
|
2012-01-04 20:48:53 +01:00
|
|
|
|
* Returns: (transfer none): The value of the Keywords key
|
2011-10-13 22:33:21 +02:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.32
|
|
|
|
|
*/
|
|
|
|
|
const char * const *
|
|
|
|
|
g_desktop_app_info_get_keywords (GDesktopAppInfo *info)
|
|
|
|
|
{
|
|
|
|
|
return (const char * const *)info->keywords;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 17:34:23 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_generic_name:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
*
|
2020-10-18 10:15:54 +02:00
|
|
|
|
* Gets the generic name from the desktop file.
|
2011-05-02 05:02:53 +02:00
|
|
|
|
*
|
2020-10-18 10:15:54 +02:00
|
|
|
|
* Returns: (nullable): The value of the GenericName key
|
2011-04-27 17:34:23 +02:00
|
|
|
|
*/
|
|
|
|
|
const char *
|
2011-05-02 05:02:53 +02:00
|
|
|
|
g_desktop_app_info_get_generic_name (GDesktopAppInfo *info)
|
2011-04-27 17:34:23 +02:00
|
|
|
|
{
|
|
|
|
|
return info->generic_name;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-12 12:22:59 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_nodisplay:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
*
|
|
|
|
|
* Gets the value of the NoDisplay key, which helps determine if the
|
|
|
|
|
* application info should be shown in menus. See
|
2022-03-04 17:21:55 +01:00
|
|
|
|
* %G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY and g_app_info_should_show().
|
2011-06-12 12:22:59 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: The value of the NoDisplay key
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.30
|
|
|
|
|
*/
|
2011-06-14 09:01:25 +02:00
|
|
|
|
gboolean
|
2011-06-12 12:22:59 +02:00
|
|
|
|
g_desktop_app_info_get_nodisplay (GDesktopAppInfo *info)
|
|
|
|
|
{
|
|
|
|
|
return info->nodisplay;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-21 15:23:00 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_show_in:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
2014-05-08 14:57:50 +02:00
|
|
|
|
* @desktop_env: (nullable): a string specifying a desktop name
|
2011-07-21 15:23:00 +02:00
|
|
|
|
*
|
|
|
|
|
* Checks if the application info should be shown in menus that list available
|
|
|
|
|
* applications for a specific name of the desktop, based on the
|
2014-02-06 14:04:52 +01:00
|
|
|
|
* `OnlyShowIn` and `NotShowIn` keys.
|
2011-07-21 15:23:00 +02:00
|
|
|
|
*
|
2014-05-08 14:57:50 +02:00
|
|
|
|
* @desktop_env should typically be given as %NULL, in which case the
|
|
|
|
|
* `XDG_CURRENT_DESKTOP` environment variable is consulted. If you want
|
|
|
|
|
* to override the default mechanism then you may specify @desktop_env,
|
|
|
|
|
* but this is not recommended.
|
2011-07-21 15:23:00 +02:00
|
|
|
|
*
|
|
|
|
|
* Note that g_app_info_should_show() for @info will include this check (with
|
|
|
|
|
* %NULL for @desktop_env) as well as additional checks.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the @info should be shown in @desktop_env according to the
|
2014-02-06 14:04:52 +01:00
|
|
|
|
* `OnlyShowIn` and `NotShowIn` keys, %FALSE
|
2011-07-21 15:23:00 +02:00
|
|
|
|
* otherwise.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.30
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
g_desktop_app_info_get_show_in (GDesktopAppInfo *info,
|
|
|
|
|
const gchar *desktop_env)
|
|
|
|
|
{
|
2014-05-08 14:57:50 +02:00
|
|
|
|
const gchar *specified_envs[] = { desktop_env, NULL };
|
|
|
|
|
const gchar * const *envs;
|
|
|
|
|
gint i;
|
2011-07-21 15:23:00 +02:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), FALSE);
|
|
|
|
|
|
2014-05-08 14:57:50 +02:00
|
|
|
|
if (desktop_env)
|
|
|
|
|
envs = specified_envs;
|
|
|
|
|
else
|
|
|
|
|
envs = get_current_desktops (NULL);
|
2011-07-21 15:23:00 +02:00
|
|
|
|
|
2014-05-08 14:57:50 +02:00
|
|
|
|
for (i = 0; envs[i]; i++)
|
2011-07-21 15:23:00 +02:00
|
|
|
|
{
|
2014-05-08 14:57:50 +02:00
|
|
|
|
gint j;
|
2011-07-21 15:23:00 +02:00
|
|
|
|
|
2014-05-08 14:57:50 +02:00
|
|
|
|
if (info->only_show_in)
|
|
|
|
|
for (j = 0; info->only_show_in[j]; j++)
|
|
|
|
|
if (g_str_equal (info->only_show_in[j], envs[i]))
|
|
|
|
|
return TRUE;
|
2011-07-21 15:23:00 +02:00
|
|
|
|
|
2014-05-08 14:57:50 +02:00
|
|
|
|
if (info->not_show_in)
|
|
|
|
|
for (j = 0; info->not_show_in[j]; j++)
|
|
|
|
|
if (g_str_equal (info->not_show_in[j], envs[i]))
|
2013-07-27 21:08:58 +02:00
|
|
|
|
return FALSE;
|
2011-07-21 15:23:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 14:57:50 +02:00
|
|
|
|
return info->only_show_in == NULL;
|
2011-07-21 15:23:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* Launching... {{{2 */
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static char *
|
2017-12-07 14:33:47 +01:00
|
|
|
|
expand_macro_single (char macro, const char *uri)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2008-01-30 12:27:02 +01:00
|
|
|
|
GFile *file;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
char *result = NULL;
|
2013-09-25 16:14:17 +02:00
|
|
|
|
char *path = NULL;
|
|
|
|
|
char *name;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2008-01-30 12:27:02 +01:00
|
|
|
|
file = g_file_new_for_uri (uri);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
switch (macro)
|
|
|
|
|
{
|
|
|
|
|
case 'u':
|
2013-07-27 21:08:58 +02:00
|
|
|
|
case 'U':
|
2007-11-26 17:13:05 +01:00
|
|
|
|
result = g_shell_quote (uri);
|
|
|
|
|
break;
|
|
|
|
|
case 'f':
|
|
|
|
|
case 'F':
|
2013-09-25 16:14:17 +02:00
|
|
|
|
path = g_file_get_path (file);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
if (path)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
result = g_shell_quote (path);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
break;
|
|
|
|
|
case 'd':
|
|
|
|
|
case 'D':
|
2013-09-25 16:14:17 +02:00
|
|
|
|
path = g_file_get_path (file);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
if (path)
|
2008-09-21 02:00:18 +02:00
|
|
|
|
{
|
|
|
|
|
name = g_path_get_dirname (path);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
result = g_shell_quote (name);
|
2008-09-21 02:00:18 +02:00
|
|
|
|
g_free (name);
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
break;
|
|
|
|
|
case 'n':
|
|
|
|
|
case 'N':
|
2013-09-25 16:14:17 +02:00
|
|
|
|
path = g_file_get_path (file);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
if (path)
|
2008-09-21 02:00:18 +02:00
|
|
|
|
{
|
|
|
|
|
name = g_path_get_basename (path);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
result = g_shell_quote (name);
|
2008-09-21 02:00:18 +02:00
|
|
|
|
g_free (name);
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-25 16:14:17 +02:00
|
|
|
|
g_object_unref (file);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_free (path);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-07 14:33:47 +01:00
|
|
|
|
static char *
|
|
|
|
|
expand_macro_uri (char macro, const char *uri, gboolean force_file_uri, char force_file_uri_macro)
|
|
|
|
|
{
|
|
|
|
|
char *expanded = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (uri != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (!force_file_uri ||
|
|
|
|
|
/* Pass URI if it contains an anchor */
|
|
|
|
|
strchr (uri, '#') != NULL)
|
|
|
|
|
{
|
|
|
|
|
expanded = expand_macro_single (macro, uri);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
expanded = expand_macro_single (force_file_uri_macro, uri);
|
|
|
|
|
if (expanded == NULL)
|
|
|
|
|
expanded = expand_macro_single (macro, uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return expanded;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static void
|
2013-07-27 21:08:58 +02:00
|
|
|
|
expand_macro (char macro,
|
|
|
|
|
GString *exec,
|
|
|
|
|
GDesktopAppInfo *info,
|
2008-01-30 12:27:02 +01:00
|
|
|
|
GList **uri_list)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2008-01-30 12:27:02 +01:00
|
|
|
|
GList *uris = *uri_list;
|
2017-12-07 14:33:47 +01:00
|
|
|
|
char *expanded = NULL;
|
2008-10-01 19:46:57 +02:00
|
|
|
|
gboolean force_file_uri;
|
|
|
|
|
char force_file_uri_macro;
|
2017-12-07 14:33:47 +01:00
|
|
|
|
const char *uri;
|
2008-10-01 19:46:57 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_return_if_fail (exec != NULL);
|
2008-10-01 19:46:57 +02:00
|
|
|
|
|
|
|
|
|
/* On %u and %U, pass POSIX file path pointing to the URI via
|
|
|
|
|
* the FUSE mount in ~/.gvfs. Note that if the FUSE daemon isn't
|
|
|
|
|
* running or the URI doesn't have a POSIX file path via FUSE
|
|
|
|
|
* we'll just pass the URI.
|
|
|
|
|
*/
|
2009-02-26 15:59:16 +01:00
|
|
|
|
force_file_uri_macro = macro;
|
|
|
|
|
force_file_uri = FALSE;
|
|
|
|
|
if (!info->no_fuse)
|
2008-10-01 19:46:57 +02:00
|
|
|
|
{
|
2009-02-26 15:59:16 +01:00
|
|
|
|
switch (macro)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
|
|
|
|
case 'u':
|
|
|
|
|
force_file_uri_macro = 'f';
|
|
|
|
|
force_file_uri = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
case 'U':
|
|
|
|
|
force_file_uri_macro = 'F';
|
|
|
|
|
force_file_uri = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-10-01 19:46:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
switch (macro)
|
|
|
|
|
{
|
|
|
|
|
case 'u':
|
|
|
|
|
case 'f':
|
|
|
|
|
case 'd':
|
|
|
|
|
case 'n':
|
2008-01-30 12:27:02 +01:00
|
|
|
|
if (uris)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
|
|
|
|
uri = uris->data;
|
2017-12-07 14:33:47 +01:00
|
|
|
|
expanded = expand_macro_uri (macro, uri,
|
|
|
|
|
force_file_uri, force_file_uri_macro);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
if (expanded)
|
|
|
|
|
{
|
|
|
|
|
g_string_append (exec, expanded);
|
|
|
|
|
g_free (expanded);
|
|
|
|
|
}
|
|
|
|
|
uris = uris->next;
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
case 'U':
|
2007-11-26 17:13:05 +01:00
|
|
|
|
case 'F':
|
|
|
|
|
case 'D':
|
|
|
|
|
case 'N':
|
2008-01-30 12:27:02 +01:00
|
|
|
|
while (uris)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
|
|
|
|
uri = uris->data;
|
2017-12-07 14:33:47 +01:00
|
|
|
|
expanded = expand_macro_uri (macro, uri,
|
|
|
|
|
force_file_uri, force_file_uri_macro);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
if (expanded)
|
|
|
|
|
{
|
|
|
|
|
g_string_append (exec, expanded);
|
|
|
|
|
g_free (expanded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uris = uris->next;
|
|
|
|
|
|
|
|
|
|
if (uris != NULL && expanded)
|
|
|
|
|
g_string_append_c (exec, ' ');
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'i':
|
|
|
|
|
if (info->icon_name)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
|
|
|
|
g_string_append (exec, "--icon ");
|
2010-07-08 20:58:33 +02:00
|
|
|
|
expanded = g_shell_quote (info->icon_name);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
g_string_append (exec, expanded);
|
2010-07-08 20:58:33 +02:00
|
|
|
|
g_free (expanded);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'c':
|
2013-07-27 21:08:58 +02:00
|
|
|
|
if (info->name)
|
2010-07-08 20:58:33 +02:00
|
|
|
|
{
|
|
|
|
|
expanded = g_shell_quote (info->name);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
g_string_append (exec, expanded);
|
2010-07-08 20:58:33 +02:00
|
|
|
|
g_free (expanded);
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'k':
|
2013-07-27 21:08:58 +02:00
|
|
|
|
if (info->filename)
|
2010-07-08 20:58:33 +02:00
|
|
|
|
{
|
|
|
|
|
expanded = g_shell_quote (info->filename);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
g_string_append (exec, expanded);
|
2010-07-08 20:58:33 +02:00
|
|
|
|
g_free (expanded);
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'm': /* deprecated */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
|
g_string_append_c (exec, '%');
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-01-30 12:27:02 +01:00
|
|
|
|
*uri_list = uris;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
|
expand_application_parameters (GDesktopAppInfo *info,
|
2013-07-11 18:46:59 +02:00
|
|
|
|
const gchar *exec_line,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
GList **uris,
|
|
|
|
|
int *argc,
|
|
|
|
|
char ***argv,
|
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2008-01-30 12:27:02 +01:00
|
|
|
|
GList *uri_list = *uris;
|
2013-07-11 18:46:59 +02:00
|
|
|
|
const char *p = exec_line;
|
2010-01-06 00:18:55 +01:00
|
|
|
|
GString *expanded_exec;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
gboolean res;
|
2010-01-06 00:18:55 +01:00
|
|
|
|
|
2013-07-11 18:46:59 +02:00
|
|
|
|
if (exec_line == NULL)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
2016-09-30 05:47:15 +02:00
|
|
|
|
_("Desktop file didn’t specify Exec field"));
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2010-01-06 00:18:55 +01:00
|
|
|
|
|
|
|
|
|
expanded_exec = g_string_new (NULL);
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
while (*p)
|
|
|
|
|
{
|
|
|
|
|
if (p[0] == '%' && p[1] != '\0')
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
|
|
|
|
expand_macro (p[1], expanded_exec, info, uris);
|
|
|
|
|
p++;
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
else
|
2013-07-27 21:08:58 +02:00
|
|
|
|
g_string_append_c (expanded_exec, *p);
|
2010-01-06 00:18:55 +01:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
p++;
|
|
|
|
|
}
|
2010-01-06 00:18:55 +01:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
/* No file substitutions */
|
2008-01-30 12:27:02 +01:00
|
|
|
|
if (uri_list == *uris && uri_list != NULL)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
/* If there is no macro default to %f. This is also what KDE does */
|
|
|
|
|
g_string_append_c (expanded_exec, ' ');
|
2008-01-30 12:27:02 +01:00
|
|
|
|
expand_macro ('f', expanded_exec, info, uris);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
2010-01-06 00:18:55 +01:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
res = g_shell_parse_argv (expanded_exec->str, argc, argv, error);
|
|
|
|
|
g_string_free (expanded_exec, TRUE);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2022-11-01 00:31:58 +01:00
|
|
|
|
prepend_terminal_to_vector (int *argc,
|
|
|
|
|
char ***argv,
|
|
|
|
|
const char *path,
|
|
|
|
|
const char *working_dir)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
|
char **real_argv;
|
2022-07-23 20:16:11 +02:00
|
|
|
|
size_t real_argc;
|
|
|
|
|
size_t i;
|
2022-07-23 22:00:53 +02:00
|
|
|
|
size_t term_argc;
|
2022-07-23 20:16:11 +02:00
|
|
|
|
char *found_terminal;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
char **the_argv;
|
2022-07-23 20:16:11 +02:00
|
|
|
|
const char *term_arg;
|
|
|
|
|
static const struct {
|
|
|
|
|
const char *exec;
|
|
|
|
|
const char *exec_arg;
|
|
|
|
|
} known_terminals[] = {
|
2022-07-23 22:00:53 +02:00
|
|
|
|
{ "xdg-terminal-exec", NULL },
|
2022-10-27 00:21:39 +02:00
|
|
|
|
{ "kgx", "-e" },
|
2022-07-23 20:16:11 +02:00
|
|
|
|
{ "gnome-terminal", "--" },
|
|
|
|
|
{ "mate-terminal", "-x" },
|
|
|
|
|
{ "xfce4-terminal", "-x" },
|
|
|
|
|
{ "tilix", "-e" },
|
|
|
|
|
{ "konsole", "-e" },
|
|
|
|
|
{ "nxterm", "-e" },
|
|
|
|
|
{ "color-xterm", "-e" },
|
|
|
|
|
{ "rxvt", "-e" },
|
|
|
|
|
{ "dtterm", "-e" },
|
|
|
|
|
{ "xterm", "-e" }
|
|
|
|
|
};
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_return_val_if_fail (argc != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (argv != NULL, FALSE);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
/* sanity */
|
|
|
|
|
if(*argv == NULL)
|
|
|
|
|
*argc = 0;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
the_argv = *argv;
|
|
|
|
|
|
|
|
|
|
/* compute size if not given */
|
|
|
|
|
if (*argc < 0)
|
|
|
|
|
{
|
2022-07-23 20:16:11 +02:00
|
|
|
|
for ((*argc) = 0; the_argv[*argc] != NULL; (*argc)++)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2022-07-23 20:16:11 +02:00
|
|
|
|
for (i = 0, found_terminal = NULL; i < G_N_ELEMENTS (known_terminals); i++)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2023-02-13 17:12:07 +01:00
|
|
|
|
found_terminal = GLIB_PRIVATE_CALL (g_find_program_for_path) (known_terminals[i].exec,
|
|
|
|
|
path, working_dir);
|
2022-07-23 20:16:11 +02:00
|
|
|
|
if (found_terminal != NULL)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
2022-07-23 20:16:11 +02:00
|
|
|
|
term_arg = known_terminals[i].exec_arg;
|
|
|
|
|
break;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:16:11 +02:00
|
|
|
|
if (found_terminal == NULL)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("Couldn’t find a known terminal");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 22:00:53 +02:00
|
|
|
|
/* check if the terminal require an option */
|
|
|
|
|
term_argc = term_arg ? 2 : 1;
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
real_argc = term_argc + *argc;
|
|
|
|
|
real_argv = g_new (char *, real_argc + 1);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2022-07-23 22:00:53 +02:00
|
|
|
|
i = 0;
|
|
|
|
|
real_argv[i++] = found_terminal;
|
|
|
|
|
|
|
|
|
|
if (term_arg)
|
|
|
|
|
real_argv[i++] = g_strdup (term_arg);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2022-07-23 22:00:53 +02:00
|
|
|
|
g_assert (i == term_argc);
|
|
|
|
|
for (int j = 0; j < *argc; j++)
|
|
|
|
|
real_argv[i++] = the_argv[j];
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
real_argv[i] = NULL;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_free (*argv);
|
|
|
|
|
*argv = real_argv;
|
|
|
|
|
*argc = real_argc;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return TRUE;
|
|
|
|
|
#else
|
|
|
|
|
return FALSE;
|
|
|
|
|
#endif /* G_OS_WIN32 */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GList *
|
2010-12-20 19:12:28 +01:00
|
|
|
|
create_files_for_uris (GList *uris)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
GList *res;
|
2010-12-20 19:12:28 +01:00
|
|
|
|
GList *iter;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
res = NULL;
|
2010-12-20 19:12:28 +01:00
|
|
|
|
|
|
|
|
|
for (iter = uris; iter; iter = iter->next)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2010-12-20 19:12:28 +01:00
|
|
|
|
GFile *file = g_file_new_for_uri ((char *)iter->data);
|
2008-01-30 12:27:02 +01:00
|
|
|
|
res = g_list_prepend (res, file);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return g_list_reverse (res);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-20 19:12:28 +01:00
|
|
|
|
static void
|
|
|
|
|
notify_desktop_launch (GDBusConnection *session_bus,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
GDesktopAppInfo *info,
|
|
|
|
|
long pid,
|
|
|
|
|
const char *display,
|
|
|
|
|
const char *sn_id,
|
|
|
|
|
GList *uris)
|
2010-12-20 19:12:28 +01:00
|
|
|
|
{
|
|
|
|
|
GDBusMessage *msg;
|
|
|
|
|
GVariantBuilder uri_variant;
|
|
|
|
|
GVariantBuilder extras_variant;
|
|
|
|
|
GList *iter;
|
2011-01-06 17:47:58 +01:00
|
|
|
|
const char *desktop_file_id;
|
2011-02-07 21:25:33 +01:00
|
|
|
|
const char *gio_desktop_file;
|
2010-12-20 19:12:28 +01:00
|
|
|
|
|
|
|
|
|
if (session_bus == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_variant_builder_init (&uri_variant, G_VARIANT_TYPE ("as"));
|
|
|
|
|
for (iter = uris; iter; iter = iter->next)
|
|
|
|
|
g_variant_builder_add (&uri_variant, "s", iter->data);
|
|
|
|
|
|
|
|
|
|
g_variant_builder_init (&extras_variant, G_VARIANT_TYPE ("a{sv}"));
|
|
|
|
|
if (sn_id != NULL && g_utf8_validate (sn_id, -1, NULL))
|
|
|
|
|
g_variant_builder_add (&extras_variant, "{sv}",
|
2013-07-27 21:08:58 +02:00
|
|
|
|
"startup-id",
|
|
|
|
|
g_variant_new ("s",
|
|
|
|
|
sn_id));
|
2011-02-07 21:25:33 +01:00
|
|
|
|
gio_desktop_file = g_getenv ("GIO_LAUNCHED_DESKTOP_FILE");
|
|
|
|
|
if (gio_desktop_file != NULL)
|
|
|
|
|
g_variant_builder_add (&extras_variant, "{sv}",
|
2013-07-27 21:08:58 +02:00
|
|
|
|
"origin-desktop-file",
|
|
|
|
|
g_variant_new_bytestring (gio_desktop_file));
|
2011-02-16 19:49:20 +01:00
|
|
|
|
if (g_get_prgname () != NULL)
|
|
|
|
|
g_variant_builder_add (&extras_variant, "{sv}",
|
2013-07-27 21:08:58 +02:00
|
|
|
|
"origin-prgname",
|
|
|
|
|
g_variant_new_bytestring (g_get_prgname ()));
|
2011-02-07 21:25:33 +01:00
|
|
|
|
g_variant_builder_add (&extras_variant, "{sv}",
|
2013-07-27 21:08:58 +02:00
|
|
|
|
"origin-pid",
|
|
|
|
|
g_variant_new ("x",
|
|
|
|
|
(gint64)getpid ()));
|
2011-01-06 17:47:58 +01:00
|
|
|
|
|
|
|
|
|
if (info->filename)
|
|
|
|
|
desktop_file_id = info->filename;
|
|
|
|
|
else if (info->desktop_id)
|
|
|
|
|
desktop_file_id = info->desktop_id;
|
|
|
|
|
else
|
|
|
|
|
desktop_file_id = "";
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2010-12-20 19:12:28 +01:00
|
|
|
|
msg = g_dbus_message_new_signal ("/org/gtk/gio/DesktopAppInfo",
|
2013-07-27 21:08:58 +02:00
|
|
|
|
"org.gtk.gio.DesktopAppInfo",
|
|
|
|
|
"Launched");
|
2010-12-20 19:12:28 +01:00
|
|
|
|
g_dbus_message_set_body (msg, g_variant_new ("(@aysxasa{sv})",
|
2013-07-27 21:08:58 +02:00
|
|
|
|
g_variant_new_bytestring (desktop_file_id),
|
|
|
|
|
display ? display : "",
|
|
|
|
|
(gint64)pid,
|
|
|
|
|
&uri_variant,
|
|
|
|
|
&extras_variant));
|
2010-12-20 19:12:28 +01:00
|
|
|
|
g_dbus_connection_send_message (session_bus,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
msg, 0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2010-12-20 19:12:28 +01:00
|
|
|
|
g_object_unref (msg);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-29 08:19:09 +02:00
|
|
|
|
static void
|
|
|
|
|
emit_launch_started (GAppLaunchContext *context,
|
|
|
|
|
GDesktopAppInfo *info,
|
|
|
|
|
const gchar *startup_id)
|
|
|
|
|
{
|
|
|
|
|
GVariantBuilder builder;
|
|
|
|
|
GVariant *platform_data = NULL;
|
|
|
|
|
|
|
|
|
|
if (startup_id)
|
|
|
|
|
{
|
|
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}",
|
|
|
|
|
"startup-notification-id",
|
|
|
|
|
g_variant_new_string (startup_id));
|
|
|
|
|
platform_data = g_variant_ref_sink (g_variant_builder_end (&builder));
|
|
|
|
|
}
|
|
|
|
|
g_signal_emit_by_name (context, "launch-started", info, platform_data);
|
|
|
|
|
g_clear_pointer (&platform_data, g_variant_unref);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-20 20:48:53 +01:00
|
|
|
|
#define _SPAWN_FLAGS_DEFAULT (G_SPAWN_SEARCH_PATH)
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static gboolean
|
2013-04-29 22:37:55 +02:00
|
|
|
|
g_desktop_app_info_launch_uris_with_spawn (GDesktopAppInfo *info,
|
|
|
|
|
GDBusConnection *session_bus,
|
2013-07-11 18:46:59 +02:00
|
|
|
|
const gchar *exec_line,
|
2013-04-29 22:37:55 +02:00
|
|
|
|
GList *uris,
|
|
|
|
|
GAppLaunchContext *launch_context,
|
|
|
|
|
GSpawnFlags spawn_flags,
|
|
|
|
|
GSpawnChildSetupFunc user_setup,
|
|
|
|
|
gpointer user_setup_data,
|
|
|
|
|
GDesktopAppLaunchCallback pid_callback,
|
|
|
|
|
gpointer pid_callback_data,
|
2018-06-06 14:59:59 +02:00
|
|
|
|
gint stdin_fd,
|
|
|
|
|
gint stdout_fd,
|
|
|
|
|
gint stderr_fd,
|
2013-04-29 22:37:55 +02:00
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
gboolean completed = FALSE;
|
2008-01-30 12:27:02 +01:00
|
|
|
|
GList *old_uris;
|
2017-12-07 14:33:20 +01:00
|
|
|
|
GList *dup_uris;
|
|
|
|
|
|
2011-10-15 22:59:59 +02:00
|
|
|
|
char **argv, **envp;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
int argc;
|
|
|
|
|
|
2013-04-29 22:37:55 +02:00
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
argv = NULL;
|
2009-06-10 22:20:51 +02:00
|
|
|
|
|
2011-10-15 22:59:59 +02:00
|
|
|
|
if (launch_context)
|
|
|
|
|
envp = g_app_launch_context_get_environment (launch_context);
|
|
|
|
|
else
|
|
|
|
|
envp = g_get_environ ();
|
|
|
|
|
|
2017-12-07 14:33:20 +01:00
|
|
|
|
/* The GList* passed to expand_application_parameters() will be modified
|
|
|
|
|
* internally by expand_macro(), so we need to pass a copy of it instead,
|
|
|
|
|
* and also use that copy to control the exit condition of the loop below.
|
|
|
|
|
*/
|
2020-07-04 20:01:33 +02:00
|
|
|
|
dup_uris = uris;
|
2009-06-10 22:20:51 +02:00
|
|
|
|
do
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2010-12-20 19:12:28 +01:00
|
|
|
|
GPid pid;
|
|
|
|
|
GList *launched_uris;
|
|
|
|
|
GList *iter;
|
2015-09-15 09:22:12 +02:00
|
|
|
|
char *sn_id = NULL;
|
2018-06-05 03:07:11 +02:00
|
|
|
|
char **wrapped_argv;
|
|
|
|
|
int i;
|
2010-12-20 19:12:28 +01:00
|
|
|
|
|
2017-12-07 14:33:20 +01:00
|
|
|
|
old_uris = dup_uris;
|
|
|
|
|
if (!expand_application_parameters (info, exec_line, &dup_uris, &argc, &argv, error))
|
2011-10-15 22:59:59 +02:00
|
|
|
|
goto out;
|
2010-12-20 19:12:28 +01:00
|
|
|
|
|
|
|
|
|
/* Get the subset of URIs we're launching with this process */
|
|
|
|
|
launched_uris = NULL;
|
2017-12-07 14:33:20 +01:00
|
|
|
|
for (iter = old_uris; iter != NULL && iter != dup_uris; iter = iter->next)
|
2011-10-15 22:59:59 +02:00
|
|
|
|
launched_uris = g_list_prepend (launched_uris, iter->data);
|
2010-12-20 19:12:28 +01:00
|
|
|
|
launched_uris = g_list_reverse (launched_uris);
|
2011-10-15 22:59:59 +02:00
|
|
|
|
|
2022-11-01 00:31:58 +01:00
|
|
|
|
if (info->terminal && !prepend_terminal_to_vector (&argc, &argv,
|
|
|
|
|
g_environ_getenv (envp, "PATH"),
|
|
|
|
|
info->path))
|
2011-10-15 22:59:59 +02:00
|
|
|
|
{
|
|
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
2008-06-16 18:53:58 +02:00
|
|
|
|
_("Unable to find terminal required for application"));
|
2011-10-15 22:59:59 +02:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2011-10-15 22:59:59 +02:00
|
|
|
|
if (info->filename)
|
2018-06-05 03:07:11 +02:00
|
|
|
|
envp = g_environ_setenv (envp,
|
|
|
|
|
"GIO_LAUNCHED_DESKTOP_FILE",
|
|
|
|
|
info->filename,
|
|
|
|
|
TRUE);
|
2011-10-15 22:59:59 +02:00
|
|
|
|
|
|
|
|
|
sn_id = NULL;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
if (launch_context)
|
2011-10-15 22:59:59 +02:00
|
|
|
|
{
|
|
|
|
|
GList *launched_files = create_files_for_uris (launched_uris);
|
|
|
|
|
|
|
|
|
|
if (info->startup_notify)
|
|
|
|
|
{
|
|
|
|
|
sn_id = g_app_launch_context_get_startup_notify_id (launch_context,
|
2013-04-29 22:37:55 +02:00
|
|
|
|
G_APP_INFO (info),
|
2011-10-15 22:59:59 +02:00
|
|
|
|
launched_files);
|
2014-04-12 00:46:38 +02:00
|
|
|
|
if (sn_id)
|
2022-11-25 19:01:10 +01:00
|
|
|
|
{
|
|
|
|
|
envp = g_environ_setenv (envp, "DESKTOP_STARTUP_ID", sn_id, TRUE);
|
|
|
|
|
envp = g_environ_setenv (envp, "XDG_ACTIVATION_TOKEN", sn_id, TRUE);
|
|
|
|
|
}
|
2011-10-15 22:59:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-02 16:30:11 +01:00
|
|
|
|
g_list_free_full (launched_files, g_object_unref);
|
2021-09-29 08:19:09 +02:00
|
|
|
|
|
|
|
|
|
emit_launch_started (launch_context, info, sn_id);
|
2011-10-15 22:59:59 +02:00
|
|
|
|
}
|
2009-06-10 22:20:51 +02:00
|
|
|
|
|
2022-11-01 00:55:15 +01:00
|
|
|
|
g_assert (argc > 0);
|
|
|
|
|
|
|
|
|
|
if (!g_path_is_absolute (argv[0]) ||
|
|
|
|
|
!g_file_test (argv[0], G_FILE_TEST_IS_EXECUTABLE) ||
|
|
|
|
|
g_file_test (argv[0], G_FILE_TEST_IS_DIR))
|
|
|
|
|
{
|
|
|
|
|
char *program = g_steal_pointer (&argv[0]);
|
|
|
|
|
char *program_path = NULL;
|
|
|
|
|
|
|
|
|
|
if (!g_path_is_absolute (program))
|
|
|
|
|
{
|
|
|
|
|
const char *env_path = g_environ_getenv (envp, "PATH");
|
|
|
|
|
|
2023-02-13 17:12:07 +01:00
|
|
|
|
program_path = GLIB_PRIVATE_CALL (g_find_program_for_path) (program,
|
|
|
|
|
env_path,
|
|
|
|
|
info->path);
|
2022-11-01 00:55:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (program_path)
|
|
|
|
|
{
|
|
|
|
|
argv[0] = g_steal_pointer (&program_path);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (sn_id)
|
|
|
|
|
g_app_launch_context_launch_failed (launch_context, sn_id);
|
|
|
|
|
|
|
|
|
|
g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_NOENT,
|
|
|
|
|
_("Program ‘%s’ not found in $PATH"),
|
|
|
|
|
program);
|
|
|
|
|
|
|
|
|
|
g_free (program);
|
|
|
|
|
g_clear_pointer (&sn_id, g_free);
|
|
|
|
|
g_clear_list (&launched_uris, NULL);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (program);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-12 08:59:52 +02:00
|
|
|
|
if (g_once_init_enter_pointer (&gio_launch_desktop_path))
|
2022-07-14 13:02:51 +02:00
|
|
|
|
{
|
2022-07-14 17:43:57 +02:00
|
|
|
|
const gchar *tmp = NULL;
|
|
|
|
|
gboolean is_setuid = GLIB_PRIVATE_CALL (g_check_setuid) ();
|
2022-07-14 13:02:51 +02:00
|
|
|
|
|
|
|
|
|
/* Allow test suite to specify path to gio-launch-desktop */
|
2022-07-14 17:43:57 +02:00
|
|
|
|
if (!is_setuid)
|
|
|
|
|
tmp = g_getenv ("GIO_LAUNCH_DESKTOP");
|
2022-07-14 13:02:51 +02:00
|
|
|
|
|
2022-07-14 15:28:11 +02:00
|
|
|
|
/* Allow build system to specify path to gio-launch-desktop */
|
|
|
|
|
if (tmp == NULL && g_file_test (GIO_LAUNCH_DESKTOP, G_FILE_TEST_IS_EXECUTABLE))
|
|
|
|
|
tmp = GIO_LAUNCH_DESKTOP;
|
|
|
|
|
|
2022-07-14 13:02:51 +02:00
|
|
|
|
/* Fall back on usual searching in $PATH */
|
|
|
|
|
if (tmp == NULL)
|
|
|
|
|
tmp = "gio-launch-desktop";
|
2023-09-12 08:59:52 +02:00
|
|
|
|
g_once_init_leave_pointer (&gio_launch_desktop_path, tmp);
|
2022-07-14 13:02:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wrapped_argv = g_new (char *, argc + 2);
|
|
|
|
|
wrapped_argv[0] = g_strdup (gio_launch_desktop_path);
|
|
|
|
|
|
2018-06-05 03:07:11 +02:00
|
|
|
|
for (i = 0; i < argc; i++)
|
2022-07-14 13:02:51 +02:00
|
|
|
|
wrapped_argv[i + 1] = g_steal_pointer (&argv[i]);
|
2018-06-05 03:07:11 +02:00
|
|
|
|
|
2022-07-14 13:02:51 +02:00
|
|
|
|
wrapped_argv[i + 1] = NULL;
|
2018-06-05 03:07:11 +02:00
|
|
|
|
g_free (argv);
|
|
|
|
|
argv = NULL;
|
|
|
|
|
|
2018-06-06 14:59:59 +02:00
|
|
|
|
if (!g_spawn_async_with_fds (info->path,
|
|
|
|
|
wrapped_argv,
|
|
|
|
|
envp,
|
|
|
|
|
spawn_flags,
|
|
|
|
|
user_setup,
|
|
|
|
|
user_setup_data,
|
|
|
|
|
&pid,
|
|
|
|
|
stdin_fd,
|
|
|
|
|
stdout_fd,
|
|
|
|
|
stderr_fd,
|
|
|
|
|
error))
|
2011-10-15 22:59:59 +02:00
|
|
|
|
{
|
2013-07-27 21:08:58 +02:00
|
|
|
|
if (sn_id)
|
|
|
|
|
g_app_launch_context_launch_failed (launch_context, sn_id);
|
2009-06-10 22:20:51 +02:00
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
g_free (sn_id);
|
|
|
|
|
g_list_free (launched_uris);
|
2022-10-23 17:10:59 +02:00
|
|
|
|
g_clear_pointer (&wrapped_argv, g_strfreev);
|
2009-06-10 22:20:51 +02:00
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2010-12-20 20:48:53 +01:00
|
|
|
|
if (pid_callback != NULL)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
pid_callback (info, pid, pid_callback_data);
|
2010-12-20 20:48:53 +01:00
|
|
|
|
|
2012-11-17 00:24:21 +01:00
|
|
|
|
if (launch_context != NULL)
|
|
|
|
|
{
|
|
|
|
|
GVariantBuilder builder;
|
|
|
|
|
GVariant *platform_data;
|
|
|
|
|
|
|
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "pid", g_variant_new_int32 (pid));
|
|
|
|
|
if (sn_id)
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "startup-notification-id", g_variant_new_string (sn_id));
|
|
|
|
|
platform_data = g_variant_ref_sink (g_variant_builder_end (&builder));
|
|
|
|
|
g_signal_emit_by_name (launch_context, "launched", info, platform_data);
|
|
|
|
|
g_variant_unref (platform_data);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-20 19:12:28 +01:00
|
|
|
|
notify_desktop_launch (session_bus,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
info,
|
|
|
|
|
pid,
|
2015-09-15 09:22:12 +02:00
|
|
|
|
NULL,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
sn_id,
|
|
|
|
|
launched_uris);
|
2010-12-20 19:12:28 +01:00
|
|
|
|
|
2011-10-15 22:59:59 +02:00
|
|
|
|
g_free (sn_id);
|
2010-12-20 19:12:28 +01:00
|
|
|
|
g_list_free (launched_uris);
|
2009-06-10 22:20:51 +02:00
|
|
|
|
|
2018-06-05 03:07:11 +02:00
|
|
|
|
g_strfreev (wrapped_argv);
|
|
|
|
|
wrapped_argv = NULL;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
2017-12-07 14:33:20 +01:00
|
|
|
|
while (dup_uris != NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2013-04-29 22:37:55 +02:00
|
|
|
|
completed = TRUE;
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
g_strfreev (argv);
|
|
|
|
|
g_strfreev (envp);
|
|
|
|
|
|
|
|
|
|
return completed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gchar *
|
2016-04-12 17:06:11 +02:00
|
|
|
|
object_path_from_appid (const gchar *appid)
|
2013-04-29 22:37:55 +02:00
|
|
|
|
{
|
2016-04-12 17:06:11 +02:00
|
|
|
|
gchar *appid_path, *iter;
|
2013-04-29 22:37:55 +02:00
|
|
|
|
|
2016-04-12 17:06:11 +02:00
|
|
|
|
appid_path = g_strconcat ("/", appid, NULL);
|
|
|
|
|
for (iter = appid_path; *iter; iter++)
|
|
|
|
|
{
|
|
|
|
|
if (*iter == '.')
|
|
|
|
|
*iter = '/';
|
2013-04-29 22:37:55 +02:00
|
|
|
|
|
2016-04-12 17:06:11 +02:00
|
|
|
|
if (*iter == '-')
|
|
|
|
|
*iter = '_';
|
|
|
|
|
}
|
2013-04-29 22:37:55 +02:00
|
|
|
|
|
2016-04-12 17:06:11 +02:00
|
|
|
|
return appid_path;
|
2013-04-29 22:37:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-11 18:46:59 +02:00
|
|
|
|
static GVariant *
|
|
|
|
|
g_desktop_app_info_make_platform_data (GDesktopAppInfo *info,
|
|
|
|
|
GList *uris,
|
|
|
|
|
GAppLaunchContext *launch_context)
|
|
|
|
|
{
|
|
|
|
|
GVariantBuilder builder;
|
|
|
|
|
|
|
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
|
|
|
|
|
|
|
|
|
|
if (launch_context)
|
|
|
|
|
{
|
|
|
|
|
GList *launched_files = create_files_for_uris (uris);
|
|
|
|
|
|
|
|
|
|
if (info->startup_notify)
|
|
|
|
|
{
|
|
|
|
|
gchar *sn_id;
|
|
|
|
|
|
|
|
|
|
sn_id = g_app_launch_context_get_startup_notify_id (launch_context, G_APP_INFO (info), launched_files);
|
2014-04-12 00:46:38 +02:00
|
|
|
|
if (sn_id)
|
2022-11-25 19:01:10 +01:00
|
|
|
|
{
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "desktop-startup-id", g_variant_new_string (sn_id));
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "activation-token", g_variant_new_take_string (g_steal_pointer (&sn_id)));
|
|
|
|
|
}
|
2013-07-11 18:46:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free_full (launched_files, g_object_unref);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return g_variant_builder_end (&builder);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 12:15:27 +02:00
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info; /* (owned) */
|
|
|
|
|
GAppLaunchContext *launch_context; /* (owned) (nullable) */
|
|
|
|
|
GAsyncReadyCallback callback;
|
2023-02-03 01:10:41 +01:00
|
|
|
|
gchar *startup_id; /* (owned) (nullable) */
|
2021-08-19 12:15:27 +02:00
|
|
|
|
gpointer user_data;
|
|
|
|
|
} LaunchUrisWithDBusData;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
launch_uris_with_dbus_data_free (LaunchUrisWithDBusData *data)
|
|
|
|
|
{
|
|
|
|
|
g_clear_object (&data->info);
|
|
|
|
|
g_clear_object (&data->launch_context);
|
|
|
|
|
g_free (data->startup_id);
|
|
|
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
launch_uris_with_dbus_signal_cb (GObject *object,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
LaunchUrisWithDBusData *data = user_data;
|
|
|
|
|
GVariantBuilder builder;
|
|
|
|
|
|
|
|
|
|
if (data->launch_context)
|
|
|
|
|
{
|
|
|
|
|
if (g_task_had_error (G_TASK (result)))
|
2023-02-03 01:10:41 +01:00
|
|
|
|
{
|
|
|
|
|
if (data->startup_id != NULL)
|
|
|
|
|
g_app_launch_context_launch_failed (data->launch_context, data->startup_id);
|
|
|
|
|
}
|
2021-08-19 12:15:27 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GVariant *platform_data;
|
|
|
|
|
|
|
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
|
|
|
|
|
/* the docs guarantee `pid` will be set, but we can’t
|
|
|
|
|
* easily know it for a D-Bus process, so set it to zero */
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "pid", g_variant_new_int32 (0));
|
|
|
|
|
if (data->startup_id)
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}",
|
|
|
|
|
"startup-notification-id",
|
|
|
|
|
g_variant_new_string (data->startup_id));
|
|
|
|
|
platform_data = g_variant_ref_sink (g_variant_builder_end (&builder));
|
|
|
|
|
g_signal_emit_by_name (data->launch_context,
|
|
|
|
|
"launched",
|
|
|
|
|
data->info,
|
|
|
|
|
platform_data);
|
|
|
|
|
g_variant_unref (platform_data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data->callback)
|
|
|
|
|
data->callback (object, result, data->user_data);
|
2022-09-02 20:34:21 +02:00
|
|
|
|
else if (!g_task_had_error (G_TASK (result)))
|
|
|
|
|
g_variant_unref (g_dbus_connection_call_finish (G_DBUS_CONNECTION (object),
|
|
|
|
|
result, NULL));
|
2021-08-19 12:15:27 +02:00
|
|
|
|
|
|
|
|
|
launch_uris_with_dbus_data_free (data);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-06 20:22:38 +02:00
|
|
|
|
static void
|
|
|
|
|
launch_uris_with_dbus (GDesktopAppInfo *info,
|
|
|
|
|
GDBusConnection *session_bus,
|
|
|
|
|
GList *uris,
|
2019-01-22 15:39:15 +01:00
|
|
|
|
GAppLaunchContext *launch_context,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data)
|
2013-04-29 22:37:55 +02:00
|
|
|
|
{
|
2021-08-19 12:15:27 +02:00
|
|
|
|
GVariant *platform_data;
|
2013-04-29 22:37:55 +02:00
|
|
|
|
GVariantBuilder builder;
|
2021-08-19 12:15:27 +02:00
|
|
|
|
GVariantDict dict;
|
2013-04-29 22:37:55 +02:00
|
|
|
|
gchar *object_path;
|
2021-08-19 12:15:27 +02:00
|
|
|
|
LaunchUrisWithDBusData *data;
|
2013-04-29 22:37:55 +02:00
|
|
|
|
|
|
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
|
|
|
|
|
|
|
|
|
|
if (uris)
|
|
|
|
|
{
|
|
|
|
|
GList *iter;
|
|
|
|
|
|
|
|
|
|
g_variant_builder_open (&builder, G_VARIANT_TYPE_STRING_ARRAY);
|
|
|
|
|
for (iter = uris; iter; iter = iter->next)
|
|
|
|
|
g_variant_builder_add (&builder, "s", iter->data);
|
|
|
|
|
g_variant_builder_close (&builder);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 12:15:27 +02:00
|
|
|
|
platform_data = g_desktop_app_info_make_platform_data (info, uris, launch_context);
|
2013-04-29 22:37:55 +02:00
|
|
|
|
|
2021-08-19 12:15:27 +02:00
|
|
|
|
g_variant_builder_add_value (&builder, platform_data);
|
2013-04-29 22:37:55 +02:00
|
|
|
|
object_path = object_path_from_appid (info->app_id);
|
2021-08-19 12:15:27 +02:00
|
|
|
|
|
|
|
|
|
data = g_new0 (LaunchUrisWithDBusData, 1);
|
|
|
|
|
data->info = g_object_ref (info);
|
|
|
|
|
data->callback = callback;
|
|
|
|
|
data->user_data = user_data;
|
|
|
|
|
data->launch_context = launch_context ? g_object_ref (launch_context) : NULL;
|
|
|
|
|
g_variant_dict_init (&dict, platform_data);
|
|
|
|
|
g_variant_dict_lookup (&dict, "desktop-startup-id", "s", &data->startup_id);
|
|
|
|
|
|
2021-09-29 08:19:09 +02:00
|
|
|
|
if (launch_context)
|
|
|
|
|
emit_launch_started (launch_context, info, data->startup_id);
|
|
|
|
|
|
2013-04-29 22:37:55 +02:00
|
|
|
|
g_dbus_connection_call (session_bus, info->app_id, object_path, "org.freedesktop.Application",
|
|
|
|
|
uris ? "Open" : "Activate", g_variant_builder_end (&builder),
|
2019-01-22 15:39:15 +01:00
|
|
|
|
NULL, G_DBUS_CALL_FLAGS_NONE, -1,
|
2021-08-19 12:15:27 +02:00
|
|
|
|
cancellable, launch_uris_with_dbus_signal_cb, g_steal_pointer (&data));
|
2013-04-29 22:37:55 +02:00
|
|
|
|
g_free (object_path);
|
2022-02-18 03:37:37 +01:00
|
|
|
|
|
|
|
|
|
g_variant_dict_clear (&dict);
|
2017-05-06 20:22:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
g_desktop_app_info_launch_uris_with_dbus (GDesktopAppInfo *info,
|
|
|
|
|
GDBusConnection *session_bus,
|
|
|
|
|
GList *uris,
|
2019-01-22 15:39:15 +01:00
|
|
|
|
GAppLaunchContext *launch_context,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data)
|
2017-05-06 20:22:38 +02:00
|
|
|
|
{
|
|
|
|
|
GList *ruris = uris;
|
2018-03-27 17:06:54 +02:00
|
|
|
|
char *app_id = NULL;
|
2017-05-06 20:22:38 +02:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
|
app_id = g_desktop_app_info_get_string (info, "X-Flatpak");
|
|
|
|
|
if (app_id && *app_id)
|
|
|
|
|
{
|
|
|
|
|
ruris = g_document_portal_add_documents (uris, app_id, NULL);
|
|
|
|
|
if (ruris == NULL)
|
|
|
|
|
ruris = uris;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-01-22 15:39:15 +01:00
|
|
|
|
launch_uris_with_dbus (info, session_bus, ruris, launch_context,
|
|
|
|
|
cancellable, callback, user_data);
|
2017-05-06 20:22:38 +02:00
|
|
|
|
|
|
|
|
|
if (ruris != uris)
|
|
|
|
|
g_list_free_full (ruris, g_free);
|
2013-04-29 22:37:55 +02:00
|
|
|
|
|
2018-03-27 17:06:54 +02:00
|
|
|
|
g_free (app_id);
|
|
|
|
|
|
2013-04-29 22:37:55 +02:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
g_desktop_app_info_launch_uris_internal (GAppInfo *appinfo,
|
|
|
|
|
GList *uris,
|
|
|
|
|
GAppLaunchContext *launch_context,
|
|
|
|
|
GSpawnFlags spawn_flags,
|
|
|
|
|
GSpawnChildSetupFunc user_setup,
|
|
|
|
|
gpointer user_setup_data,
|
|
|
|
|
GDesktopAppLaunchCallback pid_callback,
|
|
|
|
|
gpointer pid_callback_data,
|
2018-06-06 14:59:59 +02:00
|
|
|
|
gint stdin_fd,
|
|
|
|
|
gint stdout_fd,
|
|
|
|
|
gint stderr_fd,
|
2013-04-29 22:37:55 +02:00
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
GDBusConnection *session_bus;
|
|
|
|
|
gboolean success = TRUE;
|
|
|
|
|
|
|
|
|
|
session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (session_bus && info->app_id)
|
2019-01-22 15:39:15 +01:00
|
|
|
|
/* This is non-blocking API. Similar to launching via fork()/exec()
|
|
|
|
|
* we don't wait around to see if the program crashed during startup.
|
|
|
|
|
* This is what startup-notification's job is...
|
|
|
|
|
*/
|
|
|
|
|
g_desktop_app_info_launch_uris_with_dbus (info, session_bus, uris, launch_context,
|
|
|
|
|
NULL, NULL, NULL);
|
2013-04-29 22:37:55 +02:00
|
|
|
|
else
|
2013-07-11 18:46:59 +02:00
|
|
|
|
success = g_desktop_app_info_launch_uris_with_spawn (info, session_bus, info->exec, uris, launch_context,
|
2013-04-29 22:37:55 +02:00
|
|
|
|
spawn_flags, user_setup, user_setup_data,
|
2018-06-06 14:59:59 +02:00
|
|
|
|
pid_callback, pid_callback_data,
|
|
|
|
|
stdin_fd, stdout_fd, stderr_fd, error);
|
2013-04-29 22:37:55 +02:00
|
|
|
|
|
2010-12-20 19:12:28 +01:00
|
|
|
|
if (session_bus != NULL)
|
2011-02-04 21:37:51 +01:00
|
|
|
|
{
|
|
|
|
|
/* This asynchronous flush holds a reference until it completes,
|
|
|
|
|
* which ensures that the following unref won't immediately kill
|
|
|
|
|
* the connection if we were the initial owner.
|
|
|
|
|
*/
|
|
|
|
|
g_dbus_connection_flush (session_bus, NULL, NULL, NULL);
|
2013-04-29 22:37:55 +02:00
|
|
|
|
g_object_unref (session_bus);
|
2011-02-04 21:37:51 +01:00
|
|
|
|
}
|
2010-12-20 19:12:28 +01:00
|
|
|
|
|
2013-04-29 22:37:55 +02:00
|
|
|
|
return success;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-20 20:48:53 +01:00
|
|
|
|
static gboolean
|
|
|
|
|
g_desktop_app_info_launch_uris (GAppInfo *appinfo,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
GList *uris,
|
|
|
|
|
GAppLaunchContext *launch_context,
|
|
|
|
|
GError **error)
|
2010-12-20 20:48:53 +01:00
|
|
|
|
{
|
2013-04-29 22:37:55 +02:00
|
|
|
|
return g_desktop_app_info_launch_uris_internal (appinfo, uris,
|
|
|
|
|
launch_context,
|
|
|
|
|
_SPAWN_FLAGS_DEFAULT,
|
|
|
|
|
NULL, NULL, NULL, NULL,
|
2018-06-06 14:59:59 +02:00
|
|
|
|
-1, -1, -1,
|
2013-04-29 22:37:55 +02:00
|
|
|
|
error);
|
2010-12-20 20:48:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-22 15:39:15 +01:00
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2022-07-21 16:39:27 +02:00
|
|
|
|
GList *uris; /* (element-type utf8) (owned) (nullable) */
|
|
|
|
|
GAppLaunchContext *context; /* (owned) (nullable) */
|
2019-01-22 15:39:15 +01:00
|
|
|
|
} LaunchUrisData;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
launch_uris_data_free (LaunchUrisData *data)
|
|
|
|
|
{
|
|
|
|
|
g_clear_object (&data->context);
|
|
|
|
|
g_list_free_full (data->uris, g_free);
|
|
|
|
|
g_free (data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
launch_uris_with_dbus_cb (GObject *object,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GTask *task = G_TASK (user_data);
|
2022-07-21 16:39:27 +02:00
|
|
|
|
GError *local_error = NULL;
|
2022-09-02 20:38:46 +02:00
|
|
|
|
GVariant *ret;
|
2019-01-22 15:39:15 +01:00
|
|
|
|
|
2022-09-02 20:38:46 +02:00
|
|
|
|
ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (object), result, &local_error);
|
2022-07-21 16:39:27 +02:00
|
|
|
|
if (local_error != NULL)
|
2019-01-22 15:39:15 +01:00
|
|
|
|
{
|
2022-07-21 16:39:27 +02:00
|
|
|
|
g_dbus_error_strip_remote_error (local_error);
|
|
|
|
|
g_task_return_error (task, g_steal_pointer (&local_error));
|
2019-01-22 15:39:15 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
2022-09-02 20:38:46 +02:00
|
|
|
|
{
|
|
|
|
|
g_task_return_boolean (task, TRUE);
|
|
|
|
|
g_variant_unref (ret);
|
|
|
|
|
}
|
2019-01-22 15:39:15 +01:00
|
|
|
|
|
|
|
|
|
g_object_unref (task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
launch_uris_flush_cb (GObject *object,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GTask *task = G_TASK (user_data);
|
|
|
|
|
|
|
|
|
|
g_dbus_connection_flush_finish (G_DBUS_CONNECTION (object), result, NULL);
|
|
|
|
|
g_task_return_boolean (task, TRUE);
|
|
|
|
|
g_object_unref (task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
launch_uris_bus_get_cb (GObject *object,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GTask *task = G_TASK (user_data);
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (g_task_get_source_object (task));
|
|
|
|
|
LaunchUrisData *data = g_task_get_task_data (task);
|
|
|
|
|
GCancellable *cancellable = g_task_get_cancellable (task);
|
|
|
|
|
GDBusConnection *session_bus;
|
2022-07-21 16:39:27 +02:00
|
|
|
|
GError *local_error = NULL;
|
2019-01-22 15:39:15 +01:00
|
|
|
|
|
|
|
|
|
session_bus = g_bus_get_finish (result, NULL);
|
|
|
|
|
|
|
|
|
|
if (session_bus && info->app_id)
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: The g_document_portal_add_documents() function, which is called
|
|
|
|
|
* from the g_desktop_app_info_launch_uris_with_dbus() function, still
|
|
|
|
|
* uses blocking calls.
|
|
|
|
|
*/
|
|
|
|
|
g_desktop_app_info_launch_uris_with_dbus (info, session_bus,
|
|
|
|
|
data->uris, data->context,
|
|
|
|
|
cancellable,
|
|
|
|
|
launch_uris_with_dbus_cb,
|
|
|
|
|
g_steal_pointer (&task));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: The D-Bus message from the notify_desktop_launch() function
|
|
|
|
|
* can be still lost even if flush is called later. See:
|
|
|
|
|
* https://gitlab.freedesktop.org/dbus/dbus/issues/72
|
|
|
|
|
*/
|
|
|
|
|
g_desktop_app_info_launch_uris_with_spawn (info, session_bus, info->exec,
|
|
|
|
|
data->uris, data->context,
|
|
|
|
|
_SPAWN_FLAGS_DEFAULT, NULL,
|
|
|
|
|
NULL, NULL, NULL, -1, -1, -1,
|
2022-07-21 16:39:27 +02:00
|
|
|
|
&local_error);
|
|
|
|
|
if (local_error != NULL)
|
2019-01-22 15:39:15 +01:00
|
|
|
|
{
|
2022-07-21 16:39:27 +02:00
|
|
|
|
g_task_return_error (task, g_steal_pointer (&local_error));
|
2019-01-22 15:39:15 +01:00
|
|
|
|
g_object_unref (task);
|
|
|
|
|
}
|
2022-06-14 23:10:16 +02:00
|
|
|
|
else if (session_bus)
|
2019-01-22 15:39:15 +01:00
|
|
|
|
g_dbus_connection_flush (session_bus,
|
|
|
|
|
cancellable,
|
|
|
|
|
launch_uris_flush_cb,
|
|
|
|
|
g_steal_pointer (&task));
|
2022-06-14 23:10:16 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_task_return_boolean (task, TRUE);
|
|
|
|
|
g_clear_object (&task);
|
|
|
|
|
}
|
2019-01-22 15:39:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_clear_object (&session_bus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_desktop_app_info_launch_uris_async (GAppInfo *appinfo,
|
|
|
|
|
GList *uris,
|
|
|
|
|
GAppLaunchContext *context,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GTask *task;
|
|
|
|
|
LaunchUrisData *data;
|
|
|
|
|
|
|
|
|
|
task = g_task_new (appinfo, cancellable, callback, user_data);
|
|
|
|
|
g_task_set_source_tag (task, g_desktop_app_info_launch_uris_async);
|
|
|
|
|
|
|
|
|
|
data = g_new0 (LaunchUrisData, 1);
|
|
|
|
|
data->uris = g_list_copy_deep (uris, (GCopyFunc) g_strdup, NULL);
|
2022-07-21 16:39:27 +02:00
|
|
|
|
g_set_object (&data->context, context);
|
2019-01-22 15:39:15 +01:00
|
|
|
|
g_task_set_task_data (task, g_steal_pointer (&data), (GDestroyNotify) launch_uris_data_free);
|
|
|
|
|
|
|
|
|
|
g_bus_get (G_BUS_TYPE_SESSION, cancellable, launch_uris_bus_get_cb, task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
g_desktop_app_info_launch_uris_finish (GAppInfo *appinfo,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (g_task_is_valid (result, appinfo), FALSE);
|
|
|
|
|
|
|
|
|
|
return g_task_propagate_boolean (G_TASK (result), error);
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static gboolean
|
|
|
|
|
g_desktop_app_info_supports_uris (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
|
|
|
|
return info->exec &&
|
2007-12-22 19:15:57 +01:00
|
|
|
|
((strstr (info->exec, "%u") != NULL) ||
|
|
|
|
|
(strstr (info->exec, "%U") != NULL));
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-04 11:51:56 +01:00
|
|
|
|
static gboolean
|
|
|
|
|
g_desktop_app_info_supports_files (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
|
|
|
|
return info->exec &&
|
2008-01-04 11:51:56 +01:00
|
|
|
|
((strstr (info->exec, "%f") != NULL) ||
|
|
|
|
|
(strstr (info->exec, "%F") != NULL));
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static gboolean
|
2008-01-30 12:27:02 +01:00
|
|
|
|
g_desktop_app_info_launch (GAppInfo *appinfo,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
GList *files,
|
|
|
|
|
GAppLaunchContext *launch_context,
|
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2008-01-30 12:27:02 +01:00
|
|
|
|
GList *uris;
|
|
|
|
|
char *uri;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
gboolean res;
|
|
|
|
|
|
2008-01-30 12:27:02 +01:00
|
|
|
|
uris = NULL;
|
|
|
|
|
while (files)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2008-01-30 12:27:02 +01:00
|
|
|
|
uri = g_file_get_uri (files->data);
|
|
|
|
|
uris = g_list_prepend (uris, uri);
|
|
|
|
|
files = files->next;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-01-30 12:27:02 +01:00
|
|
|
|
uris = g_list_reverse (uris);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-01-30 12:27:02 +01:00
|
|
|
|
res = g_desktop_app_info_launch_uris (appinfo, uris, launch_context, error);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2012-01-02 16:30:11 +01:00
|
|
|
|
g_list_free_full (uris, g_free);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-06 14:59:59 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_launch_uris_as_manager_with_fds:
|
|
|
|
|
* @appinfo: a #GDesktopAppInfo
|
|
|
|
|
* @uris: (element-type utf8): List of URIs
|
|
|
|
|
* @launch_context: (nullable): a #GAppLaunchContext
|
|
|
|
|
* @spawn_flags: #GSpawnFlags, used for each process
|
2023-01-13 17:06:23 +01:00
|
|
|
|
* @user_setup: (scope async) (nullable) (closure user_setup_data): a #GSpawnChildSetupFunc, used once
|
2018-06-06 14:59:59 +02:00
|
|
|
|
* for each process.
|
2023-01-13 17:06:23 +01:00
|
|
|
|
* @user_setup_data: User data for @user_setup
|
|
|
|
|
* @pid_callback: (scope call) (nullable) (closure pid_callback_data): Callback for child processes
|
|
|
|
|
* @pid_callback_data: User data for @callback
|
2018-06-06 14:59:59 +02:00
|
|
|
|
* @stdin_fd: file descriptor to use for child's stdin, or -1
|
|
|
|
|
* @stdout_fd: file descriptor to use for child's stdout, or -1
|
|
|
|
|
* @stderr_fd: file descriptor to use for child's stderr, or -1
|
|
|
|
|
* @error: return location for a #GError, or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Equivalent to g_desktop_app_info_launch_uris_as_manager() but allows
|
|
|
|
|
* you to pass in file descriptors for the stdin, stdout and stderr streams
|
|
|
|
|
* of the launched process.
|
|
|
|
|
*
|
|
|
|
|
* If application launching occurs via some non-spawn mechanism (e.g. D-Bus
|
|
|
|
|
* activation) then @stdin_fd, @stdout_fd and @stderr_fd are ignored.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on successful launch, %FALSE otherwise.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.58
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
g_desktop_app_info_launch_uris_as_manager_with_fds (GDesktopAppInfo *appinfo,
|
|
|
|
|
GList *uris,
|
|
|
|
|
GAppLaunchContext *launch_context,
|
|
|
|
|
GSpawnFlags spawn_flags,
|
|
|
|
|
GSpawnChildSetupFunc user_setup,
|
|
|
|
|
gpointer user_setup_data,
|
|
|
|
|
GDesktopAppLaunchCallback pid_callback,
|
|
|
|
|
gpointer pid_callback_data,
|
|
|
|
|
gint stdin_fd,
|
|
|
|
|
gint stdout_fd,
|
|
|
|
|
gint stderr_fd,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
return g_desktop_app_info_launch_uris_internal ((GAppInfo*)appinfo,
|
|
|
|
|
uris,
|
|
|
|
|
launch_context,
|
|
|
|
|
spawn_flags,
|
|
|
|
|
user_setup,
|
|
|
|
|
user_setup_data,
|
|
|
|
|
pid_callback,
|
|
|
|
|
pid_callback_data,
|
|
|
|
|
stdin_fd,
|
|
|
|
|
stdout_fd,
|
|
|
|
|
stderr_fd,
|
|
|
|
|
error);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-20 20:48:53 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_launch_uris_as_manager:
|
|
|
|
|
* @appinfo: a #GDesktopAppInfo
|
|
|
|
|
* @uris: (element-type utf8): List of URIs
|
2016-10-29 03:29:02 +02:00
|
|
|
|
* @launch_context: (nullable): a #GAppLaunchContext
|
2010-12-20 20:48:53 +01:00
|
|
|
|
* @spawn_flags: #GSpawnFlags, used for each process
|
2015-10-02 19:57:14 +02:00
|
|
|
|
* @user_setup: (scope async) (nullable): a #GSpawnChildSetupFunc, used once
|
2013-12-11 13:17:10 +01:00
|
|
|
|
* for each process.
|
2016-10-29 03:29:02 +02:00
|
|
|
|
* @user_setup_data: (closure user_setup) (nullable): User data for @user_setup
|
|
|
|
|
* @pid_callback: (scope call) (nullable): Callback for child processes
|
|
|
|
|
* @pid_callback_data: (closure pid_callback) (nullable): User data for @callback
|
2011-05-02 05:02:53 +02:00
|
|
|
|
* @error: return location for a #GError, or %NULL
|
2010-12-20 20:48:53 +01:00
|
|
|
|
*
|
|
|
|
|
* This function performs the equivalent of g_app_info_launch_uris(),
|
|
|
|
|
* but is intended primarily for operating system components that
|
|
|
|
|
* launch applications. Ordinary applications should use
|
|
|
|
|
* g_app_info_launch_uris().
|
|
|
|
|
*
|
2018-06-05 03:07:11 +02:00
|
|
|
|
* If the application is launched via GSpawn, then @spawn_flags, @user_setup
|
|
|
|
|
* and @user_setup_data are used for the call to g_spawn_async().
|
|
|
|
|
* Additionally, @pid_callback (with @pid_callback_data) will be called to
|
|
|
|
|
* inform about the PID of the created process. See g_spawn_async_with_pipes()
|
|
|
|
|
* for information on certain parameter conditions that can enable an
|
|
|
|
|
* optimized posix_spawn() codepath to be used.
|
2010-12-20 20:48:53 +01:00
|
|
|
|
*
|
2013-04-29 22:37:55 +02:00
|
|
|
|
* If application launching occurs via some other mechanism (eg: D-Bus
|
|
|
|
|
* activation) then @spawn_flags, @user_setup, @user_setup_data,
|
|
|
|
|
* @pid_callback and @pid_callback_data are ignored.
|
2011-05-02 05:02:53 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on successful launch, %FALSE otherwise.
|
2010-12-20 20:48:53 +01:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
g_desktop_app_info_launch_uris_as_manager (GDesktopAppInfo *appinfo,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
GList *uris,
|
|
|
|
|
GAppLaunchContext *launch_context,
|
|
|
|
|
GSpawnFlags spawn_flags,
|
|
|
|
|
GSpawnChildSetupFunc user_setup,
|
|
|
|
|
gpointer user_setup_data,
|
|
|
|
|
GDesktopAppLaunchCallback pid_callback,
|
|
|
|
|
gpointer pid_callback_data,
|
|
|
|
|
GError **error)
|
2010-12-20 20:48:53 +01:00
|
|
|
|
{
|
2018-06-06 14:59:59 +02:00
|
|
|
|
return g_desktop_app_info_launch_uris_as_manager_with_fds (appinfo,
|
|
|
|
|
uris,
|
|
|
|
|
launch_context,
|
|
|
|
|
spawn_flags,
|
|
|
|
|
user_setup,
|
|
|
|
|
user_setup_data,
|
|
|
|
|
pid_callback,
|
|
|
|
|
pid_callback_data,
|
|
|
|
|
-1, -1, -1,
|
|
|
|
|
error);
|
2010-12-20 20:48:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* OnlyShowIn API support {{{2 */
|
|
|
|
|
|
2008-01-04 11:51:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_set_desktop_env:
|
|
|
|
|
* @desktop_env: a string specifying what desktop this is
|
|
|
|
|
*
|
|
|
|
|
* Sets the name of the desktop that the application is running in.
|
2011-07-21 15:23:00 +02:00
|
|
|
|
* This is used by g_app_info_should_show() and
|
|
|
|
|
* g_desktop_app_info_get_show_in() to evaluate the
|
2014-02-06 14:04:52 +01:00
|
|
|
|
* `OnlyShowIn` and `NotShowIn`
|
2008-01-04 11:51:56 +01:00
|
|
|
|
* desktop entry fields.
|
|
|
|
|
*
|
|
|
|
|
* Should be called only once; subsequent calls are ignored.
|
2014-05-08 14:57:50 +02:00
|
|
|
|
*
|
|
|
|
|
* Deprecated:2.42:do not use this API. Since 2.42 the value of the
|
|
|
|
|
* `XDG_CURRENT_DESKTOP` environment variable will be used.
|
2008-01-04 11:51:56 +01:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
g_desktop_app_info_set_desktop_env (const gchar *desktop_env)
|
|
|
|
|
{
|
2014-05-08 14:57:50 +02:00
|
|
|
|
get_current_desktops (desktop_env);
|
2008-01-04 11:51:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static gboolean
|
2008-01-04 11:51:56 +01:00
|
|
|
|
g_desktop_app_info_should_show (GAppInfo *appinfo)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
|
|
|
|
|
if (info->nodisplay)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2011-07-21 15:23:00 +02:00
|
|
|
|
return g_desktop_app_info_get_show_in (info, NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* mime types/default apps support {{{2 */
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
typedef enum {
|
2014-04-09 14:44:18 +02:00
|
|
|
|
CONF_DIR,
|
2007-11-26 17:13:05 +01:00
|
|
|
|
APP_DIR,
|
|
|
|
|
MIMETYPE_DIR
|
|
|
|
|
} DirType;
|
|
|
|
|
|
|
|
|
|
static char *
|
2007-11-29 08:17:59 +01:00
|
|
|
|
ensure_dir (DirType type,
|
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
char *path, *display_name;
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
|
int errsv;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case CONF_DIR:
|
|
|
|
|
path = g_build_filename (g_get_user_config_dir (), NULL);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case APP_DIR:
|
|
|
|
|
path = g_build_filename (g_get_user_data_dir (), "applications", NULL);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MIMETYPE_DIR:
|
|
|
|
|
path = g_build_filename (g_get_user_data_dir (), "mime", "packages", NULL);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2018-12-13 18:01:19 +01:00
|
|
|
|
g_debug ("%s: Ensuring %s", G_STRFUNC, path);
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
errno = 0;
|
|
|
|
|
if (g_mkdir_with_parents (path, 0700) == 0)
|
|
|
|
|
return path;
|
|
|
|
|
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
|
errsv = errno;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
display_name = g_filename_display_name (path);
|
|
|
|
|
if (type == APP_DIR)
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
|
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
|
2016-09-30 05:47:15 +02:00
|
|
|
|
_("Can’t create user application configuration folder %s: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
|
display_name, g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
|
else
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
|
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
|
2016-09-30 05:47:15 +02:00
|
|
|
|
_("Can’t create user MIME configuration folder %s: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
|
display_name, g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
g_free (display_name);
|
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-07-27 21:08:58 +02:00
|
|
|
|
update_mimeapps_list (const char *desktop_id,
|
|
|
|
|
const char *content_type,
|
2010-12-15 17:56:22 +01:00
|
|
|
|
UpdateMimeFlags flags,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2010-12-15 17:56:22 +01:00
|
|
|
|
char *dirname, *filename, *string;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
GKeyFile *key_file;
|
2011-09-26 09:56:22 +02:00
|
|
|
|
gboolean load_succeeded, res;
|
2008-10-13 12:02:30 +02:00
|
|
|
|
char **old_list, **list;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
gsize length, data_size;
|
|
|
|
|
char *data;
|
2008-09-26 21:57:36 +02:00
|
|
|
|
int i, j, k;
|
|
|
|
|
char **content_types;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2008-01-25 13:06:14 +01:00
|
|
|
|
/* Don't add both at start and end */
|
2010-12-15 17:56:22 +01:00
|
|
|
|
g_assert (!((flags & UPDATE_MIME_SET_DEFAULT) &&
|
|
|
|
|
(flags & UPDATE_MIME_SET_NON_DEFAULT)));
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
dirname = ensure_dir (CONF_DIR, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
if (!dirname)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2008-02-06 11:57:27 +01:00
|
|
|
|
filename = g_build_filename (dirname, "mimeapps.list", NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_free (dirname);
|
|
|
|
|
|
|
|
|
|
key_file = g_key_file_new ();
|
|
|
|
|
load_succeeded = g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, NULL);
|
2011-09-30 05:32:20 +02:00
|
|
|
|
if (!load_succeeded ||
|
|
|
|
|
(!g_key_file_has_group (key_file, ADDED_ASSOCIATIONS_GROUP) &&
|
|
|
|
|
!g_key_file_has_group (key_file, REMOVED_ASSOCIATIONS_GROUP) &&
|
|
|
|
|
!g_key_file_has_group (key_file, DEFAULT_APPLICATIONS_GROUP)))
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
g_key_file_free (key_file);
|
|
|
|
|
key_file = g_key_file_new ();
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
if (content_type)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2008-09-26 21:57:36 +02:00
|
|
|
|
content_types = g_new (char *, 2);
|
|
|
|
|
content_types[0] = g_strdup (content_type);
|
|
|
|
|
content_types[1] = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-12-15 17:56:22 +01:00
|
|
|
|
content_types = g_key_file_get_keys (key_file, DEFAULT_APPLICATIONS_GROUP, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (k = 0; content_types && content_types[k]; k++)
|
|
|
|
|
{
|
|
|
|
|
/* set as default, if requested so */
|
|
|
|
|
string = g_key_file_get_string (key_file,
|
|
|
|
|
DEFAULT_APPLICATIONS_GROUP,
|
|
|
|
|
content_types[k],
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (g_strcmp0 (string, desktop_id) != 0 &&
|
|
|
|
|
(flags & UPDATE_MIME_SET_DEFAULT))
|
|
|
|
|
{
|
|
|
|
|
g_free (string);
|
|
|
|
|
string = g_strdup (desktop_id);
|
|
|
|
|
|
|
|
|
|
/* add in the non-default list too, if it's not already there */
|
|
|
|
|
flags |= UPDATE_MIME_SET_NON_DEFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string == NULL || desktop_id == NULL)
|
|
|
|
|
g_key_file_remove_key (key_file,
|
|
|
|
|
DEFAULT_APPLICATIONS_GROUP,
|
|
|
|
|
content_types[k],
|
|
|
|
|
NULL);
|
|
|
|
|
else
|
2011-09-26 09:56:22 +02:00
|
|
|
|
g_key_file_set_string (key_file,
|
|
|
|
|
DEFAULT_APPLICATIONS_GROUP,
|
|
|
|
|
content_types[k],
|
|
|
|
|
string);
|
2010-12-15 17:56:22 +01:00
|
|
|
|
|
|
|
|
|
g_free (string);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-15 17:56:22 +01:00
|
|
|
|
if (content_type)
|
|
|
|
|
{
|
|
|
|
|
/* reuse the list from above */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_strfreev (content_types);
|
|
|
|
|
content_types = g_key_file_get_keys (key_file, ADDED_ASSOCIATIONS_GROUP, NULL, NULL);
|
|
|
|
|
}
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
for (k = 0; content_types && content_types[k]; k++)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
2008-09-26 21:57:36 +02:00
|
|
|
|
/* Add to the right place in the list */
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
length = 0;
|
|
|
|
|
old_list = g_key_file_get_string_list (key_file, ADDED_ASSOCIATIONS_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
content_types[k], &length, NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
list = g_new (char *, 1 + length + 1);
|
2008-01-25 13:06:14 +01:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
i = 0;
|
2010-12-15 17:56:22 +01:00
|
|
|
|
|
|
|
|
|
/* if we're adding a last-used hint, just put the application in front of the list */
|
|
|
|
|
if (flags & UPDATE_MIME_SET_LAST_USED)
|
|
|
|
|
{
|
|
|
|
|
/* avoid adding this again as non-default later */
|
|
|
|
|
if (flags & UPDATE_MIME_SET_NON_DEFAULT)
|
|
|
|
|
flags ^= UPDATE_MIME_SET_NON_DEFAULT;
|
|
|
|
|
|
|
|
|
|
list[i++] = g_strdup (desktop_id);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
if (old_list)
|
|
|
|
|
{
|
|
|
|
|
for (j = 0; old_list[j] != NULL; j++)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
|
|
|
|
if (g_strcmp0 (old_list[j], desktop_id) != 0)
|
2010-12-15 17:56:22 +01:00
|
|
|
|
{
|
|
|
|
|
/* rewrite other entries if they're different from the new one */
|
|
|
|
|
list[i++] = g_strdup (old_list[j]);
|
|
|
|
|
}
|
2013-07-27 21:08:58 +02:00
|
|
|
|
else if (flags & UPDATE_MIME_SET_NON_DEFAULT)
|
|
|
|
|
{
|
2010-12-15 17:56:22 +01:00
|
|
|
|
/* we encountered an old entry which is equal to the one we're adding as non-default,
|
|
|
|
|
* don't change its position in the list.
|
|
|
|
|
*/
|
2013-07-27 21:08:58 +02:00
|
|
|
|
flags ^= UPDATE_MIME_SET_NON_DEFAULT;
|
|
|
|
|
list[i++] = g_strdup (old_list[j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-09-26 21:57:36 +02:00
|
|
|
|
}
|
2008-10-13 12:02:30 +02:00
|
|
|
|
|
2010-12-15 17:56:22 +01:00
|
|
|
|
/* add it at the end of the list */
|
|
|
|
|
if (flags & UPDATE_MIME_SET_NON_DEFAULT)
|
|
|
|
|
list[i++] = g_strdup (desktop_id);
|
2010-11-18 18:49:32 +01:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
list[i] = NULL;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
g_strfreev (old_list);
|
2008-01-25 13:06:14 +01:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
if (list[0] == NULL || desktop_id == NULL)
|
|
|
|
|
g_key_file_remove_key (key_file,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
ADDED_ASSOCIATIONS_GROUP,
|
|
|
|
|
content_types[k],
|
|
|
|
|
NULL);
|
2008-09-26 21:57:36 +02:00
|
|
|
|
else
|
2011-09-26 09:56:22 +02:00
|
|
|
|
g_key_file_set_string_list (key_file,
|
|
|
|
|
ADDED_ASSOCIATIONS_GROUP,
|
|
|
|
|
content_types[k],
|
|
|
|
|
(const char * const *)list, i);
|
2010-12-20 17:44:51 +01:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
g_strfreev (list);
|
|
|
|
|
}
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
if (content_type)
|
2008-01-25 13:06:14 +01:00
|
|
|
|
{
|
2008-09-26 21:57:36 +02:00
|
|
|
|
/* reuse the list from above */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_strfreev (content_types);
|
|
|
|
|
content_types = g_key_file_get_keys (key_file, REMOVED_ASSOCIATIONS_GROUP, NULL, NULL);
|
2008-01-25 13:06:14 +01:00
|
|
|
|
}
|
2008-09-26 21:57:36 +02:00
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
for (k = 0; content_types && content_types[k]; k++)
|
2008-09-26 21:57:36 +02:00
|
|
|
|
{
|
|
|
|
|
/* Remove from removed associations group (unless remove) */
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
length = 0;
|
|
|
|
|
old_list = g_key_file_get_string_list (key_file, REMOVED_ASSOCIATIONS_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
content_types[k], &length, NULL);
|
2008-01-25 13:06:14 +01:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
list = g_new (char *, 1 + length + 1);
|
|
|
|
|
|
|
|
|
|
i = 0;
|
2010-12-15 17:56:22 +01:00
|
|
|
|
if (flags & UPDATE_MIME_REMOVE)
|
2008-09-26 21:57:36 +02:00
|
|
|
|
list[i++] = g_strdup (desktop_id);
|
|
|
|
|
if (old_list)
|
|
|
|
|
{
|
|
|
|
|
for (j = 0; old_list[j] != NULL; j++)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
|
|
|
|
if (g_strcmp0 (old_list[j], desktop_id) != 0)
|
|
|
|
|
list[i++] = g_strdup (old_list[j]);
|
|
|
|
|
}
|
2008-09-26 21:57:36 +02:00
|
|
|
|
}
|
|
|
|
|
list[i] = NULL;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
g_strfreev (old_list);
|
2008-01-25 13:06:14 +01:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
if (list[0] == NULL || desktop_id == NULL)
|
|
|
|
|
g_key_file_remove_key (key_file,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
REMOVED_ASSOCIATIONS_GROUP,
|
|
|
|
|
content_types[k],
|
|
|
|
|
NULL);
|
2008-09-26 21:57:36 +02:00
|
|
|
|
else
|
|
|
|
|
g_key_file_set_string_list (key_file,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
REMOVED_ASSOCIATIONS_GROUP,
|
|
|
|
|
content_types[k],
|
|
|
|
|
(const char * const *)list, i);
|
2008-01-25 13:06:14 +01:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
g_strfreev (list);
|
|
|
|
|
}
|
2010-12-15 17:56:22 +01:00
|
|
|
|
|
2011-09-30 05:32:20 +02:00
|
|
|
|
g_strfreev (content_types);
|
2008-09-26 21:57:36 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
data = g_key_file_to_data (key_file, &data_size, error);
|
|
|
|
|
g_key_file_free (key_file);
|
2011-09-30 05:32:20 +02:00
|
|
|
|
|
2020-05-27 19:00:48 +02:00
|
|
|
|
res = g_file_set_contents_full (filename, data, data_size,
|
|
|
|
|
G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING,
|
|
|
|
|
0600, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
desktop_file_dirs_invalidate_user_config ();
|
2011-09-30 05:32:20 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_free (filename);
|
|
|
|
|
g_free (data);
|
2011-09-30 05:32:20 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-15 17:56:22 +01:00
|
|
|
|
static gboolean
|
|
|
|
|
g_desktop_app_info_set_as_last_used_for_type (GAppInfo *appinfo,
|
|
|
|
|
const char *content_type,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
|
|
|
|
|
if (!g_desktop_app_info_ensure_saved (info, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2011-08-26 17:36:12 +02:00
|
|
|
|
if (!info->desktop_id)
|
|
|
|
|
{
|
|
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
|
_("Application information lacks an identifier"));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-15 17:56:22 +01:00
|
|
|
|
/* both add support for the content type and set as last used */
|
|
|
|
|
return update_mimeapps_list (info->desktop_id, content_type,
|
|
|
|
|
UPDATE_MIME_SET_NON_DEFAULT |
|
|
|
|
|
UPDATE_MIME_SET_LAST_USED,
|
|
|
|
|
error);
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static gboolean
|
|
|
|
|
g_desktop_app_info_set_as_default_for_type (GAppInfo *appinfo,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
const char *content_type,
|
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
if (!g_desktop_app_info_ensure_saved (info, error))
|
2011-08-26 17:36:12 +02:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!info->desktop_id)
|
|
|
|
|
{
|
|
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
|
_("Application information lacks an identifier"));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-15 17:56:22 +01:00
|
|
|
|
return update_mimeapps_list (info->desktop_id, content_type,
|
|
|
|
|
UPDATE_MIME_SET_DEFAULT,
|
|
|
|
|
error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_program_done (GPid pid,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
gint status,
|
|
|
|
|
gpointer data)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
/* Did the application exit correctly */
|
Distinguish more clearly between wait status and exit status
On Unix platforms, wait() and friends yield an integer that encodes
how the process exited. Confusingly, this is usually not the same as
the integer passed to exit() or returned from main(): conceptually it's
an integer encoding of this tagged union:
enum { EXITED, SIGNALLED, ... } tag;
union {
int exit_status; /* if EXITED */
struct {
int terminating_signal;
bool core_dumped;
} terminating_signal; /* if SIGNALLED */
...
} detail;
Meanwhile, on Windows, wait statuses and exit statuses are
interchangeable.
I find that it's clearer what is going on if we are consistent about
referring to the result of wait() as a "wait status", and the value
passed to exit() as an "exit status".
GSubprocess already gets this right: g_subprocess_get_status() returns
the wait status, while g_subprocess_get_exit_status() genuinely returns
the exit status. However, the GSpawn family of APIs has tended to
conflate the two.
Confusingly, g_spawn_check_exit_status() has always checked a wait
status, and it would not be correct to pass an exit status to it; so
let's deprecate it in favour of g_spawn_check_wait_status(), which
does the same thing that g_spawn_check_exit_status() always did.
Code that needs backwards-compatibility with older GLib can use:
#if !GLIB_CHECK_VERSION(2, 69, 0)
#define g_spawn_check_wait_status(x) (g_spawn_check_exit_status (x))
#endif
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-06-14 13:51:01 +02:00
|
|
|
|
if (g_spawn_check_wait_status (status, NULL))
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
/* Here we could clean out any caches in use */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
run_update_command (char *command,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
char *subdir)
|
|
|
|
|
{
|
2022-07-21 16:39:27 +02:00
|
|
|
|
char *argv[3] = {
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
};
|
|
|
|
|
GPid pid = 0;
|
|
|
|
|
GError *local_error = NULL;
|
|
|
|
|
|
|
|
|
|
argv[0] = command;
|
|
|
|
|
argv[1] = g_build_filename (g_get_user_data_dir (), subdir, NULL);
|
|
|
|
|
|
|
|
|
|
if (g_spawn_async ("/", argv,
|
|
|
|
|
NULL, /* envp */
|
|
|
|
|
G_SPAWN_SEARCH_PATH |
|
|
|
|
|
G_SPAWN_STDOUT_TO_DEV_NULL |
|
|
|
|
|
G_SPAWN_STDERR_TO_DEV_NULL |
|
|
|
|
|
G_SPAWN_DO_NOT_REAP_CHILD,
|
|
|
|
|
NULL, NULL, /* No setup function */
|
|
|
|
|
&pid,
|
|
|
|
|
&local_error))
|
|
|
|
|
g_child_watch_add (pid, update_program_done, NULL);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* If we get an error at this point, it's quite likely the user doesn't
|
|
|
|
|
* have an installed copy of either 'update-mime-database' or
|
|
|
|
|
* 'update-desktop-database'. I don't think we want to popup an error
|
|
|
|
|
* dialog at this point, so we just do a g_warning to give the user a
|
|
|
|
|
* chance of debugging it.
|
|
|
|
|
*/
|
|
|
|
|
g_warning ("%s", local_error->message);
|
|
|
|
|
g_error_free (local_error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (argv[1]);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
|
g_desktop_app_info_set_as_default_for_extension (GAppInfo *appinfo,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
const char *extension,
|
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
char *filename, *basename, *mimetype;
|
|
|
|
|
char *dirname;
|
|
|
|
|
gboolean res;
|
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
if (!g_desktop_app_info_ensure_saved (G_DESKTOP_APP_INFO (appinfo), error))
|
2013-07-27 21:08:58 +02:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
dirname = ensure_dir (MIMETYPE_DIR, error);
|
|
|
|
|
if (!dirname)
|
|
|
|
|
return FALSE;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
basename = g_strdup_printf ("user-extension-%s.xml", extension);
|
|
|
|
|
filename = g_build_filename (dirname, basename, NULL);
|
|
|
|
|
g_free (basename);
|
|
|
|
|
g_free (dirname);
|
|
|
|
|
|
|
|
|
|
mimetype = g_strdup_printf ("application/x-extension-%s", extension);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
|
|
|
|
if (!g_file_test (filename, G_FILE_TEST_EXISTS))
|
2007-11-30 06:11:25 +01:00
|
|
|
|
{
|
|
|
|
|
char *contents;
|
|
|
|
|
|
|
|
|
|
contents =
|
|
|
|
|
g_strdup_printf ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
|
|
|
|
"<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">\n"
|
|
|
|
|
" <mime-type type=\"%s\">\n"
|
|
|
|
|
" <comment>%s document</comment>\n"
|
|
|
|
|
" <glob pattern=\"*.%s\"/>\n"
|
|
|
|
|
" </mime-type>\n"
|
|
|
|
|
"</mime-info>\n", mimetype, extension, extension);
|
|
|
|
|
|
2020-05-27 19:00:48 +02:00
|
|
|
|
g_file_set_contents_full (filename, contents, -1,
|
|
|
|
|
G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING,
|
|
|
|
|
0600, NULL);
|
2007-11-30 06:11:25 +01:00
|
|
|
|
g_free (contents);
|
|
|
|
|
|
|
|
|
|
run_update_command ("update-mime-database", "mime");
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_free (filename);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
res = g_desktop_app_info_set_as_default_for_type (appinfo,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
mimetype,
|
|
|
|
|
error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
g_free (mimetype);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
|
g_desktop_app_info_add_supports_type (GAppInfo *appinfo,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
const char *content_type,
|
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
if (!g_desktop_app_info_ensure_saved (G_DESKTOP_APP_INFO (info), error))
|
2013-07-27 21:08:58 +02:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2010-12-15 17:56:22 +01:00
|
|
|
|
return update_mimeapps_list (info->desktop_id, content_type,
|
|
|
|
|
UPDATE_MIME_SET_NON_DEFAULT,
|
|
|
|
|
error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
|
g_desktop_app_info_can_remove_supports_type (GAppInfo *appinfo)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2008-01-25 13:06:14 +01:00
|
|
|
|
return TRUE;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
|
g_desktop_app_info_remove_supports_type (GAppInfo *appinfo,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
const char *content_type,
|
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
if (!g_desktop_app_info_ensure_saved (G_DESKTOP_APP_INFO (info), error))
|
|
|
|
|
return FALSE;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2010-12-15 17:56:22 +01:00
|
|
|
|
return update_mimeapps_list (info->desktop_id, content_type,
|
|
|
|
|
UPDATE_MIME_REMOVE,
|
|
|
|
|
error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-14 19:34:00 +02:00
|
|
|
|
static const char **
|
|
|
|
|
g_desktop_app_info_get_supported_types (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
|
|
|
|
|
return (const char**) info->mime_types;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* Saving and deleting {{{2 */
|
2012-04-14 19:34:00 +02:00
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
static gboolean
|
2008-11-28 08:27:13 +01:00
|
|
|
|
g_desktop_app_info_ensure_saved (GDesktopAppInfo *info,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
GKeyFile *key_file;
|
|
|
|
|
char *dirname;
|
2008-01-30 12:27:02 +01:00
|
|
|
|
char *filename;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
char *data, *desktop_id;
|
|
|
|
|
gsize data_size;
|
|
|
|
|
int fd;
|
|
|
|
|
gboolean res;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
if (info->filename != NULL)
|
|
|
|
|
return TRUE;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
/* This is only used for object created with
|
|
|
|
|
* g_app_info_create_from_commandline. All other
|
|
|
|
|
* object should have a filename
|
|
|
|
|
*/
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
dirname = ensure_dir (APP_DIR, error);
|
|
|
|
|
if (!dirname)
|
2008-01-29 15:07:07 +01:00
|
|
|
|
return FALSE;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
key_file = g_key_file_new ();
|
|
|
|
|
|
|
|
|
|
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
"Encoding", "UTF-8");
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
G_KEY_FILE_DESKTOP_KEY_VERSION, "1.0");
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
G_KEY_FILE_DESKTOP_KEY_TYPE,
|
2007-11-26 17:13:05 +01:00
|
|
|
|
G_KEY_FILE_DESKTOP_TYPE_APPLICATION);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
if (info->terminal)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
G_KEY_FILE_DESKTOP_KEY_TERMINAL, TRUE);
|
2011-06-12 12:22:59 +02:00
|
|
|
|
if (info->nodisplay)
|
|
|
|
|
g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, TRUE);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
G_KEY_FILE_DESKTOP_KEY_EXEC, info->exec);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
G_KEY_FILE_DESKTOP_KEY_NAME, info->name);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2011-04-27 17:34:23 +02:00
|
|
|
|
if (info->generic_name != NULL)
|
|
|
|
|
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
GENERIC_NAME_KEY, info->generic_name);
|
2011-04-27 17:34:23 +02:00
|
|
|
|
|
2009-11-18 23:37:47 +01:00
|
|
|
|
if (info->fullname != NULL)
|
|
|
|
|
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
FULL_NAME_KEY, info->fullname);
|
2009-11-18 23:37:47 +01:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
G_KEY_FILE_DESKTOP_KEY_COMMENT, info->comment);
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, TRUE);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
data = g_key_file_to_data (key_file, &data_size, NULL);
|
|
|
|
|
g_key_file_free (key_file);
|
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
desktop_id = g_strdup_printf ("userapp-%s-XXXXXX.desktop", info->name);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
filename = g_build_filename (dirname, desktop_id, NULL);
|
|
|
|
|
g_free (desktop_id);
|
|
|
|
|
g_free (dirname);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
fd = g_mkstemp (filename);
|
|
|
|
|
if (fd == -1)
|
|
|
|
|
{
|
|
|
|
|
char *display_name;
|
|
|
|
|
|
|
|
|
|
display_name = g_filename_display_name (filename);
|
|
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
2016-09-30 05:47:15 +02:00
|
|
|
|
_("Can’t create user desktop file %s"), display_name);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
g_free (display_name);
|
|
|
|
|
g_free (filename);
|
|
|
|
|
g_free (data);
|
2008-01-29 15:07:07 +01:00
|
|
|
|
return FALSE;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
desktop_id = g_path_get_basename (filename);
|
|
|
|
|
|
2013-01-25 18:05:26 +01:00
|
|
|
|
/* FIXME - actually handle error */
|
|
|
|
|
(void) g_close (fd, NULL);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2020-05-27 19:00:48 +02:00
|
|
|
|
res = g_file_set_contents_full (filename, data, data_size,
|
|
|
|
|
G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING,
|
|
|
|
|
0600, error);
|
2012-08-24 23:06:46 +02:00
|
|
|
|
g_free (data);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
if (!res)
|
|
|
|
|
{
|
|
|
|
|
g_free (desktop_id);
|
|
|
|
|
g_free (filename);
|
2008-01-29 15:07:07 +01:00
|
|
|
|
return FALSE;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
info->filename = filename;
|
|
|
|
|
info->desktop_id = desktop_id;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
run_update_command ("update-desktop-database", "applications");
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
/* We just dropped a file in the user's desktop file directory. Save
|
|
|
|
|
* the monitor the bother of having to notice it and invalidate
|
|
|
|
|
* immediately.
|
|
|
|
|
*
|
|
|
|
|
* This means that calls directly following this will be able to see
|
|
|
|
|
* the results immediately.
|
|
|
|
|
*/
|
2014-04-09 14:44:18 +02:00
|
|
|
|
desktop_file_dirs_invalidate_user_data ();
|
2013-07-27 22:04:56 +02:00
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
static gboolean
|
|
|
|
|
g_desktop_app_info_can_delete (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
|
|
|
|
|
|
|
|
|
if (info->filename)
|
2008-11-28 08:27:13 +01:00
|
|
|
|
{
|
|
|
|
|
if (strstr (info->filename, "/userapp-"))
|
|
|
|
|
return g_access (info->filename, W_OK) == 0;
|
|
|
|
|
}
|
2008-09-26 21:57:36 +02:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
g_desktop_app_info_delete (GAppInfo *appinfo)
|
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
if (info->filename)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
2008-09-26 21:57:36 +02:00
|
|
|
|
if (g_remove (info->filename) == 0)
|
|
|
|
|
{
|
2010-12-15 17:56:22 +01:00
|
|
|
|
update_mimeapps_list (info->desktop_id, NULL,
|
|
|
|
|
UPDATE_MIME_NONE,
|
|
|
|
|
NULL);
|
2008-09-26 21:57:36 +02:00
|
|
|
|
|
|
|
|
|
g_free (info->filename);
|
|
|
|
|
info->filename = NULL;
|
|
|
|
|
g_free (info->desktop_id);
|
|
|
|
|
info->desktop_id = NULL;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* Create for commandline {{{2 */
|
2008-01-29 15:07:07 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_app_info_create_from_commandline:
|
2017-10-11 18:49:11 +02:00
|
|
|
|
* @commandline: (type filename): the commandline to use
|
2016-10-29 03:29:02 +02:00
|
|
|
|
* @application_name: (nullable): the application name, or %NULL to use @commandline
|
2008-01-29 15:07:07 +01:00
|
|
|
|
* @flags: flags that can specify details of the created #GAppInfo
|
2011-08-29 20:49:32 +02:00
|
|
|
|
* @error: a #GError location to store the error occurring, %NULL to ignore.
|
2008-01-29 15:07:07 +01:00
|
|
|
|
*
|
|
|
|
|
* Creates a new #GAppInfo from the given information.
|
|
|
|
|
*
|
2012-05-17 22:24:10 +02:00
|
|
|
|
* Note that for @commandline, the quoting rules of the Exec key of the
|
2014-02-06 03:23:28 +01:00
|
|
|
|
* [freedesktop.org Desktop Entry Specification](http://freedesktop.org/Standards/desktop-entry-spec)
|
|
|
|
|
* are applied. For example, if the @commandline contains
|
2012-05-17 22:24:10 +02:00
|
|
|
|
* percent-encoded URIs, the percent-character must be doubled in order to prevent it from
|
|
|
|
|
* being swallowed by Exec key unquoting. See the specification for exact quoting rules.
|
|
|
|
|
*
|
2010-09-24 20:51:26 +02:00
|
|
|
|
* Returns: (transfer full): new #GAppInfo for given command.
|
2008-01-29 15:07:07 +01:00
|
|
|
|
**/
|
|
|
|
|
GAppInfo *
|
|
|
|
|
g_app_info_create_from_commandline (const char *commandline,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
const char *application_name,
|
|
|
|
|
GAppInfoCreateFlags flags,
|
|
|
|
|
GError **error)
|
2008-01-29 15:07:07 +01:00
|
|
|
|
{
|
|
|
|
|
char **split;
|
|
|
|
|
char *basename;
|
|
|
|
|
GDesktopAppInfo *info;
|
|
|
|
|
|
2009-11-19 16:58:43 +01:00
|
|
|
|
g_return_val_if_fail (commandline, NULL);
|
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
info = g_object_new (G_TYPE_DESKTOP_APP_INFO, NULL);
|
|
|
|
|
|
|
|
|
|
info->filename = NULL;
|
|
|
|
|
info->desktop_id = NULL;
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2011-04-25 14:29:35 +02:00
|
|
|
|
info->terminal = (flags & G_APP_INFO_CREATE_NEEDS_TERMINAL) != 0;
|
|
|
|
|
info->startup_notify = (flags & G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION) != 0;
|
2008-01-29 15:07:07 +01:00
|
|
|
|
info->hidden = FALSE;
|
2011-04-25 14:29:35 +02:00
|
|
|
|
if ((flags & G_APP_INFO_CREATE_SUPPORTS_URIS) != 0)
|
2008-01-29 16:47:27 +01:00
|
|
|
|
info->exec = g_strconcat (commandline, " %u", NULL);
|
|
|
|
|
else
|
|
|
|
|
info->exec = g_strconcat (commandline, " %f", NULL);
|
2008-01-29 15:07:07 +01:00
|
|
|
|
info->nodisplay = TRUE;
|
|
|
|
|
info->binary = binary_from_exec (info->exec);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2008-01-29 15:07:07 +01:00
|
|
|
|
if (application_name)
|
|
|
|
|
info->name = g_strdup (application_name);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
else
|
2008-01-29 15:07:07 +01:00
|
|
|
|
{
|
|
|
|
|
/* FIXME: this should be more robust. Maybe g_shell_parse_argv and use argv[0] */
|
|
|
|
|
split = g_strsplit (commandline, " ", 2);
|
2009-11-19 16:58:43 +01:00
|
|
|
|
basename = split[0] ? g_path_get_basename (split[0]) : NULL;
|
2008-01-29 15:07:07 +01:00
|
|
|
|
g_strfreev (split);
|
|
|
|
|
info->name = basename;
|
|
|
|
|
if (info->name == NULL)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
info->name = g_strdup ("custom");
|
2008-01-29 15:07:07 +01:00
|
|
|
|
}
|
2008-04-09 16:53:05 +02:00
|
|
|
|
info->comment = g_strdup_printf (_("Custom definition for %s"), info->name);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return G_APP_INFO (info);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* GAppInfo interface init */
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static void
|
|
|
|
|
g_desktop_app_info_iface_init (GAppInfoIface *iface)
|
|
|
|
|
{
|
|
|
|
|
iface->dup = g_desktop_app_info_dup;
|
|
|
|
|
iface->equal = g_desktop_app_info_equal;
|
|
|
|
|
iface->get_id = g_desktop_app_info_get_id;
|
|
|
|
|
iface->get_name = g_desktop_app_info_get_name;
|
|
|
|
|
iface->get_description = g_desktop_app_info_get_description;
|
|
|
|
|
iface->get_executable = g_desktop_app_info_get_executable;
|
|
|
|
|
iface->get_icon = g_desktop_app_info_get_icon;
|
|
|
|
|
iface->launch = g_desktop_app_info_launch;
|
|
|
|
|
iface->supports_uris = g_desktop_app_info_supports_uris;
|
2008-01-04 11:51:56 +01:00
|
|
|
|
iface->supports_files = g_desktop_app_info_supports_files;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
iface->launch_uris = g_desktop_app_info_launch_uris;
|
2019-01-22 15:39:15 +01:00
|
|
|
|
iface->launch_uris_async = g_desktop_app_info_launch_uris_async;
|
|
|
|
|
iface->launch_uris_finish = g_desktop_app_info_launch_uris_finish;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
iface->should_show = g_desktop_app_info_should_show;
|
|
|
|
|
iface->set_as_default_for_type = g_desktop_app_info_set_as_default_for_type;
|
|
|
|
|
iface->set_as_default_for_extension = g_desktop_app_info_set_as_default_for_extension;
|
|
|
|
|
iface->add_supports_type = g_desktop_app_info_add_supports_type;
|
|
|
|
|
iface->can_remove_supports_type = g_desktop_app_info_can_remove_supports_type;
|
|
|
|
|
iface->remove_supports_type = g_desktop_app_info_remove_supports_type;
|
2008-09-26 21:57:36 +02:00
|
|
|
|
iface->can_delete = g_desktop_app_info_can_delete;
|
|
|
|
|
iface->do_delete = g_desktop_app_info_delete;
|
2008-11-29 00:16:45 +01:00
|
|
|
|
iface->get_commandline = g_desktop_app_info_get_commandline;
|
2009-11-18 23:37:47 +01:00
|
|
|
|
iface->get_display_name = g_desktop_app_info_get_display_name;
|
2010-12-15 17:56:22 +01:00
|
|
|
|
iface->set_as_last_used_for_type = g_desktop_app_info_set_as_last_used_for_type;
|
2012-04-14 19:34:00 +02:00
|
|
|
|
iface->get_supported_types = g_desktop_app_info_get_supported_types;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* Recommended applications {{{2 */
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
/* Converts content_type into a list of itself with all of its parent
|
|
|
|
|
* types (if include_fallback is enabled) or just returns a single-item
|
|
|
|
|
* list with the unaliased content type.
|
|
|
|
|
*/
|
|
|
|
|
static gchar **
|
|
|
|
|
get_list_of_mimetypes (const gchar *content_type,
|
|
|
|
|
gboolean include_fallback)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2014-04-09 14:44:18 +02:00
|
|
|
|
gchar *unaliased;
|
|
|
|
|
GPtrArray *array;
|
|
|
|
|
|
|
|
|
|
array = g_ptr_array_new ();
|
|
|
|
|
unaliased = _g_unix_content_type_unalias (content_type);
|
|
|
|
|
g_ptr_array_add (array, unaliased);
|
|
|
|
|
|
|
|
|
|
if (include_fallback)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2020-11-17 11:03:25 +01:00
|
|
|
|
guint i;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
/* Iterate the array as we grow it, until we have nothing more to add */
|
|
|
|
|
for (i = 0; i < array->len; i++)
|
|
|
|
|
{
|
|
|
|
|
gchar **parents = _g_unix_content_type_get_parents (g_ptr_array_index (array, i));
|
|
|
|
|
gint j;
|
|
|
|
|
|
|
|
|
|
for (j = 0; parents[j]; j++)
|
|
|
|
|
/* Don't add duplicates */
|
|
|
|
|
if (!array_contains (array, parents[j]))
|
|
|
|
|
g_ptr_array_add (array, parents[j]);
|
|
|
|
|
else
|
|
|
|
|
g_free (parents[j]);
|
|
|
|
|
|
|
|
|
|
/* We already stole or freed each element. Free the container. */
|
|
|
|
|
g_free (parents);
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
g_ptr_array_add (array, NULL);
|
|
|
|
|
|
|
|
|
|
return (gchar **) g_ptr_array_free (array, FALSE);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
static gchar **
|
|
|
|
|
g_desktop_app_info_get_desktop_ids_for_content_type (const gchar *content_type,
|
|
|
|
|
gboolean include_fallback)
|
|
|
|
|
{
|
2020-06-12 15:02:30 +02:00
|
|
|
|
GPtrArray *hits, *blocklist;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
gchar **types;
|
2020-11-17 11:05:28 +01:00
|
|
|
|
guint i, j;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
hits = g_ptr_array_new ();
|
2020-06-12 15:02:30 +02:00
|
|
|
|
blocklist = g_ptr_array_new ();
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
|
|
|
|
types = get_list_of_mimetypes (content_type, include_fallback);
|
|
|
|
|
|
|
|
|
|
desktop_file_dirs_lock ();
|
|
|
|
|
|
|
|
|
|
for (i = 0; types[i]; i++)
|
2019-10-11 22:33:47 +02:00
|
|
|
|
for (j = 0; j < desktop_file_dirs->len; j++)
|
2020-06-12 15:02:30 +02:00
|
|
|
|
desktop_file_dir_mime_lookup (g_ptr_array_index (desktop_file_dirs, j), types[i], hits, blocklist);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
2015-04-02 23:17:35 +02:00
|
|
|
|
/* We will keep the hits past unlocking, so we must dup them */
|
|
|
|
|
for (i = 0; i < hits->len; i++)
|
|
|
|
|
hits->pdata[i] = g_strdup (hits->pdata[i]);
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
desktop_file_dirs_unlock ();
|
|
|
|
|
|
|
|
|
|
g_ptr_array_add (hits, NULL);
|
|
|
|
|
|
2020-06-12 15:02:30 +02:00
|
|
|
|
g_ptr_array_free (blocklist, TRUE);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
g_strfreev (types);
|
|
|
|
|
|
|
|
|
|
return (gchar **) g_ptr_array_free (hits, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* g_app_info_get_recommended_for_type:
|
|
|
|
|
* @content_type: the content type to find a #GAppInfo for
|
|
|
|
|
*
|
|
|
|
|
* Gets a list of recommended #GAppInfos for a given content type, i.e.
|
|
|
|
|
* those applications which claim to support the given content type exactly,
|
|
|
|
|
* and not by MIME type subclassing.
|
|
|
|
|
* Note that the first application of the list is the last used one, i.e.
|
2011-09-12 07:49:01 +02:00
|
|
|
|
* the last one for which g_app_info_set_as_last_used_for_type() has been
|
2010-12-15 17:56:22 +01:00
|
|
|
|
* called.
|
2010-11-19 10:39:16 +01:00
|
|
|
|
*
|
2010-11-24 21:57:40 +01:00
|
|
|
|
* Returns: (element-type GAppInfo) (transfer full): #GList of #GAppInfos
|
|
|
|
|
* for given @content_type or %NULL on error.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.28
|
2010-11-19 10:39:16 +01:00
|
|
|
|
**/
|
2010-11-18 18:45:56 +01:00
|
|
|
|
GList *
|
|
|
|
|
g_app_info_get_recommended_for_type (const gchar *content_type)
|
|
|
|
|
{
|
2014-04-09 14:44:18 +02:00
|
|
|
|
gchar **desktop_ids;
|
2010-11-18 18:45:56 +01:00
|
|
|
|
GList *infos;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
gint i;
|
2010-11-18 18:45:56 +01:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (content_type != NULL, NULL);
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
desktop_ids = g_desktop_app_info_get_desktop_ids_for_content_type (content_type, FALSE);
|
2010-11-18 18:45:56 +01:00
|
|
|
|
|
|
|
|
|
infos = NULL;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
for (i = 0; desktop_ids[i]; i++)
|
2010-11-18 18:45:56 +01:00
|
|
|
|
{
|
2014-04-09 14:44:18 +02:00
|
|
|
|
GDesktopAppInfo *info;
|
2010-11-18 18:45:56 +01:00
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
info = g_desktop_app_info_new (desktop_ids[i]);
|
2010-11-18 18:45:56 +01:00
|
|
|
|
if (info)
|
2014-04-09 14:44:18 +02:00
|
|
|
|
infos = g_list_prepend (infos, info);
|
2010-11-18 18:45:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
g_strfreev (desktop_ids);
|
2010-12-15 17:56:22 +01:00
|
|
|
|
|
2010-11-18 18:45:56 +01:00
|
|
|
|
return g_list_reverse (infos);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 10:39:16 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_app_info_get_fallback_for_type:
|
|
|
|
|
* @content_type: the content type to find a #GAppInfo for
|
2013-07-27 21:08:58 +02:00
|
|
|
|
*
|
2010-11-24 21:57:40 +01:00
|
|
|
|
* Gets a list of fallback #GAppInfos for a given content type, i.e.
|
|
|
|
|
* those applications which claim to support the given content type
|
|
|
|
|
* by MIME type subclassing and not directly.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (element-type GAppInfo) (transfer full): #GList of #GAppInfos
|
|
|
|
|
* for given @content_type or %NULL on error.
|
2010-11-19 10:39:16 +01:00
|
|
|
|
*
|
2010-11-24 21:57:40 +01:00
|
|
|
|
* Since: 2.28
|
2010-11-19 10:39:16 +01:00
|
|
|
|
**/
|
2010-11-18 18:45:56 +01:00
|
|
|
|
GList *
|
|
|
|
|
g_app_info_get_fallback_for_type (const gchar *content_type)
|
|
|
|
|
{
|
2014-04-09 14:44:18 +02:00
|
|
|
|
gchar **recommended_ids;
|
|
|
|
|
gchar **all_ids;
|
|
|
|
|
GList *infos;
|
|
|
|
|
gint i;
|
2010-11-18 18:45:56 +01:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (content_type != NULL, NULL);
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
recommended_ids = g_desktop_app_info_get_desktop_ids_for_content_type (content_type, FALSE);
|
|
|
|
|
all_ids = g_desktop_app_info_get_desktop_ids_for_content_type (content_type, TRUE);
|
2010-11-18 18:45:56 +01:00
|
|
|
|
|
|
|
|
|
infos = NULL;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
for (i = 0; all_ids[i]; i++)
|
2010-11-18 18:45:56 +01:00
|
|
|
|
{
|
2014-04-09 14:44:18 +02:00
|
|
|
|
GDesktopAppInfo *info;
|
|
|
|
|
gint j;
|
|
|
|
|
|
|
|
|
|
/* Don't return the ones on the recommended list */
|
|
|
|
|
for (j = 0; recommended_ids[j]; j++)
|
|
|
|
|
if (g_str_equal (all_ids[i], recommended_ids[j]))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (recommended_ids[j])
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
info = g_desktop_app_info_new (all_ids[i]);
|
2010-11-18 18:45:56 +01:00
|
|
|
|
|
|
|
|
|
if (info)
|
2014-04-09 14:44:18 +02:00
|
|
|
|
infos = g_list_prepend (infos, info);
|
2010-11-18 18:45:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
g_strfreev (recommended_ids);
|
|
|
|
|
g_strfreev (all_ids);
|
2010-11-18 18:45:56 +01:00
|
|
|
|
|
|
|
|
|
return g_list_reverse (infos);
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* g_app_info_get_all_for_type:
|
2007-11-28 07:01:13 +01:00
|
|
|
|
* @content_type: the content type to find a #GAppInfo for
|
2011-09-12 07:56:45 +02:00
|
|
|
|
*
|
|
|
|
|
* Gets a list of all #GAppInfos for a given content type,
|
|
|
|
|
* including the recommended and fallback #GAppInfos. See
|
|
|
|
|
* g_app_info_get_recommended_for_type() and
|
|
|
|
|
* g_app_info_get_fallback_for_type().
|
2007-11-28 05:29:02 +01:00
|
|
|
|
*
|
2010-11-24 21:57:40 +01:00
|
|
|
|
* Returns: (element-type GAppInfo) (transfer full): #GList of #GAppInfos
|
|
|
|
|
* for given @content_type or %NULL on error.
|
2007-11-26 17:13:05 +01:00
|
|
|
|
**/
|
|
|
|
|
GList *
|
|
|
|
|
g_app_info_get_all_for_type (const char *content_type)
|
|
|
|
|
{
|
2014-04-09 14:44:18 +02:00
|
|
|
|
gchar **desktop_ids;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
GList *infos;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
gint i;
|
2008-01-10 14:25:41 +01:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (content_type != NULL, NULL);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
desktop_ids = g_desktop_app_info_get_desktop_ids_for_content_type (content_type, TRUE);
|
2010-12-15 17:56:22 +01:00
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
infos = NULL;
|
|
|
|
|
for (i = 0; desktop_ids[i]; i++)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2014-04-09 14:44:18 +02:00
|
|
|
|
GDesktopAppInfo *info;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
info = g_desktop_app_info_new (desktop_ids[i]);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
if (info)
|
2014-04-09 14:44:18 +02:00
|
|
|
|
infos = g_list_prepend (infos, info);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 14:44:18 +02:00
|
|
|
|
g_strfreev (desktop_ids);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return g_list_reverse (infos);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:57:36 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_app_info_reset_type_associations:
|
2011-09-12 07:56:45 +02:00
|
|
|
|
* @content_type: a content type
|
2008-09-26 21:57:36 +02:00
|
|
|
|
*
|
|
|
|
|
* Removes all changes to the type associations done by
|
2011-09-12 07:56:45 +02:00
|
|
|
|
* g_app_info_set_as_default_for_type(),
|
|
|
|
|
* g_app_info_set_as_default_for_extension(),
|
|
|
|
|
* g_app_info_add_supports_type() or
|
|
|
|
|
* g_app_info_remove_supports_type().
|
2008-09-26 21:57:36 +02:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.20
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
g_app_info_reset_type_associations (const char *content_type)
|
|
|
|
|
{
|
2010-12-15 17:56:22 +01:00
|
|
|
|
update_mimeapps_list (NULL, content_type,
|
|
|
|
|
UPDATE_MIME_NONE,
|
|
|
|
|
NULL);
|
2008-09-26 21:57:36 +02:00
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
/**
|
2007-11-28 05:29:02 +01:00
|
|
|
|
* g_app_info_get_default_for_type:
|
2007-11-28 07:01:13 +01:00
|
|
|
|
* @content_type: the content type to find a #GAppInfo for
|
|
|
|
|
* @must_support_uris: if %TRUE, the #GAppInfo is expected to
|
|
|
|
|
* support URIs
|
2011-09-12 07:56:45 +02:00
|
|
|
|
*
|
|
|
|
|
* Gets the default #GAppInfo for a given content type.
|
2007-11-28 05:29:02 +01:00
|
|
|
|
*
|
2020-04-28 10:49:57 +02:00
|
|
|
|
* Returns: (transfer full) (nullable): #GAppInfo for given @content_type or
|
2010-12-27 15:40:07 +01:00
|
|
|
|
* %NULL on error.
|
2011-09-12 07:56:45 +02:00
|
|
|
|
*/
|
2007-11-26 17:13:05 +01:00
|
|
|
|
GAppInfo *
|
|
|
|
|
g_app_info_get_default_for_type (const char *content_type,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
gboolean must_support_uris)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2020-06-12 15:02:30 +02:00
|
|
|
|
GPtrArray *blocklist;
|
2015-04-02 23:17:35 +02:00
|
|
|
|
GPtrArray *results;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
GAppInfo *info;
|
2015-04-02 23:17:35 +02:00
|
|
|
|
gchar **types;
|
2020-11-17 11:07:46 +01:00
|
|
|
|
guint i, j, k;
|
2008-01-10 14:25:41 +01:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (content_type != NULL, NULL);
|
2013-07-27 21:08:58 +02:00
|
|
|
|
|
2015-04-02 23:17:35 +02:00
|
|
|
|
types = get_list_of_mimetypes (content_type, TRUE);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2020-06-12 15:02:30 +02:00
|
|
|
|
blocklist = g_ptr_array_new ();
|
2015-04-02 23:17:35 +02:00
|
|
|
|
results = g_ptr_array_new ();
|
2007-11-26 17:13:05 +01:00
|
|
|
|
info = NULL;
|
2010-12-15 17:56:22 +01:00
|
|
|
|
|
2015-04-02 23:17:35 +02:00
|
|
|
|
desktop_file_dirs_lock ();
|
2010-12-15 17:56:22 +01:00
|
|
|
|
|
2015-04-02 23:17:35 +02:00
|
|
|
|
for (i = 0; types[i]; i++)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2015-04-02 23:17:35 +02:00
|
|
|
|
/* Collect all the default apps for this type */
|
2019-10-11 22:33:47 +02:00
|
|
|
|
for (j = 0; j < desktop_file_dirs->len; j++)
|
|
|
|
|
desktop_file_dir_default_lookup (g_ptr_array_index (desktop_file_dirs, j), types[i], results);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2015-04-02 23:17:35 +02:00
|
|
|
|
/* Consider the associations as well... */
|
2019-10-11 22:33:47 +02:00
|
|
|
|
for (j = 0; j < desktop_file_dirs->len; j++)
|
2020-06-12 15:02:30 +02:00
|
|
|
|
desktop_file_dir_mime_lookup (g_ptr_array_index (desktop_file_dirs, j), types[i], results, blocklist);
|
2015-04-02 23:17:35 +02:00
|
|
|
|
|
|
|
|
|
/* (If any), see if one of those apps is installed... */
|
|
|
|
|
for (j = 0; j < results->len; j++)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
2015-04-02 23:17:35 +02:00
|
|
|
|
const gchar *desktop_id = g_ptr_array_index (results, j);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
for (k = 0; k < desktop_file_dirs->len; k++)
|
2013-07-27 21:08:58 +02:00
|
|
|
|
{
|
2019-10-11 22:33:47 +02:00
|
|
|
|
info = (GAppInfo *) desktop_file_dir_get_app (g_ptr_array_index (desktop_file_dirs, k), desktop_id);
|
2015-04-02 23:17:35 +02:00
|
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
|
{
|
|
|
|
|
if (!must_support_uris || g_app_info_supports_uris (info))
|
|
|
|
|
goto out;
|
2014-04-09 14:44:18 +02:00
|
|
|
|
|
2015-04-02 23:17:35 +02:00
|
|
|
|
g_clear_object (&info);
|
|
|
|
|
}
|
2013-07-27 21:08:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-02 23:17:35 +02:00
|
|
|
|
/* Reset the list, ready to try again with the next (parent)
|
2020-06-12 15:02:30 +02:00
|
|
|
|
* mimetype, but keep the blocklist in place.
|
2015-04-02 23:17:35 +02:00
|
|
|
|
*/
|
|
|
|
|
g_ptr_array_set_size (results, 0);
|
2014-04-09 14:44:18 +02:00
|
|
|
|
}
|
2010-12-15 17:56:22 +01:00
|
|
|
|
|
2015-04-02 23:17:35 +02:00
|
|
|
|
out:
|
|
|
|
|
desktop_file_dirs_unlock ();
|
|
|
|
|
|
2020-06-12 15:02:30 +02:00
|
|
|
|
g_ptr_array_unref (blocklist);
|
2015-04-02 23:17:35 +02:00
|
|
|
|
g_ptr_array_unref (results);
|
|
|
|
|
g_strfreev (types);
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* g_app_info_get_default_for_uri_scheme:
|
2007-12-09 16:51:12 +01:00
|
|
|
|
* @uri_scheme: a string containing a URI scheme.
|
|
|
|
|
*
|
2011-09-12 07:56:45 +02:00
|
|
|
|
* Gets the default application for handling URIs with
|
|
|
|
|
* the given URI scheme. A URI scheme is the initial part
|
|
|
|
|
* of the URI, up to but not including the ':', e.g. "http",
|
2008-02-11 08:12:56 +01:00
|
|
|
|
* "ftp" or "sip".
|
2011-09-12 07:56:45 +02:00
|
|
|
|
*
|
2020-04-28 10:49:57 +02:00
|
|
|
|
* Returns: (transfer full) (nullable): #GAppInfo for given @uri_scheme or
|
|
|
|
|
* %NULL on error.
|
2011-09-12 07:56:45 +02:00
|
|
|
|
*/
|
2007-11-26 17:13:05 +01:00
|
|
|
|
GAppInfo *
|
|
|
|
|
g_app_info_get_default_for_uri_scheme (const char *uri_scheme)
|
|
|
|
|
{
|
2010-10-05 16:02:37 +02:00
|
|
|
|
GAppInfo *app_info;
|
|
|
|
|
char *content_type, *scheme_down;
|
2008-01-29 13:18:48 +01:00
|
|
|
|
|
2022-06-14 16:30:42 +02:00
|
|
|
|
g_return_val_if_fail (uri_scheme != NULL && *uri_scheme != '\0', NULL);
|
|
|
|
|
|
2010-10-05 16:02:37 +02:00
|
|
|
|
scheme_down = g_ascii_strdown (uri_scheme, -1);
|
|
|
|
|
content_type = g_strdup_printf ("x-scheme-handler/%s", scheme_down);
|
|
|
|
|
g_free (scheme_down);
|
|
|
|
|
app_info = g_app_info_get_default_for_type (content_type, FALSE);
|
|
|
|
|
g_free (content_type);
|
2008-01-29 13:18:48 +01:00
|
|
|
|
|
2010-10-05 16:02:37 +02:00
|
|
|
|
return app_info;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* "Get all" API {{{2 */
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2013-11-15 20:40:37 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_implementations:
|
|
|
|
|
* @interface: the name of the interface
|
|
|
|
|
*
|
|
|
|
|
* Gets all applications that implement @interface.
|
|
|
|
|
*
|
|
|
|
|
* An application implements an interface if that interface is listed in
|
|
|
|
|
* the Implements= line of the desktop file of the application.
|
|
|
|
|
*
|
2014-09-16 22:45:34 +02:00
|
|
|
|
* Returns: (element-type GDesktopAppInfo) (transfer full): a list of #GDesktopAppInfo
|
|
|
|
|
* objects.
|
|
|
|
|
*
|
2013-11-15 20:40:37 +01:00
|
|
|
|
* Since: 2.42
|
|
|
|
|
**/
|
|
|
|
|
GList *
|
|
|
|
|
g_desktop_app_info_get_implementations (const gchar *interface)
|
|
|
|
|
{
|
|
|
|
|
GList *result = NULL;
|
|
|
|
|
GList **ptr;
|
2020-11-17 11:09:07 +01:00
|
|
|
|
guint i;
|
2013-11-15 20:40:37 +01:00
|
|
|
|
|
|
|
|
|
desktop_file_dirs_lock ();
|
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
for (i = 0; i < desktop_file_dirs->len; i++)
|
|
|
|
|
desktop_file_dir_get_implementations (g_ptr_array_index (desktop_file_dirs, i), &result, interface);
|
2013-11-15 20:40:37 +01:00
|
|
|
|
|
|
|
|
|
desktop_file_dirs_unlock ();
|
|
|
|
|
|
|
|
|
|
ptr = &result;
|
|
|
|
|
while (*ptr)
|
|
|
|
|
{
|
|
|
|
|
gchar *name = (*ptr)->data;
|
|
|
|
|
GDesktopAppInfo *app;
|
|
|
|
|
|
|
|
|
|
app = g_desktop_app_info_new (name);
|
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
|
|
if (app)
|
|
|
|
|
{
|
|
|
|
|
(*ptr)->data = app;
|
|
|
|
|
ptr = &(*ptr)->next;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*ptr = g_list_delete_link (*ptr, *ptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 04:51:48 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_search:
|
|
|
|
|
* @search_string: the search string to use
|
|
|
|
|
*
|
|
|
|
|
* Searches desktop files for ones that match @search_string.
|
|
|
|
|
*
|
|
|
|
|
* The return value is an array of strvs. Each strv contains a list of
|
|
|
|
|
* applications that matched @search_string with an equal score. The
|
|
|
|
|
* outer list is sorted by score so that the first strv contains the
|
|
|
|
|
* best-matching applications, and so on.
|
2013-11-07 23:41:21 +01:00
|
|
|
|
* The algorithm for determining matches is undefined and may change at
|
|
|
|
|
* any time.
|
2013-11-06 04:51:48 +01:00
|
|
|
|
*
|
2020-04-21 15:08:38 +02:00
|
|
|
|
* None of the search results are subjected to the normal validation
|
|
|
|
|
* checks performed by g_desktop_app_info_new() (for example, checking that
|
|
|
|
|
* the executable referenced by a result exists), and so it is possible for
|
|
|
|
|
* g_desktop_app_info_new() to return %NULL when passed an app ID returned by
|
|
|
|
|
* this function. It is expected that calling code will do this when
|
|
|
|
|
* subsequently creating a #GDesktopAppInfo for each result.
|
|
|
|
|
*
|
2013-11-06 04:51:48 +01:00
|
|
|
|
* Returns: (array zero-terminated=1) (element-type GStrv) (transfer full): a
|
|
|
|
|
* list of strvs. Free each item with g_strfreev() and free the outer
|
|
|
|
|
* list with g_free().
|
|
|
|
|
*/
|
|
|
|
|
gchar ***
|
|
|
|
|
g_desktop_app_info_search (const gchar *search_string)
|
|
|
|
|
{
|
|
|
|
|
gchar **search_tokens;
|
|
|
|
|
gint last_category = -1;
|
2022-12-06 04:24:45 +01:00
|
|
|
|
gint last_match_type = -1;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
gchar ***results;
|
2022-12-06 04:24:45 +01:00
|
|
|
|
gint n_groups = 0;
|
|
|
|
|
gint start_of_group;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
gint i, j;
|
2020-11-17 11:11:45 +01:00
|
|
|
|
guint k;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
|
|
|
|
|
search_tokens = g_str_tokenize_and_fold (search_string, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
desktop_file_dirs_lock ();
|
|
|
|
|
|
|
|
|
|
reset_total_search_results ();
|
|
|
|
|
|
2020-11-17 11:11:45 +01:00
|
|
|
|
for (k = 0; k < desktop_file_dirs->len; k++)
|
2013-11-06 04:51:48 +01:00
|
|
|
|
{
|
|
|
|
|
for (j = 0; search_tokens[j]; j++)
|
|
|
|
|
{
|
2020-11-17 11:11:45 +01:00
|
|
|
|
desktop_file_dir_search (g_ptr_array_index (desktop_file_dirs, k), search_tokens[j]);
|
2013-11-06 04:51:48 +01:00
|
|
|
|
merge_token_results (j == 0);
|
|
|
|
|
}
|
|
|
|
|
merge_directory_results ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sort_total_search_results ();
|
|
|
|
|
|
2022-12-06 04:24:45 +01:00
|
|
|
|
/* Count the total number of unique categories and match types */
|
2013-11-06 04:51:48 +01:00
|
|
|
|
for (i = 0; i < static_total_results_size; i++)
|
2022-12-06 04:24:45 +01:00
|
|
|
|
if (static_total_results[i].category != last_category ||
|
|
|
|
|
static_total_results[i].match_type != last_match_type)
|
2013-11-06 04:51:48 +01:00
|
|
|
|
{
|
|
|
|
|
last_category = static_total_results[i].category;
|
2022-12-06 04:24:45 +01:00
|
|
|
|
last_match_type = static_total_results[i].match_type;
|
|
|
|
|
n_groups++;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-06 04:24:45 +01:00
|
|
|
|
results = g_new (gchar **, n_groups + 1);
|
2013-11-06 04:51:48 +01:00
|
|
|
|
|
|
|
|
|
/* Start loading into the results list */
|
2022-12-06 04:24:45 +01:00
|
|
|
|
start_of_group = 0;
|
|
|
|
|
for (i = 0; i < n_groups; i++)
|
2013-11-06 04:51:48 +01:00
|
|
|
|
{
|
2022-12-06 04:24:45 +01:00
|
|
|
|
gint n_items_in_group = 0;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
gint this_category;
|
2022-12-06 04:24:45 +01:00
|
|
|
|
gint this_match_type;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
gint j;
|
|
|
|
|
|
2022-12-06 04:24:45 +01:00
|
|
|
|
this_category = static_total_results[start_of_group].category;
|
|
|
|
|
this_match_type = static_total_results[start_of_group].match_type;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
|
2022-12-06 04:24:45 +01:00
|
|
|
|
while (start_of_group + n_items_in_group < static_total_results_size &&
|
|
|
|
|
static_total_results[start_of_group + n_items_in_group].category == this_category &&
|
|
|
|
|
static_total_results[start_of_group + n_items_in_group].match_type == this_match_type)
|
|
|
|
|
n_items_in_group++;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
|
2022-12-06 04:24:45 +01:00
|
|
|
|
results[i] = g_new (gchar *, n_items_in_group + 1);
|
|
|
|
|
for (j = 0; j < n_items_in_group; j++)
|
|
|
|
|
results[i][j] = g_strdup (static_total_results[start_of_group + j].app_name);
|
2013-11-06 04:51:48 +01:00
|
|
|
|
results[i][j] = NULL;
|
|
|
|
|
|
2022-12-06 04:24:45 +01:00
|
|
|
|
start_of_group += n_items_in_group;
|
2013-11-06 04:51:48 +01:00
|
|
|
|
}
|
|
|
|
|
results[i] = NULL;
|
|
|
|
|
|
|
|
|
|
desktop_file_dirs_unlock ();
|
|
|
|
|
|
|
|
|
|
g_strfreev (search_tokens);
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_app_info_get_all:
|
2007-12-09 16:51:12 +01:00
|
|
|
|
*
|
2013-07-27 21:08:58 +02:00
|
|
|
|
* Gets a list of all of the applications currently registered
|
2008-01-04 11:51:56 +01:00
|
|
|
|
* on this system.
|
2013-07-27 21:08:58 +02:00
|
|
|
|
*
|
|
|
|
|
* For desktop files, this includes applications that have
|
2014-02-06 14:04:52 +01:00
|
|
|
|
* `NoDisplay=true` set or are excluded from display by means
|
|
|
|
|
* of `OnlyShowIn` or `NotShowIn`. See g_app_info_should_show().
|
2008-01-04 11:51:56 +01:00
|
|
|
|
* The returned list does not include applications which have
|
2014-02-06 14:04:52 +01:00
|
|
|
|
* the `Hidden` key set.
|
2013-07-27 21:08:58 +02:00
|
|
|
|
*
|
2014-02-06 14:04:52 +01:00
|
|
|
|
* Returns: (element-type GAppInfo) (transfer full): a newly allocated #GList of references to #GAppInfos.
|
2007-11-26 17:13:05 +01:00
|
|
|
|
**/
|
|
|
|
|
GList *
|
|
|
|
|
g_app_info_get_all (void)
|
|
|
|
|
{
|
|
|
|
|
GHashTable *apps;
|
2007-12-15 05:39:26 +01:00
|
|
|
|
GHashTableIter iter;
|
2007-12-22 19:15:57 +01:00
|
|
|
|
gpointer value;
|
2020-11-17 11:13:29 +01:00
|
|
|
|
guint i;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
GList *infos;
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
apps = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
desktop_file_dirs_lock ();
|
2013-07-24 23:48:37 +02:00
|
|
|
|
|
2019-10-11 22:33:47 +02:00
|
|
|
|
for (i = 0; i < desktop_file_dirs->len; i++)
|
|
|
|
|
desktop_file_dir_get_all (g_ptr_array_index (desktop_file_dirs, i), apps);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
desktop_file_dirs_unlock ();
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
infos = NULL;
|
2007-12-15 05:39:26 +01:00
|
|
|
|
g_hash_table_iter_init (&iter, apps);
|
2007-12-22 19:15:57 +01:00
|
|
|
|
while (g_hash_table_iter_next (&iter, NULL, &value))
|
2007-12-31 02:47:59 +01:00
|
|
|
|
{
|
|
|
|
|
if (value)
|
|
|
|
|
infos = g_list_prepend (infos, value);
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
g_hash_table_destroy (apps);
|
|
|
|
|
|
2013-07-27 22:04:56 +02:00
|
|
|
|
return infos;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* GDesktopAppInfoLookup interface {{{2 */
|
2010-11-09 13:19:19 +01:00
|
|
|
|
|
2015-02-05 16:20:43 +01:00
|
|
|
|
/**
|
|
|
|
|
* GDesktopAppInfoLookup:
|
|
|
|
|
*
|
|
|
|
|
* #GDesktopAppInfoLookup is an opaque data structure and can only be accessed
|
|
|
|
|
* using the following functions.
|
2019-05-27 19:09:08 +02:00
|
|
|
|
*
|
|
|
|
|
* Deprecated: 2.28: The #GDesktopAppInfoLookup interface is deprecated and
|
|
|
|
|
* unused by GIO.
|
2015-02-05 16:20:43 +01:00
|
|
|
|
**/
|
|
|
|
|
|
2012-02-10 14:49:17 +01:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
|
2010-11-09 13:19:19 +01:00
|
|
|
|
typedef GDesktopAppInfoLookupIface GDesktopAppInfoLookupInterface;
|
|
|
|
|
G_DEFINE_INTERFACE (GDesktopAppInfoLookup, g_desktop_app_info_lookup, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_desktop_app_info_lookup_default_init (GDesktopAppInfoLookupInterface *iface)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* "Get for mime type" APIs {{{2 */
|
|
|
|
|
|
2010-11-09 13:19:19 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_lookup_get_default_for_uri_scheme:
|
|
|
|
|
* @lookup: a #GDesktopAppInfoLookup
|
|
|
|
|
* @uri_scheme: a string containing a URI scheme.
|
|
|
|
|
*
|
2013-07-27 21:08:58 +02:00
|
|
|
|
* Gets the default application for launching applications
|
2019-05-27 19:09:35 +02:00
|
|
|
|
* using this URI scheme for a particular #GDesktopAppInfoLookup
|
2010-11-09 13:19:19 +01:00
|
|
|
|
* implementation.
|
|
|
|
|
*
|
2019-05-27 19:09:35 +02:00
|
|
|
|
* The #GDesktopAppInfoLookup interface and this function is used
|
2010-11-09 13:19:19 +01:00
|
|
|
|
* to implement g_app_info_get_default_for_uri_scheme() backends
|
|
|
|
|
* in a GIO module. There is no reason for applications to use it
|
|
|
|
|
* directly. Applications should use g_app_info_get_default_for_uri_scheme().
|
2013-07-27 21:08:58 +02:00
|
|
|
|
*
|
2020-04-28 10:49:57 +02:00
|
|
|
|
* Returns: (transfer full) (nullable): #GAppInfo for given @uri_scheme or
|
|
|
|
|
* %NULL on error.
|
2010-11-09 13:19:19 +01:00
|
|
|
|
*
|
2019-05-27 19:09:08 +02:00
|
|
|
|
* Deprecated: 2.28: The #GDesktopAppInfoLookup interface is deprecated and
|
|
|
|
|
* unused by GIO.
|
2010-11-09 13:19:19 +01:00
|
|
|
|
*/
|
|
|
|
|
GAppInfo *
|
|
|
|
|
g_desktop_app_info_lookup_get_default_for_uri_scheme (GDesktopAppInfoLookup *lookup,
|
2013-07-27 21:08:58 +02:00
|
|
|
|
const char *uri_scheme)
|
2010-11-09 13:19:19 +01:00
|
|
|
|
{
|
|
|
|
|
GDesktopAppInfoLookupIface *iface;
|
2012-01-30 20:21:03 +01:00
|
|
|
|
|
2010-11-09 13:19:19 +01:00
|
|
|
|
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO_LOOKUP (lookup), NULL);
|
|
|
|
|
|
|
|
|
|
iface = G_DESKTOP_APP_INFO_LOOKUP_GET_IFACE (lookup);
|
|
|
|
|
|
|
|
|
|
return (* iface->get_default_for_uri_scheme) (lookup, uri_scheme);
|
|
|
|
|
}
|
2012-02-10 14:49:17 +01:00
|
|
|
|
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
2012-04-05 23:26:12 +02:00
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* Misc getter APIs {{{2 */
|
|
|
|
|
|
2012-04-05 23:26:12 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_startup_wm_class:
|
2012-09-23 08:18:56 +02:00
|
|
|
|
* @info: a #GDesktopAppInfo that supports startup notify
|
2012-04-05 23:26:12 +02:00
|
|
|
|
*
|
2012-09-23 08:18:56 +02:00
|
|
|
|
* Retrieves the StartupWMClass field from @info. This represents the
|
|
|
|
|
* WM_CLASS property of the main window of the application, if launched
|
|
|
|
|
* through @info.
|
2012-04-05 23:26:12 +02:00
|
|
|
|
*
|
2020-10-18 10:15:54 +02:00
|
|
|
|
* Returns: (nullable) (transfer none): the startup WM class, or %NULL if none is set
|
2012-04-05 23:26:12 +02:00
|
|
|
|
* in the desktop file.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.34
|
|
|
|
|
*/
|
|
|
|
|
const char *
|
2012-09-23 08:18:56 +02:00
|
|
|
|
g_desktop_app_info_get_startup_wm_class (GDesktopAppInfo *info)
|
2012-04-05 23:26:12 +02:00
|
|
|
|
{
|
2012-09-23 08:18:56 +02:00
|
|
|
|
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
|
2012-04-05 23:26:12 +02:00
|
|
|
|
|
2012-09-23 08:18:56 +02:00
|
|
|
|
return info->startup_wm_class;
|
2012-04-05 23:26:12 +02:00
|
|
|
|
}
|
2012-11-17 00:22:45 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_string:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
* @key: the key to look up
|
|
|
|
|
*
|
|
|
|
|
* Looks up a string value in the keyfile backing @info.
|
|
|
|
|
*
|
|
|
|
|
* The @key is looked up in the "Desktop Entry" group.
|
|
|
|
|
*
|
2020-10-18 10:15:54 +02:00
|
|
|
|
* Returns: (nullable): a newly allocated string, or %NULL if the key
|
2012-11-17 00:22:45 +01:00
|
|
|
|
* is not found
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.36
|
|
|
|
|
*/
|
|
|
|
|
char *
|
|
|
|
|
g_desktop_app_info_get_string (GDesktopAppInfo *info,
|
|
|
|
|
const char *key)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
|
|
|
|
|
|
|
|
|
|
return g_key_file_get_string (info->keyfile,
|
|
|
|
|
G_KEY_FILE_DESKTOP_GROUP, key, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-07 12:14:46 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_locale_string:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
* @key: the key to look up
|
|
|
|
|
*
|
|
|
|
|
* Looks up a localized string value in the keyfile backing @info
|
|
|
|
|
* translated to the current locale.
|
|
|
|
|
*
|
|
|
|
|
* The @key is looked up in the "Desktop Entry" group.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (nullable): a newly allocated string, or %NULL if the key
|
|
|
|
|
* is not found
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.56
|
|
|
|
|
*/
|
|
|
|
|
char *
|
|
|
|
|
g_desktop_app_info_get_locale_string (GDesktopAppInfo *info,
|
|
|
|
|
const char *key)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
|
|
|
|
|
g_return_val_if_fail (key != NULL && *key != '\0', NULL);
|
|
|
|
|
|
|
|
|
|
return g_key_file_get_locale_string (info->keyfile,
|
|
|
|
|
G_KEY_FILE_DESKTOP_GROUP,
|
|
|
|
|
key, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-17 00:22:45 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_boolean:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
* @key: the key to look up
|
|
|
|
|
*
|
|
|
|
|
* Looks up a boolean value in the keyfile backing @info.
|
|
|
|
|
*
|
|
|
|
|
* The @key is looked up in the "Desktop Entry" group.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the boolean value, or %FALSE if the key
|
|
|
|
|
* is not found
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.36
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
g_desktop_app_info_get_boolean (GDesktopAppInfo *info,
|
|
|
|
|
const char *key)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), FALSE);
|
|
|
|
|
|
|
|
|
|
return g_key_file_get_boolean (info->keyfile,
|
|
|
|
|
G_KEY_FILE_DESKTOP_GROUP, key, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
gdesktopappinfo: add get_string_list() function
The X-Flatpak-RenamedFrom key is used in .desktop files to identify past
names for the desktop file. It is defined to be a list of strings.
However, there was previously no correct way to retrieve a list of
strings from the GKeyFile wrapped by GDesktopAppInfo, short of
re-parsing the file with GKeyFile.
Note that doing something like:
g_strsplit (g_desktop_app_info_get_string (...), ";", -1)
is not correct: the raw value "a\;b;" represents the one-element list
["a;b"], but g_key_file_get_string() rejects the sequence "\;", and so
g_desktop_app_info_get_string() returns NULL in this case. (Of course, a
.desktop file with a semicolon in its name is a pathological case.)
Add g_desktop_app_info_get_string_list(), a trivial wrapper around
g_key_file_get_string_list(), similar to g_desktop_app_info_get_string()
and co.
The change from g_key_file_free() to g_key_file_unref() in the test is
needed because g_key_file_free() clears the contents of the keyfile.
This is fine for all the fields which are eagerly loaded and copied into
GDesktopAppInfo, but not when we want to access arbitrary stuff from the
keyfile.
2018-09-20 17:26:55 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_string_list:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
* @key: the key to look up
|
|
|
|
|
* @length: (out) (optional): return location for the number of returned strings, or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Looks up a string list value in the keyfile backing @info.
|
|
|
|
|
*
|
|
|
|
|
* The @key is looked up in the "Desktop Entry" group.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (array zero-terminated=1 length=length) (element-type utf8) (transfer full):
|
|
|
|
|
* a %NULL-terminated string array or %NULL if the specified
|
|
|
|
|
* key cannot be found. The array should be freed with g_strfreev().
|
|
|
|
|
*
|
2019-03-07 18:27:35 +01:00
|
|
|
|
* Since: 2.60
|
gdesktopappinfo: add get_string_list() function
The X-Flatpak-RenamedFrom key is used in .desktop files to identify past
names for the desktop file. It is defined to be a list of strings.
However, there was previously no correct way to retrieve a list of
strings from the GKeyFile wrapped by GDesktopAppInfo, short of
re-parsing the file with GKeyFile.
Note that doing something like:
g_strsplit (g_desktop_app_info_get_string (...), ";", -1)
is not correct: the raw value "a\;b;" represents the one-element list
["a;b"], but g_key_file_get_string() rejects the sequence "\;", and so
g_desktop_app_info_get_string() returns NULL in this case. (Of course, a
.desktop file with a semicolon in its name is a pathological case.)
Add g_desktop_app_info_get_string_list(), a trivial wrapper around
g_key_file_get_string_list(), similar to g_desktop_app_info_get_string()
and co.
The change from g_key_file_free() to g_key_file_unref() in the test is
needed because g_key_file_free() clears the contents of the keyfile.
This is fine for all the fields which are eagerly loaded and copied into
GDesktopAppInfo, but not when we want to access arbitrary stuff from the
keyfile.
2018-09-20 17:26:55 +02:00
|
|
|
|
*/
|
|
|
|
|
gchar **
|
|
|
|
|
g_desktop_app_info_get_string_list (GDesktopAppInfo *info,
|
|
|
|
|
const char *key,
|
|
|
|
|
gsize *length)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
|
|
|
|
|
|
|
|
|
|
return g_key_file_get_string_list (info->keyfile,
|
|
|
|
|
G_KEY_FILE_DESKTOP_GROUP, key, length, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-17 00:22:45 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_has_key:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
* @key: the key to look up
|
|
|
|
|
*
|
|
|
|
|
* Returns whether @key exists in the "Desktop Entry" group
|
|
|
|
|
* of the keyfile backing @info.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the @key exists
|
|
|
|
|
*
|
2014-01-13 12:33:35 +01:00
|
|
|
|
* Since: 2.36
|
2012-11-17 00:22:45 +01:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
g_desktop_app_info_has_key (GDesktopAppInfo *info,
|
|
|
|
|
const char *key)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), FALSE);
|
|
|
|
|
|
|
|
|
|
return g_key_file_has_key (info->keyfile,
|
|
|
|
|
G_KEY_FILE_DESKTOP_GROUP, key, NULL);
|
|
|
|
|
}
|
2013-07-11 18:46:59 +02:00
|
|
|
|
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* Desktop actions support {{{2 */
|
|
|
|
|
|
2013-07-11 18:46:59 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_list_actions:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
*
|
|
|
|
|
* Returns the list of "additional application actions" supported on the
|
|
|
|
|
* desktop file, as per the desktop file specification.
|
|
|
|
|
*
|
|
|
|
|
* As per the specification, this is the list of actions that are
|
|
|
|
|
* explicitly listed in the "Actions" key of the [Desktop Entry] group.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (array zero-terminated=1) (element-type utf8) (transfer none): a list of strings, always non-%NULL
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.38
|
|
|
|
|
**/
|
|
|
|
|
const gchar * const *
|
|
|
|
|
g_desktop_app_info_list_actions (GDesktopAppInfo *info)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
|
|
|
|
|
|
|
|
|
|
return (const gchar **) info->actions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
app_info_has_action (GDesktopAppInfo *info,
|
|
|
|
|
const gchar *action_name)
|
|
|
|
|
{
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; info->actions[i]; i++)
|
|
|
|
|
if (g_str_equal (info->actions[i], action_name))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_get_action_name:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
* @action_name: the name of the action as from
|
|
|
|
|
* g_desktop_app_info_list_actions()
|
|
|
|
|
*
|
|
|
|
|
* Gets the user-visible display name of the "additional application
|
|
|
|
|
* action" specified by @action_name.
|
|
|
|
|
*
|
|
|
|
|
* This corresponds to the "Name" key within the keyfile group for the
|
|
|
|
|
* action.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): the locale-specific action name
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.38
|
|
|
|
|
*/
|
|
|
|
|
gchar *
|
|
|
|
|
g_desktop_app_info_get_action_name (GDesktopAppInfo *info,
|
|
|
|
|
const gchar *action_name)
|
|
|
|
|
{
|
|
|
|
|
gchar *group_name;
|
|
|
|
|
gchar *result;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
|
|
|
|
|
g_return_val_if_fail (action_name != NULL, NULL);
|
2013-07-31 00:20:44 +02:00
|
|
|
|
g_return_val_if_fail (app_info_has_action (info, action_name), NULL);
|
2013-07-11 18:46:59 +02:00
|
|
|
|
|
|
|
|
|
group_name = g_strdup_printf ("Desktop Action %s", action_name);
|
|
|
|
|
result = g_key_file_get_locale_string (info->keyfile, group_name, "Name", NULL, NULL);
|
|
|
|
|
g_free (group_name);
|
|
|
|
|
|
|
|
|
|
/* The spec says that the Name field must be given.
|
|
|
|
|
*
|
|
|
|
|
* If it's not, let's follow the behaviour of our get_name()
|
|
|
|
|
* implementation above and never return %NULL.
|
|
|
|
|
*/
|
|
|
|
|
if (result == NULL)
|
|
|
|
|
result = g_strdup (_("Unnamed"));
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* g_desktop_app_info_launch_action:
|
|
|
|
|
* @info: a #GDesktopAppInfo
|
|
|
|
|
* @action_name: the name of the action as from
|
|
|
|
|
* g_desktop_app_info_list_actions()
|
2016-10-29 03:29:02 +02:00
|
|
|
|
* @launch_context: (nullable): a #GAppLaunchContext
|
2013-07-11 18:46:59 +02:00
|
|
|
|
*
|
|
|
|
|
* Activates the named application action.
|
|
|
|
|
*
|
|
|
|
|
* You may only call this function on action names that were
|
|
|
|
|
* returned from g_desktop_app_info_list_actions().
|
|
|
|
|
*
|
|
|
|
|
* Note that if the main entry of the desktop file indicates that the
|
|
|
|
|
* application supports startup notification, and @launch_context is
|
|
|
|
|
* non-%NULL, then startup notification will be used when activating the
|
|
|
|
|
* action (and as such, invocation of the action on the receiving side
|
|
|
|
|
* must signal the end of startup notification when it is completed).
|
|
|
|
|
* This is the expected behaviour of applications declaring additional
|
|
|
|
|
* actions, as per the desktop file specification.
|
|
|
|
|
*
|
|
|
|
|
* As with g_app_info_launch() there is no way to detect failures that
|
|
|
|
|
* occur while using this function.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.38
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
g_desktop_app_info_launch_action (GDesktopAppInfo *info,
|
|
|
|
|
const gchar *action_name,
|
|
|
|
|
GAppLaunchContext *launch_context)
|
|
|
|
|
{
|
|
|
|
|
GDBusConnection *session_bus;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_DESKTOP_APP_INFO (info));
|
|
|
|
|
g_return_if_fail (action_name != NULL);
|
|
|
|
|
g_return_if_fail (app_info_has_action (info, action_name));
|
|
|
|
|
|
|
|
|
|
session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (session_bus && info->app_id)
|
|
|
|
|
{
|
|
|
|
|
gchar *object_path;
|
|
|
|
|
|
|
|
|
|
object_path = object_path_from_appid (info->app_id);
|
|
|
|
|
g_dbus_connection_call (session_bus, info->app_id, object_path,
|
|
|
|
|
"org.freedesktop.Application", "ActivateAction",
|
|
|
|
|
g_variant_new ("(sav@a{sv})", action_name, NULL,
|
|
|
|
|
g_desktop_app_info_make_platform_data (info, NULL, launch_context)),
|
|
|
|
|
NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
|
|
|
|
|
g_free (object_path);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gchar *group_name;
|
|
|
|
|
gchar *exec_line;
|
|
|
|
|
|
|
|
|
|
group_name = g_strdup_printf ("Desktop Action %s", action_name);
|
|
|
|
|
exec_line = g_key_file_get_string (info->keyfile, group_name, "Exec", NULL);
|
|
|
|
|
g_free (group_name);
|
|
|
|
|
|
|
|
|
|
if (exec_line)
|
|
|
|
|
g_desktop_app_info_launch_uris_with_spawn (info, session_bus, exec_line, NULL, launch_context,
|
2018-06-06 14:59:59 +02:00
|
|
|
|
_SPAWN_FLAGS_DEFAULT, NULL, NULL, NULL, NULL,
|
|
|
|
|
-1, -1, -1, NULL);
|
2018-06-27 10:52:33 +02:00
|
|
|
|
|
|
|
|
|
g_free (exec_line);
|
2013-07-11 18:46:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (session_bus != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_dbus_connection_flush (session_bus, NULL, NULL, NULL);
|
|
|
|
|
g_object_unref (session_bus);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-27 21:08:58 +02:00
|
|
|
|
/* Epilogue {{{1 */
|
|
|
|
|
|
|
|
|
|
/* vim:set foldmethod=marker: */
|