Remove Mono and Python EPlugin bindings.
EPlugin is deprecated. These bindings have never been used for anything and they're never going to be used at this point. Remove the dead weight.
This commit is contained in:
62
configure.ac
62
configure.ac
@ -721,64 +721,6 @@ dnl Kerberos 5
|
||||
dnl ************
|
||||
EVO_KRB5_SUPPORT(no)
|
||||
|
||||
dnl ******************************
|
||||
dnl Mono hooks
|
||||
dnl This should just define mono CFLAGS etc here, it is used later to turn on the mono plugin or not.
|
||||
dnl ******************************
|
||||
AC_ARG_ENABLE([mono],
|
||||
AS_HELP_STRING([--enable-mono],
|
||||
[Add Mono embedded hooks.]),
|
||||
[enable_mono=$enableval],[enable_mono=no])
|
||||
if test "x${enable_mono}" = "xyes"; then
|
||||
PKG_CHECK_MODULES([MONO], ["mono-2"])
|
||||
AC_DEFINE(ENABLE_MONO,1,[Define if Mono embedding should be enabled])
|
||||
fi
|
||||
AC_SUBST(MONO_CFLAGS)
|
||||
AC_SUBST(MONO_LIBS)
|
||||
|
||||
AM_CONDITIONAL(ENABLE_MONO, [test "x$enable_mono" = "xyes"])
|
||||
|
||||
dnl ******************************
|
||||
dnl Python hooks
|
||||
dnl This should just define python CFLAGS etc here, it is used later to turn on the python plugin or not.
|
||||
dnl (Thanks to Pidgin)
|
||||
dnl ******************************
|
||||
|
||||
AC_ARG_ENABLE([python],
|
||||
AS_HELP_STRING([--enable-python],
|
||||
[Add python embedded hooks.]),
|
||||
[enable_python=$enableval],[enable_python=no])
|
||||
|
||||
if test "x${enable_python}" = "xyes"; then
|
||||
AC_PATH_PROG(pythonpath, python)
|
||||
if test "_$pythonpath" != _ ; then
|
||||
AC_MSG_CHECKING([for python compile flags])
|
||||
PY_PREFIX=`$pythonpath -c 'import sys ; print sys.prefix'`
|
||||
PY_EXEC_PREFIX=`$pythonpath -c 'import sys ; print sys.exec_prefix'`
|
||||
changequote(<<, >>)dnl
|
||||
PY_VERSION=`$pythonpath -c 'import sys ; print sys.version[0:3]'`
|
||||
PY_MAJOR=`$pythonpath -c 'import sys ; print sys.version[0:2]'`
|
||||
changequote([, ])dnl
|
||||
|
||||
if test -f $PY_PREFIX/include/python$PY_VERSION/Python.h -a "$PY_MAJOR" = "2."; then
|
||||
PY_LIBS="-lpython$PY_VERSION -L$PY_EXEC_PREFIX/lib/python$PY_VERSION/config"
|
||||
PY_INCLUDES="-I$PY_PREFIX/include/python$PY_VERSION"
|
||||
AC_MSG_RESULT([ok])
|
||||
python_package="python-devel"
|
||||
else
|
||||
AC_MSG_ERROR([Can't find Python.h])
|
||||
PY_LIBS=""
|
||||
PY_INCLUDES=""
|
||||
python_package=""
|
||||
fi
|
||||
fi
|
||||
AC_SUBST(PY_LIBS)
|
||||
AC_SUBST(PY_INCLUDES)
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(ENABLE_PYTHON, [test "x$enable_python" = "xyes"])
|
||||
|
||||
|
||||
dnl ********************************************************************************
|
||||
dnl security extension support (SSL and S/MIME)
|
||||
dnl
|
||||
@ -1628,8 +1570,6 @@ modules/online-accounts/Makefile
|
||||
modules/offline-alert/Makefile
|
||||
modules/plugin-lib/Makefile
|
||||
modules/plugin-manager/Makefile
|
||||
modules/plugin-mono/Makefile
|
||||
modules/plugin-python/Makefile
|
||||
modules/prefer-plain/Makefile
|
||||
modules/prefer-plain/plugin/Makefile
|
||||
modules/spamassassin/Makefile
|
||||
@ -1689,6 +1629,4 @@ echo "
|
||||
SMIME support: $msg_smime
|
||||
Plugins: $msg_plugins
|
||||
User documentation: $with_help
|
||||
Mono bindings: $enable_mono
|
||||
Python bindings: $enable_python
|
||||
"
|
||||
|
||||
@ -6,14 +6,6 @@ if ENABLE_WEATHER
|
||||
CONFIG_WEATHER_DIR = cal-config-weather
|
||||
endif
|
||||
|
||||
if ENABLE_MONO
|
||||
MONO_DIR = plugin-mono
|
||||
endif
|
||||
|
||||
if ENABLE_PYTHON
|
||||
PYTHON_DIR = plugin-python
|
||||
endif
|
||||
|
||||
if ENABLE_ONLINE_ACCOUNTS
|
||||
ONLINE_ACCOUNTS_DIR = online-accounts
|
||||
endif
|
||||
@ -57,8 +49,6 @@ SUBDIRS = \
|
||||
text-highlight \
|
||||
vcard-inline \
|
||||
web-inspector \
|
||||
$(MONO_DIR) \
|
||||
$(PYTHON_DIR) \
|
||||
$(ONLINE_ACCOUNTS_DIR) \
|
||||
$(TNEF_ATTACHMENT_DIR) \
|
||||
$(AUDIO_INLINE_DIR)
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
module_LTLIBRARIES = module-plugin-mono.la
|
||||
|
||||
module_plugin_mono_la_CPPFLAGS = \
|
||||
$(AM_CPPFLAGS) \
|
||||
-DG_LOG_DOMAIN=\"evolution-plugin-mono\" \
|
||||
-I$(top_srcdir) \
|
||||
$(EVOLUTION_DATA_SERVER_CFLAGS) \
|
||||
$(MONO_CFLAGS)
|
||||
|
||||
module_plugin_mono_la_SOURCES = \
|
||||
evolution-module-plugin-mono.c \
|
||||
e-plugin-mono.c \
|
||||
e-plugin-mono.h
|
||||
|
||||
module_plugin_mono_la_LIBADD = \
|
||||
$(top_builddir)/e-util/libeutil.la \
|
||||
$(EVOLUTION_DATA_SERVER_LIBS) \
|
||||
$(MONO_LIBS)
|
||||
|
||||
module_plugin_mono_la_LDFLAGS = \
|
||||
-module -avoid-version $(NO_UNDEFINED)
|
||||
|
||||
-include $(top_srcdir)/git.mk
|
||||
@ -1,275 +0,0 @@
|
||||
/*
|
||||
* e-plugin-mono.c
|
||||
*
|
||||
* This program 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 of the License, or (at your option) version 3.
|
||||
*
|
||||
* 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with the program; if not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "e-plugin-mono.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "e-plugin-mono.h"
|
||||
|
||||
#include <mono/metadata/debug-helpers.h>
|
||||
#include <mono/metadata/object.h>
|
||||
#include <mono/metadata/appdomain.h>
|
||||
#include <mono/metadata/assembly.h>
|
||||
#include <mono/metadata/threads.h>
|
||||
#include <mono/metadata/mono-config.h>
|
||||
#include <mono/jit/jit.h>
|
||||
|
||||
#define E_PLUGIN_MONO_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE \
|
||||
((obj), E_TYPE_PLUGIN_MONO, EPluginMonoPrivate))
|
||||
|
||||
struct _EPluginMonoPrivate {
|
||||
MonoAssembly *assembly;
|
||||
MonoClass *class;
|
||||
MonoObject *plugin;
|
||||
GHashTable *methods;
|
||||
};
|
||||
|
||||
static MonoDomain *domain;
|
||||
static gpointer parent_class;
|
||||
static GType plugin_mono_type;
|
||||
|
||||
static gchar *
|
||||
get_xml_prop (xmlNodePtr node,
|
||||
const gchar *id)
|
||||
{
|
||||
xmlChar *prop;
|
||||
gchar *out = NULL;
|
||||
|
||||
prop = xmlGetProp (node, (xmlChar *) id);
|
||||
|
||||
if (prop != NULL) {
|
||||
out = g_strdup ((gchar *) prop);
|
||||
xmlFree (prop);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
static void
|
||||
plugin_mono_finalize (GObject *object)
|
||||
{
|
||||
EPluginMono *plugin_mono;
|
||||
|
||||
plugin_mono = E_PLUGIN_MONO (object);
|
||||
|
||||
g_free (plugin_mono->location);
|
||||
g_free (plugin_mono->handler);
|
||||
|
||||
g_hash_table_destroy (plugin_mono->priv->methods);
|
||||
|
||||
/* Chain up to parent's finalize() method. */
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static gint
|
||||
plugin_mono_construct (EPlugin *plugin,
|
||||
xmlNodePtr root)
|
||||
{
|
||||
EPluginMono *plugin_mono;
|
||||
|
||||
/* Chain up to parent's construct() method. */
|
||||
if (E_PLUGIN_CLASS (parent_class)->construct (plugin, root) == -1)
|
||||
return -1;
|
||||
|
||||
plugin_mono = E_PLUGIN_MONO (plugin);
|
||||
plugin_mono->location = get_xml_prop (root, "location");
|
||||
plugin_mono->handler = get_xml_prop (root, "handler");
|
||||
|
||||
return (plugin_mono->location != NULL) ? 0 : -1;
|
||||
}
|
||||
|
||||
/*
|
||||
Two approaches:
|
||||
* You can have a Evolution.Plugin implementation which has every
|
||||
* callback as methods on it. Or you can just use static methods
|
||||
* for everything.
|
||||
*
|
||||
* All methods take a single (structured) argument.
|
||||
*/
|
||||
|
||||
static gpointer
|
||||
plugin_mono_invoke (EPlugin *plugin,
|
||||
const gchar *name,
|
||||
gpointer data)
|
||||
{
|
||||
EPluginMono *plugin_mono;
|
||||
EPluginMonoPrivate *priv;
|
||||
MonoMethodDesc *d;
|
||||
MonoMethod *m;
|
||||
MonoObject *x = NULL, *res;
|
||||
gpointer *params;
|
||||
|
||||
plugin_mono = E_PLUGIN_MONO (plugin);
|
||||
priv = plugin_mono->priv;
|
||||
|
||||
if (!domain) {
|
||||
mono_config_parse (NULL);
|
||||
domain = mono_jit_init (plugin_mono->location);
|
||||
}
|
||||
|
||||
/* We need to do this every time since we may
|
||||
* be called from any thread for some uses. */
|
||||
mono_thread_attach (domain);
|
||||
|
||||
if (priv->assembly == NULL) {
|
||||
priv->assembly = mono_domain_assembly_open (
|
||||
domain, plugin_mono->location);
|
||||
if (priv->assembly == NULL) {
|
||||
g_warning (
|
||||
"Can't load assembly '%s'",
|
||||
plugin_mono->location);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (plugin_mono->handler == NULL
|
||||
|| (priv->class = mono_class_from_name (
|
||||
mono_assembly_get_image (priv->assembly),
|
||||
"", plugin_mono->handler)) == NULL) {
|
||||
} else {
|
||||
priv->plugin = mono_object_new (domain, priv->class);
|
||||
/* could conceivably init with some context too */
|
||||
mono_runtime_object_init (priv->plugin);
|
||||
}
|
||||
}
|
||||
|
||||
m = g_hash_table_lookup (priv->methods, name);
|
||||
if (m == NULL) {
|
||||
if (priv->class) {
|
||||
/* class method */
|
||||
MonoMethod * mono_method;
|
||||
gpointer iter = NULL;
|
||||
|
||||
d = mono_method_desc_new (name, FALSE);
|
||||
/*if (d == NULL) {
|
||||
g_warning ("Can't create method descriptor for '%s'", name);
|
||||
return NULL;
|
||||
}*/
|
||||
|
||||
while ((mono_method = mono_class_get_methods (priv->class, &iter))) {
|
||||
g_print (
|
||||
"\n\a Method name is : <%s>\n\a",
|
||||
mono_method_get_name (mono_method));
|
||||
}
|
||||
//mono_class_get_method_from_name
|
||||
m = mono_class_get_method_from_name (priv->class, name, -1);
|
||||
if (m == NULL) {
|
||||
g_warning ("Can't find method callback '%s'", name);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
/* static method */
|
||||
d = mono_method_desc_new (name, FALSE);
|
||||
if (d == NULL) {
|
||||
g_warning ("Can't create method descriptor for '%s'", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
m = mono_method_desc_search_in_image (
|
||||
d, mono_assembly_get_image (priv->assembly));
|
||||
if (m == NULL) {
|
||||
g_warning ("Can't find method callback '%s'", name);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
g_hash_table_insert (priv->methods, g_strdup (name), m);
|
||||
}
|
||||
|
||||
params = g_malloc0 (sizeof (*params) * 1);
|
||||
params[0] = &data;
|
||||
res = mono_runtime_invoke (m, priv->plugin, params, &x);
|
||||
/* do i need to free params?? */
|
||||
|
||||
if (x)
|
||||
mono_print_unhandled_exception (x);
|
||||
|
||||
if (res) {
|
||||
gpointer *p = mono_object_unbox (res);
|
||||
return *p;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
plugin_mono_class_init (EPluginMonoClass *class)
|
||||
{
|
||||
GObjectClass *object_class;
|
||||
EPluginClass *plugin_class;
|
||||
|
||||
parent_class = g_type_class_peek_parent (class);
|
||||
g_type_class_add_private (class, sizeof (EPluginMonoPrivate));
|
||||
|
||||
object_class = G_OBJECT_CLASS (class);
|
||||
object_class->finalize = plugin_mono_finalize;
|
||||
|
||||
plugin_class = E_PLUGIN_CLASS (class);
|
||||
plugin_class->construct = plugin_mono_construct;
|
||||
plugin_class->invoke = plugin_mono_invoke;
|
||||
plugin_class->type = "mono";
|
||||
}
|
||||
|
||||
static void
|
||||
plugin_mono_init (EPluginMono *plugin_mono)
|
||||
{
|
||||
GHashTable *methods;
|
||||
|
||||
methods = g_hash_table_new_full (
|
||||
g_str_hash, g_str_equal,
|
||||
(GDestroyNotify) g_free,
|
||||
(GDestroyNotify) NULL);
|
||||
|
||||
plugin_mono->priv = E_PLUGIN_MONO_GET_PRIVATE (plugin_mono);
|
||||
plugin_mono->priv->methods = methods;
|
||||
}
|
||||
|
||||
GType
|
||||
e_plugin_mono_get_type (void)
|
||||
{
|
||||
return plugin_mono_type;
|
||||
}
|
||||
|
||||
void
|
||||
e_plugin_mono_register_type (GTypeModule *type_module)
|
||||
{
|
||||
static const GTypeInfo type_info = {
|
||||
sizeof (EPluginMonoClass),
|
||||
(GBaseInitFunc) NULL,
|
||||
(GBaseFinalizeFunc) NULL,
|
||||
(GClassInitFunc) plugin_mono_class_init,
|
||||
(GClassFinalizeFunc) NULL,
|
||||
NULL, /* class_data */
|
||||
sizeof (EPluginMono),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) plugin_mono_init,
|
||||
NULL /* value_table */
|
||||
};
|
||||
|
||||
plugin_mono_type = g_type_module_register_type (
|
||||
type_module, E_TYPE_PLUGIN,
|
||||
"EPluginMono", &type_info, 0);
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* e-plugin-mono.h
|
||||
*
|
||||
* This program 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 of the License, or (at your option) version 3.
|
||||
*
|
||||
* 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with the program; if not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef E_PLUGIN_MONO_H
|
||||
#define E_PLUGIN_MONO_H
|
||||
|
||||
#include <e-util/e-plugin.h>
|
||||
|
||||
/* Standard GObject macros */
|
||||
#define E_TYPE_PLUGIN_MONO \
|
||||
(e_plugin_mono_get_type ())
|
||||
#define E_PLUGIN_MONO(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST \
|
||||
((obj), E_TYPE_PLUGIN_MONO, EPluginMono))
|
||||
#define E_PLUGIN_MONO_CLASS(cls) \
|
||||
(G_TYPE_CHECK_CLASS_CAST \
|
||||
((cls), E_TYPE_PLUGIN_MONO, EPluginMonoClass))
|
||||
#define E_IS_PLUGIN_MONO(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE \
|
||||
((obj), E_TYPE_PLUGIN_MONO))
|
||||
#define E_IS_PLUGIN_MONO_CLASS(cls) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE \
|
||||
((cls), E_TYPE_PLUGIN_MONO))
|
||||
#define E_PLUGIN_MONO_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS \
|
||||
((obj), E_TYPE_PLUGIN_MONO, EPluginMonoClass))
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _EPluginMono EPluginMono;
|
||||
typedef struct _EPluginMonoClass EPluginMonoClass;
|
||||
typedef struct _EPluginMonoPrivate EPluginMonoPrivate;
|
||||
|
||||
struct _EPluginMono {
|
||||
EPlugin parent;
|
||||
EPluginMonoPrivate *priv;
|
||||
|
||||
gchar *location;
|
||||
gchar *handler;
|
||||
};
|
||||
|
||||
struct _EPluginMonoClass {
|
||||
EPluginClass parent_class;
|
||||
};
|
||||
|
||||
GType e_plugin_mono_get_type (void);
|
||||
void e_plugin_mono_register_type (GTypeModule *type_module);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* E_PLUGIN_MONO_H */
|
||||
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* evolution-module-plugin-mono.c
|
||||
*
|
||||
* This program 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 of the License, or (at your option) version 3.
|
||||
*
|
||||
* 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with the program; if not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "e-plugin-mono.h"
|
||||
|
||||
/* Module Entry Points */
|
||||
void e_module_load (GTypeModule *type_module);
|
||||
void e_module_unload (GTypeModule *type_module);
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
e_module_load (GTypeModule *type_module)
|
||||
{
|
||||
/* Register dynamically loaded types. */
|
||||
|
||||
e_plugin_mono_register_type (type_module);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
e_module_unload (GTypeModule *type_module)
|
||||
{
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
module_LTLIBRARIES = module-plugin-python.la
|
||||
|
||||
module_plugin_python_la_CPPFLAGS = \
|
||||
$(AM_CPPFLAGS) \
|
||||
-DG_LOG_DOMAIN=\"evolution-plugin-python\" \
|
||||
-I$(top_srcdir) \
|
||||
$(EVOLUTION_DATA_SERVER_CFLAGS) \
|
||||
$(PY_INCLUDES)
|
||||
|
||||
module_plugin_python_la_SOURCES = \
|
||||
evolution-module-plugin-python.c \
|
||||
e-plugin-python.c \
|
||||
e-plugin-python.h
|
||||
|
||||
module_plugin_python_la_LIBADD = \
|
||||
-ldl -lutil -lm \
|
||||
$(top_builddir)/e-util/libeutil.la \
|
||||
$(EVOLUTION_DATA_SERVER_LIBS) \
|
||||
$(PY_LIBS)
|
||||
|
||||
module_plugin_python_la_LDFLAGS = \
|
||||
-module -avoid-version $(NO_UNDEFINED)
|
||||
|
||||
example_sources = \
|
||||
example/hello_python.py \
|
||||
example/org-gnome-hello-python-ui.xml \
|
||||
example/org-gnome-hello-python.eplug.xml \
|
||||
example/Makefile.am
|
||||
|
||||
EXTRA_DIST = $(example_sources)
|
||||
|
||||
-include $(top_srcdir)/git.mk
|
||||
@ -1,238 +0,0 @@
|
||||
/*
|
||||
* e-plugin-python.c
|
||||
*
|
||||
* This program 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 of the License, or (at your option) version 3.
|
||||
*
|
||||
* 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with the program; if not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
/* Include <Python.h> first to avoid:
|
||||
* warning: "_POSIX_C_SOURCE" redefined */
|
||||
#include <Python.h>
|
||||
|
||||
#include "e-plugin-python.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#define E_PLUGIN_PYTHON_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE \
|
||||
((obj), E_TYPE_PLUGIN_PYTHON, EPluginPythonPrivate))
|
||||
|
||||
struct _EPluginPythonPrivate {
|
||||
PyObject *pModule;
|
||||
PyObject *pClass;
|
||||
PyObject *pFunc;
|
||||
PyObject *pDict;
|
||||
GHashTable *methods;
|
||||
};
|
||||
|
||||
static gpointer parent_class;
|
||||
static GType plugin_python_type;
|
||||
|
||||
static gchar *
|
||||
get_xml_prop (xmlNodePtr node,
|
||||
const gchar *id)
|
||||
{
|
||||
xmlChar *prop;
|
||||
gchar *out = NULL;
|
||||
|
||||
prop = xmlGetProp (node, (xmlChar *) id);
|
||||
|
||||
if (prop != NULL) {
|
||||
out = g_strdup ((gchar *) prop);
|
||||
xmlFree (prop);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
static void
|
||||
plugin_python_finalize (GObject *object)
|
||||
{
|
||||
EPluginPython *plugin_python;
|
||||
|
||||
plugin_python = E_PLUGIN_PYTHON (object);
|
||||
|
||||
g_free (plugin_python->location);
|
||||
g_free (plugin_python->module_name);
|
||||
g_free (plugin_python->pClass);
|
||||
|
||||
g_hash_table_destroy (plugin_python->priv->methods);
|
||||
|
||||
/* Chain up to parent's finalize() method. */
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static gint
|
||||
plugin_python_construct (EPlugin *plugin,
|
||||
xmlNodePtr root)
|
||||
{
|
||||
EPluginPython *plugin_python;
|
||||
|
||||
/* Chain up to parent's construct() method. */
|
||||
if (E_PLUGIN_CLASS (parent_class)->construct (plugin, root) == -1)
|
||||
return -1;
|
||||
|
||||
plugin_python = E_PLUGIN_PYTHON (plugin);
|
||||
plugin_python->location = get_xml_prop (root, "location");
|
||||
plugin_python->module_name = get_xml_prop (root, "module_name");
|
||||
plugin_python->pClass = get_xml_prop (root, "pClass");
|
||||
|
||||
return (plugin_python->location != NULL) ? 0 : -1;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
plugin_python_invoke (EPlugin *plugin,
|
||||
const gchar *name,
|
||||
gpointer data)
|
||||
{
|
||||
EPluginPython *plugin_python;
|
||||
EPluginPythonPrivate *priv;
|
||||
PyObject *pModuleName, *pFunc;
|
||||
PyObject *pValue = NULL;
|
||||
|
||||
plugin_python = E_PLUGIN_PYTHON (plugin);
|
||||
priv = plugin_python->priv;
|
||||
|
||||
/* We need to do this every time since we may be called
|
||||
* from any thread for some uses. */
|
||||
Py_Initialize ();
|
||||
|
||||
if (priv->pModule == NULL) {
|
||||
gchar *string;
|
||||
|
||||
pModuleName = PyString_FromString (plugin_python->module_name);
|
||||
|
||||
string = g_strdup_printf (
|
||||
"import sys; "
|
||||
"sys.path.insert(0, '%s')",
|
||||
plugin_python->location);
|
||||
PyRun_SimpleString (string);
|
||||
g_free (string);
|
||||
|
||||
priv->pModule = PyImport_Import (pModuleName);
|
||||
|
||||
Py_DECREF (pModuleName);
|
||||
|
||||
if (priv->pModule == NULL) {
|
||||
PyErr_Print ();
|
||||
g_warning (
|
||||
"Can't load python module '%s'",
|
||||
plugin_python->location);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
priv->pDict = PyModule_GetDict (priv->pModule);
|
||||
|
||||
if (plugin_python->pClass != NULL) {
|
||||
priv->pClass = PyDict_GetItemString (
|
||||
priv->pDict, plugin_python->pClass);
|
||||
}
|
||||
}
|
||||
|
||||
if (priv->pClass) {
|
||||
|
||||
if (PyCallable_Check (priv->pClass)) {
|
||||
PyObject *pInstance;
|
||||
|
||||
pInstance = PyObject_CallObject (priv->pClass, NULL);
|
||||
pValue = PyObject_CallMethod (pInstance, (gchar *) name, NULL);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
pFunc = PyDict_GetItemString (priv->pDict, name);
|
||||
|
||||
if (pFunc && PyCallable_Check (pFunc))
|
||||
pValue = PyObject_CallObject (pFunc, NULL);
|
||||
else
|
||||
PyErr_Print ();
|
||||
}
|
||||
|
||||
if (pValue) {
|
||||
Py_DECREF (pValue);
|
||||
/* Fixme */
|
||||
return NULL;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
plugin_python_class_init (EPluginPythonClass *class)
|
||||
{
|
||||
GObjectClass *object_class;
|
||||
EPluginClass *plugin_class;
|
||||
|
||||
parent_class = g_type_class_peek_parent (class);
|
||||
g_type_class_add_private (class, sizeof (EPluginPythonPrivate));
|
||||
|
||||
object_class = G_OBJECT_CLASS (class);
|
||||
object_class->finalize = plugin_python_finalize;
|
||||
|
||||
plugin_class = E_PLUGIN_CLASS (class);
|
||||
plugin_class->construct = plugin_python_construct;
|
||||
plugin_class->invoke = plugin_python_invoke;
|
||||
plugin_class->type = "python";
|
||||
}
|
||||
|
||||
static void
|
||||
plugin_python_init (EPluginPython *plugin_python)
|
||||
{
|
||||
GHashTable *methods;
|
||||
|
||||
methods = g_hash_table_new_full (
|
||||
g_str_hash, g_str_equal,
|
||||
(GDestroyNotify) g_free,
|
||||
(GDestroyNotify) NULL);
|
||||
|
||||
plugin_python->priv = E_PLUGIN_PYTHON_GET_PRIVATE (plugin_python);
|
||||
plugin_python->priv->methods = methods;
|
||||
}
|
||||
|
||||
GType
|
||||
e_plugin_python_get_type (void)
|
||||
{
|
||||
return plugin_python_type;
|
||||
}
|
||||
|
||||
void
|
||||
e_plugin_python_register_type (GTypeModule *type_module)
|
||||
{
|
||||
static const GTypeInfo type_info = {
|
||||
sizeof (EPluginPythonClass),
|
||||
(GBaseInitFunc) NULL,
|
||||
(GBaseFinalizeFunc) NULL,
|
||||
(GClassInitFunc) plugin_python_class_init,
|
||||
(GClassFinalizeFunc) NULL,
|
||||
NULL, /* class_data */
|
||||
sizeof (EPluginPython),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) plugin_python_init,
|
||||
NULL /* value_table */
|
||||
};
|
||||
|
||||
plugin_python_type = g_type_module_register_type (
|
||||
type_module, E_TYPE_PLUGIN,
|
||||
"EPluginPython", &type_info, 0);
|
||||
|
||||
/* TODO Does this mean I can cache the instance of pyobjects? */
|
||||
Py_Initialize ();
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* e-plugin-python.h
|
||||
*
|
||||
* This program 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 of the License, or (at your option) version 3.
|
||||
*
|
||||
* 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with the program; if not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef E_PLUGIN_PYTHON_H
|
||||
#define E_PLUGIN_PYTHON_H
|
||||
|
||||
#include <e-util/e-plugin.h>
|
||||
|
||||
/* Standard GObject macros */
|
||||
#define E_TYPE_PLUGIN_PYTHON \
|
||||
(e_plugin_python_get_type ())
|
||||
#define E_PLUGIN_PYTHON(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST \
|
||||
((obj), E_TYPE_PLUGIN_PYTHON, EPluginPython))
|
||||
#define E_PLUGIN_PYTHON_CLASS(cls) \
|
||||
(G_TYPE_CHECK_CLASS_CAST \
|
||||
((cls), E_TYPE_PLUGIN_PYTHON, EPluginPythonClass))
|
||||
#define E_IS_PLUGIN_PYTHON(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE \
|
||||
((obj), E_TYPE_PLUGIN_PYTHON))
|
||||
#define E_IS_PLUGIN_PYTHON_CLASS(cls) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE \
|
||||
((cls), E_TYPE_PLUGIN_PYTHON))
|
||||
#define E_PLUGIN_PYTHON_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS \
|
||||
((obj), E_TYPE_PLUGIN_PYTHON, EPluginPythonClass))
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _EPluginPython EPluginPython;
|
||||
typedef struct _EPluginPythonClass EPluginPythonClass;
|
||||
typedef struct _EPluginPythonPrivate EPluginPythonPrivate;
|
||||
|
||||
struct _EPluginPython {
|
||||
EPlugin parent;
|
||||
EPluginPythonPrivate *priv;
|
||||
|
||||
gchar *location;
|
||||
gchar *pClass;
|
||||
gchar *module_name;
|
||||
};
|
||||
|
||||
struct _EPluginPythonClass {
|
||||
EPluginClass parent_class;
|
||||
};
|
||||
|
||||
GType e_plugin_python_get_type (void);
|
||||
void e_plugin_python_register_type (GTypeModule *type_module);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* E_PLUGIN_PYTHON_H */
|
||||
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* evolution-module-plugin-python.c
|
||||
*
|
||||
* This program 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 of the License, or (at your option) version 3.
|
||||
*
|
||||
* 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with the program; if not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "e-plugin-python.h"
|
||||
|
||||
/* Module Entry Points */
|
||||
void e_module_load (GTypeModule *type_module);
|
||||
void e_module_unload (GTypeModule *type_module);
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
e_module_load (GTypeModule *type_module)
|
||||
{
|
||||
/* Register dynamically loaded types. */
|
||||
|
||||
e_plugin_python_register_type (type_module);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
e_module_unload (GTypeModule *type_module)
|
||||
{
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
@EVO_PLUGIN_RULE@
|
||||
|
||||
plugin_DATA = \
|
||||
hello_python.py \
|
||||
org-gnome-hello-python-ui.xml \
|
||||
org-gnome-hello-python.eplug
|
||||
|
||||
liborg_gnome_py_plug_test_la_CPPFLAGS = \
|
||||
$(AM_CPPFLAGS) \
|
||||
-DEVOLUTION_UIDIR=\""$(uidir)"\" \
|
||||
-DEVOLUTION_IMAGESDIR=\""$(imagesdir)"\"
|
||||
|
||||
liborg_gnome_py_plug_test_la_LDFLAGS = -module -avoid-version $(NO_UNDEFINED)
|
||||
|
||||
errordir = $(privdatadir)/errors
|
||||
|
||||
BUILDME = org-gnome-hello-python.eplug \
|
||||
$(error_i18n)
|
||||
|
||||
BUILT_SOURCES = \
|
||||
$(BUILDME)
|
||||
|
||||
EXTRA_DIST = \
|
||||
hello_python.py \
|
||||
org-gnome-hello-python-ui.xml \
|
||||
org-gnome-hello-python.eplug.xml
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
-include $(top_srcdir)/git.mk
|
||||
@ -1,5 +0,0 @@
|
||||
'''hello_python.py - Python source designed to '''
|
||||
'''demonstrate the use of python Eplugins'''
|
||||
|
||||
def say_hello():
|
||||
print 'Hello ! From python'
|
||||
@ -1,16 +0,0 @@
|
||||
<Root>
|
||||
<commands>
|
||||
<cmd name="HelloPy" _label="Hello Python"
|
||||
_tip="Python Plugin Loader tests"
|
||||
/>
|
||||
</commands>
|
||||
|
||||
<menu>
|
||||
<placeholder name="MessagePlaceholder">
|
||||
<submenu name="Message">
|
||||
<separator f="" name="sep"/>
|
||||
<menuitem name="HelloPy" verb=""/>
|
||||
</submenu>
|
||||
</placeholder>
|
||||
</menu>
|
||||
</Root>
|
||||
@ -1,20 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<e-plugin-list>
|
||||
<e-plugin id="org.gnome.evolution.hello_python" type="python" _name="Python Test Plugin" location="@PLUGINDIR@" module_name="hello_python">
|
||||
|
||||
<author name="Johnny Jacob" email="jjohnny@novell.com"/>
|
||||
|
||||
<_description>
|
||||
Test Plugin for Python EPlugin loader.
|
||||
</_description>
|
||||
|
||||
<hook class="org.gnome.evolution.mail.bonobomenu:1.0">
|
||||
<menu id="org.gnome.evolution.mail.browser" target="select">
|
||||
<!-- the path to the bonobo menu description. Any UI items on Evolution should come here -->
|
||||
<ui file="@PLUGINDIR@/org-gnome-hello-python-ui.xml"/>
|
||||
<item type="item" verb="HelloPy" path="/commands/HelloPy" enable="one" activate="say_hello"/>
|
||||
</menu>
|
||||
</hook>
|
||||
|
||||
</e-plugin>
|
||||
</e-plugin-list>
|
||||
Reference in New Issue
Block a user