[gnome-calendar/gbsneto/gtk4: 17/37] event-editor/dialog: Port to GTK4
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/gbsneto/gtk4: 17/37] event-editor/dialog: Port to GTK4
- Date: Wed, 26 Jan 2022 16:31:54 +0000 (UTC)
commit 209f7703fab540c96a68b4a245db0f8db29dd50c
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Jan 14 11:22:37 2022 -0300
event-editor/dialog: Port to GTK4
src/gui/event-editor/gcal-event-editor-dialog.c | 6 +--
src/gui/event-editor/gcal-event-editor-dialog.ui | 67 ++++--------------------
src/utils/gcal-utils.c | 64 +++++++++++-----------
3 files changed, 46 insertions(+), 91 deletions(-)
---
diff --git a/src/gui/event-editor/gcal-event-editor-dialog.c b/src/gui/event-editor/gcal-event-editor-dialog.c
index 69b1a82e..83a26c27 100644
--- a/src/gui/event-editor/gcal-event-editor-dialog.c
+++ b/src/gui/event-editor/gcal-event-editor-dialog.c
@@ -31,7 +31,6 @@
#include "gcal-schedule-section.h"
#include "gcal-summary-section.h"
-#include <dazzle.h>
#include <libecal/libecal.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
@@ -59,7 +58,7 @@ struct _GcalEventEditorDialog
GcalEventEditorSection *reminders_section;
GcalEventEditorSection *schedule_section;
GtkWidget *sources_button;
- GtkWidget *sources_popover;
+ GtkPopoverMenu *sources_popover;
GtkWidget *source_image;
GtkWidget *source_label;
GtkWidget *subtitle_label;
@@ -182,7 +181,8 @@ fill_sources_menu (GcalEventEditorDialog *self)
g_menu_append_item (self->sources_menu, item);
}
- gtk_popover_bind_model (GTK_POPOVER (self->sources_popover), G_MENU_MODEL (self->sources_menu), "edit");
+ gtk_popover_menu_set_menu_model (self->sources_popover,
+ G_MENU_MODEL (self->sources_menu));
/* HACK: show the popover menu icons */
fix_popover_menu_icons (GTK_POPOVER (self->sources_popover));
diff --git a/src/gui/event-editor/gcal-event-editor-dialog.ui
b/src/gui/event-editor/gcal-event-editor-dialog.ui
index f919a4ef..be5ff863 100644
--- a/src/gui/event-editor/gcal-event-editor-dialog.ui
+++ b/src/gui/event-editor/gcal-event-editor-dialog.ui
@@ -1,22 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GcalEventEditorDialog" parent="GtkDialog">
- <property name="can_focus">False</property>
<property name="modal">True</property>
<property name="default-width">450</property>
<property name="default-height">500</property>
- <property name="window_position">center-on-parent</property>
<property name="use_header_bar">1</property>
<property name="destroy_with_parent">True</property>
- <property name="type_hint">dialog</property>
+ <property name="hide-on-close">True</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="titlebar">
- <property name="visible">True</property>
<child>
<object class="GtkButton" id="cancel_button">
<property name="label" translatable="yes">Cancel</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
<signal name="clicked" handler="on_cancel_button_clicked_cb" object="GcalEventEditorDialog"
swapped="no"/>
</object>
</child>
@@ -24,14 +19,10 @@
<object class="GtkImage" id="lock">
<property name="visible" bind-source="GcalEventEditorDialog" bind-property="writable"
bind-flags="default|invert-boolean" />
<property name="icon_name">changes-prevent-symbolic</property>
- <property name="icon_size">1</property>
</object>
</child>
<child type="title">
<object class="GtkMenuButton" id="sources_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
<property name="popover">sources_popover</property>
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable"
bind-flags="default" />
<property name="tooltip-text" translatable="yes">Click to select the calendar</property>
@@ -41,19 +32,13 @@
</style>
<child>
<object class="GtkBox">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox" id="title_label_box">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="valign">center</property>
<child>
<object class="GtkLabel" id="title_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="ellipsize">middle</property>
<property name="max_width_chars">40</property>
<style>
@@ -63,14 +48,10 @@
</child>
<child>
<object class="GtkBox" id="subtitle_box">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="orientation">horizontal</property>
<property name="halign">center</property>
<child>
<object class="GtkImage" id="source_image">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<style>
<class name="calendar-color-image"/>
</style>
@@ -78,8 +59,6 @@
</child>
<child>
<object class="GtkLabel" id="subtitle_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<style>
<class name="subtitle"/>
</style>
@@ -94,8 +73,6 @@
</child>
<child>
<object class="GtkImage" id="pan_down_image">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="icon_name">pan-down-symbolic</property>
</object>
</child>
@@ -103,40 +80,28 @@
</child>
</object>
</child>
- <child>
+ <child type="end">
<object class="GtkButton" id="done_button">
<property name="label" translatable="yes">Done</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
<signal name="clicked" handler="on_done_button_clicked_cb" object="GcalEventEditorDialog"
swapped="no"/>
<style>
<class name="suggested-action"/>
</style>
</object>
- <packing>
- <property name="pack_type">end</property>
- </packing>
</child>
</object>
</child>
- <child internal-child="vbox">
- <object class="GtkBox" id="dialog-vbox">
- <property name="visible">true</property>
- <property name="spacing">0</property>
- <property name="border_width">0</property>
+ <child>
+ <object class="GtkBox">
<child>
- <object class="HdyPreferencesPage">
- <property name="visible">True</property>
+ <object class="AdwPreferencesPage">
<property name="vexpand">True</property>
<!-- Summary -->
<child>
- <object class="HdyPreferencesGroup">
- <property name="visible">True</property>
+ <object class="AdwPreferencesGroup">
<child>
<object class="GcalSummarySection" id="summary_section">
- <property name="visible">True</property>
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable"
bind-flags="default" />
</object>
</child>
@@ -145,12 +110,10 @@
<!-- Schedule -->
<child>
- <object class="HdyPreferencesGroup">
- <property name="visible">True</property>
+ <object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Schedule</property>
<child>
<object class="GcalScheduleSection" id="schedule_section">
- <property name="visible">True</property>
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable"
bind-flags="default" />
</object>
</child>
@@ -159,12 +122,10 @@
<!-- Reminders -->
<child>
- <object class="HdyPreferencesGroup">
- <property name="visible">True</property>
+ <object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Reminders</property>
<child>
<object class="GcalRemindersSection" id="reminders_section">
- <property name="visible">True</property>
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable"
bind-flags="default" />
</object>
</child>
@@ -173,12 +134,10 @@
<!-- Notes -->
<child>
- <object class="HdyPreferencesGroup">
- <property name="visible">True</property>
+ <object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Notes</property>
<child>
<object class="GcalNotesSection" id="notes_section">
- <property name="visible">True</property>
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable"
bind-flags="default" />
</object>
</child>
@@ -187,18 +146,14 @@
<!-- Delete Button -->
<child>
- <object class="HdyPreferencesGroup">
- <property name="visible">True</property>
+ <object class="AdwPreferencesGroup">
<child>
<object class="GtkButton" id="delete_button">
- <property name="visible">True</property>
<property name="halign">end</property>
- <property name="can_focus">True</property>
<signal name="clicked" handler="on_delete_button_clicked_cb"
object="GcalEventEditorDialog" swapped="no"/>
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable"
bind-flags="default" />
<child>
<object class="GtkLabel" id="delete_label">
- <property name="visible">True</property>
<property name="label" translatable="yes">Delete Event</property>
</object>
</child>
@@ -215,7 +170,7 @@
</object>
</child>
</template>
- <object class="GtkPopover" id="sources_popover">
+ <object class="GtkPopoverMenu" id="sources_popover">
</object>
<object class="GtkSizeGroup">
<property name="mode">vertical</property>
diff --git a/src/utils/gcal-utils.c b/src/utils/gcal-utils.c
index 977dd5ee..5ea22b42 100644
--- a/src/utils/gcal-utils.c
+++ b/src/utils/gcal-utils.c
@@ -710,64 +710,53 @@ fix_popover_menu_icons (GtkPopover *popover)
GtkWidget *popover_stack;
GtkWidget *menu_section;
GtkWidget *menu_section_box;
- GList *stack_children;
- GList *menu_section_children;
- GList *menu_section_box_children, *aux;
+ GtkWidget *child;
- popover_stack = gtk_bin_get_child (GTK_BIN (popover));
- stack_children = gtk_container_get_children (GTK_CONTAINER (popover_stack));
+ popover_stack = gtk_popover_get_child (GTK_POPOVER (popover));
/**
* At the moment, the popover stack surely contains only
* one child of type GtkMenuSectionBox, which contains
* a single GtkBox.
*/
- menu_section = stack_children->data;
- menu_section_children = gtk_container_get_children (GTK_CONTAINER (menu_section));
+ menu_section = gtk_widget_get_first_child (popover_stack);
/**
* Get the unique box's children.
*/
- menu_section_box = menu_section_children->data;
- menu_section_box_children = gtk_container_get_children (GTK_CONTAINER (menu_section_box));
+ menu_section_box = gtk_widget_get_first_child (menu_section);
- gtk_style_context_add_class (gtk_widget_get_style_context (menu_section_box), "calendars-list");
+ gtk_widget_add_css_class (menu_section_box, "calendars-list");
/**
* Iterate through the GtkModelButtons inside the menu section box.
*/
- for (aux = menu_section_box_children; aux != NULL; aux = aux->next)
+ for (child = gtk_widget_get_first_child (menu_section_box);
+ child;
+ child = gtk_widget_get_next_sibling (child))
{
GtkWidget *button_box;
- GList *button_box_children, *aux2;
+ GtkWidget *child2;
- button_box = gtk_bin_get_child (GTK_BIN (aux->data));
- button_box_children = gtk_container_get_children (GTK_CONTAINER (button_box));
+ button_box = gtk_widget_get_first_child (child);
/**
* Since there is no guarantee that the first child is
* the GtkImage we're looking for, we have to iterate
* through the children and check if the types match.
*/
- for (aux2 = button_box_children; aux2 != NULL; aux2 = aux2->next)
+ for (child2 = gtk_widget_get_first_child (button_box);
+ child2;
+ child2 = gtk_widget_get_next_sibling (child))
{
- GtkWidget *button_box_child;
- button_box_child = aux2->data;
-
- if (g_type_is_a (G_OBJECT_TYPE (button_box_child), GTK_TYPE_IMAGE))
+ if (g_type_is_a (G_OBJECT_TYPE (child2), GTK_TYPE_IMAGE))
{
- gtk_style_context_add_class (gtk_widget_get_style_context (button_box_child),
"calendar-color-image");
- gtk_widget_show (button_box_child);
+ gtk_widget_add_css_class (child2, "calendar-color-image");
+ gtk_widget_show (child2);
break;
}
}
-
- g_list_free (button_box_children);
}
-
- g_list_free (stack_children);
- g_list_free (menu_section_children);
- g_list_free (menu_section_box_children);
}
/**
@@ -952,6 +941,14 @@ is_source_enabled (ESource *source)
return e_source_selectable_get_selected (selectable);
}
+static void
+on_dialog_response_cb (GtkDialog *dialog,
+ gint response,
+ gint *out_response)
+{
+ *out_response = response;
+}
+
/**
* ask_recurrence_modification_type:
* @parent: a #GtkWidget
@@ -976,12 +973,12 @@ ask_recurrence_modification_type (GtkWidget *parent,
ECalClient *client;
GtkWidget *dialog;
gboolean is_set;
- gint result;
+ gint result = 0;
flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
*modtype = GCAL_RECURRENCE_MOD_THIS_ONLY;
- dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (parent)),
+ dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_native (parent)),
flags,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
@@ -1000,10 +997,13 @@ ask_recurrence_modification_type (GtkWidget *parent,
gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Subsequent events"), GTK_RESPONSE_OK);
gtk_dialog_add_button (GTK_DIALOG (dialog), _("_All events"), GTK_RESPONSE_YES);
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_native (parent)));
+ g_signal_connect (dialog, "response", G_CALLBACK (on_dialog_response_cb), &result);
- gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_toplevel (parent)));
+ gtk_window_present (GTK_WINDOW (dialog));
- result = gtk_dialog_run (GTK_DIALOG (dialog));
+ while (result == 0)
+ g_main_context_iteration (NULL, TRUE);
switch (result)
{
@@ -1027,7 +1027,7 @@ ask_recurrence_modification_type (GtkWidget *parent,
break;
}
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ gtk_window_destroy (GTK_WINDOW (dialog));
return is_set;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]