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