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