Added close_all_but_initial() function call
[modest] / src / widgets / modest-window-mgr.h
1 /* Copyright (c) 2006,2007 Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef __MODEST_WINDOW_MGR_H__
31 #define __MODEST_WINDOW_MGR_H__
32
33 #include <glib-object.h>
34 #include "modest-window.h"
35
36 G_BEGIN_DECLS
37
38 /* convenience macros */
39 #define MODEST_TYPE_WINDOW_MGR             (modest_window_mgr_get_type())
40 #define MODEST_WINDOW_MGR(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_WINDOW_MGR,ModestWindowMgr))
41 #define MODEST_WINDOW_MGR_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_WINDOW_MGR,ModestWindowMgrClass))
42 #define MODEST_IS_WINDOW_MGR(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_WINDOW_MGR))
43 #define MODEST_IS_WINDOW_MGR_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_WINDOW_MGR))
44 #define MODEST_WINDOW_MGR_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_WINDOW_MGR,ModestWindowMgrClass))
45
46 typedef struct _ModestWindowMgr      ModestWindowMgr;
47 typedef struct _ModestWindowMgrClass ModestWindowMgrClass;
48
49 struct _ModestWindowMgr {
50          GObject parent;
51 };
52
53 struct _ModestWindowMgrClass {
54         GObjectClass parent_class;
55
56         /* Virtuals */
57         gboolean              (*register_window)                (ModestWindowMgr *self,
58                                                                  ModestWindow *window,
59                                                                  ModestWindow *parent);
60         void                  (*unregister_window)              (ModestWindowMgr *self,
61                                                                  ModestWindow *window);
62         void                  (*set_fullscreen_mode)            (ModestWindowMgr *self,
63                                                                  gboolean on);
64         gboolean              (*get_fullscreen_mode)            (ModestWindowMgr *self);
65         void                  (*show_toolbars)                  (ModestWindowMgr *self,
66                                                                  GType window_type,
67                                                                  gboolean show_toolbars,
68                                                                  gboolean fullscreen);
69 #ifndef MODEST_TOOLKIT_HILDON2
70         ModestWindow *        (*get_main_window)                (ModestWindowMgr *self,
71                                                                  gboolean show);
72 #endif
73         gboolean              (*close_all_windows)              (ModestWindowMgr *self);
74         GtkWindow *           (*get_modal)                      (ModestWindowMgr *self);
75         void                  (*set_modal)                      (ModestWindowMgr *self,
76                                                                  GtkWindow *window,
77                                                                  GtkWindow *parent);
78         gboolean              (*find_registered_header)         (ModestWindowMgr *self,
79                                                                  TnyHeader *header,
80                                                                  ModestWindow **win);
81         gboolean              (*find_registered_message_uid)    (ModestWindowMgr *self,
82                                                                  const gchar *msg_uid,
83                                                                  ModestWindow **win);
84         GList *               (*get_window_list)                (ModestWindowMgr *self);
85         ModestWindow *        (*show_initial_window)            (ModestWindowMgr *self);
86         ModestWindow *        (*get_current_top)                (ModestWindowMgr *self);
87         gboolean              (*close_all_but_initial)          (ModestWindowMgr *self);
88
89         gboolean              (*screen_is_on)                   (ModestWindowMgr *self);
90         void                  (*create_caches)                  (ModestWindowMgr *self);
91
92         /* Signals */
93         void (*window_list_empty) (ModestWindowMgr *self);
94         void (*progress_list_changed) (ModestWindowMgr *self);
95 };
96
97
98 /* member functions */
99 GType        modest_window_mgr_get_type    (void) G_GNUC_CONST;
100
101 /* typical parameter-less _new function */
102 ModestWindowMgr*    modest_window_mgr_new         (void);
103
104
105 /**
106  * modest_window_mgr_register_window:
107  * @self: the #ModestWindowMgr
108  * @window: a #ModestWindow
109  * 
110  * Registers a new window in the window manager. The window manager
111  * will keep a reference.
112  **/
113 gboolean           modest_window_mgr_register_window       (ModestWindowMgr *self, 
114                                                             ModestWindow *window,
115                                                             ModestWindow *parent);
116
117 /**
118  * modest_window_mgr_unregister_window:
119  * @self: the #ModestWindowMgr
120  * @window: a #ModestWindow
121  * 
122  * Unregisters a given window from the window manager. The window
123  * manager will free its reference to it.
124  **/
125 void           modest_window_mgr_unregister_window     (ModestWindowMgr *self, 
126                                                         ModestWindow *window);
127
128 /**
129  * modest_window_mgr_register_banner:
130  * @self: a #ModestWindowMgr
131  *
132  * Increase the count of pending banners in the window manager
133  */
134 void           modest_window_mgr_register_banner (ModestWindowMgr *self);
135
136 /**
137  * modest_window_mgr_unregister_banner:
138  * @self: a #ModestWindowMgr
139  *
140  * Decrease the count of pending banners in the window manager
141  */
142 void           modest_window_mgr_unregister_banner (ModestWindowMgr *self);
143
144 /**
145  * modest_window_mgr_set_fullscreen_mode:
146  * @self: a #ModestWindowMgr
147  * @on: a #gboolean
148  * 
149  * sets/unsets the application windows in fullscreen mode
150  **/
151 void           modest_window_mgr_set_fullscreen_mode   (ModestWindowMgr *self,
152                                                         gboolean on);
153
154 /**
155  * modest_window_mgr_get_fullscreen_mode:
156  * @self: a #ModestWindowMgr
157  * 
158  * gets the application current fullscreen mode
159  *
160  * Return value: TRUE is the application is in fullscrenn mode,
161  * otherwise FALSE
162  **/
163 gboolean       modest_window_mgr_get_fullscreen_mode   (ModestWindowMgr *self);
164
165
166 /**
167  * modest_window_mgr_show_toolbars:
168  * @self: a #ModestWindowMgr
169  * @window_type: apply the show toolbars command only to the windows of this type
170  * @show_toolbar: whether or not the toolbars should be shown
171  * @fullscreen: TRUE/FALSE for show/hide in fullscreen mode, otherwise
172  * it applies to normal mode
173  * 
174  * shows or hides the toolbars of the registered windows. Note that if
175  * the #fullscreen attribute is TRUE and the application is in normal
176  * mode, you will not see the changes until the application switches
177  * to fullscreen mode and viceversa
178  **/
179 void           modest_window_mgr_show_toolbars         (ModestWindowMgr *self,
180                                                         GType window_type,
181                                                         gboolean show_toolbars,
182                                                         gboolean fullscreen);
183 #ifndef MODEST_TOOLKIT_HILDON2
184 /**
185  * modest_window_mgr_get_main_window:
186  * @self: a #ModestWindowMgr
187  * @show: if TRUE, create the main window and show it if it was not existing.
188  *
189  * get the main window, and depending on @create, create one if it does not exist yet
190  *
191  * Returns: the main window or NULL in case of error, or the main-window
192  * did not yet exist
193  **/
194 ModestWindow*  modest_window_mgr_get_main_window       (ModestWindowMgr *self,
195                                                         gboolean show);
196
197 /**
198  * modest_window_mgr_set_main_window:
199  * @self: a #ModestWindowMgr
200  * @main_win: a #ModestMainWindow
201  */
202 void modest_window_mgr_set_main_window (ModestWindowMgr *self, ModestWindow *main_win);
203
204
205 /**
206  * modest_window_mgr_main_window_exists:
207  * @self: a #ModestWindowMgr
208  *
209  * do we have a main window?
210  *
211  * Returns: TRUE if there's a main window, FALSE otherwise
212  **/
213 gboolean  modest_window_mgr_main_window_exists       (ModestWindowMgr *self);
214 #endif
215
216 /**
217  * modest_window_mgr_get_modal:
218  * @self: a #ModestWindowMgr
219  *
220  * get the modal window; if it's NULL, there's no active modal window
221  *
222  * Returns: the modal window or NULL
223  **/
224 GtkWindow*    modest_window_mgr_get_modal  (ModestWindowMgr *self);
225
226
227 /**
228  * modest_window_mgr_get_easysetup_dialog:
229  * @self: a #ModestWindowMgr
230  *
231  * set the modal dialog; set it to NULL after destroying the dialog
232  *
233  **/
234 void          modest_window_mgr_set_modal  (ModestWindowMgr *self,
235                                             GtkWindow *window,
236                                             GtkWindow *parent);
237
238 /**
239  * modest_window_mgr_prevent_hibernation_while_window_is_shown:
240  * @self: a #ModestWindowMgr
241  * @window: The window that should prevent hibernation while it is shown.
242  * 
243  * Call this if hibernation should not be allowed because 
244  * windows are open whose state cannot sensible be saved, such as Account 
245  * Settings dialogs.
246  * This causes modest_window_mgr_get_hibernation_is_prevented() to return TRUE 
247  * until all such windows have been closed. That means, until the windows have 
248  * been hidden - window destruction or other memory management is not relevant.
249  **/
250 void modest_window_mgr_prevent_hibernation_while_window_is_shown (ModestWindowMgr *self, 
251         GtkWindow *window);
252
253
254
255 /**
256  * modest_window_mgr_register_help_id
257  * @self: a #ModestWindowMgr
258  * @win: some window
259  * @help_id: the help_id for this window
260  * 
261  * register a help id for a window
262  **/
263 void
264 modest_window_mgr_register_help_id (ModestWindowMgr *self, GtkWindow *win, const gchar* help_id);
265
266
267 /**
268  * modest_window_mgr_get_help_id:
269  * @self: a #ModestWindowMgr
270  * @win: some window
271  * 
272  * get the help id for a window; if the window is the main-window and some folder is
273  * selected, it will return the proper help_id for that
274  *
275  * Returns: a help _id
276  **/
277 const gchar*
278 modest_window_mgr_get_help_id (ModestWindowMgr *self, GtkWindow *win);
279
280
281
282 /**
283  * modest_window_mgr_find_registered_header
284  * @self: a #ModestWindowMgr
285  * @header: a valid #TnyHeader
286  * 
287  * search for the given uid in both the list of preregistered uids and in the window list;
288  * if it's available in the window list, fill the *win out-param
289  *
290  * returns TRUE if found, FALSE otherwise
291  **/
292 gboolean modest_window_mgr_find_registered_header (ModestWindowMgr *self,  TnyHeader *header,
293                                                ModestWindow **win);
294
295
296 /**
297  * modest_window_mgr_find_registered_header
298  * @self: a #ModestWindowMgr
299  * @msg_uid: a message uid
300  * 
301  * search for the given uid in both the list of preregistered uids and in the window list;
302  * if it's available in the window list, fill the *win out-param
303  *
304  * returns TRUE if found, FALSE otherwise
305  **/
306 gboolean modest_window_mgr_find_registered_message_uid (ModestWindowMgr *self,  const gchar *msg_uid,
307                                                         ModestWindow **win);
308
309 /**
310  * modest_window_mgr_get_window_list:
311  * @self: a #ModestWindowMgr
312  *
313  * get the list of windows registered in window mgr.
314  *
315  * Returns: a #GList, that caller should free
316  */
317 GList *modest_window_mgr_get_window_list (ModestWindowMgr *self);
318
319 /**
320  * modest_window_mgr_close_all_windows
321  * @self: a #ModestWindowMgr
322  * 
323  * Close all registered windows. If failed (for example because
324  * one confirmation dialog rejected the operation), return %FALSE
325  **/
326 gboolean modest_window_mgr_close_all_windows (ModestWindowMgr *self);
327
328 /**
329  * modest_window_mgr_register_header
330  * @self: a #ModestWindowMgr
331  * @header: a valid #TnyHeader
332  * @alt_uid: alternative uid in case @header does not provide one
333  * 
334  * register the uid, even before the window is created. thus, we know when
335  * some window creation might already be underway. the uid will automatically be
336  * removed when the window itself will registered
337  * 
338  **/
339 void  modest_window_mgr_register_header   (ModestWindowMgr *self,  TnyHeader *header, const gchar *alt_uid);
340         
341
342 /**
343  * modest_window_mgr_unregister_header
344  * @self: a #ModestWindowMgr
345  * @header: a valid #TnyHeader
346  * 
347  * unregister the uid. We could need to do that if there is any error
348  * retrieving a message. In that case the window will not be
349  * registered and thus the header will not be removed, so we must do
350  * it manually
351  **/
352 void  modest_window_mgr_unregister_header (ModestWindowMgr *self,  TnyHeader *header);
353
354 /**
355  * modest_window_mgr_get_hibernation_is_prevented:
356  * @self: a #ModestWindowMgr
357  * @result: Whether any windows are currently preventing hibernation.
358  * 
359  * Use this to discover whether hibernation should not be allowed because 
360  * windows are open whose state cannot sensible be saved, such as Account 
361  * Settings dialogs. This function will return true after someone has called 
362  * modest_window_mgr_prevent_hibernation_while_window_is_shown() and before 
363  * that window has been closed.
364  **/
365 gboolean modest_window_mgr_get_hibernation_is_prevented (ModestWindowMgr *self);
366
367 /**
368  * modest_window_mgr_save_state_for_all_windows:
369  * @self: a #ModestWindowMgr
370  * 
371  * Save any state for all windows. For instance, call this before allowing 
372  * application hibernation.
373  **/
374 void modest_window_mgr_save_state_for_all_windows (ModestWindowMgr *self);
375
376 /**
377  * modest_window_mgr_get_num_windows:
378  * @self: a #ModestWindowMgr
379  * 
380  * Gets the number of already registered windows, and pending banners
381  *
382  * Returns: the number of already registered windows, and pending banners
383  **/
384 guint modest_window_mgr_get_num_windows (ModestWindowMgr *self);
385
386 /**
387  * modest_window_mgr_get_msg_view_window:
388  * @self: a #ModestWindowMgr
389  *
390  * obtain a cached #ModestMsgViewWindow if available, or construct a new
391  * one.
392  *
393  * Returns: a #ModestMsgViewWindow
394  */
395 GtkWidget *   modest_window_mgr_get_msg_view_window (ModestWindowMgr *self);
396
397 /**
398  * modest_window_mgr_get_msg_edit_window:
399  * @self: a #ModestWindowMgr
400  *
401  * obtain a cached #ModestMsgEditWindow if available, or construct a new
402  * one.
403  *
404  * Returns: a #ModestMsgEditWindow
405  */
406 GtkWidget *   modest_window_mgr_get_msg_edit_window (ModestWindowMgr *self);
407
408 /**
409  * modest_window_mgr_show_initial_window:
410  * @self: a #ModestWindowMgr
411  *
412  * This function determines which is the window that should be
413  * initially launched. After that it shows that window. If there is no
414  * account available this function also launches the account setup
415  * wizard.
416  *
417  * Returns: the initial window. NULL if something goes wrong
418  **/
419 ModestWindow* modest_window_mgr_show_initial_window (ModestWindowMgr *self);
420
421 /**
422  * modest_window_mgr_get_current_top:
423  * @self: a #ModestWindowMgr
424  * 
425  * this function returns the ModestWindow that is currently on top of all the others
426  * 
427  * Returns: the topmost #ModestWindow
428  **/
429 ModestWindow* modest_window_mgr_get_current_top (ModestWindowMgr *self);
430
431 /**
432  * modest_window_mgr_screen_is_on:
433  * @self: a #ModestWindowMgr
434  *
435  * this function returns if device display is on or not
436  *
437  * Returns: %TRUE if screen is on, %FALSE if not
438  */
439 gboolean modest_window_mgr_screen_is_on (ModestWindowMgr *self);
440
441 /**
442  * modest_window_mgr_get_progress_operations:
443  * @self: a #ModestWindowMgr
444  *
445  * get a list of operations in progress
446  *
447  * Returns: a newly allocated #TnyList
448  */
449 TnyList *modest_window_mgr_get_progress_operations (ModestWindowMgr *self);
450
451 /**
452  * modest_window_mgr_has_progress_operation:
453  * @self: a #ModestWindowMgr
454  *
455  * is there are send/receive or receive operations in progress for any account.
456  *
457  * Returns: %TRUE if receive progress operations are in progress.
458  */
459 gboolean modest_window_mgr_has_progress_operation (ModestWindowMgr *self);
460
461 /**
462  * modest_window_mgr_has_progress_operation_on_account:
463  * @self: a #ModestWindowMgr
464  * @account_name: a string
465  *
466  * is there are send/receive or receive operations in progress for @account_name.
467  *
468  * Returns: %TRUE if receive progress operations are in progress.
469  */
470 gboolean modest_window_mgr_has_progress_operation_on_account (ModestWindowMgr *self,
471                                                               const gchar *account_name);
472
473 /**
474  * modest_window_mgr_create_caches:
475  * @self: a #ModestWindowMgr
476  *
477  * creates cached windows. This is called in modest main, just before the show-ui
478  * code. So it should be valid for the two startup ways (with --show-ui and without).
479  */
480 void modest_window_mgr_create_caches (ModestWindowMgr *self);
481
482 /**
483  * modest_window_mgr_close_all_but_initial:
484  * @self: a #ModestWindowMgr
485  *
486  * closes all but the initial window.
487  *
488  * Returns: %TRUE if the initial window is returned in @initial_window
489  * and it does not have any other dialog or window on top, otherwhise
490  * %FALSE
491  */
492 gboolean modest_window_mgr_close_all_but_initial (ModestWindowMgr *self);
493
494
495 G_END_DECLS
496
497 #endif /* __MODEST_WINDOW_MGR_H__ */