gnome-panel r10850 - trunk/applets/clock
- From: matthiasc svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-panel r10850 - trunk/applets/clock
- Date: Tue, 19 Feb 2008 01:58:03 +0000 (GMT)
Author: matthiasc
Date: Tue Feb 19 01:58:02 2008
New Revision: 10850
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=10850&view=rev
Log:
2008-02-18 Matthias Clasen <mclasen redhat com>
Set timezones asynchronously. This keeps the clock ticking
while the auth dialog is up.
* set-timezone.[hc]: Replace the synchronous set_timezone call
by an asynchronous version, reusing the async machinery for the
set_time call.
* clock-location.[hc]: Do the same for the
clock_location_make_current call.
* clock-location-tile.c: Use async call to set the timezone.
Modified:
trunk/applets/clock/ChangeLog
trunk/applets/clock/clock-location-tile.c
trunk/applets/clock/clock-location.c
trunk/applets/clock/clock-location.h
trunk/applets/clock/set-timezone.c
trunk/applets/clock/set-timezone.h
Modified: trunk/applets/clock/clock-location-tile.c
==============================================================================
--- trunk/applets/clock/clock-location-tile.c (original)
+++ trunk/applets/clock/clock-location-tile.c Tue Feb 19 01:58:02 2008
@@ -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,
Modified: trunk/applets/clock/clock-location.c
==============================================================================
--- trunk/applets/clock/clock-location.c (original)
+++ trunk/applets/clock/clock-location.c Tue Feb 19 01:58:02 2008
@@ -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 *
Modified: trunk/applets/clock/clock-location.h
==============================================================================
--- trunk/applets/clock/clock-location.h (original)
+++ trunk/applets/clock/clock-location.h Tue Feb 19 01:58:02 2008
@@ -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);
Modified: trunk/applets/clock/set-timezone.c
==============================================================================
--- trunk/applets/clock/set-timezone.c (original)
+++ trunk/applets/clock/set-timezone.c Tue Feb 19 01:58:02 2008
@@ -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;
Modified: trunk/applets/clock/set-timezone.h
==============================================================================
--- trunk/applets/clock/set-timezone.h (original)
+++ trunk/applets/clock/set-timezone.h Tue Feb 19 01:58:02 2008
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]