adb8fd2
diff -up gnome-panel-2.19.92/gnome-panel/launcher.h.desktop-file-monitoring gnome-panel-2.19.92/gnome-panel/launcher.h
adb8fd2
--- gnome-panel-2.19.92/gnome-panel/launcher.h.desktop-file-monitoring	2007-09-04 13:34:26.000000000 -0400
1c078e5
+++ gnome-panel-2.19.92/gnome-panel/launcher.h	2007-09-13 12:23:44.000000000 -0400
adb8fd2
@@ -13,6 +13,7 @@
adb8fd2
 
adb8fd2
 #include "applet.h"
adb8fd2
 #include "panel-widget.h"
adb8fd2
+#include <libgnomevfs/gnome-vfs.h>
adb8fd2
 
adb8fd2
 G_BEGIN_DECLS
adb8fd2
 
adb8fd2
@@ -29,6 +30,8 @@ typedef struct {
adb8fd2
 	GSList 		  *error_dialogs;
adb8fd2
 
adb8fd2
 	gulong             destroy_handler;
adb8fd2
+
adb8fd2
+	GnomeVFSMonitorHandle *monitor; 
adb8fd2
 } Launcher;
adb8fd2
 
adb8fd2
 void panel_launcher_create           (PanelToplevel *toplevel,
adb8fd2
diff -up gnome-panel-2.19.92/gnome-panel/panel-ditem-editor.h.desktop-file-monitoring gnome-panel-2.19.92/gnome-panel/panel-ditem-editor.h
adb8fd2
--- gnome-panel-2.19.92/gnome-panel/panel-ditem-editor.h.desktop-file-monitoring	2007-09-04 13:34:26.000000000 -0400
1c078e5
+++ gnome-panel-2.19.92/gnome-panel/panel-ditem-editor.h	2007-09-13 12:23:44.000000000 -0400
adb8fd2
@@ -101,6 +101,8 @@ void panel_ditem_editor_set_uri (PanelDI
adb8fd2
 				 const char       *uri);
adb8fd2
 
adb8fd2
 G_CONST_RETURN char *panel_ditem_editor_get_uri (PanelDItemEditor *dialog);
adb8fd2
+G_CONST_RETURN char *panel_ditem_editor_get_orig_desktop_file (PanelDItemEditor *dialog);
adb8fd2
+
adb8fd2
 
adb8fd2
 void panel_ditem_register_save_uri_func (PanelDItemEditor  *dialog,
adb8fd2
 					 PanelDitemSaveUri  save_uri,
adb8fd2
diff -up gnome-panel-2.19.92/gnome-panel/launcher.c.desktop-file-monitoring gnome-panel-2.19.92/gnome-panel/launcher.c
adb8fd2
--- gnome-panel-2.19.92/gnome-panel/launcher.c.desktop-file-monitoring	2007-09-04 13:34:26.000000000 -0400
1c078e5
+++ gnome-panel-2.19.92/gnome-panel/launcher.c	2007-09-13 12:23:44.000000000 -0400
1c078e5
@@ -285,6 +285,8 @@ static void
adb8fd2
 destroy_launcher (GtkWidget *widget,
adb8fd2
 		  Launcher  *launcher)
adb8fd2
 {
adb8fd2
+	if (launcher->monitor)
adb8fd2
+		gnome_vfs_monitor_cancel (launcher->monitor);
adb8fd2
 	launcher_properties_destroy (launcher);
adb8fd2
 	launcher_widget_destroy_open_dialogs (launcher);
adb8fd2
 }
1c078e5
@@ -458,6 +460,37 @@ drag_data_get_cb (GtkWidget        *widg
adb8fd2
 
adb8fd2
 }
adb8fd2
 
adb8fd2
+static void setup_button (Launcher *launcher);
adb8fd2
+
adb8fd2
+static void
adb8fd2
+desktop_file_changed (GnomeVFSMonitorHandle    *handle,
adb8fd2
+		      const gchar              *monitor_uri,
adb8fd2
+		      const gchar              *info_uri,
adb8fd2
+		      GnomeVFSMonitorEventType  event_type,
adb8fd2
+		      gpointer                  user_data)
adb8fd2
+{
adb8fd2
+	Launcher *launcher = user_data;
adb8fd2
+	GKeyFile *key_file;
adb8fd2
+
adb8fd2
+	if (event_type == GNOME_VFS_MONITOR_EVENT_CHANGED ||
adb8fd2
+	    event_type == GNOME_VFS_MONITOR_EVENT_CREATED) {
adb8fd2
+		gchar *path;
adb8fd2
+
adb8fd2
+		path = gnome_vfs_get_local_path_from_uri (monitor_uri);
adb8fd2
+
adb8fd2
+		key_file = g_key_file_new ();
adb8fd2
+		if (g_key_file_load_from_file (key_file, path,
adb8fd2
+					       G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
adb8fd2
+					       NULL)) {
adb8fd2
+			g_key_file_free (launcher->key_file);
adb8fd2
+			launcher->key_file = key_file;
adb8fd2
+			setup_button (launcher);        
adb8fd2
+		}
adb8fd2
+
adb8fd2
+		g_free (path);
adb8fd2
+	}
adb8fd2
+}
adb8fd2
+
adb8fd2
 static Launcher *
adb8fd2
 create_launcher (const char *location)
adb8fd2
 {
1c078e5
@@ -534,6 +567,25 @@ create_launcher (const char *location)
adb8fd2
 	launcher->key_file = key_file;
adb8fd2
 	launcher->prop_dialog = NULL;
adb8fd2
 	launcher->destroy_handler = 0;
adb8fd2
+	launcher->monitor = NULL;
adb8fd2
+
adb8fd2
+	/* Watch for changes to the desktop file. Since we don't want 
adb8fd2
+	 * to do this for every launcher, we only do it if the desktop 
adb8fd2
+	 * file contains a X-Panel-Monitor entry.
adb8fd2
+	 */
adb8fd2
+	if (g_key_file_get_boolean (key_file, "Desktop Entry", "X-Panel-Monitor", NULL)) {
adb8fd2
+		gchar *uri;
adb8fd2
+
adb8fd2
+
adb8fd2
+
adb8fd2
+		uri = g_strdup_printf ("file:%s", new_location);
adb8fd2
+		gnome_vfs_monitor_add (&launcher->monitor, 
adb8fd2
+				       uri,
adb8fd2
+				       GNOME_VFS_MONITOR_FILE,
adb8fd2
+				       desktop_file_changed,
adb8fd2
+				       launcher);
adb8fd2
+		g_free (uri);
adb8fd2
+	}
adb8fd2
 
adb8fd2
 	/* Icon will be setup later */
adb8fd2
 	launcher->button = button_widget_new (NULL /* icon */,
1c078e5
@@ -662,6 +714,15 @@ static void
adb8fd2
 launcher_changed (PanelDItemEditor *dialog,
adb8fd2
 		  Launcher         *launcher)
adb8fd2
 {
adb8fd2
+	/* If the user manually changes launcher properties,
adb8fd2
+	 * we stop monitoring the desktop file to not overwrite
adb8fd2
+	 * user changes.
adb8fd2
+	 */
adb8fd2
+	if (launcher->monitor) {
adb8fd2
+		gnome_vfs_monitor_cancel (launcher->monitor);
adb8fd2
+		launcher->monitor = NULL;
adb8fd2
+	}
adb8fd2
+
adb8fd2
 	/* Setup the button look */
adb8fd2
 	setup_button (launcher);
adb8fd2
 }
1c078e5
@@ -733,6 +794,43 @@ launcher_save_uri (PanelDItemEditor *dia
adb8fd2
 	return NULL;
adb8fd2
 }
adb8fd2
 
adb8fd2
+static const char *
adb8fd2
+desktop_file_to_monitor (PanelDItemEditor *editor)
adb8fd2
+{
adb8fd2
+	const char *entry;
adb8fd2
+	GKeyFile *key_file;
adb8fd2
+
adb8fd2
+	/* When the user selects a desktop file in the ditem editor,
adb8fd2
+	 * start monitoring the desktop file for changes.
adb8fd2
+	 */
adb8fd2
+	entry = panel_ditem_editor_get_orig_desktop_file (editor);
adb8fd2
+	if (entry) {
adb8fd2
+		key_file = g_key_file_new ();
adb8fd2
+		if (!g_key_file_load_from_file (key_file, entry, 0, NULL) ||
adb8fd2
+		    !panel_util_key_file_get_boolean (key_file, "X-Panel-Monitor", FALSE)) 
adb8fd2
+			entry = NULL;
adb8fd2
+		g_key_file_free (key_file);
adb8fd2
+	}
adb8fd2
+
adb8fd2
+	return entry;
adb8fd2
+}
adb8fd2
+
adb8fd2
+static void
adb8fd2
+start_monitoring (Launcher *launcher)
adb8fd2
+{
adb8fd2
+	gchar *uri;
adb8fd2
+
adb8fd2
+	uri = g_strdup_printf ("file:%s", launcher->location);
adb8fd2
+	if (launcher->monitor)
adb8fd2
+		gnome_vfs_monitor_cancel (launcher->monitor);
adb8fd2
+	gnome_vfs_monitor_add (&launcher->monitor, 
adb8fd2
+			       uri,
adb8fd2
+			       GNOME_VFS_MONITOR_FILE,
adb8fd2
+			       desktop_file_changed,
adb8fd2
+			       launcher);
adb8fd2
+	g_free (uri);
adb8fd2
+}
adb8fd2
+ 
adb8fd2
 static void
adb8fd2
 launcher_saved (GtkWidget *dialog,
adb8fd2
 		Launcher  *launcher)
1c078e5
@@ -740,11 +838,15 @@ launcher_saved (GtkWidget *dialog,
adb8fd2
 	const char  *uri;
adb8fd2
 	GConfClient *client;
adb8fd2
 	const char  *key;
adb8fd2
+	const char *path;
adb8fd2
 
adb8fd2
 	uri = panel_ditem_editor_get_uri (PANEL_DITEM_EDITOR (dialog));
adb8fd2
 	if (panel_launcher_get_filename (uri) != NULL)
adb8fd2
 		uri = panel_launcher_get_filename (uri);
adb8fd2
 
adb8fd2
+	if ((path = desktop_file_to_monitor (PANEL_DITEM_EDITOR (dialog))) != NULL)
adb8fd2
+		uri = path;
adb8fd2
+
adb8fd2
 	if (uri && launcher->location && strcmp (uri, launcher->location)) {
adb8fd2
 		client = panel_gconf_get_client ();
adb8fd2
 
1c078e5
@@ -757,6 +859,9 @@ launcher_saved (GtkWidget *dialog,
adb8fd2
 		if (launcher->location)
adb8fd2
 			g_free (launcher->location);
adb8fd2
 		launcher->location = g_strdup (uri);
adb8fd2
+
adb8fd2
+		if (path)
adb8fd2
+			start_monitoring (launcher);
adb8fd2
 	}
adb8fd2
 }
adb8fd2
 
1c078e5
@@ -923,6 +1028,7 @@ launcher_new_saved (GtkWidget *dialog,
adb8fd2
 	PanelWidget *panel;
adb8fd2
 	int          pos;
adb8fd2
 	const char  *uri;
adb8fd2
+	const char  *path;
adb8fd2
 
adb8fd2
 	pos = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), "pos"));
adb8fd2
 	panel = g_object_get_data (G_OBJECT (dialog), "panel");
1c078e5
@@ -930,6 +1036,10 @@ launcher_new_saved (GtkWidget *dialog,
adb8fd2
 	uri = panel_ditem_editor_get_uri (PANEL_DITEM_EDITOR (dialog));
adb8fd2
 	if (panel_launcher_get_filename (uri) != NULL)
adb8fd2
 		uri = panel_launcher_get_filename (uri);
adb8fd2
+
adb8fd2
+	if ((path = desktop_file_to_monitor (PANEL_DITEM_EDITOR (dialog))) != NULL)
adb8fd2
+		uri = path;
adb8fd2
+
adb8fd2
 	panel_launcher_create (panel->toplevel, pos, uri);
adb8fd2
 }
adb8fd2
 
adb8fd2
diff -up gnome-panel-2.19.92/gnome-panel/panel-ditem-editor.c.desktop-file-monitoring gnome-panel-2.19.92/gnome-panel/panel-ditem-editor.c
1c078e5
--- gnome-panel-2.19.92/gnome-panel/panel-ditem-editor.c.desktop-file-monitoring	2007-09-13 12:23:44.000000000 -0400
1c078e5
+++ gnome-panel-2.19.92/gnome-panel/panel-ditem-editor.c	2007-09-13 12:31:03.000000000 -0400
adb8fd2
@@ -80,6 +80,8 @@ struct _PanelDItemEditorPrivate
adb8fd2
 
adb8fd2
 	/* the directory of the theme for the icon, see bug #119208 */
adb8fd2
 	char *icon_theme_dir;
adb8fd2
+
adb8fd2
+	char *orig_desktop_file;
adb8fd2
 };
adb8fd2
 
adb8fd2
 /* Time in seconds after which we save the file on the disk */
adb8fd2
@@ -367,6 +369,10 @@ panel_ditem_editor_destroy (GtkObject *o
adb8fd2
 		g_free (dialog->priv->icon_theme_dir);
adb8fd2
 	dialog->priv->icon_theme_dir = NULL;
adb8fd2
 
adb8fd2
+	if (dialog->priv->orig_desktop_file != NULL)
adb8fd2
+		g_free (dialog->priv->orig_desktop_file);
adb8fd2
+	dialog->priv->orig_desktop_file = NULL;
adb8fd2
+
adb8fd2
 	GTK_OBJECT_CLASS (panel_ditem_editor_parent_class)->destroy (object);
adb8fd2
 }
adb8fd2
 
adb8fd2
@@ -833,6 +839,13 @@ panel_ditem_editor_changed (PanelDItemEd
adb8fd2
 							   TRUE);
adb8fd2
 	}
adb8fd2
 
adb8fd2
+	/* When the user changes any fields, unset the orig_desktop_file
adb8fd2
+	 * field since the editor contents are not entirely from a desktop
adb8fd2
+	 * file anymore.
adb8fd2
+	 */ 
adb8fd2
+	g_free (dialog->priv->orig_desktop_file);
adb8fd2
+	dialog->priv->orig_desktop_file = NULL;
adb8fd2
+
adb8fd2
 	dialog->priv->dirty = TRUE;
adb8fd2
 	g_signal_emit (G_OBJECT (dialog), ditem_edit_signals[CHANGED], 0);
adb8fd2
 }
