From 2e7d17fe63b6a7f80d2634fe2a31d0f603c53f5a Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Wed, 6 Jul 2016 02:35:54 -0300 Subject: [PATCH] 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(+) diff --git a/data/ui/edit-dialog.ui b/data/ui/edit-dialog.ui index 4bdc2fb2..fe0a378d 100644 --- a/data/ui/edit-dialog.ui +++ b/data/ui/edit-dialog.ui @@ -322,6 +322,7 @@ True True True + alarms_popover True @@ -386,4 +387,86 @@ + + False + + + True + False + 12 + vertical + + + True + True + True + 5 minutes + + + + + + True + True + True + 10 minutes + + + + + + True + True + True + 30 minutes + + + + + + True + True + True + 1 hour + + + + + + True + True + 1 day + + + + + + True + True + True + 2 days + + + + + + True + True + True + 3 days + + + + + + True + True + True + 1 week + + + + + + diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c index 66f34c65..4d1a8158 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)