calendar-popover: Port to GTK4

This commit is contained in:
Georges Basile Stavracas Neto
2022-02-12 13:08:50 -03:00
parent c91f03feb1
commit 5ebab9f6d5
2 changed files with 40 additions and 52 deletions
+18 -24
View File
@@ -61,20 +61,19 @@ make_calendar_row (GcalCalendar *calendar)
{ {
g_autoptr (GdkPaintable) paintable = NULL; g_autoptr (GdkPaintable) paintable = NULL;
GtkWidget *label, *icon, *checkbox, *box, *row; GtkWidget *label, *icon, *checkbox, *box, *row;
GtkStyleContext *context;
const GdkRGBA *color; const GdkRGBA *color;
row = gtk_list_box_row_new (); row = gtk_list_box_row_new ();
/* apply some nice styling */ /* apply some nice styling */
context = gtk_widget_get_style_context (row); gtk_widget_add_css_class (row, "button");
gtk_style_context_add_class (context, "button"); gtk_widget_add_css_class (row, "flat");
gtk_style_context_add_class (context, "flat"); gtk_widget_add_css_class (row, "menuitem");
gtk_style_context_add_class (context, "menuitem");
/* main box */ /* main box */
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_container_set_border_width (GTK_CONTAINER (box), 6); gtk_widget_set_margin_start (box, 6);
gtk_widget_set_margin_end (box, 6);
/* source color icon */ /* source color icon */
color = gcal_calendar_get_color (calendar); color = gcal_calendar_get_color (calendar);
@@ -96,16 +95,14 @@ make_calendar_row (GcalCalendar *calendar)
"active", "active",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
gtk_container_add (GTK_CONTAINER (box), icon); gtk_box_append (GTK_BOX (box), icon);
gtk_container_add (GTK_CONTAINER (box), label); gtk_box_append (GTK_BOX (box), label);
gtk_container_add (GTK_CONTAINER (box), checkbox); gtk_box_append (GTK_BOX (box), checkbox);
gtk_container_add (GTK_CONTAINER (row), box); gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), box);
g_object_set_data (G_OBJECT (row), "check", checkbox); g_object_set_data (G_OBJECT (row), "check", checkbox);
g_object_set_data (G_OBJECT (row), "calendar", calendar); g_object_set_data (G_OBJECT (row), "calendar", calendar);
gtk_widget_show_all (row);
return row; return row;
} }
@@ -116,25 +113,24 @@ add_calendar (GcalCalendarPopover *self,
GtkWidget *row; GtkWidget *row;
row = make_calendar_row (calendar); row = make_calendar_row (calendar);
gtk_container_add (GTK_CONTAINER (self->calendar_listbox), row); gtk_list_box_append (GTK_LIST_BOX (self->calendar_listbox), row);
} }
static void static void
remove_calendar (GcalCalendarPopover *self, remove_calendar (GcalCalendarPopover *self,
GcalCalendar *calendar) GcalCalendar *calendar)
{ {
g_autoptr (GList) children = NULL; GtkWidget *child;
GList *aux;
children = gtk_container_get_children (GTK_CONTAINER (self->calendar_listbox)); for (child = gtk_widget_get_first_child (self->calendar_listbox);
child;
for (aux = children; aux != NULL; aux = aux->next) child = gtk_widget_get_next_sibling (child))
{ {
GcalCalendar *row_calendar = g_object_get_data (G_OBJECT (aux->data), "calendar"); GcalCalendar *row_calendar = g_object_get_data (G_OBJECT (child), "calendar");
if (row_calendar && row_calendar == calendar) if (row_calendar && row_calendar == calendar)
{ {
gtk_widget_destroy (aux->data); gtk_list_box_remove (GTK_LIST_BOX (self->calendar_listbox), child);
break; break;
} }
} }
@@ -248,11 +244,9 @@ on_listbox_row_activated_cb (GtkListBox *listbox,
GtkListBoxRow *row, GtkListBoxRow *row,
GcalCalendarPopover *self) GcalCalendarPopover *self)
{ {
GtkToggleButton *check; GtkCheckButton *check = g_object_get_data (G_OBJECT (row), "check");
check = (GtkToggleButton *) g_object_get_data (G_OBJECT (row), "check"); gtk_check_button_set_active (check, !gtk_check_button_get_active (check));
gtk_toggle_button_set_active (check, !gtk_toggle_button_get_active (check));
} }
+16 -22
View File
@@ -1,23 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<template class="GcalCalendarPopover" parent="GtkPopover"> <template class="GcalCalendarPopover" parent="GtkPopover">
<property name="can_focus">False</property>
<property name="position">bottom</property> <property name="position">bottom</property>
<property name="constrain_to">none</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin">6</property>
<child> <child>
<object class="GtkScrolledWindow"> <object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="hscrollbar_policy">never</property> <property name="hscrollbar_policy">never</property>
<property name="max_content_height">450</property> <property name="max_content_height">450</property>
<property name="propagate-natural-height">True</property> <property name="propagate-natural-height">True</property>
<child> <child>
<object class="GtkListBox" id="calendar_listbox"> <object class="GtkListBox" id="calendar_listbox">
<property name="visible">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="selection_mode">none</property> <property name="selection_mode">none</property>
<signal name="row-activated" handler="on_listbox_row_activated_cb" object="GcalCalendarPopover" swapped="no"/> <signal name="row-activated" handler="on_listbox_row_activated_cb" object="GcalCalendarPopover" swapped="no"/>
@@ -31,14 +25,12 @@
<child> <child>
<object class="GtkSeparator"> <object class="GtkSeparator">
<property name="visible">True</property>
</object> </object>
</child> </child>
<!-- Synchronize --> <!-- Synchronize -->
<child> <child>
<object class="GtkModelButton" id="synchronize_button"> <object class="GtkModelButton" id="synchronize_button">
<property name="visible">True</property>
<property name="action-name">app.sync</property> <property name="action-name">app.sync</property>
<property name="text" translatable="yes">_Synchronize Calendars</property> <property name="text" translatable="yes">_Synchronize Calendars</property>
</object> </object>
@@ -46,7 +38,6 @@
<child> <child>
<object class="GtkModelButton" id="calendar_settings_button"> <object class="GtkModelButton" id="calendar_settings_button">
<property name="visible">True</property>
<property name="action_name">win.show-calendars</property> <property name="action_name">win.show-calendars</property>
<property name="text" translatable="yes">Manage Calendars…</property> <property name="text" translatable="yes">Manage Calendars…</property>
</object> </object>
@@ -57,35 +48,38 @@
<!-- Icon --> <!-- Icon -->
<object class="GtkStack" id="icon_stack"> <object class="GtkStack" id="icon_stack">
<property name="visible">True</property>
<property name="transition-type">crossfade</property> <property name="transition-type">crossfade</property>
<property name="transition-duration">250</property> <property name="transition-duration">250</property>
<child> <child>
<object class="GtkStackPage">
<property name="name">icon</property>
<property name="child">
<object class="GtkImage" id="calendar_image"> <object class="GtkImage" id="calendar_image">
<property name="visible">True</property>
<property name="icon_name">x-office-calendar-symbolic</property> <property name="icon_name">x-office-calendar-symbolic</property>
</object> </object>
<packing> </property>
<property name="name">icon</property> </object>
</packing>
</child> </child>
<child> <child>
<object class="GtkStackPage">
<property name="name">spinner</property>
<property name="child">
<object class="GtkSpinner" id="refreshing_spinner"> <object class="GtkSpinner" id="refreshing_spinner">
<property name="active">True</property> <property name="spinning">True</property>
<property name="tooltip_text" translatable="yes" context="tooltip">Synchronizing remote calendars…</property> <property name="tooltip_text" translatable="yes" context="tooltip">Synchronizing remote calendars…</property>
</object> </object>
<packing> </property>
<property name="name">spinner</property> </object>
</packing>
</child> </child>
<child> <child>
<object class="GtkStackPage">
<property name="name">success</property>
<property name="child">
<object class="GtkImage" id="success_image"> <object class="GtkImage" id="success_image">
<property name="visible">True</property>
<property name="icon_name">emblem-ok-symbolic</property> <property name="icon_name">emblem-ok-symbolic</property>
</object> </object>
<packing> </property>
<property name="name">success</property> </object>
</packing>
</child> </child>
</object> </object>
</interface> </interface>