[Xfce4-commits] [xfce/xfce4-session] 08/11: dbus-clients: Attempt to find and save the .desktop file
noreply at xfce.org
noreply at xfce.org
Tue Jun 28 09:26:11 CEST 2016
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository xfce/xfce4-session.
commit 9aa26d1465829e2a5b20d083f05597fa86a9ac26
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Sun Jun 26 14:50:29 2016 +0300
dbus-clients: Attempt to find and save the .desktop file
---
xfce4-session/xfsm-client.c | 86 +++++++++++++++++++++++++++++++++++++++++---
xfce4-session/xfsm-client.h | 4 +++
xfce4-session/xfsm-manager.c | 3 ++
3 files changed, 89 insertions(+), 4 deletions(-)
diff --git a/xfce4-session/xfsm-client.c b/xfce4-session/xfsm-client.c
index 8daa286..09fcecb 100644
--- a/xfce4-session/xfsm-client.c
+++ b/xfce4-session/xfsm-client.c
@@ -29,6 +29,7 @@
#endif
#include <gio/gio.h>
+#include <gio/gdesktopappinfo.h>
#include <libxfsm/xfsm-util.h>
@@ -48,6 +49,7 @@ struct _XfsmClient
XfsmManager *manager;
gchar *id;
+ gchar *app_id;
gchar *object_path;
gchar *service_name;
@@ -112,6 +114,7 @@ xfsm_client_finalize (GObject *obj)
xfsm_properties_free (client->properties);
g_free (client->id);
+ g_free (client->app_id);
g_free (client->object_path);
g_free (client->service_name);
@@ -258,6 +261,14 @@ xfsm_client_get_id (XfsmClient *client)
}
+const gchar *
+xfsm_client_get_app_id (XfsmClient *client)
+{
+ g_return_val_if_fail (XFSM_IS_CLIENT (client), NULL);
+ return client->app_id;
+}
+
+
SmsConn
xfsm_client_get_sms_connection (XfsmClient *client)
{
@@ -399,12 +410,12 @@ xfsm_client_save_restart_command (XfsmClient *client)
strv[0] = output;
strv[1] = NULL;
- xfsm_verbose ("%s restart command %s", input, output);
+ xfsm_verbose ("%s restart command %s\n", input, output);
xfsm_properties_set_strv (properties, "RestartCommand", strv);
}
else
{
- xfsm_verbose ("Failed to get the process command line using the command %s, error was %s", input, error->message);
+ xfsm_verbose ("Failed to get the process command line using the command %s, error was %s\n", input, error->message);
}
g_free (input);
@@ -428,12 +439,12 @@ xfsm_client_save_program_name (XfsmClient *client)
/* remove the newline at the end of the string */
output[strcspn(output, "\n")] = 0;
- xfsm_verbose ("%s program name %s", input, output);
+ xfsm_verbose ("%s program name %s\n", input, output);
xfsm_properties_set_string (properties, "Program", output);
}
else
{
- xfsm_verbose ("Failed to get the process command line using the command %s, error was %s", input, error->message);
+ xfsm_verbose ("Failed to get the process command line using the command %s, error was %s\n", input, error->message);
}
g_free (input);
@@ -441,6 +452,62 @@ xfsm_client_save_program_name (XfsmClient *client)
+static void
+xfsm_client_save_desktop_file (XfsmClient *client)
+{
+ XfsmProperties *properties = client->properties;
+ GDesktopAppInfo *app_info = NULL;
+ const gchar *app_id = client->app_id;
+ gchar *desktop_file = NULL;
+
+ if (app_id == NULL)
+ return;
+
+ /* First attempt to append .desktop to the filename since the desktop file
+ * may match the application id. I.e. org.gnome.Devhelp.desktop matches
+ * the GApplication org.gnome.Devhelp
+ */
+ desktop_file = g_strdup_printf("%s.desktop", app_id);
+ xfsm_verbose ("looking for desktop file %s\n", desktop_file);
+ app_info = g_desktop_app_info_new (desktop_file);
+
+ if (app_info == NULL || g_desktop_app_info_get_filename (app_info) == NULL)
+ {
+ gchar *begin;
+ g_free (desktop_file);
+ desktop_file = NULL;
+
+ /* Find the last '.' and try to load that. This is because the app_id is
+ * in the funky org.xfce.parole format and the desktop file may just be
+ * parole.desktop */
+ begin = g_strrstr (app_id, ".");
+
+ /* maybe it doesn't have dots in the name? */
+ if (begin == NULL || begin++ == NULL)
+ return;
+
+ desktop_file = g_strdup_printf ("%s.desktop", begin);
+ xfsm_verbose ("looking for desktop file %s\n", desktop_file);
+ app_info = g_desktop_app_info_new (desktop_file);
+
+ if (app_info == NULL || g_desktop_app_info_get_filename (app_info) == NULL)
+ {
+ /* Failed to get a desktop file, maybe it doesn't have one */
+ xfsm_verbose ("failed to get a desktop file for the client\n");
+ g_free (desktop_file);
+ return;
+ }
+ }
+
+ /* if we got here we found a .desktop file, save it */
+ xfsm_properties_set_string (properties, "DesktopFile", g_desktop_app_info_get_filename (app_info));
+
+ g_free (desktop_file);
+}
+
+
+
+
void
xfsm_client_set_pid (XfsmClient *client,
pid_t pid)
@@ -472,6 +539,17 @@ xfsm_client_set_pid (XfsmClient *client,
}
+void
+xfsm_client_set_app_id (XfsmClient *client,
+ const gchar *app_id)
+{
+ client->app_id = g_strdup (app_id);
+
+ /* save the desktop file */
+ xfsm_client_save_desktop_file (client);
+}
+
+
/*
* dbus server impl
diff --git a/xfce4-session/xfsm-client.h b/xfce4-session/xfsm-client.h
index 9388466..ea68c86 100644
--- a/xfce4-session/xfsm-client.h
+++ b/xfce4-session/xfsm-client.h
@@ -64,6 +64,7 @@ void xfsm_client_set_state (XfsmClient *client,
XfsmClientState state);
const gchar *xfsm_client_get_id (XfsmClient *client);
+const gchar *xfsm_client_get_app_id (XfsmClient *client);
SmsConn xfsm_client_get_sms_connection (XfsmClient *client);
@@ -82,6 +83,9 @@ const gchar *xfsm_client_get_object_path (XfsmClient *client);
void xfsm_client_set_pid (XfsmClient *client,
pid_t pid);
+void xfsm_client_set_app_id (XfsmClient *client,
+ const gchar *app_id);
+
void xfsm_client_set_service_name (XfsmClient *client,
const gchar *service_name);
const gchar *xfsm_client_get_service_name (XfsmClient *client);
diff --git a/xfce4-session/xfsm-manager.c b/xfce4-session/xfsm-manager.c
index c71d726..8912153 100644
--- a/xfce4-session/xfsm-manager.c
+++ b/xfce4-session/xfsm-manager.c
@@ -2437,6 +2437,9 @@ xfsm_manager_dbus_register_client (XfsmDbusManager *object,
/* register it so that it exports the dbus name */
xfsm_manager_register_client (manager, client, client_id, NULL);
+ /* save the app-id */
+ xfsm_client_set_app_id (client, arg_app_id);
+
/* attempt to get the caller'd pid */
if (!get_caller_info (manager, g_dbus_method_invocation_get_sender (invocation), &pid))
{
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list