[Xfce4-commits] <xfce4-panel:nick/gtk3> Install XfcePanelPlugin properties at once.

Nick Schermer noreply at xfce.org
Mon Apr 8 00:52:23 CEST 2013


Updating branch refs/heads/nick/gtk3
         to 791ab4d9f75fe2916cfffeca225a7c52ef5290c6 (commit)
       from 157e3165ec1b72d9773d476351f15c6a4583fd92 (commit)

commit 791ab4d9f75fe2916cfffeca225a7c52ef5290c6
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Mar 23 13:34:44 2013 +0100

    Install XfcePanelPlugin properties at once.
    
    Also use direct pspec notify to avoid lookup.

 libxfce4panel/xfce-panel-plugin.c |  240 ++++++++++++++++++-------------------
 1 files changed, 116 insertions(+), 124 deletions(-)

diff --git a/libxfce4panel/xfce-panel-plugin.c b/libxfce4panel/xfce-panel-plugin.c
index 8126922..d43d4e9 100644
--- a/libxfce4panel/xfce-panel-plugin.c
+++ b/libxfce4panel/xfce-panel-plugin.c
@@ -131,7 +131,8 @@ enum
   PROP_EXPAND,
   PROP_MODE,
   PROP_NROWS,
-  PROP_SHRINK
+  PROP_SHRINK,
+  N_PROPERTIES
 };
 
 enum
@@ -195,9 +196,10 @@ struct _XfcePanelPluginPrivate
 
 
 
-static guint  plugin_signals[LAST_SIGNAL];
-static GQuark item_properties = 0;
-static GQuark item_about = 0;
+static guint       plugin_signals[LAST_SIGNAL];
+static GQuark      item_properties = 0;
+static GQuark      item_about = 0;
+static GParamSpec *plugin_props[N_PROPERTIES] = { NULL, };
 
 
 
