GnuCash  4.11-137-g155922540d+
gnc-plugin-register.c
1 /*
2  * gnc-plugin-register.c --
3  *
4  * Copyright (C) 2003 Jan Arne Petersen
5  * Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, contact:
19  *
20  * Free Software Foundation Voice: +1-617-542-5942
21  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
22  * Boston, MA 02110-1301, USA gnu@gnu.org
23  */
24 
25 #include <config.h>
26 
27 #include <gtk/gtk.h>
28 #include <glib/gi18n.h>
29 #include <string.h>
30 
31 #include "gnc-component-manager.h"
32 #include "gnc-plugin-register.h"
34 #include "gnc-prefs.h"
35 
36 
37 static void gnc_plugin_register_class_init (GncPluginRegisterClass *klass);
38 static void gnc_plugin_register_init (GncPluginRegister *plugin);
39 static void gnc_plugin_register_finalize (GObject *object);
40 
41 static void gnc_plugin_register_add_to_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
42 static void gnc_plugin_register_remove_from_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
43 
44 /* Command callbacks */
45 static void gnc_plugin_register_cmd_general_ledger (GtkAction *action, GncMainWindowActionData *data);
46 
47 #define PLUGIN_ACTIONS_NAME "gnc-plugin-register-actions"
48 #define PLUGIN_UI_FILENAME "gnc-plugin-register-ui.xml"
49 
50 static GtkActionEntry gnc_plugin_actions [] =
51 {
52  {
53 #ifdef REGISTER2_ENABLED
54  "ToolsGeneralJournalAction", NULL, N_("Old St_yle General Journal"), NULL,
55  N_("Open an old style general journal window"),
56  G_CALLBACK (gnc_plugin_register_cmd_general_ledger)
57 #else
58  "ToolsGeneralJournalAction", NULL, N_("_General Journal"), NULL,
59  N_("Open general journal window"),
60  G_CALLBACK (gnc_plugin_register_cmd_general_ledger)
61 #endif
62  },
63 };
64 static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
65 
67 {
68  gpointer dummy;
70 
71 G_DEFINE_TYPE_WITH_PRIVATE(GncPluginRegister, gnc_plugin_register, GNC_TYPE_PLUGIN)
72 
73 #define GNC_PLUGIN_REGISTER_GET_PRIVATE(o) \
74  ((GncPluginRegisterPrivate*)gnc_plugin_register_get_instance_private((GncPluginRegister*)o))
75 
76 static GObjectClass *parent_class = NULL;
77 static QofLogModule log_module = GNC_MOD_GUI;
78 
79 /************************************************************
80  * Other Functions *
81  ************************************************************/
82 
95 static void
96 gnc_plugin_register_pref_changed (gpointer prefs, gchar *pref,
97  gpointer user_data)
98 {
99  ENTER("");
100  gnc_gui_refresh_all ();
101  LEAVE("");
102 }
103 
104 /************************************************************
105  * Object Implementation *
106  ************************************************************/
107 
108 GncPlugin *
109 gnc_plugin_register_new (void)
110 {
111  GncPluginRegister *plugin;
112 
113  /* Reference the register page plugin to ensure it exists in
114  * the gtk type system. */
115  GNC_TYPE_PLUGIN_PAGE_REGISTER;
116 
117  plugin = g_object_new (GNC_TYPE_PLUGIN_REGISTER,
118  NULL);
119 
120  return GNC_PLUGIN (plugin);
121 }
122 
123 static void
124 gnc_plugin_register_class_init (GncPluginRegisterClass *klass)
125 {
126  GObjectClass *object_class = G_OBJECT_CLASS (klass);
127  GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
128 
129  parent_class = g_type_class_peek_parent (klass);
130 
131  object_class->finalize = gnc_plugin_register_finalize;
132 
133  /* plugin info */
134  plugin_class->plugin_name = GNC_PLUGIN_REGISTER_NAME;
135 
136  /* function overrides */
137  plugin_class->add_to_window = gnc_plugin_register_add_to_window;
138  plugin_class->remove_from_window =
139  gnc_plugin_register_remove_from_window;
140 
141  /* widget addition/removal */
142  plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
143  plugin_class->actions = gnc_plugin_actions;
144  plugin_class->n_actions = gnc_plugin_n_actions;
145  plugin_class->ui_filename = PLUGIN_UI_FILENAME;
146 }
147 
148 static void
149 gnc_plugin_register_init (GncPluginRegister *plugin)
150 {
151 }
152 
153 static void
154 gnc_plugin_register_finalize (GObject *object)
155 {
156  g_return_if_fail (GNC_IS_PLUGIN_REGISTER (object));
157 
158  G_OBJECT_CLASS (parent_class)->finalize (object);
159 }
160 
161 /************************************************************
162  * Plugin Function Implementation *
163  ************************************************************/
164 
179 static void
180 gnc_plugin_register_add_to_window (GncPlugin *plugin,
181  GncMainWindow *window,
182  GQuark type)
183 {
184  gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
185  gnc_plugin_register_pref_changed, window);
186 }
187 
188 
200 static void
201 gnc_plugin_register_remove_from_window (GncPlugin *plugin,
202  GncMainWindow *window,
203  GQuark type)
204 {
205  gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
206  gnc_plugin_register_pref_changed, window);
207 }
208 
209 
210 /************************************************************
211  * Command Callbacks *
212  ************************************************************/
213 
214 static void
215 gnc_plugin_register_cmd_general_ledger (GtkAction *action,
217 {
218  GncPluginPage *page;
219 
220  g_return_if_fail (data != NULL);
221 
223  gnc_main_window_open_page (data->window, page);
224 }
guint n_actions
The number of actions in the actions array.
Definition: gnc-plugin.h:124
The instance data structure for a content plugin.
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
Register a callback that gets triggered when the given preference changes.
Definition: gnc-prefs.c:128
The class data structure for a menu-only plugin.
Definition: gnc-plugin.h:107
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
const gchar * ui_filename
The relative name of the XML file describing the menu/toolbar action items.
Definition: gnc-plugin.h:137
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
Display a data plugin page in a window.
GtkActionEntry * actions
An array of actions that should automatically be added to any GnuCash "main" content window that is o...
Definition: gnc-plugin.h:122
Functions providing a register page for the GnuCash UI.
void(* remove_from_window)(GncPlugin *plugin, GncMainWindow *window, GQuark type)
A callback that will be invoked when this plugin is removed from a window.
Definition: gnc-plugin.h:171
void(* add_to_window)(GncPlugin *plugin, GncMainWindow *window, GQuark type)
A callback that will be invoked when this plugin is added to a window.
Definition: gnc-plugin.h:155
const gchar * actions_name
A name for the set of actions that will be added by this plugin.
Definition: gnc-plugin.h:119
Generic api to store and retrieve preferences.
const gchar * plugin_name
The textual name of this plugin.
Definition: gnc-plugin.h:112
GncPluginPage * gnc_plugin_page_register_new_gl(void)
Create a new "register" plugin page containing a general journal.
The instance data structure for a menu-only plugin.
Definition: gnc-plugin.h:100
#define PLUGIN_ACTIONS_NAME
The label given to the main window for this plugin.
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
The instance data structure for a main window object.
#define PLUGIN_UI_FILENAME
The name of the UI description file for this plugin.
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)
Remove a function that was registered for a callback when the given preference changed.
Definition: gnc-prefs.c:143