[gnome-calendar/gnome-3-24] views: use the new GcalClock to redraw



commit a272f4a0c976fb5ddad8028c01e77a3c9829be37
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue May 16 14:44:39 2017 -0300

    views: use the new GcalClock to redraw
    
    Instead of having each view manage it's own timeout (or
    even worse, making GcalWindow manage it), use the newly
    introduced GcalClock API to do that.

 src/gcal-window.c            |   24 ------------------------
 src/views/gcal-month-view.c  |    5 +++++
 src/views/gcal-week-grid.c   |   28 +++++-----------------------
 src/views/gcal-week-header.c |   28 +++++-----------------------
 src/views/gcal-year-view.c   |    5 +++++
 5 files changed, 20 insertions(+), 70 deletions(-)
---
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 46891c3..40ae457 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -117,7 +117,6 @@ struct _GcalWindow
   gint                 refresh_timeout;
   gint                 refresh_timeout_id;
   gint                 open_edit_dialog_timeout_id;
-  gint                 update_current_date_timeout_id;
 
   /* temp to keep event_creation */
   gboolean             open_edit_dialog;
@@ -450,21 +449,6 @@ key_pressed (GtkWidget *widget,
                                       event);
 }
 
-static gboolean
-update_current_date (GcalWindow *self)
-{
-  GCAL_ENTRY;
-
-  if (self->update_current_date_timeout_id == 0)
-    self->update_current_date_timeout_id = g_timeout_add_seconds (60, (GSourceFunc) update_current_date, 
self);
-
-  gtk_widget_queue_draw (self->views[GCAL_WINDOW_VIEW_WEEK]);
-  gtk_widget_queue_draw (self->views[GCAL_WINDOW_VIEW_MONTH]);
-  gtk_widget_queue_draw (self->views[GCAL_WINDOW_VIEW_YEAR]);
-
-  GCAL_RETURN (G_SOURCE_CONTINUE);
-}
-
 static void
 search_event_selected (GcalSearchView *search_view,
                        icaltimetype   *date,
@@ -1251,12 +1235,6 @@ gcal_window_finalize (GObject *object)
       window->open_edit_dialog_timeout_id = 0;
     }
 
-  if (window->update_current_date_timeout_id > 0)
-    {
-      g_source_remove (window->update_current_date_timeout_id);
-      window->update_current_date_timeout_id = 0;
-    }
-
   /* If we have a queued event to delete, remove it now */
   if (window->event_to_delete)
     {
@@ -1615,8 +1593,6 @@ gcal_window_init (GcalWindow *self)
   gcal_window_add_accelerator (app, "win.change-view(1)",  "<Ctrl>1")
   gcal_window_add_accelerator (app, "win.change-view(2)",  "<Ctrl>2");
   gcal_window_add_accelerator (app, "win.change-view(3)",  "<Ctrl>3");
-
-  update_current_date (self);
 }
 
 /* Public API */
diff --git a/src/views/gcal-month-view.c b/src/views/gcal-month-view.c
index 80db0d8..280b042 100644
--- a/src/views/gcal-month-view.c
+++ b/src/views/gcal-month-view.c
@@ -2307,4 +2307,9 @@ gcal_month_view_set_manager (GcalMonthView *self,
   g_return_if_fail (GCAL_IS_MONTH_VIEW (self));
 
   self->manager = manager;
+
+  g_signal_connect_swapped (gcal_manager_get_clock (manager),
+                            "day-changed",
+                            G_CALLBACK (gtk_widget_queue_draw),
+                            self);
 }
diff --git a/src/views/gcal-week-grid.c b/src/views/gcal-week-grid.c
index 68d0d87..20ddb48 100644
--- a/src/views/gcal-week-grid.c
+++ b/src/views/gcal-week-grid.c
@@ -59,7 +59,6 @@ struct _GcalWeekGrid
   GcalRangeTree      *events;
 
   gboolean            children_changed;
