summaryrefslogtreecommitdiffstats
path: root/async-timezone.patch
blob: 7a3ce7cd1c66fa3e142a2ed0c7ef38286832fcd5 (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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
--- gnome-panel-2.21.91/applets/clock/set-timezone.c	2008-02-11 16:15:51.000000000 -0500
+++ hacked/applets/clock/set-timezone.c	2008-02-18 00:49:27.000000000 -0500
@@ -91,108 +91,6 @@
 	return pk_context;
 }
 
-gboolean
-set_system_timezone (const char *filename, GError **err)
-{
-        DBusGConnection *session_bus;
-        DBusGConnection *system_bus;
-        DBusGProxy      *mechanism_proxy;
-        DBusGProxy      *polkit_gnome_proxy;
-	gboolean ret = FALSE;
-
-       	session_bus = get_session_bus ();
-        if (session_bus == NULL) 
-		goto out;
-
-        system_bus = get_system_bus ();
-        if (system_bus == NULL) 
-               	goto out;
-
-	mechanism_proxy = dbus_g_proxy_new_for_name (system_bus,
-                                                     "org.gnome.ClockApplet.Mechanism",
-                                                     "/",
-                                                     "org.gnome.ClockApplet.Mechanism");
-
-	polkit_gnome_proxy = dbus_g_proxy_new_for_name (session_bus,
-                                                        "org.gnome.PolicyKit",
-                                                        "/org/gnome/PolicyKit/Manager",
-                                                        "org.gnome.PolicyKit.Manager");
-
-        if (filename != NULL) {
-                GError *error;
-
-                g_debug ("Trying to set timezone '%s'", filename);
-        try_again:
-                error = NULL;
-                /* first, try to call into the mechanism */
-                if (!dbus_g_proxy_call_with_timeout (mechanism_proxy,
-                                                     "SetTimezone",
-                                                     INT_MAX,
-                                                     &error,
-                                                     /* parameters: */
-                                                     G_TYPE_STRING, filename,
-                                                     G_TYPE_INVALID,
-                                                     /* return values: */
-                                                     G_TYPE_INVALID)) {
-                        if (dbus_g_error_has_name (error, "org.gnome.ClockApplet.Mechanism.NotPrivileged")) {
-                                char **tokens;
-                                char *polkit_result_textual;
-                                char *polkit_action;
-                                gboolean gained_privilege;
-
-                                tokens = g_strsplit (error->message, " ", 2);
-                                g_error_free (error);                                
-                                if (g_strv_length (tokens) != 2) {
-                                        g_warning ("helper return string malformed");
-                                        g_strfreev (tokens);
-                                        goto out;
-                                }
-                                polkit_action = tokens[0];
-                                polkit_result_textual = tokens[1];
-
-                                g_debug ("helper refused; returned polkit_result='%s' and polkit_action='%s'", 
-                                         polkit_result_textual, polkit_action);
-
-                                /* Now ask the user for auth... */
-                                if (!dbus_g_proxy_call_with_timeout (polkit_gnome_proxy,
-                                                                     "ShowDialog",
-                                                                     INT_MAX,
-                                                                     &error,
-                                                                     /* parameters: */
-                                                                     G_TYPE_STRING, polkit_action,
-                                                                     G_TYPE_UINT, 0, /* X11 window ID; none */
-                                                                     G_TYPE_INVALID,
-                                                                     /* return values: */
-                                                                     G_TYPE_BOOLEAN, &gained_privilege,
-                                                                     G_TYPE_INVALID)) {
-                                        g_propagate_error (err, error);
-                                        g_strfreev (tokens);
-                                        goto out;
-                                }
-                                g_strfreev (tokens);
-
-                                if (gained_privilege) {
-                                        g_debug ("Gained privilege; trying to set timezone again");
-                                        goto try_again;
-                                }
-
-                        } else {
-                                g_propagate_error (err, error);
-                        }
-                        goto out;
-                }
-
-                g_debug ("Successfully set time zone to '%s'", filename);
-        }
-
-        ret = TRUE;
-out:
-	g_object_unref (mechanism_proxy);
-	g_object_unref (polkit_gnome_proxy);
-
-        return ret;
-}
-
 static gint
 can_do (const gchar *pk_action_id)
 {
@@ -269,7 +167,9 @@
 
 typedef struct {
 	gint ref_count;
+        gchar *call;
 	gint64 time;
+	gchar *filename;
 	GFunc callback;
 	gpointer data;
 	GDestroyNotify notify;
@@ -284,6 +184,7 @@
 	if (data->ref_count == 0) {
 		if (data->notify)
 			data->notify (data->data);
+		g_free (data->filename);
 		g_free (data);
 	}
 }
@@ -392,16 +293,28 @@
 					   "org.gnome.ClockApplet.Mechanism");
 
 	data->ref_count++;
