GnuCash  2.6.99
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 #define GNC_PLUGIN_REGISTER_GET_PRIVATE(o) \
72  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN_REGISTER, GncPluginRegisterPrivate))
73 
74 static GObjectClass *parent_class = NULL;
75 static QofLogModule log_module = GNC_MOD_GUI;
76 
77 /************************************************************
78  * Other Functions *
79  ************************************************************/
80 
93 static void
94 gnc_plugin_register_pref_changed (gpointer prefs, gchar *pref,
95  gpointer user_data)
96 {
97  ENTER("");
98  gnc_gui_refresh_all ();
99  LEAVE("");
100 }
101 
102 /************************************************************
103  * Object Implementation *
104  ************************************************************/
105 
106 GType
107 gnc_plugin_register_get_type (void)
108 {
109  static GType gnc_plugin_register_type = 0;
110 
111  if (gnc_plugin_register_type == 0)
112  {
113  static const GTypeInfo our_info =
114  {
115  sizeof (GncPluginRegisterClass),
116  NULL, /* base_init */
117  NULL, /* base_finalize */
118  (GClassInitFunc) gnc_plugin_register_class_init,
119  NULL, /* class_finalize */
120  NULL, /* class_data */
121  sizeof (GncPluginRegister),
122  0, /* n_preallocs */
123  (GInstanceInitFunc) gnc_plugin_register_init
124  };
125 
126  gnc_plugin_register_type = g_type_register_static (GNC_TYPE_PLUGIN,
127  "GncPluginRegister",
128  &our_info, 0);
129  }
130 
131  return gnc_plugin_register_type;
132 }
133 
134 GncPlugin *
135 gnc_plugin_register_new (void)
136 {
137  GncPluginRegister *plugin;
138 
139  /* Reference the register page plugin to ensure it exists in
140  * the gtk type system. */
141  GNC_TYPE_PLUGIN_PAGE_REGISTER;
142 
143  plugin = g_object_new (GNC_TYPE_PLUGIN_REGISTER,
144  NULL);
145 
146  return GNC_PLUGIN (plugin);
147 }
148 
149 static void
150 gnc_plugin_register_class_init (GncPluginRegisterClass *klass)
151 {
152  GObjectClass *object_class = G_OBJECT_CLASS (klass);
153  GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
154 
155  parent_class = g_type_class_peek_parent (klass);
156 
157  object_class->finalize = gnc_plugin_register_finalize;
158 
159  /* plugin info */
160  plugin_class->plugin_name = GNC_PLUGIN_REGISTER_NAME;
161 
162  /* function overrides */
163  plugin_class->add_to_window = gnc_plugin_register_add_to_window;
164  plugin_class->remove_from_window =
165  gnc_plugin_register_remove_from_window;
166 
167  /* widget addition/removal */
168  plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
169  plugin_class->actions = gnc_plugin_actions;
170  plugin_class->n_actions = gnc_plugin_n_actions;
171  plugin_class->ui_filename = PLUGIN_UI_FILENAME;
172 
173  g_type_class_add_private(klass, sizeof(GncPluginRegisterPrivate));
174 }
175 
176 static void
177 gnc_plugin_register_init (GncPluginRegister *plugin)
178 {
179 }
180 
181 static void
182 gnc_plugin_register_finalize (GObject *object)
183 {
184  g_return_if_fail (GNC_IS_PLUGIN_REGISTER (object));
185 
186  G_OBJECT_CLASS (parent_class)->finalize (object);
187 }
188 
189 /************************************************************
190  * Plugin Function Implementation *
191  ************************************************************/
192 
207 static void
208 gnc_plugin_register_add_to_window (GncPlugin *plugin,
209  GncMainWindow *window,
210  GQuark type)
211 {
212  gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
213  gnc_plugin_register_pref_changed, window);
214 }
215 
216 
228 static void
229 gnc_plugin_register_remove_from_window (GncPlugin *plugin,
230  GncMainWindow *window,
231  GQuark type)
232 {
233  gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
234  gnc_plugin_register_pref_changed, window);
235 }
236 
237 
238 /************************************************************
239  * Command Callbacks *
240  ************************************************************/
241 
242 static void
243 gnc_plugin_register_cmd_general_ledger (GtkAction *action,
245 {
246  GncPluginPage *page;
247 
248  g_return_if_fail (data != NULL);
249 
251  gnc_main_window_open_page (data->window, page);
252 }
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:261
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:271
The instance data structure for a main window object.
#define PLUGIN_UI_FILENAME
The name of the UI description file for this plugin.
const gchar * QofLogModule
QofLogModule declaration.
Definition: qofid.h:89
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:148