[gnome-calendar] window: propagate manager using properties



commit e60c8593dd02b55e3458e5c99e6d0fef19a2081c
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Sep 7 14:35:44 2017 -0300

    window: propagate manager using properties

 src/gcal-edit-dialog.c       |    4 +-
 src/gcal-quick-add-popover.c |   58 +++----
 src/gcal-quick-add-popover.h |    3 -
 src/gcal-source-dialog.c     |  407 +++++++++++++++++++++++-------------------
 src/gcal-source-dialog.h     |    5 -
 src/gcal-view.c              |   33 ++++
 src/gcal-view.h              |    2 +
 src/gcal-window.c            |   22 ++-
 src/views/gcal-month-view.c  |   39 +++--
 src/views/gcal-month-view.h  |    3 -
 src/views/gcal-week-view.c   |   31 ++--
 src/views/gcal-week-view.h   |    3 -
 src/views/gcal-year-view.c   |   40 +++--
 src/views/gcal-year-view.h   |    2 -
 14 files changed, 364 insertions(+), 288 deletions(-)
---
diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c
index e74bac9..5a70d39 100644
--- a/src/gcal-edit-dialog.c
+++ b/src/gcal-edit-dialog.c
@@ -726,8 +726,6 @@ gcal_edit_dialog_class_init (GcalEditDialogClass *klass)
   object_class->get_property = gcal_edit_dialog_get_property;
   object_class->set_property = gcal_edit_dialog_set_property;
 
-  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/edit-dialog.ui");
-
   /**
    * GcalEditDialog::event:
    *
@@ -767,6 +765,8 @@ gcal_edit_dialog_class_init (GcalEditDialogClass *klass)
                                                          TRUE,
                                                          G_PARAM_READWRITE));
 
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/edit-dialog.ui");
+
   /* Alarms */
   gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, five_minutes_button);
   gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, ten_minutes_button);