-	dbus_g_proxy_begin_call_with_timeout (proxy, 
-					      "SetTime",
-					      set_time_notify,
-					      data, free_data,
-					      INT_MAX,
-					      /* parameters: */
-					      G_TYPE_INT64, data->time,
-					      G_TYPE_INVALID,
-					      /* return values: */
-					      G_TYPE_INVALID);
+	if (strcmp (data->call, "SetTime") == 0)
+		dbus_g_proxy_begin_call_with_timeout (proxy, 
+						      "SetTime",
+						      set_time_notify,
+						      data, free_data,
+						      INT_MAX,
+						      /* parameters: */
+						      G_TYPE_INT64, data->time,
+						      G_TYPE_INVALID,
+						      /* return values: */
+						      G_TYPE_INVALID);
+	else 
+		dbus_g_proxy_begin_call_with_timeout (proxy, 
+						      "SetTimezone",
+						      set_time_notify,
+						      data, free_data,
+						      INT_MAX,
+						      /* parameters: */
+						      G_TYPE_STRING, data->filename,
+						      G_TYPE_INVALID,
+						      /* return values: */
+						      G_TYPE_INVALID);
 }
 
 void
@@ -417,7 +330,33 @@
 
 	data = g_new (SetTimeCallbackData, 1);
 	data->ref_count = 1;
+	data->call = "SetTime";
 	data->time = time;
+	data->filename = NULL;
+	data->callback = callback;
+	data->data = d;
+	data->notify = notify;
+
+	set_time_async (data);
+	free_data (data);
+}
+
+void
+set_system_timezone_async (const gchar    *filename,
+	             	   GFunc           callback, 
+		           gpointer        d, 
+		           GDestroyNotify  notify)
+{
+	SetTimeCallbackData *data;
+
+	if (filename == NULL)
+		return;
+
+	data = g_new (SetTimeCallbackData, 1);
+	data->ref_count = 1;
+	data->call = "SetTimezone";
+	data->time = -1;
+	data->filename = g_strdup (filename);
 	data->callback = callback;
 	data->data = d;
 	data->notify = notify;
--- gnome-panel-2.21.91/applets/clock/set-timezone.h	2008-02-11 16:15:51.000000000 -0500
+++ hacked/applets/clock/set-timezone.h	2008-02-18 00:48:40.000000000 -0500
@@ -23,8 +23,6 @@
 #include <glib.h>
 #include <time.h>
 
-gboolean set_system_timezone     (const char  *filename, 
-                                  GError     **err);
 gint     can_set_system_timezone (void);
 
 gint     can_set_system_time     (void);
@@ -34,4 +32,9 @@
                                   gpointer       data,
                                   GDestroyNotify notify);
 
+void     set_system_timezone_async   (const gchar    *filename,
+                                      GFunc           callback,
+                                      gpointer        data,
+                                      GDestroyNotify  notify);
+
 #endif
--- gnome-panel-2.21.91/applets/clock/clock-location.h	2008-02-11 16:15:51.000000000 -0500
+++ hacked/applets/clock/clock-location.h	2008-02-18 00:11:57.000000000 -0500
@@ -52,7 +52,10 @@
 void clock_location_localtime (ClockLocation *loc, struct tm *tm);
 
 gboolean clock_location_is_current (ClockLocation *loc);
-gboolean clock_location_make_current (ClockLocation *loc, GError **error);
+void clock_location_make_current (ClockLocation *loc, 
+				  GFunc          callback,
+				  gpointer       data,
+				  GDestroyNotify destroy);
 
 const gchar *clock_location_get_weather_code (ClockLocation *loc);
 void         clock_location_set_weather_code (ClockLocation *loc, const gchar *code);
--- gnome-panel-2.21.91/applets/clock/clock-location.c	2008-02-11 16:15:51.000000000 -0500
+++ hacked/applets/clock/clock-location.c	2008-02-18 00:50:53.000000000 -0500
@@ -667,18 +667,20 @@
         return offset;
 }
 
