calendar-management: Switch to HdyWindow

Make GcalCalendarManagementDialog an HdyWindow subclass,
and adapt the widgetry to work with the new parent class.

Use HdyHeaderBar everywhere.
This commit is contained in:
Georges Basile Stavracas Neto
2021-08-06 17:32:58 -03:00
parent 36278b1bb4
commit 8c71c60e8d
7 changed files with 68 additions and 65 deletions
@@ -55,9 +55,9 @@ typedef enum
struct _GcalCalendarManagementDialog struct _GcalCalendarManagementDialog
{ {
GtkDialog parent; HdyWindow parent;
GtkWidget *headerbar; HdyHeaderBar *headerbar;
GtkWidget *notebook; GtkWidget *notebook;
GtkWidget *stack; GtkWidget *stack;
@@ -77,7 +77,7 @@ static void on_page_switched_cb (GcalCalendarMa
GcalCalendar *calendar, GcalCalendar *calendar,
GcalCalendarManagementDialog *self); GcalCalendarManagementDialog *self);
G_DEFINE_TYPE (GcalCalendarManagementDialog, gcal_calendar_management_dialog, GTK_TYPE_DIALOG) G_DEFINE_TYPE (GcalCalendarManagementDialog, gcal_calendar_management_dialog, HDY_TYPE_WINDOW)
enum enum
{ {
@@ -115,7 +115,7 @@ set_page (GcalCalendarManagementDialog *self,
gtk_stack_set_visible_child (GTK_STACK (self->stack), GTK_WIDGET (page)); gtk_stack_set_visible_child (GTK_STACK (self->stack), GTK_WIDGET (page));
gcal_calendar_management_page_activate (page, calendar); gcal_calendar_management_page_activate (page, calendar);
gtk_header_bar_set_title (GTK_HEADER_BAR (self->headerbar), hdy_header_bar_set_title (self->headerbar,
gcal_calendar_management_page_get_title (page)); gcal_calendar_management_page_get_title (page));
break; break;
} }
@@ -184,13 +184,19 @@ on_page_switched_cb (GcalCalendarManagementPage *page,
GCAL_EXIT; GCAL_EXIT;
} }
/*
* GtkWidget overrides
*/
static void static void
on_dialog_response_signal_cb (GtkDialog *dialog, gcal_calendar_management_dialog_hide (GtkWidget *widget)
gint response_id,
GcalCalendarManagementDialog *self)
{ {
GcalCalendarManagementDialog *self = (GcalCalendarManagementDialog *) widget;
set_page (self, "calendars", NULL); set_page (self, "calendars", NULL);
gtk_widget_hide (GTK_WIDGET (dialog));
GTK_WIDGET_CLASS (gcal_calendar_management_dialog_parent_class)->hide (widget);
} }
@@ -198,22 +204,6 @@ on_dialog_response_signal_cb (GtkDialog *dialog,
* GObject overrides * GObject overrides
*/ */
static void
gcal_calendar_management_dialog_constructed (GObject *object)
{
GcalCalendarManagementDialog *self;
self = GCAL_CALENDAR_MANAGEMENT_DIALOG (object);
G_OBJECT_CLASS (gcal_calendar_management_dialog_parent_class)->constructed (object);
/* widget responses */
gtk_dialog_set_default_response (GTK_DIALOG (object), GTK_RESPONSE_CANCEL);
/* setup titlebar */
gtk_window_set_titlebar (GTK_WINDOW (object), self->headerbar);
}
static void static void
gcal_calendar_management_dialog_get_property (GObject *object, gcal_calendar_management_dialog_get_property (GObject *object,
guint prop_id, guint prop_id,
@@ -262,10 +252,11 @@ gcal_calendar_management_dialog_class_init (GcalCalendarManagementDialogClass *k
g_type_ensure (E_TYPE_SOURCE_LOCAL); g_type_ensure (E_TYPE_SOURCE_LOCAL);
object_class->constructed = gcal_calendar_management_dialog_constructed;
object_class->get_property = gcal_calendar_management_dialog_get_property; object_class->get_property = gcal_calendar_management_dialog_get_property;
object_class->set_property = gcal_calendar_management_dialog_set_property; object_class->set_property = gcal_calendar_management_dialog_set_property;
widget_class->hide = gcal_calendar_management_dialog_hide;
properties[PROP_CONTEXT] = g_param_spec_object ("context", properties[PROP_CONTEXT] = g_param_spec_object ("context",
"Context", "Context",
"The context object of the application", "The context object of the application",
@@ -278,8 +269,6 @@ gcal_calendar_management_dialog_class_init (GcalCalendarManagementDialogClass *k
gtk_widget_class_bind_template_child (widget_class, GcalCalendarManagementDialog, headerbar); gtk_widget_class_bind_template_child (widget_class, GcalCalendarManagementDialog, headerbar);
gtk_widget_class_bind_template_child (widget_class, GcalCalendarManagementDialog, stack); gtk_widget_class_bind_template_child (widget_class, GcalCalendarManagementDialog, stack);
gtk_widget_class_bind_template_callback (widget_class, on_dialog_response_signal_cb);
} }
static void static void
@@ -287,3 +276,11 @@ gcal_calendar_management_dialog_init (GcalCalendarManagementDialog *self)
{ {
gtk_widget_init_template (GTK_WIDGET (self)); gtk_widget_init_template (GTK_WIDGET (self));
} }
HdyHeaderBar*
gcal_calendar_management_dialog_get_titlebar (GcalCalendarManagementDialog *self)
{
g_return_val_if_fail (GCAL_IS_CALENDAR_MANAGEMENT_DIALOG (self), NULL);
return HDY_HEADER_BAR (self->headerbar);
}
@@ -19,12 +19,11 @@
#pragma once #pragma once
#include <glib-object.h>
#include "gcal-application.h" #include "gcal-application.h"
#include "gcal-manager.h" #include "gcal-manager.h"
#include <libecal/libecal.h> #include <libecal/libecal.h>
#include <gtk/gtk.h> #include <handy.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@@ -35,6 +34,8 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GcalCalendarManagementDialog, G_DECLARE_FINAL_TYPE (GcalCalendarManagementDialog,
gcal_calendar_management_dialog, gcal_calendar_management_dialog,
GCAL, CALENDAR_MANAGEMENT_DIALOG, GCAL, CALENDAR_MANAGEMENT_DIALOG,
GtkDialog) HdyWindow)
HdyHeaderBar* gcal_calendar_management_dialog_get_titlebar (GcalCalendarManagementDialog *self);
G_END_DECLS G_END_DECLS
@@ -2,7 +2,7 @@
<!-- Generated with glade 3.18.1 --> <!-- Generated with glade 3.18.1 -->
<interface> <interface>
<requires lib="gtk+" version="3.15"/> <requires lib="gtk+" version="3.15"/>
<template class="GcalCalendarManagementDialog" parent="GtkDialog"> <template class="GcalCalendarManagementDialog" parent="HdyWindow">
<property name="width_request">450</property> <property name="width_request">450</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="border_width">0</property> <property name="border_width">0</property>
@@ -12,36 +12,40 @@
<property name="modal">True</property> <property name="modal">True</property>
<property name="destroy_with_parent">True</property> <property name="destroy_with_parent">True</property>
<property name="modal">True</property> <property name="modal">True</property>
<signal name="response" handler="on_dialog_response_signal_cb" object="GcalCalendarManagementDialog" swapped="no"/> <child>
<child internal-child="vbox"> <object class="HdyDeck">
<object class="GtkBox" id="vbox"> <property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="border_width">0</property>
<child> <child>
<object class="GtkOverlay" id="overlay"> <object class="GtkBox" id="vbox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="orientation">vertical</property>
<child> <child>
<object class="GtkStack" id="stack"> <object class="HdyHeaderBar" id="headerbar">
<property name="visible">True</property> <property name="visible">True</property>
<property name="hexpand">True</property> <property name="title" translatable="yes">Calendar Settings</property>
<property name="vexpand">True</property> <property name="show_close_button">True</property>
<property name="vhomogeneous">False</property>
<property name="transition_type">crossfade</property>
</object> </object>
</child> </child>
<child>
<object class="GtkOverlay" id="overlay">
<property name="visible">True</property>
<child>
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="vhomogeneous">False</property>
<property name="transition_type">crossfade</property>
</object>
</child>
</object>
</child>
</object> </object>
<packing>
<property name="position">1</property>
</packing>
</child> </child>
</object> </object>
</child> </child>
<child type="titlebar">
<object class="GtkHeaderBar" id="headerbar">
<property name="visible">True</property>
<property name="title" translatable="yes">Calendar Settings</property>
<property name="show_close_button">True</property>
</object>
</child>
</template> </template>
</interface> </interface>
@@ -20,6 +20,7 @@
#define G_LOG_DOMAIN "GcalCalendarManagementPage" #define G_LOG_DOMAIN "GcalCalendarManagementPage"
#include "gcal-calendar-management-dialog.h"
#include "gcal-calendar-management-page.h" #include "gcal-calendar-management-page.h"
#include "gcal-context.h" #include "gcal-context.h"
@@ -107,7 +108,7 @@ gcal_calendar_management_page_switch_page (GcalCalendarManagementPage *self,
g_signal_emit (self, signals[SWITCH_PAGE], 0, page_name, calendar); g_signal_emit (self, signals[SWITCH_PAGE], 0, page_name, calendar);
} }
GtkHeaderBar* HdyHeaderBar*
gcal_calendar_management_page_get_titlebar (GcalCalendarManagementPage *self) gcal_calendar_management_page_get_titlebar (GcalCalendarManagementPage *self)
{ {
GtkWidget *toplevel; GtkWidget *toplevel;
@@ -115,5 +116,5 @@ gcal_calendar_management_page_get_titlebar (GcalCalendarManagementPage *self)
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self)); toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
g_assert (toplevel != NULL); g_assert (toplevel != NULL);
return GTK_HEADER_BAR (gtk_window_get_titlebar (GTK_WINDOW (toplevel))); return gcal_calendar_management_dialog_get_titlebar (GCAL_CALENDAR_MANAGEMENT_DIALOG (toplevel));
} }
@@ -20,7 +20,7 @@
#pragma once #pragma once
#include <gtk/gtk.h> #include <handy.h>
#include "gcal-calendar.h" #include "gcal-calendar.h"
@@ -61,6 +61,6 @@ void gcal_calendar_management_page_switch_page (GcalCalendarMa
const gchar *page_name, const gchar *page_name,
GcalCalendar *calendar); GcalCalendar *calendar);
GtkHeaderBar* gcal_calendar_management_page_get_titlebar (GcalCalendarManagementPage *self); HdyHeaderBar* gcal_calendar_management_page_get_titlebar (GcalCalendarManagementPage *self);
G_END_DECLS G_END_DECLS
@@ -307,11 +307,11 @@ gcal_edit_calendar_page_activate (GcalCalendarManagementPage *page,
GcalCalendar *calendar) GcalCalendar *calendar)
{ {
GcalEditCalendarPage *self; GcalEditCalendarPage *self;
GtkHeaderBar *headerbar; HdyHeaderBar *headerbar;
self = GCAL_EDIT_CALENDAR_PAGE (page); self = GCAL_EDIT_CALENDAR_PAGE (page);
headerbar = gcal_calendar_management_page_get_titlebar (page); headerbar = gcal_calendar_management_page_get_titlebar (page);
gtk_header_bar_pack_start (headerbar, self->back_button); hdy_header_bar_pack_start (headerbar, self->back_button);
setup_calendar (self, calendar); setup_calendar (self, calendar);
} }
@@ -320,7 +320,7 @@ static void
gcal_edit_calendar_page_deactivate (GcalCalendarManagementPage *page) gcal_edit_calendar_page_deactivate (GcalCalendarManagementPage *page)
{ {
GcalEditCalendarPage *self; GcalEditCalendarPage *self;
GtkHeaderBar *headerbar; HdyHeaderBar *headerbar;
GcalManager *manager; GcalManager *manager;
GCAL_ENTRY; GCAL_ENTRY;
@@ -518,16 +518,16 @@ gcal_new_calendar_page_activate (GcalCalendarManagementPage *page,
GcalCalendar *calendar) GcalCalendar *calendar)
{ {
GcalNewCalendarPage *self; GcalNewCalendarPage *self;
GtkHeaderBar *headerbar; HdyHeaderBar *headerbar;
GCAL_ENTRY; GCAL_ENTRY;
self = GCAL_NEW_CALENDAR_PAGE (page); self = GCAL_NEW_CALENDAR_PAGE (page);
headerbar = gcal_calendar_management_page_get_titlebar (page); headerbar = gcal_calendar_management_page_get_titlebar (page);
gtk_header_bar_pack_start (headerbar, self->cancel_button); hdy_header_bar_pack_start (headerbar, self->cancel_button);
gtk_header_bar_pack_end (headerbar, self->add_button); hdy_header_bar_pack_end (headerbar, self->add_button);
gtk_header_bar_set_show_close_button (headerbar, FALSE); hdy_header_bar_set_show_close_button (headerbar, FALSE);
GCAL_EXIT; GCAL_EXIT;
} }
@@ -535,7 +535,7 @@ static void
gcal_new_calendar_page_deactivate (GcalCalendarManagementPage *page) gcal_new_calendar_page_deactivate (GcalCalendarManagementPage *page)
{ {
GcalNewCalendarPage *self; GcalNewCalendarPage *self;
GtkHeaderBar *headerbar; HdyHeaderBar *headerbar;
GCAL_ENTRY; GCAL_ENTRY;
@@ -544,7 +544,7 @@ gcal_new_calendar_page_deactivate (GcalCalendarManagementPage *page)
gtk_container_remove (GTK_CONTAINER (headerbar), self->cancel_button); gtk_container_remove (GTK_CONTAINER (headerbar), self->cancel_button);
gtk_container_remove (GTK_CONTAINER (headerbar), self->add_button); gtk_container_remove (GTK_CONTAINER (headerbar), self->add_button);
gtk_header_bar_set_show_close_button (headerbar, TRUE); hdy_header_bar_set_show_close_button (headerbar, TRUE);
g_clear_object (&self->local_source); g_clear_object (&self->local_source);
g_clear_pointer (&self->remote_sources, g_ptr_array_unref); g_clear_pointer (&self->remote_sources, g_ptr_array_unref);