@@ -463,15 +465,14 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    * xfce_panel_plugin_get_name() is recommended since that returns
    * a const string.
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_NAME,
-                                   g_param_spec_string ("name",
-                                                        "Name",
-                                                        "Plugin internal name",
-                                                        NULL,
-                                                        G_PARAM_READWRITE
-                                                        | G_PARAM_STATIC_STRINGS
-                                                        | G_PARAM_CONSTRUCT_ONLY));
+  plugin_props[PROP_NAME] =
+      g_param_spec_string ("name",
+                           "Name",
+                           "Plugin internal name",
+                           NULL,
+                           G_PARAM_READWRITE
+                           | G_PARAM_STATIC_STRINGS
+                           | G_PARAM_CONSTRUCT_ONLY);
 
   /**
    * XfcePanelPlugin:display-name:
@@ -481,15 +482,14 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    * it to read the plugin display name, but xfce_panel_plugin_get_display_name()
    * is recommended.
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_DISPLAY_NAME,
-                                   g_param_spec_string ("display-name",
-                                                        "Display Name",
-                                                        "Plugin display name",
-                                                        NULL,
-                                                        G_PARAM_READWRITE
-                                                        | G_PARAM_STATIC_STRINGS
-                                                        | G_PARAM_CONSTRUCT_ONLY));
+  plugin_props[PROP_DISPLAY_NAME] =
+      g_param_spec_string ("display-name",
+                           "Display Name",
+                           "Plugin display name",
+                           NULL,
+                           G_PARAM_READWRITE
+                           | G_PARAM_STATIC_STRINGS
+                           | G_PARAM_CONSTRUCT_ONLY);
 
   /**
    * XfcePanelPlugin:comment:
@@ -501,15 +501,14 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    *
    * Since: 4.8
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_COMMENT,
-                                   g_param_spec_string ("comment",
-                                                        "Comment",
-                                                        "Plugin comment",
-                                                        NULL,
-                                                        G_PARAM_READWRITE
-                                                        | G_PARAM_STATIC_STRINGS
-                                                        | G_PARAM_CONSTRUCT_ONLY));
+  plugin_props[PROP_COMMENT] =
+      g_param_spec_string ("comment",
+                           "Comment",
+                           "Plugin comment",
+                           NULL,
+                           G_PARAM_READWRITE
+                           | G_PARAM_STATIC_STRINGS
+                           | G_PARAM_CONSTRUCT_ONLY);
 
   /**
    * XfcePanelPlugin:id:
@@ -520,15 +519,14 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    *
    * Since: 4.8
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_UNIQUE_ID,
-                                   g_param_spec_int ("unique-id",
-                                                     "Unique ID",
-                                                     "Unique plugin ID",
-                                                     -1, G_MAXINT, -1,
-                                                     G_PARAM_READWRITE
-                                                     | G_PARAM_STATIC_STRINGS
-                                                     | G_PARAM_CONSTRUCT_ONLY));
+  plugin_props[PROP_UNIQUE_ID] =
+      g_param_spec_int ("unique-id",
+                        "Unique ID",
+                        "Unique plugin ID",
+                        -1, G_MAXINT, -1,
+                        G_PARAM_READWRITE
+                        | G_PARAM_STATIC_STRINGS
+                        | G_PARAM_CONSTRUCT_ONLY);
 
   /**
    * XfcePanelPlugin:arguments:
@@ -538,15 +536,14 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    * use it to read the arguments array, but
    * xfce_panel_plugin_get_arguments() is recommended.
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_ARGUMENTS,
-                                   g_param_spec_boxed ("arguments",
-                                                       "Arguments",
-                                                       "Startup arguments for the plugin",
-                                                       G_TYPE_STRV,
-                                                       G_PARAM_READWRITE
-                                                       | G_PARAM_STATIC_STRINGS
-                                                       | G_PARAM_CONSTRUCT_ONLY));
+  plugin_props[PROP_ARGUMENTS] =
+      g_param_spec_boxed ("arguments",
+                          "Arguments",
+                          "Startup arguments for the plugin",
+                          G_TYPE_STRV,
+                          G_PARAM_READWRITE
+                          | G_PARAM_STATIC_STRINGS
+                          | G_PARAM_CONSTRUCT_ONLY);
 
   /**
    * XfcePanelPlugin:orientation:
@@ -554,15 +551,14 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    * The #GtkOrientation of the #XfcePanelPlugin. Plugin writer can use it to read the
    * plugin orientation, but xfce_panel_plugin_get_orientation() is recommended.
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_ORIENTATION,
-                                   g_param_spec_enum ("orientation",
-                                                      "Orientation",
-                                                      "Orientation of the plugin's panel",
-                                                      GTK_TYPE_ORIENTATION,
-                                                      GTK_ORIENTATION_HORIZONTAL,
-                                                      G_PARAM_READABLE
-                                                      | G_PARAM_STATIC_STRINGS));
+  plugin_props[PROP_ORIENTATION] =
+      g_param_spec_enum ("orientation",
+                         "Orientation",
+                         "Orientation of the plugin's panel",
+                         GTK_TYPE_ORIENTATION,
+                         GTK_ORIENTATION_HORIZONTAL,
+                         G_PARAM_READABLE
+                         | G_PARAM_STATIC_STRINGS);
 
   /**
    * XfcePanelPlugin:size:
@@ -570,14 +566,13 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    * The size in pixels of the #XfcePanelPlugin. Plugin writer can use it to read the
    * plugin size, but xfce_panel_plugin_get_size() is recommended.
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_SIZE,
-                                   g_param_spec_int ("size",
-                                                     "Size",
-                                                     "Size of the plugin's panel",
-                                                     0, (128 * 6), 0,
-                                                     G_PARAM_READABLE
-                                                     | G_PARAM_STATIC_STRINGS));
+  plugin_props[PROP_SIZE] =
+      g_param_spec_int ("size",
+                        "Size",
+                        "Size of the plugin's panel",
+                        0, (128 * 6), 0,
+                        G_PARAM_READABLE
+                        | G_PARAM_STATIC_STRINGS);
 
   /**
    * XfcePanelPlugin:screen-position:
@@ -586,15 +581,14 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    * to read the plugin's screen position, but xfce_panel_plugin_get_screen_psotion()
    * is recommended.
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_SCREEN_POSITION,
-                                   g_param_spec_enum  ("screen-position",
-                                                       "Screen Position",
-                                                       "Screen position of the plugin's panel",
-                                                       XFCE_TYPE_SCREEN_POSITION,
-                                                       XFCE_SCREEN_POSITION_NONE,
-                                                       G_PARAM_READABLE
-                                                       | G_PARAM_STATIC_STRINGS));
+  plugin_props[PROP_SCREEN_POSITION] =
+      g_param_spec_enum  ("screen-position",
+                          "Screen Position",
+                          "Screen position of the plugin's panel",
+                          XFCE_TYPE_SCREEN_POSITION,
+                          XFCE_SCREEN_POSITION_NONE,
+                          G_PARAM_READABLE
+                          | G_PARAM_STATIC_STRINGS);
 
   /**
    * XfcePanelPlugin:small:
@@ -605,14 +599,13 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    *
    * Since: 4.10
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_SMALL,
-                                   g_param_spec_boolean ("small",
-                                                         "Small",
-                                                         "Is this plugin small, e.g. a single button?",
-                                                         FALSE,
-                                                         G_PARAM_READWRITE
-                                                         | G_PARAM_STATIC_STRINGS));
+  plugin_props[PROP_SMALL] =
+      g_param_spec_boolean ("small",
+                            "Small",
+                            "Is this plugin small, e.g. a single button?",
+                            FALSE,
+                            G_PARAM_READWRITE
+                            | G_PARAM_STATIC_STRINGS);
 
   /**
    * XfcePanelPlugin:expand:
@@ -621,14 +614,13 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    * to read or set this property, but xfce_panel_plugin_set_expand()
    * is recommended.
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_EXPAND,
-                                   g_param_spec_boolean ("expand",
-                                                         "Expand",
-                                                         "Whether this plugin is expanded",
-                                                         FALSE,
-                                                         G_PARAM_READWRITE
-                                                         | G_PARAM_STATIC_STRINGS));
+  plugin_props[PROP_EXPAND] =
+      g_param_spec_boolean ("expand",
+                            "Expand",
+                            "Whether this plugin is expanded",
+                            FALSE,
+                            G_PARAM_READWRITE
+                            | G_PARAM_STATIC_STRINGS);
 
   /**
    * XfcePanelPlugin:shrink:
@@ -639,14 +631,13 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    *
    * Since: 4.10
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_SHRINK,
-                                   g_param_spec_boolean ("shrink",
-                                                         "Shrink",
-                                                         "Whether this plugin can shrink",
-                                                         FALSE,
-                                                         G_PARAM_READWRITE
-                                                         | G_PARAM_STATIC_STRINGS));
+  plugin_props[PROP_SHRINK] =
+      g_param_spec_boolean ("shrink",
+                            "Shrink",
+                            "Whether this plugin can shrink",
+                            FALSE,
+                            G_PARAM_READWRITE
+                            | G_PARAM_STATIC_STRINGS);
 
   /**
    * XfcePanelPlugin:mode:
@@ -655,15 +646,14 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    *
    * Since: 4.10
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_MODE,
-                                   g_param_spec_enum ("mode",
-                                                      "Mode",
-                                                      "Disply mode of the plugin",
-                                                      XFCE_TYPE_PANEL_PLUGIN_MODE,
-                                                      XFCE_PANEL_PLUGIN_MODE_HORIZONTAL,
-                                                      G_PARAM_READABLE
-                                                      | G_PARAM_STATIC_STRINGS));
+  plugin_props[PROP_MODE] =
+      g_param_spec_enum ("mode",
+                         "Mode",
+                         "Disply mode of the plugin",
+                         XFCE_TYPE_PANEL_PLUGIN_MODE,
+                         XFCE_PANEL_PLUGIN_MODE_HORIZONTAL,
+                         G_PARAM_READABLE
+                         | G_PARAM_STATIC_STRINGS);
 
   /**
    * XfcePanelPlugin:nrows:
@@ -672,14 +662,16 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
    *
    * Since: 4.10
    **/
