* check for a valid foldername
[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
41 G_BEGIN_DECLS
42
43 /* convenience macros */
44 #define MODEST_TYPE_HEADER_VIEW             (modest_header_view_get_type())
45 #define MODEST_HEADER_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_HEADER_VIEW,ModestHeaderView))
46 #define MODEST_HEADER_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_HEADER_VIEW,ModestHeaderViewClass))
47 #define MODEST_IS_HEADER_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_HEADER_VIEW))
48 #define MODEST_IS_HEADER_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_HEADER_VIEW))
49 #define MODEST_HEADER_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_HEADER_VIEW,ModestHeaderViewClass))
50
51 typedef struct _ModestHeaderView      ModestHeaderView;
52 typedef struct _ModestHeaderViewClass ModestHeaderViewClass;
53
54 struct _ModestHeaderView {
55          GtkTreeView parent;
56         /* insert public members, if any */
57 };
58
59 #define MODEST_HEADER_VIEW_COLUMN    "header-view-column"
60 #define MODEST_HEADER_VIEW_FLAG_SORT "header-view-flags-sort"
61
62 typedef enum _ModestHeaderViewColumn {
63         MODEST_HEADER_VIEW_COLUMN_FROM                  = 0,
64         MODEST_HEADER_VIEW_COLUMN_TO                    = 1,
65         MODEST_HEADER_VIEW_COLUMN_SUBJECT               = 2,
66         MODEST_HEADER_VIEW_COLUMN_SENT_DATE             = 3,
67         MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE         = 4,
68         MODEST_HEADER_VIEW_COLUMN_MSGTYPE               = 5,
69         MODEST_HEADER_VIEW_COLUMN_ATTACH                = 6,
70         MODEST_HEADER_VIEW_COLUMN_SIZE                  = 7,
71         MODEST_HEADER_VIEW_COLUMN_STATUS                = 8,
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          = 9, /* priority and attachments */
78         MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN     = 10, /* incoming mail */
79         MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT    = 11,/* outgoing mail */
80         MODEST_HEADER_VIEW_COLUMN_COMPACT_SENT_DATE     = 12,
81         MODEST_HEADER_VIEW_COLUMN_COMPACT_RECEIVED_DATE = 13,
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 struct _ModestHeaderViewClass {
106         GtkTreeViewClass parent_class;
107
108         void (*header_selected) (ModestHeaderView* self,
109                                  TnyHeader *header,
110                                  gpointer user_data);
111
112         void (*item_not_found) (ModestHeaderView* self,
113                                 ModestItemType type,
114                                 gpointer user_data);
115
116         void (*header_activated) (ModestHeaderView* self,
117                                   TnyHeader *header,
118                                   gpointer user_data);
119
120         void (*msg_count_changed) (ModestHeaderView* self,
121                                    TnyFolder *folder,
122                                    TnyFolderChange *change,
123                                    gpointer user_data);
124 };
125
126 /**
127  * modest_header_view_get_type:
128  * 
129  * get the GType for ModestHeaderView
130  *  
131  * Returns: the GType
132  */
133 GType        modest_header_view_get_type    (void) G_GNUC_CONST;
134
135
136 /**
137  * modest_header_view_new:
138  * @folder: a TnyMsgFolder object
139  * @style: a ModestHeaderViewColumn with the style of this listview
140  *  (   MODEST_HEADER_VIEW_STYLE_NORMAL or MODEST_HEADER_VIEW_STYLE_COMPACT)
141  * 
142  * create a new ModestHeaderView instance, based on a folder iface
143  *   
144  * Returns: a new GtkWidget (a GtkTreeView-subclass)
145  */
146 GtkWidget*   modest_header_view_new        (TnyFolder *folder,
147                                             ModestHeaderViewStyle style);
148
149 /**
150  * modest_header_view_set_folder:
151  * @self: a ModestHeaderView instance
152  * @folder: a TnyFolder object
153  * 
154  * set the folder for this ModestHeaderView
155  */
156 void         modest_header_view_set_folder (ModestHeaderView *self,
157                                             TnyFolder *folder,
158                                             RefreshAsyncUserCallback callback,
159                                             gpointer user_data);
160
161 /**
162  * modest_header_view_get_folder:
163  * @self: a ModestHeaderView instance
164  * 
165  * get the folder in this ModestHeaderView
166  *  
167  * Returns: the tny folder instance or NULL if there is none
168  */
169 TnyFolder *modest_header_view_get_folder (ModestHeaderView *self);
170
171
172 /**
173  * modest_header_view_set_columns:
174  * @self: a ModestHeaderView instance
175  * @columns: a list of gint ModestHeaderViewColumn column IDs, using GINT_TO_POINTER() and GPOINTER_TO_INT().
176  * @type: #TnyFolderType type
177  * 
178  * set the columns for this ModestHeaderView.
179  *  
180  * Returns: TRUE if it succeeded, FALSE otherwise
181  */
182 gboolean modest_header_view_set_columns (ModestHeaderView *self,
183                                          const GList *columns,
184                                          TnyFolderType type);
185 /**
186  * modest_header_view_get_columns:
187  * @self: a ModestHeaderView instance
188  * 
189  * get the GtkTreeColumns for this ModestHeaderView. Each one of the
190  * tree columns will have property  than can be retrieved
191  * with g_object_get_data MODEST_HEADER_VIEW_COLUMN (#define),
192  * and which contains the corresponding ModestHeaderViewColumn
193  *  
194  * Returns: newly allocated list of #GtkTreeViewColumns objects, or NULL in case of no columns or error
195  * You must free the list with g_list_free
196  */
197 GList*  modest_header_view_get_columns (ModestHeaderView *self);
198
199
200 /**
201  * modest_header_view_set_style:
202  * @self: a ModestHeaderView instance
203  * @style: the style for this tree view
204  * 
205  * set the style for this ModestHeaderView
206  *  
207  * Returns: TRUE if it succeeded, FALSE otherwise
208  */
209 gboolean   modest_header_view_set_style (ModestHeaderView *self,
210                                          ModestHeaderViewStyle style);
211
212 /**
213  * modest_header_view_set_folder:
214  * @self: a ModestHeaderView instance
215  * 
216  * get the style for this ModestHeaderView
217  *  
218  * Returns: the current style
219  */
220 ModestHeaderViewStyle   modest_header_view_get_style (ModestHeaderView *self);
221
222 /**
223  * modest_header_view_count_selected_headers:
224  * @self: a ModestHeaderView instance
225  * 
226  * Check selected headers counter. 
227  * Returns: the number of selected headers.
228  */
229 guint
230 modest_header_view_count_selected_headers (ModestHeaderView *self);
231
232 /**
233  * modest_header_view_has_selected_headers:
234  * @self: a ModestHeaderView instance
235  * 
236  * Check if any row is selected on headers tree view. 
237  * Returns: TRUE if any header is selected, FALSE otherwise.
238  */
239 gboolean
240 modest_header_view_has_selected_headers (ModestHeaderView *self);
241
242 /**
243  * modest_header_view_get_selected_headers:
244  * @self: a ModestHeaderView instance
245  * 
246  * get the list of the currently selected TnyHeader's. The list and
247  * the headers should be freed by the caller
248  *  
249  * Returns: the list with the currently selected headers
250  */
251 TnyList* modest_header_view_get_selected_headers (ModestHeaderView *self);
252
253
254 /**
255  * modest_header_view_is_empty:
256  * @self: a valid ModestHeaderView instance
257  * 
258  * see if this header view is empty; use this function instead of
259  * using the GtkTreeView parent directly, as 'empty' in this case
260  * may mean that there is one "This is empty"-message, and of course
261  * GtkTreeView then thinks it is *not* empty
262  *  
263  * Returns: TRUE if the header view is empty, FALSE otherwise
264  */
265 gboolean  modest_header_view_is_empty (ModestHeaderView *self);
266
267
268
269 /**
270  * modest_header_view_select_next:
271  * @self: a #ModestHeaderView
272  * 
273  * Selects the header next to the current selected one
274  **/
275 void         modest_header_view_select_next          (ModestHeaderView *self);
276
277 /**
278  * modest_header_view_select_prev:
279  * @self: a #ModestHeaderView
280  * 
281  * Selects the previous header of the current selected one
282  **/
283 void         modest_header_view_select_prev          (ModestHeaderView *self);
284
285
286 /* PROTECTED method. It's useful when we want to force a given
287    selection to reload a msg. For example if we have selected a header
288    in offline mode, when Modest become online, we want to reload the
289    message automatically without an user click over the header */
290 void 
291 _modest_header_view_change_selection (GtkTreeSelection *selection,
292                                       gpointer user_data);
293
294 /**
295  * modest_header_view_get_sort_column_id:
296  * @self: a #ModestHeaderView
297  * @type: #TnyFolderType type
298  * 
299  * Gets the selected logical columnd id for sorting.
300  **/
301 gint
302 modest_header_view_get_sort_column_id (ModestHeaderView *self, TnyFolderType type);
303
304 /**
305  * modest_header_view_get_sort_type:
306  * @self: a #ModestHeaderView
307  * @type: #TnyFolderType type
308  * 
309  * Gets the selected sort type.
310  **/
311 GtkSortType
312 modest_header_view_get_sort_type (ModestHeaderView *self, TnyFolderType type);
313
314 /**
315  * modest_header_view_set_sort_params:
316  * @self: a #ModestHeaderView
317  * @sort_colid: logical column id to sort
318  * @sort_type: #GtkSortType sort type
319  * @type: #TnyFolderType type
320  * 
321  * Sets the logical columnd id and sort type for sorting operations.
322  **/
323 void
324 modest_header_view_set_sort_params (ModestHeaderView *self, guint sort_colid, GtkSortType sort_type, TnyFolderType type);
325
326 /**
327  * modest_header_view_set_sort_params:
328  * @self: a #ModestHeaderView
329  * @sort_colid: logical column id to sort
330  * @sort_type: #GtkSortType sort type
331  * 
332  * Sorts headers treeview by logical column id, @sort_colid, using a 
333  * @sort_type sorting method. In addition, new headder settings will be 
334  * stored in @self object. 
335  **/
336 void
337 modest_header_view_sort_by_column_id (ModestHeaderView *self, 
338                                       guint sort_colid,
339                                       GtkSortType sort_type);
340
341 /**
342  * modest_header_view_clear:
343  * @self: a #ModestHeaderView
344  *
345  * Clear the contents of a header view. It internally calls the
346  * set_folder function with last three arguments as NULL
347  **/
348 void
349 modest_header_view_clear (ModestHeaderView *self);
350
351 /**
352  * modest_header_view_copy_selection:
353  * @self: a #ModestHeaderView
354  * 
355  * Stores a #TnyList of selected headers in the own clibpoard of 
356  * @self header view.
357  **/
358 void 
359 modest_header_view_copy_selection (ModestHeaderView *header_view);
360
361 /**
362  * modest_header_view_cut_selection:
363  * @self: a #ModestHeaderView
364  * 
365  * Stores a #TnyList of selected headers in the own clibpoard of 
366  * @self header view and filter them into headers tree model to
367  * hide these rows in treeview.
368  **/
369 void 
370 modest_header_view_cut_selection (ModestHeaderView *header_view);
371
372
373 /**
374  * modest_header_view_paste_selection:
375  * @self: a #ModestHeaderView
376  * @headers: ouput parameter with a #TnyList of headers which will be returned.
377  * @delete: output parameter with indication about delete or not the selected headers. 
378  * 
379  * Gets the selected headers to copy/cut.
380  **/
381 void
382 modest_header_view_paste_selection (ModestHeaderView *header_view,
383                                     TnyList **headers,
384                                     gboolean *delete);
385
386 void modest_header_view_refilter (ModestHeaderView *header_view);
387
388 G_END_DECLS
389
390
391
392 #endif /* __MODEST_HEADER_VIEW_H__ */
393