[gnome-builder] runtime-manager: defer runtime loading until GInitable::init



commit dbd29d3863035fbfa778ca5b9701df99c75d5db0
Author: Christian Hergert <chergert redhat com>
Date:   Sun Oct 16 14:56:18 2016 -0700

    runtime-manager: defer runtime loading until GInitable::init
    
    This moves the loading of runtime providers from the constructed func to
    a GInitable::init vfunc. This allows us to defer loading until after the
    project has been loaded.

 libide/ide-context.c                  |   22 ++++++++++++++++++++++
 libide/runtimes/ide-runtime-manager.c |   25 +++++++++++++++++--------
 2 files changed, 39 insertions(+), 8 deletions(-)
---
diff --git a/libide/ide-context.c b/libide/ide-context.c
index f7e3d62..dca2955 100644
--- a/libide/ide-context.c
+++ b/libide/ide-context.c
@@ -1058,6 +1058,27 @@ ide_context_init_build_system (gpointer             source_object,
 }
 
 static void
+ide_context_init_runtimes (gpointer             source_object,
+                           GCancellable        *cancellable,
+                           GAsyncReadyCallback  callback,
+                           gpointer             user_data)
+{
+  IdeContext *self = source_object;
+  g_autoptr(GTask) task = NULL;
+  GError *error = NULL;
+
+  g_return_if_fail (IDE_IS_CONTEXT (self));
+
+  task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_source_tag (task, ide_context_init_runtimes);
+
+  if (!g_initable_init (G_INITABLE (self->runtime_manager), cancellable, &error))
+    g_task_return_error (task, error);
+  else
+    g_task_return_boolean (task, TRUE);
+}
+
+static void
 ide_context_init_unsaved_files_cb (GObject      *object,
                                    GAsyncResult *result,
                                    gpointer      user_data)
@@ -1537,6 +1558,7 @@ ide_context_init_async (GAsyncInitable      *initable,
                         ide_context_init_unsaved_files,
                         ide_context_init_add_recent,
                         ide_context_init_search_engine,
+                        ide_context_init_runtimes,
                         ide_context_init_configuration_manager,
                         ide_context_init_loaded,
                         NULL);
diff --git a/libide/runtimes/ide-runtime-manager.c b/libide/runtimes/ide-runtime-manager.c
index ef766e6..67ae5e5 100644
--- a/libide/runtimes/ide-runtime-manager.c
+++ b/libide/runtimes/ide-runtime-manager.c
@@ -36,9 +36,11 @@ struct _IdeRuntimeManager
 };
 
 static void list_model_iface_init (GListModelInterface *iface);
+static void initable_iface_init   (GInitableIface      *iface);
 
 G_DEFINE_TYPE_EXTENDED (IdeRuntimeManager, ide_runtime_manager, IDE_TYPE_OBJECT, 0,
-                        G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, list_model_iface_init))
+                        G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, list_model_iface_init)
+                        G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init))
 
 static void
 ide_runtime_manager_extension_added (PeasExtensionSet *set,
@@ -72,16 +74,16 @@ ide_runtime_manager_extension_removed (PeasExtensionSet *set,
   ide_runtime_provider_unload (provider, self);
 }
 
-static void
-ide_runtime_manager_constructed (GObject *object)
+static gboolean
+ide_runtime_manager_initable_init (GInitable     *initable,
+                                   GCancellable  *cancellable,
+                                   GError       **error)
 {
-  IdeRuntimeManager *self = (IdeRuntimeManager *)object;
+  IdeRuntimeManager *self = (IdeRuntimeManager *)initable;
   IdeContext *context;
 
-  G_OBJECT_CLASS (ide_runtime_manager_parent_class)->constructed (object);
-
+  g_assert (IDE_IS_RUNTIME_MANAGER (self));
   context = ide_object_get_context (IDE_OBJECT (self));
-
   g_assert (IDE_IS_CONTEXT (context));
 
   self->extensions = peas_extension_set_new (peas_engine_get_default (),
@@ -103,6 +105,14 @@ ide_runtime_manager_constructed (GObject *object)
                               self);
 
   ide_runtime_manager_add (self, ide_runtime_new (context, "host", _("Host operating system")));
+
+  return TRUE;
+}
+
+static void
+initable_iface_init (GInitableIface *iface)
+{
+  iface->init = ide_runtime_manager_initable_init;
 }
 
 void
@@ -130,7 +140,6 @@ ide_runtime_manager_class_init (IdeRuntimeManagerClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  object_class->constructed = ide_runtime_manager_constructed;
   object_class->dispose = ide_runtime_manager_dispose;
 }
 


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