[gnome-calendar] view: Let views handle subscription range
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] view: Let views handle subscription range
- Date: Thu, 9 May 2019 20:43:16 +0000 (UTC)
commit da31180cbafcc329740c1b53d53b0192646b7295
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Thu May 9 12:32:20 2019 -0300
view: Let views handle subscription range
Instead of GcalWindow handling the ranges themselves,
delegate this responsibility to the views.
src/gui/gcal-window.c | 82 ++++-----------------------------------------
src/views/gcal-month-view.c | 27 +++++++++++++++
src/views/gcal-view.c | 20 +++++++++++
src/views/gcal-view.h | 4 +++
src/views/gcal-week-view.c | 23 +++++++++++++
src/views/gcal-year-view.c | 23 +++++++++++++
6 files changed, 103 insertions(+), 76 deletions(-)
---
diff --git a/src/gui/gcal-window.c b/src/gui/gcal-window.c
index efa5f620..c853585c 100644
--- a/src/gui/gcal-window.c
+++ b/src/gui/gcal-window.c
@@ -251,92 +251,22 @@ static void
update_active_date (GcalWindow *window,
GDateTime *new_date)
{
- g_autoptr (GDateTime) previous_date = NULL;
g_autofree gchar *new_date_string = NULL;
- GcalManager *manager;
- GDateTime *date_start, *date_end;
- time_t range_start, range_end;
- GDate old_week, new_week;
+ GcalWindowView i;
GCAL_ENTRY;
- previous_date = window->active_date;
- window->active_date = g_date_time_ref (new_date);
- manager = gcal_context_get_manager (window->context);
-
new_date_string = g_date_time_format (new_date, "%x %X %z");
g_debug ("Updating active date to %s", new_date_string);
- gcal_view_set_date (GCAL_VIEW (window->views[GCAL_WINDOW_VIEW_WEEK]), new_date);
- gcal_view_set_date (GCAL_VIEW (window->views[GCAL_WINDOW_VIEW_MONTH]), new_date);
- gcal_view_set_date (GCAL_VIEW (window->views[GCAL_WINDOW_VIEW_YEAR]), new_date);
-
- /* year_view */
- if (g_date_time_get_year (previous_date) != g_date_time_get_year (new_date))
- {
- date_start = g_date_time_new_local (g_date_time_get_year (new_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 (manager, E_CAL_DATA_MODEL_SUBSCRIBER (window->year_view), range_start,
range_end);
-
- gcal_clear_date_time (&date_start);
- gcal_clear_date_time (&date_end);
- }
-
- /* month_view */
- if (g_date_time_get_year (previous_date) != g_date_time_get_year (new_date) ||
- g_date_time_get_month (previous_date) != g_date_time_get_month (new_date))
- {
- date_start = g_date_time_new_local (g_date_time_get_year (new_date),
- g_date_time_get_month (new_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 (manager, E_CAL_DATA_MODEL_SUBSCRIBER (window->month_view), range_start,
range_end);
-
- gcal_clear_date_time (&date_start);
- gcal_clear_date_time (&date_end);
- }
-
- /* week_view */
- g_date_clear (&old_week, 1);
+ gcal_set_date_time (&window->active_date, new_date);
- if (g_date_time_get_day_of_month (previous_date) > 0 &&
- g_date_time_get_month (previous_date) > 0 &&
- g_date_time_get_year (previous_date))
+ for (i = GCAL_WINDOW_VIEW_WEEK; i <= GCAL_WINDOW_VIEW_YEAR; i++)
{
- g_date_set_dmy (&old_week,
- g_date_time_get_day_of_month (previous_date),
- g_date_time_get_month (previous_date),
- g_date_time_get_year (previous_date));
- }
-
- g_date_clear (&new_week, 1);
- g_date_set_dmy (&new_week,
- g_date_time_get_day_of_month (new_date),
- g_date_time_get_month (new_date),
- g_date_time_get_year (new_date));
-
- if (g_date_time_get_year (previous_date) != g_date_time_get_year (new_date) ||
- !g_date_valid (&old_week) ||
- g_date_get_iso8601_week_of_year (&old_week) != g_date_get_iso8601_week_of_year (&new_week))
- {
- date_start = gcal_date_time_get_start_of_week (new_date);
- range_start = g_date_time_to_unix (date_start);
-
- date_end = gcal_date_time_get_end_of_week (new_date);
- range_end = g_date_time_to_unix (date_end);
-
- gcal_manager_set_subscriber (manager, E_CAL_DATA_MODEL_SUBSCRIBER (window->week_view), range_start,
range_end);
+ GcalView *view = GCAL_VIEW (window->views[i]);
- gcal_clear_date_time (&date_start);
- gcal_clear_date_time (&date_end);
+ gcal_view_set_date (view, new_date);
+ gcal_view_update_subscription (view);
}
update_today_button_sensitive (window);
diff --git a/src/views/gcal-month-view.c b/src/views/gcal-month-view.c
index f9b7a946..24893f82 100644
--- a/src/views/gcal-month-view.c
+++ b/src/views/gcal-month-view.c
@@ -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;
}
diff --git a/src/views/gcal-view.c b/src/views/gcal-view.c
index 6553fd90..baa38848 100644
--- a/src/views/gcal-view.c
+++ b/src/views/gcal-view.c
@@ -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);
+}
diff --git a/src/views/gcal-view.h b/src/views/gcal-view.h
index e16c2bd7..b2eea60d 100644
--- a/src/views/gcal-view.h
+++ b/src/views/gcal-view.h
@@ -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
diff --git a/src/views/gcal-week-view.c b/src/views/gcal-week-view.c
index 03b3ddda..0d4dc49a 100644
--- a/src/views/gcal-week-view.c
+++ b/src/views/gcal-week-view.c
@@ -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
diff --git a/src/views/gcal-year-view.c b/src/views/gcal-year-view.c
index 7e11e260..87befea0 100644
--- a/src/views/gcal-year-view.c
+++ b/src/views/gcal-year-view.c
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]