quick-add-popover: Port to GTK4

This commit is contained in:
Georges Basile Stavracas Neto
2022-02-11 09:18:38 -03:00
parent ffadcb4f4e
commit bd2ac18c19
2 changed files with 152 additions and 239 deletions
+19 -30
View File
@@ -88,7 +88,7 @@ create_calendar_row (GcalManager *manager,
paintable = get_circle_paintable_from_color (color, 16); paintable = get_circle_paintable_from_color (color, 16);
icon = gtk_image_new_from_paintable (paintable); icon = gtk_image_new_from_paintable (paintable);
gtk_container_add (GTK_CONTAINER (box), icon); gtk_box_append (GTK_BOX (box), icon);
gtk_style_context_add_class (gtk_widget_get_style_context (icon), "calendar-color-image"); gtk_style_context_add_class (gtk_widget_get_style_context (icon), "calendar-color-image");
@@ -96,11 +96,12 @@ create_calendar_row (GcalManager *manager,
label = gtk_label_new (gcal_calendar_get_name (calendar)); label = gtk_label_new (gcal_calendar_get_name (calendar));
gtk_widget_set_margin_end (label, 12); gtk_widget_set_margin_end (label, 12);
gtk_container_add (GTK_CONTAINER (box), label); gtk_box_append (GTK_BOX (box), label);
/* Selected icon */ /* Selected icon */
selected_icon = gtk_image_new_from_icon_name ("emblem-ok-symbolic", GTK_ICON_SIZE_BUTTON); selected_icon = gtk_image_new_from_icon_name ("emblem-ok-symbolic");
gtk_container_add (GTK_CONTAINER (box), selected_icon); gtk_widget_hide (selected_icon);
gtk_box_append (GTK_BOX (box), selected_icon);
/* The row itself */ /* The row itself */
row = gtk_list_box_row_new (); row = gtk_list_box_row_new ();
@@ -108,7 +109,7 @@ create_calendar_row (GcalManager *manager,
read_only = gcal_calendar_is_read_only (calendar); read_only = gcal_calendar_is_read_only (calendar);
gtk_widget_set_sensitive (row, !read_only); gtk_widget_set_sensitive (row, !read_only);
gtk_container_add (GTK_CONTAINER (row), box); gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), box);
/* Setup also a cool tooltip */ /* Setup also a cool tooltip */
get_source_parent_name_color (manager, gcal_calendar_get_source (calendar), &parent_name, NULL); get_source_parent_name_color (manager, gcal_calendar_get_source (calendar), &parent_name, NULL);
@@ -130,11 +131,6 @@ create_calendar_row (GcalManager *manager,
g_object_set_data (G_OBJECT (row), "color-icon", icon); g_object_set_data (G_OBJECT (row), "color-icon", icon);
g_object_set_data (G_OBJECT (row), "name-label", label); g_object_set_data (G_OBJECT (row), "name-label", label);
gtk_widget_show (label);
gtk_widget_show (icon);
gtk_widget_show (box);
gtk_widget_show (row);
g_free (parent_name); g_free (parent_name);
g_free (tooltip); g_free (tooltip);
@@ -149,26 +145,19 @@ static GtkWidget*
get_row_for_calendar (GcalQuickAddPopover *self, get_row_for_calendar (GcalQuickAddPopover *self,
GcalCalendar *calendar) GcalCalendar *calendar)
{ {
GList *children, *l;
GtkWidget *row; GtkWidget *row;
row = NULL; for (row = gtk_widget_get_first_child (self->calendars_listbox);
children = gtk_container_get_children (GTK_CONTAINER (self->calendars_listbox)); row;
row = gtk_widget_get_next_sibling (row))
for (l = children; l != NULL; l = g_list_next (l))
{ {
GcalCalendar *row_calendar = g_object_get_data (l->data, "calendar"); GcalCalendar *row_calendar = g_object_get_data (G_OBJECT (row), "calendar");
if (row_calendar == calendar) if (row_calendar == calendar)
{ return row;
row = l->data;
break;
}
} }
g_list_free (children); return NULL;
return row;
} }
static void static void
@@ -521,9 +510,9 @@ on_calendar_added (GcalManager *manager,
default_calendar = gcal_manager_get_default_calendar (manager); default_calendar = gcal_manager_get_default_calendar (manager);
row = create_calendar_row (manager, calendar); row = create_calendar_row (manager, calendar);
gtk_container_add (GTK_CONTAINER (self->calendars_listbox), row); gtk_list_box_append (GTK_LIST_BOX (self->calendars_listbox), row);
/* Select the default source whe first adding events */ /* Select the default source when first adding events */
if (calendar == default_calendar && !self->selected_row) if (calendar == default_calendar && !self->selected_row)
select_row (self, GTK_LIST_BOX_ROW (row)); select_row (self, GTK_LIST_BOX_ROW (row));
} }
@@ -545,7 +534,7 @@ on_calendar_changed (GcalManager *manager,
if (read_only) if (read_only)
{ {
if (row) if (row)
gtk_container_remove (GTK_CONTAINER (self->calendars_listbox), row); gtk_list_box_remove (GTK_LIST_BOX (self->calendars_listbox), row);
return; return;
} }
@@ -592,7 +581,7 @@ on_calendar_removed (GcalManager *manager,
if (!row) if (!row)
return; return;
gtk_container_remove (GTK_CONTAINER (self->calendars_listbox), row); gtk_list_box_remove (GTK_LIST_BOX (self->calendars_listbox), row);
} }
/* Sort the calendars by their display name */ /* Sort the calendars by their display name */
@@ -682,7 +671,7 @@ edit_or_create_event (GcalQuickAddPopover *self,
/* Gather the summary */ /* Gather the summary */
if (gtk_entry_get_text_length (GTK_ENTRY (self->summary_entry)) > 0) if (gtk_entry_get_text_length (GTK_ENTRY (self->summary_entry)) > 0)
summary = gtk_entry_get_text (GTK_ENTRY (self->summary_entry)); summary = gtk_editable_get_text (GTK_EDITABLE (self->summary_entry));
else else
summary = _("Unnamed event"); summary = _("Unnamed event");
@@ -825,7 +814,7 @@ gcal_quick_add_popover_closed (GtkPopover *popover)
self = GCAL_QUICK_ADD_POPOVER (popover); self = GCAL_QUICK_ADD_POPOVER (popover);
/* Clear text */ /* Clear text */
gtk_entry_set_text (GTK_ENTRY (self->summary_entry), ""); gtk_editable_set_text (GTK_EDITABLE (self->summary_entry), "");
/* Select the default row again */ /* Select the default row again */
update_default_calendar_row (self); update_default_calendar_row (self);
@@ -852,7 +841,7 @@ gcal_quick_add_popover_class_init (GcalQuickAddPopoverClass *klass)
* @self: a #GcalQuickAddPopover * @self: a #GcalQuickAddPopover
* @event: the new #GcalEvent * @event: the new #GcalEvent
* *
* Emited when the user clicks 'Edit event' button. * Emitted when the user clicks 'Edit event' button.
*/ */
signals[EDIT_EVENT] = g_signal_new ("edit-event", signals[EDIT_EVENT] = g_signal_new ("edit-event",
GCAL_TYPE_QUICK_ADD_POPOVER, GCAL_TYPE_QUICK_ADD_POPOVER,
+133 -209
View File
@@ -3,242 +3,166 @@
<requires lib="gtk+" version="3.16"/> <requires lib="gtk+" version="3.16"/>
<template class="GcalQuickAddPopover" parent="GtkPopover"> <template class="GcalQuickAddPopover" parent="GtkPopover">
<property name="width_request">350</property> <property name="width_request">350</property>
<property name="can_focus">False</property>
<signal name="show" handler="gtk_widget_grab_focus" object="summary_entry" swapped="yes" /> <signal name="show" handler="gtk_widget_grab_focus" object="summary_entry" swapped="yes" />
<child> <child>
<object class="GtkStack" id="stack"> <object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="border_width">12</property> <property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<property name="hhomogeneous">False</property> <property name="hhomogeneous">False</property>
<property name="vhomogeneous">True</property> <property name="vhomogeneous">True</property>
<property name="transition_type">slide-left-right</property> <property name="transition_type">slide-left-right</property>
<property name="interpolate_size">True</property> <property name="interpolate_size">True</property>
<child> <child>
<object class="GtkGrid"> <object class="GtkStackPage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_spacing">12</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkLabel" id="title_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">3</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="summary_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="hexpand">True</property>
<signal name="notify::text" handler="summary_entry_text_changed" object="GcalQuickAddPopover" swapped="no" />
<signal name="activate" handler="summary_entry_activated" object="GcalQuickAddPopover" swapped="no" />
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="select_calendar_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<signal name="clicked" handler="select_calendar_button_clicked" object="GcalQuickAddPopover" swapped="yes" />
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkImage" id="color_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
<style>
<class name="calendar-color-image"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="calendar_name_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-next-symbolic</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="width">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="edit_button">
<property name="label" translatable="yes">Edit Details…</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_top">6</property>
<signal name="clicked" handler="edit_or_create_event" object="GcalQuickAddPopover" swapped="yes" />
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="add_button">
<property name="label" translatable="yes">Add</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="sensitive">False</property>
<property name="margin_top">6</property>
<signal name="clicked" handler="edit_or_create_event" object="GcalQuickAddPopover" swapped="yes" />
<style>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">3</property>
</packing>
</child>
</object>
<packing>
<property name="name">events</property> <property name="name">events</property>
</packing> <property name="child">
</child> <object class="GtkGrid">
<child> <property name="row_spacing">12</property>
<object class="GtkBox"> <property name="column_spacing">12</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child> <child>
<object class="GtkButton" id="back_button"> <object class="GtkLabel" id="title_label">
<property name="visible">True</property> <property name="hexpand">True</property>
<property name="can_focus">True</property>
<property name="relief">none</property>
<signal name="clicked" handler="back_button_clicked" object="GcalQuickAddPopover" swapped="yes" />
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-previous-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child type="center">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Calendar</property>
<attributes> <attributes>
<attribute name="weight" value="bold"/> <attribute name="weight" value="bold"/>
</attributes> </attributes>
<layout>
<property name="column">0</property>
<property name="row">0</property>
<property name="column-span">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkEntry" id="summary_entry">
<property name="hexpand">True</property>
<signal name="notify::text" handler="summary_entry_text_changed" object="GcalQuickAddPopover" swapped="no" />
<signal name="activate" handler="summary_entry_activated" object="GcalQuickAddPopover" swapped="no" />
<layout>
<property name="column">0</property>
<property name="row">1</property>
<property name="column-span">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="select_calendar_button">
<property name="hexpand">True</property>
<signal name="clicked" handler="select_calendar_button_clicked" object="GcalQuickAddPopover" swapped="yes" />
<layout>
<property name="column">0</property>
<property name="row">2</property>
<property name="column-span">3</property>
</layout>
<child>
<object class="GtkBox">
<property name="spacing">12</property>
<child>
<object class="GtkImage" id="color_image">
<style>
<class name="calendar-color-image"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="calendar_name_label">
<property name="hexpand">True</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkImage">
<property name="icon_name">go-next-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton" id="edit_button">
<property name="label" translatable="yes">Edit Details…</property>
<property name="margin_top">6</property>
<signal name="clicked" handler="edit_or_create_event" object="GcalQuickAddPopover" swapped="yes" />
<layout>
<property name="column">0</property>
<property name="row">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="add_button">
<property name="label" translatable="yes">Add</property>
<property name="sensitive">False</property>
<property name="margin_top">6</property>
<signal name="clicked" handler="edit_or_create_event" object="GcalQuickAddPopover" swapped="yes" />
<layout>
<property name="column">2</property>
<property name="row">3</property>
</layout>
<style>
<class name="suggested-action"/>
</style>
</object> </object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child> </child>
</object> </object>
<packing> </property>
<property name="expand">False</property> </object>
<property name="fill">True</property> </child>
<property name="position">0</property> <child>
</packing> <object class="GtkStackPage">
</child> <property name="name">calendars</property>
<child> <property name="child">
<object class="GtkScrolledWindow"> <object class="GtkBox">
<property name="visible">True</property> <property name="orientation">vertical</property>
<property name="can_focus">False</property> <property name="spacing">6</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow_type">in</property>
<child> <child>
<object class="GtkViewport"> <object class="GtkCenterBox">
<property name="visible">True</property> <child type="start">
<property name="can_focus">False</property> <object class="GtkButton" id="back_button">
<property name="shadow_type">none</property> <property name="icon_name">go-previous-symbolic</property>
<child> <signal name="clicked" handler="back_button_clicked" object="GcalQuickAddPopover" swapped="yes" />
<object class="GtkListBox" id="calendars_listbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
<signal name="row-activated" handler="select_row" object="GcalQuickAddPopover" swapped="yes" />
<style> <style>
<class name="calendars-list"/> <class name="flat"/>
</style> </style>
</object> </object>
</child> </child>
<child type="center">
<object class="GtkLabel">
<property name="label" translatable="yes">Calendar</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child>
<object class="GtkViewport">
<property name="scroll-to-focus">True</property>
<child>
<object class="GtkListBox" id="calendars_listbox">
<property name="selection_mode">none</property>
<signal name="row-activated" handler="select_row" object="GcalQuickAddPopover" swapped="yes" />
<style>
<class name="calendars-list"/>
</style>
</object>
</child>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>
<packing> </property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object> </object>
<packing>
<property name="name">calendars</property>
<property name="position">1</property>
</packing>
</child> </child>
</object> </object>
</child> </child>