diff --git a/src/gcal-quick-add-popover.c b/src/gcal-quick-add-popover.c
index 9d9e0c6..093f815 100644
--- a/src/gcal-quick-add-popover.c
+++ b/src/gcal-quick-add-popover.c
@@ -777,7 +777,28 @@ gcal_quick_add_popover_set_property (GObject      *object,
       break;
 
     case PROP_MANAGER:
-      gcal_quick_add_popover_set_manager (self, g_value_get_object (value));
+      if (g_set_object (&self->manager, g_value_get_object (value)))
+        {
+          GcalManager *manager;
+          GList *sources, *l;
+
+          /* Add currently leaded sources */
+          manager = self->manager;
+          sources = gcal_manager_get_sources_connected (manager);
+
+          for (l = sources; l != NULL; l = g_list_next (l))
+            on_source_added (manager, l->data, gcal_manager_is_client_writable (manager, l->data), self);
+
+          g_list_free (sources);
+
+          /* Connect to the manager signals and keep the list updates */
+          g_signal_connect (manager, "source-added", G_CALLBACK (on_source_added), self);
+          g_signal_connect (manager, "source-changed", G_CALLBACK (on_source_changed), self);
+          g_signal_connect (manager, "source-removed", G_CALLBACK (on_source_removed), self);
+          g_signal_connect_swapped (manager, "notify::default-calendar", G_CALLBACK 
(update_default_calendar_row), self);
+
+          g_object_notify (G_OBJECT (self), "manager");
+        }
       break;
 
     default:
@@ -904,41 +925,6 @@ gcal_quick_add_popover_new (void)
 }
 
 /**
- * gcal_quick_add_popover_set_manager:
- * @self: a #GcalQuickAddPopover
- * @manager: a #GcalManager
- *
- * Sets the manager of the popover.
- */
-void
-gcal_quick_add_popover_set_manager (GcalQuickAddPopover *self,
-                                    GcalManager         *manager)
-{
-  g_return_if_fail (GCAL_IS_QUICK_ADD_POPOVER (self));
-
-  if (g_set_object (&self->manager, manager))
-    {
-      GList *sources, *l;
-
-      /* Add currently leaded sources */
-      sources = gcal_manager_get_sources_connected (manager);
-
-      for (l = sources; l != NULL; l = g_list_next (l))
-        on_source_added (manager, l->data, gcal_manager_is_client_writable (manager, l->data), self);
-
-      g_list_free (sources);
-
-      /* Connect to the manager signals and keep the list updates */
-      g_signal_connect (manager, "source-added", G_CALLBACK (on_source_added), self);
-      g_signal_connect (manager, "source-changed", G_CALLBACK (on_source_changed), self);
-      g_signal_connect (manager, "source-removed", G_CALLBACK (on_source_removed), self);
-      g_signal_connect_swapped (manager, "notify::default-calendar", G_CALLBACK 
(update_default_calendar_row), self);
-
-      g_object_notify (G_OBJECT (self), "manager");
-    }
-}
-
-/**
  * gcal_quick_add_popover_get_date_start:
  * @self: a #GcalQuickAddPopover
  *
diff --git a/src/gcal-quick-add-popover.h b/src/gcal-quick-add-popover.h
index b2b3180..443644a 100644
--- a/src/gcal-quick-add-popover.h
+++ b/src/gcal-quick-add-popover.h
@@ -33,9 +33,6 @@ G_DECLARE_FINAL_TYPE (GcalQuickAddPopover, gcal_quick_add_popover, GCAL, QUICK_A
 
 GtkWidget*           gcal_quick_add_popover_new                  (void);
 
-void                 gcal_quick_add_popover_set_manager          (GcalQuickAddPopover *self,
-                                                                  GcalManager         *manager);
-
 GDateTime*           gcal_quick_add_popover_get_date_start       (GcalQuickAddPopover *self);
 
 void                 gcal_quick_add_popover_set_date_start       (GcalQuickAddPopover *self,
diff --git a/src/gcal-source-dialog.c b/src/gcal-source-dialog.c
index f6c543b..fc7dd2f 100644
--- a/src/gcal-source-dialog.c
+++ b/src/gcal-source-dialog.c
@@ -242,6 +242,15 @@ static void       discover_sources_cb                   (GObject             *so
 
 G_DEFINE_TYPE (GcalSourceDialog, gcal_source_dialog, GTK_TYPE_DIALOG)
 
+enum
+{
+  PROP_0,
+  PROP_MANAGER,
+  N_PROPS
+};
+
+static GParamSpec *properties[N_PROPS] = { NULL, };
+
 GActionEntry actions[] = {
   {"file",  on_file_activated,  NULL, NULL, NULL},
   {"local", on_local_activated, NULL, NULL, NULL},
@@ -1766,142 +1775,9 @@ remove_button_clicked (GtkWidget *button,
   gcal_source_dialog_set_mode (GCAL_SOURCE_DIALOG (user_data), GCAL_SOURCE_DIALOG_MODE_NORMAL);
 }
 
-GtkWidget*
-gcal_source_dialog_new (void)
-{
-  return g_object_new (GCAL_TYPE_SOURCE_DIALOG, NULL);
-}
-
-static void
-gcal_source_dialog_constructed (GObject *object)
-{
-  GcalSourceDialog *self;
-  GtkBuilder *builder;
-  GMenuModel *menu;
-
-  self = GCAL_SOURCE_DIALOG (object);
-
-  G_OBJECT_CLASS (gcal_source_dialog_parent_class)->constructed (object);
-
-  /* widget responses */
-  gtk_dialog_set_default_response (GTK_DIALOG (object), GTK_RESPONSE_CANCEL);
-
-  g_object_set_data (G_OBJECT (self->remove_button), "response", GINT_TO_POINTER 
(GCAL_RESPONSE_REMOVE_SOURCE));
-
-  /* Setup listbox header functions */
-  gtk_list_box_set_header_func (GTK_LIST_BOX (self->calendars_listbox), display_header_func, NULL, NULL);
-  gtk_list_box_set_sort_func (GTK_LIST_BOX (self->calendars_listbox), (GtkListBoxSortFunc) 
calendar_listbox_sort_func,
-                              object, NULL);
-
-  gtk_list_box_set_header_func (GTK_LIST_BOX (self->online_accounts_listbox), display_header_func, NULL, 
NULL);
-  gtk_list_box_set_sort_func (GTK_LIST_BOX (self->online_accounts_listbox), (GtkListBoxSortFunc) 
online_accounts_listbox_sort_func,
-                              object, NULL);
-
-  /* Action group */
-  self->action_group = g_simple_action_group_new ();
-  gtk_widget_insert_action_group (GTK_WIDGET (object), "source", G_ACTION_GROUP (self->action_group));
-
-  g_action_map_add_action_entries (G_ACTION_MAP (self->action_group), actions, G_N_ELEMENTS (actions), 
object);
-
-  /* Load the "Add" button menu */
-  builder = gtk_builder_new_from_resource ("/org/gnome/calendar/gtk/menus.ui");
-
-  menu = G_MENU_MODEL (gtk_builder_get_object (builder, "add-source-menu"));
-  gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (self->add_calendar_menu_button), menu);
-
-  g_object_unref (builder);
-
-  /* setup titlebar */
-  gtk_window_set_titlebar (GTK_WINDOW (object), self->headerbar);
-}
-
-static void
-gcal_source_dialog_class_init (GcalSourceDialogClass *klass)
-{
-  GObjectClass *object_class;
-  GtkWidgetClass *widget_class;
-
-  /**
-   * Since we cannot guarantee that the
-   * type system registered ESourceLocal,
-   * it must be ensured at least here.
-   */
-  g_type_ensure (E_TYPE_SOURCE_LOCAL);
-
-  object_class = G_OBJECT_CLASS (klass);
-  object_class->constructed = gcal_source_dialog_constructed;
-
-  widget_class = GTK_WIDGET_CLASS (klass);
-
-  /* bind things for/from the template class */
-  gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), 
"/org/gnome/calendar/source-dialog.ui");
-
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, account_box);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, account_label);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, add_button);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, add_calendar_menu_button);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, back_button);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, calendar_address_entry);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, calendar_color_button);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, calendar_url_button);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, calendar_visible_check);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, calendars_listbox);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, cancel_button);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, credentials_cancel_button);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, credentials_connect_button);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, credentials_dialog);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, credentials_password_entry);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, credentials_user_entry);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, default_check);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, edit_grid);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, exchange_stub_row);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, google_stub_row);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, headerbar);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, location_dim_label);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, main_scrolledwindow);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, name_entry);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, notification);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, notification_label);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, online_accounts_listbox);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, owncloud_stub_row);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, remove_button);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, settings_button);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, stack);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, web_source_grid);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, web_sources_listbox);
-  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, web_sources_revealer);
-
-  gtk_widget_class_bind_template_callback (widget_class, add_button_clicked);
-  gtk_widget_class_bind_template_callback (widget_class, action_widget_activated);
-  gtk_widget_class_bind_template_callback (widget_class, back_button_clicked);
-  gtk_widget_class_bind_template_callback (widget_class, calendar_address_activated);
-  gtk_widget_class_bind_template_callback (widget_class, calendar_file_selected);
-  gtk_widget_class_bind_template_callback (widget_class, calendar_listbox_row_activated);
-  gtk_widget_class_bind_template_callback (widget_class, calendar_visible_check_toggled);
-  gtk_widget_class_bind_template_callback (widget_class, cancel_button_clicked);
-  gtk_widget_class_bind_template_callback (widget_class, credential_button_clicked);
-  gtk_widget_class_bind_template_callback (widget_class, credential_entry_activate);
-  gtk_widget_class_bind_template_callback (widget_class, color_set);
-  gtk_widget_class_bind_template_callback (widget_class, default_check_toggled);
-  gtk_widget_class_bind_template_callback (widget_class, description_label_link_activated);
-  gtk_widget_class_bind_template_callback (widget_class, hide_notification);
-  gtk_widget_class_bind_template_callback (widget_class, name_entry_text_changed);
-  gtk_widget_class_bind_template_callback (widget_class, notification_child_revealed_changed);
-  gtk_widget_class_bind_template_callback (widget_class, online_accounts_listbox_row_activated);
-  gtk_widget_class_bind_template_callback (widget_class, online_accounts_settings_button_clicked);
-  gtk_widget_class_bind_template_callback (widget_class, remove_button_clicked);
-  gtk_widget_class_bind_template_callback (widget_class, response_signal);
-  gtk_widget_class_bind_template_callback (widget_class, settings_button_clicked);
-  gtk_widget_class_bind_template_callback (widget_class, stack_visible_child_name_changed);
-  gtk_widget_class_bind_template_callback (widget_class, undo_remove_action);
-  gtk_widget_class_bind_template_callback (widget_class, url_entry_text_changed);
-}
-
-static void
-gcal_source_dialog_init (GcalSourceDialog *self)
-{
-  gtk_widget_init_template (GTK_WIDGET (self));
-}
+/*
+ * Callbacks
+ */
 
 static GcalAccountType
 get_account_type (GoaAccount *account)
