summaryrefslogtreecommitdiffstats
path: root/desktop-file-monitoring.patch
blob: adfa5e26733d067c687e106679be7dc73415ecd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
diff -up gnome-panel-2.29.5.1/gnome-panel/launcher.c.desktop-file-monitoring gnome-panel-2.29.5.1/gnome-panel/launcher.c
--- gnome-panel-2.29.5.1/gnome-panel/launcher.c.desktop-file-monitoring	2010-01-13 22:26:27.000000000 -0500
+++ gnome-panel-2.29.5.1/gnome-panel/launcher.c	2010-01-17 18:06:14.640537280 -0500
@@ -237,6 +237,8 @@ static void
 destroy_launcher (GtkWidget *widget,
 		  Launcher  *launcher)
 {
+	if (launcher->monitor) 
+		g_object_unref (launcher->monitor);
 	launcher_properties_destroy (launcher);
 	launcher_widget_destroy_open_dialogs (launcher);
 }
@@ -410,6 +412,37 @@ drag_data_get_cb (GtkWidget        *widg
 
 }
 
+static void setup_button (Launcher *launcher);
+
+static void
+desktop_file_changed (GFileMonitor      *monitor,
+                      GFile             *file,
+                      GFile             *other_file,
+                      GFileMonitorEvent  event_type,
+		      gpointer                  user_data)
+{
+	Launcher *launcher = user_data;
+	GKeyFile *key_file;
+
+	if (event_type == G_FILE_MONITOR_EVENT_CHANGED ||
+	    event_type == G_FILE_MONITOR_EVENT_CREATED) {
+		gchar *path;
+
+		path = g_file_get_path (file);
+
+		key_file = g_key_file_new ();
+		if (g_key_file_load_from_file (key_file, path,
+					       G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
+					       NULL)) {
+			g_key_file_free (launcher->key_file);
+			launcher->key_file = key_file;
+			setup_button (launcher);        
+		}
+
+		g_free (path);
+	}
+}
+
 static Launcher *
 create_launcher (const char *location)
 {
@@ -482,6 +515,21 @@ create_launcher (const char *location)
 	launcher->key_file = key_file;
 	launcher->prop_dialog = NULL;
 	launcher->destroy_handler = 0;
+	launcher->monitor = NULL;
+
+	/* Watch for changes to the desktop file. Since we don't want 
+	 * to do this for every launcher, we only do it if the desktop 
+	 * file contains a X-Panel-Monitor entry.
+	 */
+	if (g_key_file_get_boolean (key_file, "Desktop Entry", "X-Panel-Monitor", NULL)) {
+		GFile *file;
+
+		file = g_file_new_for_path (new_location);
+		launcher->monitor = g_file_monitor_file (file, 0, NULL, NULL);
+		g_signal_connect (launcher->monitor, "changed",
+				  G_CALLBACK (desktop_file_changed), launcher);
+		g_object_unref (file);
+	}
 
 	/* Icon will be setup later */
 	launcher->button = button_widget_new (NULL /* icon */,
@@ -612,6 +660,15 @@ static void
 launcher_changed (PanelDItemEditor *dialog,
 		  Launcher         *launcher)
 {
+	/* If the user manually changes launcher properties,
+	 * we stop monitoring the desktop file to not overwrite
+	 * user changes.
+	 */
+	if (launcher->monitor) {
+		g_object_unref (launcher->monitor);
+		launcher->monitor = NULL;
+	}
+
 	/* Setup the button look */
 	setup_button (launcher);
 }
@@ -681,6 +738,42 @@ launcher_save_uri (PanelDItemEditor *dia
 	return NULL;
 }
 
+static const char *
+desktop_file_to_monitor (PanelDItemEditor *editor)
+{
+	const char *entry;
+	GKeyFile *key_file;
+
+	/* When the user selects a desktop file in the ditem editor,
+	 * start monitoring the desktop file for changes.
+	 */
+	entry = panel_ditem_editor_get_orig_desktop_file (editor);
+	if (entry) {
+		key_file = g_key_file_new ();
+		if (!g_key_file_load_from_file (key_file, entry, 0, NULL) ||
+		    !panel_key_file_get_boolean (key_file, "X-Panel-Monitor", FALSE)) 
+			entry = NULL;
+		g_key_file_free (key_file);
+	}
+
+	return entry;
+}
+
+static void
+start_monitoring (Launcher *launcher)
+{
+	GFile *file;
+
+	file = g_file_new_for_path (launcher->location);
+	if (launcher->monitor)
+		g_object_unref (launcher->monitor);
+	launcher->monitor = g_file_monitor_file (file, 0, NULL, NULL);
+	g_signal_connect (launcher->monitor, "changed",
+			  G_CALLBACK (desktop_file_changed),
+			  launcher);
+	g_object_unref (file);
+}
+ 
 static void
 launcher_saved (GtkWidget *dialog,
 		Launcher  *launcher)
@@ -688,11 +781,15 @@ launcher_saved (GtkWidget *dialog,
 	const char  *uri;
 	GConfClient *client;
 	const char  *key;
+	const char *path;
 
 	uri = panel_ditem_editor_get_uri (PANEL_DITEM_EDITOR (dialog));
 	if (panel_launcher_get_filename (uri) != NULL)
 		uri = panel_launcher_get_filename (uri);
 
+	if ((path = desktop_file_to_monitor (PANEL_DITEM_EDITOR (dialog))) != NULL)
+		uri = path;
+
 	if (uri && launcher->location && strcmp (uri, launcher->location)) {
 		client = panel_gconf_get_client ();
 
@@ -705,6 +802,9 @@ launcher_saved (GtkWidget *dialog,
 		if (launcher->location)
 			g_free (launcher->location);
 		launcher->location = g_strdup (uri);
+
+		if (path)
+			start_monitoring (launcher);
 	}
 }
 
@@ -871,6 +971,7 @@ launcher_new_saved (GtkWidget *dialog,
 	PanelWidget *panel;
 	int          pos;
 	const char  *uri;
+	const char  *path;
 
 	pos = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), "pos"));
 	panel = g_object_get_data (G_OBJECT (dialog), "panel");
@@ -878,6 +979,10 @@ launcher_new_saved (GtkWidget *dialog,
 	uri = panel_ditem_editor_get_uri (PANEL_DITEM_EDITOR (dialog));
 	if (panel_launcher_get_filename (uri) != NULL)
 		uri = panel_launcher_get_filename (uri);
+
+	if ((path = desktop_file_to_monitor (PANEL_DITEM_EDITOR (dialog))) != NULL)
+		uri = path;
+
 	panel_launcher_create (panel->toplevel, pos, uri);
 }
 
diff -up gnome-panel-2.29.5.1/gnome-panel/launcher.h.desktop-file-monitoring gnome-panel-2.29.5.1/gnome-panel/launcher.h
--- gnome-panel-2.29.5.1/gnome-panel/launcher.h.desktop-file-monitoring	2009-04-19 13:45:09.000000000 -0400
+++ gnome-panel-2.29.5.1/gnome-panel/launcher.h	2010-01-17 18:06:14.638537025 -0500
@@ -27,6 +27,8 @@ typedef struct {
 	GSList 		  *error_dialogs;
 
 	gulong             destroy_handler;
+
+	GFileMonitor      *monitor; 
 } Launcher;
 
 void panel_launcher_create           (PanelToplevel *toplevel,
@@ -56,7 +58,6 @@ void            launcher_load_from_gconf
 						 gint         position,
 						 const char  *id);
 
-void            panel_launcher_delete           (Launcher *launcher);
 
 void		ask_about_launcher		(const char *file,
 						 PanelWidget *panel,
diff -up gnome-panel-2.29.5.1/gnome-panel/panel-ditem-editor.c.desktop-file-monitoring gnome-panel-2.29.5.1/gnome-panel/panel-ditem-editor.c
--- gnome-panel-2.29.5.1/gnome-panel/panel-ditem-editor.c.desktop-file-monitoring	2010-01-17 18:06:14.635278719 -0500
+++ gnome-panel-2.29.5.1/gnome-panel/panel-ditem-editor.c	2010-01-17 18:11:39.921279627 -0500
@@ -81,6 +81,8 @@ struct _PanelDItemEditorPrivate
 	GtkWidget *close_button;
 	GtkWidget *cancel_button;
 	GtkWidget *ok_button;
+
+	char *orig_desktop_file;
 };
 
 /* Time in seconds after which we save the file on the disk */
@@ -366,6 +368,10 @@ panel_ditem_editor_destroy (GtkObject *o
 		g_free (dialog->priv->uri);
 	dialog->priv->uri = NULL;
 
+	if (dialog->priv->orig_desktop_file != NULL)
+		g_free (dialog->priv->orig_desktop_file);
+	dialog->priv->orig_desktop_file = NULL;
+
 	GTK_OBJECT_CLASS (panel_ditem_editor_parent_class)->destroy (object);
 }
 
@@ -833,6 +839,13 @@ panel_ditem_editor_changed (PanelDItemEd
 							   TRUE);
 	}
 
