[libpeas/proxys: 13/22] Update peas-demo to use PeasActivatable.



commit 81539c9157b9f242680a107157bbdee13d2d8762
Author: Steve Frécinaux <code istique net>
Date:   Wed May 19 17:08:18 2010 +0200

    Update peas-demo to use PeasActivatable.
    
    There are still remains of "the ol' ways" but they should disappear
    slowly...

 peas-demo/Makefile.am                              |    2 +
 peas-demo/peas-demo-window.c                       |  108 ++++++++++++++++++++
 peas-demo/peas-demo-window.h                       |   66 ++++++++++++
 peas-demo/peas-demo.c                              |   33 +-----
 .../helloworld/peasdemo-hello-world-plugin.c       |    8 +-
 .../helloworld/peasdemo-hello-world-plugin.h       |    1 +
 6 files changed, 189 insertions(+), 29 deletions(-)
---
diff --git a/peas-demo/Makefile.am b/peas-demo/Makefile.am
index ea9d746..9e96c2e 100644
--- a/peas-demo/Makefile.am
+++ b/peas-demo/Makefile.am
@@ -11,6 +11,8 @@ INCLUDES =								\
 	$(DISABLE_DEPRECATED)
 
 peas_demo_SOURCES = \
+	peas-demo-window.c		\
+	peas-demo-window.h		\
 	peas-demo.c
 
 peas_demo_LDADD = \
diff --git a/peas-demo/peas-demo-window.c b/peas-demo/peas-demo-window.c
new file mode 100644
index 0000000..660db4c
--- /dev/null
+++ b/peas-demo/peas-demo-window.c
@@ -0,0 +1,108 @@
+/*
+ * peas-demo-window.c
+ * 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-demo-window.h"
+#include <libpeas/peas-activatable.h>
+
+G_DEFINE_TYPE (DemoWindow, demo_window, GTK_TYPE_WINDOW);
+
+static void
+demo_window_init (DemoWindow *dw)
+{
+  DemoWindowClass *klass = DEMO_WINDOW_GET_CLASS (dw);
+  gchar *label;
+
+  dw->box = gtk_vbox_new (TRUE, 6);
+  gtk_container_add (GTK_CONTAINER (dw), dw->box);
+
+  label = g_strdup_printf ("Peas Window %d", ++(klass->n_windows));
+  gtk_window_set_title (GTK_WINDOW (dw), label);
+  g_free (label);
+}
+
+static void
+on_extension_added (PeasExtensionSet *set,
+                    PeasPluginInfo   *info,
+                    PeasExtension    *exten,
+                    DemoWindow       *dw)
+{
+  peas_extension_call (exten, "activate", dw);
+}
+
+static void
+on_extension_removed (PeasExtensionSet *set,
+                      PeasPluginInfo   *info,
+                      PeasExtension    *exten,
+                      DemoWindow       *dw)
+{
+  peas_extension_call (exten, "deactivate", dw);
+}
+
+static void
+demo_window_set_data (DemoWindow *dw,
+                      PeasEngine *engine)
+{
+  dw->engine = engine;
+  dw->exten_set = peas_extension_set_new (engine, PEAS_TYPE_ACTIVATABLE);
+
+  peas_extension_set_call (dw->exten_set, "activate", dw);
+
+  g_signal_connect (dw->exten_set, "extension-added", G_CALLBACK (on_extension_added), dw);
+  g_signal_connect (dw->exten_set, "extension-removed", G_CALLBACK (on_extension_removed), dw);
+}
+
+static void
+demo_window_finalize (GObject *object)
+{
+  DemoWindow *dw = DEMO_WINDOW (object);
+
+  peas_extension_set_call (dw->exten_set, "deactivate", dw);
+
+  g_object_unref (dw->exten_set);
+  g_object_unref (dw->engine);
+
+  G_OBJECT_CLASS (demo_window_parent_class)->finalize (object);
+}
+
+static void
+demo_window_class_init (DemoWindowClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = demo_window_finalize;
+
+  klass->n_windows = 0;
+}
+
+GtkWidget *
+demo_window_new (PeasEngine *engine)
+{
+  DemoWindow *dw;
+
+  dw = g_object_new (DEMO_TYPE_WINDOW, NULL);
+  demo_window_set_data (dw, engine);
+
+  return GTK_WIDGET (dw);
+}
diff --git a/peas-demo/peas-demo-window.h b/peas-demo/peas-demo-window.h
new file mode 100644
index 0000000..76a9e00
--- /dev/null
+++ b/peas-demo/peas-demo-window.h
@@ -0,0 +1,66 @@
+/*
+ * peas-demo-window.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_DEMO_WINDOW_H__
+#define __PEAS_DEMO_WINDOW_H__
+
+#include <gtk/gtk.h>
+#include <libpeas/peas-engine.h>
+#include <libpeas/peas-extension-set.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define DEMO_TYPE_WINDOW              (demo_window_get_type())
+#define DEMO_WINDOW(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj), DEMO_TYPE_WINDOW, DemoWindow))
+#define DEMO_WINDOW_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), DEMO_TYPE_WINDOW, DemoWindowClass))
+#define DEMO_IS_WINDOW(obj)           (G_TYPE_CHECK_INSTANCE_TYPE((obj), DEMO_TYPE_WINDOW))
+#define DEMO_IS_WINDOW_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), DEMO_TYPE_WINDOW))
+#define DEMO_WINDOW_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj), DEMO_TYPE_WINDOW, DemoWindowClass))
+
+typedef struct _DemoWindow         DemoWindow;
+typedef struct _DemoWindowClass    DemoWindowClass;
+
+struct _DemoWindow
+{
+  GtkWindow parent;
+
+  GtkWidget *box;
+
+  PeasEngine *engine;
+  PeasExtensionSet *exten_set;
+};
+
+struct _DemoWindowClass
+{
+  GtkWindowClass parent_class;
+
+  guint n_windows;
+};
+
+GType       demo_window_get_type      (void)  G_GNUC_CONST;
+GtkWidget  *demo_window_new           (PeasEngine *engine);
+
+G_END_DECLS
+
+#endif /* __DEMO_WINDOW_H__  */
diff --git a/peas-demo/peas-demo.c b/peas-demo/peas-demo.c
index f98ff69..b8d6c9f 100644
--- a/peas-demo/peas-demo.c
+++ b/peas-demo/peas-demo.c
@@ -3,9 +3,11 @@
 #include <libpeas/peas-engine.h>
 #include <libpeasui/peas-ui-plugin-manager.h>
 
