c8abdf0c1d084dbf929f09ad36bcf748567e6bc1
[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 <gtk/gtk.h>
34 #include <tny-folder.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
40 G_BEGIN_DECLS
41
42 /* convenience macros */
43 #define MODEST_TYPE_HEADER_VIEW             (modest_header_view_get_type())
44 #define MODEST_HEADER_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_HEADER_VIEW,ModestHeaderView))
45 #define MODEST_HEADER_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_HEADER_VIEW,ModestHeaderViewClass))
46 #define MODEST_IS_HEADER_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_HEADER_VIEW))
47 #define MODEST_IS_HEADER_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_HEADER_VIEW))
48 #define MODEST_HEADER_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_HEADER_VIEW,ModestHeaderViewClass))
49
50 typedef struct _ModestHeaderView      ModestHeaderView;
51 typedef struct _ModestHeaderViewClass ModestHeaderViewClass;
52
53 struct _ModestHeaderView {
54          GtkTreeView parent;
55         /* insert public members, if any */
56 };
57
58 #define MODEST_HEADER_VIEW_COLUMN    "header-view-column"
59
60 typedef enum _ModestHeaderViewColumn {
61         MODEST_HEADER_VIEW_COLUMN_FROM            = 0,
62         MODEST_HEADER_VIEW_COLUMN_TO,
63         MODEST_HEADER_VIEW_COLUMN_SUBJECT,
64         MODEST_HEADER_VIEW_COLUMN_SENT_DATE,
65         MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE,
66         MODEST_HEADER_VIEW_COLUMN_MSGTYPE,
67         MODEST_HEADER_VIEW_COLUMN_ATTACH,
68         MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER,
69         MODEST_HEADER_VIEW_COLUMN_NUM
70 } ModestHeaderViewColumn;
71
72 typedef enum _ModestHeaderViewStyle {
73         MODEST_HEADER_VIEW_STYLE_NORMAL,
74         MODEST_HEADER_VIEW_STYLE_COMPACT,
75         MODEST_HEADER_VIEW_STYLE_NUM
76 } ModestHeaderViewStyle;
77
78 typedef enum _ModestItemType {
79         MODEST_ITEM_TYPE_MESSAGE,
80         MODEST_ITEM_TYPE_FOLDER,
81         MODEST_ITEM_TYPE_NUM
82 } ModestItemType;
83
84 struct _ModestHeaderViewClass {
85         GtkTreeViewClass parent_class;
86
87         void (*message_selected) (ModestHeaderView* self,
88                                   TnyMsg *msg,
89                                   gpointer user_data);
90
91         void (*item_not_found) (ModestHeaderView* self,
92                                 ModestItemType type,
93                                 gpointer user_data);
94         
95         /* msg == NULL implies that the operation is finished, ie.
96          * the progress indictation can be hidden */
97         void (*status_update) (ModestHeaderView* self,
98                                const gchar* msg,
99                                gint num, gint total,
100                                gpointer user_data);
101 };
102
103 /**
104  * modest_header_view_get_type:
105  * 
106  * get the GType for ModestHeaderView
107  *  
108  * Returns: the GType
109  */
110 GType        modest_header_view_get_type    (void) G_GNUC_CONST;
111
112
113 /**
114  * modest_header_view_new:
115  * @folder: a TnyMsgFolder object
116  * @columns: a list of ModestHeaderViewColumn
117  * @style: a ModestHeaderViewColumn with the style of this listview
118  *  (   MODEST_HEADER_VIEW_STYLE_NORMAL or MODEST_HEADER_VIEW_STYLE_COMPACT)
119  * 
120  * create a new ModestHeaderView instance, based on a folder iface
121  *   
122  * Returns: a new GtkWidget (a GtkTreeView-subclass)
123  */
124 GtkWidget*   modest_header_view_new        (TnyFolder *folder,
125                                             const GList *columns,
126                                             ModestHeaderViewStyle style);
127
128 /**
129  * modest_header_view_set_folder:
130  * @self: a ModestHeaderView instance
131  * @folder: a TnyFolder object
132  * 
133  * set the folder for this ModestHeaderView
134  *  
135  * Returns: TRUE if it succeeded, FALSE otherwise
136  */
137 gboolean     modest_header_view_set_folder (ModestHeaderView *self,
138                                             TnyFolder *folder);
139
140
141
142
143 /**
144  * modest_header_view_get_folder:
145  * @self: a ModestHeaderView instance
146  * 
147  * get the folder in this ModestHeaderView
148  *  
149  * Returns: the tny folder instance or NULL if there is none
150  */
151 TnyFolder *modest_header_view_get_folder (ModestHeaderView *self);
152
153
154 /**
155  * modest_header_view_set_columns:
156  * @self: a ModestHeaderView instance
157  * @columns: a list of ModestHeaderViewColumn
158  * 
159  * set the columns for this ModestHeaderView.
160  *  
161  * Returns: TRUE if it succeeded, FALSE otherwise
162  */
163 gboolean modest_header_view_set_columns (ModestHeaderView *self,
164                                          const GList *columns);
165 /**
166  * modest_header_view_get_columns:
167  * @self: a ModestHeaderView instance
168  * 
169  * get the GtkTreeColumns for this ModestHeaderView. Each one of the
170  * tree columns will have property  than can be retrieved
171  * with g_object_get_data MODEST_HEADER_VIEW_COLUMN (#define),
172  * and which contains the corresponding ModestHeaderViewColumn
173  *  
174  * Returns: newly allocated list of column ids, or NULL in case of no columns or error
175  * You must free the list with g_list_free
176  */
177 GList*  modest_header_view_get_columns (ModestHeaderView *self);
178         
179
180 /**
181  * modest_header_view_set_style:
182  * @self: a ModestHeaderView instance
183  * @style: the style for this tree view
184  * 
185  * set the style this ModestHeaderView
186  *  
187  * Returns: TRUE if it succeeded, FALSE otherwise
188  */
189 gboolean   modest_header_view_set_style (ModestHeaderView *self,
190                                          ModestHeaderViewStyle style);
191
192 /**
193  * modest_header_view_set_folder:
194  * @self: a ModestHeaderView instance
195  * 
196  * get the style for this ModestHeaderView
197  *  
198  * Returns: the current style
199  */
200 ModestHeaderViewStyle   modest_header_view_get_style (ModestHeaderView *self);
201
202 /**
203  * modest_header_view_get_selected_headers:
204  * @self: a ModestHeaderView instance
205  * 
206  * get the list of the currently selected TnyHeader's
207  *  
208  * Returns: the list with the currently selected headers
209  */
210 TnyList* modest_header_view_get_selected_headers (ModestHeaderView *self);
211
212 G_END_DECLS
213
214
215 #endif /* __MODEST_HEADER_VIEW_H__ */
216