@@ -1920,27 +1796,6 @@ get_account_type (GoaAccount *account)
   return GCAL_ACCOUNT_TYPE_NOT_SUPPORTED;
 }
 
-static gint
-online_accounts_listbox_sort_func (GtkListBoxRow *row1,
-                                   GtkListBoxRow *row2,
-                                   gpointer       user_data)
-{
-  GcalAccountType t1, t2;
-  GoaAccount *a1 = g_object_get_data (G_OBJECT (row1), "goa-account");
-  GoaAccount *a2 = g_object_get_data (G_OBJECT (row2), "goa-account");
-
-  if (!a1 || !a2)
-    return a1 ? -1 : (a2 ? 1 : 0);
-
-  t1 = get_account_type (a1);
-  t2 = get_account_type (a2);
-
-  if (t1 != t2)
-    return t1 - t2;
-
-  return g_strcmp0 (goa_account_get_identity (a1), goa_account_get_identity (a2));
-}
-
 static void
 account_calendar_disable_changed (GObject    *object,
                                   GParamSpec *pspec,
@@ -1953,7 +1808,6 @@ account_calendar_disable_changed (GObject    *object,
   gtk_label_set_label (GTK_LABEL (user_data), goa_account_get_calendar_disabled (account) ? _("Off") : 
_("On"));
 }
 
-
 static void
 add_goa_account (GcalSourceDialog *dialog,
                  GoaAccount       *account)
@@ -2132,39 +1986,226 @@ loading_changed_cb (GcalSourceDialog *dialog)
   GCAL_EXIT;
 }
 
