annotate src/collect-io.c @ 364:4862e9a61f3d

collection_load(): fix typo (missing #) made in rev 453.
author zas_
date Mon, 14 Apr 2008 23:09:48 +0000
parents 5b8617c3821c
children addd05a425fe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
196
f6e307c7bad6 rename GQview -> Geeqie over the code
nadvornik
parents: 138
diff changeset
2 * Geeqie
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
3 * (C) 2004 John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
4 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 236
diff changeset
13 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14 #include "collect-io.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16 #include "collect.h"
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
17 #include "filelist.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
18 #include "layout_util.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include "rcfile.h"
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
20 #include "secure_save.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21 #include "thumb.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24
288
d1f74154463e Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents: 283
diff changeset
25 #define GQ_COLLECTION_MARKER "#" GQ_APPNAME
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26
283
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
27 #define GQ_COLLECTION_FAIL_MIN 300
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
28 #define GQ_COLLECTION_FAIL_PERCENT 98
360
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
29 #define GQ_COLLECTION_READ_BUFSIZE 4096
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
31 typedef struct _CollectManagerEntry CollectManagerEntry;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 static void collection_load_thumb_step(CollectionData *cd);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
34 static gint collection_save_private(CollectionData *cd, const gchar *path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
35
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
36 static CollectManagerEntry *collect_manager_get_entry(const gchar *path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
37 static void collect_manager_entry_reset(CollectManagerEntry *entry);
235
a154d41fd666 Make collect_manager_process_action() static.
zas_
parents: 217
diff changeset
38 static gint collect_manager_process_action(CollectManagerEntry *entry, gchar **path_ptr);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 static gint scan_geometry(gchar *buffer, gint *x, gint *y, gint *w, gint *h)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 gint nx, ny, nw, nh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45 if(sscanf(buffer, "%d %d %d %d", &nx, &ny, &nw, &nh) != 4) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 *x = nx;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 *y = ny;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 *w = nw;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 *h = nh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
55 static gint collection_load_private(CollectionData *cd, const gchar *path, CollectionLoadFlags flags)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56 {
360
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
57 gchar s_buf[GQ_COLLECTION_READ_BUFSIZE];
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 FILE *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 gchar *pathl;
361
e0295af4f716 collection_load(): replace official by limit_failures (and
zas_
parents: 360
diff changeset
60 gint limit_failures = TRUE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61 gint success = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62 guint total = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63 guint fail = 0;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
64 gboolean changed = FALSE;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
65 CollectManagerEntry *entry = NULL;
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
66 guint flush = flags & COLLECTION_LOAD_FLUSH;
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
67 guint append = flags & COLLECTION_LOAD_APPEND;
359
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
68 guint only_geometry = flags & COLLECTION_LOAD_GEOMETRY;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69
359
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
70 if (!only_geometry)
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
71 {
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
72 collection_load_stop(cd);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73
359
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
74 if (flush)
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
75 collect_manager_flush();
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
76 else
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
77 entry = collect_manager_get_entry(path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78
359
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
79 if (!append)
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
80 {
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
81 collection_list_free(cd->list);
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
82 cd->list = NULL;
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
83 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86 if (!path && !cd->path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
88 if (!path) path = cd->path;
360
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
89
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
90 if (debug) printf("collection load: append=%d flush=%d only_geometry=%d path=%s\n",
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
91 append, flush, only_geometry, path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 /* load it */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 f = fopen(pathl, "r");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97 if (!f)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99 printf("Failed to open collection file: \"%s\"\n", path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 while (fgets(s_buf, sizeof(s_buf), f))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 gchar *buf;
363
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
106 gchar *p = s_buf;
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
107
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
108 /* Skip whitespaces and empty lines */
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
109 while (*p && g_ascii_isspace(*p)) p++;
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
110 if (*p == '\n' || *p == '\r') continue;
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
111
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
112 /* Parse comments */
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
113 if (*p == '#')
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114 {
363
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
115 if (strncasecmp(p, GQ_COLLECTION_MARKER, strlen(GQ_COLLECTION_MARKER)) == 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117 /* Looks like an official collection, allow unchecked input.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 * All this does is allow adding files that may not exist,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
119 * which is needed for the collection manager to work.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
120 * Also unofficial files abort after too many invalid entries.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121 */
361
e0295af4f716 collection_load(): replace official by limit_failures (and
zas_
parents: 360
diff changeset
122 limit_failures = FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123 }
363
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
124 else if (strncmp(p, "#geometry:", 10 ) == 0 &&
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
125 scan_geometry(p + 10, &cd->window_x, &cd->window_y, &cd->window_w, &cd->window_h) )
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 cd->window_read = TRUE;
359
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
128 if (only_geometry)
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
129 {
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
130 fclose(f);
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
131 return TRUE;
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
132 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 }
364
4862e9a61f3d collection_load(): fix typo (missing #) made in rev 453.
zas_
parents: 363
diff changeset
134 else if (strncasecmp(p, "#GQview collection", strlen("#GQview collection")) == 0)
360
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
135 {
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
136 /* As 2008/04/15 there is no difference between our collection file format
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
137 * and GQview 2.1.5 collection file format so ignore failures as well. */
361
e0295af4f716 collection_load(): replace official by limit_failures (and
zas_
parents: 360
diff changeset
138 limit_failures = FALSE;
360
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
139 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140 continue;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142
363
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
143 /* Read filenames */
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
144 buf = quoted_value(p, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 if (buf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147 gint valid;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
148
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
149 if (!flush)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
150 changed |= collect_manager_process_action(entry, &buf);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
151
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
152 valid = (buf[0] == '/' && collection_add_check(cd, file_data_new_simple(buf), FALSE, TRUE));
362
c5d5ebcc1e50 collection_load(): increase verbosity in debug mode.
zas_
parents: 361
diff changeset
153 if (debug && !valid) printf("collection invalid file: %s\n", buf);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156 total++;
361
e0295af4f716 collection_load(): replace official by limit_failures (and
zas_
parents: 360
diff changeset
157 if (!valid && limit_failures)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159 fail++;
283
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
160 if (fail > GQ_COLLECTION_FAIL_MIN &&
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
161 fail * 100 / total > GQ_COLLECTION_FAIL_PERCENT)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 {
362
c5d5ebcc1e50 collection_load(): increase verbosity in debug mode.
zas_
parents: 361
diff changeset
163 printf("%d invalid filenames in unoffical collection file, closing: %s\n", fail, path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164 success = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170
362
c5d5ebcc1e50 collection_load(): increase verbosity in debug mode.
zas_
parents: 361
diff changeset
171 if (debug) printf("collection files: total = %d fail = %d\n", total, fail);
c5d5ebcc1e50 collection_load(): increase verbosity in debug mode.
zas_
parents: 361
diff changeset
172
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173 fclose(f);
359
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
174 if (only_geometry) return FALSE;
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
175
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
176 if (!flush)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
177 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
178 gchar *buf = NULL;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
179 while (collect_manager_process_action(entry, &buf))
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
180 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
181 collection_add_check(cd, file_data_new_simple(buf), FALSE, TRUE);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
182 changed = TRUE;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
183 g_free(buf);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
184 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
185 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 cd->list = collection_list_sort(cd->list, cd->sort_method);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
188
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
189 if (!flush && changed && success)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
190 collection_save_private(cd, path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
191
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
192 if (!flush)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
193 collect_manager_entry_reset(entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
194
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 if (!append) cd->changed = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 return success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
200 gint collection_load(CollectionData *cd, const gchar *path, CollectionLoadFlags flags)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 {
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
202 if (collection_load_private(cd, path, flags | COLLECTION_LOAD_FLUSH))
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
203 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204 layout_recent_add_path(cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
206 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
207
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
210
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
211 static void collection_load_thumb_do(CollectionData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213 GdkPixbuf *pixbuf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 if (!cd->thumb_loader || !g_list_find(cd->list, cd->thumb_info)) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 pixbuf = thumb_loader_get_pixbuf(cd->thumb_loader, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 collection_info_set_thumb(cd->thumb_info, pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 g_object_unref(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 if (cd->info_updated_func) cd->info_updated_func(cd, cd->thumb_info, cd->info_updated_data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224 static void collection_load_thumb_error_cb(ThumbLoader *tl, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 CollectionData *cd = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 collection_load_thumb_do(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 collection_load_thumb_step(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 static void collection_load_thumb_done_cb(ThumbLoader *tl, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 CollectionData *cd = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 collection_load_thumb_do(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237 collection_load_thumb_step(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 static void collection_load_thumb_step(CollectionData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243 CollectInfo *ci;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245 if (!cd->list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 collection_load_stop(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251 work = cd->list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252 ci = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 /* find first unloaded thumb */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 while (work && ci->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 ci = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
260
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
261 if (!ci || ci->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263 /* done */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 collection_load_stop(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
266 /* send a NULL CollectInfo to notify end */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
267 if (cd->info_updated_func) cd->info_updated_func(cd, NULL, cd->info_updated_data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
268
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
269 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
270 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
271
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
272 /* setup loader and call it */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
273 cd->thumb_info = ci;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
274 thumb_loader_free(cd->thumb_loader);
333
767b53cd9ab7 Rename thumbnails related options.
zas_
parents: 318
diff changeset
275 cd->thumb_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276 thumb_loader_set_callbacks(cd->thumb_loader,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277 collection_load_thumb_done_cb,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 collection_load_thumb_error_cb,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
279 NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280 cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
281
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
282 /* start it */
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
283 if (!thumb_loader_start(cd->thumb_loader, ci->fd->path))
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285 /* error, handle it, do next */
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
286 if (debug) printf("error loading thumb for %s\n", ci->fd->path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287 collection_load_thumb_do(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288 collection_load_thumb_step(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292 void collection_load_thumb_idle(CollectionData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 if (!cd->thumb_loader) collection_load_thumb_step(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
297 gint collection_load_begin(CollectionData *cd, const gchar *path, CollectionLoadFlags flags)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298 {
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
299 if (!collection_load(cd, path, flags)) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 collection_load_thumb_idle(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306 void collection_load_stop(CollectionData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 if (!cd->thumb_loader) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 thumb_loader_free(cd->thumb_loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 cd->thumb_loader = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 static gint collection_save_private(CollectionData *cd, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 {
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
316 SecureSaveInfo *ssi;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320 if (!path && !cd->path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322 if (!path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 path = cd->path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
328 pathl = path_from_utf8(path);
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
329 ssi = secure_open(pathl);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 g_free(pathl);
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
331 if (!ssi)
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
332 {
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
333 gchar *buf;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
335 buf = g_strdup_printf(_("failed to open collection (write) \"%s\"\n"), path);
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
336 print_term(buf);
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
337 g_free(buf);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
341 secure_fprintf(ssi, "%s collection\n", GQ_COLLECTION_MARKER);
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
342 secure_fprintf(ssi, "#created with %s version %s\n", GQ_APPNAME, VERSION);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 collection_update_geometry(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345 if (cd->window_read)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 {
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
347 secure_fprintf(ssi, "#geometry: %d %d %d %d\n", cd->window_x, cd->window_y, cd->window_w, cd->window_h);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 work = cd->list;
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
351 while (work && secsave_errno == SS_ERR_NONE)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 CollectInfo *ci = work->data;
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
354 secure_fprintf(ssi, "\"%s\"\n", ci->fd->path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
358 secure_fprintf(ssi, "#end\n");
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
360 if (secure_close(ssi))
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
361 {
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
362 gchar *buf;
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
363
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
364 buf = g_strdup_printf(_("error saving collection file: %s\nerror: %s\n"), path,
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
365 secsave_strerror(secsave_errno));
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
366 print_term(buf);
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
367 g_free(buf);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 if (!cd->path || strcmp(path, cd->path) != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 gchar *buf = cd->path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 cd->path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 path = cd->path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378 g_free(cd->name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 cd->name = g_strdup(filename_from_path(cd->path));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381 collection_path_changed(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 cd->changed = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389 gint collection_save(CollectionData *cd, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 if (collection_save_private(cd, path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 layout_recent_add_path(cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 gint collection_load_only_geometry(CollectionData *cd, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 {
359
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
402 return collection_load(cd, path, COLLECTION_LOAD_GEOMETRY);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408 * collection manager
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 #define COLLECT_MANAGER_ACTIONS_PER_IDLE 1000
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 #define COLLECT_MANAGER_FLUSH_DELAY 10000
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 struct _CollectManagerEntry
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 gchar *path;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
418 GList *add_list;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
419 GHashTable *oldpath_hash;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
420 GHashTable *newpath_hash;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
421 gboolean empty;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 typedef enum {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425 COLLECTION_MANAGER_UPDATE,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 COLLECTION_MANAGER_ADD,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 COLLECTION_MANAGER_REMOVE
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 } CollectManagerType;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 typedef struct _CollectManagerAction CollectManagerAction;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 struct _CollectManagerAction
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 gchar *oldpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 gchar *newpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 CollectManagerType type;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 gint ref;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442 static GList *collection_manager_entry_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443 static GList *collection_manager_action_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444 static GList *collection_manager_action_tail = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445 static gint collection_manager_timer_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 static CollectManagerAction *collect_manager_action_new(const gchar *oldpath, const gchar *newpath,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 CollectManagerType type)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 action = g_new0(CollectManagerAction, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454 action->ref = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 action->oldpath = g_strdup(oldpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 action->newpath = g_strdup(newpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 action->type = type;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 return action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464 static void collect_manager_action_ref(CollectManagerAction *action)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 action->ref++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
468
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 static void collect_manager_action_unref(CollectManagerAction *action)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
470 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471 action->ref--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 if (action->ref > 0) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475 g_free(action->oldpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 g_free(action->newpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477 g_free(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
480 static void collect_manager_entry_free_data(CollectManagerEntry *entry)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
484 work = entry->add_list;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 action = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 collect_manager_action_unref(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 }
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
494 g_list_free(entry->add_list);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
495 g_hash_table_destroy(entry->oldpath_hash);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
496 g_hash_table_destroy(entry->newpath_hash);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
497 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
498
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
499 static void collect_manager_entry_init_data(CollectManagerEntry *entry)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
500 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
501 entry->add_list = NULL;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
502 entry->oldpath_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify) collect_manager_action_unref);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
503 entry->newpath_hash = g_hash_table_new(g_str_hash, g_str_equal);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
504 entry->empty = TRUE;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
505
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
506 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
507
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
508 static CollectManagerEntry *collect_manager_entry_new(const gchar *path)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
509 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
510 CollectManagerEntry *entry;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
511
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
512 entry = g_new0(CollectManagerEntry, 1);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
513 entry->path = g_strdup(path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
514 collect_manager_entry_init_data(entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
515
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
516 collection_manager_entry_list = g_list_append(collection_manager_entry_list, entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
517
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
518 return entry;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
519 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
520
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
521
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
522 static void collect_manager_entry_free(CollectManagerEntry *entry)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
523 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
524 collection_manager_entry_list = g_list_remove(collection_manager_entry_list, entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
525
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
526 collect_manager_entry_free_data(entry);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
527
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528 g_free(entry->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 g_free(entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
532 static void collect_manager_entry_reset(CollectManagerEntry *entry)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
533 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
534 collect_manager_entry_free_data(entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
535 collect_manager_entry_init_data(entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
536 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
537
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
538 static CollectManagerEntry *collect_manager_get_entry(const gchar *path)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
539 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
540 GList *work;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
541
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
542 work = collection_manager_entry_list;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
543 while (work)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
544 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
545 CollectManagerEntry *entry;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
546
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
547 entry = work->data;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
548 work = work->next;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
549 if (strcmp(entry->path, path) == 0)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
550 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
551 return entry;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
552 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
553 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
554 return NULL;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
555
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
556 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
557
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
558 static void collect_manager_entry_add_action(CollectManagerEntry *entry, CollectManagerAction *action)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
559 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
560
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
561 CollectManagerAction *orig_action;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
562
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
563 entry->empty = FALSE;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
564
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
565 if (action->oldpath == NULL)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
566 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
567 /* add file */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
568 if (action->newpath == NULL)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
569 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
570 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
571 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
572
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
573 orig_action = g_hash_table_lookup(entry->newpath_hash, action->newpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
574 if (orig_action)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
575 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
576 /* target already exists */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
577 printf("collection manager failed to add another action for target %s in collection %s\n",
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
578 action->newpath, entry->path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
579 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
580 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
581 entry->add_list = g_list_append(entry->add_list, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
582 g_hash_table_insert(entry->newpath_hash, action->newpath, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
583 collect_manager_action_ref(action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
584 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
585 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
586
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
587 orig_action = g_hash_table_lookup(entry->newpath_hash, action->oldpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
588 if (orig_action)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
589 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
590 /* new action with the same file */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
591 CollectManagerAction *new_action = collect_manager_action_new(orig_action->oldpath, action->newpath, action->type);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
592
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
593 if (new_action->oldpath)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
594 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
595 g_hash_table_steal(entry->oldpath_hash, orig_action->oldpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
596 g_hash_table_insert(entry->oldpath_hash, new_action->oldpath, new_action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
597 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
598 else
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
599 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
600 GList *work = g_list_find(entry->add_list, orig_action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
601 work->data = new_action;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
602 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
603
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
604 g_hash_table_steal(entry->newpath_hash, orig_action->newpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
605 if (new_action->newpath)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
606 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
607 g_hash_table_insert(entry->newpath_hash, new_action->newpath, new_action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
608 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
609 collect_manager_action_unref(orig_action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
610 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
611 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
612
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
613
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
614 orig_action = g_hash_table_lookup(entry->oldpath_hash, action->oldpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
615 if (orig_action)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
616 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
617 /* another action for the same source, ignore */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
618 printf("collection manager failed to add another action for source %s in collection %s\n",
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
619 action->oldpath, entry->path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
620 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
621 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
622
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
623 g_hash_table_insert(entry->oldpath_hash, action->oldpath, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
624 if (action->newpath)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
625 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
626 g_hash_table_insert(entry->newpath_hash, action->newpath, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
627 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
628 collect_manager_action_ref(action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
629 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
630
235
a154d41fd666 Make collect_manager_process_action() static.
zas_
parents: 217
diff changeset
631 static gint collect_manager_process_action(CollectManagerEntry *entry, gchar **path_ptr)
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
632 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
633 gchar *path = *path_ptr;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
634 CollectManagerAction *action;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
635
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
636 if (path == NULL)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
637 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
638 /* get new files */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
639 if (entry->add_list)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
640 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
641 action = entry->add_list->data;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
642 g_assert(action->oldpath == NULL);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
643 entry->add_list = g_list_remove(entry->add_list, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
644 path = g_strdup(action->newpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
645 g_hash_table_remove(entry->newpath_hash, path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
646 collect_manager_action_unref(action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
647 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
648 *path_ptr = path;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
649 return (path != NULL);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
650 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
651
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
652 action = g_hash_table_lookup(entry->oldpath_hash, path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
653
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
654 if (action)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
655 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
656 g_free(path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
657 path = g_strdup(action->newpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
658 *path_ptr = path;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
659 return TRUE;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
660 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
661
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
662 return FALSE; /* no change */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
663 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
664
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
665 static void collect_manager_refresh(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
666 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
667 GList *list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
668 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
669 gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
670
283
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
671 base = g_strconcat(homedir(), "/", GQ_RC_DIR_COLLECTIONS, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672 path_list(base, &list, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673 g_free(base);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
675 work = collection_manager_entry_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676 while (work && list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678 CollectManagerEntry *entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679 GList *list_step;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 entry = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
683
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
684 list_step = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
685 while (list_step && entry)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
686 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
687 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
688
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
689 path = list_step->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
690 list_step = list_step->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
691
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
692 if (strcmp(path, entry->path) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
693 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
694 list = g_list_remove(list, path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
695 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
696
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
697 entry = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
698 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
699 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
700 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
701 collect_manager_entry_free(entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
702 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
703 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
705
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
706 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
707 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
708 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
709 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
710
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
711 path = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
712 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
714 collect_manager_entry_new(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
715 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
716 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
717
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
718 g_list_free(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
719 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
720
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
721 static void collect_manager_process_actions(gint max)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
722 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
723 if (debug && collection_manager_action_list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
724 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
725 printf("collection manager processing actions\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
726 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
727
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
728 while (collection_manager_action_list != NULL && max > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
729 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
731 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
732
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
733 action = collection_manager_action_list->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
734 work = collection_manager_entry_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
735 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
737 CollectManagerEntry *entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
738
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
739 entry = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
740 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
741
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
742 if (action->type == COLLECTION_MANAGER_UPDATE)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
743 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
744 collect_manager_entry_add_action(entry, action);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
745 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
746 else if (action->oldpath && action->newpath &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
747 strcmp(action->newpath, entry->path) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
748 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
749 /* convert action to standard add format */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
750 g_free(action->newpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
751 if (action->type == COLLECTION_MANAGER_ADD)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
752 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
753 action->newpath = action->oldpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
754 action->oldpath = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
755 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
756 else if (action->type == COLLECTION_MANAGER_REMOVE)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
757 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
758 action->newpath = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
759 }
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
760 collect_manager_entry_add_action(entry, action);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
761 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
762
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
763 max--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
764 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
765
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
766 if (action->type != COLLECTION_MANAGER_UPDATE &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
767 action->oldpath && action->newpath)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
768 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
769 printf("collection manager failed to %s %s for collection %s\n",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
770 (action->type == COLLECTION_MANAGER_ADD) ? "add" : "remove",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
771 action->oldpath, action->newpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
772 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
773
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
774 if (collection_manager_action_tail == collection_manager_action_list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
775 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
776 collection_manager_action_tail = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
777 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
778 collection_manager_action_list = g_list_remove(collection_manager_action_list, action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
779 collect_manager_action_unref(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
780 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
781 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
782
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
783 static gint collect_manager_process_entry(CollectManagerEntry *entry)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
784 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
785 CollectionData *cd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
786 gint success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
787
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
788 if (entry->empty) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
789
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
790 cd = collection_new(entry->path);
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
791 success = collection_load_private(cd, entry->path, COLLECTION_LOAD_NONE);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
792
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
793 collection_unref(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
794
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
795 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
796 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
797
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
798 static gint collect_manager_process_entry_list(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
799 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
800 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
801
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
802 work = collection_manager_entry_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
803 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
804 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
805 CollectManagerEntry *entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
806
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
807 entry = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
808 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
809 if (collect_manager_process_entry(entry)) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
810 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
811
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
812 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
813 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
814
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
815
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
816
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
817 static gint collect_manager_process_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
818 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
819 if (collection_manager_action_list) collect_manager_refresh();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
820 collect_manager_process_actions(COLLECT_MANAGER_ACTIONS_PER_IDLE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
821 if (collection_manager_action_list) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
822
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
823 if (collect_manager_process_entry_list()) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
824
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
825 if (debug) printf("collection manager is up to date\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
826 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
827 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
828
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
829 static gint collect_manager_timer_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
830 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
831 if (debug) printf("collection manager timer expired\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
832
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
833 g_idle_add_full(G_PRIORITY_LOW, collect_manager_process_cb, NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
834
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
835 collection_manager_timer_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
836 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
837 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
838
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
839 static void collect_manager_timer_push(gint stop)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
840 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
841 if (collection_manager_timer_id != -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
842 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
843 if (!stop) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
844
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
845 g_source_remove(collection_manager_timer_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
846 collection_manager_timer_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
847 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
848
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
849 if (!stop)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
850 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
851 collection_manager_timer_id = g_timeout_add(COLLECT_MANAGER_FLUSH_DELAY,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
852 collect_manager_timer_cb, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
853 if (debug) printf("collection manager timer started\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
854 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
855 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
856
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
857 static void collect_manager_add_action(CollectManagerAction *action)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
858 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
859 if (!action) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
860
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
861 /* we keep track of the list's tail to keep this a n(1) operation */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
862
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
863 if (collection_manager_action_tail)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
864 {
66
ebbff299ad0d Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
865 collection_manager_action_tail = g_list_append(collection_manager_action_tail, action);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
866 collection_manager_action_tail = collection_manager_action_tail->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
867 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
868 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
869 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
870 collection_manager_action_list = g_list_append(collection_manager_action_list, action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
871 collection_manager_action_tail = collection_manager_action_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
872 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
873
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
874 collect_manager_timer_push(FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
875 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
876
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
877 void collect_manager_moved(FileData *fd)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
878 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
879 CollectManagerAction *action;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
880 const gchar *oldpath = fd->change->source;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
881 const gchar *newpath = fd->change->dest;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
882
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
883 action = collect_manager_action_new(oldpath, newpath, COLLECTION_MANAGER_UPDATE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
884 collect_manager_add_action(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
885 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
886
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
887 void collect_manager_add(FileData *fd, const gchar *collection)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
888 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
889 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
890 CollectWindow *cw;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
891
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
892 if (!fd || !collection) return;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
893
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
894 cw = collection_window_find_by_path(collection);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
895 if (cw)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
896 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
897 if (collection_list_find(cw->cd->list, fd->path) == NULL)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
898 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
899 collection_add(cw->cd, fd, FALSE);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
900 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
901 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
902 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
903
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
904 action = collect_manager_action_new(fd->path, collection, COLLECTION_MANAGER_ADD);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
905 collect_manager_add_action(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
906 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
907
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
908 void collect_manager_remove(FileData *fd, const gchar *collection)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
909 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
910 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
911 CollectWindow *cw;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
912
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
913 if (!fd || !collection) return;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
914
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
915 cw = collection_window_find_by_path(collection);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
916 if (cw)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
917 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
918 while (collection_remove(cw->cd, fd));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
919 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
920 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
921
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
922 action = collect_manager_action_new(fd->path, collection, COLLECTION_MANAGER_REMOVE);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
923 collect_manager_add_action(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
924 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
925
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
926 void collect_manager_flush(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
927 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
928 collect_manager_timer_push(TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
929
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
930 if (debug) printf("collection manager flushing\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
931 while (collect_manager_process_cb(NULL));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
932 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
933