GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-plugin-register2.c
1 /*
2  * gnc-plugin-register2.c --
3  *
4  * Copyright (C) 2003 Jan Arne Petersen
5  * Author: Jan Arne Petersen <[email protected]>
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 [email protected]
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-register2.h"
33 #include "gnc-plugin-page-register2.h"
34 #include "gnc-prefs.h"
35 
36 static void gnc_plugin_register2_class_init (GncPluginRegister2Class *klass);
37 static void gnc_plugin_register2_init (GncPluginRegister2 *plugin);
38 static void gnc_plugin_register2_finalize (GObject *object);
39 
40 static void gnc_plugin_register2_add_to_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
41 static void gnc_plugin_register2_remove_from_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
42 
43 /* Command callbacks */
44 static void gnc_plugin_register2_cmd_general_ledger (GtkAction *action, GncMainWindowActionData *data);
45 
46 #define PLUGIN_ACTIONS_NAME "gnc-plugin-register2-actions"
47 
48 #ifdef REGISTER2_ENABLED
49 #define PLUGIN_UI_FILENAME "gnc-plugin-register2-ui.xml"
50 #else
51 #define PLUGIN_UI_FILENAME "gnc-plugin-register22-ui.xml"
52 #endif
53 static GtkActionEntry gnc_plugin_actions [] =
54 {
55 #ifdef REGISTER2_ENABLED
56  {
57  "ToolsGeneralLedger2Action", NULL, N_("_General Ledger"), NULL,
58  N_("Open a general ledger window"),
59  G_CALLBACK (gnc_plugin_register2_cmd_general_ledger)
60  },
61 #endif
62 
63  /* Extensions Menu */
64  { "Register2TestAction", NULL, N_("_Register2"), NULL, NULL, NULL },
65  {
66  "Register2TestGLAction", NULL, N_("Register2 Open GL Account"), NULL,
67  N_("Register2 Open GL Account"),
68  G_CALLBACK (gnc_plugin_register2_cmd_general_ledger)
69  },
70 };
71 static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
72 
74 {
75  gpointer dummy;
77 
78 #define GNC_PLUGIN_REGISTER2_GET_PRIVATE(o) \
79  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN_REGISTER2, GncPluginRegister2Private))
80 
81 static GObjectClass *parent_class = NULL;
82 static QofLogModule log_module = GNC_MOD_GUI;
83 
84 /************************************************************
85  * Other Functions *
86  ************************************************************/
87 
100 static void
101 gnc_plugin_register2_pref_changed (gpointer prefs, gchar *pref,
102  gpointer user_data)
103 {
104  ENTER("");
105  gnc_gui_refresh_all ();
106  LEAVE("");
107 }
108 
109 /************************************************************
110  * Object Implementation *
111  ************************************************************/
112 
113 GType
114 gnc_plugin_register2_get_type (void)
115 {
116  static GType gnc_plugin_register2_type = 0;
117 
118  if (gnc_plugin_register2_type == 0)
119  {
120  static const GTypeInfo our_info =
121  {
122  sizeof (GncPluginRegister2Class),
123  NULL, /* base_init */
124  NULL, /* base_finalize */
125  (GClassInitFunc) gnc_plugin_register2_class_init,
126  NULL, /* class_finalize */
127  NULL, /* class_data */
128  sizeof (GncPluginRegister2),
129  0, /* n_preallocs */
130  (GInstanceInitFunc) gnc_plugin_register2_init
131  };
132 
133  gnc_plugin_register2_type = g_type_register_static (GNC_TYPE_PLUGIN,
134  "GncPluginRegister2",
135  &our_info, 0);
136  }
137 
138  return gnc_plugin_register2_type;
139 }
140 
141 GncPlugin *
142 gnc_plugin_register2_new (void)
143 {
144  GncPluginRegister2 *plugin;
145 
146  /* Reference the register page plugin to ensure it exists in
147  * the gtk type system. */
148  GNC_TYPE_PLUGIN_PAGE_REGISTER2;
149 
150  plugin = g_object_new (GNC_TYPE_PLUGIN_REGISTER2,
151  NULL);
152 
153  return GNC_PLUGIN (plugin);
154 }
155 
156 static void
157 gnc_plugin_register2_class_init (GncPluginRegister2Class *klass)
158 {
159  GObjectClass *object_class = G_OBJECT_CLASS (klass);
160  GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
161 
162  parent_class = g_type_class_peek_parent (klass);
163 
164  object_class->finalize = gnc_plugin_register2_finalize;
165 
166  /* plugin info */
167  plugin_class->plugin_name = GNC_PLUGIN_REGISTER2_NAME;
168 
169  /* function overrides */
170  plugin_class->add_to_window = gnc_plugin_register2_add_to_window;
171  plugin_class->remove_from_window =
172  gnc_plugin_register2_remove_from_window;
173 
174  /* widget addition/removal */
175  plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
176  plugin_class->actions = gnc_plugin_actions;
177  plugin_class->n_actions = gnc_plugin_n_actions;
178  plugin_class->ui_filename = PLUGIN_UI_FILENAME;
179 
180  g_type_class_add_private(klass, sizeof(GncPluginRegister2Private));
181 }
182 
183 static void
184 gnc_plugin_register2_init (GncPluginRegister2 *plugin)
185 {
186 }
187 
188 static void
189 gnc_plugin_register2_finalize (GObject *object)
190 {
191  GncPluginRegister2 *plugin;
193 
194  g_return_if_fail (GNC_IS_PLUGIN_REGISTER2 (object));
195 
196  plugin = GNC_PLUGIN_REGISTER2 (object);
197  priv = GNC_PLUGIN_REGISTER2_GET_PRIVATE(plugin);
198 
199  G_OBJECT_CLASS (parent_class)->finalize (object);
200 }
201 
202 /************************************************************
203  * Plugin Function Implementation *
204  ************************************************************/
205 
220 static void
221 gnc_plugin_register2_add_to_window (GncPlugin *plugin,
222  GncMainWindow *window,
223  GQuark type)
224 {
225  gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
226  gnc_plugin_register2_pref_changed, window);
227 }
228 
229 
241 static void
242 gnc_plugin_register2_remove_from_window (GncPlugin *plugin,
243  GncMainWindow *window,
244  GQuark type)
245 {
246  gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
247  gnc_plugin_register2_pref_changed, window);
248 }
249 
250 /************************************************************
251  * Command Callbacks *
252  ************************************************************/
253 
254 static void
255 gnc_plugin_register2_cmd_general_ledger (GtkAction *action,
257 {
258  GncPluginPage *page;
259 
260  g_return_if_fail (data != NULL);
261 
263  gnc_main_window_open_page (data->window, page);
264 }
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
Definition: gnc-prefs.c:128
GncPluginPage * gnc_plugin_page_register2_new_gl(void)
#define ENTER(format, args...)
Definition: qoflog.h:261
const gchar * ui_filename
Definition: gnc-plugin.h:137
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
GtkActionEntry * actions
Definition: gnc-plugin.h:122
void(* remove_from_window)(GncPlugin *plugin, GncMainWindow *window, GQuark type)
Definition: gnc-plugin.h:171
const gchar * actions_name
Definition: gnc-plugin.h:119
Generic api to store and retrieve preferences.
const gchar * plugin_name
Definition: gnc-plugin.h:112
#define PLUGIN_ACTIONS_NAME
#define LEAVE(format, args...)
Definition: qoflog.h:271
void(* add_to_window)(GncPlugin *plugin, GncMainWindow *window, GQuark type)
Definition: gnc-plugin.h:155
#define PLUGIN_UI_FILENAME
const gchar * QofLogModule
Definition: qofid.h:89
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)
Definition: gnc-prefs.c:148