GnuCash c935c2f+
Loading...
Searching...
No Matches
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
37static void gnc_plugin_register_finalize (GObject *object);
38
39static void gnc_plugin_register_add_to_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
40static void gnc_plugin_register_remove_from_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
41
42/* Command callbacks */
43static void gnc_plugin_register_cmd_general_ledger (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
44
45#define PLUGIN_ACTIONS_NAME "gnc-plugin-register-actions"
46#define PLUGIN_UI_FILENAME "gnc-plugin-register.ui"
47
48static GActionEntry gnc_plugin_actions [] =
49{
50 { "ToolsGeneralJournalAction", gnc_plugin_register_cmd_general_ledger, NULL, NULL, NULL },
51};
53static guint gnc_plugin_n_actions = G_N_ELEMENTS(gnc_plugin_actions);
54
56static const gchar *gnc_plugin_load_ui_items [] =
57{
58 "ToolsPlaceholder2",
59 NULL,
60};
61
63{
64 GncPlugin gnc_plugin;
65};
66
67G_DEFINE_TYPE(GncPluginRegister, gnc_plugin_register, GNC_TYPE_PLUGIN)
68
69static QofLogModule log_module = GNC_MOD_GUI;
70
71/************************************************************
72 * Other Functions *
73 ************************************************************/
74
87static void
88gnc_plugin_register_pref_changed (gpointer prefs, gchar *pref,
89 gpointer user_data)
90{
91 ENTER("");
92 gnc_gui_refresh_all ();
93 LEAVE("");
94}
95
96/************************************************************
97 * Object Implementation *
98 ************************************************************/
99
100GncPlugin *
101gnc_plugin_register_new (void)
102{
103 GncPluginRegister *plugin;
104
105 /* Reference the register page plugin to ensure it exists in
106 * the gtk type system. */
107 GNC_TYPE_PLUGIN_PAGE_REGISTER;
108
109 plugin = g_object_new (GNC_TYPE_PLUGIN_REGISTER,
110 NULL);
111
112 return GNC_PLUGIN (plugin);
113}
114
115static void
116gnc_plugin_register_class_init (GncPluginRegisterClass *klass)
117{
118 GObjectClass *object_class = G_OBJECT_CLASS (klass);
119 GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
120
121 object_class->finalize = gnc_plugin_register_finalize;
122
123 /* plugin info */
124 plugin_class->plugin_name = GNC_PLUGIN_REGISTER_NAME;
125
126 /* function overrides */
127 plugin_class->add_to_window = gnc_plugin_register_add_to_window;
128 plugin_class->remove_from_window =
129 gnc_plugin_register_remove_from_window;
130
131 /* widget addition/removal */
132 plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
133 plugin_class->actions = gnc_plugin_actions;
134 plugin_class->n_actions = gnc_plugin_n_actions;
135 plugin_class->ui_filename = PLUGIN_UI_FILENAME;
136 plugin_class->ui_updates = gnc_plugin_load_ui_items;
137}
138
139static void
140gnc_plugin_register_init (GncPluginRegister *plugin)
141{
142}
143
144static void
145gnc_plugin_register_finalize (GObject *object)
146{
147 g_return_if_fail (GNC_IS_PLUGIN_REGISTER (object));
148
149 G_OBJECT_CLASS (gnc_plugin_register_parent_class)->finalize (object);
150}
151
152/************************************************************
153 * Plugin Function Implementation *
154 ************************************************************/
155
170static void
171gnc_plugin_register_add_to_window (GncPlugin *plugin,
172 GncMainWindow *window,
173 GQuark type)
174{
175 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
176 gnc_plugin_register_pref_changed, window);
177}
178
179
191static void
192gnc_plugin_register_remove_from_window (GncPlugin *plugin,
193 GncMainWindow *window,
194 GQuark type)
195{
196 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
197 gnc_plugin_register_pref_changed, window);
198}
199
200
201/************************************************************
202 * Command Callbacks *
203 ************************************************************/
204
205static void
206gnc_plugin_register_cmd_general_ledger (GSimpleAction *simple,
207 GVariant *parameter,
208 gpointer user_data)
209{
210 GncMainWindowActionData *data = user_data;
211 GncPluginPage *page;
212
213 g_return_if_fail (data != NULL);
214
216 gnc_main_window_open_page (data->window, page);
217}
Functions providing a register page for the GnuCash UI.
Generic api to store and retrieve preferences.
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
Display a data plugin page in a window.
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
#define ENTER(format, args...)
Print a function entry debugging message.
Definition qoflog.h:272
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.
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.
GncPluginPage * gnc_plugin_page_register_new_gl(void)
Create a new "register" plugin page containing a general journal.
The instance data structure for a content plugin.