Browse Source

Add support GTypeModule type support to the wrapper.

upstream/xfce4-panel-4.10.1
Nick Schermer 13 years ago
parent
commit
c97ac6af62
  1. 6
      panel/main.c
  2. 2
      panel/panel-application.c
  3. 17
      panel/panel-module.c
  4. 46
      panel/panel-plugin-external.c
  5. 2
      plugins/clock/clock.c
  6. 2
      wrapper/Makefile.am
  7. 81
      wrapper/main.c
  8. 203
      wrapper/wrapper-module.c
  9. 50
      wrapper/wrapper-module.h

6
panel/main.c

@ -44,7 +44,7 @@ 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;
static gchar **opt_arguments = NULL;
@ -59,7 +59,7 @@ static const GOptionEntry option_entries[] =
{ "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 },
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &opt_arguments, NULL, NULL },
{ NULL }
};
@ -145,7 +145,7 @@ main (gint argc, gchar **argv)
gdk_notify_startup_complete ();
/* send a add new item signal to the running instance */
result = panel_dbus_client_add_new_item (opt_add, arguments, &error);
result = panel_dbus_client_add_new_item (opt_add, opt_arguments, &error);
goto dbus_return;
}

2
panel/panel-application.c

@ -842,7 +842,7 @@ panel_application_add_new_item (PanelApplication *application,
/* add the panel to the end of the choosen window */
panel_application_insert_plugin (application, window, gtk_widget_get_screen (GTK_WIDGET (window)),
plugin_name, NULL, arguments, FROM_DESKTOP_FILE, -1);
plugin_name, NULL, arguments, /* FROM_DESKTOP_FILE */ FORCE_EXTERNAL, -1);
}
else
{

17
panel/panel-module.c

@ -151,8 +151,8 @@ panel_module_finalize (GObject *object)
static gboolean
panel_module_load (GTypeModule *type_module)
{
PanelModule *module = PANEL_MODULE (type_module);
PluginRegisterTypesFunc register_func;
PanelModule *module = PANEL_MODULE (type_module);
PluginRegisterTypesFunc register_func;
panel_return_val_if_fail (PANEL_IS_MODULE (module), FALSE);
panel_return_val_if_fail (G_IS_TYPE_MODULE (module), FALSE);
@ -177,7 +177,7 @@ panel_module_load (GTypeModule *type_module)
return FALSE;
}
/* run the register function if available */
/* run the type register function if available */
if (g_module_symbol (module->library, "xfce_panel_plugin_register_types", (gpointer) &register_func))
(*register_func) (type_module);
@ -219,8 +219,9 @@ panel_module_item_finalized (gpointer user_data,
module->use_count--;
/* unuse the library if the plugin runs internal */
if (!xfce_panel_plugin_provider_is_external (XFCE_PANEL_PLUGIN_PROVIDER (item)))
g_type_module_unuse (G_TYPE_MODULE (module));
/* TODO this needs to be fixed */
//if (!xfce_panel_plugin_provider_is_external (XFCE_PANEL_PLUGIN_PROVIDER (item)))
// g_type_module_unuse (G_TYPE_MODULE (module));
/* emit signal unique signal in the factory */
if (module->is_unique)
@ -258,7 +259,7 @@ panel_module_new_from_desktop_file (const gchar *filename,
/* build the module path */
path = g_module_build_path (directory, module_name);
/* test if the module exists */
/* test if the library exists */
if (G_LIKELY (g_file_test (path, G_FILE_TEST_EXISTS)))
{
/* create new module */
@ -332,8 +333,8 @@ panel_module_create_plugin (PanelModule *module,
panel_return_val_if_fail (PANEL_IS_MODULE (module), NULL);
panel_return_val_if_fail (G_IS_TYPE_MODULE (module), NULL);
panel_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
panel_return_val_if_fail (name != NULL, NULL);
panel_return_val_if_fail (id != NULL, NULL);
panel_return_val_if_fail (name != NULL && *name != '\0', NULL);
panel_return_val_if_fail (id != NULL && *id != '\0', NULL);
panel_return_val_if_fail (exo_str_is_equal (name, G_TYPE_MODULE (module)->name), NULL);
/* return null if the module is not usable (unique and already used) */

46
panel/panel-plugin-external.c

@ -66,16 +66,19 @@ struct _PanelPluginExternal
GtkSocket __parent__;
/* plugin information */
gchar *id;
gchar *id;
/* startup arguments */
gchar **arguments;
/* the module */
PanelModule *module;
PanelModule *module;
/* the plug window id */
GdkNativeWindow plug_window_id;
GdkNativeWindow plug_window_id;
/* message queue */
GSList *queue;
GSList *queue;
};
typedef struct
@ -127,6 +130,7 @@ panel_plugin_external_init (PanelPluginExternal *external)
external->module = NULL;
external->plug_window_id = 0;
external->queue = NULL;
external->arguments = NULL;
g_signal_connect (G_OBJECT (external), "notify::sensitive", G_CALLBACK (panel_plugin_external_set_sensitive), NULL);
}
@ -154,6 +158,7 @@ panel_plugin_external_finalize (GObject *object)
/* cleanup */
g_free (external->id);
g_strfreev (external->arguments);
/* release the module */
g_object_unref (G_OBJECT (external->module));
@ -166,12 +171,13 @@ panel_plugin_external_finalize (GObject *object)
static void
panel_plugin_external_realize (GtkWidget *widget)
{
PanelPluginExternal *external = PANEL_PLUGIN_EXTERNAL (widget);
gchar *argv[12];
GPid pid;
GError *error = NULL;
gboolean succeed;
gchar *socket_id;
PanelPluginExternal *external = PANEL_PLUGIN_EXTERNAL (widget);
gchar **argv;
GPid pid;
GError *error = NULL;
gboolean succeed;
gchar *socket_id;
gint i, argc = 12;
/* realize the socket first */
(*GTK_WIDGET_CLASS (panel_plugin_external_parent_class)->realize) (widget);
@ -179,7 +185,14 @@ panel_plugin_external_realize (GtkWidget *widget)
/* get the socket id in a string */
socket_id = g_strdup_printf ("%d", gtk_socket_get_id (GTK_SOCKET (widget)));
/* construct the argv */
/* add the number of arguments to the argv count */
if (G_UNLIKELY (external->arguments != NULL))
argc += g_strv_length (external->arguments);
/* allocate argv */
argv = g_new0 (gchar *, argc);
/* setup the basic argv */
argv[0] = LIBEXECDIR "/xfce4-panel-wrapper";
argv[1] = "-n";
argv[2] = (gchar *) panel_module_get_internal_name (external->module);
@ -191,13 +204,21 @@ panel_plugin_external_realize (GtkWidget *widget)
argv[8] = (gchar *) panel_module_get_library_filename (external->module);
argv[9] = "-s";
argv[10] = socket_id;
argv[11] = NULL;
/* append the arguments */
if (G_UNLIKELY (external->arguments != NULL))
for (i = 0; external->arguments[i] != NULL; i++)
argv[i + 11] = external->arguments[i];
/* close the argv */
argv[argc - 1] = 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);
g_free (argv);
/* handle problem */
if (G_UNLIKELY (succeed == FALSE))
@ -475,6 +496,7 @@ panel_plugin_external_new (PanelModule *module,
/* set name, id and module */
external->id = g_strdup (id);
external->module = g_object_ref (G_OBJECT (module));
external->arguments = g_strdupv (arguments);
return XFCE_PANEL_PLUGIN_PROVIDER (external);
}

2
plugins/clock/clock.c

@ -728,6 +728,8 @@ xfce_clock_widget_update_mode (XfceClock *clock)
G_MODULE_EXPORT void
xfce_panel_plugin_register_types (XfcePanelModule *panel_module)
{
panel_return_if_fail (G_IS_TYPE_MODULE (panel_module));
/* register the types */
xfce_clock_register_type (panel_module);
xfce_clock_analog_register_type (panel_module);

2
wrapper/Makefile.am

@ -16,6 +16,8 @@ libexec_PROGRAMS = \
xfce4_panel_wrapper_SOURCES = \
main.c \
wrapper-module.c \
wrapper-module.h \
wrapper-plug.c \
wrapper-plug.h

81
wrapper/main.c

@ -27,20 +27,21 @@
#endif
#include <gtk/gtk.h>
#include <gmodule.h>
#include <libxfce4util/libxfce4util.h>
#include <libxfce4panel/libxfce4panel.h>
#include <libxfce4panel/xfce-panel-plugin-provider.h>
#include <wrapper/wrapper-module.h>
#include <wrapper/wrapper-plug.h>
static gchar *opt_name = NULL;
static gchar *opt_display_name = NULL;
static gchar *opt_id = NULL;
static gchar *opt_filename = NULL;
static gint opt_socket_id = 0;
static gchar *opt_name = NULL;
static gchar *opt_display_name = NULL;
static gchar *opt_id = NULL;
static gchar *opt_filename = NULL;
static gint opt_socket_id = 0;
static gchar **opt_arguments = NULL;
@ -51,6 +52,7 @@ static const GOptionEntry option_entries[] =
{ "id", 'i', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_id, NULL, NULL },
{ "filename", 'f', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_filename, NULL, NULL },
{ "socket-id", 's', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &opt_socket_id, NULL, NULL },
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &opt_arguments, NULL, NULL },
{ NULL }
};
@ -60,10 +62,10 @@ gint
main (gint argc, gchar **argv)
{
GError *error = NULL;
GModule *library;
PluginConstructFunc construct_func;
XfcePanelPluginProvider *provider = NULL;
XfcePanelPluginProvider *provider;
GtkWidget *plug;
WrapperModule *module;
gboolean succeed = FALSE;
/* set translation domain */
xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
@ -76,7 +78,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 error */
g_critical ("Failed to initialize GTK+: %s", error ? error->message : "Unable to open display");
@ -90,7 +92,7 @@ main (gint argc, gchar **argv)
}
/* check arguments */
if (opt_filename == NULL || opt_socket_id == 0 || opt_name == NULL || opt_id == NULL)
if (opt_filename == NULL || opt_socket_id == 0 || opt_name == NULL || opt_id == NULL || opt_display_name == NULL)
{
/* print error */
g_critical ("One of the required arguments for the wrapper is missing");
@ -99,43 +101,38 @@ main (gint argc, gchar **argv)
return EXIT_FAILURE;
}
/* try to open the library */
library = g_module_open (opt_filename, 0);
if (G_LIKELY (library != NULL))
/* try to create a wrapper module */
module = wrapper_module_new (opt_filename, opt_name);
if (G_LIKELY (module != NULL))
{
/* try to ling the plugin init func */
if (g_module_symbol (library, "xfce_panel_plugin_init", (gpointer) &construct_func))
/* try to create the panel plugin */
provider = wrapper_module_create_plugin (module, opt_name, opt_id, opt_display_name, opt_arguments);
if (G_LIKELY (provider != NULL))
{
/* create the panel plugin */
provider = (*construct_func) (opt_name, opt_id, NULL, NULL, gdk_screen_get_default ());
}
else
{
/* print warning */
g_critical ("Plugin '%s' lacks required symbol: %s", opt_display_name, g_module_error ());
}
}
/* create the plug */
plug = wrapper_plug_new (opt_socket_id, provider);
gtk_container_add (GTK_CONTAINER (plug), GTK_WIDGET (provider));
gtk_widget_show (plug);
if (G_LIKELY (provider != NULL))
{
/* create the plug */
plug = wrapper_plug_new (opt_socket_id, provider);
gtk_container_add (GTK_CONTAINER (plug), GTK_WIDGET (provider));
gtk_widget_show (plug);
/* show the plugin */
gtk_widget_show (GTK_WIDGET (provider));
/* show the plugin */
gtk_widget_show (GTK_WIDGET (provider));
/* everything worked fine */
succeed = TRUE;
/* enter the mainloop */
gtk_main ();
/* enter the mainloop */
gtk_main ();
/* destroy the plug (and provider) */
gtk_widget_destroy (plug);
}
/* destroy the plug (and provider) */
gtk_widget_destroy (plug);
/* decrease the module use count */
g_type_module_unuse (G_TYPE_MODULE (module));
}
/* close the library */
if (G_LIKELY (library != NULL))
g_module_close (library);
/* g_object_unref for the module doesn't work,
* so we don't do that... */
}
return EXIT_SUCCESS;
return succeed ? EXIT_SUCCESS : EXIT_FAILURE;
}

