[libpeas/proxys: 9/25] Split PeasActivatable out of PeasPlugin.



commit bb0679713833fe285c6fe272ecbc569bfa973962
Author: Steve Frécinaux <code istique net>
Date:   Wed May 19 01:20:34 2010 +0200

    Split PeasActivatable out of PeasPlugin.
    
    The idea there is that PeasPlugin should be the minimalist base class
    that provides stuff like plugin information and data dir accessor.

 libpeas/Makefile.am        |    2 +
 libpeas/peas-activatable.c |  107 ++++++++++++++++++++++++++++++++++++++++++++
 libpeas/peas-activatable.h |   67 +++++++++++++++++++++++++++
 libpeas/peas-plugin.c      |   67 ---------------------------
 libpeas/peas-plugin.h      |   17 -------
 5 files changed, 176 insertions(+), 84 deletions(-)
---
diff --git a/libpeas/Makefile.am b/libpeas/Makefile.am
index 983cf56..f0caed9 100644
--- a/libpeas/Makefile.am
+++ b/libpeas/Makefile.am
@@ -20,6 +20,7 @@ INST_H_FILES =			\
 	peas-plugin.h		\
 	peas-plugin-info.h	\
 	peas-extension.h	\
+	peas-activatable.h	\
 	peas-engine.h
 
 NOINST_H_FILES =		\
@@ -39,6 +40,7 @@ C_FILES =			\
 	peas-plugin-info.c	\
 	peas-plugin-loader.c	\
 	peas-extension.c	\
+	peas-activatable.c	\
 	peas-engine.c
 
 libpeas_2_0_la_SOURCES = 	\