-/**
- * gcal_source_dialog_set_manager:
- * @dialog: a #GcalSourceDialog
- * @manager: a #GcalManager
- *
- * Setup the #GcalManager singleton
- * instance of the application.
- */
-void
-gcal_source_dialog_set_manager (GcalSourceDialog *dialog,
-                                GcalManager      *manager)
+
+static void
+gcal_source_dialog_constructed (GObject *object)
 {
-  dialog->manager = manager;
+  GcalSourceDialog *self;
+  GtkBuilder *builder;
+  GMenuModel *menu;
 
-  if (!gcal_manager_get_loading (dialog->manager))
-    {
-      GList *sources, *l;
+  self = GCAL_SOURCE_DIALOG (object);
+
+  G_OBJECT_CLASS (gcal_source_dialog_parent_class)->constructed (object);
+
+  /* widget responses */
+  gtk_dialog_set_default_response (GTK_DIALOG (object), GTK_RESPONSE_CANCEL);
+
+  g_object_set_data (G_OBJECT (self->remove_button), "response", GINT_TO_POINTER 
(GCAL_RESPONSE_REMOVE_SOURCE));
+
+  /* Setup listbox header functions */
+  gtk_list_box_set_header_func (GTK_LIST_BOX (self->calendars_listbox), display_header_func, NULL, NULL);
+  gtk_list_box_set_sort_func (GTK_LIST_BOX (self->calendars_listbox), (GtkListBoxSortFunc) 
calendar_listbox_sort_func,
+                              object, NULL);
 
-      sources = gcal_manager_get_sources_connected (dialog->manager);
+  gtk_list_box_set_header_func (GTK_LIST_BOX (self->online_accounts_listbox), display_header_func, NULL, 
NULL);
+  gtk_list_box_set_sort_func (GTK_LIST_BOX (self->online_accounts_listbox), (GtkListBoxSortFunc) 
online_accounts_listbox_sort_func,
+                              object, NULL);
 
-      for (l = sources; l != NULL; l = l->next)
-        add_source (dialog->manager, l->data, is_source_enabled (l->data), dialog);
+  /* Action group */
+  self->action_group = g_simple_action_group_new ();
+  gtk_widget_insert_action_group (GTK_WIDGET (object), "source", G_ACTION_GROUP (self->action_group));
+
+  g_action_map_add_action_entries (G_ACTION_MAP (self->action_group), actions, G_N_ELEMENTS (actions), 
object);
+
+  /* Load the "Add" button menu */
+  builder = gtk_builder_new_from_resource ("/org/gnome/calendar/gtk/menus.ui");
+
+  menu = G_MENU_MODEL (gtk_builder_get_object (builder, "add-source-menu"));
+  gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (self->add_calendar_menu_button), menu);
+
+  g_object_unref (builder);
+
+  /* setup titlebar */
+  gtk_window_set_titlebar (GTK_WINDOW (object), self->headerbar);
+}
+
+static void
+gcal_source_dialog_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  GcalSourceDialog *self = (GcalSourceDialog *) object;
+
+  switch (prop_id)
+    {
+    case PROP_MANAGER:
+      g_value_set_object (value, self->manager);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
-  else
+}
+static void
+gcal_source_dialog_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  GcalSourceDialog *self = (GcalSourceDialog *) object;
+
+  switch (prop_id)
     {
-      g_signal_connect_swapped (manager,
-                                "notify::loading",
-                                G_CALLBACK (loading_changed_cb),
-                                dialog);
+    case PROP_MANAGER:
+      self->manager = g_value_dup_object (value);
+
+      if (!gcal_manager_get_loading (self->manager))
+        {
+          GList *sources, *l;
+
+          sources = gcal_manager_get_sources_connected (self->manager);
+
+          for (l = sources; l != NULL; l = l->next)
+            add_source (self->manager, l->data, is_source_enabled (l->data), self);
+        }
+      else
+        {
+          g_signal_connect_swapped (self->manager,
+                                    "notify::loading",
+                                    G_CALLBACK (loading_changed_cb),
+                                    self);
+        }
+
+      g_signal_connect (self->manager, "source-added", G_CALLBACK (add_source), self);
+      g_signal_connect (self->manager, "source-removed", G_CALLBACK (remove_source), self);
+
+      g_object_notify_by_pspec (object, properties[PROP_MANAGER]);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
+}
+
+static void
+gcal_source_dialog_class_init (GcalSourceDialogClass *klass)
+{
+  GObjectClass *object_class;
+  GtkWidgetClass *widget_class;
+
+  /**
+   * Since we cannot guarantee that the
+   * type system registered ESourceLocal,
+   * it must be ensured at least here.
+   */
+  g_type_ensure (E_TYPE_SOURCE_LOCAL);
+
+  object_class = G_OBJECT_CLASS (klass);
+  object_class->constructed = gcal_source_dialog_constructed;
+  object_class->get_property = gcal_source_dialog_get_property;
+  object_class->set_property = gcal_source_dialog_set_property;
+
+  properties[PROP_MANAGER] = g_param_spec_object ("manager",
+                                                  "Manager",
+                                                  "The manager object of the application",
+                                                  GCAL_TYPE_MANAGER,
+                                                  G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  widget_class = GTK_WIDGET_CLASS (klass);
+
+  /* bind things for/from the template class */
+  gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), 
"/org/gnome/calendar/source-dialog.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, account_box);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, account_label);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, add_button);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, add_calendar_menu_button);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, back_button);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, calendar_address_entry);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, calendar_color_button);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, calendar_url_button);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, calendar_visible_check);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, calendars_listbox);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, cancel_button);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, credentials_cancel_button);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, credentials_connect_button);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, credentials_dialog);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, credentials_password_entry);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, credentials_user_entry);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, default_check);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, edit_grid);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, exchange_stub_row);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, google_stub_row);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, headerbar);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, location_dim_label);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, main_scrolledwindow);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, name_entry);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, notification);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, notification_label);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, online_accounts_listbox);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, owncloud_stub_row);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, remove_button);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, settings_button);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, stack);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, web_source_grid);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, web_sources_listbox);
+  gtk_widget_class_bind_template_child (widget_class, GcalSourceDialog, web_sources_revealer);
 
-  g_signal_connect (dialog->manager, "source-added", G_CALLBACK (add_source), dialog);
-  g_signal_connect (dialog->manager, "source-removed", G_CALLBACK (remove_source), dialog);
+  gtk_widget_class_bind_template_callback (widget_class, add_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, action_widget_activated);
+  gtk_widget_class_bind_template_callback (widget_class, back_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, calendar_address_activated);
+  gtk_widget_class_bind_template_callback (widget_class, calendar_file_selected);
+  gtk_widget_class_bind_template_callback (widget_class, calendar_listbox_row_activated);
+  gtk_widget_class_bind_template_callback (widget_class, calendar_visible_check_toggled);
+  gtk_widget_class_bind_template_callback (widget_class, cancel_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, credential_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, credential_entry_activate);
+  gtk_widget_class_bind_template_callback (widget_class, color_set);
+  gtk_widget_class_bind_template_callback (widget_class, default_check_toggled);
+  gtk_widget_class_bind_template_callback (widget_class, description_label_link_activated);
+  gtk_widget_class_bind_template_callback (widget_class, hide_notification);
+  gtk_widget_class_bind_template_callback (widget_class, name_entry_text_changed);
+  gtk_widget_class_bind_template_callback (widget_class, notification_child_revealed_changed);
+  gtk_widget_class_bind_template_callback (widget_class, online_accounts_listbox_row_activated);
+  gtk_widget_class_bind_template_callback (widget_class, online_accounts_settings_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, remove_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, response_signal);
+  gtk_widget_class_bind_template_callback (widget_class, settings_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, stack_visible_child_name_changed);
+  gtk_widget_class_bind_template_callback (widget_class, undo_remove_action);
+  gtk_widget_class_bind_template_callback (widget_class, url_entry_text_changed);
+}
+
+static void
+gcal_source_dialog_init (GcalSourceDialog *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+static gint
+online_accounts_listbox_sort_func (GtkListBoxRow *row1,
+                                   GtkListBoxRow *row2,
+                                   gpointer       user_data)
+{
+  GcalAccountType t1, t2;
+  GoaAccount *a1 = g_object_get_data (G_OBJECT (row1), "goa-account");
+  GoaAccount *a2 = g_object_get_data (G_OBJECT (row2), "goa-account");
+
+  if (!a1 || !a2)
+    return a1 ? -1 : (a2 ? 1 : 0);
+
+  t1 = get_account_type (a1);
+  t2 = get_account_type (a2);
+
+  if (t1 != t2)
+    return t1 - t2;
+
+  return g_strcmp0 (goa_account_get_identity (a1), goa_account_get_identity (a2));
 }
 
 /**
diff --git a/src/gcal-source-dialog.h b/src/gcal-source-dialog.h
index 11aec38..cfa8e21 100644
--- a/src/gcal-source-dialog.h
+++ b/src/gcal-source-dialog.h
@@ -52,11 +52,6 @@ typedef enum
   GCAL_SOURCE_DIALOG_MODE_NORMAL
 } GcalSourceDialogMode;
 
-GtkWidget*          gcal_source_dialog_new                  (void);
-
-void                gcal_source_dialog_set_manager          (GcalSourceDialog   *dialog,
-                                                             GcalManager        *manager);
-
 void                gcal_source_dialog_set_mode             (GcalSourceDialog     *dialog,
                                                              GcalSourceDialogMode  mode);
 
diff --git a/src/gcal-view.c b/src/gcal-view.c
index f6fd54c..d9ce8b7 100644
--- a/src/gcal-view.c
+++ b/src/gcal-view.c
@@ -45,6 +45,18 @@ gcal_view_default_init (GcalViewInterface *iface)
                                                            G_PARAM_READWRITE));
 
   /**
+   * GcalView::manager:
+   *
+   * The #GcalManager of the view.
+   */
+  g_object_interface_install_property (iface,
+                                       g_param_spec_object ("manager",
+                                                            "The manager",
+                                                            "The manager of the view",
+                                                            GCAL_TYPE_MANAGER,
+                                                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  /**
    * GcalView::create-event:
    *
    * Emitted when the view wants to create an event.
@@ -93,6 +105,27 @@ gcal_view_set_date (GcalView     *view,
 }
 
 /**
+ * gcal_view_get_manager:
+ * @self: a #GcalView
+ *
+ * Retrieves the #GcalManager instance from @self.
+ *
+ * Returns: (transfer none): a #GcalManager
+ */
+GcalManager*
+gcal_view_get_manager (GcalView *self)
+{
+  GcalManager *manager;
+
+  g_return_val_if_fail (GCAL_IS_VIEW (self), NULL);
+
+  g_object_get (self, "manager", &manager, NULL);
+  g_object_unref (manager);
+
+  return manager;
+}
+
+/**
  * gcal_view_get_date:
  * @view: a #GcalView
  *
diff --git a/src/gcal-view.h b/src/gcal-view.h
index a746bfd..ce416a3 100644
--- a/src/gcal-view.h
+++ b/src/gcal-view.h
@@ -61,6 +61,8 @@ void                 gcal_view_set_date                          (GcalView
 
 icaltimetype*        gcal_view_get_date                          (GcalView           *view);
 
+GcalManager*         gcal_view_get_manager                       (GcalView           *self);
+
 void                 gcal_view_clear_marks                       (GcalView           *view);
 
 GList*               gcal_view_get_children_by_uuid              (GcalView              *view,
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 8bd8f5d..0802a62 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -1378,12 +1378,6 @@ gcal_window_set_property (GObject      *object,
           g_signal_connect_swapped (self->manager, "source-enabled", G_CALLBACK (source_enabled), object);
           g_signal_connect_swapped (self->manager, "source-changed", G_CALLBACK (source_changed), object);
 
-          gcal_edit_dialog_set_manager (GCAL_EDIT_DIALOG (self->edit_dialog), self->manager);
-          gcal_week_view_set_manager (GCAL_WEEK_VIEW (self->week_view), self->manager);
-          gcal_month_view_set_manager (GCAL_MONTH_VIEW (self->month_view), self->manager);
-          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);
           gcal_search_view_connect (GCAL_SEARCH_VIEW (self->search_view), self->manager);
 
           g_object_notify (object, "manager");
@@ -1490,7 +1484,6 @@ gcal_window_class_init(GcalWindowClass *klass)
   widget_class = GTK_WIDGET_CLASS (klass);
   widget_class->configure_event = gcal_window_configure_event;
   widget_class->window_state_event = gcal_window_state_event;
-  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/window.ui");
 
   g_object_class_install_property (
       object_class,
@@ -1507,7 +1500,7 @@ gcal_window_class_init(GcalWindowClass *klass)
       PROP_MANAGER,
       g_param_spec_object ("manager",
                            "The manager object",
-                           "A weak reference to the app manager object",
+                           "The manager object",
                            GCAL_TYPE_MANAGER,
                            G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
 
@@ -1529,6 +1522,8 @@ gcal_window_class_init(GcalWindowClass *klass)
                             FALSE,
                             G_PARAM_READWRITE));
 
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/window.ui");
+
   /* widgets */
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, edit_dialog);
   gtk_widget_class_bind_template_child (widget_class, GcalWindow, header_bar);
@@ -1658,6 +1653,17 @@ gcal_window_init (GcalWindow *self)
   self->active_date = g_new0 (icaltimetype, 1);
   self->rtl = gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL;
 
+  /*
+   * FIXME: this is a hack around the issue that happens when trying to bind
+   * there properties using the GtkBuilder .ui file.
+   */
+  g_object_bind_property (self, "manager", self->edit_dialog, "manager", G_BINDING_DEFAULT);
+  g_object_bind_property (self, "manager", self->source_dialog, "manager", G_BINDING_DEFAULT);
+  g_object_bind_property (self, "manager", self->week_view, "manager", G_BINDING_DEFAULT);
+  g_object_bind_property (self, "manager", self->month_view, "manager", G_BINDING_DEFAULT);
+  g_object_bind_property (self, "manager", self->year_view, "manager", G_BINDING_DEFAULT);
+  g_object_bind_property (self, "manager", self->quick_add_popover, "manager", G_BINDING_DEFAULT);
+
   /* setup accels */
   app = g_application_get_default ();
 
diff --git a/src/views/gcal-month-view.c b/src/views/gcal-month-view.c
index 392c1b4..ea0214f 100644
--- a/src/views/gcal-month-view.c
+++ b/src/views/gcal-month-view.c
@@ -104,7 +104,9 @@ G_DEFINE_TYPE_WITH_CODE (GcalMonthView, gcal_month_view, GCAL_TYPE_SUBSCRIBER_VI
 enum
 {
   PROP_0,
-  PROP_DATE,  /* active-date inherited property */
+  PROP_DATE,
+  PROP_MANAGER,
+  N_PROPS
 };
 
 static inline gint
@@ -1006,12 +1008,25 @@ gcal_month_view_set_property (GObject       *object,
                               const GValue  *value,
                               GParamSpec    *pspec)
 {
+  GcalMonthView *self = (GcalMonthView *) object;
+
   switch (property_id)
     {
     case PROP_DATE:
       gcal_view_set_date (GCAL_VIEW (object), g_value_get_boxed (value));
       break;
 
+    case PROP_MANAGER:
+      self->manager = g_value_dup_object (value);
+
+      g_signal_connect_swapped (gcal_manager_get_clock (self->manager),
+                                "day-changed",
+                                G_CALLBACK (gtk_widget_queue_draw),
+                                self);
+
+      g_object_notify (object, "manager");
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -1031,6 +1046,11 @@ gcal_month_view_get_property (GObject       *object,
     case PROP_DATE:
       g_value_set_boxed (value, self->date);
       break;
+
+    case PROP_MANAGER:
+      g_value_set_object (value, self->manager);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -1044,6 +1064,8 @@ gcal_month_view_finalize (GObject *object)
 
   g_clear_pointer (&self->date, g_free);
 
+  g_clear_object (&self->manager);
+
   /* Chain up to parent's finalize() method. */
   G_OBJECT_CLASS (gcal_month_view_parent_class)->finalize (object);
 }
@@ -2285,6 +2307,7 @@ gcal_month_view_class_init (GcalMonthViewClass *klass)
   subscriber_view_class->clear_state = gcal_month_view_clear_state;
 
   g_object_class_override_property (object_class, PROP_DATE, "active-date");
+  g_object_class_override_property (object_class, PROP_MANAGER, "manager");
 
   gtk_widget_class_set_css_name (widget_class, "calendar-view");
 }
@@ -2388,17 +2411,3 @@ gcal_month_view_set_use_24h_format (GcalMonthView *self,
 {
   self->use_24h_format = use_24h;
 }
-
-void
-gcal_month_view_set_manager (GcalMonthView *self,
-                             GcalManager   *manager)
-{
-  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-month-view.h b/src/views/gcal-month-view.h
index 147af67..25b87b2 100644
--- a/src/views/gcal-month-view.h
+++ b/src/views/gcal-month-view.h
@@ -35,9 +35,6 @@ void                 gcal_month_view_set_first_weekday           (GcalMonthView
 void                 gcal_month_view_set_use_24h_format          (GcalMonthView      *self,
                                                                   gboolean            use_24h);
 
-void                 gcal_month_view_set_manager                 (GcalMonthView      *self ,
-                                                                  GcalManager        *manager);
-
 G_END_DECLS
 
 #endif /* __GCAL_MONTH_VIEW_H__ */
diff --git a/src/views/gcal-week-view.c b/src/views/gcal-week-view.c
index 9e92faf..b60dcd1 100644
--- a/src/views/gcal-week-view.c
+++ b/src/views/gcal-week-view.c
@@ -85,6 +85,7 @@ enum
 {
   PROP_0,
   PROP_DATE,
+  PROP_MANAGER,
   NUM_PROPS
 };
 
@@ -519,6 +520,8 @@ gcal_week_view_finalize (GObject       *object)
 
   g_clear_pointer (&self->date, g_free);
 
+  g_clear_object (&self->manager);
+
   /* Chain up to parent's finalize() method. */
   G_OBJECT_CLASS (gcal_week_view_parent_class)->finalize (object);
 }
@@ -529,12 +532,23 @@ gcal_week_view_set_property (GObject       *object,
                              const GValue  *value,
                              GParamSpec    *pspec)
 {
+  GcalWeekView *self = (GcalWeekView *) object;
+
   switch (property_id)
     {
     case PROP_DATE:
       gcal_view_set_date (GCAL_VIEW (object), g_value_get_boxed (value));
       break;
 
+    case PROP_MANAGER:
+      self->manager = g_value_dup_object (value);
+
+      gcal_week_grid_set_manager (GCAL_WEEK_GRID (self->week_grid), self->manager);
+      gcal_week_header_set_manager (GCAL_WEEK_HEADER (self->header), self->manager);
+
+      g_object_notify (object, "manager");
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -558,6 +572,10 @@ gcal_week_view_get_property (GObject       *object,
       g_value_set_boxed (value, self->date);
       break;
 
+    case PROP_MANAGER:
+      g_value_set_object (value, self->manager);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -575,6 +593,7 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
   object_class->get_property = gcal_week_view_get_property;
 
   g_object_class_override_property (object_class, PROP_DATE, "active-date");
+  g_object_class_override_property (object_class, PROP_MANAGER, "manager");
 
   signals[EVENT_ACTIVATED] = g_signal_new ("event-activated",
                                            GCAL_TYPE_WEEK_VIEW,
@@ -619,18 +638,6 @@ gcal_week_view_new (void)
   return g_object_new (GCAL_TYPE_WEEK_VIEW, NULL);
 }
 
-void
-gcal_week_view_set_manager (GcalWeekView *self,
-                            GcalManager  *manager)
-{
-  g_return_if_fail (GCAL_IS_WEEK_VIEW (self));
-
-  self->manager = manager;
-
-  gcal_week_grid_set_manager (GCAL_WEEK_GRID (self->week_grid), manager);
-  gcal_week_header_set_manager (GCAL_WEEK_HEADER (self->header), manager);
-}
-
 /**
  * gcal_week_view_set_first_weekday:
  * @view:
diff --git a/src/views/gcal-week-view.h b/src/views/gcal-week-view.h
index ae2e503..b5aebf8 100644
--- a/src/views/gcal-week-view.h
+++ b/src/views/gcal-week-view.h
@@ -31,9 +31,6 @@ G_DECLARE_FINAL_TYPE (GcalWeekView, gcal_week_view, GCAL, WEEK_VIEW, GtkBox)
 
 GtkWidget*           gcal_week_view_new                          (void);
 
-void                 gcal_week_view_set_manager                  (GcalWeekView       *self,
-                                                                  GcalManager        *manager);
-
 void                 gcal_week_view_set_first_weekday            (GcalWeekView       *self,
                                                                   gint                day_nr);
 
diff --git a/src/views/gcal-year-view.c b/src/views/gcal-year-view.c
index a7b13a3..63cf9f0 100644
--- a/src/views/gcal-year-view.c
+++ b/src/views/gcal-year-view.c
@@ -120,6 +120,7 @@ struct _GcalYearView
 enum {
   PROP_0,
   PROP_DATE,
+  PROP_MANAGER,
   PROP_SHOW_WEEK_NUMBERS,
   LAST_PROP
 };
@@ -1651,6 +1652,10 @@ gcal_year_view_get_property (GObject    *object,
       g_value_set_boxed (value, self->date);
       break;
 
+    case PROP_MANAGER:
+      g_value_set_object (value, self->manager);
+      break;
+
     case PROP_SHOW_WEEK_NUMBERS:
       g_value_set_boolean (value, self->show_week_numbers);
       break;
@@ -1674,6 +1679,17 @@ gcal_year_view_set_property (GObject      *object,
       gcal_view_set_date (GCAL_VIEW (self), g_value_get_boxed (value));
       break;
 
+    case PROP_MANAGER:
+      self->manager = g_value_dup_object (value);
+
+      g_signal_connect_swapped (gcal_manager_get_clock (self->manager),
+                                "day-changed",
+                                G_CALLBACK (gtk_widget_queue_draw),
+                                self->navigator);
+
+      g_object_notify (object, "manager");
+      break;
+
     case PROP_SHOW_WEEK_NUMBERS:
       if (self->show_week_numbers != g_value_get_boolean (value))
         {
@@ -1948,6 +1964,7 @@ gcal_year_view_class_init (GcalYearViewClass *klass)
   widget_class->direction_changed = gcal_year_view_direction_changed;
 
   g_object_class_override_property (object_class, PROP_DATE, "active-date");
+  g_object_class_override_property (object_class, PROP_MANAGER, "manager");
 
   g_object_class_install_property (object_class,
                                    PROP_SHOW_WEEK_NUMBERS,
@@ -1958,10 +1975,13 @@ gcal_year_view_class_init (GcalYearViewClass *klass)
                                                          G_PARAM_READWRITE));
 
   /* FIXME: it will problably go back to GcalView */
-  signals[EVENT_ACTIVATED] = g_signal_new ("event-activated", GCAL_TYPE_YEAR_VIEW, G_SIGNAL_RUN_LAST,
-                                           0,
-                                           NULL, NULL, NULL,
-                                           G_TYPE_NONE, 1, GCAL_TYPE_EVENT_WIDGET);
+  signals[EVENT_ACTIVATED] = g_signal_new ("event-activated",
+                                           GCAL_TYPE_YEAR_VIEW,
+                                           G_SIGNAL_RUN_LAST,
+                                           0, NULL, NULL, NULL,
+                                           G_TYPE_NONE,
+                                           1,
+                                           GCAL_TYPE_EVENT_WIDGET);
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/year-view.ui");
 
@@ -2044,18 +2064,6 @@ gcal_data_model_subscriber_interface_init (ECalDataModelSubscriberInterface *ifa
 
 /* Public API */
 void
-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
 gcal_year_view_set_first_weekday (GcalYearView *year_view,
                                   gint          nr_day)
 {
diff --git a/src/views/gcal-year-view.h b/src/views/gcal-year-view.h
index 2e88ace..676385c 100644
--- a/src/views/gcal-year-view.h
+++ b/src/views/gcal-year-view.h
@@ -30,8 +30,6 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GcalYearView, gcal_year_view, GCAL, YEAR_VIEW, GtkBox)
 
-void              gcal_year_view_set_manager        (GcalYearView *year_view,
-                                                     GcalManager  *manager);
 void              gcal_year_view_set_first_weekday  (GcalYearView *year_view,
                                                      gint          nr_day);
 void              gcal_year_view_set_use_24h_format (GcalYearView *year_view,



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