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