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.vfolder-hacks
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 } Entry;
86
87 Entry        *entry_new                  (VFolderInfo *info,
88                                           const gchar *filename,
89                                           const gchar *displayname,
90                                           gboolean     user_private,
91                                           gushort      weight);
92
93 void          entry_ref                  (Entry *entry);
94 void          entry_unref                (Entry *entry);
95
96 void          entry_alloc                (Entry *entry);
97 void          entry_dealloc              (Entry *entry);
98 gboolean      entry_is_allocated         (Entry *entry);
99
100 gboolean      entry_make_user_private    (Entry *entry, Folder *folder);
101 gboolean      entry_is_user_private      (Entry *entry);
102
103 gushort       entry_get_weight           (Entry *entry);
104 void          entry_set_weight           (Entry *entry, gushort weight);
105
106 void          entry_set_dirty            (Entry *entry);
107
108 void          entry_set_filename         (Entry *entry, const gchar *name);
109 const gchar  *entry_get_filename         (Entry *entry);
110
111 void          entry_set_displayname      (Entry *entry, const gchar *name);
112 const gchar  *entry_get_displayname      (Entry *entry);
113
114 GnomeVFSURI  *entry_get_real_uri         (Entry *entry);
115
116 const GSList *entry_get_keywords         (Entry *entry);
117 void          entry_add_implicit_keyword (Entry *entry, GQuark keyword);
118
119 void          entry_quick_read_keys      (Entry        *entry,
120                                           const gchar  *key1,
121                                           gchar       **value1,
122                                           const gchar  *key2,
123                                           gchar       **value2);
124
125 void          entry_dump                 (Entry *entry, int indent);
126
127
128 /* 
129  * Folder API
130  */
131 struct _Folder {
132         gint               refcnt;
133
134         VFolderInfo       *info;
135
136         char              *name;
137
138         gchar             *extend_uri;
139         VFolderMonitor    *extend_monitor;
140
141         Folder            *parent;
142
143         char              *desktop_file;     /* the .directory file */
144
145         Query             *query;
146
147         /* The following is for per file access */
148         GHashTable        *excludes;         /* excluded by dirname/fileuri */
149         GSList            *includes;         /* included by dirname/fileuri */
150
151         GSList            *subfolders;
152         GHashTable        *subfolders_ht;
153
154         GSList            *entries;
155         GHashTable        *entries_ht;
156
157         /* Some flags */
158         guint              read_only : 1;
159         guint              dont_show_if_empty : 1;
160         guint              only_unallocated : 1; /* include only unallocated */
161         guint              is_link : 1;
162
163         guint              has_user_private_subfolders : 1;
164         guint              user_private : 1;
165
166         /* lazily done, will run query only when it needs to */
167         guint              dirty : 1;
168         guint              loading : 1;
169         guint              sorted : 1;
170 };
171
172 typedef struct {
173         enum {
174                 FOLDER = 1,
175                 DESKTOP_FILE,
176                 UNKNOWN_URI
177         } type;
178         
179         Folder      *folder;
180         Entry       *entry;
181         GnomeVFSURI *uri;
182 } FolderChild;
183
184 Folder       *folder_new               (VFolderInfo *info, 
185                                         const gchar *name,
186                                         gboolean     user_private);
187
188 void          folder_ref               (Folder *folder);
189 void          folder_unref             (Folder *folder);
190
191 gboolean      folder_make_user_private (Folder *folder);
192 gboolean      folder_is_user_private   (Folder *folder);
193
194 void          folder_set_dirty         (Folder *folder);
195
196 void          folder_set_name          (Folder *folder, const gchar *name);
197 const gchar  *folder_get_name          (Folder *folder);
198
199 void          folder_set_query         (Folder *folder, Query *query);
200 Query        *folder_get_query         (Folder *folder);
201
202 void          folder_set_extend_uri    (Folder *folder, const gchar *uri);
203 const gchar  *folder_get_extend_uri    (Folder *folder);
204
205 void          folder_set_desktop_file  (Folder *folder, const gchar *filename);
206 const gchar  *folder_get_desktop_file  (Folder *folder);
207
208 gboolean      folder_get_child         (Folder      *folder, 
209                                         const gchar *name,
210                                         FolderChild *child);
211 GSList       *folder_list_children     (Folder      *folder);
212
213 Entry        *folder_get_entry         (Folder *folder, const gchar *filename);
214 const GSList *folder_list_entries      (Folder *folder);
215 void          folder_remove_entry      (Folder *folder, Entry *entry);
216 void          folder_add_entry         (Folder *folder, Entry *entry);
217
218 void          folder_add_include       (Folder *folder, const gchar *file);
219 void          folder_remove_include    (Folder *folder, const gchar *file);
220
221 void          folder_add_exclude       (Folder *folder, const gchar *file);
222 void          folder_remove_exclude    (Folder *folder, const gchar *file);
223
224 Folder       *folder_get_subfolder     (Folder *folder, const gchar *name);
225 const GSList *folder_list_subfolders   (Folder *folder);
226 void          folder_remove_subfolder  (Folder *folder, Folder *sub);
227 void          folder_add_subfolder     (Folder *folder, Folder *sub);
228
229 gboolean      folder_is_hidden         (Folder *folder);
230
231 void          folder_dump_tree         (Folder *folder, int indent);
232
233 void          folder_emit_changed      (Folder                   *folder,
234                                         const gchar              *child,
235                                         GnomeVFSMonitorEventType  event_type);
236
237
238 /* 
239  * Query API
240  */
241 struct _Query {
242         enum {
243                 QUERY_OR,
244                 QUERY_AND,
245                 QUERY_PARENT,
246                 QUERY_KEYWORD,
247                 QUERY_FILENAME
248         } type;
249         union {
250                 GSList   *queries;
251                 GQuark    keyword;
252                 gchar    *filename;
253         } val;
254         guint not : 1;
255 };
256
257 Query    *query_new (int type);
258
259 void      query_free (Query *query);
260
261 gboolean  query_try_match (Query  *query,
262                            Folder *folder,
263                            Entry  *efile);
264
265 /* 
266  * VFolderInfo API
267  */
268 /* NOTE: Exposed only so do_monitor_cancel can lock the VFolderInfo */
269 typedef struct {
270         GnomeVFSURI         *uri;
271         GnomeVFSMonitorType  type;
272         VFolderInfo         *info;
273 } MonitorHandle;
274
275 struct _VFolderInfo {
276         GStaticRWLock   rw_lock;
277
278         char           *scheme;
279
280         char           *filename;
281         VFolderMonitor *filename_monitor;
282         guint           filename_reload_tag;
283
284         /* dir where user changes to items are stored */
285         char           *write_dir; 
286         VFolderMonitor *write_dir_monitor;
287
288         /* deprecated */
289         char           *desktop_dir; /* directory with .directorys */
290         VFolderMonitor *desktop_dir_monitor;
291
292         /* Consider item dirs and mergedirs writeable?? */
293         /* Monitoring on mergedirs?? */
294         GSList         *item_dirs;          /* CONTAINS: ItemDir */
295
296         GSList         *entries;            /* CONTAINS: Entry */
297         GHashTable     *entries_ht;         /* KEY: Entry->name, VALUE: Entry */
298
299         /* The root folder */
300         Folder         *root;
301
302         /* some flags */
303         guint           read_only : 1;
304         guint           dirty : 1;
305         guint           loading : 1;
306         guint           has_unallocated_folder : 1;
307
308         GSList         *requested_monitors; /* CONTAINS: MonitorHandle */
309
310         /* ctime for folders */
311         time_t          modification_time;
312 };
313
314 #define VFOLDER_INFO_READ_LOCK(vi) \
315         g_static_rw_lock_reader_lock (&(vi->rw_lock))
316 #define VFOLDER_INFO_READ_UNLOCK(vi) \
317         g_static_rw_lock_reader_unlock (&(vi->rw_lock))
318
319 #define VFOLDER_INFO_WRITE_LOCK(vi) \
320         g_static_rw_lock_writer_lock (&(vi->rw_lock))
321 /* Writes out .vfolder-info file if there are changes */
322 #define VFOLDER_INFO_WRITE_UNLOCK(vi)                   \
323         vfolder_info_write_user (vi);                   \
324         g_static_rw_lock_writer_unlock (&(vi->rw_lock))
325
326 VFolderInfo  *vfolder_info_locate           (const gchar *scheme);
327
328 void          vfolder_info_set_dirty        (VFolderInfo *info);
329 void          vfolder_info_write_user       (VFolderInfo *info);
330
331 Folder       *vfolder_info_get_folder       (VFolderInfo *info, 
332                                              const gchar *path);
333 Folder       *vfolder_info_get_parent       (VFolderInfo *info, 
334                                              const gchar *path);
335 Entry        *vfolder_info_get_entry        (VFolderInfo *info, 
336                                              const gchar *path);
337
338 const GSList *vfolder_info_list_all_entries (VFolderInfo *info);
339 Entry        *vfolder_info_lookup_entry     (VFolderInfo *info, 
340                                              const gchar *name);
341 void          vfolder_info_add_entry        (VFolderInfo *info, Entry *entry);
342 void          vfolder_info_remove_entry     (VFolderInfo *info, Entry *entry);
343
344 void          vfolder_info_emit_change      (VFolderInfo              *info,
345                                              const char               *path,
346                                              GnomeVFSMonitorEventType  event_type);
347
348 void          vfolder_info_add_monitor      (VFolderInfo           *info,
349                                              GnomeVFSMonitorType    type,
350                                              GnomeVFSURI           *path,
351                                              GnomeVFSMethodHandle **handle);
352 void          vfolder_info_cancel_monitor   (GnomeVFSMethodHandle  *handle);
353
354 void          vfolder_info_destroy_all      (void);
355
356 void          vfolder_info_dump_entries     (VFolderInfo *info, int offset);
357
358 G_END_DECLS
359
360 #endif /* VFOLDER_COMMON_H */