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