-  gint                redraw_timeout_id;
 
   /*
    * These fields are "cells" rather than minutes. Each cell
@@ -250,12 +249,6 @@ gcal_week_grid_finalize (GObject *object)
   g_clear_pointer (&self->events, gcal_range_tree_unref);
   g_clear_pointer (&self->active_date, g_free);
 
-  if (self->redraw_timeout_id > 0)
-    {
-      g_source_remove (self->redraw_timeout_id);
-      self->redraw_timeout_id = 0;
-    }
-
   G_OBJECT_CLASS (gcal_week_grid_parent_class)->finalize (object);
 }
 
@@ -419,14 +412,6 @@ get_today_column (GcalWeekGrid *self)
 }
 
 static gboolean
-on_redraw_timeout_cb (gpointer data)
-{
-  gtk_widget_queue_draw (data);
-
-  return G_SOURCE_CONTINUE;
-}
-
-static gboolean
 gcal_week_grid_draw (GtkWidget *widget,
                      cairo_t   *cr)
 {
@@ -588,14 +573,6 @@ gcal_week_grid_draw (GtkWidget *widget,
       gtk_style_context_restore (context);
     }
 
-  /* Fire the redraw timeout if needed */
-  if (self->redraw_timeout_id == 0)
-    {
-      self->redraw_timeout_id = g_timeout_add_seconds (5,
-                                                       on_redraw_timeout_cb,
-                                                       self);
-    }
-
   return FALSE;
 }
 
@@ -1124,6 +1101,11 @@ gcal_week_grid_set_manager (GcalWeekGrid *self,
   g_return_if_fail (GCAL_IS_WEEK_GRID (self));
 
   self->manager = manager;
+
+  g_signal_connect_swapped (gcal_manager_get_clock (manager),
+                            "minute-changed",
+                            G_CALLBACK (gtk_widget_queue_draw),
+                            self);
 }
 
 void
diff --git a/src/views/gcal-week-header.c b/src/views/gcal-week-header.c
index d305b83..9d10841 100644
--- a/src/views/gcal-week-header.c
+++ b/src/views/gcal-week-header.c
@@ -67,7 +67,6 @@ struct _GcalWeekHeader
   gboolean          expanded;
 
   gboolean          use_24h_format;
-  gint              redraw_timeout_id;
 
   icaltimetype     *active_date;
 
@@ -976,14 +975,6 @@ on_expand_action_activated (GcalWeekHeader *self,
     header_expand (self);
 }
 
-static gboolean
-on_redraw_timeout_cb (gpointer data)
-{
-  gtk_widget_queue_draw (data);
-
-  return G_SOURCE_CONTINUE;
-}
-
 /* Drawing area content and size */
 static gdouble
 get_weekday_names_height (GtkWidget *widget)
@@ -1038,12 +1029,6 @@ gcal_week_header_finalize (GObject *object)
 
   g_clear_pointer (&self->active_date, g_free);
 
-  if (self->redraw_timeout_id > 0)
-    {
-      g_source_remove (self->redraw_timeout_id);
-      self->redraw_timeout_id = 0;
-    }
-
   for (i = 0; i < 7; i++)
     g_list_free (self->events[i]);
 }
@@ -1292,14 +1277,6 @@ gcal_week_header_draw (GtkWidget      *widget,
 
   GTK_WIDGET_CLASS (gcal_week_header_parent_class)->draw (widget, cr);
 
-  /* Fire the redraw timeout if needed */
-  if (self->redraw_timeout_id == 0)
-    {
-      self->redraw_timeout_id = g_timeout_add_seconds (5,
-                                                       (GSourceFunc) on_redraw_timeout_cb,
-                                                       self);
-    }
-
   g_clear_pointer (&week_start, g_date_time_unref);
   g_clear_pointer (&week_end, g_date_time_unref);
 
@@ -1526,6 +1503,11 @@ gcal_week_header_set_manager (GcalWeekHeader *self,
   g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
 
   self->manager = manager;
+
+  g_signal_connect_swapped (gcal_manager_get_clock (manager),
+                            "day-changed",
+                            G_CALLBACK (gtk_widget_queue_draw),
+                            self);
 }
 
 void
diff --git a/src/views/gcal-year-view.c b/src/views/gcal-year-view.c
index 982c0c6..0b0554e 100644
--- a/src/views/gcal-year-view.c
+++ b/src/views/gcal-year-view.c
@@ -2035,6 +2035,11 @@ gcal_year_view_set_manager (GcalYearView *year_view,
                             GcalManager  *manager)
 {
   year_view->manager = manager;
+
+  g_signal_connect_swapped (gcal_manager_get_clock (manager),
+                            "day-changed",
+                            G_CALLBACK (gtk_widget_queue_draw),
+                            year_view->navigator);
 }
 
 void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]