Hello. Attached are two patches, one for gnome-desktop and one for gnome-panel, which provides gnome-panel support for the Actions key in the .desktop file format. It simply populates the right-click menu with the extra actions specified in the .desktop file. Christian -- Christian Hammond <> The GNUpdate Project chipx86 gnupdate org <> http://www.gnupdate.org/ To err is human; To moo is bovine.
? gnome-desktop-actions-20031213-1526.diff
? intltool-modules
Index: libgnome-desktop/gnome-desktop-item.c
===================================================================
RCS file: /cvs/gnome/gnome-desktop/libgnome-desktop/gnome-desktop-item.c,v
retrieving revision 1.131
diff -u -r1.131 gnome-desktop-item.c
--- libgnome-desktop/gnome-desktop-item.c 3 Dec 2003 21:58:42 -0000 1.131
+++ libgnome-desktop/gnome-desktop-item.c 29 Dec 2003 06:37:27 -0000
@@ -1921,6 +1921,7 @@
static int
gnome_desktop_item_launch_on_screen_with_env (
const GnomeDesktopItem *item,
+ const char *action,
GList *file_list,
GnomeDesktopItemLaunchFlags flags,
GdkScreen *screen,
@@ -1932,7 +1933,16 @@
char *the_exec;
int ret;
- exec = gnome_desktop_item_get_string (item, GNOME_DESKTOP_ITEM_EXEC);
+ if (action == NULL) {
+ exec = gnome_desktop_item_get_string (item, GNOME_DESKTOP_ITEM_EXEC);
+ } else {
+ char *key = g_strdup_printf ("Desktop Action %s/Exec", action);
+
+ exec = gnome_desktop_item_get_string (item, key);
+
+ g_free (key);
+ }
+
/* This is a URL, so launch it as a url */
if (item->type == GNOME_DESKTOP_ITEM_TYPE_LINK) {
const char *url;
@@ -2026,7 +2036,7 @@
GError **error)
{
return gnome_desktop_item_launch_on_screen_with_env (
- item, file_list, flags, NULL, -1, NULL, error);
+ item, NULL, file_list, flags, NULL, -1, NULL, error);
}
/**
@@ -2053,7 +2063,7 @@
GError **error)
{
return gnome_desktop_item_launch_on_screen_with_env (
- item, file_list, flags,
+ item, NULL, file_list, flags,
NULL, -1, envp, error);
}
@@ -2083,10 +2093,104 @@
GError **error)
{
return gnome_desktop_item_launch_on_screen_with_env (
- item, file_list, flags,
+ item, NULL, file_list, flags,
screen, workspace, NULL, error);
}
+/**
+ * gnome_desktop_item_launch_action:
+ * @item: A desktop item
+ * @action: The action to launch
+ * @file_list: Files/URIs to launch this item with, can be %NULL
+ * @flags: FIXME
+ * @error: FIXME
+ *
+ * This function runs the action listed in the specified 'item',
+ * optionally appending additional arguments to its command line. It uses
+ * #g_shell_parse_argv to parse the the exec string into a vector which is
+ * then passed to #g_spawn_async for execution. This can return all
+ * the errors from GnomeURL, #g_shell_parse_argv and #g_spawn_async,
+ * in addition to it's own. The files are
+ * only added if the entry defines one of the standard % strings in it's
+ * Exec field.
+ *
+ * Returns: The the pid of the process spawned. If more then one
+ * process was spawned the last pid is returned. On error -1
+ * is returned and @error is set.
+ */
+int
+gnome_desktop_item_launch_action (const GnomeDesktopItem *item,
+ const char *action,
+ GList *file_list,
+ GnomeDesktopItemLaunchFlags flags,
+ GError **error)
+{
+ return gnome_desktop_item_launch_on_screen_with_env (
+ item, action, file_list, flags, NULL, -1, NULL, error);
+}
+
+/**
+ * gnome_desktop_item_launch_action_with_env:
+ * @item: A desktop item
+ * @action: The action to launch
+ * @file_list: Files/URIs to launch this item with, can be %NULL
+ * @flags: FIXME
+ * @envp: child's environment, or %NULL to inherit parent's
+ * @error: FIXME
+ *
+ * See gnome_desktop_item_launch for a full description. This function
+ * additionally passes an environment vector for the child process
+ * which is to be launched.
+ *
+ * Returns: The the pid of the process spawned. If more then one
+ * process was spawned the last pid is returned. On error -1
+ * is returned and @error is set.
+ */
+int
+gnome_desktop_item_launch_action_with_env (const GnomeDesktopItem *item,
+ const char *action,
+ GList *file_list,
+ GnomeDesktopItemLaunchFlags flags,
+ char **envp,
+ GError **error)
+{
+ return gnome_desktop_item_launch_on_screen_with_env (
+ item, action, file_list, flags,
+ NULL, -1, envp, error);
+}
+
+
+/**
+ * gnome_desktop_item_launch_action_on_screen:
+ * @item: A desktop item
+ * @action: The action to launch
+ * @file_list: Files/URIs to launch this item with, can be %NULL
+ * @flags: FIXME
+ * @screen: the %GdkScreen on which the application should be launched
+ * @workspace: the workspace on which the app should be launched (-1 for current)
+ * @error: FIXME
+ *
+ * See gnome_desktop_item_launch_action for a full description. This function
+ * additionally attempts to launch the application on a given screen
+ * and workspace.
+ *
+ * Returns: The the pid of the process spawned. If more then one
+ * process was spawned the last pid is returned. On error -1
+ * is returned and @error is set.
+ */
+int
+gnome_desktop_item_launch_action_on_screen (const GnomeDesktopItem *item,
+ const char *action,
+ GList *file_list,
+ GnomeDesktopItemLaunchFlags flags,
+ GdkScreen *screen,
+ int workspace,
+ GError **error)
+{
+ return gnome_desktop_item_launch_on_screen_with_env (
+ item, action, file_list, flags,
+ screen, workspace, NULL, error);
+}
/**
* gnome_desktop_item_drop_uri_list:
* @item: A desktop item
Index: libgnome-desktop/gnome-desktop-item.h
===================================================================
RCS file: /cvs/gnome/gnome-desktop/libgnome-desktop/gnome-desktop-item.h,v
retrieving revision 1.49
diff -u -r1.49 gnome-desktop-item.h
--- libgnome-desktop/gnome-desktop-item.h 28 Nov 2002 11:38:41 -0000 1.49
+++ libgnome-desktop/gnome-desktop-item.h 29 Dec 2003 06:37:28 -0000
@@ -180,6 +180,26 @@
int workspace,
GError **error);
+int gnome_desktop_item_launch_action (const GnomeDesktopItem *item,
+ const char *action,
+ GList *file_list,
+ GnomeDesktopItemLaunchFlags flags,
+ GError **error);
+int gnome_desktop_item_launch_action_with_env (const GnomeDesktopItem *item,
+ const char *action,
+ GList *file_list,
+ GnomeDesktopItemLaunchFlags flags,
+ char **envp,
+ GError **error);
+
+int gnome_desktop_item_launch_action_on_screen (const GnomeDesktopItem *item,
+ const char *action,
+ GList *file_list,
+ GnomeDesktopItemLaunchFlags flags,
+ GdkScreen *screen,
+ int workspace,
+ GError **error);
+
/* A list of files or urls dropped onto an icon This is the output
* of gnome_vfs_uri_list_parse */
int gnome_desktop_item_drop_uri_list (const GnomeDesktopItem *item,
? intltool-modules
Index: gnome-panel/applet.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/applet.c,v
retrieving revision 1.226
diff -u -r1.226 applet.c
--- gnome-panel/applet.c 10 Dec 2003 17:47:54 -0000 1.226
+++ gnome-panel/applet.c 29 Dec 2003 06:36:45 -0000
@@ -180,6 +180,33 @@
if (!strcmp (menu->name, "properties"))
launcher_properties (
menu->info->data, screen);
+ else {
+ Launcher *launcher = (Launcher *)menu->info->data;
+ const char *cmd;
+ char *key;
+
+ key = g_strdup_printf ("Desktop Action %s/Exec", menu->name);
+ cmd = gnome_desktop_item_get_string (launcher->ditem, key);
+
+ g_free(key);
+
+ if (cmd != NULL) {
+ GError *error = NULL;
+
+ panel_ditem_launch_action (
+ launcher->ditem, menu->name, NULL, 0, screen, &error);
+
+ if (error) {
+ panel_error_dialog (screen,
+ "cannot_launch_icon",
+ _("Cannot launch icon"),
+ "%s",
+ error->message);
+
+ g_clear_error (&error);
+ }
+ }
+ }
break;
case PANEL_OBJECT_DRAWER:
if (strcmp (menu->name, "properties")==0) {
Index: gnome-panel/launcher.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/launcher.c,v
retrieving revision 1.265
diff -u -r1.265 launcher.c
--- gnome-panel/launcher.c 11 Dec 2003 17:10:43 -0000 1.265
+++ gnome-panel/launcher.c 29 Dec 2003 06:36:45 -0000
@@ -715,6 +715,7 @@
const char *id)
{
Launcher *launcher;
+ char **actions;
launcher = create_launcher (location);
@@ -727,6 +728,22 @@
PANEL_OBJECT_LAUNCHER, id);
if (!launcher->info)
return NULL;
+
+ actions = gnome_desktop_item_get_strings (launcher->ditem,
+ GNOME_DESKTOP_ITEM_ACTIONS);
+
+ if (actions != NULL) {
+ int i;
+
+ for (i = 0; actions[i] != NULL; i++) {
+ if (*actions[i] != '\0') {
+ panel_applet_add_callback (launcher->info,
+ actions[i], NULL, _(actions[i]));
+ }
+ }
+
+ g_strfreev (actions);
+ }
if ( ! panel_profile_get_locked_down () &&
! panel_toplevel_get_locked_down (panel->toplevel) &&
Index: gnome-panel/panel-action-button.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/panel-action-button.c,v
retrieving revision 1.21
diff -u -r1.21 panel-action-button.c
--- gnome-panel/panel-action-button.c 10 Dec 2003 17:47:54 -0000 1.21
+++ gnome-panel/panel-action-button.c 29 Dec 2003 06:36:45 -0000
@@ -633,7 +633,7 @@
action_type = gconf_client_get_string (panel_gconf_get_client (), key, NULL);
if (!gconf_string_to_enum (panel_action_type_map, action_type, &type)) {
- g_warning ("Unkown action type '%s' from %s", action_type, key);
+ g_warning ("Unknown action type '%s' from %s", action_type, key);
g_free (action_type);
return;
}
Index: gnome-panel/panel-util.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/panel-util.c,v
retrieving revision 1.142
diff -u -r1.142 panel-util.c
--- gnome-panel/panel-util.c 11 Dec 2003 17:10:44 -0000 1.142
+++ gnome-panel/panel-util.c 29 Dec 2003 06:36:46 -0000
@@ -55,6 +55,21 @@
item, file_list, flags, screen, workspace, error);
}
+int
+panel_ditem_launch_action (const GnomeDesktopItem *item,
+ const char *action,
+ GList *file_list,
+ GnomeDesktopItemLaunchFlags flags,
+ GdkScreen *screen,
+ GError **error)
+{
+ int workspace;
+
+ workspace = xstuff_get_current_workspace (screen);
+
+ return gnome_desktop_item_launch_action_on_screen (
+ item, action, file_list, flags, screen, workspace, error);
+}
void
panel_show_help (GdkScreen *screen,
const char *doc_name,
Index: gnome-panel/panel-util.h
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/panel-util.h,v
retrieving revision 1.77
diff -u -r1.77 panel-util.h
--- gnome-panel/panel-util.h 4 Dec 2003 14:07:38 -0000 1.77
+++ gnome-panel/panel-util.h 29 Dec 2003 06:36:46 -0000
@@ -24,6 +24,13 @@
GdkScreen *screen,
GError **error);
+int panel_ditem_launch_action (const GnomeDesktopItem *item,
+ const char *action,
+ GList *file_list,
+ GnomeDesktopItemLaunchFlags flags,
+ GdkScreen *screen,
+ GError **error);
+
void panel_show_help (GdkScreen *screen,
const char *path,
const char *linkid);
Attachment:
pgpajDXd0htHb.pgp
Description: PGP signature