-gboolean
-clock_location_make_current (ClockLocation *loc, GError **error)
-{
-        ClockLocationPrivate *priv = PRIVATE (loc);
-        gchar *filename;
-        gboolean ret;
+typedef struct {
+	ClockLocation *location;
+	GFunc callback;
+	gpointer data;
+	GDestroyNotify destroy;
+} MakeCurrentData;
 
-        filename = g_build_filename (SYSTEM_ZONEINFODIR, priv->timezone, NULL);
-        ret = set_system_timezone (filename, error);
-        g_free (filename);
+static void
+make_current_cb (gpointer data, GError *error)
+{
+	MakeCurrentData *mcdata = data;
+        ClockLocationPrivate *priv = PRIVATE (mcdata->location);
 
-	if (ret) {
+	if (error == NULL) {
 		/* FIXME this ugly shortcut is necessary until we move the
  	  	 * current timezone tracking to clock.c and emit the
  	 	 * signal from there
@@ -687,7 +689,47 @@
 		current_zone = g_strdup (priv->timezone);
 	}
 
-        return ret;
+	if (mcdata->callback)
+		mcdata->callback (mcdata->data, error);
+	else
+		g_error_free (error);
+}
+
+static void
+free_make_current_data (gpointer data)
+{
+	MakeCurrentData *mcdata = data;
+	
+	if (mcdata->destroy)
+		mcdata->destroy (mcdata->data);
+	
+	g_object_unref (mcdata->location);
+	g_free (mcdata);
+}
+
+void
+clock_location_make_current (ClockLocation *loc, 
+                             GFunc          callback,
+                             gpointer       data,
+                             GDestroyNotify destroy)
+{
+        ClockLocationPrivate *priv = PRIVATE (loc);
+        gchar *filename;
+	MakeCurrentData *mcdata;
+
+	mcdata = g_new (MakeCurrentData, 1);
+
+	mcdata->location = g_object_ref (loc);
+	mcdata->callback = callback;
+	mcdata->data = data;
+	mcdata->destroy = destroy;
+
+        filename = g_build_filename (SYSTEM_ZONEINFODIR, priv->timezone, NULL);
+        set_system_timezone_async (filename, 
+                                   (GFunc)make_current_cb, 
+				   mcdata,
+                                   free_make_current_data);
+        g_free (filename);
 }
 
 const gchar *
--- gnome-panel-2.21.91/applets/clock/clock-location-tile.c	2008-02-18 01:08:29.000000000 -0500
+++ hacked/applets/clock/clock-location-tile.c	2008-02-18 01:10:17.000000000 -0500
@@ -104,7 +104,7 @@
 					      NULL,
 					      g_cclosure_marshal_VOID__VOID,
 					      G_TYPE_NONE, 0);
-	signals[TILE_PRESSED] = g_signal_new ("timezone-set",
+	signals[TIMEZONE_SET] = g_signal_new ("timezone-set",
 					      G_TYPE_FROM_CLASS (g_obj_class),
 					      G_SIGNAL_RUN_FIRST,
 					      G_STRUCT_OFFSET (ClockLocationTileClass, timezone_set),
@@ -171,16 +171,15 @@
 }
 
 static void
-make_current (GtkWidget *widget, ClockLocationTile *tile)
+make_current_cb (gpointer data, GError *error)
 {
-        ClockLocationTilePrivate *priv = PRIVATE (tile);
-        GError *error = NULL;
-        GtkWidget *dialog;
+	ClockLocationTile *tile = data;
+	GtkWidget *dialog;
 
-        if (clock_location_make_current (priv->location, &error)) {
+        if (error == NULL) {
 		g_signal_emit (tile, signals[TIMEZONE_SET], 0);
         }
-        else if (error) {
+        else {
                 dialog = gtk_message_dialog_new (NULL,
                                                  0,
                                                  GTK_MESSAGE_ERROR,
@@ -195,6 +194,15 @@
         }
 }
 
+static void
+make_current (GtkWidget *widget, ClockLocationTile *tile)
+{
+        ClockLocationTilePrivate *priv = PRIVATE (tile);
+
+	clock_location_make_current (priv->location, 
+				     (GFunc)make_current_cb, tile, NULL);
+}
+
 static gboolean
 enter_or_leave_tile (GtkWidget             *widget,
                      GdkEventCrossing      *event,