[Xfce4-commits] <xfce4-indicator-plugin:andrzejr/tmp3> Making the plugin a library and a subclass of XfcePanelPlugin

Andrzej noreply at xfce.org
Sat Mar 31 15:02:02 CEST 2012


Updating branch refs/heads/andrzejr/tmp3
         to f84d012dc997211a43236325bca50dc7092ec3e3 (commit)
       from d59fbfc202bd55d0821037b250e89cb31100457e (commit)

commit f84d012dc997211a43236325bca50dc7092ec3e3
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Sat Mar 31 21:57:43 2012 +0900

    Making the plugin a library and a subclass of XfcePanelPlugin
    
    The plugin is now installed as a library and to a different directory
    (following convention of other plugins).
    
    The plugin is now an object of IndicatorPlugin class, which extends
    XfcePanelPlugin. This is for making definition of properties and integration
    with xfconf easier.
    
    Conflicts:
    
    	panel-plugin/indicator.c

 configure.in.in                                    |    7 +
 panel-plugin/Makefile.am                           |   55 ++++---
 panel-plugin/indicator.c                           |  165 ++++++++++++--------
 ...ndicator.desktop.in.in => indicator.desktop.in} |    4 +-
 panel-plugin/indicator.h                           |   32 ++--
 5 files changed, 158 insertions(+), 105 deletions(-)

diff --git a/configure.in.in b/configure.in.in
index 3280c7f..b308dbd 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -30,6 +30,7 @@ dnl ***************************
 AM_INIT_AUTOMAKE([1.8 dist-bzip2 tar-ustar])
 AM_CONFIG_HEADER([config.h])
 AM_MAINTAINER_MODE()
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 dnl ********************************
 dnl *** Check for basic programs ***
@@ -40,6 +41,12 @@ AC_PROG_INSTALL()
 AC_PROG_LIBTOOL()
 AC_PROG_INTLTOOL()
 
+dnl **************************
+dnl *** Initialize libtool ***
+dnl **************************
+LT_PREREQ([2.2.6])
+LT_INIT([disable-static])
+
 dnl **********************************
 dnl *** Check for standard headers ***
 dnl **********************************
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index c07a45c..0010923 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -1,19 +1,24 @@
+
 INCLUDES =										\
 	-I$(top_srcdir)								\
-	-DG_LOG_DOMAIN=\"xfce4-indicator-plugin\"	\
+	-DG_LOG_DOMAIN=\"libindicator-plugin\"	\
 	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"		\
 	$(PLATFORM_CPPFLAGS)
 
 #
 # Indicator plugin
 #
-plugin_PROGRAMS =								\
-	xfce4-indicator-plugin
+plugindir = \
+	$(libdir)/xfce4/panel/plugins
+
+plugin_LTLIBRARIES = \
+	libindicator-plugin.la
 
-plugindir =										\
-	$(libexecdir)/xfce4/panel-plugins
+libindicator_built_sources = \
+	indicator-dialog_ui.h
 
-xfce4_indicator_plugin_SOURCES =				\
+libindicator_plugin_la_SOURCES = \
+	$(libindicator_built_sources) \
 	indicator-button.c									\
 	indicator-button.h									\
 	indicator-box.c									\
@@ -21,7 +26,7 @@ xfce4_indicator_plugin_SOURCES =				\
 	indicator.c									\
 	indicator.h									
 
-xfce4_indicator_plugin_CFLAGS =					\
+libindicator_plugin_la_CFLAGS = \
 	$(GTK_CFLAGS) \
 	$(EXO_CFLAGS) \
 	$(LIBXFCE4UTIL_CFLAGS)						\
@@ -33,8 +38,14 @@ xfce4_indicator_plugin_CFLAGS =					\
 	-DINDICATOR_ICONS_DIR=\""$(INDICATORICONSDIR)"\" \
 	-DINDICATOR_DIR=\""$(INDICATORDIR)"\"
 
+libindicator_plugin_la_LDFLAGS = \
+	-avoid-version \
+	-module \
+	-no-undefined \
+	-export-symbols-regex '^xfce_panel_module_(preinit|init|construct)' \
+	$(PLATFORM_LDFLAGS)
 
-xfce4_indicator_plugin_LDADD =					\
+libindicator_plugin_la_LIBADD = \
 	$(GTK_LIBS) \
 	$(EXO_LIBS) \
 	$(LIBXFCE4UTIL_LIBS)						\
