GnuCash  5.6-150-g038405b370+
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
28 extern "C" {
29 #endif
30 
31 
32 #define NO_COMPONENT (-1)
33 
34 typedef 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  */
76 typedef 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  */
88 typedef 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  */
99 typedef 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  */
111 typedef 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  */
119 void gnc_component_manager_init (void);
120 
121 /* gnc_component_manager_shutdown
122  * Shutdown the component manager.
123  */
124 void 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  */
153 gint 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  */
164 void gnc_gui_component_set_session (gint component_id, gpointer session);
165 
166 /* gnc_gui_component_watch_entity
167  * Add an entity to the list of those being watched by the component.
168  * Only entities with refresh handlers should add watches.
169  *
170  * component_id: id of component which is watching the entity
171  * entity: id of entity to watch
172  * event_mask: mask which determines which kinds of events are watched
173  * setting the mask to 0 turns off watching for the entity.
174  */
175 void gnc_gui_component_watch_entity (gint component_id,
176  const GncGUID *entity,
177  QofEventId event_mask);
178 
179 /* gnc_gui_component_watch_entity_type
180  * Watch all entities of a particular type.
181  *
182  * component_id: id of component which is watching the entity type
183  * entity_type: type of entity to watch, either GNC_ID_TRANS or
184  * GNC_ID_ACCOUNT
185  * event_mask: mask which determines which kinds of events are watched
186  * setting the mask to 0 turns off watching for the entity type
187  */
188 void gnc_gui_component_watch_entity_type (gint component_id,
189  QofIdTypeConst entity_type,
190  QofEventId event_mask);
191 
192 /* gnc_gui_get_entity_events
193  * Return the event info of the events which have been generated by
194  * the given entity.
195  *
196  * changes: a hash of changes as in the refresh handler
197  * entity: the GncGUID of the entity to get the event mask for
198  *
199  * Returns: the event info of the entity, or NULL
200  * if it is not found.
201  */
202 const EventInfo * gnc_gui_get_entity_events (GHashTable *changes,
203  const GncGUID *entity);
204 
205 /* gnc_gui_component_clear_watches
206  * Clear all watches for the component.
207  *
208  * component_id: id of component to clear watches for.
209  */
210 void gnc_gui_component_clear_watches (gint component_id);
211 
212 /* gnc_unregister_gui_component
213  * Unregister a gui component from the manager.
214  *
215  * component_id: id of component to unregister
216  */
217 void gnc_unregister_gui_component (gint component_id);
218 
219 /* gnc_unregister_gui_component_by_data
220  * Unregister a gui component using the user_data pointer.
221  *
222  * component_class: class component is in
223  * user_data: user_data pointer of component to unregister
224  * all components with that user_data in the
225  * class are unregistered.
226  */
227 void gnc_unregister_gui_component_by_data (const char *component_class,
228  gpointer user_data);
229 
230 /* gnc_suspend_gui_refresh
231  * Suspend refresh handlers by the component manager.
232  * This routine may be called multiple times. Each call
233  * increases the suspend counter (starts at zero).
234  */
235 void gnc_suspend_gui_refresh (void);
236 
237 /* gnc_resume_gui_refresh
238  * Resume refresh handlers by the component manager.
239  * Each call reduces the suspend counter by one. When
240  * the counter reaches zero, all changes which have
241  * occurred since the last refresh are collected and
242  * passed to the components in refresh handlers.
243  */
244 void gnc_resume_gui_refresh (void);
245 
246 /* gnc_gui_refresh_all
247  * Force all components to refresh.
248  *
249  * This routine may only be invoked when the suspend counter
250  * is zero. It should never be mixed with the suspend/resume
251  * refresh routines.
252  */
253 void gnc_gui_refresh_all (void);
254 
255 /* gnc_gui_refresh_suspended
256  * Return TRUE if gui refreshes are suspended.
257  */
258 gboolean gnc_gui_refresh_suspended (void);
259 
260 /* gnc_close_gui_component
261  * Invoke the close handler for the indicated component.
262  *
263  * component_id: id of component to close
264  */
265 void gnc_close_gui_component (gint component_id);
266 
267 /* gnc_close_gui_component_by_data
268  * Invoke the close handler for components in the given
269  * class with the given user_data.
270  *
271  * component_class: class to close components in
272  * user_data: user_data of component to close
273  * all components with that user_data
274  * are closed.
275  */
276 void gnc_close_gui_component_by_data (const char *component_class,
277  gpointer user_data);
278 
279 /* gnc_close_gui_component_by_session
280  * Invoke the close handler for components with the given session
281  *
282  * session: session to close
283  * all components with that session
284  * are closed.
285  */
286 void gnc_close_gui_component_by_session (gpointer session);
287 
288 /* gnc_find_gui_components
289  * Search for components in the specified class.
290  *
291  * component_class: the class to search for components in
292  * must be non-NULL
293  * find_cb: the handler used to search for the component
294  * if NULL, all components in class are returned
295  * find_data: find_data passed to find_cb
296  *
297  * Returns: GList of user_data of found components, or NULL if none found
298  * The list should be freed with g_list_free().
299  *
300  * Notes on finding: components should not be registered or unregistered
301  * by the find callback.
302  */
303 GList * gnc_find_gui_components (const char *component_class,
304  GNCComponentFindHandler find_handler,
305  gpointer find_data);
306 
307 /* gnc_find_first_gui_component
308  * Search for the first matching component in the specified class.
309  *
310  * component_class: the class to search for components in
311  * must be non-NULL
312  * find_cb: the handler used to search for the component
313  * must be non-null
314  * find_data: find_data passed to find_cb
315  *
316  * Returns: user_data of first found component, or NULL if none found
317  *
318  * Notes on finding: components should not be registered or unregistered
319  * by the find callback.
320  */
321 gpointer gnc_find_first_gui_component (const char *component_class,
322  GNCComponentFindHandler find_handler,
323  gpointer find_data);
324 
325 /* gnc_forall_gui_components
326  * Invoke 'handler' for components in the database.
327  *
328  * component_class: class to iterate over, if NULL then
329  * all classes are iterated over
330  * handler: handler to invoke
331  * iter_data: data passed to handler
332  *
333  * Notes on forall: components may be unregistered by the handler,
334  * but no components should be registered.
335  */
336 gint gnc_forall_gui_components (const char *component_class,
337  GNCComponentHandler handler,
338  gpointer iter_data);
339 
340 #ifdef __cplusplus
341 }
342 #endif
343 
344 #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