-PeasEngine *engine;
-GtkWidget *main_window;
-int n_windows;
+#include "peas-demo-window.h"
+
+static PeasEngine *engine;
+static GtkWidget *main_window;
+static int n_windows;
 
 static void
 activate_plugin (GtkButton   *button,
@@ -36,35 +38,12 @@ create_plugin_manager (GtkButton *button,
   gtk_widget_show_all (window);
 }
 
-static gboolean
-window_delete_event_cb (GtkWidget  *widget,
-                        GdkEvent   *event,
-                        PeasEngine *engine)
-{
-  peas_engine_remove_object (engine, G_OBJECT (widget));
-  return FALSE;
-}
-
 static void
 create_new_window (void)
 {
   GtkWidget *window;
-  GtkWidget *box;
-  gchar *label;
-
-  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-  box = gtk_vbox_new (TRUE, 6);
-  gtk_container_add (GTK_CONTAINER (window), box);
-
-  label = g_strdup_printf ("Peas Window %d", ++n_windows);
-  gtk_window_set_title (GTK_WINDOW (window), label);
-  g_free (label);
-
-  peas_engine_add_object (engine, G_OBJECT (window));
-
-  g_signal_connect (window, "delete-event",
-                    G_CALLBACK (window_delete_event_cb), engine);
 
+  window = demo_window_new (engine);
   gtk_widget_show_all (window);
 }
 
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
index fde7df8..a974996 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
@@ -166,12 +166,16 @@ register_peas_plugin (GTypeModule   *type_module)
                              NULL);
 }
 
-G_MODULE_EXPORT GObject    *create_PeasActivatable ()
+G_MODULE_EXPORT GObject *
+create_PeasActivatable ()
 {
+  g_debug ("%s called", G_STRFUNC);
   return g_object_new (PEASDEMO_TYPE_HELLO_WORLD_PLUGIN, NULL);
 }
 
-G_MODULE_EXPORT GObject    *create_PeasUIConfigurable ()
+G_MODULE_EXPORT GObject *
+create_PeasUIConfigurable ()
 {
+  g_debug ("%s called", G_STRFUNC);
   return g_object_new (PEASDEMO_TYPE_HELLO_WORLD_PLUGIN, NULL);
 }
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
index 482fd8b..7810570 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
@@ -29,6 +29,7 @@ struct _PeasDemoHelloWorldPluginClass {
 GType                       peasdemo_hello_world_plugin_get_type  (void) G_GNUC_CONST;
 G_MODULE_EXPORT GObject    *register_peas_plugin                  (GTypeModule *module);
 G_MODULE_EXPORT GObject    *create_PeasUIConfigurable ();
+G_MODULE_EXPORT GObject    *create_PeasActivatable ();
 
 G_END_DECLS
 



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