Extending test-client-custom-summary to try e_book_client_get_contacts_uids()
[platform/upstream/evolution-data-server.git] / camel / camel-store-summary.h
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  * Authors: Michael Zucchi <notzed@ximian.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of version 2 of the GNU Lesser General Public
9  * License as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
23 #error "Only <camel/camel.h> can be included directly."
24 #endif
25
26 #ifndef CAMEL_STORE_SUMMARY_H
27 #define CAMEL_STORE_SUMMARY_H
28
29 #include <stdio.h>
30
31 #include <camel/camel-enums.h>
32 #include <camel/camel-memchunk.h>
33 #include <camel/camel-mime-parser.h>
34 #include <camel/camel-object.h>
35
36 /* Standard GObject macros */
37 #define CAMEL_TYPE_STORE_SUMMARY \
38         (camel_store_summary_get_type ())
39 #define CAMEL_STORE_SUMMARY(obj) \
40         (G_TYPE_CHECK_INSTANCE_CAST \
41         ((obj), CAMEL_TYPE_STORE_SUMMARY, CamelStoreSummary))
42 #define CAMEL_STORE_SUMMARY_CLASS(cls) \
43         (G_TYPE_CHECK_CLASS_CAST \
44         ((cls), CAMEL_TYPE_STORE_SUMMARY, CamelStoreSummaryClass))
45 #define CAMEL_IS_STORE_SUMMARY(obj) \
46         (G_TYPE_CHECK_INSTANCE_TYPE \
47         ((obj), CAMEL_TYPE_STORE_SUMMARY))
48 #define CAMEL_IS_STORE_SUMMARY_CLASS(cls) \
49         (G_TYPE_CHECK_CLASS_TYPE \
50         ((cls), CAMEL_TYPE_STORE_SUMMARY))
51 #define CAMEL_STORE_SUMMARY_GET_CLASS(obj) \
52         (G_TYPE_INSTANCE_GET_CLASS \
53         ((obj), CAMEL_TYPE_STORE_SUMMARY, CamelStoreSummaryClass))
54
55 G_BEGIN_DECLS
56
57 typedef struct _CamelStoreSummary CamelStoreSummary;
58 typedef struct _CamelStoreSummaryClass CamelStoreSummaryClass;
59 typedef struct _CamelStoreSummaryPrivate CamelStoreSummaryPrivate;
60
61 typedef struct _CamelStoreInfo CamelStoreInfo;
62
63 #define CAMEL_STORE_INFO_FOLDER_UNKNOWN (~0)
64
65 enum {
66         CAMEL_STORE_INFO_PATH = 0,
67         CAMEL_STORE_INFO_NAME,
68         CAMEL_STORE_INFO_LAST
69 };
70
71 struct _CamelStoreInfo {
72         guint32 refcount;
73         gchar *path;
74         guint32 flags;
75         guint32 unread;
76         guint32 total;
77 };
78
79 typedef enum _CamelStoreSummaryFlags {
80         CAMEL_STORE_SUMMARY_DIRTY = 1 << 0,
81 } CamelStoreSummaryFlags;
82
83 /**
84  * CamelStoreSummaryLock:
85  *
86  * Since: 2.32
87  **/
88 typedef enum {
89         CAMEL_STORE_SUMMARY_SUMMARY_LOCK,
90         CAMEL_STORE_SUMMARY_IO_LOCK,
91         CAMEL_STORE_SUMMARY_REF_LOCK
92 } CamelStoreSummaryLock;
93
94 struct _CamelStoreSummary {
95         CamelObject parent;
96         CamelStoreSummaryPrivate *priv;
97
98         /* header info */
99         guint32 version;        /* version of base part of file */
100         guint32 flags;          /* flags */
101         guint32 count;          /* how many were saved/loaded */
102         time_t time;            /* timestamp for this summary (for implementors to use) */
103
104         /* sizes of memory objects */
105         guint32 store_info_size;
106
107         /* memory allocators (setup automatically) */
108         CamelMemChunk *store_info_chunks;
109
110         gchar *summary_path;
111
112         GPtrArray *folders;     /* CamelStoreInfo's */
113         GHashTable *folders_path; /* CamelStoreInfo's by path name */
114 };
115
116 struct _CamelStoreSummaryClass {
117         CamelObjectClass parent_class;
118
119         /* load/save the global info */
120         gint (*summary_header_load)(CamelStoreSummary *, FILE *);
121         gint (*summary_header_save)(CamelStoreSummary *, FILE *);
122
123         /* create/save/load an individual message info */
124         CamelStoreInfo * (*store_info_new)(CamelStoreSummary *, const gchar *path);
125         CamelStoreInfo * (*store_info_load)(CamelStoreSummary *, FILE *);
126         gint              (*store_info_save)(CamelStoreSummary *, FILE *, CamelStoreInfo *);
127         void              (*store_info_free)(CamelStoreSummary *, CamelStoreInfo *);
128
129         /* virtualise access methods */
130         const gchar *(*store_info_string)(CamelStoreSummary *, const CamelStoreInfo *, gint);
131         void (*store_info_set_string)(CamelStoreSummary *, CamelStoreInfo *, int, const gchar *);
132 };
133
134 GType                    camel_store_summary_get_type   (void);
135 CamelStoreSummary      *camel_store_summary_new (void);
136
137 void camel_store_summary_set_filename (CamelStoreSummary *summary, const gchar *filename);
138
139 /* load/save the summary in its entirety */
140 gint camel_store_summary_load (CamelStoreSummary *summary);
141 gint camel_store_summary_save (CamelStoreSummary *summary);
142
143 /* only load the header */
144 gint camel_store_summary_header_load (CamelStoreSummary *summary);
145
146 /* set the dirty bit on the summary */
147 void camel_store_summary_touch (CamelStoreSummary *summary);
148
149 /* add a new raw summary item */
150 void camel_store_summary_add (CamelStoreSummary *summary, CamelStoreInfo *info);
151
152 /* build/add raw summary items */
153 CamelStoreInfo *camel_store_summary_add_from_path (CamelStoreSummary *summary, const gchar *path);
154
155 /* Just build raw summary items */
156 CamelStoreInfo *camel_store_summary_info_new (CamelStoreSummary *summary);
157 CamelStoreInfo *camel_store_summary_info_new_from_path (CamelStoreSummary *summary, const gchar *path);
158
159 void camel_store_summary_info_ref (CamelStoreSummary *summary, CamelStoreInfo *info);
160 void camel_store_summary_info_free (CamelStoreSummary *summary, CamelStoreInfo *info);
161
162 /* removes a summary item */
163 void camel_store_summary_remove (CamelStoreSummary *summary, CamelStoreInfo *info);
164 void camel_store_summary_remove_path (CamelStoreSummary *summary, const gchar *path);
165 void camel_store_summary_remove_index (CamelStoreSummary *summary, gint index);
166
167 /* remove all items */
168 void camel_store_summary_clear (CamelStoreSummary *summary);
169
170 /* lookup functions */
171 gint camel_store_summary_count (CamelStoreSummary *summary);
172 CamelStoreInfo *camel_store_summary_index (CamelStoreSummary *summary, gint index);
173 CamelStoreInfo *camel_store_summary_path (CamelStoreSummary *summary, const gchar *path);
174 GPtrArray *camel_store_summary_array (CamelStoreSummary *summary);
175 void camel_store_summary_array_free (CamelStoreSummary *summary, GPtrArray *array);
176
177 const gchar *camel_store_info_string (CamelStoreSummary *summary, const CamelStoreInfo *info, gint type);
178 void camel_store_info_set_string (CamelStoreSummary *summary, CamelStoreInfo *info, gint type, const gchar *value);
179
180 /* helper macro's */
181 #define camel_store_info_path(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_STORE_INFO_PATH))
182 #define camel_store_info_name(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_STORE_INFO_NAME))
183
184 void camel_store_summary_lock   (CamelStoreSummary *summary, CamelStoreSummaryLock lock);
185 void camel_store_summary_unlock (CamelStoreSummary *summary, CamelStoreSummaryLock lock);
186
187 struct _CamelFolderSummary;
188 gboolean camel_store_summary_connect_folder_summary (CamelStoreSummary *summary, const gchar *path, struct _CamelFolderSummary *folder_summary);
189 gboolean camel_store_summary_disconnect_folder_summary (CamelStoreSummary *summary, struct _CamelFolderSummary *folder_summary);
190
191 G_END_DECLS
192
193 #endif /* CAMEL_STORE_SUMMARY_H */