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