views/week-view: Replace "context" property with context getter method
Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/702>
This commit is contained in:
@@ -1225,7 +1225,6 @@ 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->week_view, "context", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
|
||||
g_object_bind_property (self, "context", self->month_view, "context", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
|
||||
g_object_bind_property (self, "context", self->agenda_view, "context", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
|
||||
g_object_bind_property (self, "context", self->date_chooser, "context", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
|
||||
|
||||
@@ -76,8 +76,6 @@ struct _GcalWeekGrid
|
||||
GtkWidget *widget;
|
||||
gint event_minutes;
|
||||
} dnd;
|
||||
|
||||
GcalContext *context;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (GcalWeekGrid, gcal_week_grid, GTK_TYPE_WIDGET);
|
||||
@@ -352,7 +350,7 @@ move_event_to_cell (GcalWeekGrid *self,
|
||||
guint cell,
|
||||
GcalRecurrenceModType mod_type)
|
||||
{
|
||||
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
g_autoptr (GDateTime) week_start = NULL;
|
||||
g_autoptr (GDateTime) dnd_date = NULL;
|
||||
g_autoptr (GDateTime) new_end = NULL;
|
||||
@@ -392,7 +390,7 @@ move_event_to_cell (GcalWeekGrid *self,
|
||||
gcal_event_set_date_end (changed_event, new_end);
|
||||
|
||||
/* Commit the changes */
|
||||
gcal_manager_update_event (gcal_context_get_manager (self->context), changed_event, mod_type);
|
||||
gcal_manager_update_event (gcal_context_get_manager (context), changed_event, mod_type);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -861,6 +859,7 @@ gcal_week_grid_class_init (GcalWeekGridClass *klass)
|
||||
static void
|
||||
gcal_week_grid_init (GcalWeekGrid *self)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
GtkDropTarget *drop_target;
|
||||
GtkGesture *click_gesture;
|
||||
|
||||
@@ -900,16 +899,6 @@ gcal_week_grid_init (GcalWeekGrid *self)
|
||||
g_signal_connect (drop_target, "leave", G_CALLBACK (on_drop_target_leave_cb), self);
|
||||
g_signal_connect (drop_target, "motion", G_CALLBACK (on_drop_target_motion_cb), self);
|
||||
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (drop_target));
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
void
|
||||
gcal_week_grid_set_context (GcalWeekGrid *self,
|
||||
GcalContext *context)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_GRID (self));
|
||||
|
||||
self->context = context;
|
||||
|
||||
g_signal_connect_object (gcal_context_get_clock (context),
|
||||
"minute-changed",
|
||||
@@ -918,10 +907,12 @@ gcal_week_grid_set_context (GcalWeekGrid *self,
|
||||
G_CONNECT_SWAPPED);
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
void
|
||||
gcal_week_grid_add_event (GcalWeekGrid *self,
|
||||
GcalEvent *event)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
GtkWidget *widget;
|
||||
|
||||
g_return_if_fail (GCAL_IS_WEEK_GRID (self));
|
||||
@@ -929,7 +920,7 @@ gcal_week_grid_add_event (GcalWeekGrid *self,
|
||||
g_object_ref (event);
|
||||
|
||||
widget = g_object_new (GCAL_TYPE_EVENT_WIDGET,
|
||||
"context", self->context,
|
||||
"context", context,
|
||||
"event", event,
|
||||
"orientation", GTK_ORIENTATION_VERTICAL,
|
||||
"timestamp-policy", GCAL_TIMESTAMP_POLICY_START,
|
||||
|
||||
@@ -30,9 +30,6 @@ G_BEGIN_DECLS
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GcalWeekGrid, gcal_week_grid, GCAL, WEEK_GRID, GtkWidget)
|
||||
|
||||
void gcal_week_grid_set_context (GcalWeekGrid *week_grid,
|
||||
GcalContext *context);
|
||||
|
||||
void gcal_week_grid_set_first_weekday (GcalWeekGrid *week_grid,
|
||||
gint nr_day);
|
||||
|
||||
|
||||
@@ -78,8 +78,6 @@ struct _GcalWeekHeader
|
||||
GtkBox *weekdays_box;
|
||||
GtkWidget *main_box;
|
||||
|
||||
GcalContext *context;
|
||||
|
||||
/*
|
||||
* Stores the events as they come from the week-view
|
||||
* The list will later be iterated after the active date is changed
|
||||
@@ -214,6 +212,7 @@ clear_weather_infos (GcalWeekHeader *self)
|
||||
static void
|
||||
update_weather_infos (GcalWeekHeader *self)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
GPtrArray *weather_infos;
|
||||
GcalWeatherService *service;
|
||||
|
||||
@@ -221,8 +220,7 @@ update_weather_infos (GcalWeekHeader *self)
|
||||
|
||||
clear_weather_infos (self);
|
||||
|
||||
g_assert (self->context);
|
||||
service = gcal_context_get_weather_service (self->context);
|
||||
service = gcal_context_get_weather_service (context);
|
||||
|
||||
weather_infos = gcal_weather_service_get_weather_infos (service);
|
||||
add_weather_infos (self, weather_infos);
|
||||
@@ -787,6 +785,7 @@ add_event_to_grid (GcalWeekHeader *self,
|
||||
gint start,
|
||||
gint end)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
g_autoptr (GDateTime) week_start = NULL;
|
||||
g_autoptr (GDateTime) week_end = NULL;
|
||||
GtkLayoutManager *layout_manager;
|
||||
@@ -804,7 +803,7 @@ add_event_to_grid (GcalWeekHeader *self,
|
||||
move_events_at_column (self, DOWN, start, position);
|
||||
|
||||
/* Add the event to the grid */
|
||||
widget = gcal_event_widget_new (self->context, event);
|
||||
widget = gcal_event_widget_new (context, event);
|
||||
setup_event_widget (self, widget);
|
||||
|
||||
gtk_grid_attach (self->grid,
|
||||
@@ -1138,6 +1137,7 @@ move_event_to_cell (GcalWeekHeader *self,
|
||||
guint cell,
|
||||
GcalRecurrenceModType mod_type)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
g_autoptr (GDateTime) week_start = NULL;
|
||||
g_autoptr (GDateTime) dnd_date = NULL;
|
||||
g_autoptr (GDateTime) new_end = NULL;
|
||||
@@ -1194,7 +1194,7 @@ move_event_to_cell (GcalWeekHeader *self,
|
||||
gcal_event_set_date_start (changed_event, dnd_date);
|
||||
|
||||
/* Commit the changes */
|
||||
gcal_manager_update_event (gcal_context_get_manager (self->context), changed_event, mod_type);
|
||||
gcal_manager_update_event (gcal_context_get_manager (context), changed_event, mod_type);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1542,6 +1542,7 @@ gcal_week_header_class_init (GcalWeekHeaderClass *kclass)
|
||||
static void
|
||||
gcal_week_header_init (GcalWeekHeader *self)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
GtkDropTarget *drop_target;
|
||||
gint i;
|
||||
|
||||
@@ -1596,15 +1597,6 @@ gcal_week_header_init (GcalWeekHeader *self)
|
||||
g_signal_connect (drop_target, "leave", G_CALLBACK (on_drop_target_leave_cb), self);
|
||||
g_signal_connect (drop_target, "motion", G_CALLBACK (on_drop_target_motion_cb), self);
|
||||
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (drop_target));
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_header_set_context (GcalWeekHeader *self,
|
||||
GcalContext *context)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
|
||||
|
||||
self->context = context;
|
||||
|
||||
g_signal_connect_object (gcal_context_get_clock (context),
|
||||
"day-changed",
|
||||
@@ -1612,7 +1604,7 @@ gcal_week_header_set_context (GcalWeekHeader *self,
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
g_signal_connect_object (gcal_context_get_weather_service (self->context),
|
||||
g_signal_connect_object (gcal_context_get_weather_service (context),
|
||||
"weather-changed",
|
||||
G_CALLBACK (on_weather_update),
|
||||
self,
|
||||
|
||||
@@ -32,9 +32,6 @@ G_BEGIN_DECLS
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GcalWeekHeader, gcal_week_header, GCAL, WEEK_HEADER, GtkWidget)
|
||||
|
||||
void gcal_week_header_set_context (GcalWeekHeader *self,
|
||||
GcalContext *context);
|
||||
|
||||
void gcal_week_header_add_event (GcalWeekHeader *self,
|
||||
GcalEvent *event);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "gcal-week-hour-bar.h"
|
||||
#include "gcal-week-view-common.h"
|
||||
#include "gcal-utils.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
@@ -28,8 +29,6 @@ struct _GcalWeekHourBar
|
||||
GtkBox parent_instance;
|
||||
|
||||
GtkLabel *labels[24];
|
||||
|
||||
GcalContext *context;
|
||||
};
|
||||
|
||||
G_DEFINE_FINAL_TYPE (GcalWeekHourBar, gcal_week_hour_bar, GTK_TYPE_BOX)
|
||||
@@ -37,10 +36,11 @@ G_DEFINE_FINAL_TYPE (GcalWeekHourBar, gcal_week_hour_bar, GTK_TYPE_BOX)
|
||||
static void
|
||||
update_labels (GcalWeekHourBar *self)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
GcalTimeFormat time_format;
|
||||
gint i;
|
||||
|
||||
time_format = gcal_context_get_time_format (self->context);
|
||||
time_format = gcal_context_get_time_format (context);
|
||||
|
||||
for (i = 0; i < 24; i++)
|
||||
{
|
||||
@@ -92,6 +92,7 @@ gcal_week_hour_bar_class_init (GcalWeekHourBarClass *klass)
|
||||
static void
|
||||
gcal_week_hour_bar_init (GcalWeekHourBar *self)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
gint i;
|
||||
|
||||
g_object_set (self,
|
||||
@@ -112,15 +113,6 @@ gcal_week_hour_bar_init (GcalWeekHourBar *self)
|
||||
|
||||
self->labels[i] = GTK_LABEL (label);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_hour_bar_set_context (GcalWeekHourBar *self,
|
||||
GcalContext *context)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_HOUR_BAR (self));
|
||||
|
||||
self->context = context;
|
||||
|
||||
g_signal_connect_object (context,
|
||||
"notify::time-format",
|
||||
|
||||
@@ -29,7 +29,4 @@ G_BEGIN_DECLS
|
||||
#define GCAL_TYPE_WEEK_HOUR_BAR (gcal_week_hour_bar_get_type())
|
||||
G_DECLARE_FINAL_TYPE (GcalWeekHourBar, gcal_week_hour_bar, GCAL, WEEK_HOUR_BAR, GtkBox)
|
||||
|
||||
void gcal_week_hour_bar_set_context (GcalWeekHourBar *self,
|
||||
GcalContext *context);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -46,7 +46,6 @@ struct _GcalWeekView
|
||||
|
||||
/* property */
|
||||
GDateTime *date;
|
||||
GcalContext *context;
|
||||
|
||||
guint scroll_grid_timeout_id;
|
||||
gulong stack_page_changed_id;
|
||||
@@ -74,7 +73,6 @@ enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DATE,
|
||||
PROP_CONTEXT,
|
||||
PROP_TIME_DIRECTION,
|
||||
NUM_PROPS
|
||||
};
|
||||
@@ -209,22 +207,18 @@ apply_zoom (GcalWeekView *self,
|
||||
static void
|
||||
save_zoom_level (GcalWeekView *self)
|
||||
{
|
||||
GSettings *settings;
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
GSettings *settings = gcal_context_get_settings (context);
|
||||
|
||||
g_assert (self->context != NULL);
|
||||
|
||||
settings = gcal_context_get_settings (self->context);
|
||||
g_settings_set_double (settings, "week-view-zoom-level", self->zoom_level);
|
||||
}
|
||||
|
||||
static void
|
||||
restore_zoom_level (GcalWeekView *self)
|
||||
{
|
||||
GSettings *settings;
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
GSettings *settings = gcal_context_get_settings (context);
|
||||
|
||||
g_assert (self->context != NULL);
|
||||
|
||||
settings = gcal_context_get_settings (self->context);
|
||||
self->zoom_level = g_settings_get_double (settings, "week-view-zoom-level");
|
||||
|
||||
begin_zoom (self, 0);
|
||||
@@ -569,8 +563,6 @@ gcal_week_view_finalize (GObject *object)
|
||||
|
||||
g_clear_pointer (&self->date, g_date_time_unref);
|
||||
|
||||
g_clear_object (&self->context);
|
||||
|
||||
/* Chain up to parent's finalize() method. */
|
||||
G_OBJECT_CLASS (gcal_week_view_parent_class)->finalize (object);
|
||||
}
|
||||
@@ -581,24 +573,12 @@ gcal_week_view_set_property (GObject *object,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GcalWeekView *self = (GcalWeekView *) object;
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_DATE:
|
||||
gcal_view_set_date (GCAL_VIEW (object), g_value_get_boxed (value));
|
||||
break;
|
||||
|
||||
case PROP_CONTEXT:
|
||||
g_assert (self->context == NULL);
|
||||
self->context = g_value_dup_object (value);
|
||||
|
||||
gcal_week_grid_set_context (GCAL_WEEK_GRID (self->week_grid), self->context);
|
||||
gcal_week_header_set_context (GCAL_WEEK_HEADER (self->header), self->context);
|
||||
gcal_week_hour_bar_set_context (self->hours_bar, self->context);
|
||||
restore_zoom_level (self);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
@@ -622,10 +602,6 @@ gcal_week_view_get_property (GObject *object,
|
||||
g_value_set_boxed (value, self->date);
|
||||
break;
|
||||
|
||||
case PROP_CONTEXT:
|
||||
g_value_set_object (value, self->context);
|
||||
break;
|
||||
|
||||
case PROP_TIME_DIRECTION:
|
||||
g_value_set_enum (value, GTK_ORIENTATION_HORIZONTAL);
|
||||
break;
|
||||
@@ -651,7 +627,6 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
|
||||
object_class->get_property = gcal_week_view_get_property;
|
||||
|
||||
g_object_class_override_property (object_class, PROP_DATE, "active-date");
|
||||
g_object_class_override_property (object_class, PROP_CONTEXT, "context");
|
||||
g_object_class_override_property (object_class, PROP_TIME_DIRECTION, "time-direction");
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/views/gcal-week-view.ui");
|
||||
@@ -685,5 +660,7 @@ gcal_week_view_init (GcalWeekView *self)
|
||||
self->zoom_level = 1.0;
|
||||
|
||||
gtk_widget_set_size_request (self->content, -1, HEIGHT_DEFAULT);
|
||||
|
||||
restore_zoom_level (self);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user