diff --git a/README.md b/README.md index 1f26492..0749b7d 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,16 @@ for KDE. Then running `dbus-monitor --system` as root can be used to see the communication between the control center and this service. +Messages to the D-Bus service can also be sent with `dbus-send`. For example +to get the list of time zones: + +```sh +dbus-send --system --print-reply --type=method_call \ + --dest=org.freedesktop.timedate1 \ + /org/freedesktop/timedate1 \ + org.freedesktop.timedate1.ListTimezones +``` + ## Dependencies - glib diff --git a/data/org.freedesktop.timedate1.xml b/data/org.freedesktop.timedate1.xml index b035d10..e9010dd 100644 --- a/data/org.freedesktop.timedate1.xml +++ b/data/org.freedesktop.timedate1.xml @@ -23,5 +23,8 @@ + + + diff --git a/src/slack-timedate.cpp b/src/slack-timedate.cpp index 3f8b2d8..cc48ce8 100644 --- a/src/slack-timedate.cpp +++ b/src/slack-timedate.cpp @@ -33,18 +33,25 @@ static void slack_method_call (GDBusConnection *connection, const gchar *sender, gint64 usec_utc; // Set time zone - if (g_strcmp0 (method_name, "SetTimezone") == 0) { + if (g_strcmp0(method_name, "SetTimezone") == 0) + { g_variant_get (parameters, "(&sb)", &timezone, &user_interaction); - if (slack_set_timezone (timezone)) g_dbus_method_invocation_return_value (invocation, - NULL); - else g_dbus_method_invocation_return_error (invocation, + if (slack_set_timezone(timezone)) + { + g_dbus_method_invocation_return_value (invocation, NULL); + } + else + { + g_dbus_method_invocation_return_error (invocation, G_IO_ERROR, G_IO_ERROR_FAILED, "Write operation failed"); - + } g_free (timezone); - } else if (g_strcmp0 (method_name, "SetTime") == 0) { + } + else if (g_strcmp0(method_name, "SetTime") == 0) + { g_variant_get (parameters, "(xbb)", &usec_utc, &relative, &user_interaction); // Set time @@ -58,18 +65,31 @@ static void slack_method_call (GDBusConnection *connection, const gchar *sender, g_dbus_method_invocation_return_error(invocation, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to set system clock"); } - } else if (g_strcmp0 (method_name, "SetNTP") == 0) { + } + else if (g_strcmp0(method_name, "SetNTP") == 0) + { g_variant_get (parameters, "(bb)", &use_ntp, &user_interaction); // Enable NTP - if (slack_set_ntp (use_ntp)) g_dbus_method_invocation_return_value (invocation, - NULL); - else g_dbus_method_invocation_return_error (invocation, + if (slack_set_ntp (use_ntp)) + { + g_dbus_method_invocation_return_value (invocation, NULL); + } + else + { + g_dbus_method_invocation_return_error (invocation, G_IO_ERROR, G_IO_ERROR_FAILED, "Error enabling NTP"); + } } - return; + else if (g_strcmp0(method_name, "ListTimezones") == 0) + { + auto return_value = Glib::Variant>::create({}); + auto return_tuple = Glib::Variant>::create_tuple({ return_value }); + + g_dbus_method_invocation_return_value(invocation, return_tuple.gobj()); + } } static GVariant *slack_get_property (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *prop_name, GError **slack_err, gpointer user_data) { diff --git a/src/slack-timedate.h b/src/slack-timedate.h index 7154336..72fcc2d 100644 --- a/src/slack-timedate.h +++ b/src/slack-timedate.h @@ -48,6 +48,9 @@ " \n" \ " \n" \ " \n" \ + " \n" \ + " \n" \ + " " \ " \n" \ "\n"