diff --git a/libpeas/peas-activatable.c b/libpeas/peas-activatable.c
new file mode 100644
index 0000000..1cfee06
--- /dev/null
+++ b/libpeas/peas-activatable.c
@@ -0,0 +1,107 @@
+/*
+ * peas-activatable.h
+ * This file is part of libpeas
+ *
+ * Copyright (C) 2010 Steve Frécinaux
+ *
+ *  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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "peas-activatable.h"
+#include "peas-plugin.h"
+
+/**
+ * SECTION:peas-activatable
+ * @short_description: Interface for activatable plugins
+ **/
+
+G_DEFINE_INTERFACE(PeasActivatable, peas_activatable, PEAS_TYPE_PLUGIN)
+
+void
+peas_activatable_default_init (PeasActivatableInterface *iface)
+{
+}
+
+/**
+ * peas_activatable_activate:
+ * @activatable: A #PeasActivatable.
+ * @object: The #GObject on which the plugin should be activated.
+ *
+ * Activates the plugin on an object.  An instance of #PeasActivatable will be
+ * activated once for each object registered against the #PeasEngine which
+ * controls this #PeasActivatable.  For instance, a typical GUI application
+ * like gedit will activate the plugin once for each of its main windows.
+ */
+void
+peas_activatable_activate (PeasActivatable *activatable,
+                           GObject         *object)
+{
+  PeasActivatableInterface *iface;
+
+  g_return_if_fail (PEAS_IS_ACTIVATABLE (activatable));
+  g_return_if_fail (G_IS_OBJECT (object));
+
+  iface = PEAS_ACTIVATABLE_GET_IFACE (activatable);
+  if (iface->activate != NULL)
+    iface->activate (activatable, object);
+}
+
+/**
+ * peas_activatable_deactivate:
+ * @activatable: A #PeasActivatable.
+ * @object: A #GObject.
+ *
+ * Deactivates the plugin on the given object.
+ */
+void
+peas_activatable_deactivate (PeasActivatable *activatable,
+                             GObject         *object)
+{
+  PeasActivatableInterface *iface;
+
+  g_return_if_fail (PEAS_IS_ACTIVATABLE (activatable));
+  g_return_if_fail (G_IS_OBJECT (object));
+
+  iface = PEAS_ACTIVATABLE_GET_IFACE (activatable);
+  if (iface->deactivate != NULL)
+    iface->deactivate (activatable, object);
+}
+
+/**
+ * peas_activatable_update_state:
+ * @activatable: A #PeasActivatable.
+ * @object: A #GObject.
+ *
+ * Triggers an update of the plugin insternal state to take into account
+ * state changes in the targetted object, due to a plugin or an user action.
+ */
+void
+peas_activatable_update_state (PeasActivatable *activatable,
+                               GObject         *object)
+{
+  PeasActivatableInterface *iface;
+
+  g_return_if_fail (PEAS_IS_ACTIVATABLE (activatable));
+  g_return_if_fail (G_IS_OBJECT (object));
+
+  iface = PEAS_ACTIVATABLE_GET_IFACE (activatable);
+  if (iface->update_state != NULL)
+    iface->update_state (activatable, object);
+}
+
diff --git a/libpeas/peas-activatable.h b/libpeas/peas-activatable.h
new file mode 100644
index 0000000..172569e
--- /dev/null
+++ b/libpeas/peas-activatable.h
@@ -0,0 +1,67 @@
+/*
+ * peas-activatable.h
+ * This file is part of libpeas
+ *
+ * Copyright (C) 2010 - Steve Frécinaux
+ *
+ *  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_ACTIVATABLE_H__
+#define __PEAS_ACTIVATABLE_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define PEAS_TYPE_ACTIVATABLE             (peas_activatable_get_type ())
+#define PEAS_ACTIVATABLE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), PEAS_TYPE_ACTIVATABLE, PeasActivatable))
+#define PEAS_ACTIVATABLE_IFACE(obj)       (G_TYPE_CHECK_CLASS_CAST ((obj), PEAS_TYPE_ACTIVATABLE, PeasActivatableInterface))
+#define PEAS_IS_ACTIVATABLE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PEAS_TYPE_ACTIVATABLE))
+#define PEAS_ACTIVATABLE_GET_IFACE(obj)   (G_TYPE_INSTANCE_GET_INTERFACE ((obj), PEAS_TYPE_ACTIVATABLE, PeasActivatableInterface))
+
+typedef struct _PeasActivatable           PeasActivatable; /* dummy typedef */
+typedef struct _PeasActivatableInterface  PeasActivatableInterface;
+
+struct _PeasActivatableInterface {
+  GTypeInterface g_iface;
+
+  /* Virtual public methods */
+  void        (*activate)                 (PeasActivatable *activatable,
+                                           GObject         *object);
+  void        (*deactivate)               (PeasActivatable *activatable,
+                                           GObject         *object);
+  void        (*update_state)             (PeasActivatable *activatable,
+                                           GObject         *object);
+};
+
+/*
+ * Public methods
+ */
+GType             peas_activatable_get_type       (void)  G_GNUC_CONST;
+
+void              peas_activatable_activate       (PeasActivatable *plugin,
+                                                   GObject         *object);
+void              peas_activatable_deactivate     (PeasActivatable *plugin,
+                                                   GObject         *object);
+void              peas_activatable_update_state   (PeasActivatable *plugin,
+                                                   GObject         *object);
+
+G_END_DECLS
+
+#endif /* __PEAS_ACTIVATABLE_H__ */
diff --git a/libpeas/peas-plugin.c b/libpeas/peas-plugin.c
index 542b718..859b1a9 100644
--- a/libpeas/peas-plugin.c
+++ b/libpeas/peas-plugin.c
@@ -61,13 +61,6 @@ struct _PeasPluginPrivate {
 };
 
 static void
