window: Delegate changing dates to GcalView

The view knows its time range, and knows what the
next or previous dates should be. So instead of
calculating the next date manually, ask the views
for that.
This commit is contained in:
Georges Basile Stavracas Neto
2019-05-09 17:42:59 -03:00
parent da31180cba
commit 0baeaa160a
7 changed files with 190 additions and 69 deletions
+21
View File
@@ -1220,6 +1220,25 @@ gcal_month_view_update_subscription (GcalView *view)
range_end);
}
static GDateTime*
gcal_month_view_get_next_date (GcalView *view)
{
GcalMonthView *self = GCAL_MONTH_VIEW (view);
g_assert (self->date != NULL);
return g_date_time_add_months (self->date, 1);
}
static GDateTime*
gcal_month_view_get_previous_date (GcalView *view)
{
GcalMonthView *self = GCAL_MONTH_VIEW (view);
g_assert (self->date != NULL);
return g_date_time_add_months (self->date, -1);
}
static void
gcal_view_interface_init (GcalViewInterface *iface)
{
@@ -1228,6 +1247,8 @@ gcal_view_interface_init (GcalViewInterface *iface)
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;
iface->get_next_date = gcal_month_view_get_next_date;
iface->get_previous_date = gcal_month_view_get_previous_date;
}
+63
View File
@@ -210,3 +210,66 @@ gcal_view_update_subscription (GcalView *self)
GCAL_VIEW_GET_IFACE (self)->update_subscription (self);
}
/**
* gcal_view_get_next_date:
* @self: a #GcalView
*
* Retrieves the next date from @self. Different views have
* different time ranges (e.g. day view ranges 1 day, week
* view ranges 1 week, etc) and pressing the next button
* of the main window may advance the time in different steps.
*
* Returns: (transfer full): a #GDateTime
*/
GDateTime*
gcal_view_get_next_date (GcalView *self)
{
g_autoptr (GDateTime) next_date = NULL;
g_return_val_if_fail (GCAL_IS_VIEW (self), NULL);
g_return_val_if_fail (GCAL_VIEW_GET_IFACE (self)->get_next_date, NULL);
next_date = GCAL_VIEW_GET_IFACE (self)->get_next_date (self);
#ifdef GCAL_ENABLE_TRACE
{
g_autofree gchar *str = NULL;
str = g_date_time_format (next_date, "%x %X %z");
g_debug ("%s's next date: %s", G_OBJECT_TYPE_NAME (self), str);
}
#endif
return g_steal_pointer (&next_date);
}
/**
* gcal_view_get_previous_date:
* @self: a #GcalView
*
* Retrieves the previous date from @self.
*
* Returns: (transfer full): a #GDateTime
*/
GDateTime*
gcal_view_get_previous_date (GcalView *self)
{
g_autoptr (GDateTime) previous_date = NULL;
g_return_val_if_fail (GCAL_IS_VIEW (self), NULL);
g_return_val_if_fail (GCAL_VIEW_GET_IFACE (self)->get_previous_date, NULL);
previous_date = GCAL_VIEW_GET_IFACE (self)->get_previous_date (self);
#ifdef GCAL_ENABLE_TRACE
{
g_autofree gchar *str = NULL;
str = g_date_time_format (previous_date, "%x %X %z");
g_debug ("%s's previous date: %s", G_OBJECT_TYPE_NAME (self), str);
}
#endif
return g_steal_pointer (&previous_date);
}
+7
View File
@@ -50,6 +50,10 @@ struct _GcalViewInterface
void (*update_subscription) (GcalView *self);
GDateTime* (*get_next_date) (GcalView *self);
GDateTime* (*get_previous_date) (GcalView *self);
/* Marks related API */
void (*clear_marks) (GcalView *view);
@@ -73,6 +77,9 @@ GList* gcal_view_get_children_by_uuid (GcalView
void gcal_view_update_subscription (GcalView *self);
GDateTime* gcal_view_get_next_date (GcalView *self);
GDateTime* gcal_view_get_previous_date (GcalView *self);
G_END_DECLS
+21
View File
@@ -248,6 +248,25 @@ gcal_week_view_update_subscription (GcalView *view)
range_end);
}
static GDateTime*
gcal_week_view_get_next_date (GcalView *view)
{
GcalWeekView *self = GCAL_WEEK_VIEW (view);
g_assert (self->date != NULL);
return g_date_time_add_weeks (self->date, 1);
}
static GDateTime*
gcal_week_view_get_previous_date (GcalView *view)
{
GcalWeekView *self = GCAL_WEEK_VIEW (view);
g_assert (self->date != NULL);
return g_date_time_add_weeks (self->date, -1);
}
static void
gcal_view_interface_init (GcalViewInterface *iface)
{
@@ -256,6 +275,8 @@ gcal_view_interface_init (GcalViewInterface *iface)
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;
iface->get_next_date = gcal_week_view_get_next_date;
iface->get_previous_date = gcal_week_view_get_previous_date;
}
static void
+21
View File
@@ -1609,6 +1609,25 @@ gcal_year_view_update_subscription (GcalView *view)
range_end);
}
static GDateTime*
gcal_year_view_get_next_date (GcalView *view)
{
GcalYearView *self = GCAL_YEAR_VIEW (view);
g_assert (self->date != NULL);
return g_date_time_add_years (self->date, 1);
}
static GDateTime*
gcal_year_view_get_previous_date (GcalView *view)
{
GcalYearView *self = GCAL_YEAR_VIEW (view);
g_assert (self->date != NULL);
return g_date_time_add_years (self->date, -1);
}
static void
gcal_view_interface_init (GcalViewInterface *iface)
{
@@ -1617,6 +1636,8 @@ gcal_view_interface_init (GcalViewInterface *iface)
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;
iface->get_next_date = gcal_year_view_get_next_date;
iface->get_previous_date = gcal_year_view_get_previous_date;
}
static void