-  g_object_class_install_property (gobject_class,
-                                   PROP_NROWS,
-                                   g_param_spec_uint ("nrows",
-                                                      "Nrows",
-                                                      "Number of rows of the panel",
-                                                      1, 6, 1,
-                                                      G_PARAM_READABLE
-                                                      | G_PARAM_STATIC_STRINGS));
+  plugin_props[PROP_NROWS] =
+      g_param_spec_uint ("nrows",
+                         "Nrows",
+                         "Number of rows of the panel",
+                         1, 6, 1,
+                         G_PARAM_READABLE
+                         | G_PARAM_STATIC_STRINGS);
+
+  /* install all properties */
+  g_object_class_install_properties (gobject_class, N_PROPERTIES, plugin_props);
 
   item_properties = g_quark_from_static_string ("item-properties");
   item_about = g_quark_from_static_string ("item-about");
@@ -1376,7 +1368,7 @@ xfce_panel_plugin_set_size (XfcePanelPluginProvider *provider,
       if (!handled)
         gtk_widget_set_size_request (GTK_WIDGET (plugin), real_size, real_size);
 
-      g_object_notify (G_OBJECT (plugin), "size");
+      g_object_notify_by_pspec (G_OBJECT (plugin), plugin_props[PROP_SIZE]);
     }
 }
 
