[emerillon/gtk3] Port main application to libpeas



commit 9744dfc9b7db1099e40e9790321596473a182370
Author: Johannes Schmid <jhs gnome org>
Date:   Sat Jun 25 17:36:28 2011 +0200

    Port main application to libpeas

 configure.ac            |    7 +--
 emerillon/main.c        |   17 ++++---
 emerillon/manager.c     |  136 +++++++++++++++++++++--------------------------
 emerillon/manager.h     |    8 ++--
 emerillon/preferences.c |   10 ++--
 5 files changed, 83 insertions(+), 95 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index fd332dc..99190e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,8 +82,7 @@ GCONF_REQUIRED=2.31.1
 CHAMPLAIN_REQUIRED=0.7.1
 CHAMPLAIN_GTK_REQUIRED=0.7.1
 GEOCLUE_REQUIRED=0.11.1
-ETHOS_REQUIRED=0.2
-ETHOS_UI_REQUIRED=0.2
+PEAS_REQUIRED=1.0
 
 PKG_CHECK_MODULES(EMERILLON, [
     glib-2.0 >= $GLIB_REQUIRED
@@ -93,8 +92,8 @@ PKG_CHECK_MODULES(EMERILLON, [
     champlain-0.10 >= $CHAMPLAIN_REQUIRED
     champlain-gtk-0.10 >= $CHAMPLAIN_GTK_REQUIRED
     geoclue >= $GEOCLUE_REQUIRED
-    ethos-1.0 >= $ETHOS_REQUIRED
-    ethos-ui-1.0 >= $ETHOS_UI_REQUIRED
+    libpeas-1.0 >= $PEAS_REQUIRED
+    libpeas-gtk-1.0 >= $PEAS_REQUIRED
 ])
 
 # -----------------------------------------------------------
diff --git a/emerillon/main.c b/emerillon/main.c
index 6d60e54..bee2dc3 100644
--- a/emerillon/main.c
+++ b/emerillon/main.c
@@ -26,7 +26,8 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <clutter-gtk/clutter-gtk.h>
-#include <ethos/ethos.h>
+#include <libpeas/peas.h>
+#include <libpeas-gtk/peas-gtk.h>
 
 #ifdef HAVE_INTROSPECTION
 #include <gobject-introspection-1.0/girepository.h>
@@ -116,7 +117,7 @@ int
 main (int argc,
       char **argv)
 {
-  EthosManager *manager;
+  PeasEngine *engine;
   GtkWidget *window;
   ChamplainView *map_view = NULL;
   GError *error = NULL;
@@ -125,6 +126,7 @@ main (int argc,
   gchar *plugin_dirs[3] = {EMERILLON_PLUGINDIR,
                            NULL,
                            NULL};
+  gchar **dir = NULL;
 
   user_data = g_build_path (G_DIR_SEPARATOR_S,
                             g_get_user_data_dir (),
@@ -174,11 +176,12 @@ main (int argc,
   g_object_unref (plugin_dir);
 
   /* Setup the plugin infrastructure */
-  manager = emerillon_manager_dup_default ();
-  ethos_manager_set_app_name (manager, "Emerillon");
-  ethos_manager_set_plugin_dirs (manager, (gchar **)plugin_dirs);
-
-  ethos_manager_initialize (manager);
+  engine = emerillon_manager_dup_default ();
+  peas_engine_enable_loader (engine, "python");
+  for (dir = plugin_dirs; *dir != NULL; dir++)
+  {
+    peas_engine_add_search_path (engine, *dir, NULL);
+  }
 
   gtk_main ();
 
diff --git a/emerillon/manager.c b/emerillon/manager.c
index 00caf2d..14a2503 100644
--- a/emerillon/manager.c
+++ b/emerillon/manager.c
@@ -24,28 +24,71 @@
 #include "manager.h"
 
 #include <string.h>
-#include <ethos/ethos.h>
-
+#include <libpeas/peas.h>
 #include "config-keys.h"
 
-static EthosManager *default_manager = NULL;
+static PeasEngine *default_manager = NULL;
 
 #define EMERILLON_MANAGER_GET_PRIVATE(object) \
     (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
         EMERILLON_TYPE_MANAGER, \
         EmerillonManagerPrivate))
 
-G_DEFINE_TYPE (EmerillonManager, emerillon_manager, ETHOS_TYPE_MANAGER);
+G_DEFINE_TYPE (EmerillonManager, emerillon_manager, PEAS_TYPE_ENGINE);
 
 struct _EmerillonManagerPrivate
 {
   GSettings *settings_plugins;
 };
 
+static gboolean
+is_enabled (gchar ** conf, PeasPluginInfo *plugin)
+{
+  int i;
+  for (i = 0; conf[i] != NULL; i++)
+    {
+      if (strcmp (conf[i], peas_plugin_info_get_module_name (plugin)) == 0)
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
+static void
+emerillon_manager_initialize (EmerillonManager *manager)
+{
+  const GList  *list,
+  *iter;
+  gchar **conf_list;
+
+  manager->priv->settings_plugins = g_settings_new (EMERILLON_SCHEMA_PLUGINS);
+  conf_list = g_settings_get_strv (manager->priv->settings_plugins,
+                                   EMERILLON_CONF_PLUGINS_ACTIVE_PLUGINS);
+
+  list = peas_engine_get_plugin_list (PEAS_ENGINE(manager));
+  for (iter = list; iter; iter = iter->next)
+  {
+    if (peas_plugin_info_is_loaded (iter->data))
+    {
+      continue;
+    }
+    else if (is_enabled (conf_list, iter->data) &&
+             !peas_engine_load_plugin (PEAS_ENGINE(manager), iter->data))
+    {
+      g_warning ("%s: %s",
+                 peas_plugin_info_get_module_name (iter->data),
+                 "Error loading");
+	}
+  }
+
+  g_strfreev (conf_list);
+}
+
 static void
 emerillon_manager_init (EmerillonManager *self)
 {
   self->priv = EMERILLON_MANAGER_GET_PRIVATE (self);
+  emerillon_manager_initialize(self);
 }
 
 static void
@@ -74,7 +117,7 @@ emerillon_manager_constructor (GType type,
       object = G_OBJECT_CLASS (emerillon_manager_parent_class)->constructor (
       type, n_construct_properties, construct_params);
 
-      default_manager = ETHOS_MANAGER (object);
+      default_manager = PEAS_ENGINE (object);
       g_object_add_weak_pointer (object, (gpointer) &default_manager);
     }
   else
@@ -85,29 +128,16 @@ emerillon_manager_constructor (GType type,
   return object;
 }
 
-static gboolean
-is_enabled (gchar ** conf, EthosPluginInfo *plugin)
-{
-  int i;
-  for (i = 0; conf[i] != NULL; i++)
-    {
-      if (strcmp (conf[i], ethos_plugin_info_get_id (plugin)) == 0)
-        return TRUE;
-    }
-
-  return FALSE;
-}
-
 static void
-emerillon_manager_plugin_loaded (EthosManager    *emanager,
-                                 EthosPluginInfo *plugin_info)
+emerillon_manager_plugin_loaded (PeasEngine    *engine,
+                                 PeasPluginInfo *plugin_info)
 {
   gchar **conf_list;
   GPtrArray *tmp;
   GVariant *value;
   int i;
   gboolean res;
-  EmerillonManager *manager = EMERILLON_MANAGER (emanager);
+  EmerillonManager *manager = EMERILLON_MANAGER (engine);
 
   tmp = g_ptr_array_new_with_free_func (g_free);
 
@@ -126,7 +156,7 @@ emerillon_manager_plugin_loaded (EthosManager    *emanager,
   for (i=0;conf_list[i] != NULL;i++)
     g_ptr_array_add (tmp,g_strdup(conf_list[i]));
 
-  g_ptr_array_add (tmp, g_strdup (ethos_plugin_info_get_id (plugin_info)));
+  g_ptr_array_add (tmp, g_strdup (peas_plugin_info_get_module_name (plugin_info)));
 
   value = g_variant_new_strv  ((const gchar * const *) tmp->pdata, tmp->len);
   res = g_settings_set_value (manager->priv->settings_plugins,
@@ -142,17 +172,17 @@ emerillon_manager_plugin_loaded (EthosManager    *emanager,
 }
 
 static void
-emerillon_manager_plugin_unloaded (EthosManager    *emanager,
-                                   EthosPluginInfo *plugin_info)
+emerillon_manager_plugin_unloaded (PeasEngine    *engine,
+                                   PeasPluginInfo *plugin_info)
 {
   gboolean res;
   int i;
   gchar **conf_list;
   GPtrArray *tmp;
   GVariant *value;
-  
-  EmerillonManager *manager = EMERILLON_MANAGER (emanager);
 
+  EmerillonManager *manager = EMERILLON_MANAGER (engine);
+	
   tmp = g_ptr_array_new_with_free_func (g_free);
 
   conf_list = g_settings_get_strv (manager->priv->settings_plugins,
@@ -160,7 +190,7 @@ emerillon_manager_plugin_unloaded (EthosManager    *emanager,
 
   for (i=0; conf_list[i] != NULL; i++)
   {
-    if (!strcmp (conf_list[i], ethos_plugin_info_get_id (plugin_info)) == 0)
+    if (!strcmp (conf_list[i], peas_plugin_info_get_module_name (plugin_info)) == 0)
       g_ptr_array_add (tmp,g_strdup(conf_list[i]));
   }
   value = g_variant_new_strv  ((const gchar * const *) tmp->pdata, tmp->len);
@@ -178,66 +208,22 @@ emerillon_manager_plugin_unloaded (EthosManager    *emanager,
 }
 
 static void
-emerillon_manager_initialized (EthosManager *emanager)
-{
-  GList  *list,
-  *iter;
-  gchar **conf_list;
-  GError *error = NULL;
-
-  EmerillonManager *manager = EMERILLON_MANAGER (emanager);
-
-  g_return_if_fail (ETHOS_IS_MANAGER (manager));
-
-  manager->priv->settings_plugins = g_settings_new (EMERILLON_SCHEMA_PLUGINS);
-  conf_list = g_settings_get_strv (manager->priv->settings_plugins,
-                                   EMERILLON_CONF_PLUGINS_ACTIVE_PLUGINS);
-
-  list = ethos_manager_get_plugin_info (emanager);
-  for (iter = list; iter; iter = iter->next)
-  {
-    if (ethos_plugin_info_get_active (iter->data))
-    {
-      continue;
-    }
-    else if (is_enabled (conf_list, iter->data) &&
-             !ethos_manager_load_plugin (emanager, iter->data, &error))
-    {
-      g_warning ("%s: %s",
-                 ethos_plugin_info_get_id (iter->data),
-                 error ? error->message : "Error loading");
-
-      if (error)
-      {
-        //ethos_plugin_info_add_error (iter->data, error);
-        g_error_free (error);
-        error = NULL;
-      }
-    }
-  }
-
-  g_list_free (list);
-  g_strfreev (conf_list);
-}
-
-static void
 emerillon_manager_class_init (EmerillonManagerClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  EthosManagerClass *ethos_class = ETHOS_MANAGER_CLASS (klass);
+  PeasEngineClass *ethos_class = PEAS_ENGINE_CLASS (klass);
 
   object_class->constructor = emerillon_manager_constructor;
   object_class->dispose = emerillon_manager_dispose;
   object_class->finalize = emerillon_manager_finalize;
 
-  ethos_class->initialized = emerillon_manager_initialized;
-  ethos_class->plugin_loaded = emerillon_manager_plugin_loaded;
-  ethos_class->plugin_unloaded = emerillon_manager_plugin_unloaded;
+  ethos_class->load_plugin = emerillon_manager_plugin_loaded;
+  ethos_class->unload_plugin = emerillon_manager_plugin_unloaded;
 
   g_type_class_add_private (object_class, sizeof (EmerillonManagerPrivate));
 }
 
-EthosManager *
+PeasEngine *
 emerillon_manager_dup_default (void)
 {
   return g_object_new (EMERILLON_TYPE_MANAGER, NULL);
diff --git a/emerillon/manager.h b/emerillon/manager.h
index cf28160..9a489c7 100644
--- a/emerillon/manager.h
+++ b/emerillon/manager.h
@@ -25,7 +25,7 @@
 #define __EMERILLON_MANAGER_H__
 
 #include <gtk/gtk.h>
-#include <ethos/ethos.h>
+#include <libpeas/peas.h>
 
 G_BEGIN_DECLS
 
@@ -44,18 +44,18 @@ typedef struct _EmerillonManagerPrivate EmerillonManagerPrivate;
 
 struct _EmerillonManager
 {
-  EthosManager parent;
+  PeasEngine parent;
   EmerillonManagerPrivate *priv;
 };
 
 struct _EmerillonManagerClass
 {
-  EthosManagerClass parent_class;
+  PeasEngineClass parent_class;
 };
 
 GType         emerillon_manager_get_type        (void) G_GNUC_CONST;
 
-EthosManager *   emerillon_manager_dup_default     (void);
+PeasEngine *   emerillon_manager_dup_default     (void);
 
 G_END_DECLS
 
diff --git a/emerillon/preferences.c b/emerillon/preferences.c
index 0f11707..ca4e14e 100644
--- a/emerillon/preferences.c
+++ b/emerillon/preferences.c
@@ -25,7 +25,9 @@
 
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <ethos/ethos-ui.h>
+
+#include <libpeas/peas.h>
+#include <libpeas-gtk/peas-gtk.h>
 
 #include "manager.h"
 
@@ -113,13 +115,11 @@ build_plugin_tab (GtkNotebook *notebook)
 {
   GtkWidget *tab;
   GtkWidget *label;
-  EthosManager *manager;
+  PeasEngine *manager;
 
   label = gtk_label_new (_("Plugins"));
   manager = emerillon_manager_dup_default ();
-  tab = ethos_ui_manager_widget_new ();
-  ethos_ui_manager_widget_set_manager (ETHOS_UI_MANAGER_WIDGET (tab),
-    manager);
+  tab = peas_gtk_plugin_manager_new (manager);
   gtk_widget_show (tab);
   gtk_container_set_border_width (GTK_CONTAINER (tab), 10);
 



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