[gnome-settings-daemon] datetime: Add SetDate() function
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] datetime: Add SetDate() function
- Date: Wed, 8 Dec 2010 17:18:37 +0000 (UTC)
commit 9d94407a885f640df2aaf1b72b4b50f5907c5309
Author: Bastien Nocera <hadess hadess net>
Date: Wed Dec 8 17:17:34 2010 +0000
datetime: Add SetDate() function
So that we can set the date separately from setting the time.
Setting the time is actually easier for us, as it's just an
offset compared to the current time.
plugins/datetime/gsd-datetime-mechanism.c | 66 ++++++++++++++++++++++++++-
plugins/datetime/gsd-datetime-mechanism.h | 6 +++
plugins/datetime/gsd-datetime-mechanism.xml | 6 +++
3 files changed, 77 insertions(+), 1 deletions(-)
---
diff --git a/plugins/datetime/gsd-datetime-mechanism.c b/plugins/datetime/gsd-datetime-mechanism.c
index 8e2f852..2959e39 100644
--- a/plugins/datetime/gsd-datetime-mechanism.c
+++ b/plugins/datetime/gsd-datetime-mechanism.c
@@ -335,6 +335,57 @@ _set_time (GsdDatetimeMechanism *mechanism,
}
static gboolean
+_set_date (GsdDatetimeMechanism *mechanism,
+ guint day,
+ guint month,
+ guint year,
+ DBusGMethodInvocation *context)
+{
+ GDateTime *time;
+ char *date_str, *time_str;
+ char *date_cmd;
+ int exit_status;
+ GError *error;
+
+ date_str = g_strdup_printf ("%02d/%02d/%d", month, day, year);
+ error = NULL;
+
+ time = g_date_time_new_now_local ();
+ time_str = g_date_time_format (time, "%R:%S");
+ g_date_time_unref (time);
+
+ date_cmd = g_strdup_printf ("/bin/date -s \"%s %s\" +\"%%D %%R:%%S\"", date_str, time_str);
+ g_free (date_str);
+ g_free (time_str);
+
+ if (!g_spawn_command_line_sync (date_cmd, NULL, NULL, &exit_status, &error)) {
+ GError *error2;
+ error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
+ GSD_DATETIME_MECHANISM_ERROR_GENERAL,
+ "Error spawning /bin/date: %s", error->message);
+ g_error_free (error);
+ dbus_g_method_return_error (context, error2);
+ g_error_free (error2);
+ g_free (date_cmd);
+ return FALSE;
+ }
+ g_free (date_cmd);
+ if (WEXITSTATUS (exit_status) != 0) {
+ error = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
+ GSD_DATETIME_MECHANISM_ERROR_GENERAL,
+ "/bin/date returned %d", exit_status);
+ dbus_g_method_return_error (context, error);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ if (!_sync_hwclock (context))
+ return FALSE;
+
+ return TRUE;
+}
+
+static gboolean
_rh_update_etc_sysconfig_clock (DBusGMethodInvocation *context, const char *key, const char *value)
{
/* On Red Hat / Fedora, the /etc/sysconfig/clock file needs to be kept in sync */
@@ -417,6 +468,19 @@ gsd_datetime_mechanism_set_time (GsdDatetimeMechanism *mechanism,
}
gboolean
+gsd_datetime_mechanism_set_date (GsdDatetimeMechanism *mechanism,
+ guint day,
+ guint month,
+ guint year,
+ DBusGMethodInvocation *context)
+{
+ reset_killtimer ();
+ g_debug ("SetDate(%d, %d, %d) called", day, month, year);
+
+ return _set_date (mechanism, day, month, year, context);
+}
+
+gboolean
gsd_datetime_mechanism_adjust_time (GsdDatetimeMechanism *mechanism,
gint64 seconds_to_add,
DBusGMethodInvocation *context)
@@ -437,7 +501,7 @@ gsd_datetime_mechanism_adjust_time (GsdDatetimeMechanism *mechanism,
}
tv.tv_sec += (time_t) seconds_to_add;
- return _set_time (mechanism, &tv, context);
+ return _set_time (mechanism, &tv, context);
}
static gboolean
diff --git a/plugins/datetime/gsd-datetime-mechanism.h b/plugins/datetime/gsd-datetime-mechanism.h
index 0c192af..13ca212 100644
--- a/plugins/datetime/gsd-datetime-mechanism.h
+++ b/plugins/datetime/gsd-datetime-mechanism.h
@@ -78,6 +78,12 @@ gboolean gsd_datetime_mechanism_set_time (GsdDatetimeMechanism *
gint64 seconds_since_epoch,
DBusGMethodInvocation *context);
+gboolean gsd_datetime_mechanism_set_date (GsdDatetimeMechanism *mechanism,
+ guint day,
+ guint month,
+ guint year,
+ DBusGMethodInvocation *context);
+
gboolean gsd_datetime_mechanism_can_set_time (GsdDatetimeMechanism *mechanism,
DBusGMethodInvocation *context);
diff --git a/plugins/datetime/gsd-datetime-mechanism.xml b/plugins/datetime/gsd-datetime-mechanism.xml
index 2420e79..8ac37f9 100644
--- a/plugins/datetime/gsd-datetime-mechanism.xml
+++ b/plugins/datetime/gsd-datetime-mechanism.xml
@@ -38,6 +38,12 @@
</doc:doc>
</arg>
</method>
+ <method name="SetDate">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <arg name="day" direction="in" type="u"/>
+ <arg name="month" direction="in" type="u"/>
+ <arg name="year" direction="in" type="u"/>
+ </method>
<method name="SetTime">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="seconds_since_epoch" direction="in" type="x"/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]