f6206408d018b5dab91c8faa70b64a85009ac958
[modest] / src / widgets / modest-header-view.h
1 /* Copyright (c) 2006, 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_HEADER_VIEW_H__
31 #define __MODEST_HEADER_VIEW_H__
32
33 #include <tny-folder.h>
34 #include <tny-folder-change.h>
35 #include <tny-gtk-account-list-model.h>
36 #include <tny-msg.h>
37 #include <tny-header.h>
38 #include <tny-gtk-header-list-model.h>
39 #include "modest-window.h"
40 #include "modest-mail-operation.h"
41 #include "modest-header-view-observer.h"
42
43 G_BEGIN_DECLS
44
45 /* convenience macros */
46 #define MODEST_TYPE_HEADER_VIEW             (modest_header_view_get_type())
47 #define MODEST_HEADER_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_HEADER_VIEW,ModestHeaderView))
48 #define MODEST_HEADER_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_HEADER_VIEW,ModestHeaderViewClass))
49 #define MODEST_IS_HEADER_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_HEADER_VIEW))
50 #define MODEST_IS_HEADER_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_HEADER_VIEW))
51 #define MODEST_HEADER_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_HEADER_VIEW,ModestHeaderViewClass))
52
53 typedef struct _ModestHeaderView      ModestHeaderView;
54 typedef struct _ModestHeaderViewClass ModestHeaderViewClass;
55
56 struct _ModestHeaderView {
57          GtkTreeView parent;
58         /* insert public members, if any */
59 };
60
61 #define MODEST_HEADER_VIEW_COLUMN    "header-view-column"
62 #define MODEST_HEADER_VIEW_FLAG_SORT "header-view-flags-sort"
63
64 typedef enum _ModestHeaderViewColumn {
65         MODEST_HEADER_VIEW_COLUMN_FROM,
66         MODEST_HEADER_VIEW_COLUMN_TO,
67         MODEST_HEADER_VIEW_COLUMN_SUBJECT,
68         MODEST_HEADER_VIEW_COLUMN_SENT_DATE,
69         MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE,
70         MODEST_HEADER_VIEW_COLUMN_ATTACH,
71         MODEST_HEADER_VIEW_COLUMN_SIZE,
72         MODEST_HEADER_VIEW_COLUMN_STATUS,
73
74         /*
75          * these two are for compact display on small devices,
76          * with two line display with all relevant headers
77          */
78         MODEST_HEADER_VIEW_COLUMN_COMPACT_FLAG, /* priority and attachments */
79         MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN, /* incoming mail */
80         MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,/* outgoing mail */
81         MODEST_HEADER_VIEW_COLUMN_COMPACT_SENT_DATE,
82         MODEST_HEADER_VIEW_COLUMN_COMPACT_RECEIVED_DATE,
83
84         MODEST_HEADER_VIEW_COLUMN_NUM
85         
86 } ModestHeaderViewColumn;
87
88 /*
89  * this can be extended with more style thingies,
90  * to make a small-device specific display
91  */
92 typedef enum _ModestHeaderViewStyle {
93         MODEST_HEADER_VIEW_STYLE_DETAILS   = 0, /* many columns, single line, col headers visible */
94         MODEST_HEADER_VIEW_STYLE_TWOLINES  = 1, /* two-line headers, col headers invisible */
95         
96         MODEST_HEADER_VIEW_STYLE_NUM    
97 } ModestHeaderViewStyle;
98
99 typedef enum _ModestItemType {
100         MODEST_ITEM_TYPE_MESSAGE,
101         MODEST_ITEM_TYPE_FOLDER,
102         MODEST_ITEM_TYPE_NUM
103 } ModestItemType;
104
105
106 typedef enum _ModestHeaderViewFilter {
107         MODEST_HEADER_VIEW_FILTER_NONE = 0,
108         MODEST_HEADER_VIEW_FILTER_MOVEABLE = 1 << 0,
109         MODEST_HEADER_VIEW_FILTER_DELETABLE = 1 << 1,
110 } ModestHeaderViewFilter;
111
112 struct _ModestHeaderViewClass {
113         GtkTreeViewClass parent_class;
114
115         void (*header_selected) (ModestHeaderView* self,
116                                  TnyHeader *header,
117                                  gpointer user_data);
118
119         void (*item_not_found) (ModestHeaderView* self,
120                                 ModestItemType type,
121                                 gpointer user_data);
122
123         void (*header_activated) (ModestHeaderView* self,
124                                   TnyHeader *header,
125                                   GtkTreePath *path,
126                                   gpointer user_data);
127
128         void (*msg_count_changed) (ModestHeaderView* self,
129                                    TnyFolder *folder,
130                                    TnyFolderChange *change,
131                                    gpointer user_data);
132
133         void (*updating_msg_list) (ModestHeaderView *self,
134                                    gboolean starting,
135                                    gpointer user_data);
136 };
137
138 /**
139  * modest_header_view_get_type:
140  * 
141  * get the GType for ModestHeaderView
142  *  
143  * Returns: the GType
144  */
145 GType        modest_header_view_get_type    (void) G_GNUC_CONST;
146
147
148 /**
149  * modest_header_view_new:
150  * @folder: a TnyMsgFolder object
151  * @style: a ModestHeaderViewColumn with the style of this listview
152  *  (   MODEST_HEADER_VIEW_STYLE_NORMAL or MODEST_HEADER_VIEW_STYLE_COMPACT)
153  * 
154  * create a new ModestHeaderView instance, based on a folder iface
155  *   
156  * Returns: a new GtkWidget (a GtkTreeView-subclass)
157  */
158 GtkWidget*   modest_header_view_new        (TnyFolder *folder,
159                                             ModestHeaderViewStyle style);
160
161 /**
162  * modest_header_view_set_folder:
163  * @self: a ModestHeaderView instance
164  * @folder: a TnyFolder object
165  * 
166  * set the folder for this ModestHeaderView
167  */
168 void         modest_header_view_set_folder (ModestHeaderView *self,
169                                             TnyFolder *folder,
170                                             gboolean refresh,
171                                             ModestWindow *progress_window,
172                                             RefreshAsyncUserCallback callback,
173                                             gpointer user_data);
174
175 /**
176  * modest_header_view_get_folder:
177  * @self: a ModestHeaderView instance
178  * 
179  * get the folder in this ModestHeaderView
180  *  
181  * Returns: the tny folder instance or NULL if there is none
182  */
183 TnyFolder *modest_header_view_get_folder (ModestHeaderView *self);
184
185
186 /**
187  * modest_header_view_set_columns:
188  * @self: a ModestHeaderView instance
189  * @columns: a list of gint ModestHeaderViewColumn column IDs, using GINT_TO_POINTER() and GPOINTER_TO_INT().
190  * @type: #TnyFolderType type
191  * 
192  * set the columns for this ModestHeaderView.
193  *  
194  * Returns: TRUE if it succeeded, FALSE otherwise
195  */
196 gboolean modest_header_view_set_columns (ModestHeaderView *self,
197                                          const GList *columns,
198                                          TnyFolderType type);
199 /**
200  * modest_header_view_get_columns:
201  * @self: a ModestHeaderView instance
202  * 
203  * get the GtkTreeColumns for this ModestHeaderView. Each one of the
204  * tree columns will have property  than can be retrieved
205  * with g_object_get_data MODEST_HEADER_VIEW_COLUMN (#define),
206  * and which contains the corresponding ModestHeaderViewColumn
207  *  
208  * Returns: newly allocated list of #GtkTreeViewColumns objects, or NULL in case of no columns or error
209  * You must free the list with g_list_free
210  */
211 GList*  modest_header_view_get_columns (ModestHeaderView *self);
212
213
214 /**
215  * modest_header_view_set_style:
216  * @self: a ModestHeaderView instance
217  * @style: the style for this tree view
218  * 
219  * set the style for this ModestHeaderView
220  *  
221  * Returns: TRUE if it succeeded, FALSE otherwise
222  */
223 gboolean   modest_header_view_set_style (ModestHeaderView *self,
224                                          ModestHeaderViewStyle style);
225
226 /**
227  * modest_header_view_set_folder:
228  * @self: a ModestHeaderView instance
229  * 
230  * get the style for this ModestHeaderView
231  *  
232  * Returns: the current style
233  */
234 ModestHeaderViewStyle   modest_header_view_get_style (ModestHeaderView *self);
235
236 /**
237  * modest_header_view_count_selected_headers:
238  * @self: a ModestHeaderView instance
239  * 
240  * Check selected headers counter. 
241  * Returns: the number of selected headers.
242  */
243 guint
244 modest_header_view_count_selected_headers (ModestHeaderView *self);
245
246 /**
247  * modest_header_view_has_selected_headers:
248  * @self: a ModestHeaderView instance
249  * 
250  * Check if any row is selected on headers tree view. 
251  * Returns: TRUE if any header is selected, FALSE otherwise.
252  */
253 gboolean
254 modest_header_view_has_selected_headers (ModestHeaderView *self);
255
256 /**
257  * modest_header_view_get_selected_headers:
258  * @self: a ModestHeaderView instance
259  * 
260  * get the list of the currently selected TnyHeader's. The list and
261  * the headers should be freed by the caller
262  *  
263  * Returns: the list with the currently selected headers
264  */
265 TnyList* modest_header_view_get_selected_headers (ModestHeaderView *self);
266
267
268 /**
269  * modest_header_view_is_empty:
270  * @self: a valid ModestHeaderView instance
271  * 
272  * see if this header view is empty; use this function instead of
273  * using the GtkTreeView parent directly, as 'empty' in this case
274  * may mean that there is one "This is empty"-message, and of course
275  * GtkTreeView then thinks it is *not* empty
276  *  
277  * Returns: TRUE if the header view is empty, FALSE otherwise
278  */
279 gboolean  modest_header_view_is_empty (ModestHeaderView *self);
280
281
282
283 /**
284  * modest_header_view_select_next:
285  * @self: a #ModestHeaderView
286  * 
287  * Selects the header next to the current selected one
288  **/
289 void         modest_header_view_select_next          (ModestHeaderView *self);
290
291 /**
292  * modest_header_view_select_prev:
293  * @self: a #ModestHeaderView
294  * 
295  * Selects the previous header of the current selected one
296  **/
297 void         modest_header_view_select_prev          (ModestHeaderView *self);
298
299
300 /* PROTECTED method. It's useful when we want to force a given
301    selection to reload a msg. For example if we have selected a header
302    in offline mode, when Modest become online, we want to reload the
303    message automatically without an user click over the header */
304 void 
305 _modest_header_view_change_selection (GtkTreeSelection *selection,
306                                       gpointer user_data);
307
308 /**
309  * modest_header_view_get_sort_column_id:
310  * @self: a #ModestHeaderView
311  * @type: #TnyFolderType type
312  * 
313  * Gets the selected logical columnd id for sorting.
314  **/
315 gint
316 modest_header_view_get_sort_column_id (ModestHeaderView *self, TnyFolderType type);
317
318 /**
319  * modest_header_view_get_sort_type:
320  * @self: a #ModestHeaderView
321  * @type: #TnyFolderType type
322  * 
323  * Gets the selected sort type.
324  **/
325 GtkSortType
326 modest_header_view_get_sort_type (ModestHeaderView *self, TnyFolderType type);
327
328 /**
329  * modest_header_view_set_sort_params:
330  * @self: a #ModestHeaderView
331  * @sort_colid: logical column id to sort
332  * @sort_type: #GtkSortType sort type
333  * @type: #TnyFolderType type
334  * 
335  * Sets the logical columnd id and sort type for sorting operations.
336  **/
337 void
338 modest_header_view_set_sort_params (ModestHeaderView *self, guint sort_colid, GtkSortType sort_type, TnyFolderType type);
339
340 /**
341  * modest_header_view_set_sort_params:
342  * @self: a #ModestHeaderView
343  * @sort_colid: logical column id to sort
344  * @sort_type: #GtkSortType sort type
345  * 
346  * Sorts headers treeview by logical column id, @sort_colid, using a 
347  * @sort_type sorting method. In addition, new headder settings will be 
348  * stored in @self object. 
349  **/
350 void
351 modest_header_view_sort_by_column_id (ModestHeaderView *self, 
352                                       guint sort_colid,
353                                       GtkSortType sort_type);
354
355 /**
356  * modest_header_view_clear:
357  * @self: a #ModestHeaderView
358  *
359  * Clear the contents of a header view. It internally calls the
360  * set_folder function with last three arguments as NULL
361  **/
362 void
363 modest_header_view_clear (ModestHeaderView *self);
364
365 /**
366  * modest_header_view_copy_selection:
367  * @self: a #ModestHeaderView
368  * 
369  * Stores a #TnyList of selected headers in the own clibpoard of 
370  * @self header view.
371  **/
372 void 
373 modest_header_view_copy_selection (ModestHeaderView *header_view);
374
375 /**
376  * modest_header_view_cut_selection:
377  * @self: a #ModestHeaderView
378  * 
379  * Stores a #TnyList of selected headers in the own clibpoard of 
380  * @self header view and filter them into headers tree model to
381  * hide these rows in treeview.
382  **/
383 void 
384 modest_header_view_cut_selection (ModestHeaderView *header_view);
385
386
387 /**
388  * modest_header_view_paste_selection:
389  * @self: a #ModestHeaderView
390  * @headers: ouput parameter with a #TnyList of headers which will be returned.
391  * @delete: output parameter with indication about delete or not the selected headers. 
392  * 
393  * Gets the selected headers to copy/cut.
394  **/
395 void
396 modest_header_view_paste_selection (ModestHeaderView *header_view,
397                                     TnyList **headers,
398                                     gboolean *delete);
399
400 void modest_header_view_refilter (ModestHeaderView *header_view);
401
402 /**
403  * modest_header_view_set_filter:
404  * @self: a #ModestHeaderView
405  * @filter: a filter mask to be applied to messages
406  *
407  * sets the special filter to be applied (affects visibility of items).
408  * It's a mask, and filters applied are applied with an AND.
409  */
410 void modest_header_view_set_filter (ModestHeaderView *self,
411                                     ModestHeaderViewFilter filter);
412
413 /**
414  * modest_header_view_unset_filter:
415  * @self: a #ModestHeaderView
416  * @filter: a filter mask to be unapplied to headers
417  *
418  * Unsets the special filter to be applied (affects visibility of
419  * items).  It's a mask, and filters applied are applied with an AND.
420  */
421 void modest_header_view_unset_filter (ModestHeaderView *self,
422                                       ModestHeaderViewFilter filter);
423
424
425
426 /**
427  * modest_header_view_add_observer:
428  * @header_view: a #ModestHeaderView
429  * @observer: The observer to notify.
430  * 
431  * Registers a new observer. Warning! Each added observer object must
432  * removed using @modest_header_view_remove_observer before destroying
433  * the observer, or at least when it is under destruction. Also you
434  * should care about that the observer's #update function might be
435  * called any time until the observer is removed.
436  **/
437 void modest_header_view_add_observer(
438                 ModestHeaderView *header_view,
439                 ModestHeaderViewObserver *observer);
440
441 /**
442  * modest_header_view_remove_observer:
443  * @header_view: a #ModestHeaderView
444  * @observer: The observer to remove.
445  * 
446  * Removes exactly one observer from the notification list. If you
447  * added an observer twice, you should call this remove funtion twice
448  * as well.
449  **/
450 void modest_header_view_remove_observer(
451                 ModestHeaderView *header_view,
452                 ModestHeaderViewObserver *observer);
453
454 /**
455  * modest_header_view_get_header_at_pos:
456  * @header_view: a #ModestHeaderView
457  * @initial_x: the x coordinate
458  * @initial_y: the y coordinate
459  *
460  * Return the #TnyHeader stored in the row at (x,y) coordinates
461  * relatives to the widget. It returns a new reference so you must
462  * unref it once you're done with it.
463  *
464  * Returns: a #TnyHeader if found, else NULL
465  **/
466 TnyHeader* modest_header_view_get_header_at_pos (ModestHeaderView *header_view,
467                                                  gint initial_x,
468                                                  gint initial_y);
469
470 void modest_header_view_set_show_latest (ModestHeaderView *header_view,
471                                          gint show_latest);
472
473 gint modest_header_view_get_show_latest (ModestHeaderView *header_view);
474
475 G_END_DECLS
476
477
478
479 #endif /* __MODEST_HEADER_VIEW_H__ */
480