[libpeas/proxys] Replace old PeasPlugin class with PeasExtensionBase.



commit d0e65ede566dbf9354709384cce3b755feaa7025
Author: Steve Frécinaux <code istique net>
Date:   Wed May 26 00:03:04 2010 +0200

    Replace old PeasPlugin class with PeasExtensionBase.
    
    The idea is that this class is only useful as a base for C plugins.
    Its only purpose is to give access to the plugin info from extensions,
    especially the data dir.
    
    At the same time, references to gedit-plugins.h have been removed as
    they were not useful anymore...

 configure.ac                                       |    2 +-
 libpeas/Makefile.am                                |    4 +-
 libpeas/peas-activatable.c                         |    1 -
 libpeas/peas-engine.c                              |    1 -
 libpeas/peas-engine.h                              |    1 -
 libpeas/{peas-plugin.c => peas-extension-base.c}   |   87 +++++++++----------
 libpeas/peas-extension-base.h                      |   72 +++++++++++++++
 libpeas/peas-plugin-info-priv.h                    |    1 -
 libpeas/peas-plugin-info.c                         |    1 -
 libpeas/peas-plugin-loader.h                       |    1 -
 libpeas/peas-plugin.h                              |   91 --------------------
 libpeasui/peas-ui-configurable.c                   |    2 -
 libpeasui/peas-ui-plugin-manager.c                 |    1 -
 loaders/c/peas-plugin-loader-c.c                   |    4 +
 .../helloworld/peasdemo-hello-world-plugin.c       |    3 +-
 .../helloworld/peasdemo-hello-world-plugin.h       |    6 +-
 peas-demo/plugins/pythonhello/pythonhello.py       |    3 +-
 17 files changed, 125 insertions(+), 156 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0e95067..c73fc39 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,7 +18,7 @@ m4_define(peas_lt_age, [m4_eval(peas_binary_age - peas_interface_age)])
 AC_INIT([libpeas],[peas_version],[http://bugzilla.gnome.org/enter_bug.cgi?product=gedit],[libpeas])
 
 AC_CONFIG_HEADERS([config.h])
-AC_CONFIG_SRCDIR([libpeas/peas-plugin.c])
+AC_CONFIG_SRCDIR([libpeas/peas-engine.c])
 AC_CONFIG_MACRO_DIR([m4])
 
 AC_DEFINE(PEAS_MAJOR_VERSION, peas_major_version, [Gedit Plugins Engine major version])
diff --git a/libpeas/Makefile.am b/libpeas/Makefile.am
index 531fad1..0f9415b 100644
--- a/libpeas/Makefile.am
+++ b/libpeas/Makefile.am
@@ -17,8 +17,8 @@ libpeas_2_0_la_LDFLAGS = \
 libpeas_2_0_la_LIBADD = $(PEAS_LIBS) $(IGE_MAC_LIBS)
 
 INST_H_FILES =			\
-	peas-plugin.h		\
 	peas-plugin-info.h	\
+	peas-extension-base.h	\
 	peas-extension.h	\
 	peas-extension-set.h	\
 	peas-activatable.h	\
@@ -37,9 +37,9 @@ C_FILES =			\
 	peas-i18n.c		\
 	peas-object-module.c	\
 	peas-introspection.c	\
-	peas-plugin.c		\
 	peas-plugin-info.c	\
 	peas-plugin-loader.c	\
+	peas-extension-base.c	\
 	peas-extension.c	\
 	peas-extension-set.c	\
 	peas-activatable.c	\
diff --git a/libpeas/peas-activatable.c b/libpeas/peas-activatable.c
index 012c9b0..a341b45 100644
--- a/libpeas/peas-activatable.c
+++ b/libpeas/peas-activatable.c
@@ -24,7 +24,6 @@
 #endif
 
 #include "peas-activatable.h"
-#include "peas-plugin.h"
 
 /**
  * SECTION:peas-activatable
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index 12a8735..da8daff 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -31,7 +31,6 @@
 #include "peas-plugin-info-priv.h"
 #include "peas-plugin-loader.h"
 #include "peas-object-module.h"
-#include "peas-plugin.h"
 #include "peas-extension.h"
 #include "peas-dirs.h"
 
diff --git a/libpeas/peas-engine.h b/libpeas/peas-engine.h
index ed9bc0f..500d3a1 100644
--- a/libpeas/peas-engine.h
+++ b/libpeas/peas-engine.h
@@ -24,7 +24,6 @@
 
 #include <glib.h>
 #include "peas-plugin-info.h"
-#include "peas-plugin.h"
 #include "peas-extension.h"
 
 G_BEGIN_DECLS
diff --git a/libpeas/peas-plugin.c b/libpeas/peas-extension-base.c
similarity index 60%
rename from libpeas/peas-plugin.c
rename to libpeas/peas-extension-base.c
index 859b1a9..3639bec 100644
--- a/libpeas/peas-plugin.c
+++ b/libpeas/peas-extension-base.c
@@ -24,7 +24,7 @@
 #include <config.h>
 #endif
 
-#include "peas-plugin.h"
+#include "peas-extension-base.h"
 #include "peas-plugin-info-priv.h"
 #include "peas-dirs.h"
 
@@ -33,7 +33,7 @@
  * @short_description: Base class for plugins
  * @see_also: #PeasPluginInfo
  *
- * A #PeasPlugin is an object which represents an actual loaded plugin.
+ * A #PeasExtensionBase is an object which represents an actual loaded plugin.
  *
  * As a plugin writer, you will need to inherit from this class to perform
  * the actions you want to using the available hooks.  It will also provide
@@ -41,13 +41,13 @@
  * data lives.
  *
  * As an application developper, you might want to provide a subclass of
- * #PeasPlugin for tighter integration with your application.  But you should
+ * #PeasExtensionBase for tighter integration with your application.  But you should
  * not use this class at all in your application code apart from that, as all
  * the actions that can be performed by plugins will be proxied by the
  * #PeasEngine.
  **/
 
-G_DEFINE_TYPE (PeasPlugin, peas_plugin, G_TYPE_OBJECT);
+G_DEFINE_ABSTRACT_TYPE (PeasExtensionBase, peas_extension_base, G_TYPE_OBJECT);
 
 /* properties */
 enum {
@@ -56,25 +56,21 @@ enum {
   PROP_DATA_DIR
 };
 
-struct _PeasPluginPrivate {
-  PeasPluginInfo *info;
-};
-
 static void
-peas_plugin_get_property (GObject    *object,
-                          guint       prop_id,
-                          GValue     *value,
-                          GParamSpec *pspec)
+peas_extension_base_get_property (GObject    *object,
+                                  guint       prop_id,
+                                  GValue     *value,
+                                  GParamSpec *pspec)
 {
-  PeasPlugin *plugin = PEAS_PLUGIN (object);
+  PeasExtensionBase *extbase = PEAS_EXTENSION_BASE (object);
 
   switch (prop_id)
     {
     case PROP_PLUGIN_INFO:
-      g_value_set_boxed (value, peas_plugin_get_info (plugin));
+      g_value_set_boxed (value, peas_extension_base_get_plugin_info (extbase));
       break;
     case PROP_DATA_DIR:
-      g_value_take_string (value, peas_plugin_get_data_dir (plugin));
+      g_value_take_string (value, peas_extension_base_get_data_dir (extbase));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -83,17 +79,17 @@ peas_plugin_get_property (GObject    *object,
 }
 
 static void
-peas_plugin_set_property (GObject      *object,
-                          guint         prop_id,
-                          const GValue *value,
-                          GParamSpec   *pspec)
+peas_extension_base_set_property (GObject      *object,
+                                  guint         prop_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
 {
-  PeasPlugin *plugin = PEAS_PLUGIN (object);
+  PeasExtensionBase *extbase = PEAS_EXTENSION_BASE (object);
 
   switch (prop_id)
     {
     case PROP_PLUGIN_INFO:
-      plugin->priv->info = g_value_dup_boxed (value);
+      extbase->plugin_info = g_value_dup_boxed (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -102,35 +98,34 @@ peas_plugin_set_property (GObject      *object,
 }
 
 static void
-peas_plugin_init (PeasPlugin *plugin)
+peas_extension_base_init (PeasExtensionBase *extbase)
 {
-  plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, PEAS_TYPE_PLUGIN, PeasPluginPrivate);
 }
 
 static void
-peas_plugin_finalize (GObject *object)
+peas_extension_base_finalize (GObject *object)
 {
-  PeasPlugin *plugin = PEAS_PLUGIN (object);
+  PeasExtensionBase *extbase = PEAS_EXTENSION_BASE (object);
 
-  if (plugin->priv->info)
-    _peas_plugin_info_unref (plugin->priv->info);
+  if (extbase->plugin_info != NULL)
+    _peas_plugin_info_unref (extbase->plugin_info);
 
-  G_OBJECT_CLASS (peas_plugin_parent_class)->finalize (object);
+  G_OBJECT_CLASS (peas_extension_base_parent_class)->finalize (object);
 }
 
 static void
-peas_plugin_class_init (PeasPluginClass *klass)
+peas_extension_base_class_init (PeasExtensionBaseClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  object_class->get_property = peas_plugin_get_property;
-  object_class->set_property = peas_plugin_set_property;
-  object_class->finalize = peas_plugin_finalize;
+  object_class->get_property = peas_extension_base_get_property;
+  object_class->set_property = peas_extension_base_set_property;
+  object_class->finalize = peas_extension_base_finalize;
 
   g_object_class_install_property (object_class,
                                    PROP_PLUGIN_INFO,
                                    g_param_spec_boxed ("plugin-info",
-                                                       "Plugin Information",
+                                                       "ExtensionBase Information",
                                                        "Information relative to the current plugin",
                                                        PEAS_TYPE_PLUGIN_INFO,
                                                        G_PARAM_READWRITE |
@@ -144,29 +139,27 @@ peas_plugin_class_init (PeasPluginClass *klass)
                                                         NULL,
                                                         G_PARAM_READABLE |
                                                         G_PARAM_STATIC_STRINGS));
-
-  g_type_class_add_private (klass, sizeof (PeasPluginPrivate));
 }
 
 /**
- * peas_plugin_get_info:
- * @plugin: A #PeasPlugin.
+ * peas_extension_base_get_plugin_info:
+ * @extbase: A #PeasExtensionBase.
  *
- * Get information relative to @plugin.
+ * Get information relative to @extbase.
  *
- * Return value: the #PeasPluginInfo relative to the #PeasPlugin.
+ * Return value: the #PeasPluginInfo relative to the #PeasExtensionBase.
  */
 PeasPluginInfo *
-peas_plugin_get_info (PeasPlugin *plugin)
+peas_extension_base_get_plugin_info (PeasExtensionBase *extbase)
 {
-  g_return_val_if_fail (PEAS_IS_PLUGIN (plugin), NULL);
+  g_return_val_if_fail (PEAS_IS_EXTENSION_BASE (extbase), NULL);
 
-  return plugin->priv->info;
+  return extbase->plugin_info;
 }
 
 /**
- * peas_plugin_get_data_dir:
- * @plugin: A #PeasPlugin.
+ * peas_extension_base_get_data_dir:
+ * @extbase: A #PeasExtensionBase.
  *
  * Get the path of the directory where the plugin should look for
  * its data files.
@@ -175,9 +168,9 @@ peas_plugin_get_info (PeasPlugin *plugin)
  * directory where the plugin should look for its data files
  */
 gchar *
-peas_plugin_get_data_dir (PeasPlugin *plugin)
+peas_extension_base_get_data_dir (PeasExtensionBase *extbase)
 {
-  g_return_val_if_fail (PEAS_IS_PLUGIN (plugin), NULL);
+  g_return_val_if_fail (PEAS_IS_EXTENSION_BASE (extbase), NULL);
 
-  return g_strdup (peas_plugin_info_get_data_dir (plugin->priv->info));
+  return g_strdup (peas_plugin_info_get_data_dir (extbase->plugin_info));
 }
diff --git a/libpeas/peas-extension-base.h b/libpeas/peas-extension-base.h
new file mode 100644
index 0000000..6e97e7d
--- /dev/null
+++ b/libpeas/peas-extension-base.h
@@ -0,0 +1,72 @@
+/*
+ * peas-plugin.h
+ * This file is part of libpeas
+ *
+ * Copyright (C) 2002-2005 - Paolo Maggi
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Library General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PEAS_EXTENSION_BASE_H__
+#define __PEAS_EXTENSION_BASE_H__
+
+#include <glib-object.h>
+
+#include "peas-plugin-info.h"
+
+/* TODO: add a .h file that includes all the .h files normally needed to
+ * develop a plugin */
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define PEAS_TYPE_EXTENSION_BASE            (peas_extension_base_get_type())
+#define PEAS_EXTENSION_BASE(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), PEAS_TYPE_EXTENSION_BASE, PeasExtensionBase))
+#define PEAS_EXTENSION_BASE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), PEAS_TYPE_EXTENSION_BASE, PeasExtensionBaseClass))
+#define PEAS_IS_EXTENSION_BASE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), PEAS_TYPE_EXTENSION_BASE))
+#define PEAS_IS_EXTENSION_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PEAS_TYPE_EXTENSION_BASE))
+#define PEAS_EXTENSION_BASE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), PEAS_TYPE_EXTENSION_BASE, PeasExtensionBaseClass))
+
+/**
+ * PeasExtensionBase:
+ * @parent: the parent object.
+ *
+ * Base class for C extensions.
+ */
+typedef struct _PeasExtensionBase        PeasExtensionBase;
+typedef struct _PeasExtensionBaseClass   PeasExtensionBaseClass;
+
+struct _PeasExtensionBase {
+  GObject parent;
+  PeasPluginInfo *plugin_info;
+};
+
+struct _PeasExtensionBaseClass {
+  GObjectClass parent_class;
+};
+
+/*
+ * Public methods
+ */
+GType            peas_extension_base_get_type         (void)  G_GNUC_CONST;
+
+PeasPluginInfo  *peas_extension_base_get_plugin_info  (PeasExtensionBase *extbase);
+gchar           *peas_extension_base_get_data_dir     (PeasExtensionBase *extbase);
+
+G_END_DECLS
+
+#endif /* __PEAS_EXTENSION_BASE_H__ */
diff --git a/libpeas/peas-plugin-info-priv.h b/libpeas/peas-plugin-info-priv.h
index 7401a96..96c4bf8 100644
--- a/libpeas/peas-plugin-info-priv.h
+++ b/libpeas/peas-plugin-info-priv.h
@@ -24,7 +24,6 @@
 #define __PEAS_PLUGIN_INFO_PRIV_H__
 
 #include "peas-plugin-info.h"
-#include "peas-plugin.h"
 
 struct _PeasPluginInfo {
   /*< private >*/
diff --git a/libpeas/peas-plugin-info.c b/libpeas/peas-plugin-info.c
index 7e4df25..4ffab00 100644
--- a/libpeas/peas-plugin-info.c
+++ b/libpeas/peas-plugin-info.c
@@ -29,7 +29,6 @@
 
 #include "peas-i18n.h"
 #include "peas-plugin-info-priv.h"
-#include "peas-plugin.h"
 
 /**
  * SECTION:peas-plugin-info
diff --git a/libpeas/peas-plugin-loader.h b/libpeas/peas-plugin-loader.h
index 6028761..acabfd4 100644
--- a/libpeas/peas-plugin-loader.h
+++ b/libpeas/peas-plugin-loader.h
@@ -24,7 +24,6 @@
 
 #include <glib-object.h>
 #include <gmodule.h>
-#include "peas-plugin.h"
 #include "peas-plugin-info.h"
 #include "peas-extension.h"
 
diff --git a/libpeasui/peas-ui-configurable.c b/libpeasui/peas-ui-configurable.c
index fbb9039..2a84bc0 100644
--- a/libpeasui/peas-ui-configurable.c
+++ b/libpeasui/peas-ui-configurable.c
@@ -23,8 +23,6 @@
 #include <config.h>
 #endif
 
-#include <libpeas/peas-plugin.h>
-
 #include "peas-ui-configurable.h"
 
 /**
diff --git a/libpeasui/peas-ui-plugin-manager.c b/libpeasui/peas-ui-plugin-manager.c
index ce250af..ac742cb 100644
--- a/libpeasui/peas-ui-plugin-manager.c
+++ b/libpeasui/peas-ui-plugin-manager.c
@@ -28,7 +28,6 @@
 #include <string.h>
 
 #include <libpeas/peas-engine.h>
-#include <libpeas/peas-plugin.h>
 #include <libpeas/peas-i18n.h>
 
 #include "peas-ui-plugin-manager.h"
diff --git a/loaders/c/peas-plugin-loader-c.c b/loaders/c/peas-plugin-loader-c.c
index 51b5889..3911f17 100644
--- a/loaders/c/peas-plugin-loader-c.c
+++ b/loaders/c/peas-plugin-loader-c.c
@@ -22,6 +22,7 @@
 #include "peas-plugin-loader-c.h"
 #include "peas-extension-c.h"
 #include <libpeas/peas-object-module.h>
+#include <libpeas/peas-extension-base.h>
 #include <gmodule.h>
 
 struct _PeasPluginLoaderCPrivate
@@ -129,6 +130,9 @@ peas_plugin_loader_c_get_extension (PeasPluginLoader *loader,
   g_return_val_if_fail (G_IS_OBJECT (instance), NULL);
   g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (instance, exten_type), NULL);
 
+  if (PEAS_IS_EXTENSION_BASE (instance))
+    g_object_set (instance, "plugin-info", info, NULL);
+
   return peas_extension_c_new (exten_type, G_OBJECT (instance));
 }
 
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
index 940daf8..3bd6b2e 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
@@ -15,7 +15,7 @@ static void peas_ui_configurable_iface_init (PeasUIConfigurableInterface *iface)
 
 G_DEFINE_DYNAMIC_TYPE_EXTENDED (PeasDemoHelloWorldPlugin,
                                 peasdemo_hello_world_plugin,
-                                PEAS_TYPE_PLUGIN,
+                                PEAS_TYPE_EXTENSION_BASE,
                                 0,
                                 G_IMPLEMENT_INTERFACE (PEAS_TYPE_ACTIVATABLE,
                                                        peas_activatable_iface_init)
@@ -134,7 +134,6 @@ static void
 peasdemo_hello_world_plugin_class_init (PeasDemoHelloWorldPluginClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  PeasPluginClass *plugin_class = PEAS_PLUGIN_CLASS (klass);
 
   object_class->finalize = peasdemo_hello_world_plugin_finalize;
 }
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
index 551664e..e384cc6 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
@@ -3,7 +3,7 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <libpeas/peas-plugin.h>
+#include <libpeas/peas-extension-base.h>
 #include <libpeas/peas-plugin-info.h>
 #include <libpeas/peas-object-module.h>
 
@@ -20,11 +20,11 @@ typedef struct _PeasDemoHelloWorldPlugin       PeasDemoHelloWorldPlugin;
 typedef struct _PeasDemoHelloWorldPluginClass  PeasDemoHelloWorldPluginClass;
 
 struct _PeasDemoHelloWorldPlugin {
-  PeasPlugin parent_instance;
+  PeasExtensionBase parent_instance;
 };
 
 struct _PeasDemoHelloWorldPluginClass {
-  PeasPluginClass parent_class;
+  PeasExtensionBaseClass parent_class;
 };
 
 GType                       peasdemo_hello_world_plugin_get_type  (void) G_GNUC_CONST;
diff --git a/peas-demo/plugins/pythonhello/pythonhello.py b/peas-demo/plugins/pythonhello/pythonhello.py
index 3545e2d..61cc3d3 100644
--- a/peas-demo/plugins/pythonhello/pythonhello.py
+++ b/peas-demo/plugins/pythonhello/pythonhello.py
@@ -1,12 +1,13 @@
 # -*- coding: utf-8 -*-
 # ex:set ts=4 et sw=4 ai:
 
+import gobject
 from gi.repository import Peas
 from gi.repository import Gtk
 
 LABEL_STRING="Python Says Hello!"
 
-class PythonHelloPlugin(Peas.Plugin, Peas.Activatable):
+class PythonHelloPlugin(gobject.GObject, Peas.Activatable):
     __gtype_name__ = 'PythonHelloPlugin'
 
     def do_activate(self, window):



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