GnuCash c935c2f+
Loading...
Searching...
No Matches
gnc-component-manager.h
1/********************************************************************\
2 * gnc-component-manager.h - GUI component manager interface *
3 * Copyright (C) 2000 Dave Peticolas <dave@krondo.com> *
4 * *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License as *
7 * published by the Free Software Foundation; either version 2 of *
8 * the License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License*
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
18\********************************************************************/
19
20#ifndef GNC_COMPONENT_MANAGER_H
21#define GNC_COMPONENT_MANAGER_H
22
23#include <glib.h>
24
25#include "qof.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31
32#define NO_COMPONENT (-1)
33
34typedef struct
35{
36 QofEventId event_mask;
37} EventInfo;
38
39
40/* GNCComponentRefreshHandler
41 * Handler invoked to inform the component that a refresh
42 * may be needed.
43 *
44 * changes: if NULL, the component should perform a refresh.
45 *
46 * if non-NULL, changes is a GncGUID hash that maps
47 * GUIDs to EventInfo structs describing which
48 * events have been received. Entities not in
49 * the hash have not generated any events.
50 * Entities which have been destroyed will be in
51 * the hash, but may not exist anymore.
52 *
53 * Note since refreshes may not occur with every change,
54 * an entity may have all three change values.
55 *
56 * The component should use 'changes' to determine whether
57 * or not a refresh is needed. The hash table must not be
58 * changed.
59 *
60 * Notes on refreshing: when the handler is invoked any engine
61 * entities used by the component may have
62 * already been deleted. 'Refreshing' the
63 * component may require closing the component.
64 *
65 * Notes on dealing with destroyed entities: As stated above, entities
66 * in the changes GHashTable may no longer exist. So how can you
67 * determine if this has happened? Well, it's a good idea to check
68 * for the QOF_EVENT_DESTROY bit in the EventInfo structure. Of
69 * course, that means you need the hash key (GncGUID) for the destroyed
70 * entity. How are you going to get the GncGUID from the entity if the
71 * entity has already been destroyed? You're not. So, you have to
72 * save a COPY of the key (GncGUID) away beforehand.
73 *
74 * user_data: user_data supplied when component was registered.
75 */
76typedef void (*GNCComponentRefreshHandler) (GHashTable *changes,
77 gpointer user_data);
78
79/* GNCComponentCloseHandler
80 * Handler invoked to close the component.
81 *
82 * user_data: user_data supplied when component was registered.
83 *
84 * Notes on closing: components are not automatically unregistered
85 * when the close handler is invoked. Components
86 * may not ignore the handler.
87 */
88typedef void (*GNCComponentCloseHandler) (gpointer user_data);
89
90
91/* GNCComponentFindHandler
92 * Handler invoked when searching for a component.
93 *
94 * find_data: find_data supplied when search was started.
95 * user_data: user_data supplied when component was registered.
96 *
97 * Return: TRUE if the component matches the search criteria.
98 */
99typedef gboolean (*GNCComponentFindHandler) (gpointer find_data,
100 gpointer user_data);
101
102/* GNCComponentHandler
103 * Generic handler used in iterating over components.
104 *
105 * component_class: class of component
106 * component_id: id of component
107 * iter_data: user_data supplied by caller
108 *
109 * Return: TRUE if the callback did something
110 */
111typedef gboolean (*GNCComponentHandler) (const char *component_class,
112 gint component_id,
113 gpointer user_data,
114 gpointer iter_data);
115
116/* gnc_component_manager_init
117 * Initialize the component manager.
118 */
119void gnc_component_manager_init (void);
120
121/* gnc_component_manager_shutdown
122 * Shutdown the component manager.
123 */
124void gnc_component_manager_shutdown (void);
125
126/* gnc_register_gui_component
127 * Register a GUI component with the manager.
128 *
129 * component_class: a string defining a class of components
130 * certain component functions can be performed
131 * on all components in a class. For that reason,
132 * components in the same class should all use
133 * the same type for user_data.
134 *
135 * refresh_cb: refresh handler, may be NULL
136 * close_cb: close handler, may be NULL
137 * user_data: user_data argument for handlers
138 *
139 *
140 * Notes: After a refresh handler is registered, the
141 * component must use the API calls below to
142 * inform the component manager which engine
143 * entities are being 'watched', i.e., which
144 * engine entities may cause the component
145 * to need refreshing.
146 *
147 * When a component is first registered, it
148 * is not watching anything, and thus will
149 * not receive refresh events.
150 *
151 * Return: id of component, or NO_COMPONENT, if error
152 */
153gint gnc_register_gui_component (const char *component_class,
154 GNCComponentRefreshHandler refresh_handler,
155 GNCComponentCloseHandler close_handler,
156 gpointer user_data);
157
158/* gnc_gui_component_set_session
159 * Set the associated session of this component
160 *
161 * component_id: id of component which is watching the entity
162 * session: the session this component is associated with
163 */
164void gnc_gui_component_set_session (gint component_id, gpointer session);
165
166/* gnc_gui_component_reset_session
167 * Reset the associated session of all components with the original session
168 *
169 * old_session: the original session
170 * new_session: the new session
171 */
172void gnc_gui_component_reset_session (gpointer old_session, gpointer new_session);
173
174/* gnc_gui_component_watch_entity
175 * Add an entity to the list of those being watched by the component.
176 * Only entities with refresh handlers should add watches.
177 *
178 * component_id: id of component which is watching the entity
179 * entity: id of entity to watch
180 * event_mask: mask which determines which kinds of events are watched
181 * setting the mask to 0 turns off watching for the entity.
182 */
183void gnc_gui_component_watch_entity (gint component_id,
184 const GncGUID *entity,
185 QofEventId event_mask);
186
187/* gnc_gui_component_watch_entity_type
188 * Watch all entities of a particular type.
189 *
190 * component_id: id of component which is watching the entity type
191 * entity_type: type of entity to watch, either GNC_ID_TRANS or
192 * GNC_ID_ACCOUNT
193 * event_mask: mask which determines which kinds of events are watched
194 * setting the mask to 0 turns off watching for the entity type
195 */
196void gnc_gui_component_watch_entity_type (gint component_id,
197 QofIdTypeConst entity_type,
198 QofEventId event_mask);
199
200/* gnc_gui_get_entity_events
201 * Return the event info of the events which have been generated by
202 * the given entity.
203 *
204 * changes: a hash of changes as in the refresh handler
205 * entity: the GncGUID of the entity to get the event mask for
206 *
207 * Returns: the event info of the entity, or NULL
208 * if it is not found.
209 */
210const EventInfo * gnc_gui_get_entity_events (GHashTable *changes,
211 const GncGUID *entity);
212
213/* gnc_gui_component_clear_watches
214 * Clear all watches for the component.
215 *
216 * component_id: id of component to clear watches for.
217 */
218void gnc_gui_component_clear_watches (gint component_id);
219
220/* gnc_unregister_gui_component
221 * Unregister a gui component from the manager.
222 *
223 * component_id: id of component to unregister
224 */
225void gnc_unregister_gui_component (gint component_id);
226
227/* gnc_unregister_gui_component_by_data
228 * Unregister a gui component using the user_data pointer.
229 *
230 * component_class: class component is in
231 * user_data: user_data pointer of component to unregister
232 * all components with that user_data in the
233 * class are unregistered.
234 */
235void gnc_unregister_gui_component_by_data (const char *component_class,
236 gpointer user_data);
237
238/* gnc_suspend_gui_refresh
239 * Suspend refresh handlers by the component manager.
240 * This routine may be called multiple times. Each call
241 * increases the suspend counter (starts at zero).
242 */
243void gnc_suspend_gui_refresh (void);
244
245/* gnc_resume_gui_refresh
246 * Resume refresh handlers by the component manager.
247 * Each call reduces the suspend counter by one. When
248 * the counter reaches zero, all changes which have
249 * occurred since the last refresh are collected and
250 * passed to the components in refresh handlers.
251 */
252void gnc_resume_gui_refresh (void);
253
254/* gnc_gui_refresh_all
255 * Force all components to refresh.
256 *
257 * This routine may only be invoked when the suspend counter
258 * is zero. It should never be mixed with the suspend/resume
259 * refresh routines.
260 */
261void gnc_gui_refresh_all (void);
262
263/* gnc_gui_refresh_suspended
264 * Return TRUE if gui refreshes are suspended.
265 */
266gboolean gnc_gui_refresh_suspended (void);
267
268/* gnc_close_gui_component
269 * Invoke the close handler for the indicated component.
270 *
271 * component_id: id of component to close
272 */
273void gnc_close_gui_component (gint component_id);
274
275/* gnc_close_gui_component_by_data
276 * Invoke the close handler for components in the given
277 * class with the given user_data.
278 *
279 * component_class: class to close components in
280 * user_data: user_data of component to close
281 * all components with that user_data
282 * are closed.
283 */
284void gnc_close_gui_component_by_data (const char *component_class,
285 gpointer user_data);
286
287/* gnc_close_gui_component_by_session
288 * Invoke the close handler for components with the given session
289 *
290 * session: session to close
291 * all components with that session
292 * are closed.
293 */
294void gnc_close_gui_component_by_session (gpointer session);
295
296/* gnc_find_gui_components
297 * Search for components in the specified class.
298 *
299 * component_class: the class to search for components in
300 * must be non-NULL
301 * find_cb: the handler used to search for the component
302 * if NULL, all components in class are returned
303 * find_data: find_data passed to find_cb
304 *
305 * Returns: GList of user_data of found components, or NULL if none found
306 * The list should be freed with g_list_free().
307 *
308 * Notes on finding: components should not be registered or unregistered
309 * by the find callback.
310 */
311GList * gnc_find_gui_components (const char *component_class,
312 GNCComponentFindHandler find_handler,
313 gpointer find_data);
314
315/* gnc_find_first_gui_component
316 * Search for the first matching component in the specified class.
317 *
318 * component_class: the class to search for components in
319 * must be non-NULL
320 * find_cb: the handler used to search for the component
321 * must be non-null
322 * find_data: find_data passed to find_cb
323 *
324 * Returns: user_data of first found component, or NULL if none found
325 *
326 * Notes on finding: components should not be registered or unregistered
327 * by the find callback.
328 */
329gpointer gnc_find_first_gui_component (const char *component_class,
330 GNCComponentFindHandler find_handler,
331 gpointer find_data);
332
333/* gnc_forall_gui_components
334 * Invoke 'handler' for components in the database.
335 *
336 * component_class: class to iterate over, if NULL then
337 * all classes are iterated over
338 * handler: handler to invoke
339 * iter_data: data passed to handler
340 *
341 * Notes on forall: components may be unregistered by the handler,
342 * but no components should be registered.
343 */
344gint gnc_forall_gui_components (const char *component_class,
345 GNCComponentHandler handler,
346 gpointer iter_data);
347
348#ifdef __cplusplus
349}
350#endif
351
352#endif
const gchar * QofIdTypeConst
QofIdTypeConst declaration.
Definition qofid.h:82
gint QofEventId
Define the type of events allowed.
Definition qofevent.h:45
The type used to store guids in C.
Definition guid.h:75