You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2070 lines
65 KiB

13 years ago
/*
* Copyright (C) 2008-2009 Nick Schermer <nick@xfce.org>
13 years ago
*
13 years ago
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
13 years ago
*
13 years ago
* 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
* Lesser 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
13 years ago
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gtk/gtk.h>
#include <glib.h>
#include <libxfce4util/libxfce4util.h>
#include <common/panel-private.h>
#include <libxfce4panel/xfce-panel-macros.h>
#include <libxfce4panel/xfce-panel-plugin.h>
13 years ago
#include <libxfce4panel/xfce-panel-plugin-provider.h>
#include <libxfce4panel/libxfce4panel-marshal.h>
#include <libxfce4panel/libxfce4panel-alias.h>
13 years ago
#define XFCE_PANEL_PLUGIN_CONSTRUCTED(plugin) \
PANEL_HAS_FLAG (XFCE_PANEL_PLUGIN (plugin)->priv->flags, \
PLUGIN_FLAG_CONSTRUCTED)
#define XFCE_PANEL_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
XFCE_TYPE_PANEL_PLUGIN, \
XfcePanelPluginPrivate))
13 years ago
typedef const gchar *(*ProviderToPluginChar) (XfcePanelPluginProvider *provider);
typedef gint (*ProviderToPluginInt) (XfcePanelPluginProvider *provider);
13 years ago
static void xfce_panel_plugin_provider_init (XfcePanelPluginProviderIface *iface);
static void xfce_panel_plugin_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void xfce_panel_plugin_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void xfce_panel_plugin_dispose (GObject *object);
static void xfce_panel_plugin_finalize (GObject *object);
static void xfce_panel_plugin_realize (GtkWidget *widget);
static gboolean xfce_panel_plugin_button_press_event (GtkWidget *widget,
GdkEventButton *event);
static void xfce_panel_plugin_menu_move (XfcePanelPlugin *plugin);
static void xfce_panel_plugin_menu_remove (XfcePanelPlugin *plugin);
static void xfce_panel_plugin_menu_add_items (XfcePanelPlugin *plugin);
static void xfce_panel_plugin_menu_panel_preferences (XfcePanelPlugin *plugin);
static GtkMenu *xfce_panel_plugin_menu_get (XfcePanelPlugin *plugin);
static inline gchar *xfce_panel_plugin_relative_filename (XfcePanelPlugin *plugin);
static void xfce_panel_plugin_unregister_menu (GtkMenu *menu,
XfcePanelPlugin *plugin);
static void xfce_panel_plugin_set_size (XfcePanelPluginProvider *provider,
gint size);
static void xfce_panel_plugin_set_orientation (XfcePanelPluginProvider *provider,
GtkOrientation orientation);
static void xfce_panel_plugin_set_screen_position (XfcePanelPluginProvider *provider,
XfceScreenPosition screen_position);
static void xfce_panel_plugin_save (XfcePanelPluginProvider *provider);
static gboolean xfce_panel_plugin_get_show_configure (XfcePanelPluginProvider *provider);
static void xfce_panel_plugin_show_configure (XfcePanelPluginProvider *provider);
static gboolean xfce_panel_plugin_get_show_about (XfcePanelPluginProvider *provider);
static void xfce_panel_plugin_show_about (XfcePanelPluginProvider *provider);
static void xfce_panel_plugin_remove (XfcePanelPluginProvider *provider);
static gboolean xfce_panel_plugin_remote_event (XfcePanelPluginProvider *provider,
const gchar *name,
const GValue *value);
static void xfce_panel_plugin_take_window_notify (gpointer data,
GObject *where_the_object_was);
13 years ago
enum
{
PROP_0,
PROP_NAME,
PROP_DISPLAY_NAME,
PROP_COMMENT,
PROP_ARGUMENTS,
PROP_UNIQUE_ID,
PROP_ORIENTATION,
PROP_SIZE,
PROP_SCREEN_POSITION,
PROP_EXPAND
13 years ago
};
enum
{
ABOUT,
CONFIGURE_PLUGIN,
FREE_DATA,
ORIENTATION_CHANGED,
REMOTE_EVENT,
REMOVED,
13 years ago
SAVE,
SIZE_CHANGED,
SCREEN_POSITION_CHANGED,
LAST_SIGNAL
};
typedef enum
{
PLUGIN_FLAG_DISPOSED = 1 << 0,
PLUGIN_FLAG_CONSTRUCTED = 1 << 1,
PLUGIN_FLAG_SHOW_CONFIGURE = 1 << 2,
PLUGIN_FLAG_SHOW_ABOUT = 1 << 3,
PLUGIN_FLAG_BLOCK_AUTOHIDE = 1 << 4
}
PluginFlags;
13 years ago
struct _XfcePanelPluginPrivate
{
/* plugin information */
gchar *name;
gchar *display_name;
gchar *comment;
gint unique_id;
gchar *property_base;
gchar **arguments;
gint size;
guint expand : 1;
GtkOrientation orientation;
XfceScreenPosition screen_position;
/* flags */
PluginFlags flags;
13 years ago
/* plugin menu */
GtkMenu *menu;
/* menu block counter */
gint menu_blocked;
/* autohide block counter */
gint panel_lock;
13 years ago
};
static guint plugin_signals[LAST_SIGNAL];
G_DEFINE_TYPE_WITH_CODE (XfcePanelPlugin, xfce_panel_plugin, GTK_TYPE_EVENT_BOX,
G_IMPLEMENT_INTERFACE (XFCE_TYPE_PANEL_PLUGIN_PROVIDER,
xfce_panel_plugin_provider_init));
13 years ago
static void
xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
{
GObjectClass *gobject_class;
GtkWidgetClass *gtkwidget_class;
/* add private data */
g_type_class_add_private (klass, sizeof (XfcePanelPluginPrivate));
/* reset class contruct function */
klass->construct = NULL;
13 years ago
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = xfce_panel_plugin_get_property;
gobject_class->set_property = xfce_panel_plugin_set_property;
gobject_class->dispose = xfce_panel_plugin_dispose;
13 years ago
gobject_class->finalize = xfce_panel_plugin_finalize;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
gtkwidget_class->realize = xfce_panel_plugin_realize;
13 years ago
gtkwidget_class->button_press_event = xfce_panel_plugin_button_press_event;
/**
* XfcePanelPlugin::about
* @plugin : an #XfcePanelPlugin.
13 years ago
*
* This signal is emmitted when the About entry in the right-click
* menu is clicked. Plugin writes can use it to show information
* about the plugin and display credits of the developers, translators
* and other contributors.
*
* See also: xfce_panel_plugin_menu_show_about().
**/
plugin_signals[ABOUT] =
g_signal_new (g_intern_static_string ("about"),
13 years ago
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XfcePanelPluginClass, about),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* XfcePanelPlugin::configure-plugin
* @plugin : an #XfcePanelPlugin.
13 years ago
*
* This signal is emmitted when the Properties entry in the right-click
* menu is clicked. Plugin writes can use this signal to open a
* plugin settings dialog.
*
* See also: xfce_panel_plugin_menu_show_configure() and
* xfce_titled_dialog_new ().
**/
plugin_signals[CONFIGURE_PLUGIN] =
g_signal_new (g_intern_static_string ("configure-plugin"),
13 years ago
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XfcePanelPluginClass, configure_plugin),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* XfcePanelPlugin::free-data
* @plugin : an #XfcePanelPlugin.
13 years ago
*
* This signal is emmitted when the plugin is closing. Plugin
* writers should use this signal to free any allocated resources.
*
* See also #XfceHVBox.
**/
plugin_signals[FREE_DATA] =
g_signal_new (g_intern_static_string ("free-data"),
13 years ago
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XfcePanelPluginClass, free_data),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* XfcePanelPlugin::orientation-changed
* @plugin : an #XfcePanelPlugin.
13 years ago
* @orientation : new #GtkOrientation of the panel.
*
* This signal is emmitted whenever the orientation of the panel
* the @plugin is on changes. Plugins writers can for example use
* this signal to change the order of widgets in the plugin.
*
* See also: #XfceHVBox.
**/
plugin_signals[ORIENTATION_CHANGED] =
g_signal_new (g_intern_static_string ("orientation-changed"),
13 years ago
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XfcePanelPluginClass, orientation_changed),
NULL, NULL,
g_cclosure_marshal_VOID__ENUM,
G_TYPE_NONE, 1, GTK_TYPE_ORIENTATION);
/**
* XfcePanelPlugin::remote-event
* @plugin : an #XfcePanelPlugin.
* @name : name of the signal.
* @value : value of the signal.
*
* This signal is emmitted by the user by running
* xfce4-panel --plugin-event=plugin-name:name:type:value. It can be
* used for remote communication, like for example to popup a menu.
*
* Returns: %TRUE to stop signal emission to other plugins, %FALSE
* to send the signal also to other plugins with the same
* name.
**/
plugin_signals[REMOTE_EVENT] =
g_signal_new (g_intern_static_string ("remote-event"),
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XfcePanelPluginClass, remote_event),
NULL, NULL,
_libxfce4panel_marshal_BOOLEAN__STRING_BOXED,
G_TYPE_BOOLEAN, 2, G_TYPE_STRING, G_TYPE_VALUE);
/**
* XfcePanelPlugin::removed
* @plugin : an #XfcePanelPlugin.
*
* This signal is emmitted when the plugin is permanently removed from
* the panel configuration by the user. Developers can use this signal
* to cleanup custom setting locations that for example store passwords.
*
* The free-data signal is emitted after this signal!
*
* Note that if you use the xfconf channel and base property provided
* by xfce_panel_plugin_get_property_base() or the rc file location
* returned by xfce_panel_plugin_save_location(), the panel will take
* care of removing those settings.
*
* Since: 4.8
**/
plugin_signals[REMOVED] =
g_signal_new (g_intern_static_string ("removed"),
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XfcePanelPluginClass, removed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
13 years ago
/**
* XfcePanelPlugin::save
* @plugin : an #XfcePanelPlugin.
13 years ago
*
* This signal is emitted when the plugin should save it's
* configuration. The signal is always emmitted before the plugin
* closes (before the "free-data" signal) and also once in 10
* minutes or so.
*
* See also: xfce_panel_plugin_save_location().
**/
plugin_signals[SAVE] =
g_signal_new (g_intern_static_string ("save"),
13 years ago
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XfcePanelPluginClass, save),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* XfcePanelPlugin::size-changed
* @plugin : an #XfcePanelPlugin.
13 years ago
* @size : the new size of the panel.
*
* This signal is emmitted whenever the size of the panel
* the @plugin is on changes. Plugins writers can for example use
* this signal to update their icon size.
*
* If the function returns %FALSE or is not used, the panel will force
* a square size to the plugin. If you want non-square plugins and you
* don't need this signal you can use something like this:
*
* g_signal_connect (plugin, "size-changed", G_CALLBACK (gtk_true), NULL);
13 years ago
**/
plugin_signals[SIZE_CHANGED] =
g_signal_new (g_intern_static_string ("size-changed"),
13 years ago
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XfcePanelPluginClass, size_changed),
g_signal_accumulator_true_handled, NULL,
_libxfce4panel_marshal_BOOLEAN__INT,
G_TYPE_BOOLEAN, 1, G_TYPE_INT);
13 years ago
/**
* XfcePanelPlugin::screen-position-changed
* @plugin : an #XfcePanelPlugin.
* @position : the new #XfceScreenPosition of the panel.
13 years ago
*
* This signal is emmitted whenever the screen position of the panel
* the @plugin is on changes. Plugins writers can for example use
* this signal to change the arrow direction of buttons.
**/
plugin_signals[SCREEN_POSITION_CHANGED] =
g_signal_new (g_intern_static_string ("screen-position-changed"),
13 years ago
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XfcePanelPluginClass, screen_position_changed),
NULL, NULL,
g_cclosure_marshal_VOID__ENUM,
G_TYPE_NONE, 1, XFCE_TYPE_SCREEN_POSITION);
13 years ago
/**
* XfcePanelPlugin:name:
*
* The internal, unstranslated, name of the #XfcePanelPlugin. Plugin
* writer can use it to read the plugin name, but
* xfce_panel_plugin_get_name() is recommended since that
13 years ago
* 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));
13 years ago
/**
* XfcePanelPlugin:display-name:
*
* The display name of the #XfcePanelPlugin. This property is used during plugin
* construction and can't be set twice. Plugin writer can use it to read the
* plugin display name, but xfce_panel_plugin_get_display_name() is recommended
* since that returns a const string.
**/
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));
13 years ago
/**
* XfcePanelPlugin:comment:
*
* TODO
*
* Since 4.8.0
**/
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));
13 years ago
/**
* XfcePanelPlugin:id:
*
* The unique id of the #XfcePanelPlugin. Plugin writer can use it to
* read the unique id, but xfce_panel_plugin_get_unique_id() is recommended.
13 years ago
**/
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));
/**
* XfcePanelPlugin:arguments:
*
* The arguments the plugin was started with. If the plugin was not
* started with any arguments this value is %NULL. Plugin writer can
* 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));
/**
* XfcePanelPlugin:orientation:
*
* TODO
**/
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));
/**
* XfcePanelPlugin:size:
*
* TODO
**/
g_object_class_install_property (gobject_class,
PROP_SIZE,
g_param_spec_int ("size",
"Size",
"Size of the plugin's panel",
0, 128, 0,
G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS));
/**
* XfcePanelPlugin:screen-position:
*
* TODO
**/
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));
/**
* XfcePanelPlugin:expand:
*
* TODO
**/
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));
13 years ago
}
static void
xfce_panel_plugin_init (XfcePanelPlugin *plugin)
{
/* set private pointer */
plugin->priv = XFCE_PANEL_PLUGIN_GET_PRIVATE (plugin);
/* initialize plugin value */
plugin->priv->name = NULL;
plugin->priv->display_name = NULL;
plugin->priv->comment = NULL;
plugin->priv->unique_id = -1;
plugin->priv->property_base = NULL;
plugin->priv->arguments = NULL;
13 years ago
plugin->priv->size = 0;
plugin->priv->expand = FALSE;
plugin->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
plugin->priv->screen_position = XFCE_SCREEN_POSITION_NONE;
plugin->priv->menu = NULL;
plugin->priv->menu_blocked = 0;
plugin->priv->panel_lock = 0;
plugin->priv->flags = 0;
13 years ago
/* hide the event box window to make the plugin transparent */
gtk_event_box_set_visible_window (GTK_EVENT_BOX (plugin), FALSE);
}
static void
xfce_panel_plugin_provider_init (XfcePanelPluginProviderIface *iface)
{
iface->get_name = (ProviderToPluginChar) xfce_panel_plugin_get_name;
iface->get_unique_id = (ProviderToPluginInt) xfce_panel_plugin_get_unique_id;
13 years ago
iface->set_size = xfce_panel_plugin_set_size;
iface->set_orientation = xfce_panel_plugin_set_orientation;
iface->set_screen_position = xfce_panel_plugin_set_screen_position;
iface->save = xfce_panel_plugin_save;
iface->get_show_configure = xfce_panel_plugin_get_show_configure;
iface->show_configure = xfce_panel_plugin_show_configure;
iface->get_show_about = xfce_panel_plugin_get_show_about;
iface->show_about = xfce_panel_plugin_show_about;
iface->remove = xfce_panel_plugin_remove;
iface->remote_event = xfce_panel_plugin_remote_event;
13 years ago
}
static void
xfce_panel_plugin_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
XfcePanelPluginPrivate *private = XFCE_PANEL_PLUGIN (object)->priv;
13 years ago
switch (prop_id)
{
case PROP_NAME:
g_value_set_static_string (value, private->name);
13 years ago
break;
case PROP_DISPLAY_NAME:
g_value_set_static_string (value, private->display_name);
13 years ago
break;
case PROP_COMMENT:
g_value_set_static_string (value, private->comment);
break;
case PROP_UNIQUE_ID:
g_value_set_int (value, private->unique_id);
13 years ago
break;
case PROP_ARGUMENTS:
g_value_set_boxed (value, private->arguments);
break;
case PROP_ORIENTATION:
g_value_set_enum (value, private->orientation);
break;
case PROP_SIZE:
g_value_set_int (value, private->size);
break;
case PROP_SCREEN_POSITION:
g_value_set_enum (value, private->screen_position);
break;
case PROP_EXPAND:
g_value_set_boolean (value, private->expand);
break;
13 years ago
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
xfce_panel_plugin_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
XfcePanelPluginPrivate *private = XFCE_PANEL_PLUGIN (object)->priv;
13 years ago
switch (prop_id)
{
case PROP_NAME:
private->name = g_value_dup_string (value);
13 years ago
break;
case PROP_DISPLAY_NAME:
private->display_name = g_value_dup_string (value);
13 years ago
break;
case PROP_COMMENT:
private->comment = g_value_dup_string (value);
break;
case PROP_UNIQUE_ID:
private->unique_id = g_value_get_int (value);
13 years ago
break;
case PROP_ARGUMENTS:
private->arguments = g_value_dup_boxed (value);
break;
case PROP_EXPAND:
xfce_panel_plugin_set_expand (XFCE_PANEL_PLUGIN (object),
g_value_get_boolean (value));
break;
13 years ago
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
xfce_panel_plugin_dispose (GObject *object)
13 years ago
{
XfcePanelPlugin *plugin = XFCE_PANEL_PLUGIN (object);
if (!PANEL_HAS_FLAG (plugin->priv->flags, PLUGIN_FLAG_DISPOSED))
{
/* allow the plugin to cleanup */
g_signal_emit (G_OBJECT (object), plugin_signals[FREE_DATA], 0);
/* plugin disposed, don't try this again */
PANEL_SET_FLAG (plugin->priv->flags, PLUGIN_FLAG_DISPOSED);
}
(*G_OBJECT_CLASS (xfce_panel_plugin_parent_class)->dispose) (object);
}
static void
xfce_panel_plugin_finalize (GObject *object)
{
XfcePanelPlugin *plugin = XFCE_PANEL_PLUGIN (object);
13 years ago
/* destroy the menu */
if (plugin->priv->menu)
gtk_widget_destroy (GTK_WIDGET (plugin->priv->menu));
13 years ago
/* cleanup */
g_free (plugin->priv->name);
g_free (plugin->priv->display_name);
g_free (plugin->priv->comment);
g_free (plugin->priv->property_base);
g_strfreev (plugin->priv->arguments);
13 years ago
(*G_OBJECT_CLASS (xfce_panel_plugin_parent_class)->finalize) (object);
}
static void
xfce_panel_plugin_realize (GtkWidget *widget)
{
XfcePanelPluginClass *klass = NULL;
XfcePanelPlugin *plugin = XFCE_PANEL_PLUGIN (widget);
if (!PANEL_HAS_FLAG (plugin->priv->flags, PLUGIN_FLAG_CONSTRUCTED))
{
/* we use this flag to check plugin developers with gobject
* plugins, that they do not use plugin functions in the init
* stage. the properties are not set at that point an the
* panel is not aware of the signals and stuff */
PANEL_SET_FLAG (plugin->priv->flags, PLUGIN_FLAG_CONSTRUCTED);
/* wether this is an object plugin */
klass = XFCE_PANEL_PLUGIN_GET_CLASS (widget);
if (klass->construct == NULL)
klass = NULL;
}
/* let gtk to realize the plugin */
(*GTK_WIDGET_CLASS (xfce_panel_plugin_parent_class)->realize) (widget);
/* check if there is a construct function attached to this plugin if
* so, run it */
if (klass != NULL)
(*klass->construct) (XFCE_PANEL_PLUGIN (widget));
}
13 years ago
static gboolean
xfce_panel_plugin_button_press_event (GtkWidget *widget,
GdkEventButton *event)
{
XfcePanelPlugin *plugin = XFCE_PANEL_PLUGIN (widget);
guint modifiers;
GtkMenu *menu;
GtkWidget *item;
13 years ago
panel_return_val_if_fail (XFCE_IS_PANEL_PLUGIN (widget), FALSE);
/* get the default accelerator modifier mask */
modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
if (event->button == 3
|| (event->button == 1 && modifiers == GDK_CONTROL_MASK))
13 years ago
{
/* get the panel menu */
menu = xfce_panel_plugin_menu_get (plugin);
13 years ago
/* set the menu screen */
gtk_menu_set_screen (menu, gtk_widget_get_screen (widget));
13 years ago
/* if the menu is block, some items are insensitive */
item = g_object_get_data (G_OBJECT (menu), g_intern_static_string ("properties-item"));
gtk_widget_set_sensitive (item, plugin->priv->menu_blocked == 0);
13 years ago
/* popup the menu */
gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button, event->time);
13 years ago
return TRUE;
}
return FALSE;
}
static void
xfce_panel_plugin_menu_move (XfcePanelPlugin *plugin)
{
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin));
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (plugin));
/* move the plugin */
xfce_panel_plugin_provider_emit_signal (XFCE_PANEL_PLUGIN_PROVIDER (plugin),
PROVIDER_SIGNAL_MOVE_PLUGIN);
13 years ago
}
static void
xfce_panel_plugin_menu_remove (XfcePanelPlugin *plugin)
{
GtkWidget *dialog;
13 years ago
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin));
/* create question dialog (same code is also in panel-preferences-dialog.c) */
dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
_("Are you sure that you want to remove \"%s\"?"),
xfce_panel_plugin_get_display_name (plugin));
gtk_window_set_screen (GTK_WINDOW (dialog),
gtk_widget_get_screen (GTK_WIDGET (plugin)));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
_("If you remove the item from the panel, it is permanently lost."));
gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL,
GTK_RESPONSE_NO, GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_NO);
13 years ago
/* run the dialog */
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
13 years ago
{
/* hide the dialog */
gtk_widget_hide (dialog);
13 years ago
/* ask the panel or wrapper to remove the plugin */
xfce_panel_plugin_provider_emit_signal (XFCE_PANEL_PLUGIN_PROVIDER (plugin),
PROVIDER_SIGNAL_REMOVE_PLUGIN);
13 years ago
}
/* destroy window */
gtk_widget_destroy (dialog);
13 years ago
}
static void
xfce_panel_plugin_menu_add_items (XfcePanelPlugin *plugin)
{
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin));
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (plugin));
panel_return_if_fail (XFCE_PANEL_PLUGIN_CONSTRUCTED (plugin));
13 years ago
/* open items dialog */
xfce_panel_plugin_provider_emit_signal (XFCE_PANEL_PLUGIN_PROVIDER (plugin),
PROVIDER_SIGNAL_ADD_NEW_ITEMS);
13 years ago
}