1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
4  *
5  * This library is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12  * for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library. If not, see <http://www.gnu.org/licenses/>.
16  *
17  * Authors: Michael Zucchi <notzed@ximian.com>
18  */
19 
20 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
21 #error "Only <camel/camel.h> can be included directly."
22 #endif
23 
24 #ifndef CAMEL_STORE_SUMMARY_H
25 #define CAMEL_STORE_SUMMARY_H
26 
27 #include <stdio.h>
28 
29 #include <camel/camel-enums.h>
30 #include <camel/camel-mime-parser.h>
31 
32 /* Standard GObject macros */
33 #define CAMEL_TYPE_STORE_SUMMARY \
34 	(camel_store_summary_get_type ())
35 #define CAMEL_STORE_SUMMARY(obj) \
36 	(G_TYPE_CHECK_INSTANCE_CAST \
37 	((obj), CAMEL_TYPE_STORE_SUMMARY, CamelStoreSummary))
38 #define CAMEL_STORE_SUMMARY_CLASS(cls) \
39 	(G_TYPE_CHECK_CLASS_CAST \
40 	((cls), CAMEL_TYPE_STORE_SUMMARY, CamelStoreSummaryClass))
41 #define CAMEL_IS_STORE_SUMMARY(obj) \
42 	(G_TYPE_CHECK_INSTANCE_TYPE \
43 	((obj), CAMEL_TYPE_STORE_SUMMARY))
44 #define CAMEL_IS_STORE_SUMMARY_CLASS(cls) \
45 	(G_TYPE_CHECK_CLASS_TYPE \
46 	((cls), CAMEL_TYPE_STORE_SUMMARY))
47 #define CAMEL_STORE_SUMMARY_GET_CLASS(obj) \
48 	(G_TYPE_INSTANCE_GET_CLASS \
49 	((obj), CAMEL_TYPE_STORE_SUMMARY, CamelStoreSummaryClass))
50 
51 G_BEGIN_DECLS
52 
53 struct _CamelFolderSummary;
54 
55 typedef struct _CamelStoreSummary CamelStoreSummary;
56 typedef struct _CamelStoreSummaryClass CamelStoreSummaryClass;
57 typedef struct _CamelStoreSummaryPrivate CamelStoreSummaryPrivate;
58 
59 typedef struct _CamelStoreInfo CamelStoreInfo;
60 
61 #define CAMEL_STORE_INFO_FOLDER_UNKNOWN (~0)
62 
63 enum {
64 	CAMEL_STORE_INFO_PATH = 0,
65 	CAMEL_STORE_INFO_LAST
66 };
67 
68 struct _CamelStoreInfo {
69 	volatile gint refcount;
70 	gchar *path;
71 	guint32 flags;
72 	guint32 unread;
73 	guint32 total;
74 };
75 
76 struct _CamelStoreSummary {
77 	GObject parent;
78 	CamelStoreSummaryPrivate *priv;
79 };
80 
81 struct _CamelStoreSummaryClass {
82 	GObjectClass parent_class;
83 
84 	/* size of memory objects */
85 	gsize store_info_size;
86 
87 	/* load/save the global info */
88 	gint		(*summary_header_load)	(CamelStoreSummary *summary,
89 						 FILE *file);
90 	gint		(*summary_header_save)	(CamelStoreSummary *summary,
91 						 FILE *file);
92 
93 	/* create/save/load an individual message info */
94 	CamelStoreInfo *
95 			(*store_info_new)	(CamelStoreSummary *summary,
96 						 const gchar *path);
97 	CamelStoreInfo *
98 			(*store_info_load)	(CamelStoreSummary *summary,
99 						 FILE *file);
100 	gint		(*store_info_save)	(CamelStoreSummary *summary,
101 						 FILE *file,
102 						 CamelStoreInfo *info);
103 	void		(*store_info_free)	(CamelStoreSummary *summary,
104 						 CamelStoreInfo *info);
105 
106 	/* virtualise access methods */
107 	void		(*store_info_set_string)
108 						(CamelStoreSummary *summary,
109 						 CamelStoreInfo *info,
110 						 gint type,
111 						 const gchar *value);
112 
113 	/* Padding for future expansion */
114 	gpointer reserved[20];
115 };
116 
117 GType		camel_store_summary_get_type	(void) G_GNUC_CONST;
118 CamelStoreSummary *
119 		camel_store_summary_new		(void);
120 void		camel_store_summary_set_filename
121 						(CamelStoreSummary *summary,
122 						 const gchar *filename);
123 
124 /* load/save the summary in its entirety */
125 gint		camel_store_summary_load	(CamelStoreSummary *summary);
126 gint		camel_store_summary_save	(CamelStoreSummary *summary);
127 
128 /* set the dirty bit on the summary */
129 void		camel_store_summary_touch	(CamelStoreSummary *summary);
130 
131 /* add a new raw summary item */
132 void		camel_store_summary_add		(CamelStoreSummary *summary,
133 						 CamelStoreInfo *info);
134 
135 /* build/add raw summary items */
136 CamelStoreInfo *
137 		camel_store_summary_add_from_path
138 						(CamelStoreSummary *summary,
139 						 const gchar *path);
140 
141 /* Just build raw summary items */
142 CamelStoreInfo *
143 		camel_store_summary_info_new	(CamelStoreSummary *summary);
144 CamelStoreInfo *
145 		camel_store_summary_info_ref	(CamelStoreSummary *summary,
146 						 CamelStoreInfo *info);
147 void		camel_store_summary_info_unref	(CamelStoreSummary *summary,
148 						 CamelStoreInfo *info);
149 
150 /* removes a summary item */
151 void		camel_store_summary_remove	(CamelStoreSummary *summary,
152 						 CamelStoreInfo *info);
153 void		camel_store_summary_remove_path	(CamelStoreSummary *summary,
154 						 const gchar *path);
155 
156 /* lookup functions */
157 gint		camel_store_summary_count	(CamelStoreSummary *summary);
158 CamelStoreInfo *
159 		camel_store_summary_path	(CamelStoreSummary *summary,
160 						 const gchar *path);
161 GPtrArray *	camel_store_summary_array	(CamelStoreSummary *summary);
162 void		camel_store_summary_array_free	(CamelStoreSummary *summary,
163 						 GPtrArray *array);
164 
165 void		camel_store_info_set_string	(CamelStoreSummary *summary,
166 						 CamelStoreInfo *info,
167 						 gint type,
168 						 const gchar *value);
169 
170 const gchar *	camel_store_info_path		(CamelStoreSummary *summary,
171 						 CamelStoreInfo *info);
172 const gchar *	camel_store_info_name		(CamelStoreSummary *summary,
173 						 CamelStoreInfo *info);
174 void		camel_store_summary_sort	(CamelStoreSummary *summary,
175 						 GCompareDataFunc compare_func,
176 						 gpointer user_data);
177 
178 gboolean	camel_store_summary_connect_folder_summary
179 						(CamelStoreSummary *summary,
180 						 const gchar *path,
181 						 CamelFolderSummary *folder_summary);
182 gboolean	camel_store_summary_disconnect_folder_summary
183 						(CamelStoreSummary *summary,
184 						 CamelFolderSummary *folder_summary);
185 
186 G_END_DECLS
187 
188 #endif /* CAMEL_STORE_SUMMARY_H */
189