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