5ecaa506037971c4f32d32e33f872ac60b854e1f
[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-gtk-account-list-model.h>
35 #include <tny-msg.h>
36 #include <tny-header.h>
37 #include <tny-gtk-header-list-model.h>
38
39 G_BEGIN_DECLS
40
41 /* convenience macros */
42 #define MODEST_TYPE_HEADER_VIEW             (modest_header_view_get_type())
43 #define MODEST_HEADER_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_HEADER_VIEW,ModestHeaderView))
44 #define MODEST_HEADER_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_HEADER_VIEW,ModestHeaderViewClass))
45 #define MODEST_IS_HEADER_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_HEADER_VIEW))
46 #define MODEST_IS_HEADER_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_HEADER_VIEW))
47 #define MODEST_HEADER_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_HEADER_VIEW,ModestHeaderViewClass))
48
49 typedef struct _ModestHeaderView      ModestHeaderView;
50 typedef struct _ModestHeaderViewClass ModestHeaderViewClass;
51
52 struct _ModestHeaderView {
53          GtkTreeView parent;
54         /* insert public members, if any */
55 };
56
57 #define MODEST_HEADER_VIEW_COLUMN    "header-view-column"
58
59 typedef enum _ModestHeaderViewColumn {
60         MODEST_HEADER_VIEW_COLUMN_FROM            = 0,
61         MODEST_HEADER_VIEW_COLUMN_TO,
62         MODEST_HEADER_VIEW_COLUMN_SUBJECT,
63         MODEST_HEADER_VIEW_COLUMN_SENT_DATE,
64         MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE,
65         MODEST_HEADER_VIEW_COLUMN_MSGTYPE,
66         MODEST_HEADER_VIEW_COLUMN_ATTACH,
67         MODEST_HEADER_VIEW_COLUMN_SIZE,
68         MODEST_HEADER_VIEW_COLUMN_STATUS,
69         /*
70          * these two are for compact display on small devices,
71          * with two line display with all relevant headers
72          */
73         MODEST_HEADER_VIEW_COLUMN_COMPACT_FLAG,       /* priority and attachments */
74         MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN,  /* incoming mail */
75         MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT, /* outgoing mail */
76
77         MODEST_HEADER_VIEW_COLUMN_NUM
78
79 } ModestHeaderViewColumn;
80
81 /*
82  * this can be extended with more style thingies,
83  * to make a small-device specific display
84  */
85 typedef enum _ModestHeaderViewStyle {
86         MODEST_HEADER_VIEW_STYLE_DETAILS, /* many columns, single line, col headers visible */
87         MODEST_HEADER_VIEW_STYLE_TWOLINES, /* two-line headers, col headers invisible */
88
89         MODEST_HEADER_VIEW_STYLE_NUM    
90 } ModestHeaderViewStyle;
91
92 typedef enum _ModestItemType {
93         MODEST_ITEM_TYPE_MESSAGE,
94         MODEST_ITEM_TYPE_FOLDER,
95         MODEST_ITEM_TYPE_NUM
96 } ModestItemType;
97
98
99 struct _ModestHeaderViewClass {
100         GtkTreeViewClass parent_class;
101
102         void (*header_selected) (ModestHeaderView* self,
103                                  TnyHeader *header,
104                                  gpointer user_data);
105
106         void (*item_not_found) (ModestHeaderView* self,
107                                 ModestItemType type,
108                                 gpointer user_data);
109
110         void (*header_activated) (ModestHeaderView* self,
111                                   TnyHeader *header,
112                                   gpointer user_data);
113
114         /* msg == NULL implies that the operation is finished, ie.
115          * the progress indictation can be hidden */
116         void (*status_update) (ModestHeaderView* self,
117                                const gchar* msg,
118                                gint num, gint total,
119                                gpointer user_data);
120 };
121
122 /**
123  * modest_header_view_get_type:
124  * 
125  * get the GType for ModestHeaderView
126  *  
127  * Returns: the GType
128  */
129 GType        modest_header_view_get_type    (void) G_GNUC_CONST;
130
131
132 /**
133  * modest_header_view_new:
134  * @folder: a TnyMsgFolder object
135  * @style: a ModestHeaderViewColumn with the style of this listview
136  *  (   MODEST_HEADER_VIEW_STYLE_NORMAL or MODEST_HEADER_VIEW_STYLE_COMPACT)
137  * 
138  * create a new ModestHeaderView instance, based on a folder iface
139  *   
140  * Returns: a new GtkWidget (a GtkTreeView-subclass)
141  */
142 GtkWidget*   modest_header_view_new        (TnyFolder *folder,
143                                             ModestHeaderViewStyle style);
144
145 /**
146  * modest_header_view_set_folder:
147  * @self: a ModestHeaderView instance
148  * @folder: a TnyFolder object
149  * 
150  * set the folder for this ModestHeaderView
151  */
152 void         modest_header_view_set_folder (ModestHeaderView *self,
153                                             TnyFolder *folder);
154
155 /**
156  * modest_header_view_get_folder:
157  * @self: a ModestHeaderView instance
158  * 
159  * get the folder in this ModestHeaderView
160  *  
161  * Returns: the tny folder instance or NULL if there is none
162  */
163 TnyFolder *modest_header_view_get_folder (ModestHeaderView *self);
164
165
166 /**
167  * modest_header_view_set_columns:
168  * @self: a ModestHeaderView instance
169  * @columns: a list of ModestHeaderViewColumn
170  * 
171  * set the columns for this ModestHeaderView.
172  *  
173  * Returns: TRUE if it succeeded, FALSE otherwise
174  */
175 gboolean modest_header_view_set_columns (ModestHeaderView *self,
176                                          const GList *columns);
177 /**
178  * modest_header_view_get_columns:
179  * @self: a ModestHeaderView instance
180  * 
181  * get the GtkTreeColumns for this ModestHeaderView. Each one of the
182  * tree columns will have property  than can be retrieved
183  * with g_object_get_data MODEST_HEADER_VIEW_COLUMN (#define),
184  * and which contains the corresponding ModestHeaderViewColumn
185  *  
186  * Returns: newly allocated list of column ids, or NULL in case of no columns or error
187  * You must free the list with g_list_free
188  */
189 GList*  modest_header_view_get_columns (ModestHeaderView *self);
190
191
192 /**
193  * modest_header_view_set_style:
194  * @self: a ModestHeaderView instance
195  * @style: the style for this tree view
196  * 
197  * set the style for this ModestHeaderView
198  *  
199  * Returns: TRUE if it succeeded, FALSE otherwise
200  */
201 gboolean   modest_header_view_set_style (ModestHeaderView *self,
202                                          ModestHeaderViewStyle style);
203
204 /**
205  * modest_header_view_set_folder:
206  * @self: a ModestHeaderView instance
207  * 
208  * get the style for this ModestHeaderView
209  *  
210  * Returns: the current style
211  */
212 ModestHeaderViewStyle   modest_header_view_get_style (ModestHeaderView *self);
213
214 /**
215  * modest_header_view_get_selected_headers:
216  * @self: a ModestHeaderView instance
217  * 
218  * get the list of the currently selected TnyHeader's
219  *  
220  * Returns: the list with the currently selected headers
221  */
222 TnyList* modest_header_view_get_selected_headers (ModestHeaderView *self);
223
224
225 /**
226  * modest_header_view_is_empty:
227  * @self: a valid ModestHeaderView instance
228  * 
229  * see if this header view is empty; use this function instead of
230  * using the GtkTreeView parent directly, as 'empty' in this case
231  * may mean that there is one "This is empty"-message, and of course
232  * GtkTreeView then thinks it is *not* empty
233  *  
234  * Returns: TRUE if the header view is empty, FALSE otherwise
235  */
236 gboolean  modest_header_view_is_empty (ModestHeaderView *self);
237
238
239
240 /**
241  * modest_header_view_select_next:
242  * @self: a #ModestHeaderView
243  * 
244  * Selects the header next to the current selected one
245  **/
246 void         modest_header_view_select_next          (ModestHeaderView *self);
247
248 /**
249  * modest_header_view_select_prev:
250  * @self: a #ModestHeaderView
251  * 
252  * Selects the previous header of the current selected one
253  **/
254 void         modest_header_view_select_prev          (ModestHeaderView *self);
255
256
257 /* PROTECTED method. It's useful when we want to force a given
258    selection to reload a msg. For example if we have selected a header
259    in offline mode, when Modest become online, we want to reload the
260    message automatically without an user click over the header */
261 void 
262 _modest_header_view_change_selection (GtkTreeSelection *selection,
263                                       gpointer user_data);
264
265 G_END_DECLS
266
267
268 #endif /* __MODEST_HEADER_VIEW_H__ */
269