event-editor/dialog: Port to GTK4

This commit is contained in:
Georges Basile Stavracas Neto
2022-02-11 09:18:38 -03:00
parent 2139f40e67
commit 0f7a0db138
3 changed files with 55 additions and 99 deletions
@@ -31,7 +31,6 @@
#include "gcal-schedule-section.h" #include "gcal-schedule-section.h"
#include "gcal-summary-section.h" #include "gcal-summary-section.h"
#include <dazzle.h>
#include <libecal/libecal.h> #include <libecal/libecal.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
@@ -59,7 +58,7 @@ struct _GcalEventEditorDialog
GcalEventEditorSection *reminders_section; GcalEventEditorSection *reminders_section;
GcalEventEditorSection *schedule_section; GcalEventEditorSection *schedule_section;
GtkWidget *sources_button; GtkWidget *sources_button;
GtkWidget *sources_popover; GtkPopoverMenu *sources_popover;
GtkWidget *source_image; GtkWidget *source_image;
GtkWidget *source_label; GtkWidget *source_label;
GtkWidget *subtitle_label; GtkWidget *subtitle_label;
@@ -182,7 +181,8 @@ fill_sources_menu (GcalEventEditorDialog *self)
g_menu_append_item (self->sources_menu, item); 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 */ /* HACK: show the popover menu icons */
fix_popover_menu_icons (GTK_POPOVER (self->sources_popover)); fix_popover_menu_icons (GTK_POPOVER (self->sources_popover));
@@ -1,37 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<template class="GcalEventEditorDialog" parent="GtkDialog"> <template class="GcalEventEditorDialog" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="modal">True</property> <property name="modal">True</property>
<property name="default-width">450</property> <property name="default-width">450</property>
<property name="default-height">500</property> <property name="default-height">500</property>
<property name="window_position">center-on-parent</property>
<property name="use_header_bar">1</property> <property name="use_header_bar">1</property>
<property name="destroy_with_parent">True</property> <property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property> <property name="hide-on-close">True</property>
<child type="titlebar"> <child type="titlebar">
<object class="GtkHeaderBar" id="titlebar"> <object class="GtkHeaderBar" id="titlebar">
<property name="visible">True</property> <property name="show-title-buttons">False</property>
<child> <child>
<object class="GtkButton" id="cancel_button"> <object class="GtkButton" id="cancel_button">
<property name="label" translatable="yes">Cancel</property> <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"/> <signal name="clicked" handler="on_cancel_button_clicked_cb" object="GcalEventEditorDialog" swapped="no"/>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkImage" id="lock"> <object class="GtkImage" id="lock">
<property name="visible" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default|invert-boolean" /> <property name="visible" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default|invert-boolean|sync-create" />
<property name="icon_name">changes-prevent-symbolic</property> <property name="icon_name">changes-prevent-symbolic</property>
<property name="icon_size">1</property>
</object> </object>
</child> </child>
<child type="title"> <child type="title">
<object class="GtkMenuButton" id="sources_button"> <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="popover">sources_popover</property>
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" /> <property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" />
<property name="tooltip-text" translatable="yes">Click to select the calendar</property> <property name="tooltip-text" translatable="yes">Click to select the calendar</property>
@@ -41,19 +33,13 @@
</style> </style>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property> <property name="spacing">6</property>
<child> <child>
<object class="GtkBox" id="title_label_box"> <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="orientation">vertical</property>
<property name="valign">center</property> <property name="valign">center</property>
<child> <child>
<object class="GtkLabel" id="title_label"> <object class="GtkLabel" id="title_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="ellipsize">middle</property> <property name="ellipsize">middle</property>
<property name="max_width_chars">40</property> <property name="max_width_chars">40</property>
<style> <style>
@@ -63,14 +49,10 @@
</child> </child>
<child> <child>
<object class="GtkBox" id="subtitle_box"> <object class="GtkBox" id="subtitle_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">horizontal</property> <property name="orientation">horizontal</property>
<property name="halign">center</property> <property name="halign">center</property>
<child> <child>
<object class="GtkImage" id="source_image"> <object class="GtkImage" id="source_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<style> <style>
<class name="calendar-color-image"/> <class name="calendar-color-image"/>
</style> </style>
@@ -78,8 +60,6 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="subtitle_label"> <object class="GtkLabel" id="subtitle_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<style> <style>
<class name="subtitle"/> <class name="subtitle"/>
</style> </style>
@@ -94,8 +74,6 @@
</child> </child>
<child> <child>
<object class="GtkImage" id="pan_down_image"> <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> <property name="icon_name">pan-down-symbolic</property>
</object> </object>
</child> </child>
@@ -103,40 +81,28 @@
</child> </child>
</object> </object>
</child> </child>
<child> <child type="end">
<object class="GtkButton" id="done_button"> <object class="GtkButton" id="done_button">
<property name="label" translatable="yes">Done</property> <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"/> <signal name="clicked" handler="on_done_button_clicked_cb" object="GcalEventEditorDialog" swapped="no"/>
<style> <style>
<class name="suggested-action"/> <class name="suggested-action"/>
</style> </style>
</object> </object>
<packing>
<property name="pack_type">end</property>
</packing>
</child> </child>
</object> </object>
</child> </child>
<child internal-child="vbox"> <child>
<object class="GtkBox" id="dialog-vbox"> <object class="GtkBox">
<property name="visible">true</property>
<property name="spacing">0</property>
<property name="border_width">0</property>
<child> <child>
<object class="HdyPreferencesPage"> <object class="AdwPreferencesPage">
<property name="visible">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<!-- Summary --> <!-- Summary -->
<child> <child>
<object class="HdyPreferencesGroup"> <object class="AdwPreferencesGroup">
<property name="visible">True</property>
<child> <child>
<object class="GcalSummarySection" id="summary_section"> <object class="GcalSummarySection" id="summary_section">
<property name="visible">True</property>
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" /> <property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" />
</object> </object>
</child> </child>
@@ -145,12 +111,10 @@
<!-- Schedule --> <!-- Schedule -->
<child> <child>
<object class="HdyPreferencesGroup"> <object class="AdwPreferencesGroup">
<property name="visible">True</property>
<property name="title" translatable="yes">Schedule</property> <property name="title" translatable="yes">Schedule</property>
<child> <child>
<object class="GcalScheduleSection" id="schedule_section"> <object class="GcalScheduleSection" id="schedule_section">
<property name="visible">True</property>
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" /> <property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" />
</object> </object>
</child> </child>
@@ -159,12 +123,10 @@
<!-- Reminders --> <!-- Reminders -->
<child> <child>
<object class="HdyPreferencesGroup"> <object class="AdwPreferencesGroup">
<property name="visible">True</property>
<property name="title" translatable="yes">Reminders</property> <property name="title" translatable="yes">Reminders</property>
<child> <child>
<object class="GcalRemindersSection" id="reminders_section"> <object class="GcalRemindersSection" id="reminders_section">
<property name="visible">True</property>
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" /> <property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" />
</object> </object>
</child> </child>
@@ -173,12 +135,10 @@
<!-- Notes --> <!-- Notes -->
<child> <child>
<object class="HdyPreferencesGroup"> <object class="AdwPreferencesGroup">
<property name="visible">True</property>
<property name="title" translatable="yes">Notes</property> <property name="title" translatable="yes">Notes</property>
<child> <child>
<object class="GcalNotesSection" id="notes_section"> <object class="GcalNotesSection" id="notes_section">
<property name="visible">True</property>
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" /> <property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" />
</object> </object>
</child> </child>
@@ -187,18 +147,14 @@
<!-- Delete Button --> <!-- Delete Button -->
<child> <child>
<object class="HdyPreferencesGroup"> <object class="AdwPreferencesGroup">
<property name="visible">True</property>
<child> <child>
<object class="GtkButton" id="delete_button"> <object class="GtkButton" id="delete_button">
<property name="visible">True</property>
<property name="halign">end</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"/> <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" /> <property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" />
<child> <child>
<object class="GtkLabel" id="delete_label"> <object class="GtkLabel" id="delete_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Delete Event</property> <property name="label" translatable="yes">Delete Event</property>
</object> </object>
</child> </child>
@@ -215,7 +171,7 @@
</object> </object>
</child> </child>
</template> </template>
<object class="GtkPopover" id="sources_popover"> <object class="GtkPopoverMenu" id="sources_popover">
</object> </object>
<object class="GtkSizeGroup"> <object class="GtkSizeGroup">
<property name="mode">vertical</property> <property name="mode">vertical</property>
+39 -39
View File
@@ -710,64 +710,53 @@ fix_popover_menu_icons (GtkPopover *popover)
GtkWidget *popover_stack; GtkWidget *popover_stack;
GtkWidget *menu_section; GtkWidget *menu_section;
GtkWidget *menu_section_box; GtkWidget *menu_section_box;
GList *stack_children; GtkWidget *widget;
GList *menu_section_children; GtkWidget *child;
GList *menu_section_box_children, *aux;
popover_stack = gtk_bin_get_child (GTK_BIN (popover)); /* GtkScrolledWindow */
stack_children = gtk_container_get_children (GTK_CONTAINER (popover_stack)); widget = gtk_popover_get_child (GTK_POPOVER (popover));
/** /* GtkViewport */
* At the moment, the popover stack surely contains only widget = gtk_scrolled_window_get_child (GTK_SCROLLED_WINDOW (widget));
* one child of type GtkMenuSectionBox, which contains
* a single GtkBox. /* GtkStack */
*/ popover_stack = gtk_viewport_get_child (GTK_VIEWPORT (widget));
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. * Get the unique box's children.
*/ */
menu_section_box = menu_section_children->data; menu_section_box = gtk_widget_get_first_child (menu_section);
menu_section_box_children = gtk_container_get_children (GTK_CONTAINER (menu_section_box));
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. * 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; GtkWidget *child2;
GList *button_box_children, *aux2;
button_box = gtk_bin_get_child (GTK_BIN (aux->data));
button_box_children = gtk_container_get_children (GTK_CONTAINER (button_box));
/** /**
* Since there is no guarantee that the first child is * Since there is no guarantee that the first child is
* the GtkImage we're looking for, we have to iterate * the GtkImage we're looking for, we have to iterate
* through the children and check if the types match. * 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 (child);
child2;
child2 = gtk_widget_get_next_sibling (child2))
{ {
GtkWidget *button_box_child; if (GTK_IS_IMAGE (child2))
button_box_child = aux2->data;
if (g_type_is_a (G_OBJECT_TYPE (button_box_child), GTK_TYPE_IMAGE))
{ {
gtk_style_context_add_class (gtk_widget_get_style_context (button_box_child), "calendar-color-image"); gtk_widget_add_css_class (child2, "calendar-color-image");
gtk_widget_show (button_box_child); gtk_widget_show (child2);
break; 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); 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: * ask_recurrence_modification_type:
* @parent: a #GtkWidget * @parent: a #GtkWidget
@@ -976,12 +973,12 @@ ask_recurrence_modification_type (GtkWidget *parent,
ECalClient *client; ECalClient *client;
GtkWidget *dialog; GtkWidget *dialog;
gboolean is_set; gboolean is_set;
gint result; gint result = 0;
flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT; flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
*modtype = GCAL_RECURRENCE_MOD_THIS_ONLY; *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, flags,
GTK_MESSAGE_QUESTION, GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE, 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), _("_Subsequent events"), GTK_RESPONSE_OK);
gtk_dialog_add_button (GTK_DIALOG (dialog), _("_All events"), GTK_RESPONSE_YES); 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) switch (result)
{ {
@@ -1027,7 +1027,7 @@ ask_recurrence_modification_type (GtkWidget *parent,
break; break;
} }
gtk_widget_destroy (GTK_WIDGET (dialog)); gtk_window_destroy (GTK_WINDOW (dialog));
return is_set; return is_set;
} }