summaryrefslogtreecommitdiff
path: root/src/contacts-contact-editor.vala
diff options
context:
space:
mode:
authorErick Pérez Castellanos <erick.red@gmail.com>2014-05-30 09:00:31 -0400
committerErick Pérez Castellanos <erick.red@gmail.com>2014-05-30 09:00:31 -0400
commit13ff0d01a259e1411ba7fe399a21ec90be6757f1 (patch)
tree816dc835801f9bf7e1155faa60d53c6da077c1e1 /src/contacts-contact-editor.vala
parent963647ad3bbb627da65c5514fd7ca5f7fe351281 (diff)
downloadgnome-contacts-13ff0d01a259e1411ba7fe399a21ec90be6757f1.tar.gz
ContactEditor: improved showing of birthday fields
Added year field to birthday Added constraints to prevent from non-sense dates Fixed: https://bugzilla.gnome.org/show_bug.cgi?id=690137 Fixed: https://bugzilla.gnome.org/show_bug.cgi?id=701708
Diffstat (limited to 'src/contacts-contact-editor.vala')
-rw-r--r--src/contacts-contact-editor.vala37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/contacts-contact-editor.vala b/src/contacts-contact-editor.vala
index 86de95d..8314086 100644
--- a/src/contacts-contact-editor.vala
+++ b/src/contacts-contact-editor.vala
@@ -151,10 +151,11 @@ public class Contacts.ContactEditor : Grid {
var box = get_child_at (1, row_entry.key) as Grid;
var day_spin = box.get_child_at (0, 0) as SpinButton;
var combo = box.get_child_at (1, 0) as ComboBoxText;
+ var year_spin = box.get_child_at (2, 0) as SpinButton;
- var bday = new DateTime.local ((int)box.get_data<int> ("year"),
+ var bday = new DateTime.local (year_spin.get_value_as_int (),
combo.get_active () + 1,
- (int)day_spin.get_value (),
+ day_spin.get_value_as_int (),
0, 0, 0);
bday = bday.to_utc ();
@@ -349,6 +350,8 @@ public class Contacts.ContactEditor : Grid {
focus_widget = value_text;
}
+ delegate void AdjustingDateFn();
+
void attach_row_for_birthday (string title, AbstractFieldDetails? details, DateTime birthday, int row) {
var title_label = new Label (title);
title_label.set_hexpand (false);
@@ -380,10 +383,14 @@ public class Contacts.ContactEditor : Grid {
combo.get_style_context ().add_class ("contacts-combo");
combo.set_hexpand (true);
- /* hack to preserver year in order to compare latter full date */
- box.set_data ("year", birthday.to_local ().get_year ());
+ var year_spin = new SpinButton.with_range (1800, 3000, 1);
+ year_spin.set_digits (0);
+ year_spin.numeric = true;
+ year_spin.set_value ((double)birthday.to_local ().get_year ());
+
box.add (day_spin);
box.add (combo);
+ box.add (year_spin);
attach (box, 1, row, 1, 1);
@@ -393,12 +400,34 @@ public class Contacts.ContactEditor : Grid {
delete_button.add (image);
attach (delete_button, 3, row, 1, 1);
+ AdjustingDateFn fn = () => {
+ int[] month_of_31 = {3, 5, 8, 10};
+ if (combo.get_active () in month_of_31) {
+ day_spin.set_range (1, 30);
+ } else if (combo.get_active () == 1) {
+ if (year_spin.get_value_as_int () % 4 == 0 &&
+ year_spin.get_value_as_int () % 100 != 0) {
+ day_spin.set_range (1, 29);
+ } else {
+ day_spin.set_range (1, 28);
+ }
+ }
+ };
+
/* Notify change to upper layer */
day_spin.changed.connect (() => {
set_field_changed (row);
});
combo.changed.connect (() => {
set_field_changed (row);
+
+ /* adjusting day_spin value using selected month constraints*/
+ fn ();
+ });
+ year_spin.changed.connect (() => {
+ set_field_changed (row);
+
+ fn ();
});
delete_button.clicked.connect (() => {
remove_row (row);