[gnome-builder] tools: use IdeRecentProjects instead of direct miner



commit 098e1f9fc0a6876a02a211465212f834b56aa6ef
Author: Christian Hergert <christian hergert me>
Date:   Sat Aug 22 17:23:51 2015 -0700

    tools: use IdeRecentProjects instead of direct miner
    
    We should get the miners from the plugin loading in IdeRecentProjects,
    just like the greeter does.

 tools/Makefile.am         |    7 ++++
 tools/ide-mine-projects.c |   71 ++++++++++++++++++++++++++-------------------
 2 files changed, 48 insertions(+), 30 deletions(-)
---
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 3f4ef1f..caeda26 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -3,16 +3,23 @@ tools_PROGRAMS =
 tools_cflags = \
        -I$(top_srcdir)/libide \
        -I$(top_builddir)/libide \
+       -I$(top_srcdir)/src/util \
        $(LIBIDE_CFLAGS) \
        $(NULL)
 
 tools_libs = \
        $(LIBIDE_LIBS) \
        $(top_builddir)/libide/libide-1.0.la \
+       $(top_builddir)/src/libplugins-util.la \
        $(NULL)
 
 toolsdir = $(libexecdir)/gnome-builder
 
+# TODO:
+# 
+#  We should make these utilities require gnome-builder since lots of plugins will
+#  be extending types in the application as well as libide.
+
 tools_PROGRAMS += ide-build
 ide_build_SOURCES = ide-build.c
 ide_build_CFLAGS = $(tools_cflags)
diff --git a/tools/ide-mine-projects.c b/tools/ide-mine-projects.c
index 90b2c68..70b2802 100644
--- a/tools/ide-mine-projects.c
+++ b/tools/ide-mine-projects.c
@@ -19,37 +19,47 @@
 #include <glib/gi18n.h>
 #include <ide.h>
 
-#include "ide-project-miner.h"
-#include "autotools/ide-autotools-project-miner.h"
+#include "gb-plugins.h"
+
+static GMainLoop *main_loop;
 
 static void
-mine_cb (GObject      *object,
-         GAsyncResult *result,
-         gpointer      user_data)
+discover_cb (GObject      *object,
+             GAsyncResult *result,
+             gpointer      user_data)
 {
-  IdeProjectMiner *miner = (IdeProjectMiner *)object;
-  g_autoptr(GError) error = NULL;
-  GMainLoop *main_loop = user_data;
+  IdeRecentProjects *projects = (IdeRecentProjects *)object;
+  GError *error = NULL;
+  guint count;
+  guint i;
 
-  if (!ide_project_miner_mine_finish (miner, result, &error))
-    g_warning ("%s", error->message);
+  if (!ide_recent_projects_discover_finish (projects, result, &error))
+    {
+      g_printerr ("%s\n", error->message);
+      g_clear_error (&error);
+      g_main_loop_quit (main_loop);
+      return;
+    }
 
-  g_main_loop_quit (main_loop);
-}
+  count = g_list_model_get_n_items (G_LIST_MODEL (projects));
 
-static void
-discovered_cb (IdeProjectMiner *miner,
-               IdeProjectInfo  *info)
-{
-  GFile *file;
-  gchar *path;
+  for (i = 0; i < count; i++)
+    {
+      g_autoptr(IdeProjectInfo) info = NULL;
+      GFile *file;
+      gchar *path;
 
-  file = ide_project_info_get_file (info);
-  path = g_file_get_path (file);
+      info = g_list_model_get_item (G_LIST_MODEL (projects), i);
 
-  g_print ("%s (%s)\n", path, ide_project_info_get_name (info));
+      file = ide_project_info_get_file (info);
+      path = g_file_get_path (file);
 
-  g_free (path);
+      g_print ("%s (%s)\n", path, ide_project_info_get_name (info));
+
+      g_free (path);
+    }
+
+  g_main_loop_quit (main_loop);
 }
 
 static gboolean
@@ -68,9 +78,8 @@ main (int    argc,
       G_OPTION_ARG_CALLBACK, verbose_cb },
     { NULL }
   };
-  IdeProjectMiner *miner;
+  IdeRecentProjects *projects;
   GOptionContext *context;
-  GMainLoop *main_loop;
   GError *error = NULL;
 
   ide_log_init (TRUE, NULL);
@@ -84,15 +93,17 @@ main (int    argc,
       return EXIT_FAILURE;
     }
 
-  miner = g_object_new (IDE_TYPE_AUTOTOOLS_PROJECT_MINER,
-                        "root-directory", NULL,
-                        NULL);
-  g_signal_connect (miner, "discovered", G_CALLBACK (discovered_cb), NULL);
   main_loop = g_main_loop_new (NULL, FALSE);
-  ide_project_miner_mine_async (miner, NULL, mine_cb, main_loop);
+
+  gb_plugins_init ();
+
+  projects = ide_recent_projects_new ();
+  ide_recent_projects_discover_async (projects, NULL, discover_cb, NULL);
+
   g_main_loop_run (main_loop);
-  g_main_loop_unref (main_loop);
 
+  g_clear_object (&projects);
+  g_main_loop_unref (main_loop);
   ide_log_shutdown ();
 
   return 0;


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