[gnome-calendar/gbsneto/gtk4: 8/8] Rework calendar popover to be a button




commit 7098ccac3d0755d3080809e6ac5f2aa9ce4afda2
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Feb 3 17:49:20 2022 -0300

    Rework calendar popover to be a button
    
    This allows more precise control of the style and the contents
    of the popover.

 ...l-calendar-popover.c => gcal-calendar-button.c} |  78 +++++++---------
 ...l-calendar-popover.h => gcal-calendar-button.h} |  10 +-
 src/gui/gcal-calendar-button.ui                    | 101 +++++++++++++++++++++
 src/gui/gcal-calendar-popover.ui                   |  85 -----------------
 src/gui/gcal-window.c                              |  13 +--
 src/gui/gcal-window.ui                             |   9 +-
 src/gui/gui.gresource.xml                          |   2 +-
 src/gui/meson.build                                |   2 +-
 8 files changed, 146 insertions(+), 154 deletions(-)
---
diff --git a/src/gui/gcal-calendar-popover.c b/src/gui/gcal-calendar-button.c
similarity index 82%
rename from src/gui/gcal-calendar-popover.c
rename to src/gui/gcal-calendar-button.c
index 256d388f..ceb6d745 100644
--- a/src/gui/gcal-calendar-popover.c
+++ b/src/gui/gcal-calendar-button.c
@@ -1,4 +1,4 @@
-/* gcal-calendar-popover.c
+/* gcal-calendar-button.c
  *
  * Copyright 2019 Georges Basile Stavracas Neto <georges stavracas gmail com>
  *
@@ -18,20 +18,19 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#define G_LOG_DOMAIN "GcalCalendarPopover"
+#define G_LOG_DOMAIN "GcalCalendarButton"
 
 #include "gcal-calendar.h"
-#include "gcal-calendar-popover.h"
+#include "gcal-calendar-button.h"
 #include "gcal-context.h"
 #include "gcal-utils.h"
 
-struct _GcalCalendarPopover
+struct _GcalCalendarButton
 {
-  GtkPopover          parent;
+  AdwBin              parent;
 
   GtkWidget          *calendar_listbox;
   GtkStack           *icon_stack;
-  GtkWidget          *synchronize_button;
 
   GcalContext        *context;
 
@@ -40,7 +39,7 @@ struct _GcalCalendarPopover
 
 static gboolean      icon_change_timeout_cb                      (gpointer           data);
 
-G_DEFINE_TYPE (GcalCalendarPopover, gcal_calendar_popover, GTK_TYPE_POPOVER)
+G_DEFINE_TYPE (GcalCalendarButton, gcal_calendar_button, ADW_TYPE_BIN)
 
 enum
 {
@@ -107,7 +106,7 @@ make_calendar_row (GcalCalendar *calendar)
 }
 
 static void
-add_calendar (GcalCalendarPopover *self,
+add_calendar (GcalCalendarButton *self,
               GcalCalendar        *calendar)
 {
   GtkWidget *row;
@@ -117,7 +116,7 @@ add_calendar (GcalCalendarPopover *self,
 }
 
 static void
-remove_calendar (GcalCalendarPopover *self,
+remove_calendar (GcalCalendarButton *self,
                  GcalCalendar        *calendar)
 {
   GtkWidget *child;
@@ -137,7 +136,7 @@ remove_calendar (GcalCalendarPopover *self,
 }
 
 static void
-schedule_switch_to_spinner (GcalCalendarPopover *self)
+schedule_switch_to_spinner (GcalCalendarButton *self)
 {
   if (self->icon_changed_source_id > 0)
     return;
@@ -148,7 +147,7 @@ schedule_switch_to_spinner (GcalCalendarPopover *self)
 }
 
 static void
-schedule_switch_to_success (GcalCalendarPopover *self)
+schedule_switch_to_success (GcalCalendarButton *self)
 {
   g_clear_handle_id (&self->icon_changed_source_id, g_source_remove);
 
@@ -167,10 +166,10 @@ schedule_switch_to_success (GcalCalendarPopover *self)
 static gboolean
 icon_change_timeout_cb (gpointer data)
 {
-  GcalCalendarPopover *self;
+  GcalCalendarButton *self;
   GcalManager *manager;
 
-  self = GCAL_CALENDAR_POPOVER (data);
+  self = GCAL_CALENDAR_BUTTON (data);
   manager = gcal_context_get_manager (self->context);
 
   g_debug ("Updating calendar icon to spinner");
@@ -206,7 +205,7 @@ listbox_sort_func (GtkListBoxRow *row1,
 static void
 on_manager_calendar_added_cb (GcalManager         *manager,
                               GcalCalendar        *calendar,
-                              GcalCalendarPopover *self)
+                              GcalCalendarButton *self)
 {
   add_calendar (self, calendar);
 }
@@ -214,7 +213,7 @@ on_manager_calendar_added_cb (GcalManager         *manager,
 static void
 on_manager_calendar_changed_cb (GcalManager         *manager,
                                 GcalCalendar        *calendar,
-                                GcalCalendarPopover *self)
+                                GcalCalendarButton *self)
 {
   remove_calendar (self, calendar);
   add_calendar (self, calendar);
@@ -223,7 +222,7 @@ on_manager_calendar_changed_cb (GcalManager         *manager,
 static void
 on_manager_calendar_removed_cb (GcalManager         *manager,
                                 GcalCalendar        *calendar,
-                                GcalCalendarPopover *self)
+                                GcalCalendarButton *self)
 {
   remove_calendar (self, calendar);
 }
@@ -231,7 +230,7 @@ on_manager_calendar_removed_cb (GcalManager         *manager,
 static void
 on_manager_synchronizing_changed_cb (GcalManager         *manager,
                                      GParamSpec          *pspec,
-                                     GcalCalendarPopover *self)
+                                     GcalCalendarButton *self)
 {
   if (gcal_manager_get_synchronizing (manager))
     schedule_switch_to_spinner (self);
@@ -242,7 +241,7 @@ on_manager_synchronizing_changed_cb (GcalManager         *manager,
 static void
 on_listbox_row_activated_cb (GtkListBox          *listbox,
                              GtkListBoxRow       *row,
-                             GcalCalendarPopover *self)
+                             GcalCalendarButton *self)
 {
   GtkCheckButton *check = g_object_get_data (G_OBJECT (row), "check");
 
@@ -255,23 +254,23 @@ on_listbox_row_activated_cb (GtkListBox          *listbox,
  */
 
 static void
