datetime: add a function to retrieve current timezone from dbus

Add get_system_timezone_async function to request the current timezone from
the SettingsDaemon.DateTimeMechanism dbus object.
This commit is contained in:
Thomas Wood 2010-06-28 17:48:47 +01:00
parent 8db6536da9
commit 8174f22fe7
2 changed files with 99 additions and 0 deletions

View file

@ -289,3 +289,85 @@ set_system_timezone_async (const gchar *filename,
set_time_async (data);
free_data (data);
}
/* get timezone */
typedef struct
{
GetTimezoneFunc callback;
GDestroyNotify notify;
gpointer data;
} GetTimezoneData;
static void
get_timezone_destroy_notify (GetTimezoneData *data)
{
if (data->notify && data->data)
data->notify (data);
g_free (data);
}
static void
get_timezone_notify (DBusGProxy *proxy,
DBusGProxyCall *call,
void *user_data)
{
GError *error = NULL;
gboolean retval;
gchar *string = NULL;
GetTimezoneData *data = user_data;
retval = dbus_g_proxy_end_call (proxy, call, &error,
G_TYPE_STRING, &string,
G_TYPE_INVALID);
if (data->callback) {
if (!retval) {
data->callback (data->data, NULL, error);
g_error_free (error);
}
else {
data->callback (data->data, string, NULL);
g_free (string);
}
}
}
void
get_system_timezone_async (GetTimezoneFunc callback,
gpointer user_data,
GDestroyNotify notify)
{
DBusGConnection *bus;
DBusGProxy *proxy;
GetTimezoneData *data;
bus = get_system_bus ();
if (bus == NULL)
return;
data = g_new0 (GetTimezoneData, 1);
data->data = user_data;
data->notify = notify;
data->callback = callback;
proxy = dbus_g_proxy_new_for_name (bus,
"org.gnome.SettingsDaemon.DateTimeMechanism",
"/",
"org.gnome.SettingsDaemon.DateTimeMechanism");
dbus_g_proxy_begin_call (proxy,
"GetTimezone",
get_timezone_notify,
data,
(GDestroyNotify) get_timezone_destroy_notify,
/* parameters: */
G_TYPE_INVALID,
/* return values: */
G_TYPE_STRING,
G_TYPE_INVALID);
}

View file

@ -20,9 +20,18 @@
#ifndef __SET_SYSTEM_TIMEZONE_H__
#include <config.h>
#include <glib.h>
#include <time.h>
typedef void (*GetTimezoneFunc) (gpointer data,
const gchar *timezone,
GError *error);
void get_system_timezone_async (GetTimezoneFunc callback,
gpointer data,
GDestroyNotify notify);
gint can_set_system_timezone (void);
gint can_set_system_time (void);
@ -37,4 +46,12 @@ void set_system_timezone_async (const gchar *filename,
gpointer data,
GDestroyNotify notify);
#ifdef HAVE_SOLARIS
#define SYSTEM_ZONEINFODIR "/usr/share/lib/zoneinfo/tab"
#else
#define SYSTEM_ZONEINFODIR "/usr/share/zoneinfo"
#endif
#endif