[gnome-calendar] window: attach update date timeout to window



commit 141f8d87b8e964bf2a5b0d86e3d75ecb64dae239
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Apr 18 09:55:56 2017 -0300

    window: attach update date timeout to window
    
    So we can properly remove the timeout source whenever the
    window is finalized.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781431

 src/gcal-window.c |   29 +++++++++++++++++------------
 1 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 1ab5335..e691a3c 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -155,9 +155,11 @@ struct _GcalWindow
   GtkWidget           *calendar_popover;
   GtkWidget           *calendar_listbox;
   GtkWidget           *source_dialog;
+
   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;
@@ -466,22 +468,18 @@ key_pressed (GtkWidget *widget,
 }
 
 static gboolean
-update_current_date (GcalWindow *window)
+update_current_date (GcalWindow *self)
 {
   GCAL_ENTRY;
 
-  /* FIXME: we end up here before constructed(), this shouldn't happen */
-  if (!window->views[GCAL_WINDOW_VIEW_WEEK])
-    GCAL_GOTO (out);
-
-  gtk_widget_queue_draw (window->views[GCAL_WINDOW_VIEW_WEEK]);
-  gtk_widget_queue_draw (window->views[GCAL_WINDOW_VIEW_MONTH]);
-  gtk_widget_queue_draw (window->views[GCAL_WINDOW_VIEW_YEAR]);
+  if (self->update_current_date_timeout_id == 0)
+    self->update_current_date_timeout_id = g_timeout_add_seconds (60, (GSourceFunc) update_current_date, 
self);
 
-out:
-  g_timeout_add_seconds (60, (GSourceFunc) update_current_date, window);
+  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_REMOVE);
+  GCAL_RETURN (G_SOURCE_CONTINUE);
 }
 
 static void
@@ -1256,6 +1254,12 @@ 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)
     {
@@ -1331,7 +1335,6 @@ gcal_window_set_property (GObject      *object,
           gcal_year_view_set_manager (GCAL_YEAR_VIEW (self->year_view), self->manager);
           gcal_quick_add_popover_set_manager (GCAL_QUICK_ADD_POPOVER (self->quick_add_popover), 
self->manager);
           gcal_source_dialog_set_manager (GCAL_SOURCE_DIALOG (self->source_dialog), self->manager);
-          update_current_date (GCAL_WINDOW (object));
 
           g_object_notify (object, "manager");
         }
@@ -1615,6 +1618,8 @@ 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 */


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