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