[gnome-clocks/wip/vala] Port the AlarmDialog to Vala and GtkBuilder (in progress)
- From: Volker Sobek <vsobek src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks/wip/vala] Port the AlarmDialog to Vala and GtkBuilder (in progress)
- Date: Mon, 11 Feb 2013 23:03:31 +0000 (UTC)
commit 0b90528aa7655a5c1c33f90cc79a3702c656d80a
Author: Volker Sobek <reklov live com>
Date: Mon Feb 11 11:52:31 2013 +0100
Port the AlarmDialog to Vala and GtkBuilder (in progress)
src/alarm.ui | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/alarm.vala | 50 ++++++++++++------
src/widgets.vala | 41 ++++++++++++++
3 files changed, 234 insertions(+), 16 deletions(-)
---
diff --git a/src/alarm.ui b/src/alarm.ui
index 0722c9b..9b8c4df 100644
--- a/src/alarm.ui
+++ b/src/alarm.ui
@@ -1,6 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.6 -->
+ <object class="GtkAdjustment" id="h_adjustment">
+ <property name="upper">100</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
+ <object class="GtkAdjustment" id="m_adjustment">
+ <property name="upper">59</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
<object class="GtkGrid" id="ringing_panel">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -78,4 +88,153 @@
</packing>
</child>
</object>
+ <object class="GtkGrid" id="setup_dialog_content">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="row_spacing">9</property>
+ <property name="column_spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="time_labe">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Time</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="name_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Name</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="repeat_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Repeat Every</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="name_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">â</property>
+ <property name="invisible_char_set">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="time_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkSpinButton" id="h_spinbutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">â</property>
+ <property name="input_purpose">number</property>
+ <property name="adjustment">h_adjustment</property>
+ <property name="numeric">True</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="m_spinbutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">â</property>
+ <property name="input_purpose">number</property>
+ <property name="adjustment">m_adjustment</property>
+ <property name="numeric">True</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="box1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="homogeneous">True</property>
+ <style>
+ <class name="linked"/>
+ </style>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
</interface>
diff --git a/src/alarm.vala b/src/alarm.vala
index 5135972..bbf6fc6 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -199,27 +199,44 @@ private class Item : Object {
private class SetupDialog : Gtk.Dialog {
- private Gtk.Entry h_entry;
- private Gtk.Entry m_entry;
+ private Gtk.SpinButton h_spinbutton;
+ private Gtk.SpinButton m_spinbutton;
+ private AmPmToggleButton am_pm_button;
public SetupDialog (Gtk.Window parent, Item? alarm) {
Object (transient_for: parent, modal: true, title: _("New Alarm"));
- h_entry = new Gtk.Entry ();
- m_entry = new Gtk.Entry ();
-
- var content_area = get_content_area ();
- content_area.add (h_entry);
- content_area.add (m_entry);
- content_area.show_all ();
-
add_buttons (Gtk.Stock.CANCEL, 0, Gtk.Stock.SAVE, 1);
+ var builder = Utils.load_ui ("alarm.ui");
+
+ var grid = builder.get_object ("setup_dialog_content") as Gtk.Grid;
+ get_content_area ().add (grid);
+ h_spinbutton = builder.get_object ("h_spinbutton") as Gtk.SpinButton;
+ m_spinbutton = builder.get_object ("m_spinbutton") as Gtk.SpinButton;
+ am_pm_button = new AmPmToggleButton();
+ var time_entry = builder.get_object ("time_entry") as Gtk.Box;
+
+ var wc = Utils.WallClock.get_default ();
+ if (wc.format == Utils.WallClock.Format.TWENTYFOUR)
+ h_spinbutton.set_range (0,23);
+ else {
+ h_spinbutton.set_range (1,12);
+ }
+ h_spinbutton.output.connect (show_leading_zeros);
+ m_spinbutton.output.connect (show_leading_zeros);
+ time_entry.pack_end(am_pm_button);
}
- public Item get_alarm_item () {
- var h = h_entry.get_text ();
- var m = h_entry.get_text ();
- return new Item ("Alarm", true, int.parse (h), int.parse (m), null);
+ // TODO: use the spin buttons
+ // public Item get_alarm_item () {
+ // var h = h_entry.get_text ();
+ // var m = h_entry.get_text ();
+ // return new Item ("Alarm", true, int.parse (h), int.parse (m), null);
+ // }
+
+ private bool show_leading_zeros (Gtk.SpinButton spin_button) {
+ spin_button.set_text ("%02i".printf(spin_button.get_value_as_int ()));
+ return true;
}
}
@@ -324,8 +341,9 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
var dialog = new SetupDialog ((Gtk.Window) get_toplevel (), null);
dialog.response.connect ((dialog, response) => {
if (response == 1) {
- var alarm = ((SetupDialog) dialog).get_alarm_item ();
- add_alarm (alarm);
+ // TODO: uncomment when implemented
+ //var alarm = ((SetupDialog) dialog).get_alarm_item ();
+ //add_alarm (alarm);
}
dialog.destroy ();
});
diff --git a/src/widgets.vala b/src/widgets.vala
index a646a47..02901bb 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -346,4 +346,45 @@ public class ContentView : Gtk.Bin {
}
}
+public class AmPmToggleButton : Gtk.Button {
+ public enum AmPm {
+ AM,
+ PM
+ }
+
+ public AmPm choice;
+
+ private Gtk.Notebook notebook;
+ private Gtk.Label am_label;
+ private Gtk.Label pm_label;
+
+ public AmPmToggleButton () {
+ notebook = new Gtk.Notebook();
+ notebook.set_show_tabs (false);
+ // TODO: get translated AM/PM strings from the system
+ am_label = new Gtk.Label("AM");
+ pm_label = new Gtk.Label("PM");
+
+ notebook.append_page(am_label);
+ notebook.append_page(pm_label);
+ add(notebook);
+
+ choice = AmPm.AM;
+ notebook.set_current_page(0);
+ clicked.connect(toggle);
+ show_all();
+ }
+
+ public void set_choice(AmPm new_choice) {
+ if (new_choice != choice)
+ toggle();
+ }
+
+ private void toggle () {
+ choice = choice == AmPm.AM ? AmPm.PM : AmPm.AM;
+ notebook.set_current_page(choice == AmPm.AM ? 0 : 1);
+ }
+}
+
+
} // namespace Clocks
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]