GnuCash  4.12-527-g05ffd3d4eb
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  "ToolsGeneralJournalAction", NULL, N_("_General Journal"), NULL,
54  N_("Open general journal window"),
55  G_CALLBACK (gnc_plugin_register_cmd_general_ledger)
56  },
57 };
58 static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
59 
61 {
62  gpointer dummy;
64 
65 G_DEFINE_TYPE_WITH_PRIVATE(GncPluginRegister, gnc_plugin_register, GNC_TYPE_PLUGIN)
66 
67 #define GNC_PLUGIN_REGISTER_GET_PRIVATE(o) \
68  ((GncPluginRegisterPrivate*)gnc_plugin_register_get_instance_private((GncPluginRegister*)o))
69 
70 static GObjectClass *parent_class = NULL;
71 static QofLogModule log_module = GNC_MOD_GUI;
72 
73 /************************************************************
74  * Other Functions *
75  ************************************************************/
76 
89 static void
90 gnc_plugin_register_pref_changed (gpointer prefs, gchar *pref,
91  gpointer user_data)
92 {
93  ENTER("");
94  gnc_gui_refresh_all ();
95  LEAVE("");
96 }
97 
98 /************************************************************
99  * Object Implementation *
100  ************************************************************/
101 
102 GncPlugin *
103 gnc_plugin_register_new (void)
104 {
105  GncPluginRegister *plugin;
106 
107  /* Reference the register page plugin to ensure it exists in
108  * the gtk type system. */
109  GNC_TYPE_PLUGIN_PAGE_REGISTER;
110 
111  plugin = g_object_new (GNC_TYPE_PLUGIN_REGISTER,
112  NULL);
113 
114  return GNC_PLUGIN (plugin);
115 }
116 
117 static void
118 gnc_plugin_register_class_init (GncPluginRegisterClass *klass)
119 {
120  GObjectClass *object_class = G_OBJECT_CLASS (klass);
121  GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
122 
123  parent_class = g_type_class_peek_parent (klass);
124 
125  object_class->finalize = gnc_plugin_register_finalize;
126 
127  /* plugin info */
128  plugin_class->plugin_name = GNC_PLUGIN_REGISTER_NAME;
129 
130  /* function overrides */
131  plugin_class->add_to_window = gnc_plugin_register_add_to_window;
132  plugin_class->remove_from_window =
133  gnc_plugin_register_remove_from_window;
134 
135  /* widget addition/removal */
136  plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
137  plugin_class->actions = gnc_plugin_actions;
138  plugin_class->n_actions = gnc_plugin_n_actions;
139  plugin_class->ui_filename = PLUGIN_UI_FILENAME;
140 }
141 
142 static void
143 gnc_plugin_register_init (GncPluginRegister *plugin)
144 {
145 }
146 
147 static void
148 gnc_plugin_register_finalize (GObject *object)
149 {
150  g_return_if_fail (GNC_IS_PLUGIN_REGISTER (object));
151 
152  G_OBJECT_CLASS (parent_class)->finalize (object);
153 }
154 
155 /************************************************************
156  * Plugin Function Implementation *
157  ************************************************************/
158 
173 static void
174 gnc_plugin_register_add_to_window (GncPlugin *plugin,
175  GncMainWindow *window,
176  GQuark type)
177 {
178  gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
179  gnc_plugin_register_pref_changed, window);
180 }
181 
182 
194 static void
195 gnc_plugin_register_remove_from_window (GncPlugin *plugin,
196  GncMainWindow *window,
197  GQuark type)
198 {
199  gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
200  gnc_plugin_register_pref_changed, window);
201 }
202 
203 
204 /************************************************************
205  * Command Callbacks *
206  ************************************************************/
207 
208 static void
209 gnc_plugin_register_cmd_general_ledger (GtkAction *action,
211 {
212  GncPluginPage *page;
213 
214  g_return_if_fail (data != NULL);
215 
217  gnc_main_window_open_page (data->window, page);
218 }
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