From 1c0f4d61d1bc5f06924f16c4c8726100ba615008 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Wed, 25 Dec 2013 06:12:56 +0000 Subject: [PATCH] Add plugin example to plugins This is the former content of plugins-example.tgz, mentioned in the wiki documentation. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23615 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/plugins/Makefile.am | 8 ++ src/plugins/example/Makefile.am | 39 +++++++ src/plugins/example/glade/Makefile.am | 4 + src/plugins/example/gnc-plugin.example.c | 107 ++++++++++++++++++ src/plugins/example/gnc-plugin.example.h | 78 +++++++++++++ src/plugins/example/gncmod-example.c | 97 ++++++++++++++++ src/plugins/example/ui/Makefile.am | 5 + .../example/ui/gnc-plugin-example-ui.xml | 9 ++ 8 files changed, 347 insertions(+) create mode 100644 src/plugins/example/Makefile.am create mode 100644 src/plugins/example/glade/Makefile.am create mode 100644 src/plugins/example/gnc-plugin.example.c create mode 100644 src/plugins/example/gnc-plugin.example.h create mode 100644 src/plugins/example/gncmod-example.c create mode 100644 src/plugins/example/ui/Makefile.am create mode 100644 src/plugins/example/ui/gnc-plugin-example-ui.xml diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index a2374a698f..aa11dfe284 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -1 +1,9 @@ SUBDIRS=customer_import bi_import +EXTRA_DIST = \ + example/Makefile.am \ + example/gnc-plugin.example.c \ + example/gnc-plugin.example.h \ + example/gncmod-example.c \ + example/glade/Makefile.am \ + example/ui/Makefile.am \ + example/ui/gnc-plugin-example-ui.xml diff --git a/src/plugins/example/Makefile.am b/src/plugins/example/Makefile.am new file mode 100644 index 0000000000..ff20330260 --- /dev/null +++ b/src/plugins/example/Makefile.am @@ -0,0 +1,39 @@ +SUBDIRS = ui glade . + +pkglib_LTLIBRARIES = libgncmod-example.la + +libgncmod_example_la_SOURCES = \ + gnc-plugin-example.c \ + gncmod-example.c + +noinst_HEADERS = \ + gnc-plugin-example.h + +libgncmod_example_la_LDFLAGS = -avoid-version + +libgncmod_example_la_LIBADD = \ + ${top_builddir}/src/gnc-module/libgnc-module.la \ + ${GNOME_LIBS} \ + ${GLADE_LIBS} \ + ${QOF_LIBS} \ + ${GLIB_LIBS} \ + ${AQBANKING_LIBS} + +AM_CFLAGS = \ + -I${top_srcdir}/src \ + -I${top_srcdir}/src/gnome \ + -I${top_srcdir}/src/register/ledger-core \ + -I${top_srcdir}/src/register/register-gnome \ + -I${top_srcdir}/src/register/register-core \ + -I${top_srcdir}/src/gnome-utils \ + -I${top_srcdir}/src/app-utils \ + -I${top_srcdir}/src/engine \ + -I${top_srcdir}/src/core-utils \ + -I${top_srcdir}/src/gnc-module \ + ${GNOME_CFLAGS} \ + ${GLADE_CFLAGS} \ + ${QOF_CFLAGS} \ + ${GLIB_CFLAGS} \ + ${AQBANKING_CFLAGS} + +INCLUDES = -DG_LOG_DOMAIN=\"gnc.plugin.example\" diff --git a/src/plugins/example/glade/Makefile.am b/src/plugins/example/glade/Makefile.am new file mode 100644 index 0000000000..4096c72279 --- /dev/null +++ b/src/plugins/example/glade/Makefile.am @@ -0,0 +1,4 @@ +gladedir = $(GNC_GLADE_DIR) +glade_DATA = + +EXTRA_DIST = ${glade_DATA} diff --git a/src/plugins/example/gnc-plugin.example.c b/src/plugins/example/gnc-plugin.example.c new file mode 100644 index 0000000000..f23da8a4ab --- /dev/null +++ b/src/plugins/example/gnc-plugin.example.c @@ -0,0 +1,107 @@ +/* + * gnc-plugin-example.c -- + * + * 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, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 + * Boston, MA 02110-1301, USA gnu@gnu.org + */ + +/** + * @internal + * @file gnc-plugin-example.c + * @brief Plugin registration of the example plugin + * @author Copyright (C) 2009 ?enter your name here? + */ + +#include "config.h" + +#include + +#include "gnc-plugin-example.h" + +/* This static indicates the debugging module that this .o belongs to. */ +static QofLogModule log_module = G_LOG_DOMAIN; + +static void gnc_plugin_example_class_init (GncPluginexampleClass *klass); +static void gnc_plugin_example_init (GncPluginexample *plugin); +static void gnc_plugin_example_finalize (GObject *object); + +/* Command callbacks */ +static void gnc_plugin_example_cmd_test (GtkAction *action, GncMainWindowActionData *data); + +#define PLUGIN_ACTIONS_NAME "gnc-plugin-example-actions" +#define PLUGIN_UI_FILENAME "gnc-plugin-example-ui.xml" + +static GtkActionEntry gnc_plugin_actions [] = { + /* Menu Items */ + { "exampleAction", NULL, N_("example description..."), NULL, + N_("example tooltip"), + G_CALLBACK(gnc_plugin_example_cmd_test) }, +}; +static guint gnc_plugin_n_actions = G_N_ELEMENTS(gnc_plugin_actions); + + +/************************************************************ + * Object Implementation * + ************************************************************/ + +G_DEFINE_TYPE(GncPluginexample, gnc_plugin_example, GNC_TYPE_PLUGIN) + +GncPlugin * +gnc_plugin_example_new (void) +{ + return GNC_PLUGIN (g_object_new (GNC_TYPE_PLUGIN_example, (gchar*) NULL)); +} + +static void +gnc_plugin_example_class_init (GncPluginexampleClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GncPluginClass *plugin_class = GNC_PLUGIN_CLASS(klass); + + object_class->finalize = gnc_plugin_example_finalize; + + /* plugin info */ + plugin_class->plugin_name = GNC_PLUGIN_example_NAME; + + /* widget addition/removal */ + plugin_class->actions_name = PLUGIN_ACTIONS_NAME; + plugin_class->actions = gnc_plugin_actions; + plugin_class->n_actions = gnc_plugin_n_actions; + plugin_class->ui_filename = PLUGIN_UI_FILENAME; +} + +static void +gnc_plugin_example_init (GncPluginexample *plugin) +{ +} + +static void +gnc_plugin_example_finalize (GObject *object) +{ +} + +/************************************************************ + * Command Callbacks * + ************************************************************/ + +static void +gnc_plugin_example_cmd_test (GtkAction *action, GncMainWindowActionData *data) +{ + ENTER ("action %p, main window data %p", action, data); + g_message ("example"); + LEAVE (" "); +} diff --git a/src/plugins/example/gnc-plugin.example.h b/src/plugins/example/gnc-plugin.example.h new file mode 100644 index 0000000000..f3c8400a18 --- /dev/null +++ b/src/plugins/example/gnc-plugin.example.h @@ -0,0 +1,78 @@ +/* + * gnc-plugin-example.h -- + * + * 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, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 + * Boston, MA 02110-1301, USA gnu@gnu.org + */ + +/** + * @addtogroup Tools + * @{ + * @file gnc-plugin-example.h + * @brief Plugin registration of the example module + * @author Copyright (C) 2009 ?enter your name here? + */ + +#ifndef GNC_PLUGIN_example_H +#define GNC_PLUGIN_example_H + +#include + +#include "gnc-plugin.h" + +G_BEGIN_DECLS + +/* type macros */ +#define GNC_TYPE_PLUGIN_example (gnc_plugin_example_get_type()) +#define GNC_PLUGIN_example(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNC_TYPE_PLUGIN_example, GncPluginexample)) +#define GNC_PLUGIN_example_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNC_TYPE_PLUGIN_example, GncPluginexampleClass)) +#define GNC_IS_PLUGIN_example(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNC_TYPE_PLUGIN_example)) +#define GNC_IS_PLUGIN_example_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNC_TYPE_PLUGIN_example)) +#define GNC_PLUGIN_example_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNC_TYPE_PLUGIN_example, GncPluginexampleClass)) + +#define GNC_PLUGIN_example_NAME "gnc-plugin-example" + +/* typedefs & structures */ +typedef struct { + GncPlugin gnc_plugin; +} GncPluginexample; + +typedef struct { + GncPluginClass gnc_plugin; +} GncPluginexampleClass; + +/* function prototypes */ +/** + * @return The glib runtime type of an example plugin page + **/ +GType gnc_plugin_example_get_type (void); + +/** + * @return A new GncPluginexample object + */ +GncPlugin* gnc_plugin_example_new (void); + +/** + * Create a new GncPluginexample object and register it. + */ +void gnc_plugin_example_create_plugin (void); + +G_END_DECLS + +/** @} */ + +#endif /* GNC_PLUGIN_example_H */ diff --git a/src/plugins/example/gncmod-example.c b/src/plugins/example/gncmod-example.c new file mode 100644 index 0000000000..94e204bcce --- /dev/null +++ b/src/plugins/example/gncmod-example.c @@ -0,0 +1,97 @@ +/********************************************************************* + * gncmod-example.c + * module definition/initialization for the example GNOME UI module + * + * Copyright (c) 2009 Sebastian Held + * Copyright (c) 2001 Derek Atkins + * + * 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, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 + * Boston, MA 02110-1301, USA gnu@gnu.org + * + *********************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#include "gnc-hooks.h" +#include "gnc-module.h" +#include "gnc-module-api.h" + +#include "gnc-plugin-manager.h" +#include "gnc-plugin-example.h" + +GNC_MODULE_API_DECL(libgncmod_example) + +/* version of the gnc module system interface we require */ +int libgncmod_example_gnc_module_system_interface = 0; + +/* module versioning uses libtool semantics. */ +int libgncmod_example_gnc_module_current = 0; +int libgncmod_example_gnc_module_revision = 0; +int libgncmod_example_gnc_module_age = 0; + + +char * +libgncmod_example_gnc_module_path (void) +{ + return g_strdup("gnucash/plugins/example"); +} + +char * +libgncmod_example_gnc_module_description (void) +{ + return g_strdup("The GnuCash example plugin"); +} + +int +libgncmod_example_gnc_module_init (int refcount) +{ + if (!gnc_module_load ("gnucash/app-utils", 0)) { + return FALSE; + } + if (!gnc_module_load ("gnucash/gnome-utils", 0)) { + return FALSE; + } + if (!gnc_module_load ("gnucash/engine", 0)) { + return FALSE; + } + + if (refcount == 0) { + /* this is the first time the module is loaded */ + + gnc_plugin_manager_add_plugin ( gnc_plugin_manager_get (), + gnc_plugin_example_new ()); + } + + return TRUE; +} + +int +libgncmod_example_gnc_module_end (int refcount) +{ + if (refcount == 0) { + /* this is the last time the module is unloaded */ + } + + return TRUE; +} diff --git a/src/plugins/example/ui/Makefile.am b/src/plugins/example/ui/Makefile.am new file mode 100644 index 0000000000..210eee8804 --- /dev/null +++ b/src/plugins/example/ui/Makefile.am @@ -0,0 +1,5 @@ +uidir = $(GNC_UI_DIR) +ui_DATA = \ + gnc-plugin-example-ui.xml + +EXTRA_DIST = $(ui_DATA) diff --git a/src/plugins/example/ui/gnc-plugin-example-ui.xml b/src/plugins/example/ui/gnc-plugin-example-ui.xml new file mode 100644 index 0000000000..0c96ec50ec --- /dev/null +++ b/src/plugins/example/ui/gnc-plugin-example-ui.xml @@ -0,0 +1,9 @@ + + + + + + + + +