Browse Source

Allow adding plugins from the commandline with arguments.

upstream/xfce4-panel-4.10.1
Nick Schermer 13 years ago
parent
commit
6b967de2cf
  1. 2
      Panel-desktop-handler.desktop.in.in
  2. 34
      libxfce4panel/libxfce4panel.h
  3. 19
      libxfce4panel/xfce-panel-plugin-provider.h
  4. 73
      libxfce4panel/xfce-panel-plugin.c
  5. 9
      libxfce4panel/xfce-panel-plugin.h
  6. 35
      panel/main.c
  7. 209
      panel/panel-application.c
  8. 40
      panel/panel-application.h
  9. 34
      panel/panel-dbus-client.c
  10. 18
      panel/panel-dbus-client.h
  11. 13
      panel/panel-dbus-service-infos.xml
  12. 29
      panel/panel-dbus-service.c
  13. 39
      panel/panel-module-factory.c
  14. 17
      panel/panel-module-factory.h
  15. 15
      panel/panel-module.c
  16. 31
      panel/panel-module.h
  17. 121
      panel/panel-plugin-external.c
  18. 2
      panel/panel-plugin-external.h
  19. 4
      plugins/launcher/launcher-dialog.c
  20. 2
      plugins/launcher/launcher-dialog.h
  21. 35
      plugins/launcher/launcher.c
  22. 2
      wrapper/main.c

2
Panel-desktop-handler.desktop.in.in

@ -6,9 +6,7 @@ _GenericName=Create Launcher on Xfce Panel
TryExec=xfce4-panel
Exec=xfce4-panel --add=launcher %F
Icon=application-x-executable
NoDisplay=true
Terminal=false
StartupNotify=true
Type=Application
Categories=System;Utility;Core;GTK;Panel;
MimeType=application/x-desktop;

34
libxfce4panel/libxfce4panel.h

@ -106,15 +106,17 @@ typedef GTypeModule XfcePanelModule;
const gchar *plugin_init_display_name = NULL; \
\
G_MODULE_EXPORT XfcePanelPlugin * \
xfce_panel_plugin_construct (const gchar *name, \
const gchar *id, \
const gchar *display_name, \
GdkScreen *screen) \
xfce_panel_plugin_construct (const gchar *name, \
const gchar *id, \
const gchar *display_name, \
gchar **arguments, \
GdkScreen *screen) \
{ \
XfcePanelPlugin *plugin; \
extern const gchar *plugin_init_name; \
extern const gchar *plugin_init_id; \
extern const gchar *plugin_init_display_name; \
XfcePanelPlugin *plugin; \
extern const gchar *plugin_init_name; \
extern const gchar *plugin_init_id; \
extern const gchar *plugin_init_display_name; \
extern gchar **plugin_init_arguments; \
\
panel_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); \
panel_return_val_if_fail (name != NULL && id != NULL, NULL); \
@ -124,13 +126,15 @@ typedef GTypeModule XfcePanelModule;
plugin_init_name = name; \
plugin_init_id = id; \
plugin_init_display_name = display_name; \
plugin_init_arguments = arguments; \
\
CODE \
\
plugin = g_object_new (type, \
"name", name, \
"display-name", display_name, \
"id", id, NULL); \
"id", id, \
"arguments", arguments, NULL); \
\
return plugin; \
}
@ -157,10 +161,11 @@ typedef GTypeModule XfcePanelModule;
} \
\
G_MODULE_EXPORT XfcePanelPlugin * \
xfce_panel_plugin_construct (const gchar *name, \
const gchar *id, \
const gchar *display_name, \
GdkScreen *screen) \
xfce_panel_plugin_construct (const gchar *name, \
const gchar *id, \
const gchar *display_name, \
gchar **arguments, \
GdkScreen *screen) \
{ \
XfcePanelPlugin *plugin = NULL; \
\
@ -173,7 +178,8 @@ typedef GTypeModule XfcePanelModule;
plugin = g_object_new (XFCE_TYPE_PANEL_PLUGIN, \
"name", name, \
"display-name", display_name, \
"id", id, NULL); \
"id", id, \
"arguments", arguments, NULL); \
\
/* signal to realize the plugin */ \
g_signal_connect_after (G_OBJECT (plugin), "realize", G_CALLBACK (xfce_panel_plugin_realize), NULL); \

19
libxfce4panel/xfce-panel-plugin-provider.h

