1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
30 #ifndef __MODEST_HEADER_VIEW_H__
31 #define __MODEST_HEADER_VIEW_H__
33 #include <tny-folder.h>
34 #include <tny-folder-change.h>
35 #include <tny-gtk-account-list-model.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"
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))
52 typedef struct _ModestHeaderView ModestHeaderView;
53 typedef struct _ModestHeaderViewClass ModestHeaderViewClass;
55 struct _ModestHeaderView {
57 /* insert public members, if any */
60 #define MODEST_HEADER_VIEW_COLUMN "header-view-column"
61 #define MODEST_HEADER_VIEW_FLAG_SORT "header-view-flags-sort"
63 typedef enum _ModestHeaderViewColumn {
64 MODEST_HEADER_VIEW_COLUMN_FROM = 0,
65 MODEST_HEADER_VIEW_COLUMN_TO = 1,
66 MODEST_HEADER_VIEW_COLUMN_SUBJECT = 2,
67 MODEST_HEADER_VIEW_COLUMN_SENT_DATE = 3,
68 MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE = 4,
69 MODEST_HEADER_VIEW_COLUMN_MSGTYPE = 5,
70 MODEST_HEADER_VIEW_COLUMN_ATTACH = 6,
71 MODEST_HEADER_VIEW_COLUMN_SIZE = 7,
72 MODEST_HEADER_VIEW_COLUMN_STATUS = 8,
75 * these two are for compact display on small devices,
76 * with two line display with all relevant headers
78 MODEST_HEADER_VIEW_COLUMN_COMPACT_FLAG = 9, /* priority and attachments */
79 MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN = 10, /* incoming mail */
80 MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT = 11,/* outgoing mail */
81 MODEST_HEADER_VIEW_COLUMN_COMPACT_SENT_DATE = 12,
82 MODEST_HEADER_VIEW_COLUMN_COMPACT_RECEIVED_DATE = 13,
84 MODEST_HEADER_VIEW_COLUMN_NUM
86 } ModestHeaderViewColumn;
89 * this can be extended with more style thingies,
90 * to make a small-device specific display
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 */
96 MODEST_HEADER_VIEW_STYLE_NUM
97 } ModestHeaderViewStyle;
99 typedef enum _ModestItemType {
100 MODEST_ITEM_TYPE_MESSAGE,
101 MODEST_ITEM_TYPE_FOLDER,
106 struct _ModestHeaderViewClass {
107 GtkTreeViewClass parent_class;
109 void (*header_selected) (ModestHeaderView* self,
113 void (*item_not_found) (ModestHeaderView* self,
117 void (*header_activated) (ModestHeaderView* self,
121 void (*msg_count_changed) (ModestHeaderView* self,
123 TnyFolderChange *change,
128 * modest_header_view_get_type:
130 * get the GType for ModestHeaderView
134 GType modest_header_view_get_type (void) G_GNUC_CONST;
138 * modest_header_view_new:
139 * @folder: a TnyMsgFolder object
140 * @style: a ModestHeaderViewColumn with the style of this listview
141 * ( MODEST_HEADER_VIEW_STYLE_NORMAL or MODEST_HEADER_VIEW_STYLE_COMPACT)
143 * create a new ModestHeaderView instance, based on a folder iface
145 * Returns: a new GtkWidget (a GtkTreeView-subclass)
147 GtkWidget* modest_header_view_new (TnyFolder *folder,
148 ModestHeaderViewStyle style);
151 * modest_header_view_set_folder:
152 * @self: a ModestHeaderView instance
153 * @folder: a TnyFolder object
155 * set the folder for this ModestHeaderView
157 void modest_header_view_set_folder (ModestHeaderView *self,
159 RefreshAsyncUserCallback callback,
163 * modest_header_view_get_folder:
164 * @self: a ModestHeaderView instance
166 * get the folder in this ModestHeaderView
168 * Returns: the tny folder instance or NULL if there is none
170 TnyFolder *modest_header_view_get_folder (ModestHeaderView *self);
174 * modest_header_view_set_columns:
175 * @self: a ModestHeaderView instance
176 * @columns: a list of gint ModestHeaderViewColumn column IDs, using GINT_TO_POINTER() and GPOINTER_TO_INT().
177 * @type: #TnyFolderType type
179 * set the columns for this ModestHeaderView.
181 * Returns: TRUE if it succeeded, FALSE otherwise
183 gboolean modest_header_view_set_columns (ModestHeaderView *self,
184 const GList *columns,
187 * modest_header_view_get_columns:
188 * @self: a ModestHeaderView instance
190 * get the GtkTreeColumns for this ModestHeaderView. Each one of the
191 * tree columns will have property than can be retrieved
192 * with g_object_get_data MODEST_HEADER_VIEW_COLUMN (#define),
193 * and which contains the corresponding ModestHeaderViewColumn
195 * Returns: newly allocated list of #GtkTreeViewColumns objects, or NULL in case of no columns or error
196 * You must free the list with g_list_free
198 GList* modest_header_view_get_columns (ModestHeaderView *self);
202 * modest_header_view_set_style:
203 * @self: a ModestHeaderView instance
204 * @style: the style for this tree view
206 * set the style for this ModestHeaderView
208 * Returns: TRUE if it succeeded, FALSE otherwise
210 gboolean modest_header_view_set_style (ModestHeaderView *self,
211 ModestHeaderViewStyle style);
214 * modest_header_view_set_folder:
215 * @self: a ModestHeaderView instance
217 * get the style for this ModestHeaderView
219 * Returns: the current style
221 ModestHeaderViewStyle modest_header_view_get_style (ModestHeaderView *self);
224 * modest_header_view_count_selected_headers:
225 * @self: a ModestHeaderView instance
227 * Check selected headers counter.
228 * Returns: the number of selected headers.
231 modest_header_view_count_selected_headers (ModestHeaderView *self);
234 * modest_header_view_has_selected_headers:
235 * @self: a ModestHeaderView instance
237 * Check if any row is selected on headers tree view.
238 * Returns: TRUE if any header is selected, FALSE otherwise.
241 modest_header_view_has_selected_headers (ModestHeaderView *self);
244 * modest_header_view_get_selected_headers:
245 * @self: a ModestHeaderView instance
247 * get the list of the currently selected TnyHeader's. The list and
248 * the headers should be freed by the caller
250 * Returns: the list with the currently selected headers
252 TnyList* modest_header_view_get_selected_headers (ModestHeaderView *self);
256 * modest_header_view_is_empty:
257 * @self: a valid ModestHeaderView instance
259 * see if this header view is empty; use this function instead of
260 * using the GtkTreeView parent directly, as 'empty' in this case
261 * may mean that there is one "This is empty"-message, and of course
262 * GtkTreeView then thinks it is *not* empty
264 * Returns: TRUE if the header view is empty, FALSE otherwise
266 gboolean modest_header_view_is_empty (ModestHeaderView *self);
271 * modest_header_view_select_next:
272 * @self: a #ModestHeaderView
274 * Selects the header next to the current selected one
276 void modest_header_view_select_next (ModestHeaderView *self);
279 * modest_header_view_select_prev:
280 * @self: a #ModestHeaderView
282 * Selects the previous header of the current selected one
284 void modest_header_view_select_prev (ModestHeaderView *self);
287 /* PROTECTED method. It's useful when we want to force a given
288 selection to reload a msg. For example if we have selected a header
289 in offline mode, when Modest become online, we want to reload the
290 message automatically without an user click over the header */
292 _modest_header_view_change_selection (GtkTreeSelection *selection,
296 * modest_header_view_get_sort_column_id:
297 * @self: a #ModestHeaderView
298 * @type: #TnyFolderType type
300 * Gets the selected logical columnd id for sorting.
303 modest_header_view_get_sort_column_id (ModestHeaderView *self, TnyFolderType type);
306 * modest_header_view_get_sort_type:
307 * @self: a #ModestHeaderView
308 * @type: #TnyFolderType type
310 * Gets the selected sort type.
313 modest_header_view_get_sort_type (ModestHeaderView *self, TnyFolderType type);
316 * modest_header_view_set_sort_params:
317 * @self: a #ModestHeaderView
318 * @sort_colid: logical column id to sort
319 * @sort_type: #GtkSortType sort type
320 * @type: #TnyFolderType type
322 * Sets the logical columnd id and sort type for sorting operations.
325 modest_header_view_set_sort_params (ModestHeaderView *self, guint sort_colid, GtkSortType sort_type, TnyFolderType type);
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
333 * Sorts headers treeview by logical column id, @sort_colid, using a
334 * @sort_type sorting method. In addition, new headder settings will be
335 * stored in @self object.
338 modest_header_view_sort_by_column_id (ModestHeaderView *self,
340 GtkSortType sort_type);
343 * modest_header_view_clear:
344 * @self: a #ModestHeaderView
346 * Clear the contents of a header view. It internally calls the
347 * set_folder function with last three arguments as NULL
350 modest_header_view_clear (ModestHeaderView *self);
353 * modest_header_view_copy_selection:
354 * @self: a #ModestHeaderView
356 * Stores a #TnyList of selected headers in the own clibpoard of
360 modest_header_view_copy_selection (ModestHeaderView *header_view);
363 * modest_header_view_cut_selection:
364 * @self: a #ModestHeaderView
366 * Stores a #TnyList of selected headers in the own clibpoard of
367 * @self header view and filter them into headers tree model to
368 * hide these rows in treeview.
371 modest_header_view_cut_selection (ModestHeaderView *header_view);
375 * modest_header_view_paste_selection:
376 * @self: a #ModestHeaderView
377 * @headers: ouput parameter with a #TnyList of headers which will be returned.
378 * @delete: output parameter with indication about delete or not the selected headers.
380 * Gets the selected headers to copy/cut.
383 modest_header_view_paste_selection (ModestHeaderView *header_view,
387 void modest_header_view_refilter (ModestHeaderView *header_view);
390 * modest_header_view_add_observer:
391 * @header_view: a #ModestHeaderView
392 * @observer: The observer to notify.
394 * Registers a new observer. Warning! Each added observer object must
395 * removed using @modest_header_view_remove_observer before destroying
396 * the observer, or at least when it is under destruction. Also you
397 * should care about that the observer's #update function might be
398 * called any time until the observer is removed.
400 void modest_header_view_add_observer(
401 ModestHeaderView *header_view,
402 ModestHeaderViewObserver *observer);
405 * modest_header_view_remove_observer:
406 * @header_view: a #ModestHeaderView
407 * @observer: The observer to remove.
409 * Removes exactly one observer from the notification list. If you
410 * added an observer twice, you should call this remove funtion twice
413 void modest_header_view_remove_observer(
414 ModestHeaderView *header_view,
415 ModestHeaderViewObserver *observer);
421 #endif /* __MODEST_HEADER_VIEW_H__ */