203
wrapper/wrapper-module.c

@ -0,0 +1,203 @@
/* $Id$ */
/*
* This program 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 program 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 General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gdk/gdk.h>
#include <gmodule.h>
#include <libxfce4util/libxfce4util.h>
#include <libxfce4panel/libxfce4panel.h>
#include <libxfce4panel/xfce-panel-plugin-provider.h>
#include <wrapper/wrapper-module.h>
static void wrapper_module_class_init (WrapperModuleClass *klass);
static void wrapper_module_init (WrapperModule *module);
static gboolean wrapper_module_load (GTypeModule *type_module);
static void wrapper_module_unload (GTypeModule *type_module);
struct _WrapperModuleClass
{
GTypeModuleClass __parent__;
};
struct _WrapperModule
{
GTypeModule __parent__;
/* plugin library */
GModule *library;
/* plugin init function */
PluginConstructFunc construct_func;
/* the library location */
const gchar *filename;
};
G_DEFINE_TYPE (WrapperModule, wrapper_module, G_TYPE_TYPE_MODULE);
static void
wrapper_module_class_init (WrapperModuleClass *klass)
{
GTypeModuleClass *gtype_module_class;
gtype_module_class = G_TYPE_MODULE_CLASS (klass);
gtype_module_class->load = wrapper_module_load;
gtype_module_class->unload = wrapper_module_unload;
}
static void
wrapper_module_init (WrapperModule *module)
{
/* initialize */
module->library = NULL;
module->construct_func = NULL;
module->filename = NULL;
}
static gboolean
wrapper_module_load (GTypeModule *type_module)
{
WrapperModule *module = WRAPPER_MODULE (type_module);
PluginRegisterTypesFunc register_func;
panel_return_val_if_fail (WRAPPER_IS_MODULE (module), FALSE);
panel_return_val_if_fail (G_IS_TYPE_MODULE (module), FALSE);
/* load the module */
module->library = g_module_open (module->filename, G_MODULE_BIND_LOCAL);
if (G_UNLIKELY (module->library == NULL))
{
g_critical ("Failed to load plugin '%s': %s", type_module->name, g_module_error ());
return FALSE;
}
/* link the required construct function */
if (!g_module_symbol (module->library, "xfce_panel_plugin_construct", (gpointer) &module->construct_func))
{
g_critical ("Plugin '%s' lacks required symbol: %s", type_module->name, g_module_error ());
/* unload */
wrapper_module_unload (type_module);
return FALSE;
}
/* run the type register function if available */
if (g_module_symbol (module->library, "xfce_panel_plugin_register_types", (gpointer) &register_func))
(*register_func) (type_module);
return TRUE;
}
static void
wrapper_module_unload (GTypeModule *type_module)
{
WrapperModule *module = WRAPPER_MODULE (type_module);
panel_return_if_fail (WRAPPER_IS_MODULE (module));
panel_return_if_fail (G_IS_TYPE_MODULE (module));
/* unload the library */
g_module_close (module->library);
/* reset plugin state */
module->library = NULL;
module->construct_func = NULL;
}
WrapperModule *
wrapper_module_new (const gchar *filename,
const gchar *name)
{
WrapperModule *module = NULL;
panel_return_val_if_fail (filename != NULL && *filename != '\0', NULL);
/* test if the library exists */
if (G_LIKELY (g_file_test (filename, G_FILE_TEST_EXISTS)))
{
/* create new module */
module = g_object_new (WRAPPER_TYPE_MODULE, NULL);
/* set the module name */
g_type_module_set_name (G_TYPE_MODULE (module), name);
/* set library location */
module->filename = filename;
}
return module;
}
XfcePanelPluginProvider *
wrapper_module_create_plugin (WrapperModule *module,
const gchar *name,
const gchar *id,
const gchar *display_name,
gchar **arguments)
{
XfcePanelPluginProvider *provider = NULL;
panel_return_val_if_fail (WRAPPER_IS_MODULE (module), NULL);
panel_return_val_if_fail (name != NULL && *name != '\0', NULL);
panel_return_val_if_fail (id != NULL && *id != '\0', NULL);
/* increase the module use count */
g_type_module_use (G_TYPE_MODULE (module));
if (G_LIKELY (module->library))
{
/* debug check */
panel_return_val_if_fail (module->construct_func != NULL, NULL);
/* create a new panel plugin */
provider = (*module->construct_func) (name, id, display_name, arguments, gdk_screen_get_default ());
}
else
{
/* decrease the module use count */
g_type_module_unuse (G_TYPE_MODULE (module));
/* this should never happen */
panel_assert_not_reached ();
}
return provider;
}