@@ -1402,7 +1394,7 @@ xfce_panel_plugin_set_mode (XfcePanelPluginProvider *provider,
       g_signal_emit (G_OBJECT (plugin),
                      plugin_signals[MODE_CHANGED], 0, mode);
 
-      g_object_notify (G_OBJECT (plugin), "mode");
+      g_object_notify_by_pspec (G_OBJECT (plugin), plugin_props[PROP_MODE]);
 
       /* emit old orientation property for compatibility */
       new_orientation = xfce_panel_plugin_get_orientation (plugin);
@@ -1411,7 +1403,7 @@ xfce_panel_plugin_set_mode (XfcePanelPluginProvider *provider,
           g_signal_emit (G_OBJECT (plugin),
                          plugin_signals[ORIENTATION_CHANGED], 0, new_orientation);
 
-          g_object_notify (G_OBJECT (plugin), "orientation");
+          g_object_notify_by_pspec (G_OBJECT (plugin), plugin_props[PROP_ORIENTATION]);
         }
     }
 }
@@ -1436,7 +1428,7 @@ xfce_panel_plugin_set_nrows (XfcePanelPluginProvider *provider,
       g_signal_emit (G_OBJECT (plugin),
                      plugin_signals[NROWS_CHANGED], 0, nrows);
 
-      g_object_notify (G_OBJECT (plugin), "nrows");
+      g_object_notify_by_pspec (G_OBJECT (plugin), plugin_props[PROP_NROWS]);
 
       /* also the size changed */
       xfce_panel_plugin_set_size (provider, -1);
@@ -1463,7 +1455,7 @@ xfce_panel_plugin_set_screen_position (XfcePanelPluginProvider *provider,
                      plugin_signals[SCREEN_POSITION_CHANGED], 0,
                      screen_position);
 
-      g_object_notify (G_OBJECT (plugin), "screen-position");
+      g_object_notify_by_pspec (G_OBJECT (plugin), plugin_props[PROP_SCREEN_POSITION]);
     }
 }
 
@@ -1844,7 +1836,7 @@ xfce_panel_plugin_set_expand (XfcePanelPlugin *plugin,
                                               expand ? PROVIDER_SIGNAL_EXPAND_PLUGIN :
                                                   PROVIDER_SIGNAL_COLLAPSE_PLUGIN);
 
-      g_object_notify (G_OBJECT (plugin), "expand");
+      g_object_notify_by_pspec (G_OBJECT (plugin), plugin_props[PROP_EXPAND]);
     }
 }
 
@@ -1902,7 +1894,7 @@ xfce_panel_plugin_set_shrink (XfcePanelPlugin *plugin,
                                               shrink ? PROVIDER_SIGNAL_SHRINK_PLUGIN :
                                                   PROVIDER_SIGNAL_UNSHRINK_PLUGIN);
 
-      g_object_notify (G_OBJECT (plugin), "shrink");
+      g_object_notify_by_pspec (G_OBJECT (plugin), plugin_props[PROP_SHRINK]);
     }
 }
 
@@ -1958,7 +1950,7 @@ xfce_panel_plugin_set_small (XfcePanelPlugin *plugin,
                                               small ? PROVIDER_SIGNAL_SMALL_PLUGIN :
                                               PROVIDER_SIGNAL_UNSMALL_PLUGIN);
 
-      g_object_notify (G_OBJECT (plugin), "small");
+      g_object_notify_by_pspec (G_OBJECT (plugin), plugin_props[PROP_SMALL]);
     }
 }
 


More information about the Xfce4-commits mailing list