[gtranslator] Add tab activatable extension point.



commit c56b7742907febdc53f145fedf78bcddcd082a0d
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Tue May 3 14:59:39 2011 +0200

    Add tab activatable extension point.

 src/Makefile.am           |    2 +
 src/gtr-tab-activatable.c |  125 +++++++++++++++++++++++++++++++++++++++++++++
 src/gtr-tab-activatable.h |   64 +++++++++++++++++++++++
 src/gtr-tab.c             |   44 ++++++++++++++++
 4 files changed, 235 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 11d7fe6..72df2c8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -69,6 +69,7 @@ INST_H_FILES = \
 	gtr-po.h \
 	gtr-profile.h \
 	gtr-statusbar.h \
+	gtr-tab-activatable.h \
 	gtr-tab.h \
 	gtr-view.h \
 	gtr-window-activatable.h \
@@ -95,6 +96,7 @@ header_DATA = \
 	$(INST_H_FILES)
 
 libgtranslator_private_la_SOURCES =	\
+	gtr-tab-activatable.c \
 	gtr-window-activatable.c
 
 libgtranslator_c_files = \
diff --git a/src/gtr-tab-activatable.c b/src/gtr-tab-activatable.c
new file mode 100644
index 0000000..ec476c3
--- /dev/null
+++ b/src/gtr-tab-activatable.c
@@ -0,0 +1,125 @@
+/*
+ * gtr-tab-activatable.h
+ * This file is part of gtr
+ *
+ * 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 "gtr-tab-activatable.h"
+#include "gtr-tab.h"
+
+/**
+ * SECTION:gtr-tab-activatable
+ * @short_description: Interface for activatable extensions on tabs
+ * @see_also: #PeasExtensionSet
+ *
+ * #GtrTabActivatable is an interface which should be implemented by
+ * extensions that should be activated on a gtr main tab.
+ **/
+
+G_DEFINE_INTERFACE (GtrTabActivatable, gtr_tab_activatable, G_TYPE_OBJECT)
+
+void
+gtr_tab_activatable_default_init (GtrTabActivatableInterface * iface)
+{
+  static gboolean initialized = FALSE;
+
+  if (!initialized)
+    {
+      /**
+       * GtrTabActivatable:tab:
+       *
+       * The tab property contains the gtr tab for this
+       * #GtrTabActivatable instance.
+       */
+      g_object_interface_install_property (iface,
+                                           g_param_spec_object ("tab",
+                                                                "Tab",
+                                                                "The gtranslator tab",
+                                                                GTR_TYPE_TAB,
+                                                                G_PARAM_READWRITE |
+                                                                G_PARAM_CONSTRUCT_ONLY |
+                                                                G_PARAM_STATIC_STRINGS));
+
+      initialized = TRUE;
+    }
+}
+
+/**
+ * gtr_tab_activatable_activate:
+ * @activatable: A #GtrTabActivatable.
+ *
+ * Activates the extension on the tab property.
+ */
+void
+gtr_tab_activatable_activate (GtrTabActivatable * activatable)
+{
+  GtrTabActivatableInterface *iface;
+
+  g_return_if_fail (GTR_IS_TAB_ACTIVATABLE (activatable));
+
+  iface = GTR_TAB_ACTIVATABLE_GET_IFACE (activatable);
+  if (iface->activate != NULL)
+    {
+      iface->activate (activatable);
+    }
+}
+
+/**
+ * gtr_tab_activatable_deactivate:
+ * @activatable: A #GtrTabActivatable.
+ *
+ * Deactivates the extension on the tab property.
+ */
+void
+gtr_tab_activatable_deactivate (GtrTabActivatable * activatable)
+{
+  GtrTabActivatableInterface *iface;
+
+  g_return_if_fail (GTR_IS_TAB_ACTIVATABLE (activatable));
+
+  iface = GTR_TAB_ACTIVATABLE_GET_IFACE (activatable);
+  if (iface->deactivate != NULL)
+    {
+      iface->deactivate (activatable);
+    }
+}
+
+/**
+ * gtr_tab_activatable_update_state:
+ * @activatable: A #GtrTabActivatable.
+ *
+ * Triggers an update of the extension internal state to take into account
+ * state changes in the tab, due to some event or user action.
+ */
+void
+gtr_tab_activatable_update_state (GtrTabActivatable * activatable)
+{
+  GtrTabActivatableInterface *iface;
+
+  g_return_if_fail (GTR_IS_TAB_ACTIVATABLE (activatable));
+
+  iface = GTR_TAB_ACTIVATABLE_GET_IFACE (activatable);
+  if (iface->update_state != NULL)
+    {
+      iface->update_state (activatable);
+    }
+}
diff --git a/src/gtr-tab-activatable.h b/src/gtr-tab-activatable.h
new file mode 100644
index 0000000..ee01228
--- /dev/null
+++ b/src/gtr-tab-activatable.h
@@ -0,0 +1,64 @@
+/*
+ * gtr-tab-activatable.h
+ * This file is part of gtr
+ *
+ * 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 __GTR_TAB_ACTIVATABLE_H__
+#define __GTR_TAB_ACTIVATABLE_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+/*
+ * Type checking and casting macros
+ */
+#define GTR_TYPE_TAB_ACTIVATABLE		(gtr_tab_activatable_get_type ())
+#define GTR_TAB_ACTIVATABLE(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTR_TYPE_TAB_ACTIVATABLE, GtrTabActivatable))
+#define GTR_TAB_ACTIVATABLE_IFACE(obj)	(G_TYPE_CHECK_CLASS_CAST ((obj), GTR_TYPE_TAB_ACTIVATABLE, GtrTabActivatableInterface))
+#define GTR_IS_TAB_ACTIVATABLE(obj)	(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTR_TYPE_TAB_ACTIVATABLE))
+#define GTR_TAB_ACTIVATABLE_GET_IFACE(obj)	(G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTR_TYPE_TAB_ACTIVATABLE, GtrTabActivatableInterface))
+typedef struct _GtrTabActivatable GtrTabActivatable;      /* dummy typedef */
+typedef struct _GtrTabActivatableInterface GtrTabActivatableInterface;
+
+struct _GtrTabActivatableInterface
+{
+  GTypeInterface g_iface;
+
+  /* Virtual public methods */
+  void (*activate) (GtrTabActivatable * activatable);
+  void (*deactivate) (GtrTabActivatable * activatable);
+  void (*update_state) (GtrTabActivatable * activatable);
+};
+
+/*
+ * Public methods
+ */
+GType
+gtr_tab_activatable_get_type (void)
+  G_GNUC_CONST;
+
+     void gtr_tab_activatable_activate (GtrTabActivatable *
+                                           activatable);
+     void gtr_tab_activatable_deactivate (GtrTabActivatable *
+                                             activatable);
+     void gtr_tab_activatable_update_state (GtrTabActivatable *
+                                               activatable);
+
+G_END_DECLS
+#endif /* __GTR_TAB_ACTIVATABLE_H__ */
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index c6def0e..21419e9 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -37,6 +37,7 @@
 #include "gtr-io-error-info-bar.h"
 #include "gtr-message-table.h"
 #include "gtr-msg.h"