-dummy (PeasPlugin *plugin,
-       GObject    *object)
-{
-  /* Empty */
-}
-
-static void
 peas_plugin_get_property (GObject    *object,
                           guint       prop_id,
                           GValue     *value,
@@ -130,10 +123,6 @@ peas_plugin_class_init (PeasPluginClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  klass->activate = dummy;
-  klass->deactivate = dummy;
-  klass->update_ui = dummy;
-
   object_class->get_property = peas_plugin_get_property;
   object_class->set_property = peas_plugin_set_property;
   object_class->finalize = peas_plugin_finalize;
@@ -192,59 +181,3 @@ peas_plugin_get_data_dir (PeasPlugin *plugin)
 
   return g_strdup (peas_plugin_info_get_data_dir (plugin->priv->info));
 }
-
-/**
- * peas_plugin_activate:
- * @plugin: A #PeasPlugin.
- * @object: The #GObject on which the plugin should be activated.
- *
- * Activates the plugin on an object.  An instance of #PeasPlugin will be
- * activated once for each object registered against the #PeasEngine which
- * controls this #PeasPlugin.  For instance, a typical GUI application like
- * gedit will activate the plugin once for each of its main windows.
- */
-void
-peas_plugin_activate (PeasPlugin *plugin,
-                      GObject    *object)
-{
-  g_return_if_fail (PEAS_IS_PLUGIN (plugin));
-  g_return_if_fail (G_IS_OBJECT (object));
-
-  PEAS_PLUGIN_GET_CLASS (plugin)->activate (plugin, object);
-}
-
-/**
- * peas_plugin_deactivate:
- * @plugin: A #PeasPlugin.
- * @object: A #GObject.
- *
- * Deactivates the plugin on the given object.
- */
-void
-peas_plugin_deactivate (PeasPlugin *plugin,
-                        GObject    *object)
-{
-  g_return_if_fail (PEAS_IS_PLUGIN (plugin));
-  g_return_if_fail (G_IS_OBJECT (object));
-
-  PEAS_PLUGIN_GET_CLASS (plugin)->deactivate (plugin, object);
-}
-
-/**
- * peas_plugin_update_ui:
- * @plugin: A #PeasPlugin.
- * @object: A #GObject.
- *
- * Triggers an update of the user interface to take into account state changes
- * due to a plugin or an user action.
- */
-void
-peas_plugin_update_ui (PeasPlugin *plugin,
-                       GObject    *object)
-{
-  g_return_if_fail (PEAS_IS_PLUGIN (plugin));
-  g_return_if_fail (G_IS_OBJECT (object));
-
-  PEAS_PLUGIN_GET_CLASS (plugin)->update_ui (plugin, object);
-}
-
diff --git a/libpeas/peas-plugin.h b/libpeas/peas-plugin.h
index bf2a15e..75c0437 100644
--- a/libpeas/peas-plugin.h
+++ b/libpeas/peas-plugin.h
@@ -71,16 +71,6 @@ struct _PeasPlugin {
 struct _PeasPluginClass {
   GObjectClass parent_class;
 
-  /* Virtual public methods */
-  void        (*activate)                 (PeasPlugin *plugin,
-                                           GObject    *object);
-  void        (*deactivate)               (PeasPlugin *plugin,
-                                           GObject    *object);
-
-  /* FIXME: those two following functions are too UI-centric */
-  void        (*update_ui)                (PeasPlugin *plugin,
-                                           GObject    *object);
-
   /* Padding for future expansion */
   void        (*_peas_reserved1)          (void);
   void        (*_peas_reserved2)          (void);
@@ -96,13 +86,6 @@ GType peas_plugin_get_type (void)  G_GNUC_CONST;
 PeasPluginInfo   *peas_plugin_get_info                (PeasPlugin *plugin);
 gchar            *peas_plugin_get_data_dir            (PeasPlugin *plugin);
 
-void              peas_plugin_activate                (PeasPlugin *plugin,
-                                                       GObject    *object);
-void              peas_plugin_deactivate              (PeasPlugin *plugin,
-                                                       GObject    *object);
-void              peas_plugin_update_ui               (PeasPlugin *plugin,
-                                                       GObject    *object);
-
 /**
  * PEAS_REGISTER_TYPE_WITH_CODE(PARENT_TYPE, PluginName, plugin_name, CODE):
  * @PARENT_TYPE: The PeasPlugin subclass used as the parent type.



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