From 5283bfe546eb11f1f97d01665e00e4d3674b4df0 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Fri, 8 Nov 2024 17:38:10 -0300 Subject: [PATCH] event-editor/dialog: Compose calendars model Currently we only show writable calendars in the calendar row, but for read-only events, the read-only calendar must be selected. But that's impossible because it's not in the model. Change the model to a flattened list as follows: + FlattenListModel -----------+ | | | + writable calendars -----+ | | | | | | | - Calendar 1 | | | | - Calendar 2 | | | | - Calendar 3 | | | | [...] | | | | | | | +-------------------------+ | | + read-only calendars ----+ | | | | | | | - Calendar 1 | | | | [...] | | | | | | | +-------------------------+ | +-----------------------------+ The read-only calendars list only ever has 1 item: the calendar of the current event, and only if the event is in a read-only calendar. --- .../event-editor/gcal-event-editor-dialog.c | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/gui/event-editor/gcal-event-editor-dialog.c b/src/gui/event-editor/gcal-event-editor-dialog.c index 218cdee2..de39f352 100644 --- a/src/gui/event-editor/gcal-event-editor-dialog.c +++ b/src/gui/event-editor/gcal-event-editor-dialog.c @@ -74,6 +74,8 @@ struct _GcalEventEditorDialog GBinding *event_title_binding; + GListStore *read_only_calendar_model; + /* flags */ gboolean event_is_new; gboolean recurrence_changed; @@ -197,15 +199,27 @@ apply_event_properties_to_template_event (GcalEvent *template_event, static void setup_context (GcalEventEditorDialog *self) { - g_autoptr (GListModel) calendars = NULL; + g_autoptr (GtkFlattenListModel) flatten_model = NULL; + g_autoptr (GListModel) writable_calendars = NULL; + g_autoptr (GListStore) all_calendars = NULL; GcalManager *manager; GCAL_ENTRY; - manager = gcal_context_get_manager (self->context); - calendars = gcal_create_writable_calendars_model (manager); + g_assert (GCAL_IS_EVENT_EDITOR_DIALOG (self)); - adw_combo_row_set_model ( ADW_COMBO_ROW (self->calendar_combo_row), calendars); + manager = gcal_context_get_manager (self->context); + writable_calendars = gcal_create_writable_calendars_model (manager); + + self->read_only_calendar_model = g_list_store_new (GCAL_TYPE_CALENDAR); + + all_calendars = g_list_store_new (G_TYPE_LIST_MODEL); + g_list_store_append (all_calendars, self->read_only_calendar_model); + g_list_store_append (all_calendars, writable_calendars); + + flatten_model = gtk_flatten_list_model_new (G_LIST_MODEL (g_steal_pointer (&all_calendars))); + + adw_combo_row_set_model (ADW_COMBO_ROW (self->calendar_combo_row), G_LIST_MODEL (flatten_model)); GCAL_EXIT; } @@ -441,6 +455,7 @@ gcal_event_editor_dialog_finalize (GObject *object) self = GCAL_EVENT_EDITOR_DIALOG (object); + g_clear_object (&self->read_only_calendar_model); g_clear_object (&self->context); g_clear_object (&self->event); @@ -655,6 +670,10 @@ gcal_event_editor_dialog_set_event (GcalEventEditorDialog *self, else gtk_label_set_label (GTK_LABEL (self->title_label), _("Edit Event")); + g_list_store_remove_all (self->read_only_calendar_model); + if (gcal_calendar_is_read_only (calendar)) + g_list_store_append (self->read_only_calendar_model, calendar); + gcal_calendar_combo_row_set_calendar (self->calendar_combo_row, calendar); /* recurrence_changed */