view: rework active-date

The current implementation is deficient in many ways, the
worst one being the it relying on GObject semi-synchronous
property emission.

This issue was exposed by the Week view code, where the active
date was updated, but delayed to reach the Week header and some
events were being added ~before~ the active date changed.

With this work, I was also able to figure out a bunch of code
that relied on this (i.e. luck) to work.
This commit is contained in:
Georges Basile Stavracas Neto
2017-04-12 20:51:23 -03:00
parent 2e84c00233
commit aa5b963412
11 changed files with 295 additions and 259 deletions
+49 -20
View File
@@ -24,6 +24,7 @@
#define G_LOG_DOMAIN "GcalMonthView"
#include "gcal-debug.h"
#include "gcal-month-view.h"
#include "gcal-subscriber-view-private.h"
#include "gcal-utils.h"
@@ -914,6 +915,42 @@ add_new_event_button_cb (GtkWidget *button,
}
/* GcalView Interface API */
static icaltimetype*
gcal_month_view_get_date (GcalView *view)
{
GcalMonthView *self = GCAL_MONTH_VIEW (view);
return self->date;
}
static void
gcal_month_view_set_date (GcalView *view,
icaltimetype *date)
{
GcalSubscriberViewPrivate *ppriv;
GcalMonthView *self;
GCAL_ENTRY;
self = GCAL_MONTH_VIEW (view);
ppriv = GCAL_SUBSCRIBER_VIEW (view)->priv;
g_clear_pointer (&self->date, g_free);
self->date = gcal_dup_icaltime (date);
self->days_delay = (time_day_of_week (1, self->date->month - 1, self->date->year) - self->first_weekday + 7) % 7;
self->keyboard_cell = self->days_delay + (self->date->day - 1);
GCAL_TRACE_MSG ("new date: %s", icaltime_as_ical_string (*date));
cancel_selection (self);
ppriv->children_changed = TRUE;
gtk_widget_queue_resize (GTK_WIDGET (view));
GCAL_EXIT;
}
static void
gcal_month_view_clear_marks (GcalView *view)
{
@@ -939,6 +976,8 @@ gcal_month_view_get_children_by_uuid (GcalView *view,
static void
gcal_view_interface_init (GcalViewInterface *iface)
{
iface->get_date = gcal_month_view_get_date;
iface->set_date = gcal_month_view_set_date;
iface->clear_marks = gcal_month_view_clear_marks;
iface->get_children_by_uuid = gcal_month_view_get_children_by_uuid;
}
@@ -949,29 +988,12 @@ gcal_month_view_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
GcalSubscriberViewPrivate *ppriv;
GcalMonthView *self;
ppriv = GCAL_SUBSCRIBER_VIEW (object)->priv;
self = GCAL_MONTH_VIEW (object);
switch (property_id)
{
case PROP_DATE:
{
if (self->date != NULL)
g_free (self->date);
gcal_view_set_date (GCAL_VIEW (object), g_value_get_boxed (value));
break;
self->date = g_value_dup_boxed (value);
self->days_delay = (time_day_of_week (1, self->date->month - 1, self->date->year) - self->first_weekday + 7) % 7;
self->keyboard_cell = self->days_delay + (self->date->day - 1);
cancel_selection (GCAL_MONTH_VIEW (object));
ppriv->children_changed = TRUE;
gtk_widget_queue_resize (GTK_WIDGET (object));
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -2063,15 +2085,22 @@ gcal_month_view_button_release (GtkWidget *widget,
if (current_day >= self->days_delay && current_day < days)
{
gboolean valid;
g_clear_pointer (&self->end_mark_cell, g_date_time_unref);
self->keyboard_cell = current_day;
self->end_mark_cell = g_date_time_new_local (self->date->year, self->date->month, current_day - self->days_delay + 1, 0, 0, 0);
self->date->day = g_date_time_get_day_of_month (self->end_mark_cell);
/* First, make sure to show the popover */
valid = show_popover_for_position (GCAL_MONTH_VIEW (widget), x, y, released_indicator);
/* Then update the active date */
g_object_notify (G_OBJECT (self), "active-date");
return show_popover_for_position (GCAL_MONTH_VIEW (widget), x, y, released_indicator);
return valid;
}
else
{