[gnome-calendar/wip/gbsneto/alarms: 5/6] edit-dialog: implement add alarm popover
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/gbsneto/alarms: 5/6] edit-dialog: implement add alarm popover
- Date: Wed, 6 Jul 2016 05:39:54 +0000 (UTC)
commit 0feeff746e59af9a9b9fbe4abdb08c70946787b4
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Jul 6 02:35:54 2016 -0300
edit-dialog: implement add alarm popover
The new popover handles all the possible alarms we support.
data/ui/edit-dialog.ui | 83 ++++++++++++++++++++++++++++++++++++++++++++++++
src/gcal-edit-dialog.c | 76 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 159 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/edit-dialog.ui b/data/ui/edit-dialog.ui
index 4bdc2fb..fe0a378 100644
--- a/data/ui/edit-dialog.ui
+++ b/data/ui/edit-dialog.ui
@@ -322,6 +322,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
+ <property name="popover">alarms_popover</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@@ -386,4 +387,86 @@
</template>
<object class="GtkPopover" id="sources_popover">
</object>
+ <object class="GtkPopoverMenu" id="alarms_popover">
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">12</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkModelButton" id="five_minutes_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="text" translatable="yes">5 minutes</property>
+ <signal name="clicked" handler="add_alarm_button_clicked" object="GcalEditDialog" swapped="no" />
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton" id="ten_minutes_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="text" translatable="yes">10 minutes</property>
+ <signal name="clicked" handler="add_alarm_button_clicked" object="GcalEditDialog" swapped="no" />
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton" id="thirty_minutes_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="text" translatable="yes">30 minutes</property>
+ <signal name="clicked" handler="add_alarm_button_clicked" object="GcalEditDialog" swapped="no" />
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton" id="one_hour_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="text" translatable="yes">1 hour</property>
+ <signal name="clicked" handler="add_alarm_button_clicked" object="GcalEditDialog" swapped="no" />
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton" id="one_day_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="text" translatable="yes">1 day</property>
+ <signal name="clicked" handler="add_alarm_button_clicked" object="GcalEditDialog" swapped="no" />
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton" id="two_days_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="text" translatable="yes">2 days</property>
+ <signal name="clicked" handler="add_alarm_button_clicked" object="GcalEditDialog" swapped="no" />
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton" id="three_days_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="text" translatable="yes">3 days</property>
+ <signal name="clicked" handler="add_alarm_button_clicked" object="GcalEditDialog" swapped="no" />
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton" id="one_week_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="text" translatable="yes">1 week</property>
+ <signal name="clicked" handler="add_alarm_button_clicked" object="GcalEditDialog" swapped="no" />
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
</interface>
diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c
index 66f34c6..4d1a815 100644
--- a/src/gcal-edit-dialog.c
+++ b/src/gcal-edit-dialog.c
@@ -57,6 +57,16 @@ struct _GcalEditDialog
GtkWidget *alarms_listbox;
+ /* Add Alarms popover buttons */
+ GtkWidget *five_minutes_button;
+ GtkWidget *ten_minutes_button;
+ GtkWidget *thirty_minutes_button;
+ GtkWidget *one_hour_button;
+ GtkWidget *one_day_button;
+ GtkWidget *two_days_button;
+ GtkWidget *three_days_button;
+ GtkWidget *one_week_button;
+
/* actions */
GMenu *sources_menu;
GSimpleActionGroup *action_group;
@@ -99,6 +109,9 @@ static void gcal_edit_dialog_action_button_clicked (GtkWidget *wi
static void gcal_edit_dialog_all_day_changed (GtkWidget *widget,
gpointer user_data);
+static void add_alarm_button_clicked (GtkWidget *button,
+ GcalEditDialog *self);
+
G_DEFINE_TYPE (GcalEditDialog, gcal_edit_dialog, GTK_TYPE_DIALOG)
enum
@@ -346,6 +359,15 @@ gcal_edit_dialog_class_init (GcalEditDialogClass *klass)
TRUE,
G_PARAM_READWRITE));
+ /* Alarms */
+ gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, five_minutes_button);
+ gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, ten_minutes_button);
+ gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, thirty_minutes_button);
+ gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, one_hour_button);
+ gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, one_day_button);
+ gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, two_days_button);
+ gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, three_days_button);
+ gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, one_week_button);
/* Buttons */
gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, done_button);
gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, cancel_button);
@@ -368,6 +390,7 @@ gcal_edit_dialog_class_init (GcalEditDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, sources_popover);
/* callbacks */
+ gtk_widget_class_bind_template_callback (widget_class, add_alarm_button_clicked);
gtk_widget_class_bind_template_callback (widget_class, gcal_edit_dialog_action_button_clicked);
gtk_widget_class_bind_template_callback (widget_class, gcal_edit_dialog_all_day_changed);
gtk_widget_class_bind_template_callback (widget_class, update_summary);
@@ -731,6 +754,59 @@ setup_alarms (GcalEditDialog *self)
g_list_free (alarms);
}
+static void
+add_alarm_button_clicked (GtkWidget *button,
+ GcalEditDialog *self)
+{
+ gint i, minutes;
+
+ struct
+ {
+ GtkWidget *button;
+ gint minutes;
+ } button_minutes[] = {
+ { self->five_minutes_button, 5 },
+ { self->ten_minutes_button, 10 },
+ { self->thirty_minutes_button, 30 },
+ { self->one_hour_button, 60 },
+ { self->one_day_button, 1440 },
+ { self->two_days_button, 2880 },
+ { self->three_days_button, 4320 },
+ { self->one_week_button, 10080 },
+ { NULL, 0 }
+ };
+
+ /* Search for the button minute */
+ minutes = 0;
+
+ for (i = 0; i < G_N_ELEMENTS (button_minutes); i++)
+ {
+ if (button_minutes[i].button == button)
+ {
+ minutes = button_minutes[i].minutes;
+ break;
+ }
+ }
+
+ if (minutes == 0)
+ return;
+
+ /* Add the alarm */
+ gcal_event_add_alarm (self->event, minutes, FALSE);
+
+ /*
+ * Instead of manually handling stuff, simply remove all alarms and
+ * add back again.
+ */
+ setup_alarms (self);
+
+ /*
+ * Since we don't allow more than 1 alarm per time, set the button
+ * to insensitive so it cannot be triggered anymore.
+ */
+ gtk_widget_set_sensitive (button, FALSE);
+}
+
/* Public API */
GtkWidget*
gcal_edit_dialog_new (void)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]