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