@@ -46,16 +57,10 @@ xfce4_indicator_plugin_LDADD =					\
 # Desktop file
 #
 desktopdir =									\
-	$(datadir)/xfce4/panel-plugins
-
-desktop_in_in_files =							\
-	indicator.desktop.in.in
-
-desktop_in_files =								\
-	$(desktop_in_in_files:.desktop.in.in=.desktop.in)
+	$(datadir)/xfce4/panel/plugins
 
-%.desktop.in: %.desktop.in.in
-	sed -e "s,\@libexecdir\@,$(libexecdir),g" < $< > $@
+desktop_in_files = \
+	indicator.desktop.in
 
 desktop_DATA =									\
 	$(desktop_in_files:.desktop.in=.desktop)
@@ -63,10 +68,20 @@ desktop_DATA =									\
 @INTLTOOL_DESKTOP_RULE@
 
 EXTRA_DIST =									\
-	$(desktop_in_in_files)
+	$(desktop_in_files)
 
-CLEANFILES =									\
-	$(desktop_in_files)							\
+DISTCLEANFILES = \
 	$(desktop_DATA)
 
+if MAINTAINER_MODE
+BUILT_SOURCES = \
+	$(libindicator_plugin_built_sources)
+
+DISTCLEANFILES += \
+	$(libindicator_plugin_built_sources)
+
+indicator-dialog_ui.h: indicator-dialog.glade
+	$(AM_V_GEN) exo-csource --static --strip-comments --strip-content --name=indicator_dialog_ui $< >$@
+endif
+
 # vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/panel-plugin/indicator.c b/panel-plugin/indicator.c
index e1047cc..ff1bd29 100644
--- a/panel-plugin/indicator.c
+++ b/panel-plugin/indicator.c
@@ -41,26 +41,46 @@
 #endif
 
 /* prototypes */
-static void
-indicator_construct (XfcePanelPlugin *plugin);
-
-static gboolean
-load_module (const gchar * name, IndicatorPlugin * indicator);
-
-static gboolean
-indicator_size_changed (XfcePanelPlugin *plugin, gint size, IndicatorPlugin *indicator);
-
+static void             indicator_construct                        (XfcePanelPlugin       *plugin);
+static void             indicator_free                             (XfcePanelPlugin       *plugin);
+static gboolean         load_module                                (const gchar           *name,
+                                                                    IndicatorPlugin       *indicator);
+static gboolean         indicator_size_changed                     (XfcePanelPlugin       *plugin,
+                                                                    gint                   size);
 #ifdef HAS_PANEL_49
-static void
-indicator_mode_changed (XfcePanelPlugin *plugin, XfcePanelPluginMode mode, IndicatorPlugin *indicator);
+static void             indicator_mode_changed                     (XfcePanelPlugin       *plugin,
+                                                                    XfcePanelPluginMode    mode);
 #else
-static void
-indicator_orientation_changed (XfcePanelPlugin *plugin, GtkOrientation orientation, IndicatorPlugin *indicator);
+static void             indicator_orientation_changed              (XfcePanelPlugin       *plugin,
+                                                                    GtkOrientation         orientation);
 #endif
 
 
-/* register the plugin */
-XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (indicator_construct);
+struct _IndicatorPluginClass
+{
+  XfcePanelPluginClass __parent__;
+};
+
+/* plugin structure */
+struct _IndicatorPlugin
+{
+  XfcePanelPlugin __parent__;
+
+  /* panel widgets */
+  GtkWidget       *item;
+  GtkWidget       *buttonbox;
+  GtkWidget       *ebox;
+
+  /* indicator settings */
+  gchar          **excluded_modules;
+};
+
+
+/* define the plugin */
+XFCE_PANEL_DEFINE_PLUGIN (IndicatorPlugin, indicator)
+
+
+
 
 #if 0
 void
