[libpeas] Drop "engine" construct properties from libpeas-gtk widgets.



commit 3a7e46716338a8b756610c5cee9927fb856f9af3
Author: Steve Frécinaux <code istique net>
Date:   Sat Aug 28 17:31:30 2010 +0200

    Drop "engine" construct properties from libpeas-gtk widgets.
    
    We can use peas_engine_get_default() instead, and hopefully be able to
    construct the widgets from GtkBuilder.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=628194

 libpeas-gtk/peas-gtk-plugin-manager-store.c |   79 +-----------------------
 libpeas-gtk/peas-gtk-plugin-manager-store.h |    2 +-
 libpeas-gtk/peas-gtk-plugin-manager-view.c  |   45 +++-----------
 libpeas-gtk/peas-gtk-plugin-manager-view.h  |    4 +-
 libpeas-gtk/peas-gtk-plugin-manager.c       |   87 ++------------------------
 libpeas-gtk/peas-gtk-plugin-manager.h       |    2 +-
 peas-demo/peas-demo.c                       |    2 +-
 7 files changed, 24 insertions(+), 197 deletions(-)
---
diff --git a/libpeas-gtk/peas-gtk-plugin-manager-store.c b/libpeas-gtk/peas-gtk-plugin-manager-store.c
index 99e6fd7..7d02588 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager-store.c
+++ b/libpeas-gtk/peas-gtk-plugin-manager-store.c
@@ -49,12 +49,6 @@ struct _PeasGtkPluginManagerStorePrivate {
   PeasEngine *engine;
 };
 
-/* Properties */
-enum {
-  PROP_0,
-  PROP_ENGINE
-};
-
 G_DEFINE_TYPE (PeasGtkPluginManagerStore, peas_gtk_plugin_manager_store, GTK_TYPE_LIST_STORE);
 
 static void
@@ -145,51 +139,9 @@ peas_gtk_plugin_manager_store_init (PeasGtkPluginManagerStore *store)
   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
                                         GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
                                         GTK_SORT_ASCENDING);
-}
 