+#include "gtr-tab-activatable.h"
 #include "gtr-tab.h"
 #include "gtr-po.h"
 #include "gtr-settings.h"
@@ -44,11 +45,13 @@
 #include "gtr-translation-memory.h"
 #include "gtr-translation-memory-ui.h"
 #include "gtr-dirs.h"
+#include "gtr-plugins-engine.h"
 
 #include <glib.h>
 #include <glib-object.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
+#include <libpeas/peas-extension-set.h>
 
 #ifdef G_OS_WIN32
 #include <gdl/libgdltypebuiltins.h>
@@ -104,6 +107,8 @@ struct _GtrTabPrivate
   GtkWidget *fuzzy;
   GtkWidget *untranslated;
 
+  PeasExtensionSet *extensions;
+
   /* Autosave */
   GTimer *timer;
   gint autosave_interval;
@@ -831,6 +836,24 @@ gtr_tab_draw (GtrTab *tab)
 }
 
 static void
+extension_added (PeasExtensionSet *extensions,
+                 PeasPluginInfo   *info,
+                 PeasExtension    *exten,
+                 GtrTab           *tab)
+{
+  peas_extension_call (exten, "activate");
+}
+
+static void
+extension_removed (PeasExtensionSet *extensions,
+                   PeasPluginInfo   *info,
+                   PeasExtension    *exten,
+                   GtrTab           *tab)
+{
+  peas_extension_call (exten, "deactivate");
+}
+
+static void
 gtr_tab_init (GtrTab * tab)
 {
   tab->priv = GTR_TAB_GET_PRIVATE (tab);
@@ -853,6 +876,21 @@ gtr_tab_init (GtrTab * tab)
                                                      GTR_SETTINGS_AUTO_SAVE_INTERVAL);
   if (tab->priv->autosave_interval <= 0)
     tab->priv->autosave_interval = 1;
+
+  /* Plugins */
+  tab->priv->extensions = peas_extension_set_new (PEAS_ENGINE (gtr_plugins_engine_get_default ()),
+                                                  GTR_TYPE_TAB_ACTIVATABLE,
+                                                  "tab", tab,
+                                                  NULL);
+  g_signal_connect (tab->priv->extensions,
+                    "extension-added",
+                    G_CALLBACK (extension_added),
+                    tab);
+  g_signal_connect (tab->priv->extensions,
+                    "extension-removed",
+                    G_CALLBACK (extension_removed),
+                    tab);
+  peas_extension_set_call (tab->priv->extensions, "activate");
 }
 
 static void
@@ -874,6 +912,12 @@ gtr_tab_dispose (GObject * object)
 {
   GtrTabPrivate *priv = GTR_TAB (object)->priv;
 
+  if (priv->extensions != NULL)
+    {
+      g_object_unref (priv->extensions);
+      priv->extensions = NULL;
+    }
+
   if (priv->po != NULL)
     {
       g_object_unref (priv->po);



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