-gcal_calendar_popover_finalize (GObject *object)
+gcal_calendar_button_finalize (GObject *object)
 {
-  GcalCalendarPopover *self = (GcalCalendarPopover *)object;
+  GcalCalendarButton *self = (GcalCalendarButton *)object;
 
   g_clear_handle_id (&self->icon_changed_source_id, g_source_remove);
   g_clear_object (&self->context);
 
-  G_OBJECT_CLASS (gcal_calendar_popover_parent_class)->finalize (object);
+  G_OBJECT_CLASS (gcal_calendar_button_parent_class)->finalize (object);
 }
 
 static void
-gcal_calendar_popover_get_property (GObject    *object,
+gcal_calendar_button_get_property (GObject    *object,
                                     guint       prop_id,
                                     GValue     *value,
                                     GParamSpec *pspec)
 {
-  GcalCalendarPopover *self = GCAL_CALENDAR_POPOVER (object);
+  GcalCalendarButton *self = GCAL_CALENDAR_BUTTON (object);
 
   switch (prop_id)
     {
@@ -285,12 +284,12 @@ gcal_calendar_popover_get_property (GObject    *object,
 }
 
 static void
-gcal_calendar_popover_set_property (GObject      *object,
+gcal_calendar_button_set_property (GObject      *object,
                                     guint         prop_id,
                                     const GValue *value,
                                     GParamSpec   *pspec)
 {
-  GcalCalendarPopover *self = GCAL_CALENDAR_POPOVER (object);
+  GcalCalendarButton *self = GCAL_CALENDAR_BUTTON (object);
 
   switch (prop_id)
     {
@@ -309,11 +308,13 @@ gcal_calendar_popover_set_property (GObject      *object,
         for (l = calendars; l; l = l->next)
           add_calendar (self, l->data);
 
+        /*
         g_object_bind_property (manager,
                                 "synchronizing",
                                 self->synchronize_button,
                                 "sensitive",
                                 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
+         */
 
         g_signal_connect_object (manager, "calendar-added", G_CALLBACK (on_manager_calendar_added_cb), 
object, 0);
         g_signal_connect_object (manager, "calendar-removed", G_CALLBACK (on_manager_calendar_removed_cb), 
object, 0);
@@ -328,17 +329,17 @@ gcal_calendar_popover_set_property (GObject      *object,
 }
 
 static void
-gcal_calendar_popover_class_init (GcalCalendarPopoverClass *klass)
+gcal_calendar_button_class_init (GcalCalendarButtonClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
-  object_class->finalize = gcal_calendar_popover_finalize;
-  object_class->get_property = gcal_calendar_popover_get_property;
-  object_class->set_property = gcal_calendar_popover_set_property;
+  object_class->finalize = gcal_calendar_button_finalize;
+  object_class->get_property = gcal_calendar_button_get_property;
+  object_class->set_property = gcal_calendar_button_set_property;
 
   /**
-   * GcalCalendarPopover::context:
+   * GcalCalendarButton::context:
    *
    * The #GcalContext of the application.
    */
@@ -350,17 +351,16 @@ gcal_calendar_popover_class_init (GcalCalendarPopoverClass *klass)
 
   g_object_class_install_properties (object_class, N_PROPS, properties);
 
-  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/calendar/ui/gui/gcal-calendar-popover.ui");
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/calendar/ui/gui/gcal-calendar-button.ui");
 
-  gtk_widget_class_bind_template_child (widget_class, GcalCalendarPopover, calendar_listbox);
-  gtk_widget_class_bind_template_child (widget_class, GcalCalendarPopover, icon_stack);
-  gtk_widget_class_bind_template_child (widget_class, GcalCalendarPopover, synchronize_button);
+  gtk_widget_class_bind_template_child (widget_class, GcalCalendarButton, calendar_listbox);
+  gtk_widget_class_bind_template_child (widget_class, GcalCalendarButton, icon_stack);
 
   gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated_cb);
 }
 
 static void
-gcal_calendar_popover_init (GcalCalendarPopover *self)
+gcal_calendar_button_init (GcalCalendarButton *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
 
@@ -369,11 +369,3 @@ gcal_calendar_popover_init (GcalCalendarPopover *self)
                               self,
                               NULL);
 }
-
-GtkWidget*
-gcal_calendar_popover_get_icon (GcalCalendarPopover *self)
-{
-  g_return_val_if_fail (GCAL_IS_CALENDAR_POPOVER (self), NULL);
-
-  return GTK_WIDGET (self->icon_stack);
-}
diff --git a/src/gui/gcal-calendar-popover.h b/src/gui/gcal-calendar-button.h
similarity index 72%
rename from src/gui/gcal-calendar-popover.h
rename to src/gui/gcal-calendar-button.h
index 5cf0681c..e5750e9a 100644
--- a/src/gui/gcal-calendar-popover.h
+++ b/src/gui/gcal-calendar-button.h
@@ -1,4 +1,4 @@
-/* gcal-calendar-popover.h
+/* gcal-calendar-button.h
  *
  * Copyright 2019 Georges Basile Stavracas Neto <georges stavracas gmail com>
  *
@@ -20,13 +20,11 @@
 
 #pragma once
 
-#include <gtk/gtk.h>
+#include <adwaita.h>
 
 G_BEGIN_DECLS
 
-#define GCAL_TYPE_CALENDAR_POPOVER (gcal_calendar_popover_get_type())
-G_DECLARE_FINAL_TYPE (GcalCalendarPopover, gcal_calendar_popover, GCAL, CALENDAR_POPOVER, GtkPopover)
-
-GtkWidget*           gcal_calendar_popover_get_icon              (GcalCalendarPopover *self);
+#define GCAL_TYPE_CALENDAR_BUTTON (gcal_calendar_button_get_type())
+G_DECLARE_FINAL_TYPE (GcalCalendarButton, gcal_calendar_button, GCAL, CALENDAR_BUTTON, AdwBin)
 
 G_END_DECLS
diff --git a/src/gui/gcal-calendar-button.ui b/src/gui/gcal-calendar-button.ui
new file mode 100644
index 00000000..cbd70bcc
--- /dev/null
+++ b/src/gui/gcal-calendar-button.ui
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GcalCalendarButton" parent="AdwBin">
+    <child>
+      <object class="GtkMenuButton">
+        <property name="tooltip_text" translatable="yes">Manage your calendars</property>
+        <property name="popover">popover</property>
+        <style>
+          <class name="image-button" />
+        </style>
+
+        <child>
+          <object class="GtkStack" id="icon_stack">
+            <property name="transition-type">crossfade</property>
+            <property name="transition-duration">250</property>
+            <child>
+              <object class="GtkStackPage">
+                <property name="name">icon</property>
+                <property name="child">
+                  <object class="GtkImage" id="calendar_image">
+                    <property name="icon_name">x-office-calendar-symbolic</property>
+                  </object>
+                </property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkStackPage">
+                <property name="name">spinner</property>
+                <property name="child">
+                  <object class="GtkSpinner" id="refreshing_spinner">
+                    <property name="spinning">True</property>
+                    <property name="tooltip_text" translatable="yes" context="tooltip">Synchronizing remote 
calendars…</property>
+                  </object>
+                </property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkStackPage">
+                <property name="name">success</property>
+                <property name="child">
+                  <object class="GtkImage" id="success_image">
+                    <property name="icon_name">emblem-ok-symbolic</property>
+                  </object>
+                </property>
+              </object>
+            </child>
+          </object>
+        </child>
+
+      </object>
+    </child>
+  </template>
+
+  <menu id='menu'>
+    <section>
+      <item>
+        <attribute name="custom">list</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Synchronize Calendars</attribute>
+        <attribute name="action">app.sync</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Manage Calendars…</attribute>
+        <attribute name="action">win.show-calendars</attribute>
+      </item>
+    </section>
+  </menu>
+
+  <object class="GtkPopoverMenu" id="popover">
+    <property name="position">bottom</property>
+    <property name="menu-model">menu</property>
+
+    <child type="list">
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkScrolledWindow">
+            <property name="hscrollbar_policy">never</property>
+            <property name="max_content_height">450</property>
+            <property name="propagate-natural-height">True</property>
+            <child>
+              <object class="GtkListBox" id="calendar_listbox">
+                <property name="hexpand">True</property>
+                <property name="selection_mode">none</property>
+                <signal name="row-activated" handler="on_listbox_row_activated_cb" 
object="GcalCalendarButton" swapped="no"/>
+                <style>
+                  <class name="calendar-list"/>
+                </style>
+              </object>
+            </child>
+          </object>
+        </child>
+
+      </object>
+    </child>
+  </object>
+
+</interface>
diff --git a/src/gui/gcal-window.c b/src/gui/gcal-window.c
index 7c2673d1..216e6c2f 100644
--- a/src/gui/gcal-window.c
+++ b/src/gui/gcal-window.c
@@ -21,7 +21,7 @@
 
 #include "css-code.h"
 #include "gcal-calendar-management-dialog.h"
-#include "gcal-calendar-popover.h"
+#include "gcal-calendar-button.h"
 #include "config.h"
 #include "gcal-debug.h"
 #include "gcal-event-editor-dialog.h"
@@ -138,7 +138,6 @@ struct _GcalWindow
   AdwToast           *delete_event_toast;
 
   /* calendar management */
-  GtkWidget          *calendar_popover;
   GtkWidget          *calendar_management_dialog;
 
   gint                open_edit_dialog_timeout_id;
@@ -346,7 +345,6 @@ on_show_calendars_action_activated (GSimpleAction *action,
 {
   GcalWindow *window = GCAL_WINDOW (user_data);
 
-  gtk_widget_hide (window->calendar_popover);
   gtk_widget_show (window->calendar_management_dialog);
 }
 
@@ -838,7 +836,7 @@ gcal_window_constructed (GObject *object)
    * FIXME: this is a hack around the issue that happens when trying to bind
    * these properties using the GtkBuilder .ui file.
    */
-  g_object_bind_property (self, "context", self->calendar_popover, "context", G_BINDING_DEFAULT | 
G_BINDING_SYNC_CREATE);
+  g_object_bind_property (self, "context", self->calendars_button, "context", G_BINDING_DEFAULT | 
G_BINDING_SYNC_CREATE);
   g_object_bind_property (self, "context", self->weather_settings, "context", G_BINDING_DEFAULT | 
G_BINDING_SYNC_CREATE);
   g_object_bind_property (self, "context", self->calendar_management_dialog, "context", G_BINDING_DEFAULT | 
G_BINDING_SYNC_CREATE);
   g_object_bind_property (self, "context", self->week_view, "context", G_BINDING_DEFAULT | 
G_BINDING_SYNC_CREATE);
@@ -972,7 +970,7 @@ gcal_window_class_init (GcalWindowClass *klass)
   GtkWidgetClass *widget_class;
 
   g_type_ensure (GCAL_TYPE_CALENDAR_MANAGEMENT_DIALOG);
-  g_type_ensure (GCAL_TYPE_CALENDAR_POPOVER);
+  g_type_ensure (GCAL_TYPE_CALENDAR_BUTTON);
   g_type_ensure (GCAL_TYPE_EVENT_EDITOR_DIALOG);
   g_type_ensure (GCAL_TYPE_MANAGER);
   g_type_ensure (GCAL_TYPE_MONTH_VIEW);
@@ -1025,7 +1023,6 @@ gcal_window_class_init (GcalWindowClass *klass)
   /* widgets */
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, back_button);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, calendars_button);
-  gtk_widget_class_bind_template_child (widget_class, GcalWindow, calendar_popover);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, event_editor);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, forward_button);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, header_bar);
@@ -1078,10 +1075,6 @@ gcal_window_init (GcalWindow *self)
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  /* Calendar icon */
-  gtk_menu_button_set_child (GTK_MENU_BUTTON (self->calendars_button),
-                             gcal_calendar_popover_get_icon (GCAL_CALENDAR_POPOVER 
(self->calendar_popover)));
-
   self->views[GCAL_WINDOW_VIEW_WEEK] = self->week_view;
   self->views[GCAL_WINDOW_VIEW_MONTH] = self->month_view;
   self->views[GCAL_WINDOW_VIEW_YEAR] = self->year_view;
diff --git a/src/gui/gcal-window.ui b/src/gui/gcal-window.ui
index 6f86408f..0366b409 100644
--- a/src/gui/gcal-window.ui
+++ b/src/gui/gcal-window.ui
@@ -141,13 +141,7 @@
               </object>
             </child>
             <child type="end">
-              <object class="GtkMenuButton" id="calendars_button">
-                <property name="popover">calendar_popover</property>
-                <property name="tooltip_text" translatable="yes">Manage your calendars</property>
-                <style>
-                  <class name="image-button"/>
-                </style>
-              </object>
+              <object class="GcalCalendarButton" id="calendars_button" />
             </child>
             <child type="end">
               <object class="GcalSearchButton" id="search_button">
@@ -227,7 +221,6 @@
       </object>
     </child>
   </template>
-  <object class="GcalCalendarPopover" id="calendar_popover" />
   <object class="GcalQuickAddPopover" id="quick_add_popover">
     <signal name="edit-event" handler="edit_event" object="GcalWindow" swapped="no"/>
     <signal name="closed" handler="close_new_event_widget" object="GcalWindow" swapped="no"/>
diff --git a/src/gui/gui.gresource.xml b/src/gui/gui.gresource.xml
index 3a2e2ae9..594a4097 100644
--- a/src/gui/gui.gresource.xml
+++ b/src/gui/gui.gresource.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/org/gnome/calendar/ui/gui">
-    <file compressed="true">gcal-calendar-popover.ui</file>
+    <file compressed="true">gcal-calendar-button.ui</file>
     <file compressed="true">gcal-event-popover.ui</file>
     <file compressed="true">gcal-event-widget.ui</file>
     <file compressed="true">gcal-meeting-row.ui</file>
diff --git a/src/gui/meson.build b/src/gui/meson.build
index a0689764..78f68a9e 100644
--- a/src/gui/meson.build
+++ b/src/gui/meson.build
@@ -15,7 +15,7 @@ built_sources += gnome.compile_resources(
 
 sources += files(
   'gcal-application.c',
-  'gcal-calendar-popover.c',
+  'gcal-calendar-button.c',
   'gcal-event-popover.c',
   'gcal-event-widget.c',
   'gcal-meeting-row.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]