-static void
-peas_gtk_plugin_manager_store_set_property (GObject      *object,
-                                            guint         prop_id,
-                                            const GValue *value,
-                                            GParamSpec   *pspec)
-{
-  PeasGtkPluginManagerStore *store = PEAS_GTK_PLUGIN_MANAGER_STORE (object);
-
-  switch (prop_id)
-    {
-    case PROP_ENGINE:
-      store->priv->engine = g_value_get_object (value);
-      g_object_ref (store->priv->engine);
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
-static void
-peas_gtk_plugin_manager_store_get_property (GObject    *object,
-                                            guint       prop_id,
-                                            GValue     *value,
-                                            GParamSpec *pspec)
-{
-  PeasGtkPluginManagerStore *store = PEAS_GTK_PLUGIN_MANAGER_STORE (object);
-
-  switch (prop_id)
-    {
-    case PROP_ENGINE:
-      g_value_set_object (value, store->priv->engine);
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
-static void
-peas_gtk_plugin_manager_store_constructed (GObject *object)
-{
-  PeasGtkPluginManagerStore *store = PEAS_GTK_PLUGIN_MANAGER_STORE (object);
+  /* Set up the engine synchronization */
+  store->priv->engine = g_object_ref (peas_engine_get_default ());
 
   g_signal_connect_after (store->priv->engine,
                           "load-plugin",
@@ -201,9 +153,6 @@ peas_gtk_plugin_manager_store_constructed (GObject *object)
                           store);
 
   peas_gtk_plugin_manager_store_reload (store);
-
-  if (G_OBJECT_CLASS (peas_gtk_plugin_manager_store_parent_class)->constructed != NULL)
-    G_OBJECT_CLASS (peas_gtk_plugin_manager_store_parent_class)->constructed (object);
 }
 
 static void
@@ -229,44 +178,22 @@ peas_gtk_plugin_manager_store_class_init (PeasGtkPluginManagerStoreClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  object_class->set_property = peas_gtk_plugin_manager_store_set_property;
-  object_class->get_property = peas_gtk_plugin_manager_store_get_property;
-  object_class->constructed = peas_gtk_plugin_manager_store_constructed;
   object_class->dispose = peas_gtk_plugin_manager_store_dispose;
 
-  /*
-   * PeasGtkPLuginManagerStore:engine:
-   *
-   * The #PeasEngine this store is attached to.
-   */
-  g_object_class_install_property (object_class,
-                                   PROP_ENGINE,
-                                   g_param_spec_object ("engine",
-                                                        "engine",
-                                                        "The PeasEngine this store is attached to",
-                                                        PEAS_TYPE_ENGINE,
-                                                        G_PARAM_READWRITE |
-                                                        G_PARAM_CONSTRUCT_ONLY |
-                                                        G_PARAM_STATIC_STRINGS));
-
   g_type_class_add_private (object_class, sizeof (PeasGtkPluginManagerStorePrivate));
 }
 
 /*
  * peas_gtk_plugin_manager_store_new:
- * @engine: A #PeasEngine.
  *
  * Creates a new plugin manager store for the given #PeasEngine.
  *
  * Returns: the new #PeasGtkPluginManagerStore.
  */
 PeasGtkPluginManagerStore  *
-peas_gtk_plugin_manager_store_new (PeasEngine *engine)
+peas_gtk_plugin_manager_store_new (void)
 {
-  g_return_val_if_fail (PEAS_IS_ENGINE (engine), NULL);
-
   return PEAS_GTK_PLUGIN_MANAGER_STORE (g_object_new (PEAS_GTK_TYPE_PLUGIN_MANAGER_STORE,
-                                                      "engine", engine,
                                                       NULL));
 }
 
diff --git a/libpeas-gtk/peas-gtk-plugin-manager-store.h b/libpeas-gtk/peas-gtk-plugin-manager-store.h
index 568f621..592d35f 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager-store.h
+++ b/libpeas-gtk/peas-gtk-plugin-manager-store.h
@@ -68,7 +68,7 @@ struct _PeasGtkPluginManagerStoreClass {
 };
 
 GType                       peas_gtk_plugin_manager_store_get_type              (void) G_GNUC_CONST;
-PeasGtkPluginManagerStore  *peas_gtk_plugin_manager_store_new                   (PeasEngine                *engine);
+PeasGtkPluginManagerStore  *peas_gtk_plugin_manager_store_new                   (void);
 
 void                        peas_gtk_plugin_manager_store_reload                (PeasGtkPluginManagerStore *store);
 
diff --git a/libpeas-gtk/peas-gtk-plugin-manager-view.c b/libpeas-gtk/peas-gtk-plugin-manager-view.c
index 7bc9a70..9741347 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager-view.c
+++ b/libpeas-gtk/peas-gtk-plugin-manager-view.c
@@ -63,7 +63,6 @@ struct _PeasGtkPluginManagerViewPrivate {
 /* Properties */
 enum {
   PROP_0,
-  PROP_ENGINE,
   PROP_SHOW_BUILTIN
 };
 
@@ -469,6 +468,13 @@ peas_gtk_plugin_manager_view_init (PeasGtkPluginManagerView *view)
                                             PEAS_GTK_TYPE_PLUGIN_MANAGER_VIEW,
                                             PeasGtkPluginManagerViewPrivate);
 
+  view->priv->store = peas_gtk_plugin_manager_store_new ();
+  view->priv->engine = g_object_ref (peas_engine_get_default ());
+  g_signal_connect (view->priv->engine,
+                    "notify::plugin-list",
+                    G_CALLBACK (plugin_list_changed_cb),
+                    view);
+
   gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
 
@@ -551,10 +557,6 @@ peas_gtk_plugin_manager_view_set_property (GObject      *object,
 
   switch (prop_id)
     {
-    case PROP_ENGINE:
-      view->priv->engine = g_value_get_object (value);
-      g_object_ref (view->priv->engine);
-      break;
     case PROP_SHOW_BUILTIN:
       peas_gtk_plugin_manager_view_set_show_builtin (view,
                                                     g_value_get_boolean (value));
@@ -575,9 +577,6 @@ peas_gtk_plugin_manager_view_get_property (GObject    *object,
 
   switch (prop_id)
     {
-    case PROP_ENGINE:
-      g_value_set_object (value, view->priv->engine);
-      break;
     case PROP_SHOW_BUILTIN:
       g_value_set_boolean (value,
                            peas_gtk_plugin_manager_view_get_show_builtin (view));
@@ -593,17 +592,10 @@ peas_gtk_plugin_manager_view_constructed (GObject *object)
 {
   PeasGtkPluginManagerView *view = PEAS_GTK_PLUGIN_MANAGER_VIEW (object);
 
-  view->priv->store = peas_gtk_plugin_manager_store_new (view->priv->engine);
-
   /* Properly set the model */
   view->priv->show_builtin = TRUE;
   peas_gtk_plugin_manager_view_set_show_builtin (view, FALSE);
 
-  g_signal_connect (view->priv->engine,
-                    "notify::plugin-list",
-                    G_CALLBACK (plugin_list_changed_cb),
-                    view);
-
   if (G_OBJECT_CLASS (peas_gtk_plugin_manager_view_parent_class)->constructed != NULL)
     G_OBJECT_CLASS (peas_gtk_plugin_manager_view_parent_class)->constructed (object);
 }
@@ -650,27 +642,12 @@ peas_gtk_plugin_manager_view_class_init (PeasGtkPluginManagerViewClass *klass)
   object_class->dispose = peas_gtk_plugin_manager_view_dispose;
 
   /**
-   * PeasGtkPLuginManagerView:engine:
-   *
-   * The #PeasEngine this view is attached to.
-   */
-  g_object_class_install_property (object_class,
-                                   PROP_ENGINE,
-                                   g_param_spec_object ("engine",
-                                                        "engine",
-                                                        "The PeasEngine this view is attached to",
-                                                        PEAS_TYPE_ENGINE,
-                                                        G_PARAM_READWRITE |
-                                                        G_PARAM_CONSTRUCT_ONLY |
-                                                        G_PARAM_STATIC_STRINGS));
-
-  /**
    * PeasGtkPLuginManagerView:show-builtin:
    *
    * If builtin plugins should be shown.
    */
   g_object_class_install_property (object_class,
-                                   PROP_ENGINE,
+                                   PROP_SHOW_BUILTIN,
                                    g_param_spec_boolean ("show-builtin",
                                                          "show-builtin",
                                                          "If builtin plugins should be shown",
@@ -703,19 +680,15 @@ peas_gtk_plugin_manager_view_class_init (PeasGtkPluginManagerViewClass *klass)
 
 /**
  * peas_gtk_plugin_manager_view_new:
- * @engine: A #PeasEngine.
  *
  * Creates a new plugin manager view for the given #PeasEngine.
  *
  * Returns: the new #PeasGtkPluginManagerView.
  */
 GtkWidget *
-peas_gtk_plugin_manager_view_new (PeasEngine *engine)
+peas_gtk_plugin_manager_view_new (void)
 {
-  g_return_val_if_fail (PEAS_IS_ENGINE (engine), NULL);
-
   return GTK_WIDGET (g_object_new (PEAS_GTK_TYPE_PLUGIN_MANAGER_VIEW,
-                                   "engine", engine,
                                    NULL));
 }
 
diff --git a/libpeas-gtk/peas-gtk-plugin-manager-view.h b/libpeas-gtk/peas-gtk-plugin-manager-view.h
index 7c80a4f..80596cc 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager-view.h
+++ b/libpeas-gtk/peas-gtk-plugin-manager-view.h
@@ -58,8 +58,8 @@ struct _PeasGtkPluginManagerViewClass {
                              GtkMenu                  *menu);
 };
 
-GType           peas_gtk_plugin_manager_view_get_type            (void) G_GNUC_CONST;
-GtkWidget      *peas_gtk_plugin_manager_view_new                 (PeasEngine              *engine);
+GType           peas_gtk_plugin_manager_view_get_type             (void) G_GNUC_CONST;
+GtkWidget      *peas_gtk_plugin_manager_view_new                  (void);
 
 void            peas_gtk_plugin_manager_view_set_show_builtin     (PeasGtkPluginManagerView *view,
                                                                    gboolean                  show_builtin);
diff --git a/libpeas-gtk/peas-gtk-plugin-manager.c b/libpeas-gtk/peas-gtk-plugin-manager.c
index 0bf5d42..3410b44 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager.c
+++ b/libpeas-gtk/peas-gtk-plugin-manager.c
@@ -68,12 +68,6 @@ struct _PeasGtkPluginManagerPrivate {
   GtkWidget *configure_button;
 };
 
-/* Properties */
-enum {
-  PROP_0,
-  PROP_ENGINE
-};
-
 G_DEFINE_TYPE (PeasGtkPluginManager, peas_gtk_plugin_manager, GTK_TYPE_VBOX);
 
 static gboolean
@@ -375,11 +369,14 @@ peas_gtk_plugin_manager_init (PeasGtkPluginManager *pm)
 {
   GtkWidget *label;
   GtkWidget *hbuttonbox;
+  GtkTreeSelection *selection;
 
   pm->priv = G_TYPE_INSTANCE_GET_PRIVATE (pm,
                                           PEAS_GTK_TYPE_PLUGIN_MANAGER,
                                           PeasGtkPluginManagerPrivate);
 
+  pm->priv->engine = g_object_ref (peas_engine_get_default ());
+
   gtk_box_set_spacing (GTK_BOX (pm), 6);
 
   gtk_widget_push_composite_child ();
@@ -397,6 +394,9 @@ peas_gtk_plugin_manager_init (PeasGtkPluginManager *pm)
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), pm->priv->sw);
   gtk_box_pack_start (GTK_BOX (pm), pm->priv->sw, TRUE, TRUE, 0);
 
+  pm->priv->view = peas_gtk_plugin_manager_view_new ();
+  gtk_container_add (GTK_CONTAINER (pm->priv->sw), pm->priv->view);
+
   hbuttonbox = gtk_hbutton_box_new ();
   gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END);
   gtk_box_set_spacing (GTK_BOX (hbuttonbox), 6);
@@ -421,60 +421,12 @@ peas_gtk_plugin_manager_init (PeasGtkPluginManager *pm)
                     "clicked",
                     G_CALLBACK (show_configure_cb),
                     pm);
-}
-
-static void
-peas_gtk_plugin_manager_set_property (GObject      *object,
-                                      guint         prop_id,
-                                      const GValue *value,
-                                      GParamSpec   *pspec)
-{
-  PeasGtkPluginManager *pm = PEAS_GTK_PLUGIN_MANAGER (object);
-
-  switch (prop_id)
-    {
-    case PROP_ENGINE:
-      pm->priv->engine = g_value_get_object (value);
-      g_object_ref (pm->priv->engine);
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
-static void
-peas_gtk_plugin_manager_get_property (GObject    *object,
-                                      guint       prop_id,
-                                      GValue     *value,
-                                      GParamSpec *pspec)
-{
-  PeasGtkPluginManager *pm = PEAS_GTK_PLUGIN_MANAGER (object);
-
-  switch (prop_id)
-    {
-    case PROP_ENGINE:
-      g_value_set_object (value, pm->priv->engine);
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
 
-static void
-peas_gtk_plugin_manager_constructed (GObject *object)
-{
-  PeasGtkPluginManager *pm = PEAS_GTK_PLUGIN_MANAGER (object);
-  GtkTreeSelection *selection;
 
   /* When we create the manager, we always rescan the plugins directory
      Must come after the view has connected to notify::plugin-list */
   peas_engine_rescan_plugins (pm->priv->engine);
 
-  pm->priv->view = peas_gtk_plugin_manager_view_new (pm->priv->engine);
-  gtk_container_add (GTK_CONTAINER (pm->priv->sw), pm->priv->view);
-
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (pm->priv->view));
 
   g_signal_connect_after (pm->priv->engine,
@@ -500,9 +452,6 @@ peas_gtk_plugin_manager_constructed (GObject *object)
 
   /* Update the button sensitivity */
   selection_changed_cb (selection, pm);
-
-  if (G_OBJECT_CLASS (peas_gtk_plugin_manager_parent_class)->constructed != NULL)
-    G_OBJECT_CLASS (peas_gtk_plugin_manager_parent_class)->constructed (object);
 }
 
 static void
@@ -528,44 +477,22 @@ peas_gtk_plugin_manager_class_init (PeasGtkPluginManagerClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  object_class->set_property = peas_gtk_plugin_manager_set_property;
-  object_class->get_property = peas_gtk_plugin_manager_get_property;
-  object_class->constructed = peas_gtk_plugin_manager_constructed;
   object_class->dispose = peas_gtk_plugin_manager_dispose;
 
-  /**
-   * PeasGtkPluginManager:engine:
-   *
-   * The #PeasEngine this manager is attached to.
-   */
-  g_object_class_install_property (object_class,
-                                   PROP_ENGINE,
-                                   g_param_spec_object ("engine",
-                                                        "engine",
-                                                        "The PeasEngine this manager is attached to",
-                                                        PEAS_TYPE_ENGINE,
-                                                        G_PARAM_READWRITE |
-                                                        G_PARAM_CONSTRUCT_ONLY |
-                                                        G_PARAM_STATIC_STRINGS));
-
   g_type_class_add_private (object_class, sizeof (PeasGtkPluginManagerPrivate));
 }
 
 /**
  * peas_gtk_plugin_manager_new:
- * @engine: A #PeasEngine.
  *
  * Creates a new plugin manager for the given #PeasEngine.
  *
  * Returns: the new #PeasGtkPluginManager.
  */
 GtkWidget *
-peas_gtk_plugin_manager_new (PeasEngine *engine)
+peas_gtk_plugin_manager_new (void)
 {
-  g_return_val_if_fail (PEAS_IS_ENGINE (engine), NULL);
-
   return GTK_WIDGET (g_object_new (PEAS_GTK_TYPE_PLUGIN_MANAGER,
-                                   "engine", engine,
                                    NULL));
 }
 
diff --git a/libpeas-gtk/peas-gtk-plugin-manager.h b/libpeas-gtk/peas-gtk-plugin-manager.h
index 96a72cd..2d5c4b9 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager.h
+++ b/libpeas-gtk/peas-gtk-plugin-manager.h
@@ -55,7 +55,7 @@ struct _PeasGtkPluginManagerClass
 };
 
 GType       peas_gtk_plugin_manager_get_type  (void)  G_GNUC_CONST;
-GtkWidget  *peas_gtk_plugin_manager_new       (PeasEngine           *engine);
+GtkWidget  *peas_gtk_plugin_manager_new       (void);
 
 GtkWidget  *peas_gtk_plugin_manager_get_view  (PeasGtkPluginManager *pm);
 
diff --git a/peas-demo/peas-demo.c b/peas-demo/peas-demo.c
index 459f0a0..e87ba11 100644
--- a/peas-demo/peas-demo.c
+++ b/peas-demo/peas-demo.c
@@ -63,7 +63,7 @@ create_plugin_manager (GtkButton *button,
   gtk_container_set_border_width (GTK_CONTAINER (window), 6);
   gtk_window_set_title (GTK_WINDOW (window), "Peas Plugin Manager");
 
-  manager = peas_gtk_plugin_manager_new (engine);
+  manager = peas_gtk_plugin_manager_new ();
   gtk_container_add (GTK_CONTAINER (window), manager);
 
   gtk_widget_show_all (window);



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