more docs written
[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) 2000 Ximian Inc.
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 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 General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22
23 #ifndef _CAMEL_STORE_SUMMARY_H
24 #define _CAMEL_STORE_SUMMARY_H
25
26 #ifdef __cplusplus
27 extern "C" {
28 #pragma }
29 #endif /* __cplusplus */
30
31 #include <stdio.h>
32
33 #include <glib.h>
34
35 #include <camel/camel-mime-parser.h>
36 #include <camel/camel-object.h>
37 #include <camel/camel-url.h>
38
39 #define CAMEL_STORE_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_store_summary_get_type (), CamelStoreSummary)
40 #define CAMEL_STORE_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_store_summary_get_type (), CamelStoreSummaryClass)
41 #define CAMEL_IS_STORE_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_store_summary_get_type ())
42
43 typedef struct _CamelStoreSummary      CamelStoreSummary;
44 typedef struct _CamelStoreSummaryClass CamelStoreSummaryClass;
45
46 typedef struct _CamelStoreInfo CamelStoreInfo;
47
48 /* FIXME: this needs to track the CAMEL_FOLDER_* flags in camel-store.h */
49 typedef enum _CamelStoreInfoFlags {
50         CAMEL_STORE_INFO_FOLDER_NOSELECT = 1<<0,
51         CAMEL_STORE_INFO_FOLDER_NOINFERIORS = 1<<1,
52         CAMEL_STORE_INFO_FOLDER_CHILDREN = 1<<2,
53         CAMEL_STORE_INFO_FOLDER_NOCHILDREN = 1<<3,
54         CAMEL_STORE_INFO_FOLDER_SUBSCRIBED = 1<<4,
55         CAMEL_STORE_INFO_FOLDER_VIRTUAL = 1<<5,
56         CAMEL_STORE_INFO_FOLDER_SYSTEM = 1<<6,
57         CAMEL_STORE_INFO_FOLDER_VTRASH = 1<<7,
58         CAMEL_STORE_INFO_FOLDER_SHARED_BY_ME = 1<<8,
59         CAMEL_STORE_INFO_FOLDER_SHARED_TO_ME = 1<<9,
60
61         /* not in camle-store.h yet */
62         CAMEL_STORE_INFO_FOLDER_READONLY = 1<<13,
63
64         CAMEL_STORE_INFO_FOLDER_FLAGGED = 1<<31
65 } CamelStoreInfoFlags;
66
67 #define CAMEL_STORE_INFO_FOLDER_UNKNOWN (~0)
68
69 enum {
70         CAMEL_STORE_INFO_PATH = 0,
71         CAMEL_STORE_INFO_NAME,
72         CAMEL_STORE_INFO_URI,
73         CAMEL_STORE_INFO_LAST,
74 };
75
76 struct _CamelStoreInfo {
77         guint32 refcount;
78         char *uri;
79         char *path;
80         guint32 flags;
81         guint32 unread;
82         guint32 total;
83 };
84
85 typedef enum _CamelStoreSummaryFlags {
86         CAMEL_STORE_SUMMARY_DIRTY = 1<<0,
87         CAMEL_STORE_SUMMARY_FRAGMENT = 1<<1, /* path name is stored in fragment rather than path */
88 } CamelStoreSummaryFlags;
89
90 struct _CamelStoreSummary {
91         CamelObject parent;
92
93         struct _CamelStoreSummaryPrivate *priv;
94
95         /* header info */
96         guint32 version;        /* version of base part of file */
97         guint32 flags;          /* flags */
98         guint32 count;          /* how many were saved/loaded */
99         time_t time;            /* timestamp for this summary (for implementors to use) */
100         struct _CamelURL *uri_base;     /* url of base part of summary */
101
102         /* sizes of memory objects */
103         guint32 store_info_size;
104
105         /* memory allocators (setup automatically) */
106         struct _EMemChunk *store_info_chunks;
107
108         char *summary_path;
109
110         GPtrArray *folders;     /* CamelStoreInfo's */
111         GHashTable *folders_path; /* CamelStoreInfo's by path name */
112 };
113
114 struct _CamelStoreSummaryClass {
115         CamelObjectClass parent_class;
116
117         /* load/save the global info */
118         int (*summary_header_load)(CamelStoreSummary *, FILE *);
119         int (*summary_header_save)(CamelStoreSummary *, FILE *);
120
121         /* create/save/load an individual message info */
122         CamelStoreInfo * (*store_info_new)(CamelStoreSummary *, const char *path);
123         CamelStoreInfo * (*store_info_load)(CamelStoreSummary *, FILE *);
124         int               (*store_info_save)(CamelStoreSummary *, FILE *, CamelStoreInfo *);
125         void              (*store_info_free)(CamelStoreSummary *, CamelStoreInfo *);
126
127         /* virtualise access methods */
128         const char *(*store_info_string)(CamelStoreSummary *, const CamelStoreInfo *, int);
129         void (*store_info_set_string)(CamelStoreSummary *, CamelStoreInfo *, int, const char *);
130 };
131
132 CamelType                        camel_store_summary_get_type   (void);
133 CamelStoreSummary      *camel_store_summary_new (void);
134
135 void camel_store_summary_set_filename(CamelStoreSummary *summary, const char *filename);
136 void camel_store_summary_set_uri_base(CamelStoreSummary *summary, CamelURL *base);
137
138 /* load/save the summary in its entirety */
139 int camel_store_summary_load(CamelStoreSummary *summary);
140 int camel_store_summary_save(CamelStoreSummary *summary);
141
142 /* only load the header */
143 int camel_store_summary_header_load(CamelStoreSummary *summary);
144
145 /* set the dirty bit on the summary */
146 void camel_store_summary_touch(CamelStoreSummary *summary);
147
148 /* add a new raw summary item */
149 void camel_store_summary_add(CamelStoreSummary *summary, CamelStoreInfo *info);
150
151 /* build/add raw summary items */
152 CamelStoreInfo *camel_store_summary_add_from_path(CamelStoreSummary *summary, const char *path);
153
154 /* Just build raw summary items */
155 CamelStoreInfo *camel_store_summary_info_new(CamelStoreSummary *summary);
156 CamelStoreInfo *camel_store_summary_info_new_from_path(CamelStoreSummary *summary, const char *path);
157
158 void camel_store_summary_info_ref(CamelStoreSummary *summary, CamelStoreInfo *info);
159 void camel_store_summary_info_free(CamelStoreSummary *summary, CamelStoreInfo *info);
160
161 /* removes a summary item */
162 void camel_store_summary_remove(CamelStoreSummary *summary, CamelStoreInfo *info);
163 void camel_store_summary_remove_path(CamelStoreSummary *summary, const char *path);
164 void camel_store_summary_remove_index(CamelStoreSummary *summary, int index);
165
166 /* remove all items */
167 void camel_store_summary_clear(CamelStoreSummary *summary);
168
169 /* lookup functions */
170 int camel_store_summary_count(CamelStoreSummary *summary);
171 CamelStoreInfo *camel_store_summary_index(CamelStoreSummary *summary, int index);
172 CamelStoreInfo *camel_store_summary_path(CamelStoreSummary *summary, const char *path);
173 GPtrArray *camel_store_summary_array(CamelStoreSummary *summary);
174 void camel_store_summary_array_free(CamelStoreSummary *summary, GPtrArray *array);
175
176 const char *camel_store_info_string(CamelStoreSummary *summary, const CamelStoreInfo *info, int type);
177 void camel_store_info_set_string(CamelStoreSummary *summary, CamelStoreInfo *info, int type, const char *value);
178
179 /* helper macro's */
180 #define camel_store_info_path(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_STORE_INFO_PATH))
181 #define camel_store_info_uri(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_STORE_INFO_URI))
182 #define camel_store_info_name(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_STORE_INFO_NAME))
183
184 #ifdef __cplusplus
185 }
186 #endif /* __cplusplus */
187
188 #endif /* ! _CAMEL_STORE_SUMMARY_H */