[Xfce4-commits] <xfce4-appfinder:andrzejr/plugin> Added a panel plugin (initial rev.)
Andrzej
noreply at xfce.org
Thu Feb 16 13:00:02 CET 2012
Updating branch refs/heads/andrzejr/plugin
to cd5fa27d27cfee1ded2841caea6b812628749332 (commit)
from ac37e6036b2166e0a63341f238fb8703bda5de2b (commit)
commit cd5fa27d27cfee1ded2841caea6b812628749332
Author: Andrzej <ndrwrdck at gmail.com>
Date: Thu Feb 16 20:59:32 2012 +0900
Added a panel plugin (initial rev.)
Makefile.am | 5 +
configure.ac.in | 30 ++-
panel-plugin/Makefile.am | 63 +++++
panel-plugin/README | 19 ++
panel-plugin/appfinder-plugin.c | 566 +++++++++++++++++++++++++++++++++++++++
panel-plugin/appfinder-plugin.h | 60 ++++
6 files changed, 742 insertions(+), 1 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index ad38f13..0f06e23 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,11 @@
+if PANEL_PLUGIN
+PANEL_PLUGIN_SUBDIRS = panel-plugin
+endif
+
SUBDIRS = \
src \
+ $(PANEL_PLUGIN_SUBDIRS) \
data \
po
diff --git a/configure.ac.in b/configure.ac.in
index e3756f6..d9947c6 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -82,6 +82,33 @@ XDT_CHECK_PACKAGE([DBUS_GLIB], [dbus-glib-1], [0.84])
XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.8.0])
dnl ***********************************
+dnl *** Check for optional packages ***
+dnl ***********************************
+dnl XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [4.9.0])
+AC_ARG_ENABLE([panel-plugin], AC_HELP_STRING([--disable-panel-plugin], [Don't build the panel plugin, see panel-plugin/README]),
+ [ac_panel_plugin=$enableval], [ac_panel_plugin=yes])
+if test x"$ac_panel_plugin" = x"yes"; then
+ XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [4.9.0],
+ [
+ XDT_CHECK_PACKAGE([EXO], [exo-1], [0.6.0],
+ [
+ ac_panel_plugin=yes
+ ],
+ [
+ ac_panel_plugin=no
+ ])
+ ],
+ [
+ ac_panel_plugin=no
+ ])
+else
+ ac_panel_plugin=no
+fi
+AC_MSG_CHECKING([whether to build the panel plugin])
+AM_CONDITIONAL([PANEL_PLUGIN], [test x"$ac_panel_plugin" = x"yes"])
+AC_MSG_RESULT([$ac_panel_plugin])
+
+dnl ***********************************
dnl *** Check for debugging support ***
dnl ***********************************
XDT_FEATURE_DEBUG([appfinder_debug_default])
@@ -108,6 +135,7 @@ AC_OUTPUT([
Makefile
data/Makefile
src/Makefile
+panel-plugin/Makefile
po/Makefile.in
])
@@ -117,6 +145,6 @@ dnl ***************************
echo
echo "Build Configuration:"
echo
+echo " * Panel Plugin: $ac_panel_plugin"
echo " * Debugging Support: $enable_debug"
echo
-
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
new file mode 100644
index 0000000..a28fc70
--- /dev/null
+++ b/panel-plugin/Makefile.am
@@ -0,0 +1,63 @@
+
+INCLUDES = \
+ -I$(top_srcdir) \
+ -DG_LOG_DOMAIN=\"libappfinder\" \
+ $(PLATFORM_CPPFLAGS)
+
+plugindir = $(libdir)/xfce4/panel/plugins
+plugin_LTLIBRARIES = \
+ libappfinder.la
+
+libappfinder_la_SOURCES = \
+ appfinder-plugin.c \
+ appfinder-plugin.h
+
+libappfinder_la_CFLAGS = \
+ $(GTK_CFLAGS) \
+ $(EXO_CFLAGS) \
+ $(DBUS_CFLAGS) \
+ $(XFCONF_CFLAGS) \
+ $(LIBXFCE4PANEL_CFLAGS) \
+ $(LIBXFCE4UI_CFLAGS) \
+ $(PLATFORM_CFLAGS)
+
+libappfinder_la_LDFLAGS = \
+ -avoid-version \
+ -module \
+ -no-undefined \
+ -export-symbols-regex '^xfce_panel_module_(preinit|init|construct)' \
+ $(PLATFORM_LDFLAGS)
+
+libappfinder_la_LIBADD = \
+ $(GTK_LIBS) \
+ $(EXO_LIBS) \
+ $(DBUS_LIBS) \
+ $(XFCONF_LIBS) \
+ $(LIBXFCE4PANEL_LIBS) \
+ $(LIBXFCE4UI_LIBS)
+
+#
+# .desktop file
+#
+desktopdir = $(datadir)/xfce4/panel/plugins
+desktop_in_files = xfce4-appfinder-plugin.desktop.in
+desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
+ at INTLTOOL_DESKTOP_RULE@
+
+EXTRA_DIST = \
+ $(desktop_in_files) \
+ README
+
+DISTCLEANFILES = \
+ $(desktop_DATA)
+
+if MAINTAINER_MODE
+BUILT_SOURCES = \
+ $(libappfinder_built_sources)
+
+DISTCLEANFILES += \
+ $(libappfinder_built_sources)
+
+endif
+
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/panel-plugin/README b/panel-plugin/README
new file mode 100644
index 0000000..7f4f97d
--- /dev/null
+++ b/panel-plugin/README
@@ -0,0 +1,19 @@
+Application Finder Panel Applet (appfinder)
+===========================================
+
+Appfinder is an extension for the Xfce Panel. It enables users to add a button
+to the panel, which, when pressed, pops up an appfinder widget
+(same as the one displayed by running an xfce4-appfinder command).
+
+The differences between this panel and having a simple launcher on the panel
+that starts xfce4-appfinder are:
+- the button is configurable, i.e.:
+ * it can have an icon, a label, or both,
+ * it can occupy the whole width of the panel.
+- the configuration dialog is available by right-clicking on the button
+ and the appfinder window isn't cluttered with buttons such as "preferences",
+ "close" or "launch".
+- pressing the button toggles the appfinder window on/off rather than starting
+ several instances of xfce4-appfinder.
+
+
diff --git a/panel-plugin/appfinder-plugin.c b/panel-plugin/appfinder-plugin.c
new file mode 100644
index 0000000..b4c893b
--- /dev/null
+++ b/panel-plugin/appfinder-plugin.c
@@ -0,0 +1,566 @@
+/*
+ * Copyright (C) 2012 Andrzej <ndrwrdck at gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This library 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <exo/exo.h>
+#include <libxfce4ui/libxfce4ui.h>
+#include <libxfce4panel/libxfce4panel.h>
+#include <libxfce4panel/xfce-panel-macros.h>
+
+#include <xfconf/xfconf.h>
+
+#include <dbus/dbus-glib.h>
+
+#include "appfinder-plugin.h"
+
+/* I18N: default tooltip of the appfinder */
+#define DEFAULT_TITLE _("Programs")
+#define DEFAULT_ICON_NAME "gtk-find"
+#define DEFAULT_ICON_SIZE (16)
+
+#define APPFINDER_DBUS_SERVICE "org.xfce.Appfinder"
+#define APPFINDER_DBUS_INTERFACE APPFINDER_DBUS_SERVICE
+#define APPFINDER_DBUS_PATH "/org/xfce/Appfinder"
+#define APPFINDER_DBUS_METHOD_OPEN "OpenWindow"
+#define APPFINDER_DBUS_METHOD_OPEN_WIDGET "OpenWidget"
+#define APPFINDER_DBUS_METHOD_QUIT "Quit"
+
+struct _XfceAppfinderPluginClass
+{
+ XfcePanelPluginClass __parent__;
+};
+
+struct _XfceAppfinderPlugin
+{
+ XfcePanelPlugin __parent__;
+
+ GtkWidget *button;
+ GtkWidget *box;
+ GtkWidget *icon;
+ GtkWidget *label;
+ GtkWidget *appfinder_window;
+ GtkWidget *appfinder_socket;
+
+ gboolean visible;
+ gint busy;
+ gint handler;
+
+ DBusGProxy *proxy;
+
+ guint show_button_title : 1;
+ gchar *button_title;
+ gchar *button_icon;
+};
+
+enum
+{
+ PROP_0,
+ PROP_SHOW_BUTTON_TITLE,
+ PROP_BUTTON_TITLE,
+ PROP_BUTTON_ICON
+};
+
+static void xfce_appfinder_plugin_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void xfce_appfinder_plugin_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void xfce_appfinder_plugin_construct (XfcePanelPlugin *panel_plugin);
+static void xfce_appfinder_plugin_free_data (XfcePanelPlugin *panel_plugin);
+static gboolean xfce_appfinder_plugin_size_changed (XfcePanelPlugin *panel_plugin,
+ gint size);
+static void xfce_appfinder_plugin_mode_changed (XfcePanelPlugin *panel_plugin,
+ XfcePanelPluginMode mode);
+static void xfce_appfinder_plugin_configure_plugin (XfcePanelPlugin *panel_plugin);
+static void xfce_appfinder_plugin_activate (GtkWidget *widget,
+ GdkEventButton *event,
+ XfceAppfinderPlugin *plugin);
+
+
+
+/* define the plugin */
+XFCE_PANEL_DEFINE_PLUGIN (XfceAppfinderPlugin, xfce_appfinder_plugin)
+
+static GtkIconSize menu_icon_size = GTK_ICON_SIZE_INVALID;
+
+
+
+static void
+xfce_appfinder_plugin_class_init (XfceAppfinderPluginClass *klass)
+{
+ XfcePanelPluginClass *plugin_class;
+ GObjectClass *gobject_class;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->get_property = xfce_appfinder_plugin_get_property;
+ gobject_class->set_property = xfce_appfinder_plugin_set_property;
+
+ plugin_class = XFCE_PANEL_PLUGIN_CLASS (klass);
+ plugin_class->construct = xfce_appfinder_plugin_construct;
+ plugin_class->free_data = xfce_appfinder_plugin_free_data;
+ plugin_class->size_changed = xfce_appfinder_plugin_size_changed;
+ plugin_class->mode_changed = xfce_appfinder_plugin_mode_changed;
+ plugin_class->configure_plugin = xfce_appfinder_plugin_configure_plugin;
+ g_object_class_install_property (gobject_class,
+ PROP_SHOW_BUTTON_TITLE,
+ g_param_spec_boolean ("show-button-title",
+ NULL, NULL,
+ TRUE,
+ EXO_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_BUTTON_TITLE,
+ g_param_spec_string ("button-title",
+ NULL, NULL,
+ DEFAULT_TITLE,
+ EXO_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_BUTTON_ICON,
+ g_param_spec_string ("button-icon",
+ NULL, NULL,
+ DEFAULT_ICON_NAME,
+ EXO_PARAM_READWRITE));
+
+ menu_icon_size = gtk_icon_size_from_name ("gtk-find");
+ if (menu_icon_size == GTK_ICON_SIZE_INVALID)
+ menu_icon_size = gtk_icon_size_register ("gtk-find",
+ DEFAULT_ICON_SIZE,
+ DEFAULT_ICON_SIZE);
+}
+
+
+
+static void
+xfce_appfinder_plugin_init (XfceAppfinderPlugin *plugin)
+{
+
+ plugin->show_button_title = TRUE;
+ plugin->visible = FALSE;
+ plugin->busy = 0;
+ plugin->handler = 0;
+ plugin->proxy = NULL;
+ plugin->appfinder_window = NULL;
+ plugin->appfinder_socket = NULL;
+
+ plugin->button = xfce_panel_create_toggle_button ();
+ xfce_panel_plugin_add_action_widget (XFCE_PANEL_PLUGIN (plugin), plugin->button);
+ gtk_container_add (GTK_CONTAINER (plugin), plugin->button);
+ gtk_widget_set_name (plugin->button, "appfinder-button");
+ gtk_button_set_relief (GTK_BUTTON (plugin->button), GTK_RELIEF_NONE);
+ gtk_widget_set_tooltip_text (plugin->button, DEFAULT_TITLE);
+ g_signal_connect (G_OBJECT (plugin->button), "button-press-event",
+ G_CALLBACK (xfce_appfinder_plugin_activate), plugin);
+
+ plugin->box = xfce_hvbox_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 1);
+ gtk_container_add (GTK_CONTAINER (plugin->button), plugin->box);
+ gtk_widget_show (plugin->box);
+
+ plugin->icon = xfce_panel_image_new_from_source (DEFAULT_ICON_NAME);
+ gtk_box_pack_start (GTK_BOX (plugin->box), plugin->icon, FALSE, FALSE, 0);
+ gtk_widget_show (plugin->icon);
+
+ plugin->label = gtk_label_new (DEFAULT_TITLE);
+ gtk_box_pack_start (GTK_BOX (plugin->box), plugin->label, FALSE, FALSE, 0);
+ gtk_widget_show (plugin->label);
+}
+
+
+
+static void
+xfce_appfinder_plugin_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ XfceAppfinderPlugin *plugin = XFCE_APPFINDER_PLUGIN (object);
+
+ switch (prop_id)
+ {
+ case PROP_SHOW_BUTTON_TITLE:
+ g_value_set_boolean (value, plugin->show_button_title);
+ break;
+
+ case PROP_BUTTON_TITLE:
+ g_value_set_string (value, plugin->button_title == NULL ?
+ DEFAULT_TITLE : plugin->button_title);
+ break;
+
+ case PROP_BUTTON_ICON:
+ g_value_set_string (value, exo_str_is_empty (plugin->button_icon) ?
+ DEFAULT_ICON_NAME : plugin->button_icon);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+xfce_appfinder_plugin_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ XfceAppfinderPlugin *plugin = XFCE_APPFINDER_PLUGIN (object);
+
+ switch (prop_id)
+ {
+ case PROP_SHOW_BUTTON_TITLE:
+ plugin->show_button_title = g_value_get_boolean (value);
+ if (plugin->show_button_title)
+ gtk_widget_show (plugin->label);
+ else
+ gtk_widget_hide (plugin->label);
+ xfce_appfinder_plugin_size_changed (XFCE_PANEL_PLUGIN (plugin),
+ xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin)));
+ return;
+
+ case PROP_BUTTON_TITLE:
+ g_free (plugin->button_title);
+ plugin->button_title = g_value_dup_string (value);
+ gtk_label_set_text (GTK_LABEL (plugin->label),
+ plugin->button_title != NULL ? plugin->button_title : "");
+ gtk_widget_set_tooltip_text (plugin->button,
+ exo_str_is_empty (plugin->button_title) ? NULL : plugin->button_title);
+
+ /* check if the label still fits */
+ if (xfce_panel_plugin_get_mode (XFCE_PANEL_PLUGIN (plugin)) == XFCE_PANEL_PLUGIN_MODE_DESKBAR
+ && plugin->show_button_title)
+ {
+ xfce_appfinder_plugin_size_changed (XFCE_PANEL_PLUGIN (plugin),
+ xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin)));
+ }
+ return;
+
+ case PROP_BUTTON_ICON:
+ g_free (plugin->button_icon);
+ plugin->button_icon = g_value_dup_string (value);
+ xfce_panel_image_set_from_source (XFCE_PANEL_IMAGE (plugin->icon),
+ exo_str_is_empty (plugin->button_icon) ? DEFAULT_ICON_NAME : plugin->button_icon);
+ return;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+
+ //xfce_appfinder_plugin_reload (plugin);
+}
+
+
+
+static void
+xfce_appfinder_plugin_construct (XfcePanelPlugin *panel_plugin)
+{
+ XfceAppfinderPlugin *plugin = XFCE_APPFINDER_PLUGIN (panel_plugin);
+
+ xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));
+
+
+
+ /* bind all properties */
+ //panel_properties_bind (NULL, G_OBJECT (plugin),
+ // xfce_panel_plugin_get_property_base (panel_plugin),
+ // properties, FALSE);
+
+ gtk_widget_show (plugin->button);
+ return;
+}
+
+
+
+static void
+xfce_appfinder_plugin_destroy_window (XfceAppfinderPlugin *plugin,
+ GtkWidget *socket)
+{
+ appfinder_return_if_fail (XFCE_IS_APPFINDER_PLUGIN (plugin));
+
+ plugin->busy += 1;
+
+ if (plugin->appfinder_socket != NULL)
+ {
+ g_signal_handler_disconnect(socket, plugin->handler);
+ gtk_widget_destroy (plugin->appfinder_socket);
+ plugin->appfinder_socket = NULL;
+ }
+ if (plugin->appfinder_window != NULL)
+ {
+ gtk_widget_destroy (plugin->appfinder_window);
+ plugin->appfinder_window = NULL;
+ }
+
+ plugin->visible = FALSE;
+ if (plugin->button != NULL)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin->button), FALSE);
+
+ APPFINDER_DEBUG ("destroyed window");
+
+ plugin->busy -= 1;
+}
+
+
+
+static void
+xfce_appfinder_plugin_create_window (XfceAppfinderPlugin *plugin)
+{
+ GtkWidget *window;
+ GtkWidget *socket;
+ GtkWidget *vbox;
+
+ appfinder_return_if_fail (XFCE_IS_APPFINDER_PLUGIN (plugin));
+
+ window = plugin->appfinder_window =
+ g_object_new (GTK_TYPE_WINDOW,
+ "type", GTK_WINDOW_POPUP,
+ //"child", socket,
+ NULL);
+
+ gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
+ gtk_window_set_mnemonic_modifier (GTK_WINDOW (window), 0);
+ gtk_window_set_accept_focus (GTK_WINDOW (window), TRUE);
+
+ vbox = gtk_vbox_new (FALSE, 10);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 7);
+ gtk_widget_show (vbox);
+
+ socket = plugin->appfinder_socket = gtk_socket_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), socket, TRUE, TRUE, 0);
+ gtk_widget_show (socket);
+
+ plugin->handler = g_signal_connect_swapped
+ (G_OBJECT (socket), "destroy",
+ G_CALLBACK (xfce_appfinder_plugin_destroy_window), plugin);
+
+ APPFINDER_DEBUG ("contructed window");
+}
+
+
+
+static gboolean
+xfce_appfinder_plugin_activate_dbus (DBusGProxy *proxy,
+ GdkNativeWindow id,
+ GError **error)
+{
+ DBusGConnection *connection;
+ gboolean retval = FALSE;
+
+ /* connect to DBUS service and cache the proxy */
+ if (proxy == NULL)
+ {
+ connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
+ if (connection == NULL)
+ return retval;
+
+ proxy = dbus_g_proxy_new_for_name (connection,
+ APPFINDER_DBUS_SERVICE,
+ APPFINDER_DBUS_PATH,
+ APPFINDER_DBUS_INTERFACE);
+ }
+
+ if (G_LIKELY (proxy != NULL))
+ {
+ retval = dbus_g_proxy_call (proxy, APPFINDER_DBUS_METHOD_OPEN_WIDGET, error,
+ G_TYPE_UINT, id,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+
+ g_object_unref (G_OBJECT (proxy));
+ }
+
+ return retval;
+}
+
+
+
+static void
+xfce_appfinder_plugin_activate (GtkWidget *button,
+ GdkEventButton *event,
+ XfceAppfinderPlugin *plugin)
+{
+ GError *error = NULL;
+ gboolean succeeded;
+ gint x, y;
+
+ appfinder_return_if_fail (XFCE_IS_APPFINDER_PLUGIN (plugin));
+ appfinder_return_if_fail (button == NULL || plugin->button == button);
+
+ if (plugin->busy > 0)
+ return;
+
+ plugin->busy += 1;
+
+ APPFINDER_DEBUG ("button pressed %d", plugin->busy);
+
+ plugin->visible = !plugin->visible;
+
+ if (button != NULL)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), plugin->visible);
+
+ if (plugin->visible)
+ {
+ if (plugin->appfinder_window == NULL)
+ xfce_appfinder_plugin_create_window (plugin);
+ gtk_widget_set_size_request (plugin->appfinder_window, 600, 400);
+
+ xfce_panel_plugin_position_widget
+ (XFCE_PANEL_PLUGIN (plugin), plugin->appfinder_window, NULL, &x, &y);
+ gtk_window_move (GTK_WINDOW (plugin->appfinder_window), x, y);
+
+ succeeded = xfce_appfinder_plugin_activate_dbus
+ (plugin->proxy,
+ gtk_socket_get_id (GTK_SOCKET (plugin->appfinder_socket)),
+ &error);
+
+ if (!succeeded)
+ {
+ xfce_dialog_show_error (NULL, error,
+ _("Failed to open Appfinder widget"));
+ g_error_free (error);
+ xfce_appfinder_plugin_destroy_window (plugin, plugin->appfinder_socket);
+ plugin->busy -= 1;
+ return;
+ }
+
+ if (plugin->visible)
+ gtk_widget_set_visible (plugin->appfinder_window, plugin->visible);
+ }
+ else
+ {
+ xfce_appfinder_plugin_destroy_window (plugin, plugin->appfinder_socket);
+ }
+
+ plugin->busy -= 1;
+
+}
+
+
+
+
+
+static gboolean
+xfce_appfinder_plugin_size_changed (XfcePanelPlugin *panel_plugin,
+ gint size)
+{
+ XfceAppfinderPlugin *plugin = XFCE_APPFINDER_PLUGIN (panel_plugin);
+ gint row_size;
+ gint icon_size;
+ GtkStyle *style;
+ XfcePanelPluginMode mode;
+ GtkRequisition label_size;
+ GtkOrientation orientation;
+ gint border_thickness;
+
+ appfinder_return_val_if_fail (XFCE_IS_APPFINDER_PLUGIN (panel_plugin), FALSE);
+
+ row_size = size / xfce_panel_plugin_get_nrows (panel_plugin);
+
+ gtk_box_set_child_packing (GTK_BOX (plugin->box), plugin->icon,
+ !plugin->show_button_title, !plugin->show_button_title,
+ 0, GTK_PACK_START);
+
+ mode = xfce_panel_plugin_get_mode (panel_plugin);
+
+ if (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL)
+ orientation = GTK_ORIENTATION_HORIZONTAL;
+ else
+ orientation = GTK_ORIENTATION_VERTICAL;
+
+ if (!plugin->show_button_title)
+ {
+ xfce_panel_image_set_size (XFCE_PANEL_IMAGE (plugin->icon), -1);
+
+ if (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL)
+ gtk_widget_set_size_request (GTK_WIDGET (panel_plugin), row_size, size);
+ else
+ gtk_widget_set_size_request (GTK_WIDGET (panel_plugin), size, row_size);
+ }
+ else
+ {
+ style = gtk_widget_get_style (plugin->button);
+ border_thickness = 2 * MAX (style->xthickness, style->ythickness) + 2;
+
+ icon_size = row_size - border_thickness;
+ xfce_panel_image_set_size (XFCE_PANEL_IMAGE (plugin->icon), icon_size);
+ gtk_widget_set_size_request (GTK_WIDGET (panel_plugin), -1, -1);
+
+ if (mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR)
+ {
+ /* check if the label fits next to the icon */
+ gtk_widget_size_request (GTK_WIDGET (plugin->label), &label_size);
+ if (label_size.width <= size - border_thickness - icon_size)
+ orientation = GTK_ORIENTATION_HORIZONTAL;
+ }
+ }
+
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (plugin->box), orientation);
+
+ return TRUE;
+}
+
+
+
+static void
+xfce_appfinder_plugin_mode_changed (XfcePanelPlugin *panel_plugin,
+ XfcePanelPluginMode mode)
+{
+ XfceAppfinderPlugin *plugin = XFCE_APPFINDER_PLUGIN (panel_plugin);
+ gint angle;
+
+ appfinder_return_if_fail (XFCE_IS_APPFINDER_PLUGIN (panel_plugin));
+
+ angle = (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL) ? 270 : 0;
+ gtk_label_set_angle (GTK_LABEL (plugin->label), angle);
+
+ xfce_appfinder_plugin_size_changed (panel_plugin,
+ xfce_panel_plugin_get_size (panel_plugin));
+}
+
+
+
+
+static void
+xfce_appfinder_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
+{
+ appfinder_return_if_fail (XFCE_IS_APPFINDER_PLUGIN (panel_plugin));
+}
+
+
+
+static void
+xfce_appfinder_plugin_free_data (XfcePanelPlugin *panel_plugin)
+{
+ XfceAppfinderPlugin *plugin = XFCE_APPFINDER_PLUGIN (panel_plugin);
+
+ appfinder_return_if_fail (XFCE_IS_APPFINDER_PLUGIN (panel_plugin));
+ if (plugin->visible)
+ xfce_appfinder_plugin_destroy_window (plugin, plugin->appfinder_socket);
+
+ g_free (plugin->button_title);
+ g_free (plugin->button_icon);
+}
diff --git a/panel-plugin/appfinder-plugin.h b/panel-plugin/appfinder-plugin.h
new file mode 100644
index 0000000..0c020fe
--- /dev/null
+++ b/panel-plugin/appfinder-plugin.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2012 Andrzej <ndrwrdck at gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This library 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __XFCE_APPFINDER_PLUGIN_H__
+#define __XFCE_APPFINDER_PLUGIN_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef struct _XfceAppfinderPluginClass XfceAppfinderPluginClass;
+typedef struct _XfceAppfinderPlugin XfceAppfinderPlugin;
+
+#define XFCE_TYPE_APPFINDER_PLUGIN (xfce_appfinder_plugin_get_type ())
+#define XFCE_APPFINDER_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_APPFINDER_PLUGIN, XfceAppfinderPlugin))
+#define XFCE_APPFINDER_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_APPFINDER_PLUGIN, XfceAppfinderPluginClass))
+#define XFCE_IS_APPFINDER_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_APPFINDER_PLUGIN))
+#define XFCE_IS_APPFINDER_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_APPFINDER_PLUGIN))
+#define XFCE_APPFINDER_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_APPFINDER_PLUGIN, XfceAppfinderPluginClass))
+
+GType xfce_appfinder_plugin_get_type (void) G_GNUC_CONST;
+
+void xfce_appfinder_plugin_register_type (XfcePanelTypeModule *type_module);
+
+#ifdef DEBUG
+#define APPFINDER_DEBUG(...) g_print ("xfce4-appfinder-plugin-dbg: "); g_print (__VA_ARGS__); g_print ("\n")
+#else
+#define APPFINDER_DEBUG(...) G_STMT_START{ (void)0; }G_STMT_END
+#endif
+
+#ifdef DEBUG
+#define appfinder_assert(expr) g_assert (expr)
+#define appfinder_assert_not_reached() g_assert_not_reached ()
+#define appfinder_return_if_fail(expr) g_return_if_fail (expr)
+#define appfinder_return_val_if_fail(expr,val) g_return_val_if_fail (expr, val)
+#else
+#define appfinder_assert(expr) G_STMT_START{ (void)0; }G_STMT_END
+#define appfinder_assert_not_reached() G_STMT_START{ (void)0; }G_STMT_END
+#define appfinder_return_if_fail(expr) G_STMT_START{ (void)0; }G_STMT_END
+#define appfinder_return_val_if_fail(expr,val) G_STMT_START{ (void)0; }G_STMT_END
+#endif
+
+G_END_DECLS
+
+#endif /* !__XFCE_APPFINDER_PLUGIN_H__ */
More information about the Xfce4-commits
mailing list