50
wrapper/wrapper-module.h

@ -0,0 +1,50 @@
/* $Id$ */
/*
* This program 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 program 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 General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WRAPPER_MODULE_H__
#define __WRAPPER_MODULE_H__
#include <gtk/gtk.h>
#include <libxfce4panel/libxfce4panel.h>
#include <libxfce4panel/xfce-panel-plugin-provider.h>
G_BEGIN_DECLS
typedef struct _WrapperModuleClass WrapperModuleClass;
typedef struct _WrapperModule WrapperModule;
#define WRAPPER_TYPE_MODULE (wrapper_module_get_type ())
#define WRAPPER_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WRAPPER_TYPE_MODULE, WrapperModule))
#define WRAPPER_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WRAPPER_TYPE_MODULE, WrapperModuleClass))
#define WRAPPER_IS_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WRAPPER_TYPE_MODULE))
#define WRAPPER_IS_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WRAPPER_TYPE_MODULE))
#define WRAPPER_MODULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WRAPPER_TYPE_MODULE, WrapperModuleClass))
GType wrapper_module_get_type (void) G_GNUC_CONST;
WrapperModule *wrapper_module_new (const gchar *filename,
const gchar *name);
XfcePanelPluginProvider *wrapper_module_create_plugin (WrapperModule *module,
const gchar *name,
const gchar *id,
const gchar *display_name,
gchar **arguments);
G_END_DECLS
#endif /* !__WRAPPER_MODULE_H__ */
Loading…
Cancel
Save