aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/datetime-dialog.ui546
-rw-r--r--src/datetime-prefs.c158
2 files changed, 394 insertions, 310 deletions
diff --git a/data/datetime-dialog.ui b/data/datetime-dialog.ui
index f2a5938..1e0f726 100644
--- a/data/datetime-dialog.ui
+++ b/data/datetime-dialog.ui
@@ -88,6 +88,7 @@
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Time &amp; Date</property>
+ <property name="resizable">False</property>
<property name="icon_name">time-admin</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
@@ -264,6 +265,7 @@
<object class="GtkRadioButton" id="automaticTimeRadio">
<property name="label" translatable="yes">_Automatically from the Internet</property>
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
@@ -429,139 +431,27 @@
</packing>
</child>
<child>
- <object class="GtkVBox" id="clockBox">
+ <object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="border_width">12</property>
- <property name="spacing">12</property>
- <child>
- <object class="GtkCheckButton" id="showClockCheck">
- <property name="label" translatable="yes">_Show a clock in the panel</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
- <property name="xalign">0</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
+ <property name="yalign">0</property>
+ <property name="yscale">0</property>
<child>
- <object class="GtkHBox" id="clockOptions">
+ <object class="GtkVBox" id="clockBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="homogeneous">True</property>
+ <property name="border_width">12</property>
+ <property name="spacing">12</property>
<child>
- <object class="GtkVBox" id="vbox2">
+ <object class="GtkCheckButton" id="showClockCheck">
+ <property name="label" translatable="yes">_Show a clock in the panel</property>
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkLabel" id="label3">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">In the clock, show:</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="showWeekdayCheck">
- <property name="label" translatable="yes">_Weekday</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
- <property name="xalign">0</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="showDateTimeCheck">
- <property name="label" translatable="yes">_Date and time</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
- <property name="xalign">0</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkRadioButton" id="show12HourRadio">
- <property name="label" translatable="yes">_12-hour time</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
- <property name="xalign">0</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">3</property>
- </packing>
- </child>
- <child>
- <object class="GtkRadioButton" id="show24HourRadio">
- <property name="label" translatable="yes">_24-hour time</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
- <property name="xalign">0</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
- <property name="group">show12HourRadio</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">4</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="showSecondsCheck">
- <property name="label" translatable="yes">Seco_nds</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
- <property name="xalign">0</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">5</property>
- </packing>
- </child>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">True</property>
@@ -570,16 +460,115 @@
</packing>
</child>
<child>
- <object class="GtkVBox" id="vbox3">
+ <object class="GtkHBox" id="clockOptions">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="spacing">6</property>
+ <property name="homogeneous">True</property>
<child>
- <object class="GtkLabel" id="label4">
+ <object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">In the clock’s menu, show:</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">In the clock, show:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="showWeekdayCheck">
+ <property name="label" translatable="yes">_Weekday</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="showDateTimeCheck">
+ <property name="label" translatable="yes">_Date and time</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="show12HourRadio">
+ <property name="label" translatable="yes">_12-hour time</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="show24HourRadio">
+ <property name="label" translatable="yes">_24-hour time</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">show12HourRadio</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="showSecondsCheck">
+ <property name="label" translatable="yes">Seco_nds</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">5</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">True</property>
@@ -588,80 +577,62 @@
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="showCalendarCheck">
- <property name="label" translatable="yes">_Monthly calendar</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
- <property name="xalign">0</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkAlignment" id="calendarOptions">
+ <object class="GtkVBox" id="vbox3">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="yalign">0</property>
- <property name="xscale">0</property>
- <property name="yscale">0</property>
- <property name="left_padding">12</property>
+ <property name="spacing">6</property>
<child>
- <object class="GtkVBox" id="vbox4">
+ <object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">In the clock’s menu, show:</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="showCalendarCheck">
+ <property name="label" translatable="yes">_Monthly calendar</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="calendarOptions">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0</property>
+ <property name="xscale">0</property>
+ <property name="yscale">0</property>
+ <property name="left_padding">12</property>
<child>
- <object class="GtkCheckButton" id="includeWeekNumbersCheck">
- <property name="label" translatable="yes">Include week num_bers</property>
+ <object class="GtkVBox" id="vbox4">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
- <property name="xalign">0</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label5">
- <property name="can_focus">False</property>
- <property name="no_show_all">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Week begins on:</property>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkHBox" id="hbox3">
<property name="can_focus">False</property>
- <property name="no_show_all">True</property>
- <property name="homogeneous">True</property>
<child>
- <object class="GtkRadioButton" id="startOnSundayRadio">
- <property name="label" translatable="yes">S_unday</property>
+ <object class="GtkCheckButton" id="includeWeekNumbersCheck">
+ <property name="label" translatable="yes">Include week num_bers</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
- <property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
@@ -671,17 +642,11 @@
</packing>
</child>
<child>
- <object class="GtkRadioButton" id="startOnMondayRadio">
- <property name="label" translatable="yes">Monda_y</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
+ <object class="GtkLabel" id="label5">
+ <property name="can_focus">False</property>
+ <property name="no_show_all">True</property>
<property name="xalign">0</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
- <property name="group">startOnSundayRadio</property>
+ <property name="label" translatable="yes">Week begins on:</property>
</object>
<packing>
<property name="expand">True</property>
@@ -689,91 +654,139 @@
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkHBox" id="hbox3">
+ <property name="can_focus">False</property>
+ <property name="no_show_all">True</property>
+ <property name="homogeneous">True</property>
+ <child>
+ <object class="GtkRadioButton" id="startOnSundayRadio">
+ <property name="label" translatable="yes">S_unday</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="startOnMondayRadio">
+ <property name="label" translatable="yes">Monda_y</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">startOnSundayRadio</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">2</property>
- </packing>
</child>
</object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
</child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="showEventsCheck">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
- <property name="xalign">0</property>
- <property name="draw_indicator">True</property>
<child>
- <object class="GtkLabel" id="label12">
+ <object class="GtkCheckButton" id="showEventsCheck">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Coming _events from Evolution Calendar</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
- <property name="wrap">True</property>
- <property name="mnemonic_widget">showEventsCheck</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <child>
+ <object class="GtkLabel" id="label12">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Coming _events from Evolution Calendar</property>
+ <property name="use_underline">True</property>
+ <property name="wrap">True</property>
+ <property name="mnemonic_widget">showEventsCheck</property>
+ </object>
+ </child>
</object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
</child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">3</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="showLocationsCheck">
- <property name="label" translatable="yes">Time in _other locations</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
- <property name="xalign">0</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">4</property>
- </packing>
- </child>
- <child>
- <object class="GtkAlignment" id="alignment2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="yalign">0</property>
- <property name="xscale">0</property>
- <property name="yscale">0</property>
- <property name="left_padding">12</property>
<child>
- <object class="GtkButton" id="locationsButton">
- <property name="label" translatable="yes">Choose _Locations…</property>
+ <object class="GtkCheckButton" id="showLocationsCheck">
+ <property name="label" translatable="yes">Time in _other locations</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="alignment2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0</property>
+ <property name="xscale">0</property>
+ <property name="yscale">0</property>
+ <property name="left_padding">12</property>
+ <child>
+ <object class="GtkButton" id="locationsButton">
+ <property name="label" translatable="yes">Choose _Locations…</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ </object>
+ </child>
</object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">5</property>
+ </packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">5</property>
+ <property name="position">1</property>
</packing>
</child>
</object>
@@ -784,11 +797,6 @@
</packing>
</child>
</object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
</child>
</object>
<packing>
diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c
index 87eec94..a42c46b 100644
--- a/src/datetime-prefs.c
+++ b/src/datetime-prefs.c
@@ -27,6 +27,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <libintl.h>
#include <locale.h>
+#include <langinfo.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <unique/unique.h>
@@ -37,6 +38,8 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#define DATETIME_DIALOG_UI_FILE PKGDATADIR "/datetime-dialog.ui"
+GDBusProxy * proxy = NULL;
+
/* Turns the boolean property into a string gsettings */
static GVariant *
bind_hours_set (const GValue * value, const GVariantType * type, gpointer user_data)
@@ -116,14 +119,13 @@ add_polkit_dependency (GtkWidget * parent, GtkWidget * dependent)
polkit_dependency_cb (parent, NULL, dependent);
}
-void ntp_set_answered (GObject *object, GAsyncResult *res, gpointer autoRadio)
+void dbus_set_answered (GObject *object, GAsyncResult *res, gpointer command)
{
GError * error = NULL;
- GDBusProxy * proxy = G_DBUS_PROXY (object);
GVariant * answers = g_dbus_proxy_call_finish (proxy, res, &error);
if (error != NULL) {
- g_warning("Could not set 'using_ntp' for SettingsDaemon: %s", error->message);
+ g_warning("Could not set '%s' for SettingsDaemon: %s", (gchar *)command, error->message);
g_error_free(error);
return;
}
@@ -135,16 +137,14 @@ static void
toggle_ntp (GtkWidget * autoRadio, GParamSpec * pspec, gpointer user_data)
{
gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (autoRadio));
- GDBusProxy * proxy = G_DBUS_PROXY (g_object_get_data (G_OBJECT (autoRadio), "proxy"));
g_dbus_proxy_call (proxy, "SetUsingNtp", g_variant_new ("(b)", active),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, ntp_set_answered, autoRadio);
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, dbus_set_answered, "using_ntp");
}
void ntp_query_answered (GObject *object, GAsyncResult *res, gpointer autoRadio)
{
GError * error = NULL;
- GDBusProxy * proxy = G_DBUS_PROXY (object);
GVariant * answers = g_dbus_proxy_call_finish (proxy, res, &error);
if (error != NULL) {
@@ -164,10 +164,11 @@ void ntp_query_answered (GObject *object, GAsyncResult *res, gpointer autoRadio)
g_variant_unref (answers);
}
-void ntp_proxy_ready (GObject *object, GAsyncResult *res, gpointer autoRadio)
+void proxy_ready (GObject *object, GAsyncResult *res, gpointer autoRadio)
{
GError * error = NULL;
- GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
+
+ proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
if (error != NULL) {
g_critical("Could not grab DBus proxy for SettingsDaemon: %s", error->message);
@@ -175,48 +176,117 @@ void ntp_proxy_ready (GObject *object, GAsyncResult *res, gpointer autoRadio)
return;
}
- /* Now attach proxy to button so we can use it later */
- g_object_set_data_full (G_OBJECT (autoRadio), "proxy", proxy, g_object_unref);
-
- /* And finally ask it what is up */
+ /* And now, do initial proxy configuration */
g_dbus_proxy_call (proxy, "GetUsingNtp", NULL, G_DBUS_CALL_FLAGS_NONE, -1,
NULL, ntp_query_answered, autoRadio);
}
-static void
-setup_ntp (GtkWidget * autoRadio)
+static int
+input_time_text (GtkWidget * spinner, gdouble *value, gpointer user_data)
{
- /* Do some quick checks to see if ntp is running or installed */
+ gboolean is_time = (gboolean)GPOINTER_TO_INT (g_object_get_data (G_OBJECT (spinner), "is-time"));
+ const gchar * text = gtk_entry_get_text (GTK_ENTRY (spinner));
+
+ GDateTime * now = g_date_time_new_now_local ();
+ gint year, month, day, hour, minute, second;
+ year = g_date_time_get_year (now);
+ month = g_date_time_get_month (now);
+ day = g_date_time_get_day_of_month (now);
+ hour = g_date_time_get_hour (now);
+ minute = g_date_time_get_minute (now);
+ second = g_date_time_get_second (now);
+ g_date_time_unref (now);
+
+ /* Parse this string as if it were in the output format */
+ gint scanned = 0;
+ gboolean passed = TRUE, skip = FALSE;
+ if (is_time) {
+ gint hour_in, minute_in, second_in;
+
+ if (is_locale_12h ()) { // TODO: make this look-at/watch gsettings?
+ char ampm[51];
+
+ scanned = sscanf (text, "%u:%u:%u %50s", &hour_in, &minute_in, &second_in, ampm);
+ passed = (scanned == 4);
+
+ if (passed) {
+ const char *pm_str = nl_langinfo (PM_STR);
+ if (g_ascii_strcasecmp (pm_str, ampm) == 0) {
+ hour_in += 12;
+ }
+ }
+ } else {
+ scanned = sscanf (text, "%u:%u:%u", &hour_in, &minute_in, &second_in);
+ passed = (scanned == 3);
+ }
+
+ if (passed && (hour_in > 23 || minute_in > 59 || second_in > 59)) {
+ passed = FALSE;
+ }
+ if (passed && hour == hour_in && minute == minute_in && second == second_in) {
+ skip = TRUE; // no change
+ } else {
+ hour = hour_in;
+ minute = minute_in;
+ second = second_in;
+ }
+ }
+ else {
+ gint year_in, month_in, day_in;
+
+ scanned = sscanf (text, "%u-%u-%u", &year_in, &month_in, &day_in);
+
+ if (scanned != 3 || year_in < 1 || year_in > 9999 ||
+ month_in < 1 || month_in > 12 || day_in < 1 || day_in > 31) {
+ passed = FALSE;
+ }
+ if (passed && year == year_in && month == month_in && day == day_in) {
+ skip = TRUE; // no change
+ } else {
+ year = year_in;
+ month = month_in;
+ day = day_in;
+ }
+ }
- /* Start with assumption ntp is unusable until we prove otherwise */
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (autoRadio), FALSE);
- gtk_widget_set_sensitive (autoRadio, FALSE);
+ if (!passed) {
+ g_warning ("Could not understand %s", text);
+ return TRUE;
+ }
- g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
- "org.gnome.SettingsDaemon.DateTimeMechanism",
- "/",
- "org.gnome.SettingsDaemon.DateTimeMechanism",
- NULL, ntp_proxy_ready, autoRadio);
-}
+ if (skip) {
+ return TRUE;
+ }
-/*static int
-input_time_text (GtkWidget * spinner, gdouble *value, gpointer user_data)
-{
- //const gchar * text = gtk_entry_get_text (GTK_ENTRY (spinner));
+ GDateTime * datetime = g_date_time_new_local (year, month, day, hour, minute, second);
+
+ g_dbus_proxy_call (proxy, "SetTime", g_variant_new ("(x)", g_date_time_to_unix (datetime)),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, dbus_set_answered, "time");
return TRUE;
-}*/
+}
static gboolean
format_time_text (GtkWidget * spinner, gpointer user_data)
{
+ if (gtk_widget_has_focus (spinner)) {
+ /* Don't do anything if we have focus, user is likely editing us */
+ return TRUE;
+ }
+
GDateTime * datetime = (GDateTime *)g_object_get_data (G_OBJECT (spinner), "datetime");
+ gboolean is_time = (gboolean)GPOINTER_TO_INT (g_object_get_data (G_OBJECT (spinner), "is-time"));
const gchar * format;
- if (is_locale_12h ()) {
- format = "%I:%M:%S %p";
- } else {
- format = "%H:%M:%S";
+ if (is_time) {
+ if (is_locale_12h ()) { // TODO: make this look-at/watch gsettings?
+ format = "%I:%M:%S %p";
+ } else {
+ format = "%H:%M:%S";
+ }
+ }
+ else {
+ format = "%Y-%m-%d";
}
gchar * formatted = g_date_time_format (datetime, format);
@@ -239,16 +309,17 @@ update_spinner (GtkWidget * spinner)
}
static void
-setup_time_spinner (GtkWidget * spinner)
+setup_time_spinner (GtkWidget * spinner, GtkWidget * other, gboolean is_time)
{
/* Set up spinner to have reasonable behavior */
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinner), FALSE);
- //g_signal_connect (spinner, "input", G_CALLBACK (input_time_text), NULL);
- g_signal_connect (spinner, "output", G_CALLBACK (format_time_text), NULL);
+ g_signal_connect (spinner, "input", G_CALLBACK (input_time_text), other);
+ g_signal_connect (spinner, "output", G_CALLBACK (format_time_text), other);
+ g_object_set_data (G_OBJECT (spinner), "is-time", GINT_TO_POINTER (is_time));
/* 2 seconds is what the indicator itself uses */
guint time_id = g_timeout_add_seconds (2, (GSourceFunc)update_spinner, spinner);
- g_signal_connect_swapped (spinner, "destroy", G_CALLBACK (g_source_remove), GINT_TO_POINTER(time_id));
+ g_signal_connect_swapped (spinner, "destroy", G_CALLBACK (g_source_remove), GINT_TO_POINTER (time_id));
update_spinner (spinner);
}
@@ -322,13 +393,18 @@ create_dialog (void)
gtk_widget_set_sensitive (WIG ("showEventsCheck"), (evo_path != NULL));
g_free (evo_path);
- /* Check if ntp is usable and enabled */
- setup_ntp (WIG ("automaticTimeRadio"));
-
- setup_time_spinner (WIG ("timeSpinner"));
+ setup_time_spinner (WIG ("timeSpinner"), WIG ("dateSpinner"), TRUE);
+ setup_time_spinner (WIG ("dateSpinner"), WIG ("timeSpinner"), FALSE);
GtkWidget * dlg = WIG ("timeDateDialog");
+ /* Grab proxy for settings daemon */
+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
+ "org.gnome.SettingsDaemon.DateTimeMechanism",
+ "/",
+ "org.gnome.SettingsDaemon.DateTimeMechanism",
+ NULL, proxy_ready, WIG ("automaticTimeRadio"));
+
#undef WIG
g_object_unref (conf);