@ -27,11 +27,12 @@ typedef struct _XfcePanelPluginProviderIface XfcePanelPluginProviderIface;
typedef struct _XfcePanelPluginProvider XfcePanelPluginProvider;
typedef enum _XfcePanelPluginMessage XfcePanelPluginMessage;
typedef XfcePanelPluginProvider *(*PluginConstructFunc) (const gchar *name,
const gchar *id,
const gchar *display_name,
GdkScreen *screen);
typedef XfcePanelPluginProvider *(*PluginConstructFunc) (const gchar *name,
const gchar *id,
const gchar *display_name,
gchar **arguments,
GdkScreen *screen);
typedef void (*PluginRegisterTypesFunc) (XfcePanelModule *module);
#define XFCE_TYPE_PANEL_PLUGIN_PROVIDER (xfce_panel_plugin_provider_get_type ())
@ -58,7 +59,7 @@ struct _XfcePanelPluginProviderIface
{
/*< private >*/
GTypeInterface __parent__;
/*< public >*/
gboolean (*is_external) (void);
const gchar *(*get_name) (XfcePanelPluginProvider *provider);
@ -83,13 +84,13 @@ const gchar *xfce_panel_plugin_provider_get_id (XfcePanelPluginProv
void xfce_panel_plugin_provider_set_size (XfcePanelPluginProvider *provider,
gint size);
void xfce_panel_plugin_provider_set_orientation (XfcePanelPluginProvider *provider,
GtkOrientation orientation);
void xfce_panel_plugin_provider_set_screen_position (XfcePanelPluginProvider *provider,
XfceScreenPosition screen_position);
void xfce_panel_plugin_provider_set_opacity (XfcePanelPluginProvider *provider,
gdouble opacity);

73
libxfce4panel/xfce-panel-plugin.c

@ -74,6 +74,7 @@ enum
PROP_0,
PROP_NAME,
PROP_DISPLAY_NAME,
PROP_ARGUMENTS,
PROP_ID
};
@ -92,16 +93,17 @@ enum
struct _XfcePanelPluginPrivate
{
/* plugin information */
gchar *name;
gchar *display_name;
gchar *id;
gint size;
guint expand : 1;
GtkOrientation orientation;
XfceScreenPosition screen_position;
gchar *name;
gchar *display_name;
gchar *id;
gchar **arguments;
gint size;
guint expand : 1;
GtkOrientation orientation;
XfceScreenPosition screen_position;
/* plugin menu */
GtkWidget *menu;
GtkWidget *menu;
};
@ -111,9 +113,10 @@ static guint plugin_signals[LAST_SIGNAL];
/* external plugin information for during plugin_init */
const gchar *plugin_init_name = NULL;
const gchar *plugin_init_id = NULL;
const gchar *plugin_init_display_name = NULL;
const gchar *plugin_init_name = NULL;
const gchar *plugin_init_id = NULL;
const gchar *plugin_init_display_name = NULL;
gchar **plugin_init_arguments = NULL;
@ -321,6 +324,18 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
"Unique plugin ID",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/**
* XfcePanelPlugin:arguments:
*
* TODO
**/
g_object_class_install_property (gobject_class,
PROP_ARGUMENTS,
g_param_spec_pointer ("arguments",
"Arguemnts",
"Startup arguments for the plugin",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
@ -335,6 +350,7 @@ xfce_panel_plugin_init (XfcePanelPlugin *plugin)
plugin->priv->name = NULL;
plugin->priv->display_name = NULL;
plugin->priv->id = NULL;
plugin->priv->arguments = NULL;
plugin->priv->size = 0;
plugin->priv->expand = FALSE;
plugin->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
@ -382,6 +398,10 @@ xfce_panel_plugin_get_property (GObject *object,
g_value_set_static_string (value, plugin->priv->id);
break;
case PROP_ARGUMENTS:
g_value_set_pointer (value, plugin->priv->arguments);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -424,6 +444,14 @@ xfce_panel_plugin_set_property (GObject *object,
plugin->priv->id = g_value_dup_string (value);
break;
case PROP_ARGUMENTS:
/* cleanup previous arguments */
g_strfreev (plugin->priv->arguments);
/* set new values */
plugin->priv->arguments = g_strdupv (g_value_get_pointer (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -459,6 +487,7 @@ xfce_panel_plugin_finalize (GObject *object)
g_free (plugin->priv->name);
g_free (plugin->priv->display_name);
g_free (plugin->priv->id);
g_strfreev (plugin->priv->arguments);
(*G_OBJECT_CLASS (xfce_panel_plugin_parent_class)->finalize) (object);
}
@ -754,6 +783,28 @@ xfce_panel_plugin_get_id (XfcePanelPlugin *plugin)
gboolean
xfce_panel_plugin_get_arguments (XfcePanelPlugin *plugin,
gchar ***arguments)
{
g_return_val_if_fail (XFCE_IS_PANEL_PLUGIN (plugin), FALSE);
if (plugin->priv->arguments || plugin_init_arguments)
{
/* dupplicate the arguments */
if (arguments != NULL)
*arguments = g_strdupv (plugin->priv->arguments ? plugin->priv->arguments : plugin_init_arguments);
return TRUE;
}
else
{
return FALSE;
}
}
gint
xfce_panel_plugin_get_size (XfcePanelPlugin *plugin)
{

9
libxfce4panel/xfce-panel-plugin.h

@ -69,7 +69,7 @@ struct _XfcePanelPlugin
{
/*< private >*/
GtkEventBox __parent__;
/*< private >*/
XfcePanelPluginPrivate *priv;
};
@ -83,6 +83,9 @@ const gchar *xfce_panel_plugin_get_display_name (XfcePanelPlugin *plug
const gchar *xfce_panel_plugin_get_id (XfcePanelPlugin *plugin);
gboolean xfce_panel_plugin_get_arguments (XfcePanelPlugin *plugin,
gchar ***arguments);
gint xfce_panel_plugin_get_size (XfcePanelPlugin *plugin);
gboolean xfce_panel_plugin_get_expand (XfcePanelPlugin *plugin);
@ -113,7 +116,7 @@ void xfce_panel_plugin_unblock_menu (XfcePanelPlugin *plug
void xfce_panel_plugin_register_menu (XfcePanelPlugin *plugin,
GtkMenu *menu);
GtkArrowType xfce_panel_plugin_arrow_type (XfcePanelPlugin *plugin);
void xfce_panel_plugin_position_widget (XfcePanelPlugin *plugin,
@ -121,7 +124,7 @@ void xfce_panel_plugin_position_widget (XfcePanelPlugin *plug
GtkWidget *attach_widget,
gint *x,
gint *y);
void xfce_panel_plugin_position_menu (GtkMenu *menu,
gint *x,
gint *y,

35
panel/main.c

@ -36,26 +36,30 @@
static gboolean opt_customize = FALSE;
static gboolean opt_add = FALSE;
static gboolean opt_save = FALSE;
static gboolean opt_restart = FALSE;
static gboolean opt_quit = FALSE;
static gboolean opt_version = FALSE;
static gchar *opt_client_id = NULL;
static gboolean opt_preferences = FALSE;
static gboolean opt_add_items = FALSE;
static gboolean opt_save = FALSE;
static gchar *opt_add = NULL;
static gboolean opt_restart = FALSE;
static gboolean opt_quit = FALSE;
static gboolean opt_version = FALSE;
static gchar *opt_client_id = NULL;
static gchar **arguments = NULL;
/* command line options */
static const GOptionEntry option_entries[] =
{
{ "customize", 'c', 0, G_OPTION_ARG_NONE, &opt_customize, N_("Show the 'Customize Panel' dialog"), NULL },
{ "add", 'a', 0, G_OPTION_ARG_NONE, &opt_add, N_("Show the 'Add New Items' dialog"), NULL },
{ "preferences", 'p', 0, G_OPTION_ARG_NONE, &opt_preferences, N_("Show the 'Panel Preferences' dialog"), NULL },
{ "add-items", 'a', 0, G_OPTION_ARG_NONE, &opt_add_items, N_("Show the 'Add New Items' dialog"), NULL },
{ "save", 's', 0, G_OPTION_ARG_NONE, &opt_save, N_("Save the panel configuration"), NULL },
{ "add", '\0', 0, G_OPTION_ARG_STRING, &opt_add, N_("Add a new plugin to the panel"), N_("PLUGIN NAME") },
{ "restart", 'r', 0, G_OPTION_ARG_NONE, &opt_restart, N_("Restart the running panel instance"), NULL },
{ "quit", 'q', 0, G_OPTION_ARG_NONE, &opt_quit, N_("Quit the running panel instance"), NULL },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &opt_version, N_("Print version information and exit"), NULL },
{ "sm-client-id", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_client_id, NULL, NULL },
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &arguments, NULL, NULL },
{ NULL }
};
@ -81,7 +85,7 @@ main (gint argc, gchar **argv)
g_thread_init (NULL);
/* initialize gtk+ */
if (!gtk_init_with_args (&argc, &argv, "", (GOptionEntry *) option_entries, GETTEXT_PACKAGE, &error))
if (!gtk_init_with_args (&argc, &argv, _("[ARGUMENTS...]"), (GOptionEntry *) option_entries, GETTEXT_PACKAGE, &error))
{
/* print an error message */
if (error == NULL)
@ -114,14 +118,14 @@ main (gint argc, gchar **argv)
return EXIT_SUCCESS;
}
else if (opt_customize)
else if (opt_preferences)
{
/* send a signal to the running instance to show the preferences dialog */
result = panel_dbus_client_display_preferences_dialog (NULL, &error);
goto dbus_return;
}
else if (opt_add)
else if (opt_add_items)
{
/* send a signal to the running instance to show the add items dialog */
result = panel_dbus_client_display_items_dialog (NULL, &error);
@ -133,6 +137,13 @@ main (gint argc, gchar **argv)
/* send a save signal to the running instance */
result = panel_dbus_client_save (&error);
goto dbus_return;
}
else if (opt_add)
{
/* send a add new item signal to the running instance */
result = panel_dbus_client_add_new_item (opt_add, arguments, &error);
goto dbus_return;
}
else if (opt_restart || opt_quit)

209
panel/panel-application.c

@ -243,7 +243,7 @@ panel_application_load (PanelApplication *application)
{
/* create empty panel window */
window = panel_application_new_window (application, NULL);
/* TODO add some cruft here */
/* show window */
@ -302,7 +302,7 @@ panel_application_load_set_property (PanelWindow *window,
/* 0: normal width, 1: full width and 2: span monitors */
if (integer > 1)
panel_window_set_length (window, 100);
if (integer == 2)
panel_window_set_span_monitors (window, TRUE);
}
@ -349,23 +349,23 @@ move_handle (GtkWidget *item,
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (item));
panel_return_if_fail (PANEL_IS_APPLICATION (application));
/* get a copy of the current event */
event = gtk_get_current_event ();
if (G_LIKELY (event))
{
/* make the window insensitive */
panel_application_windows_sensitive (application, FALSE);
/* create a target list */
target_list = gtk_target_list_new (drag_targets, G_N_ELEMENTS (drag_targets));
/* begin a drag */
gtk_drag_begin (item, target_list, GDK_ACTION_MOVE, 1, event);
/* release the drag list */
gtk_target_list_unref (target_list);
/* free the event */
gdk_event_free (event);
}
@ -378,37 +378,38 @@ panel_application_get_unique_id (void)
{
static gint counter = 0;
static gchar id[30];
/* create a unique if of the current time and counter */
g_snprintf (id, sizeof(id), "%ld%d", time (NULL), counter++);
return id;
}
static gboolean
panel_application_insert_plugin (PanelApplication *application,
PanelWindow *window,
GdkScreen *screen,
const gchar *name,
const gchar *id,
UseWrapper use_wrapper,
gint position)
panel_application_insert_plugin (PanelApplication *application,
PanelWindow *window,
GdkScreen *screen,
const gchar *name,
const gchar *id,
gchar **arguments,
UseWrapper use_wrapper,
gint position)
{
GtkWidget *itembar;
gboolean succeed = FALSE;
XfcePanelPluginProvider *provider;
panel_return_val_if_fail (PANEL_IS_APPLICATION (application), FALSE);
panel_return_val_if_fail (PANEL_IS_WINDOW (window), FALSE);
panel_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
panel_return_val_if_fail (name != NULL, FALSE);
/* create a new unique id if needed */
if (id == NULL)
id = panel_application_get_unique_id ();
/* create a new panel plugin */
provider = panel_module_factory_create_plugin (application->factory, screen, name, id, use_wrapper);
provider = panel_module_factory_create_plugin (application->factory, screen, name, id, arguments, use_wrapper);
if (G_LIKELY (provider != NULL))
{
@ -422,21 +423,21 @@ panel_application_insert_plugin (PanelApplication *application,
/* add the item to the panel */
panel_itembar_insert (PANEL_ITEMBAR (itembar), GTK_WIDGET (provider), position);
/* show the plugin */
gtk_widget_show (GTK_WIDGET (provider));
xfce_panel_plugin_provider_set_orientation (provider, panel_window_get_orientation (window));
xfce_panel_plugin_provider_set_screen_position (provider, panel_glue_get_screen_position (window));
xfce_panel_plugin_provider_set_size (provider, panel_window_get_size (window));
/* we've succeeded */
succeed = TRUE;
}
return succeed;
}
static void
@ -520,7 +521,7 @@ panel_application_load_start_element (GMarkupParseContext *context,
if (G_LIKELY (name != NULL))
panel_application_insert_plugin (parser->application, parser->window,
gtk_window_get_screen (GTK_WINDOW (parser->window)),
name, id, use_wrapper, -1);
name, id, NULL, use_wrapper, -1);
}
break;
@ -736,6 +737,47 @@ panel_application_get (void)
void
panel_application_save (PanelApplication *application)
{
gchar *filename;
gchar *contents;
gboolean succeed;
GError *error = NULL;
panel_return_if_fail (PANEL_IS_APPLICATION (application));
/* get save location */
filename = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, PANEL_CONFIG_PATH, TRUE);
if (G_LIKELY (filename))
{
/* get the file xml data */
contents = panel_application_save_xml_contents (application);
/* write the data to the file */
succeed = g_file_set_contents (filename, contents, -1, &error);
if (G_UNLIKELY (succeed == FALSE))
{
/* writing failed, print warning */
g_critical ("Failed to write panel configuration to \"%s\": %s", filename, error->message);
/* cleanup */
g_error_free (error);
}
/* cleanup */
g_free (contents);
g_free (filename);
}
else
{
/* print warning */
g_critical ("Failed to create panel configuration file");
}
}
void
panel_application_take_dialog (PanelApplication *application,
GtkWindow *dialog)
@ -776,42 +818,21 @@ panel_application_destroy_dialogs (PanelApplication *application)
void
panel_application_save (PanelApplication *application)
panel_application_add_new_item (PanelApplication *application,
const gchar *plugin_name,
gchar **arguments)
{
gchar *filename;
gchar *contents;
gboolean succeed;
GError *error = NULL;
PanelWindow *window;
panel_return_if_fail (PANEL_IS_APPLICATION (application));
panel_return_if_fail (plugin_name != NULL);
/* get save location */
filename = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, PANEL_CONFIG_PATH, TRUE);
if (G_LIKELY (filename))
{
/* get the file xml data */
contents = panel_application_save_xml_contents (application);
/* write the data to the file */
succeed = g_file_set_contents (filename, contents, -1, &error);
if (G_UNLIKELY (succeed == FALSE))
{
/* writing failed, print warning */
g_critical ("Failed to write panel configuration to \"%s\": %s", filename, error->message);
/* TODO fix this */
window = application->windows->data;
/* cleanup */
g_error_free (error);
}
/* cleanup */
g_free (contents);
g_free (filename);
}
else
{
/* print warning */
g_critical ("Failed to create panel configuration file");
}
if (!panel_application_insert_plugin (application, window, gtk_widget_get_screen (GTK_WIDGET (window)),
plugin_name, NULL, arguments, FROM_DESKTOP_FILE, -1))
g_warning (_("The plugin you want to add is not recognized by the panel."), plugin_name);
}
@ -833,59 +854,59 @@ panel_application_drag_data_received (GtkWidget *itembar,
GdkScreen *screen;
const gchar *name;
guint old_position;
panel_return_if_fail (PANEL_IS_ITEMBAR (itembar));
panel_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
panel_return_if_fail (PANEL_IS_WINDOW (window));
/* get the application */
application = panel_application_get ();
/* get the drop index on the itembar */
position = panel_itembar_get_drop_index (PANEL_ITEMBAR (itembar), x, y);
/* get the widget screen */
screen = gtk_widget_get_screen (itembar);
/* TODO replace with enums */
switch (info)
{
case 0:
/* uri */
break;
case 1:
if (G_LIKELY (selection_data->length > 0))
{
/* get the name from the selection data */
name = (const gchar *) selection_data->data;
/* create a new item with a unique id */
succeed = panel_application_insert_plugin (application, window, screen, name,
NULL, FROM_DESKTOP_FILE, position);
succeed = panel_application_insert_plugin (application, window, screen, name,
NULL, NULL, FROM_DESKTOP_FILE, position);
}
break;
case 2:
/* make the itembar sensitive again */
panel_application_windows_sensitive (application, TRUE);
/* get the source widget */
provider = gtk_drag_get_source_widget (context);
/* debug check */
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
/* check if we move to another itembar */
if (gtk_widget_get_parent (provider) == itembar)
{
/* get the current position on the itembar */
old_position = panel_itembar_get_child_index (PANEL_ITEMBAR (itembar), provider);
/* decrease the counter if we drop after the current position */
if (position > old_position)
position--;
/* reorder the child if needed */
if (old_position != position)
panel_itembar_reorder_child (PANEL_ITEMBAR (itembar), provider, position);
@ -894,32 +915,32 @@ panel_application_drag_data_received (GtkWidget *itembar,
{
/* reparent the widget, this will also call remove and add for the itembar */
gtk_widget_reparent (provider, itembar);
/* move the item to the correct position on the itembar */
panel_itembar_reorder_child (PANEL_ITEMBAR (itembar), provider, position);
/* set new panel size */
xfce_panel_plugin_provider_set_size (XFCE_PANEL_PLUGIN_PROVIDER (provider), panel_window_get_size (window));
/* TODO update more here */
}
/* everything went fine */
succeed = TRUE;
break;
default:
panel_assert_not_reached ();
break;
}
/* save the panel configuration if we succeeded */
if (G_LIKELY (succeed))
panel_application_save (application);
/* release the application */
g_object_unref (G_OBJECT (application));
/* tell the peer that we handled the drop */
gtk_drag_finish (context, succeed, FALSE, time);
}
@ -935,20 +956,20 @@ panel_application_drag_drop (GtkWidget *itembar,
PanelWindow *window)
{
GdkAtom target;
panel_return_val_if_fail (PANEL_IS_ITEMBAR (itembar), FALSE);
panel_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), FALSE);
panel_return_val_if_fail (PANEL_IS_WINDOW (window), FALSE);
target = gtk_drag_dest_find_target (itembar, context, NULL);
/* we cannot handle the drag data */
if (G_UNLIKELY (target == GDK_NONE))
return FALSE;
/* request the drag data */
gtk_drag_get_data (itembar, context, target, time);
/* we call gtk_drag_finish later */
return TRUE;
}
@ -985,7 +1006,7 @@ panel_application_new_window (PanelApplication *application,
exo_binding_new (G_OBJECT (window), "orientation", G_OBJECT (itembar), "orientation");
gtk_container_add (GTK_CONTAINER (window), itembar);
gtk_widget_show (itembar);
/* signals for drag and drop */
g_signal_connect (G_OBJECT (itembar), "drag-data-received", G_CALLBACK (panel_application_drag_data_received), window);
g_signal_connect (G_OBJECT (itembar), "drag-drop", G_CALLBACK (panel_application_drag_drop), window);
@ -1021,7 +1042,7 @@ panel_application_get_window_index (PanelApplication *application,
{
panel_return_val_if_fail (PANEL_IS_APPLICATION (application), 0);
panel_return_val_if_fail (PANEL_IS_WINDOW (window), 0);
return g_slist_index (application->windows, window);
}
@ -1038,24 +1059,24 @@ panel_application_get_window (PanelApplication *application,
void
void
panel_application_windows_sensitive (PanelApplication *application,
gboolean sensitive)
{
GtkWidget *itembar;
GSList *li;
panel_return_if_fail (PANEL_IS_APPLICATION (application));
/* walk the windows */
for (li = application->windows; li != NULL; li = li->next)
{
/* get the window itembar */
itembar = gtk_bin_get_child (GTK_BIN (li->data));
/* set sensitivity of the itembar (and the plugins) */
panel_itembar_set_sensitive (PANEL_ITEMBAR (itembar), sensitive);
/* block autohide for all windows */
if (sensitive)
panel_window_thaw_autohide (PANEL_WINDOW (li->data));
@ -1066,14 +1087,14 @@ panel_application_windows_sensitive (PanelApplication *application,
void
void
panel_application_windows_autohide (PanelApplication *application,
gboolean freeze)
{
GSList *li;
panel_return_if_fail (PANEL_IS_APPLICATION (application));
for (li = application->windows; li != NULL; li = li->next)
{
if (freeze)

40
panel/panel-application.h

@ -41,29 +41,33 @@ void panel_application_multihead_area (GtkWidget *widget,
PanelApplication *panel_application_get (void);
void panel_application_save (PanelApplication *application);
void panel_application_save (PanelApplication *application);
void panel_application_take_dialog (PanelApplication *application,
GtkWindow *dialog);
void panel_application_take_dialog (PanelApplication *application,
GtkWindow *dialog);
void panel_application_destroy_dialogs (PanelApplication *application);
void panel_application_destroy_dialogs (PanelApplication *application);
PanelWindow *panel_application_new_window (PanelApplication *application,
GdkScreen *screen);
gint panel_application_get_n_windows (PanelApplication *application);
void panel_application_add_new_item (PanelApplication *application,
const gchar *plugin_name,
gchar **arguments);
gint panel_application_get_window_index (PanelApplication *application,
PanelWindow *window);
PanelWindow *panel_application_new_window (PanelApplication *application,
GdkScreen *screen);
PanelWindow *panel_application_get_window (PanelApplication *application,
guint idx);
void panel_application_windows_sensitive (PanelApplication *application,
gboolean sensitive);
void panel_application_windows_autohide (PanelApplication *application,
gboolean freeze);
gint panel_application_get_n_windows (PanelApplication *application);
gint panel_application_get_window_index (PanelApplication *application,
PanelWindow *window);
PanelWindow *panel_application_get_window (PanelApplication *application,
guint idx);
void panel_application_windows_sensitive (PanelApplication *application,
gboolean sensitive);
void panel_application_windows_autohide (PanelApplication *application,
gboolean freeze);
G_END_DECLS

34
panel/panel-dbus-client.c

@ -169,6 +169,40 @@ panel_dbus_client_save (GError **error)
gboolean
panel_dbus_client_add_new_item (const gchar *plugin_name,
gchar **arguments,
GError **error)
{
DBusMessage *message;
gboolean result;
guint length;
panel_return_val_if_fail (error == NULL || *error == NULL, FALSE);
/* arguments length */
length = arguments ? g_strv_length (arguments) : 0;
/* generate the message */
message = dbus_message_new_method_call (PANEL_DBUS_SERVICE_INTERFACE, PANEL_DBUS_SERVICE_PATH,
PANEL_DBUS_SERVICE_INTERFACE, "AddNewItem");
dbus_message_set_auto_start (message, FALSE);
dbus_message_append_args (message,
DBUS_TYPE_STRING, &plugin_name,
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &arguments, length,
DBUS_TYPE_INVALID);
/* send the message */
result = panel_dbus_client_send_message (message, error);
/* release the message */
dbus_message_unref (message);
return result;
}
gboolean
panel_dbus_client_terminate (gboolean restart,
GError **error)

18
panel/panel-dbus-client.h

@ -21,16 +21,20 @@
#include <glib.h>
#include <gdk/gdk.h>
gboolean panel_dbus_client_display_preferences_dialog (GdkScreen *screen,
GError **error);
gboolean panel_dbus_client_display_preferences_dialog (GdkScreen *screen,
GError **error);
gboolean panel_dbus_client_display_items_dialog (GdkScreen *screen,
GError **error);
gboolean panel_dbus_client_display_items_dialog (GdkScreen *screen,
GError **error);
gboolean panel_dbus_client_save (GError **error);
gboolean panel_dbus_client_save (GError **error);
gboolean panel_dbus_client_terminate (gboolean restart,
GError **error);
gboolean panel_dbus_client_add_new_item (const gchar *plugin_name,
gchar **arguments,
GError **error);
gboolean panel_dbus_client_terminate (gboolean restart,
GError **error);
G_END_DECLS

13
panel/panel-dbus-service-infos.xml

@ -48,7 +48,18 @@
Tells the panel to save its configuration, including all the plugins.
-->
<method name="Save">
<method name="Save" />
<!--
AddNewItem (name : STRING, args : ARRAY OF STRING) : VOID
plugin-name : The internal name of the plugin the user wants to add.
arguments : Optional arguments send with the command line. This
could be files or anything else.
-->
<method name="AddNewItem">
<arg name="plugin-name" direction="in" type="s" />
<arg name="arguments" direction="in" type="as" />
</method>
<!--

29
panel/panel-dbus-service.c

@ -180,6 +180,35 @@ panel_dbus_service_save (PanelDBusService *service,
static gboolean
panel_dbus_service_add_new_item (PanelDBusService *service,
const gchar *plugin_name,
gchar **arguments,
GError **error)
{
PanelApplication *application;
panel_return_val_if_fail (PANEL_IS_DBUS_SERVICE (service), FALSE);
panel_return_val_if_fail (error == NULL || *error == NULL, FALSE);
panel_return_val_if_fail (plugin_name != NULL, FALSE);
/* get the current application */
application = panel_application_get ();
/* save the configuration */
if (arguments && *arguments != NULL)
panel_application_add_new_item (application, plugin_name, arguments);
else
panel_application_add_new_item (application, plugin_name, NULL);
/* release the application */
g_object_unref (G_OBJECT (application));
return TRUE;
}
static gboolean
panel_dbus_service_terminate (PanelDBusService *service,
gboolean restart,

39
panel/panel-module-factory.c

@ -59,7 +59,7 @@ struct _PanelModuleFactory
/* table of loaded modules */
GHashTable *modules;
/* if the factory contains the launcher plugin */
guint has_launcher : 1;
};
@ -103,7 +103,7 @@ panel_module_factory_init (PanelModuleFactory *factory)
{
/* initialize */
factory->has_launcher = FALSE;
/* create hash table */
factory->modules = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
@ -187,7 +187,7 @@ panel_module_factory_load_modules (PanelModuleFactory *factory)
/* get the new module internal name */
internal_name = g_strndup (name, p - name);
/* check if the modules name is already loaded */
if (G_UNLIKELY (g_hash_table_lookup (factory->modules, internal_name) != NULL))
goto already_loaded;
@ -199,7 +199,7 @@ panel_module_factory_load_modules (PanelModuleFactory *factory)
{
/* add the module to the internal list */
g_hash_table_insert (factory->modules, internal_name, module);
/* check if this is the launcher */
if (factory->has_launcher == FALSE && exo_str_is_equal (LAUNCHER_PLUGIN_NAME, internal_name))
factory->has_launcher = TRUE;
@ -207,7 +207,7 @@ panel_module_factory_load_modules (PanelModuleFactory *factory)
else
{
already_loaded:
/* cleanup */
g_free (internal_name);
}
@ -215,7 +215,7 @@ panel_module_factory_load_modules (PanelModuleFactory *factory)
/* cleanup */
g_free (filename);
}
/* close directory */
g_dir_close (dir);
}
@ -238,17 +238,17 @@ panel_module_factory_modules_cleanup (gpointer key,
PanelModuleFactory *factory = PANEL_MODULE_FACTORY (user_data);
PanelModule *module = PANEL_MODULE (value);
gboolean remove;
panel_return_val_if_fail (PANEL_IS_MODULE (module), TRUE);
panel_return_val_if_fail (PANEL_IS_MODULE_FACTORY (factory), TRUE);
/* get whether the module is valid */
remove = !panel_module_is_valid (module);
/* if we're going to remove this item, check if it's the launcher */
if (remove == TRUE && exo_str_is_equal (LAUNCHER_PLUGIN_NAME, panel_module_get_internal_name (module)))
factory->has_launcher = FALSE;
return remove;
}
@ -280,7 +280,7 @@ gboolean
panel_module_factory_has_launcher (PanelModuleFactory *factory)
{
panel_return_val_if_fail (PANEL_IS_MODULE_FACTORY (factory), FALSE);
return factory->has_launcher;
}
@ -324,10 +324,10 @@ GList *
panel_module_factory_get_modules (PanelModuleFactory *factory)
{
panel_return_val_if_fail (PANEL_IS_MODULE_FACTORY (factory), NULL);
/* make sure the hash table is clean */
g_hash_table_foreach_remove (factory->modules, panel_module_factory_modules_cleanup, factory);
#if GLIB_CHECK_VERSION (2,14,0)
return g_hash_table_get_values (factory->modules);
#else
@ -343,11 +343,12 @@ panel_module_factory_get_modules (PanelModuleFactory *factory)
XfcePanelPluginProvider *
panel_module_factory_create_plugin (PanelModuleFactory *factory,
GdkScreen *screen,
const gchar *name,
const gchar *id,
UseWrapper use_wrapper)
panel_module_factory_create_plugin (PanelModuleFactory *factory,
GdkScreen *screen,
const gchar *name,
const gchar *id,
gchar **arguments,
UseWrapper use_wrapper)
{
PanelModule *module;
@ -367,5 +368,5 @@ panel_module_factory_create_plugin (PanelModuleFactory *factory,
}
/* create the new module */
return panel_module_create_plugin (module, screen, name, id, use_wrapper);
return panel_module_create_plugin (module, screen, name, id, arguments, use_wrapper);
}

17
panel/panel-module-factory.h

@ -41,17 +41,18 @@ GType panel_module_factory_get_type (void) G_GNUC_
PanelModuleFactory *panel_module_factory_get (void);
gboolean panel_module_factory_has_launcher (PanelModuleFactory *factory);
gboolean panel_module_factory_has_launcher (PanelModuleFactory *factory);
void panel_module_factory_emit_unique_changed (PanelModule *module);
void panel_module_factory_emit_unique_changed (PanelModule *module);
GList *panel_module_factory_get_modules (PanelModuleFactory *factory);
GList *panel_module_factory_get_modules (PanelModuleFactory *factory);
XfcePanelPluginProvider *panel_module_factory_create_plugin (PanelModuleFactory *factory,
GdkScreen *screen,
const gchar *name,
const gchar *id,
UseWrapper use_wrapper);
XfcePanelPluginProvider *panel_module_factory_create_plugin (PanelModuleFactory *factory,
GdkScreen *screen,
const gchar *name,
const gchar *id,
gchar **arguments,
UseWrapper use_wrapper);
G_END_DECLS

15
panel/panel-module.c

@ -319,11 +319,12 @@ panel_module_new_from_desktop_file (const gchar *filename,
XfcePanelPluginProvider *
panel_module_create_plugin (PanelModule *module,
GdkScreen *screen,
const gchar *name,
const gchar *id,
UseWrapper use_wrapper)
panel_module_create_plugin (PanelModule *module,
GdkScreen *screen,
const gchar *name,
const gchar *id,
gchar **arguments,
UseWrapper use_wrapper)
{
XfcePanelPluginProvider *plugin = NULL;
gboolean external;
@ -345,7 +346,7 @@ panel_module_create_plugin (PanelModule *module,
if (external)
{
/* create external plugin */
plugin = panel_plugin_external_new (module, name, id);
plugin = panel_plugin_external_new (module, name, id, arguments);
}
else
{
@ -358,7 +359,7 @@ panel_module_create_plugin (PanelModule *module,
panel_return_val_if_fail (module->construct_func != NULL, NULL);
/* create a new panel plugin */
plugin = (*module->construct_func) (name, id, module->name, screen);
plugin = (*module->construct_func) (name, id, module->name, arguments, screen);
}
else
{

31
panel/panel-module.h

@ -44,28 +44,29 @@ enum _UseWrapper
GType panel_module_get_type (void) G_GNUC_CONST;
PanelModule *panel_module_new_from_desktop_file (const gchar *filename,
const gchar *name);
PanelModule *panel_module_new_from_desktop_file (const gchar *filename,
const gchar *name);
XfcePanelPluginProvider *panel_module_create_plugin (PanelModule *module,
GdkScreen *screen,
const gchar *name,
const gchar *id,
UseWrapper use_wrapper);
const gchar *panel_module_get_internal_name (PanelModule *module);
XfcePanelPluginProvider *panel_module_create_plugin (PanelModule *module,
GdkScreen *screen,
const gchar *name,
const gchar *id,
gchar **arguments,
UseWrapper use_wrapper);
const gchar *panel_module_get_library_filename (PanelModule *module);
const gchar *panel_module_get_internal_name (PanelModule *module);
const gchar *panel_module_get_name (PanelModule *module);
const gchar *panel_module_get_library_filename (PanelModule *module);
const gchar *panel_module_get_comment (PanelModule *module);
const gchar *panel_module_get_name (PanelModule *module);
const gchar *panel_module_get_icon_name (PanelModule *module);
const gchar *panel_module_get_comment (PanelModule *module);
gboolean panel_module_is_valid (PanelModule *module);
const gchar *panel_module_get_icon_name (PanelModule *module);
gboolean panel_module_is_usable (PanelModule *module);
gboolean panel_module_is_valid (PanelModule *module);
gboolean panel_module_is_usable (PanelModule *module);
G_END_DECLS

121
panel/panel-plugin-external.c

@ -64,16 +64,16 @@ struct _PanelPluginExternalClass
struct _PanelPluginExternal
{
GtkSocket __parent__;
/* plugin information */
gchar *id;
/* the module */
PanelModule *module;
/* the plug window id */
GdkNativeWindow plug_window_id;
/* message queue */
GSList *queue;
};
@ -105,15 +105,15 @@ panel_plugin_external_class_init (PanelPluginExternalClass *klass)
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = panel_plugin_external_finalize;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
gtkwidget_class->realize = panel_plugin_external_realize;
gtkwidget_class->unrealize = panel_plugin_external_unrealize;
gtkwidget_class->client_event = panel_plugin_external_client_event;
gtksocket_class = GTK_SOCKET_CLASS (klass);
gtksocket_class->plug_removed = panel_plugin_external_plug_removed;
/* initialize the global message atom */
message_atom = panel_atom_intern ("XFCE_PANEL_PLUGIN");
}
@ -127,7 +127,7 @@ panel_plugin_external_init (PanelPluginExternal *external)
external->module = NULL;
external->plug_window_id = 0;
external->queue = NULL;
g_signal_connect (G_OBJECT (external), "notify::sensitive", G_CALLBACK (panel_plugin_external_set_sensitive), NULL);
}
@ -149,12 +149,12 @@ static void
panel_plugin_external_finalize (GObject *object)
{
PanelPluginExternal *external = PANEL_PLUGIN_EXTERNAL (object);
panel_return_if_fail (external->queue == NULL);
/* cleanup */
g_free (external->id);
/* release the module */
g_object_unref (G_OBJECT (external->module));
@ -172,13 +172,13 @@ panel_plugin_external_realize (GtkWidget *widget)
GError *error = NULL;
gboolean succeed;
gchar *socket_id;
/* realize the socket first */
(*GTK_WIDGET_CLASS (panel_plugin_external_parent_class)->realize) (widget);
/* get the socket id in a string */
socket_id = g_strdup_printf ("%d", gtk_socket_get_id (GTK_SOCKET (widget)));
/* construct the argv */
argv[0] = LIBEXECDIR "/xfce4-panel-wrapper";
argv[1] = "-n";
@ -192,19 +192,19 @@ panel_plugin_external_realize (GtkWidget *widget)
argv[9] = "-s";
argv[10] = socket_id;
argv[11] = NULL;
/* spawn the proccess */
succeed = gdk_spawn_on_screen (gdk_screen_get_default (), NULL, argv, NULL, 0, NULL, NULL, &pid, &error);
/* cleanup */
g_free (socket_id);
/* handle problem */
if (G_UNLIKELY (succeed == FALSE))
{
/* show warnings */
g_critical ("Failed to spawn the xfce4-panel-wrapped: %s", error->message);
/* cleanup */
g_error_free (error);
}
@ -212,17 +212,17 @@ panel_plugin_external_realize (GtkWidget *widget)
static void
static void
panel_plugin_external_unrealize (GtkWidget *widget)
{
PanelPluginExternal *external = PANEL_PLUGIN_EXTERNAL (widget);
/* send message to quit the wrapper */
panel_plugin_external_send_message (PANEL_PLUGIN_EXTERNAL (external), MESSAGE_QUIT, 0);
/* don't send or queue messages */
external->plug_window_id = -1;
return (*GTK_WIDGET_CLASS (panel_plugin_external_parent_class)->unrealize) (widget);
}
@ -235,57 +235,57 @@ panel_plugin_external_client_event (GtkWidget *widget,
PanelPluginExternal *external = PANEL_PLUGIN_EXTERNAL (widget);
XfcePanelPluginMessage message;
glong value;
panel_return_val_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (widget), FALSE);
/* check if this even is for us */
if (G_LIKELY (event->message_type == message_atom))
{
/* get the event message and value */
message = event->data.l[0];
value = event->data.l[1];
/* handle the message */
switch (message)
{
case MESSAGE_EXPAND_CHANGED:
g_signal_emit_by_name (G_OBJECT (external), "expand-changed", !!(value == 1));
break;
case MESSAGE_MOVE_ITEM:
g_signal_emit_by_name (G_OBJECT (external), "move-item", 0);
break;
case MESSAGE_ADD_NEW_ITEMS:
g_signal_emit_by_name (G_OBJECT (external), "add-new-items", 0);
break;
case MESSAGE_CUSTOMIZE_PANEL:
g_signal_emit_by_name (G_OBJECT (external), "customize-panel", 0);
break;
case MESSAGE_REMOVE:
/* plugin properly removed, destroy the socket */
gtk_widget_destroy (widget);
break;
case MESSAGE_SET_PLUG_ID:
/* set the plug window id */
external->plug_window_id = value;