@@ -101,11 +121,12 @@ indicator_save (XfcePanelPlugin *plugin,
 static void
 indicator_read (IndicatorPlugin *indicator)
 {
+  XfcePanelPlugin  *plugin = XFCE_PANEL_PLUGIN (indicator);
   XfconfChannel * channel = xfconf_channel_get ("xfce4-panel");
-  gchar * property = g_strconcat (xfce_panel_plugin_get_property_base(indicator->plugin),"/blacklist",NULL);
+  gchar * property = g_strconcat (xfce_panel_plugin_get_property_base(plugin),"/blacklist",NULL);
   indicator->excluded_modules = xfconf_channel_get_string_list(channel, property);
   g_free (property);
-  property = g_strconcat (xfce_panel_plugin_get_property_base(indicator->plugin),"/icon-size-max",NULL);
+  property = g_strconcat (xfce_panel_plugin_get_property_base(plugin),"/icon-size-max",NULL);
   xfconf_g_property_bind (channel, property, G_TYPE_INT, indicator->buttonbox, "icon-size-max");
   g_free (property);
   /* something went wrong, apply default values */
@@ -115,18 +136,41 @@ indicator_read (IndicatorPlugin *indicator)
   */
 }
 
-static IndicatorPlugin *
-indicator_new (XfcePanelPlugin *plugin)
+static void
+indicator_class_init (IndicatorPluginClass *klass)
 {
-  IndicatorPlugin   *indicator;
-  GtkOrientation  orientation;
-  gint indicators_loaded = 0;
+  XfcePanelPluginClass *plugin_class;
+  GObjectClass         *gobject_class;
+
+  gobject_class = G_OBJECT_CLASS (klass);
+  //gobject_class->get_property = indicator_get_property;
+  //gobject_class->set_property = indicator_set_property;
+
+  plugin_class = XFCE_PANEL_PLUGIN_CLASS (klass);
+  plugin_class->construct = indicator_construct;
+  plugin_class->free_data = indicator_free;
+  plugin_class->size_changed = indicator_size_changed;
+  //plugin_class->configure_plugin = indicator_configure_plugin;
+#ifdef HAS_PANEL_49
+  plugin_class->mode_changed = indicator_mode_changed;
+#else
+  plugin_class->orientation_changed = indicator_orientation_changed;
+#endif
+}
 
-  /* allocate memory for the plugin structure */
-  indicator = panel_slice_new0 (IndicatorPlugin);
 
-  /* pointer to plugin */
-  indicator->plugin = plugin;
+
+static void
+indicator_init (IndicatorPlugin *indicator)
+{
+  XfcePanelPlugin  *plugin = XFCE_PANEL_PLUGIN (indicator);
+  GtkRcStyle       *style;
+
+  /* setup transation domain */
+  xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+
+  GtkOrientation  orientation;
+  gint indicators_loaded = 0;
 
   /* get the current orientation */
   orientation = xfce_panel_plugin_get_orientation (plugin);
@@ -135,8 +179,9 @@ indicator_new (XfcePanelPlugin *plugin)
   gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
                                   INDICATOR_ICONS_DIR);
   /*gtk_widget_set_name(GTK_WIDGET (indicator->plugin), "indicator-plugin");*/
-  
-  indicator->buttonbox = xfce_indicator_box_new ();;
+
+  indicator->buttonbox = xfce_indicator_box_new ();
+
   /* initialize xfconf */
   if (xfconf_init(NULL)){
     /* get the list of excluded modules */
@@ -149,7 +194,7 @@ indicator_new (XfcePanelPlugin *plugin)
     const gchar * name;
     guint i, length;
     gboolean match = FALSE;
- 
+
     length = (indicator->excluded_modules != NULL) ? g_strv_length (indicator->excluded_modules) : 0;
     while ((name = g_dir_read_name(dir)) != NULL) {
       for (i = 0; i < length; ++i) {
@@ -174,7 +219,7 @@ indicator_new (XfcePanelPlugin *plugin)
     xfce_indicator_button_set_label(XFCE_INDICATOR_BUTTON(indicator->item),
                                     GTK_LABEL (gtk_label_new(_("No Indicators"))));
     gtk_container_add (GTK_CONTAINER (plugin), indicator->item);
-    gtk_widget_show(indicator->item);  
+    gtk_widget_show(indicator->item);
     /* show the panel's right-click menu on this menu */
     xfce_panel_plugin_add_action_widget (plugin, indicator->item);
   } else {
@@ -187,15 +232,14 @@ indicator_new (XfcePanelPlugin *plugin)
     /* show the panel's right-click menu on this menu */
     xfce_panel_plugin_add_action_widget (plugin, indicator->ebox);
   }
-  return indicator;
 }
 
 
 
 static void
-indicator_free (XfcePanelPlugin *plugin,
-             IndicatorPlugin    *indicator)
+indicator_free (XfcePanelPlugin *plugin)
 {
+  IndicatorPlugin *indicator = XFCE_INDICATOR_PLUGIN (plugin);
   GtkWidget *dialog;
 
   /* check if the dialog is still open. if so, destroy it */
@@ -203,8 +247,6 @@ indicator_free (XfcePanelPlugin *plugin,
   if (G_UNLIKELY (dialog != NULL))
     gtk_widget_destroy (dialog);
   xfconf_shutdown();
-  /* free the plugin structure */
-  panel_slice_free (IndicatorPlugin, indicator);
 }
 
 
@@ -212,18 +254,18 @@ indicator_free (XfcePanelPlugin *plugin,
 #ifdef HAS_PANEL_49
 static void
 indicator_mode_changed (XfcePanelPlugin     *plugin,
-                        XfcePanelPluginMode  mode,
-                        IndicatorPlugin     *indicator)
+                        XfcePanelPluginMode  mode)
 {
-  GtkOrientation orientation;
-  GtkOrientation panel_orientation = xfce_panel_plugin_get_orientation (plugin);
+  GtkOrientation   orientation;
+  GtkOrientation   panel_orientation = xfce_panel_plugin_get_orientation (plugin);
+  IndicatorPlugin *indicator = XFCE_INDICATOR_PLUGIN (plugin);
 
   orientation = (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL) ?
     GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;
 
   xfce_indicator_box_set_orientation (XFCE_INDICATOR_BOX (indicator->buttonbox), panel_orientation, orientation);
 
-  indicator_size_changed (plugin, xfce_panel_plugin_get_size (plugin), indicator);
+  indicator_size_changed (plugin, xfce_panel_plugin_get_size (plugin));
 }
 
 
@@ -231,21 +273,23 @@ indicator_mode_changed (XfcePanelPlugin     *plugin,
 #else
 static void
 indicator_orientation_changed (XfcePanelPlugin *plugin,
-                            GtkOrientation   orientation,
-                            IndicatorPlugin    *indicator)
+                               GtkOrientation   orientation)
 {
+  IndicatorPlugin *indicator = XFCE_INDICATOR_PLUGIN (plugin);
+
   xfce_indicator_box_set_orientation (XFCE_INDICATOR_BOX (indicator->buttonbox), orientation, GTK_ORIENTATION_HORIZONTAL);
 
-  indicator_size_changed (plugin, xfce_panel_plugin_get_size (plugin), indicator);
+  indicator_size_changed (plugin, xfce_panel_plugin_get_size (plugin));
 }
 #endif
 
 
 static gboolean
 indicator_size_changed (XfcePanelPlugin *plugin,
-                     gint             size,
-                     IndicatorPlugin    *indicator)
+                        gint             size)
 {
+  IndicatorPlugin *indicator = XFCE_INDICATOR_PLUGIN (plugin);
+
 #ifdef HAS_PANEL_49
   xfce_indicator_box_set_size (XFCE_INDICATOR_BOX (indicator->buttonbox),
                                size, xfce_panel_plugin_get_nrows (plugin));
@@ -262,6 +306,8 @@ indicator_size_changed (XfcePanelPlugin *plugin,
 static gboolean
 on_button_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator)
 {
+  XfcePanelPlugin  *plugin = XFCE_PANEL_PLUGIN (indicator);
+
   if (indicator != NULL)
   {
     if( event->button == 1) /* left click only */
@@ -269,7 +315,7 @@ on_button_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indi
       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),TRUE);
       gtk_menu_popup (xfce_indicator_button_get_menu (XFCE_INDICATOR_BUTTON(widget)), NULL, NULL,
                       xfce_panel_plugin_position_menu,
-                      indicator->plugin, 1, gtk_get_current_event_time ());
+                      plugin, 1, gtk_get_current_event_time ());
       
       return TRUE;
     }
@@ -289,28 +335,9 @@ menu_deactivate (GtkMenu *menu,
 static void
 indicator_construct (XfcePanelPlugin *plugin)
 {
-  IndicatorPlugin *indicator;
-
-  /* setup transation domain */
-  xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+  IndicatorPlugin *indicator = XFCE_INDICATOR_PLUGIN (plugin);
 
-  /* create the plugin */
-  indicator = indicator_new (plugin);
-
-  /* connect plugin signals */
-  g_signal_connect (G_OBJECT (plugin), "free-data",
-                    G_CALLBACK (indicator_free), indicator);
-
-  g_signal_connect (G_OBJECT (plugin), "size-changed",
-                    G_CALLBACK (indicator_size_changed), indicator);
-
-#ifdef HAS_PANEL_49
-  g_signal_connect (G_OBJECT (plugin), "mode-changed",
-                    G_CALLBACK (indicator_mode_changed), indicator);
-#else
-  g_signal_connect (G_OBJECT (plugin), "orientation-changed",
-                    G_CALLBACK (indicator_orientation_changed), indicator);
-#endif
+  //consider moving some stuff from indicator_init() here
 }
 
 
@@ -332,7 +359,7 @@ entry_scrolled (GtkWidget *menuitem, GdkEventScroll *event, IndicatorPlugin *ind
 static void
 entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
 {
-  XfcePanelPlugin *plugin = ((IndicatorPlugin *) user_data)->plugin;
+  XfcePanelPlugin *plugin = XFCE_PANEL_PLUGIN (user_data);
   GtkWidget * button = xfce_indicator_button_new (io, entry);
   gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
   gtk_button_set_use_underline(GTK_BUTTON (button),TRUE);
@@ -355,7 +382,7 @@ entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_d
   g_signal_connect(button, "scroll-event", G_CALLBACK(entry_scrolled),
                    user_data);
 
-  gtk_container_add(GTK_CONTAINER (((IndicatorPlugin *)user_data)->buttonbox), button);
+  gtk_container_add(GTK_CONTAINER (XFCE_INDICATOR_PLUGIN (user_data)->buttonbox), button);
   gtk_widget_show(button);
 }
 
diff --git a/panel-plugin/indicator.desktop.in.in b/panel-plugin/indicator.desktop.in
similarity index 67%
rename from panel-plugin/indicator.desktop.in.in
rename to panel-plugin/indicator.desktop.in
index 3f686cd..b0a757d 100644
--- a/panel-plugin/indicator.desktop.in.in
+++ b/panel-plugin/indicator.desktop.in
@@ -4,5 +4,5 @@ Encoding=UTF-8
 _Name=Indicator Plugin
 _Comment=An indicator of something that needs your attention on the desktop
 Icon=xfce4-indicator-plugin
-X-XFCE-Exec=@libexecdir@/xfce4/panel-plugins/xfce4-indicator-plugin
-#X-XFCE-Unique=true
+X-XFCE-Module=indicator-plugin
+X-XFCE-Internal=FALSE
diff --git a/panel-plugin/indicator.h b/panel-plugin/indicator.h
index 8b3393c..b59c963 100644
--- a/panel-plugin/indicator.h
+++ b/panel-plugin/indicator.h
@@ -18,24 +18,28 @@
 #ifndef __INDICATOR_H__
 #define __INDICATOR_H__
 
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <libxfce4panel/libxfce4panel.h>
+
 G_BEGIN_DECLS
+typedef struct _IndicatorPluginClass IndicatorPluginClass;
+typedef struct _IndicatorPlugin      IndicatorPlugin;
+
+#define XFCE_TYPE_INDICATOR_PLUGIN            (indicator_get_type ())
+#define XFCE_INDICATOR_PLUGIN(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_INDICATOR_PLUGIN, IndicatorPlugin))
+#define XFCE_INDICATOR_PLUGIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_INDICATOR_PLUGIN, IndicatorPluginClass))
+#define XFCE_IS_INDICATOR_PLUGIN(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_INDICATOR_PLUGIN))
+#define XFCE_IS_INDICATOR_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_INDICATOR_PLUGIN))
+#define XFCE_INDICATOR_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_INDICATOR_PLUGIN, IndicatorPluginClass))
+
+GType indicator_get_type      (void) G_GNUC_CONST;
+
+void  indicator_register_type (XfcePanelTypeModule *type_module);
+
 #ifndef INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED
 #define INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED "scroll-entry"
 #endif
-/* plugin structure */
-typedef struct
-{
-    XfcePanelPlugin *plugin;
-
-    /* panel widgets */ 
-    GtkWidget       *item;
-    GtkWidget       *buttonbox;
-    GtkWidget       *ebox;
-
-    /* indicator settings */
-    gchar          **excluded_modules;
-}
-IndicatorPlugin;
 
 void
 indicator_save (XfcePanelPlugin *plugin,


More information about the Xfce4-commits mailing list