view: Let views handle subscription range
Instead of GcalWindow handling the ranges themselves, delegate this responsibility to the views.
This commit is contained in:
@@ -1194,6 +1194,32 @@ gcal_month_view_get_children_by_uuid (GcalView *view,
|
||||
return filter_event_list_by_uid_and_modtype (children, mod, uuid);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_month_view_update_subscription (GcalView *view)
|
||||
{
|
||||
g_autoptr (GDateTime) date_start = NULL;
|
||||
g_autoptr (GDateTime) date_end = NULL;
|
||||
GcalMonthView *self;
|
||||
time_t range_start;
|
||||
time_t range_end;
|
||||
|
||||
self = GCAL_MONTH_VIEW (view);
|
||||
|
||||
g_assert (self->date != NULL);
|
||||
date_start = g_date_time_new_local (g_date_time_get_year (self->date),
|
||||
g_date_time_get_month (self->date),
|
||||
1, 0, 0, 0);
|
||||
range_start = g_date_time_to_unix (date_start);
|
||||
|
||||
date_end = g_date_time_add_months (date_start, 1);
|
||||
range_end = g_date_time_to_unix (date_end);
|
||||
|
||||
gcal_manager_set_subscriber (gcal_context_get_manager (self->context),
|
||||
E_CAL_DATA_MODEL_SUBSCRIBER (self),
|
||||
range_start,
|
||||
range_end);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_view_interface_init (GcalViewInterface *iface)
|
||||
{
|
||||
@@ -1201,6 +1227,7 @@ gcal_view_interface_init (GcalViewInterface *iface)
|
||||
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;
|
||||
iface->update_subscription = gcal_month_view_update_subscription;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#define G_LOG_DOMAIN "GcalView"
|
||||
|
||||
#include "gcal-debug.h"
|
||||
#include "gcal-event-widget.h"
|
||||
#include "gcal-view.h"
|
||||
#include "gcal-utils.h"
|
||||
@@ -190,3 +191,22 @@ gcal_view_get_children_by_uuid (GcalView *view,
|
||||
|
||||
return GCAL_VIEW_GET_IFACE (view)->get_children_by_uuid (view, mod, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_view_update_subscription:
|
||||
* @self: a #GcalView
|
||||
*
|
||||
* Asks @self to update its #ECalDataModel subscription range. This
|
||||
* is called after gcal_view_set_date(), and it's safe to assume that
|
||||
* @self's active date is correct.
|
||||
*/
|
||||
void
|
||||
gcal_view_update_subscription (GcalView *self)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_VIEW (self));
|
||||
g_return_if_fail (GCAL_VIEW_GET_IFACE (self)->update_subscription);
|
||||
|
||||
g_debug ("Updating subscription of %s", G_OBJECT_TYPE_NAME (self));
|
||||
|
||||
GCAL_VIEW_GET_IFACE (self)->update_subscription (self);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ struct _GcalViewInterface
|
||||
void (*set_date) (GcalView *view,
|
||||
GDateTime *date);
|
||||
|
||||
void (*update_subscription) (GcalView *self);
|
||||
|
||||
/* Marks related API */
|
||||
void (*clear_marks) (GcalView *view);
|
||||
|
||||
@@ -69,6 +71,8 @@ GList* gcal_view_get_children_by_uuid (GcalView
|
||||
GcalRecurrenceModType mod,
|
||||
const gchar *uuid);
|
||||
|
||||
void gcal_view_update_subscription (GcalView *self);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@@ -226,6 +226,28 @@ gcal_week_view_clear_marks (GcalView *view)
|
||||
gcal_week_grid_clear_marks (GCAL_WEEK_GRID (self->week_grid));
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_week_view_update_subscription (GcalView *view)
|
||||
{
|
||||
g_autoptr (GDateTime) date_start = NULL;
|
||||
g_autoptr (GDateTime) date_end = NULL;
|
||||
GcalWeekView *self;
|
||||
time_t range_start;
|
||||
time_t range_end;
|
||||
|
||||
self = GCAL_WEEK_VIEW (view);
|
||||
date_start = gcal_date_time_get_start_of_week (self->date);
|
||||
range_start = g_date_time_to_unix (date_start);
|
||||
|
||||
date_end = gcal_date_time_get_end_of_week (self->date);
|
||||
range_end = g_date_time_to_unix (date_end);
|
||||
|
||||
gcal_manager_set_subscriber (gcal_context_get_manager (self->context),
|
||||
E_CAL_DATA_MODEL_SUBSCRIBER (self),
|
||||
range_start,
|
||||
range_end);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_view_interface_init (GcalViewInterface *iface)
|
||||
{
|
||||
@@ -233,6 +255,7 @@ gcal_view_interface_init (GcalViewInterface *iface)
|
||||
iface->set_date = gcal_week_view_set_date;
|
||||
iface->get_children_by_uuid = gcal_week_view_get_children_by_uuid;
|
||||
iface->clear_marks = gcal_week_view_clear_marks;
|
||||
iface->update_subscription = gcal_week_view_update_subscription;
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -1587,6 +1587,28 @@ gcal_year_view_get_children_by_uuid (GcalView *view,
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_year_view_update_subscription (GcalView *view)
|
||||
{
|
||||
g_autoptr (GDateTime) date_start = NULL;
|
||||
g_autoptr (GDateTime) date_end = NULL;
|
||||
GcalYearView *self;
|
||||
time_t range_start;
|
||||
time_t range_end;
|
||||
|
||||
self = GCAL_YEAR_VIEW (view);
|
||||
date_start = g_date_time_new_local (g_date_time_get_year (self->date), 1, 1, 0, 0, 0);
|
||||
range_start = g_date_time_to_unix (date_start);
|
||||
|
||||
date_end = g_date_time_add_years (date_start, 1);
|
||||
range_end = g_date_time_to_unix (date_end);
|
||||
|
||||
gcal_manager_set_subscriber (gcal_context_get_manager (self->context),
|
||||
E_CAL_DATA_MODEL_SUBSCRIBER (self),
|
||||
range_start,
|
||||
range_end);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_view_interface_init (GcalViewInterface *iface)
|
||||
{
|
||||
@@ -1594,6 +1616,7 @@ gcal_view_interface_init (GcalViewInterface *iface)
|
||||
iface->get_date = gcal_year_view_get_date;
|
||||
iface->set_date = gcal_year_view_set_date;
|
||||
iface->get_children_by_uuid = gcal_year_view_get_children_by_uuid;
|
||||
iface->update_subscription = gcal_year_view_update_subscription;
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user