gui: introduce navigation button with date chooser

The navigation button provides access to a date chooser
at all times without requiring it to be permanently
visible, as done currently with the always-shown sidebar.

Signed-off-by: Markus Göllnitz <camelcasenick@bewares.it>
Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/542>
This commit is contained in:
Markus Göllnitz
2025-06-08 09:59:00 +00:00
committed by Marge Bot
parent df182ed942
commit 7904aba23c
5 changed files with 239 additions and 0 deletions
+152
View File
@@ -0,0 +1,152 @@
/* gcal-calendar-navigation-button.c
*
* Copyright 2025 Markus Göllnitz <camelcasenick@bewares.it>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#define G_LOG_DOMAIN "GcalCalendarNavigationButton"
#include <glib/gi18n.h>
#include "gcal-calendar-navigation-button.h"
#include "gcal-utils.h"
struct _GcalCalendarNavigationButton
{
AdwBin parent;
GDateTime *active_date;
gboolean active;
GtkMenuButton *button;
GtkStack *stack;
};
G_DEFINE_TYPE (GcalCalendarNavigationButton, gcal_calendar_navigation_button, ADW_TYPE_BIN)
enum
{
PROP_0,
PROP_ACTIVE_DATE,
PROP_ACTIVE,
N_PROPS
};
static GParamSpec *properties[N_PROPS];
/*
* GObject overrides
*/
static void
gcal_calendar_navigation_button_finalize (GObject *object)
{
GcalCalendarNavigationButton *self = (GcalCalendarNavigationButton *) object;
gcal_clear_date_time (&self->active_date);
G_OBJECT_CLASS (gcal_calendar_navigation_button_parent_class)->finalize (object);
}
static void
gcal_calendar_navigation_button_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GcalCalendarNavigationButton *self = GCAL_CALENDAR_NAVIGATION_BUTTON (object);
switch (prop_id)
{
case PROP_ACTIVE_DATE:
g_value_set_boxed (value, self->active_date);
break;
case PROP_ACTIVE:
g_value_set_boolean (value, self->active);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gcal_calendar_navigation_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GcalCalendarNavigationButton *self = GCAL_CALENDAR_NAVIGATION_BUTTON (object);
switch (prop_id)
{
case PROP_ACTIVE_DATE:
self->active_date = g_value_get_boxed (value);
/*
* Translators: %B is the month name and %Y is the year.
* More formats can be found on the doc:
* https://docs.gtk.org/glib/method.DateTime.format.html
*/
gtk_menu_button_set_label (self->button, g_date_time_format (self->active_date, _ ("%B %Y")));
break;
case PROP_ACTIVE:
self->active = g_value_get_boolean (value);
gtk_stack_set_visible_child_name (self->stack, self->active ? "active" : "inactive");
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gcal_calendar_navigation_button_class_init (GcalCalendarNavigationButtonClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = gcal_calendar_navigation_button_finalize;
object_class->get_property = gcal_calendar_navigation_button_get_property;
object_class->set_property = gcal_calendar_navigation_button_set_property;
properties[PROP_ACTIVE_DATE] = g_param_spec_boxed ("active-date",
NULL,
"The active/selected date",
G_TYPE_DATE_TIME,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
properties[PROP_ACTIVE] = g_param_spec_boolean ("active",
NULL,
"Whether the date chooser is active, or a static date should be displayed",
TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
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-navigation-button.ui");
gtk_widget_class_bind_template_child (widget_class, GcalCalendarNavigationButton, button);
gtk_widget_class_bind_template_child (widget_class, GcalCalendarNavigationButton, stack);
}
static void
gcal_calendar_navigation_button_init (GcalCalendarNavigationButton *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
+30
View File
@@ -0,0 +1,30 @@
/* gcal-calendar-navigation-button.h
*
* Copyright 2025 Markus Göllnitz <camelcasenick@bewares.it>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include <adwaita.h>
G_BEGIN_DECLS
#define GCAL_TYPE_CALENDAR_NAVIGATION_BUTTON (gcal_calendar_navigation_button_get_type ())
G_DECLARE_FINAL_TYPE (GcalCalendarNavigationButton, gcal_calendar_navigation_button, GCAL, CALENDAR_NAVIGATION_BUTTON, AdwBin)
G_END_DECLS
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GcalCalendarNavigationButton" parent="AdwBin">
<property name="child">
<object class="GtkStack" id="stack">
<property name="hhomogeneous">False</property>
<child>
<object class="GtkStackPage">
<property name="name">active</property>
<property name="child">
<object class="GtkMenuButton" id="button">
<property name="popover">popover_date_chooser</property>
<property name="label" translatable="yes">_Choose Date</property>
<property name="use-underline">True</property>
<property name="can-shrink">True</property>
<property name="tooltip-text" translatable="yes">Choose a Date</property>
<property name="always-show-arrow">True</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">inactive</property>
<property name="child">
<object class="GtkLabel" id="static_label">
<style>
<class name="heading" />
</style>
<property name="label" bind-source="button" bind-property="label" />
<property name="margin-start">9</property>
<property name="margin-end">9</property>
</object>
</property>
</object>
</child>
<property name="visible-child-name">active</property>
</object>
</property>
</template>
<object class="GtkPopover" id="popover_date_chooser">
<property name="position">bottom</property>
<property name="child">
<object class="GcalDateChooser">
<property name="split-month-year">True</property>
<property name="vexpand">False</property>
<property name="valign">end</property>
<property name="active-date" bind-source="GcalCalendarNavigationButton" bind-property="active-date" bind-flags="bidirectional" />
</object>
</property>
</object>
</interface>
+1
View File
@@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/org/gnome/calendar/ui/gui">
<file compressed="true">gcal-calendar-list.ui</file>
<file compressed="true">gcal-calendar-navigation-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>
+1
View File
@@ -17,6 +17,7 @@ built_sources += gnome.compile_resources(
sources += files(
'gcal-application.c',
'gcal-calendar-list.c',
'gcal-calendar-navigation-button.c',
'gcal-drop-overlay.c',
'gcal-event-popover.c',
'gcal-event-widget.c',