Lots of changes, too numerous to list. Changed to use
[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 enum _CamelStoreInfoFlags {
49         CAMEL_STORE_INFO_FOLDER_NOSELECT,
50         CAMEL_STORE_INFO_FOLDER_READONLY,
51         CAMEL_STORE_INFO_FOLDER_SUBSCRIBED,
52         CAMEL_STORE_INFO_FOLDER_FLAGGED,
53 };
54
55 #define CAMEL_STORE_INFO_FOLDER_UNKNOWN (~0)
56
57 enum {
58         CAMEL_STORE_INFO_PATH = 0,
59         CAMEL_STORE_INFO_NAME,
60         CAMEL_STORE_INFO_URI,
61         CAMEL_STORE_INFO_LAST,
62 };
63
64 struct _CamelStoreInfo {
65         guint32 refcount;
66         char *uri;
67         char *path;
68         guint32 flags;
69         guint32 unread;
70         guint32 total;
71 };
72
73 enum _CamelStoreSummaryFlags {
74         CAMEL_STORE_SUMMARY_DIRTY = 1<<0,
75         CAMEL_STORE_SUMMARY_FRAGMENT = 1<<1, /* path name is stored in fragment rather than path */
76 };
77
78 struct _CamelStoreSummary {
79         CamelObject parent;
80
81         struct _CamelStoreSummaryPrivate *priv;
82
83         /* header info */
84         guint32 version;        /* version of base part of file */
85         guint32 flags;          /* flags */
86         guint32 count;          /* how many were saved/loaded */
87         time_t time;            /* timestamp for this summary (for implementors to use) */
88         struct _CamelURL *uri_base;     /* url of base part of summary */
89
90         /* sizes of memory objects */
91         guint32 store_info_size;
92
93         /* memory allocators (setup automatically) */
94         struct _EMemChunk *store_info_chunks;
95
96         char *summary_path;
97
98         GPtrArray *folders;     /* CamelStoreInfo's */
99         GHashTable *folders_path; /* CamelStoreInfo's by path name */
100 };
101
102 struct _CamelStoreSummaryClass {
103         CamelObjectClass parent_class;
104
105         /* load/save the global info */
106         int (*summary_header_load)(CamelStoreSummary *, FILE *);
107         int (*summary_header_save)(CamelStoreSummary *, FILE *);
108
109         /* create/save/load an individual message info */
110         CamelStoreInfo * (*store_info_new)(CamelStoreSummary *, const char *path);
111         CamelStoreInfo * (*store_info_load)(CamelStoreSummary *, FILE *);
112         int               (*store_info_save)(CamelStoreSummary *, FILE *, CamelStoreInfo *);
113         void              (*store_info_free)(CamelStoreSummary *, CamelStoreInfo *);
114
115         /* virtualise access methods */
116         const char *(*store_info_string)(CamelStoreSummary *, const CamelStoreInfo *, int);
117         void (*store_info_set_string)(CamelStoreSummary *, CamelStoreInfo *, int, const char *);
118 };
119
120 CamelType                        camel_store_summary_get_type   (void);
121 CamelStoreSummary      *camel_store_summary_new (void);
122
123 void camel_store_summary_set_filename(CamelStoreSummary *, const char *);
124 void camel_store_summary_set_uri_base(CamelStoreSummary *s, CamelURL *base);
125
126 /* load/save the summary in its entirety */
127 int camel_store_summary_load(CamelStoreSummary *);
128 int camel_store_summary_save(CamelStoreSummary *);
129
130 /* only load the header */
131 int camel_store_summary_header_load(CamelStoreSummary *);
132
133 /* set the dirty bit on the summary */
134 void camel_store_summary_touch(CamelStoreSummary *s);
135
136 /* add a new raw summary item */
137 void camel_store_summary_add(CamelStoreSummary *, CamelStoreInfo *info);
138
139 /* build/add raw summary items */
140 CamelStoreInfo *camel_store_summary_add_from_path(CamelStoreSummary *, const char *);
141
142 /* Just build raw summary items */
143 CamelStoreInfo *camel_store_summary_info_new(CamelStoreSummary *s);
144 CamelStoreInfo *camel_store_summary_info_new_from_path(CamelStoreSummary *s, const char *);
145
146 void camel_store_summary_info_ref(CamelStoreSummary *, CamelStoreInfo *);
147 void camel_store_summary_info_free(CamelStoreSummary *, CamelStoreInfo *);
148
149 /* removes a summary item */
150 void camel_store_summary_remove(CamelStoreSummary *s, CamelStoreInfo *info);
151 void camel_store_summary_remove_path(CamelStoreSummary *s, const char *path);
152 void camel_store_summary_remove_index(CamelStoreSummary *s, int);
153
154 /* remove all items */
155 void camel_store_summary_clear(CamelStoreSummary *s);
156
157 /* lookup functions */
158 int camel_store_summary_count(CamelStoreSummary *);
159 CamelStoreInfo *camel_store_summary_index(CamelStoreSummary *, int);
160 CamelStoreInfo *camel_store_summary_path(CamelStoreSummary *, const char *uid);
161 GPtrArray *camel_store_summary_array(CamelStoreSummary *s);
162 void camel_store_summary_array_free(CamelStoreSummary *s, GPtrArray *array);
163
164 const char *camel_store_info_string(CamelStoreSummary *, const CamelStoreInfo *, int type);
165 void camel_store_info_set_string(CamelStoreSummary *, CamelStoreInfo *, int type, const char *value);
166
167 /* helper macro's */
168 #define camel_store_info_path(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_STORE_INFO_PATH))
169 #define camel_store_info_uri(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_STORE_INFO_URI))
170 #define camel_store_info_name(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_STORE_INFO_NAME))
171
172 #ifdef __cplusplus
173 }
174 #endif /* __cplusplus */
175
176 #endif /* ! _CAMEL_STORE_SUMMARY_H */