Hildon Reference Manual |
---|
Date WidgetsDate Bar — How to migrate Date widgets |
Being deprecated since Hildon 2.2, the calendar popup and date editor can be substituded by a HildonDateButton.
Examples of a typical calendar popup and a date editor are presented bellow.
Example 34. A Typical Calendar Popup
guint y = 2009, m = 4, d = 25; GtkWidget *parent, *popup; popup = hildon_calendar_popup_new (GTK_WINDOW (parent), y, m, d); gtk_dialog_run (GTK_DIALOG (popup)); hildon_calendar_popup_get_date (HILDON_CALENDAR_POPUP (popup), &y, &m, &d);
Example 35. A Typical Date Editor
gboolean on_error (GtkWidget *widget, HildonDateTimeError error_type); gboolean on_error (GtkWidget *widget, HildonDateTimeError error_type) { g_debug ("Error: %d", error_type); return FALSE; } GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new ()); HildonDateEditor *date_editor = HILDON_DATE_EDITOR (hildon_date_editor_new ()); gtk_box_pack_start (GTK_BOX (dialog->vbox), gtk_label_new ("Choose a date"), FALSE, FALSE, 10); gtk_box_pack_start (GTK_BOX (dialog->vbox), GTK_WIDGET (date_editor), FALSE, FALSE, 10); gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CANCEL); g_signal_connect (G_OBJECT (date_editor), "date_error", G_CALLBACK (on_error), NULL); gtk_widget_show_all (GTK_WIDGET (dialog)); gtk_dialog_run (dialog); hildon_date_editor_get_date (date_editor, &y, &m, &d);
The following example accomplishes equivalent functionality using a HildonDateButton.
Example 36. A Replacement for the Calendar Popup
GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new ()); guint y = 2009, m = 3, d = 25; HildonDateButton *date_button = HILDON_DATE_BUTTON (hildon_date_button_new ( HILDON_SIZE_THUMB_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL)); hildon_date_button_set_date (date_button, y, m, d); gtk_box_pack_end (GTK_BOX (dialog->vbox), GTK_WIDGET (date_button), FALSE, FALSE, 0); gtk_widget_show_all (GTK_WIDGET (dialog)); gtk_dialog_run (dialog); hildon_date_button_get_date (date_button, &y, &m, &d);
A weekday picker (deprecated since Hildon 2.2) can be easily replaced by a HildonPickerButton.
The following example presents the deprecated weekday picker in a dialog.
Example 37. A Typical Weekday Picker
GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new ()); GtkWidget *picker = hildon_weekday_picker_new (); gtk_box_pack_start (GTK_BOX (dialog->vbox), picker, TRUE, TRUE, 0); gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CLOSE); gtk_widget_show_all (GTK_WIDGET (dialog)); gtk_dialog_run (dialog);
With a HildonPickerButton it is easy to add the weekdays to its TouchSelector and thus having the same functionality.
Example 38. A Replacement for the Weekday Picker
GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new ()); GtkWidget *picker = hildon_picker_button_new (HILDON_SIZE_THUMB_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL); hildon_button_set_title (HILDON_BUTTON (picker), "Weekday:"); HildonTouchSelector *selector = HILDON_TOUCH_SELECTOR ( hildon_touch_selector_new_text ()); hildon_touch_selector_append_text (selector, "Sunday"); hildon_touch_selector_append_text (selector, "Monday"); hildon_touch_selector_append_text (selector, "Tuesday"); hildon_touch_selector_append_text (selector, "Thursday"); hildon_touch_selector_append_text (selector, "Friday"); hildon_touch_selector_append_text (selector, "Saturday"); hildon_touch_selector_set_column_selection_mode (selector, HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE); hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (picker), selector); hildon_picker_button_set_active (HILDON_PICKER_BUTTON (picker), 0); gtk_box_pack_start (GTK_BOX (dialog->vbox), picker, TRUE, TRUE, 0); gtk_widget_show_all (GTK_WIDGET (dialog)); gtk_dialog_run (dialog);