event-editor/reminders-section: Subclass GcalEventEditorSection
Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/711>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Gtk 4.0;
|
||||
using Adw 1;
|
||||
|
||||
template $GcalRemindersSection: Adw.PreferencesGroup {
|
||||
template $GcalRemindersSection: $GcalEventEditorSection {
|
||||
ListBox alarms_listbox {
|
||||
selection-mode: none;
|
||||
row-activated => $on_alarms_listbox_row_activated_cb(template) not-swapped;
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
|
||||
#include "gcal-alarm-row.h"
|
||||
#include "gcal-debug.h"
|
||||
#include "gcal-event-editor-dialog.h"
|
||||
#include "gcal-event-editor-section.h"
|
||||
#include "gcal-reminders-section.h"
|
||||
#include "gcal-utils.h"
|
||||
|
||||
@@ -31,7 +29,7 @@
|
||||
|
||||
struct _GcalRemindersSection
|
||||
{
|
||||
AdwPreferencesGroup parent;
|
||||
GcalEventEditorSection parent;
|
||||
|
||||
GtkListBox *alarms_listbox;
|
||||
GtkWidget *alarms_popover;
|
||||
@@ -53,7 +51,7 @@ struct _GcalRemindersSection
|
||||
static void on_remove_alarm_cb (GcalAlarmRow *alarm_row,
|
||||
GcalRemindersSection *self);
|
||||
|
||||
G_DEFINE_FINAL_TYPE (GcalRemindersSection, gcal_reminders_section, ADW_TYPE_PREFERENCES_GROUP)
|
||||
G_DEFINE_FINAL_TYPE (GcalRemindersSection, gcal_reminders_section, GCAL_TYPE_EVENT_EDITOR_SECTION)
|
||||
|
||||
/*
|
||||
* Auxiliary methods
|
||||
@@ -165,23 +163,19 @@ create_alarm_row (GcalRemindersSection *self,
|
||||
}
|
||||
|
||||
static void
|
||||
setup_alarms (GcalRemindersSection *self)
|
||||
setup_alarms (GcalRemindersSection *self,
|
||||
GcalEvent *event)
|
||||
{
|
||||
g_autoptr (GList) alarms = NULL;
|
||||
GtkWidget *dialog;
|
||||
GcalEvent *event;
|
||||
GList *l;
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GCAL_TYPE_EVENT_EDITOR_DIALOG);
|
||||
|
||||
g_assert (GCAL_IS_EVENT_EDITOR_DIALOG (dialog));
|
||||
|
||||
event = gcal_event_editor_dialog_get_event (GCAL_EVENT_EDITOR_DIALOG (dialog));
|
||||
|
||||
clear_alarms (self);
|
||||
|
||||
for (gsize i = 0; i < G_N_ELEMENTS (minutes_button); i++)
|
||||
gtk_widget_set_sensitive (WIDGET_FROM_OFFSET (minutes_button[i].button_offset), TRUE);
|
||||
|
||||
if (!event)
|
||||
GCAL_RETURN ();
|
||||
|
||||
@@ -230,18 +224,12 @@ sort_alarms_func (GtkListBoxRow *a,
|
||||
ECalComponentAlarm *alarm_a;
|
||||
ECalComponentAlarm *alarm_b;
|
||||
GcalRemindersSection *self;
|
||||
GtkWidget *dialog;
|
||||
GcalEvent *event;
|
||||
gint minutes_a;
|
||||
gint minutes_b;
|
||||
|
||||
self = GCAL_REMINDERS_SECTION (user_data);
|
||||
|
||||
dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GCAL_TYPE_EVENT_EDITOR_DIALOG);
|
||||
|
||||
g_assert (GCAL_IS_EVENT_EDITOR_DIALOG (dialog));
|
||||
|
||||
event = gcal_event_editor_dialog_get_event (GCAL_EVENT_EDITOR_DIALOG (dialog));
|
||||
event = gcal_event_editor_section_get_event (GCAL_EVENT_EDITOR_SECTION (self));
|
||||
|
||||
if (a == self->new_alarm_row)
|
||||
return 1;
|
||||
@@ -264,16 +252,11 @@ on_remove_alarm_cb (GcalAlarmRow *alarm_row,
|
||||
ECalComponentAlarm *alarm;
|
||||
GtkWidget *alarm_button;
|
||||
gint trigger_minutes;
|
||||
GtkWidget *dialog;
|
||||
GcalEvent *event;
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GCAL_TYPE_EVENT_EDITOR_DIALOG);
|
||||
|
||||
g_assert (GCAL_IS_EVENT_EDITOR_DIALOG (dialog));
|
||||
|
||||
event = gcal_event_editor_dialog_get_event (GCAL_EVENT_EDITOR_DIALOG (dialog));
|
||||
event = gcal_event_editor_section_get_event (GCAL_EVENT_EDITOR_SECTION (self));
|
||||
|
||||
alarm = gcal_alarm_row_get_alarm (alarm_row);
|
||||
trigger_minutes = get_alarm_trigger_minutes (event, alarm);
|
||||
@@ -299,14 +282,9 @@ on_add_alarm_button_clicked_cb (GtkWidget *button,
|
||||
ECalComponentAlarm *alarm;
|
||||
GtkWidget *row;
|
||||
guint i, minutes;
|
||||
GtkWidget *dialog;
|
||||
GcalEvent *event;
|
||||
|
||||
dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GCAL_TYPE_EVENT_EDITOR_DIALOG);
|
||||
|
||||
g_assert (GCAL_IS_EVENT_EDITOR_DIALOG (dialog));
|
||||
|
||||
event = gcal_event_editor_dialog_get_event (GCAL_EVENT_EDITOR_DIALOG (dialog));
|
||||
event = gcal_event_editor_section_get_event (GCAL_EVENT_EDITOR_SECTION (self));
|
||||
|
||||
/* Search for the button minute */
|
||||
minutes = G_MAXUINT;
|
||||
@@ -349,26 +327,12 @@ on_alarms_listbox_row_activated_cb (GtkListBox *alarms_listbox,
|
||||
*/
|
||||
|
||||
static void
|
||||
gcal_reminders_section_map (GtkWidget *widget)
|
||||
gcal_reminders_section_event_set_cb (GcalEventEditorSection *section,
|
||||
GcalEvent *event)
|
||||
{
|
||||
GcalRemindersSection *self = GCAL_REMINDERS_SECTION (widget);
|
||||
GcalRemindersSection *self = GCAL_REMINDERS_SECTION (section);
|
||||
|
||||
setup_alarms (self);
|
||||
|
||||
GTK_WIDGET_CLASS (gcal_reminders_section_parent_class)->map (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_reminders_section_unmap (GtkWidget *widget)
|
||||
{
|
||||
GcalRemindersSection *self = GCAL_REMINDERS_SECTION (widget);
|
||||
|
||||
clear_alarms (self);
|
||||
|
||||
for (gsize i = 0; i < G_N_ELEMENTS (minutes_button); i++)
|
||||
gtk_widget_set_sensitive (WIDGET_FROM_OFFSET (minutes_button[i].button_offset), TRUE);
|
||||
|
||||
GTK_WIDGET_CLASS (gcal_reminders_section_parent_class)->unmap (widget);
|
||||
setup_alarms (self, event);
|
||||
}
|
||||
|
||||
|
||||
@@ -391,11 +355,11 @@ gcal_reminders_section_class_init (GcalRemindersSectionClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
GcalEventEditorSectionClass *section_class = GCAL_EVENT_EDITOR_SECTION_CLASS (klass);
|
||||
|
||||
object_class->dispose = gcal_reminders_section_dispose;
|
||||
|
||||
widget_class->map = gcal_reminders_section_map;
|
||||
widget_class->unmap = gcal_reminders_section_unmap;
|
||||
section_class->event_set_cb = gcal_reminders_section_event_set_cb;
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/event-editor/gcal-reminders-section.ui");
|
||||
|
||||
|
||||
@@ -22,9 +22,11 @@
|
||||
|
||||
#include <adwaita.h>
|
||||
|
||||
#include "gcal-event-editor-section.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GCAL_TYPE_REMINDERS_SECTION (gcal_reminders_section_get_type())
|
||||
G_DECLARE_FINAL_TYPE (GcalRemindersSection, gcal_reminders_section, GCAL, REMINDERS_SECTION, AdwPreferencesGroup)
|
||||
G_DECLARE_FINAL_TYPE (GcalRemindersSection, gcal_reminders_section, GCAL, REMINDERS_SECTION, GcalEventEditorSection)
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
Reference in New Issue
Block a user