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