1c078e5
@@ -1005,6 +1018,13 @@ update_editor_from_desktop_file (PanelDI
adb8fd2
 		 */ 
adb8fd2
 		setup_icon_entry (dialog, icon);
adb8fd2
 
1c078e5
+                /* We set the orig_desktop_file field to let the
1c078e5
+                 * launcher know that the editor contents are coming
1c078e5
+                 * directly from a desktop file.
1c078e5
+                 */ 
1c078e5
+                g_free (dialog->priv->orig_desktop_file);
1c078e5
+                dialog->priv->orig_desktop_file = g_strdup (uri);
adb8fd2
+
1c078e5
 		g_free (name);
1c078e5
 		g_free (comment);
1c078e5
 		g_free (icon);
1c078e5
@@ -1079,6 +1099,7 @@ update_chooser_for_type (PanelDItemEdito
1c078e5
 		g_assert_not_reached ();
adb8fd2
 	}
adb8fd2
 
1c078e5
+
1c078e5
 	chooser = dialog->priv->command_browse_filechooser;
1c078e5
 
1c078e5
 	gtk_window_set_title (GTK_WINDOW (chooser),
1c078e5
@@ -1835,3 +1856,12 @@ panel_ditem_register_save_uri_func (Pane
adb8fd2
 	dialog->priv->save_uri = save_uri;
adb8fd2
 	dialog->priv->save_uri_data = data;
adb8fd2
 }
adb8fd2
+
adb8fd2
+G_CONST_RETURN char *
adb8fd2
+panel_ditem_editor_get_orig_desktop_file (PanelDItemEditor *dialog)
adb8fd2
+{
adb8fd2
+	g_return_val_if_fail (PANEL_IS_DITEM_EDITOR (dialog), NULL);
adb8fd2
+
adb8fd2
+	return dialog->priv->orig_desktop_file;
adb8fd2
+}
adb8fd2
+