+	/* When the user changes any fields, unset the orig_desktop_file
+	 * field since the editor contents are not entirely from a desktop
+	 * file anymore.
+	 */ 
+	g_free (dialog->priv->orig_desktop_file);
+	dialog->priv->orig_desktop_file = NULL;
+
 	dialog->priv->dirty = TRUE;
 	g_signal_emit (G_OBJECT (dialog), ditem_edit_signals[CHANGED], 0);
 }
@@ -992,6 +1005,13 @@ update_editor_from_desktop_file (PanelDI
                 */ 
                setup_icon_chooser (dialog, icon);
 
+               /* We set the orig_desktop_file field to let the
+                * launcher know that the editor contents are coming
+                * directly from a desktop file.
+                */ 
+               g_free (dialog->priv->orig_desktop_file);
+               dialog->priv->orig_desktop_file = g_strdup (uri);
+
                g_free (name);
                g_free (comment);
                g_free (icon);
@@ -1066,6 +1086,7 @@ update_chooser_for_type (PanelDItemEdito
 		g_assert_not_reached ();
 	}
 
+
 	chooser = dialog->priv->command_browse_filechooser;
 
 	gtk_window_set_title (GTK_WINDOW (chooser),
@@ -1849,3 +1870,12 @@ panel_ditem_register_save_uri_func (Pane
 	dialog->priv->save_uri = save_uri;
 	dialog->priv->save_uri_data = data;
 }
+
+G_CONST_RETURN char *
+panel_ditem_editor_get_orig_desktop_file (PanelDItemEditor *dialog)
+{
+	g_return_val_if_fail (PANEL_IS_DITEM_EDITOR (dialog), NULL);
+
+	return dialog->priv->orig_desktop_file;
+}
+
diff -up gnome-panel-2.29.5.1/gnome-panel/panel-ditem-editor.h.desktop-file-monitoring gnome-panel-2.29.5.1/gnome-panel/panel-ditem-editor.h
--- gnome-panel-2.29.5.1/gnome-panel/panel-ditem-editor.h.desktop-file-monitoring	2009-04-19 13:45:09.000000000 -0400
+++ gnome-panel-2.29.5.1/gnome-panel/panel-ditem-editor.h	2010-01-17 18:06:14.638537025 -0500
@@ -101,6 +101,8 @@ void panel_ditem_editor_set_uri (PanelDI
 				 const char       *uri);
 
 G_CONST_RETURN char *panel_ditem_editor_get_uri (PanelDItemEditor *dialog);
+G_CONST_RETURN char *panel_ditem_editor_get_orig_desktop_file (PanelDItemEditor *dialog);
+
 
 void panel_ditem_register_save_uri_func (PanelDItemEditor  *dialog,
 					 PanelDitemSaveUri  save_uri,