ftp://ftp.redhat.com/pub/redhat/linux/rawhide/SRPMS/SRPMS/gnome-vfs2-2.3.8-1.src.rpm
[gnome-vfs-httpcaptive.git] / modules / vfolder / vfolder-common.h
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* 
3  * vfolder-common.h - Abstract Folder, Entry, Query, and VFolderInfo 
4  *                    interfaces.
5  *
6  * Copyright (C) 2002 Ximian, Inc.
7  *
8  * The Gnome Library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * The Gnome Library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with the Gnome Library; see the file COPYING.LIB.  If not,
20  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  * Author: Alex Graveley <alex@ximian.com>
24  *         Based on original code by George Lebl <jirka@5z.com>.
25  */
26
27 #ifndef VFOLDER_COMMON_H
28 #define VFOLDER_COMMON_H
29
30 #include <glib.h>
31 #include <libgnomevfs/gnome-vfs-uri.h>
32 #include <libgnomevfs/gnome-vfs-method.h>
33
34 #include "vfolder-util.h"
35
36 G_BEGIN_DECLS
37
38 /* Turn this on to test the non-FAM monitoring code
39  */
40 #undef VFOLDER_DEBUG_WITHOUT_MONITORING
41
42 /* Turn this on to spew debugging info
43  */
44 #undef VFOLDER_DEBUG
45
46 #ifdef VFOLDER_DEBUG
47 #define D(x) x
48 #else
49 #define D(x) do {} while (0)
50 #endif
51
52 typedef struct _VFolderInfo VFolderInfo;
53 typedef struct _Query Query;
54 typedef struct _Folder Folder;
55
56 /* 
57  * Entry API
58  */
59 typedef struct {
60         gushort         refcnt;
61         gushort         allocs;
62
63         /* 
64          * Weight lets us determine if a monitor's file created (or changed) 
65          * event should replace an existing visible entry.  Higher weights 
66          * are more valuable:
67          *      1000 - WriteDir entries
68          *       900 - folder parent entries
69          *       800 - GNOME2_PATH entries in order
70          *       700 - MergeDir/ItemDir entries in order
71          */
72         gushort         weight;  
73
74         VFolderInfo    *info;
75
76         char           *displayname;
77         char           *filename;
78         GnomeVFSURI    *uri;
79
80         GSList         *keywords;          /* GQuark */
81         GSList         *implicit_keywords; /* GQuark */ 
82
83         guint           dirty : 1;
84         guint           user_private : 1;
85         guint           not_shown : 1; /* OnlyShowIn=SomeOtherDesktop */
86 } Entry;
87
88 Entry        *entry_new                  (VFolderInfo *info,
89                                           const gchar *filename,
90                                           const gchar *displayname,
91                                           gboolean     user_private,
92                                           gushort      weight);
93
94 void          entry_ref                  (Entry *entry);
95 void          entry_unref                (Entry *entry);
96
97 void          entry_alloc                (Entry *entry);
98 void          entry_dealloc              (Entry *entry);
99 gboolean      entry_is_allocated         (Entry *entry);
100
101 gboolean      entry_make_user_private    (Entry *entry, Folder *folder);
102 gboolean      entry_is_user_private      (Entry *entry);
103
104 gushort       entry_get_weight           (Entry *entry);
105 void          entry_set_weight           (Entry *entry, gushort weight);
106
107 void          entry_set_dirty            (Entry *entry);
108
109 void          entry_set_filename         (Entry *entry, const gchar *name);
110 const gchar  *entry_get_filename         (Entry *entry);
111
112 void          entry_set_displayname      (Entry *entry, const gchar *name);
113 const gchar  *entry_get_displayname      (Entry *entry);
114
115 GnomeVFSURI  *entry_get_real_uri         (Entry *entry);
116
117 const GSList *entry_get_keywords         (Entry *entry);
118 void          entry_add_implicit_keyword (Entry *entry, GQuark keyword);
119
120 void          entry_quick_read_keys      (Entry        *entry,
121                                           const gchar  *key1,
122                                           gchar       **value1,
123                                           const gchar  *key2,
124                                           gchar       **value2,
125                                           const gchar  *key3,
126                                           gchar       **value3);
127
128 void          entry_dump                 (Entry *entry, int indent);
129
130
131 /* 
132  * Folder API
133  */
134 struct _Folder {
135         gint               refcnt;
136
137         VFolderInfo       *info;
138
139         char              *name;
140
141         gchar             *extend_uri;
142         VFolderMonitor    *extend_monitor;
143
144         Folder            *parent;
145
146         char              *desktop_file;     /* the .directory file */
147
148         Query             *query;
149
150         /* The following is for per file access */
151         GHashTable        *excludes;         /* excluded by dirname/fileuri */
152         GSList            *includes;         /* included by dirname/fileuri */
153
154         GSList            *subfolders;
155         GHashTable        *subfolders_ht;
156
157         GSList            *entries;
158         GHashTable        *entries_ht;
159
160         /* Some flags */
161         guint              read_only : 1;
162         guint              dont_show_if_empty : 1;
163         guint              only_unallocated : 1; /* include only unallocated */
164         guint              is_link : 1;
165
166         guint              has_user_private_subfolders : 1;
167         guint              user_private : 1;
168
169         /* lazily done, will run query only when it needs to */
170         guint              dirty : 1;
171         guint              loading : 1;
172         guint              sorted : 1;
173 };
174
175 typedef struct {
176         enum {
177                 FOLDER = 1,
178                 DESKTOP_FILE,
179                 UNKNOWN_URI
180         } type;
181         
182         Folder      *folder;
183         Entry       *entry;
184         GnomeVFSURI *uri;
185 } FolderChild;
186
187 Folder       *folder_new               (VFolderInfo *info, 
188                                         const gchar *name,
189                                         gboolean     user_private);
190
191 void          folder_ref               (Folder *folder);
192 void          folder_unref             (Folder *folder);
193
194 gboolean      folder_make_user_private (Folder *folder);
195 gboolean      folder_is_user_private   (Folder *folder);
196
197 void          folder_set_dirty         (Folder *folder);
198
199 void          folder_set_name          (Folder *folder, const gchar *name);
200 const gchar  *folder_get_name          (Folder *folder);
201
202 void          folder_set_query         (Folder *folder, Query *query);
203 Query        *folder_get_query         (Folder *folder);
204
205 void          folder_set_extend_uri    (Folder *folder, const gchar *uri);
206 const gchar  *folder_get_extend_uri    (Folder *folder);
207
208 void          folder_set_desktop_file  (Folder *folder, const gchar *filename);
209 const gchar  *folder_get_desktop_file  (Folder *folder);
210
211 gboolean      folder_get_child         (Folder      *folder, 
212                                         const gchar *name,
213                                         FolderChild *child);
214 GSList       *folder_list_children     (Folder      *folder);
215
216 Entry        *folder_get_entry         (Folder *folder, const gchar *filename);
217 const GSList *folder_list_entries      (Folder *folder);
218 void          folder_remove_entry      (Folder *folder, Entry *entry);
219 void          folder_add_entry         (Folder *folder, Entry *entry);
220
221 void          folder_add_include       (Folder *folder, const gchar *file);
222 void          folder_remove_include    (Folder *folder, const gchar *file);
223
224 void          folder_add_exclude       (Folder *folder, const gchar *file);
225 void          folder_remove_exclude    (Folder *folder, const gchar *file);
226
227 Folder       *folder_get_subfolder     (Folder *folder, const gchar *name);
228 const GSList *folder_list_subfolders   (Folder *folder);
229 void          folder_remove_subfolder  (Folder *folder, Folder *sub);
230 void          folder_add_subfolder     (Folder *folder, Folder *sub);
231
232 gboolean      folder_is_hidden         (Folder *folder);
233
234 void          folder_dump_tree         (Folder *folder, int indent);
235
236 void          folder_emit_changed      (Folder                   *folder,
237                                         const gchar              *child,
238                                         GnomeVFSMonitorEventType  event_type);
239
240
241 /* 
242  * Query API
243  */
244 struct _Query {
245         enum {
246                 QUERY_OR,
247                 QUERY_AND,
248                 QUERY_PARENT,
249                 QUERY_KEYWORD,
250                 QUERY_FILENAME
251         } type;
252         union {
253                 GSList   *queries;
254                 GQuark    keyword;
255                 gchar    *filename;
256         } val;
257         guint not : 1;
258 };
259
260 Query    *query_new (int type);
261
262 void      query_free (Query *query);
263
264 gboolean  query_try_match (Query  *query,
265                            Folder *folder,
266                            Entry  *efile);
267
268 /* 
269  * VFolderInfo API
270  */
271 /* NOTE: Exposed only so do_monitor_cancel can lock the VFolderInfo */
272 typedef struct {
273         GnomeVFSURI         *uri;
274         GnomeVFSMonitorType  type;
275         VFolderInfo         *info;
276 } MonitorHandle;
277
278 struct _VFolderInfo {
279         GStaticRWLock   rw_lock;
280
281         char           *scheme;
282
283         char           *filename;
284         VFolderMonitor *filename_monitor;
285         guint           filename_reload_tag;
286
287         /* dir where user changes to items are stored */
288         char           *write_dir; 
289         VFolderMonitor *write_dir_monitor;
290
291         /* deprecated */
292         char           *desktop_dir; /* directory with .directorys */
293         VFolderMonitor *desktop_dir_monitor;
294
295         /* Consider item dirs and mergedirs writeable?? */
296         /* Monitoring on mergedirs?? */
297         GSList         *item_dirs;          /* CONTAINS: ItemDir */
298
299         GSList         *entries;            /* CONTAINS: Entry */
300         GHashTable     *entries_ht;         /* KEY: Entry->name, VALUE: Entry */
301
302         /* The root folder */
303         Folder         *root;
304
305         /* some flags */
306         guint           read_only : 1;
307         guint           dirty : 1;
308         guint           loading : 1;
309         guint           has_unallocated_folder : 1;
310
311         GSList         *requested_monitors; /* CONTAINS: MonitorHandle */
312
313         /* ctime for folders */
314         time_t          modification_time;
315 };
316
317 #define VFOLDER_INFO_READ_LOCK(vi) \
318         g_static_rw_lock_reader_lock (&(vi->rw_lock))
319 #define VFOLDER_INFO_READ_UNLOCK(vi) \
320         g_static_rw_lock_reader_unlock (&(vi->rw_lock))
321
322 #define VFOLDER_INFO_WRITE_LOCK(vi) \
323         g_static_rw_lock_writer_lock (&(vi->rw_lock))
324 /* Writes out .vfolder-info file if there are changes */
325 #define VFOLDER_INFO_WRITE_UNLOCK(vi)                   \
326         vfolder_info_write_user (vi);                   \
327         g_static_rw_lock_writer_unlock (&(vi->rw_lock))
328
329 VFolderInfo  *vfolder_info_locate           (const gchar *scheme);
330
331 void          vfolder_info_set_dirty        (VFolderInfo *info);
332 void          vfolder_info_write_user       (VFolderInfo *info);
333
334 Folder       *vfolder_info_get_folder       (VFolderInfo *info, 
335                                              const gchar *path);
336 Folder       *vfolder_info_get_parent       (VFolderInfo *info, 
337                                              const gchar *path);
338 Entry        *vfolder_info_get_entry        (VFolderInfo *info, 
339                                              const gchar *path);
340
341 const GSList *vfolder_info_list_all_entries (VFolderInfo *info);
342 Entry        *vfolder_info_lookup_entry     (VFolderInfo *info, 
343                                              const gchar *name);
344 void          vfolder_info_add_entry        (VFolderInfo *info, Entry *entry);
345 void          vfolder_info_remove_entry     (VFolderInfo *info, Entry *entry);
346
347 void          vfolder_info_emit_change      (VFolderInfo              *info,
348                                              const char               *path,
349                                              GnomeVFSMonitorEventType  event_type);
350
351 void          vfolder_info_add_monitor      (VFolderInfo           *info,
352                                              GnomeVFSMonitorType    type,
353                                              GnomeVFSURI           *path,
354                                              GnomeVFSMethodHandle **handle);
355 void          vfolder_info_cancel_monitor   (GnomeVFSMethodHandle  *handle);
356
357 void          vfolder_info_destroy_all      (void);
358
359 void          vfolder_info_dump_entries     (VFolderInfo *info, int offset);
360
361 G_END_DECLS
362
363 #endif /* VFOLDER_COMMON_H */