annotate src/collect-io.c @ 921:b416159a5820

Tidy up.
author zas_
date Wed, 23 Jul 2008 12:46:35 +0000
parents 912726c2f5e3
children 650c02c0c8ff
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
475
48c8e49b571c updated copyright in source files
nadvornik
parents: 447
diff changeset
4 * Copyright (C) 2008 The Geeqie Team
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 * 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
11 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 236
diff changeset
14 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15 #include "collect-io.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17 #include "collect.h"
586
905688aa2317 split filelist.c to filefilter.c and filedata.c
nadvornik
parents: 576
diff changeset
18 #include "filedata.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include "layout_util.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20 #include "rcfile.h"
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
21 #include "secure_save.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22 #include "thumb.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25
288
d1f74154463e Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents: 283
diff changeset
26 #define GQ_COLLECTION_MARKER "#" GQ_APPNAME
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27
283
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
28 #define GQ_COLLECTION_FAIL_MIN 300
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
29 #define GQ_COLLECTION_FAIL_PERCENT 98
360
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
30 #define GQ_COLLECTION_READ_BUFSIZE 4096
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
32 typedef struct _CollectManagerEntry CollectManagerEntry;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34 static void collection_load_thumb_step(CollectionData *cd);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
35 static gint collection_save_private(CollectionData *cd, const gchar *path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
36
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
37 static CollectManagerEntry *collect_manager_get_entry(const gchar *path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
38 static void collect_manager_entry_reset(CollectManagerEntry *entry);
235
a154d41fd666 Make collect_manager_process_action() static.
zas_
parents: 217
diff changeset
39 static gint collect_manager_process_action(CollectManagerEntry *entry, gchar **path_ptr);
9
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 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
43 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44 gint nx, ny, nw, nh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45
855
0c3f6ef17d18 Tidy up.
zas_
parents: 838
diff changeset
46 if (sscanf(buffer, "%d %d %d %d", &nx, &ny, &nw, &nh) != 4) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 *x = nx;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 *y = ny;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 *w = nw;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51 *h = nh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
56 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
57 {
360
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
58 gchar s_buf[GQ_COLLECTION_READ_BUFSIZE];
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 FILE *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 gchar *pathl;
361
e0295af4f716 collection_load(): replace official by limit_failures (and
zas_
parents: 360
diff changeset
61 gint limit_failures = TRUE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62 gint success = TRUE;
365
addd05a425fe collection_load(): improve headers parsing.
zas_
parents: 364
diff changeset
63 gint has_official_header = FALSE;
addd05a425fe collection_load(): improve headers parsing.
zas_
parents: 364
diff changeset
64 gint has_geometry_header = FALSE;
addd05a425fe collection_load(): improve headers parsing.
zas_
parents: 364
diff changeset
65 gint has_gqview_header = FALSE;
addd05a425fe collection_load(): improve headers parsing.
zas_
parents: 364
diff changeset
66 gint need_header = TRUE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67 guint total = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68 guint fail = 0;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
69 gboolean changed = FALSE;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
70 CollectManagerEntry *entry = NULL;
366
ce00494827e2 collection_load(): use booleans and always count failures (for debug).
zas_
parents: 365
diff changeset
71 guint flush = !!(flags & COLLECTION_LOAD_FLUSH);
ce00494827e2 collection_load(): use booleans and always count failures (for debug).
zas_
parents: 365
diff changeset
72 guint append = !!(flags & COLLECTION_LOAD_APPEND);
ce00494827e2 collection_load(): use booleans and always count failures (for debug).
zas_
parents: 365
diff changeset
73 guint only_geometry = !!(flags & COLLECTION_LOAD_GEOMETRY);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74
359
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
75 if (!only_geometry)
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
76 {
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
77 collection_load_stop(cd);
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 (flush)
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
80 collect_manager_flush();
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
81 else
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
82 entry = collect_manager_get_entry(path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83
359
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
84 if (!append)
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
85 {
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
86 collection_list_free(cd->list);
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
87 cd->list = NULL;
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
88 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91 if (!path && !cd->path) return FALSE;
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 if (!path) path = cd->path;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
94
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
95 DEBUG_1("collection load: append=%d flush=%d only_geometry=%d path=%s",
360
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
96 append, flush, only_geometry, path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 /* load it */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100 f = fopen(pathl, "r");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102 if (!f)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
104 log_printf("Failed to open collection file: \"%s\"\n", path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108 while (fgets(s_buf, sizeof(s_buf), f))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110 gchar *buf;
363
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
111 gchar *p = s_buf;
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
112
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
113 /* Skip whitespaces and empty lines */
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
114 while (*p && g_ascii_isspace(*p)) p++;
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
115 if (*p == '\n' || *p == '\r') continue;
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
116
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
117 /* Parse comments */
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
118 if (*p == '#')
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
119 {
365
addd05a425fe collection_load(): improve headers parsing.
zas_
parents: 364
diff changeset
120 if (!need_header) continue;
605
651ae2be1031 Use g_ascii_strncasecmp() instead of strncasecmp() where applicable.
zas_
parents: 586
diff changeset
121 if (g_ascii_strncasecmp(p, GQ_COLLECTION_MARKER, strlen(GQ_COLLECTION_MARKER)) == 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123 /* Looks like an official collection, allow unchecked input.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 * All this does is allow adding files that may not exist,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125 * which is needed for the collection manager to work.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 * Also unofficial files abort after too many invalid entries.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 */
365
addd05a425fe collection_load(): improve headers parsing.
zas_
parents: 364
diff changeset
128 has_official_header = TRUE;
361
e0295af4f716 collection_load(): replace official by limit_failures (and
zas_
parents: 360
diff changeset
129 limit_failures = FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130 }
363
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
131 else if (strncmp(p, "#geometry:", 10 ) == 0 &&
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
132 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
133 {
365
addd05a425fe collection_load(): improve headers parsing.
zas_
parents: 364
diff changeset
134 has_geometry_header = TRUE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 cd->window_read = TRUE;
365
addd05a425fe collection_load(): improve headers parsing.
zas_
parents: 364
diff changeset
136 if (only_geometry) break;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 }
605
651ae2be1031 Use g_ascii_strncasecmp() instead of strncasecmp() where applicable.
zas_
parents: 586
diff changeset
138 else if (g_ascii_strncasecmp(p, "#GQview collection", strlen("#GQview collection")) == 0)
360
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
139 {
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
140 /* 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
141 * and GQview 2.1.5 collection file format so ignore failures as well. */
365
addd05a425fe collection_load(): improve headers parsing.
zas_
parents: 364
diff changeset
142 has_gqview_header = TRUE;
361
e0295af4f716 collection_load(): replace official by limit_failures (and
zas_
parents: 360
diff changeset
143 limit_failures = FALSE;
360
822040a51249 Increase collection_load() buffer size and do not activate
zas_
parents: 359
diff changeset
144 }
365
addd05a425fe collection_load(): improve headers parsing.
zas_
parents: 364
diff changeset
145 need_header = (!has_official_header && !has_gqview_header) || !has_geometry_header;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 continue;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148
882
912726c2f5e3 Fix a segfault occuring when opening some collection files.
zas_
parents: 864
diff changeset
149 if (only_geometry) continue;
912726c2f5e3 Fix a segfault occuring when opening some collection files.
zas_
parents: 864
diff changeset
150
363
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
151 /* Read filenames */
5b8617c3821c collection_load(): accept whitespaces at start of lines.
zas_
parents: 362
diff changeset
152 buf = quoted_value(p, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 if (buf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 gint valid;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
156
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
157 if (!flush)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
158 changed |= collect_manager_process_action(entry, &buf);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
159
726
a1dcef8cd1ae Use G_DIR_SEPARATOR where applicable.
zas_
parents: 711
diff changeset
160 valid = (buf[0] == G_DIR_SEPARATOR && collection_add_check(cd, file_data_new_simple(buf), FALSE, TRUE));
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
161 if (!valid) DEBUG_1("collection invalid file: %s", buf);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164 total++;
366
ce00494827e2 collection_load(): use booleans and always count failures (for debug).
zas_
parents: 365
diff changeset
165 if (!valid)
9
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 fail++;
366
ce00494827e2 collection_load(): use booleans and always count failures (for debug).
zas_
parents: 365
diff changeset
168 if (limit_failures &&
ce00494827e2 collection_load(): use booleans and always count failures (for debug).
zas_
parents: 365
diff changeset
169 fail > GQ_COLLECTION_FAIL_MIN &&
283
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
170 fail * 100 / total > GQ_COLLECTION_FAIL_PERCENT)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
172 log_printf("%d invalid filenames in unofficial collection file, closing: %s\n", fail, path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173 success = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
180 DEBUG_1("collection files: total = %d fail = %d official=%d gqview=%d geometry=%d",
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
181 total, fail, has_official_header, has_gqview_header, has_geometry_header);
362
c5d5ebcc1e50 collection_load(): increase verbosity in debug mode.
zas_
parents: 361
diff changeset
182
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 fclose(f);
365
addd05a425fe collection_load(): improve headers parsing.
zas_
parents: 364
diff changeset
184 if (only_geometry) return has_geometry_header;
359
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
185
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
186 if (!flush)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
187 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
188 gchar *buf = NULL;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
189 while (collect_manager_process_action(entry, &buf))
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
190 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
191 collection_add_check(cd, file_data_new_simple(buf), FALSE, TRUE);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
192 changed = TRUE;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
193 g_free(buf);
492
dead6fb690c5 Fix adding a selection to a collection with no window open
zas_
parents: 475
diff changeset
194 buf = NULL;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
195 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
196 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198 cd->list = collection_list_sort(cd->list, cd->sort_method);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
199
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
200 if (!flush && changed && success)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
201 collection_save_private(cd, path);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
202
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
203 if (!flush)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
204 collect_manager_entry_reset(entry);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
205
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
206 if (!append) cd->changed = FALSE;
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 success;
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
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
211 gint collection_load(CollectionData *cd, const gchar *path, CollectionLoadFlags flags)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212 {
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
213 if (collection_load_private(cd, path, flags | COLLECTION_LOAD_FLUSH))
9
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 layout_recent_add_path(cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 static void collection_load_thumb_do(CollectionData *cd)
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 GdkPixbuf *pixbuf;
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 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
227
864
f40509d56fe3 added pixbuf_fallback function
nadvornik
parents: 855
diff changeset
228 pixbuf = thumb_loader_get_pixbuf(cd->thumb_loader);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 collection_info_set_thumb(cd->thumb_info, pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 g_object_unref(pixbuf);
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 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
233 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 static void collection_load_thumb_error_cb(ThumbLoader *tl, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237 CollectionData *cd = data;
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 collection_load_thumb_do(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 collection_load_thumb_step(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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243 static void collection_load_thumb_done_cb(ThumbLoader *tl, gpointer data)
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 CollectionData *cd = data;
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_thumb_do(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248 collection_load_thumb_step(cd);
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 static void collection_load_thumb_step(CollectionData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 CollectInfo *ci;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256 if (!cd->list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 collection_load_stop(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259 return;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262 work = cd->list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263 ci = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265 /* find first unloaded thumb */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
266 while (work && ci->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
267 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
268 ci = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
269 work = work->next;
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 if (!ci || ci->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
273 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
274 /* done */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
275 collection_load_stop(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277 /* send a NULL CollectInfo to notify end */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 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
279
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280 return;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
283 /* setup loader and call it */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 cd->thumb_info = ci;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285 thumb_loader_free(cd->thumb_loader);
333
767b53cd9ab7 Rename thumbnails related options.
zas_
parents: 318
diff changeset
286 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
287 thumb_loader_set_callbacks(cd->thumb_loader,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288 collection_load_thumb_done_cb,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289 collection_load_thumb_error_cb,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290 NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293 /* start it */
838
9bd49e725ad3 use FileData in thumb_loader
nadvornik
parents: 827
diff changeset
294 if (!thumb_loader_start(cd->thumb_loader, ci->fd))
9
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 /* error, handle it, do next */
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
297 DEBUG_1("error loading thumb for %s", ci->fd->path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298 collection_load_thumb_do(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 collection_load_thumb_step(cd);
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 }
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 void collection_load_thumb_idle(CollectionData *cd)
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 if (!cd->thumb_loader) collection_load_thumb_step(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
308 gint collection_load_begin(CollectionData *cd, const gchar *path, CollectionLoadFlags flags)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 {
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
310 if (!collection_load(cd, path, flags)) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 collection_load_thumb_idle(cd);
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 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317 void collection_load_stop(CollectionData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 if (!cd->thumb_loader) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321 thumb_loader_free(cd->thumb_loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322 cd->thumb_loader = NULL;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325 static gint collection_save_private(CollectionData *cd, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326 {
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
327 SecureSaveInfo *ssi;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331 if (!path && !cd->path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 if (!path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
335 path = cd->path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
339 pathl = path_from_utf8(path);
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
340 ssi = secure_open(pathl);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 g_free(pathl);
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
342 if (!ssi)
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
343 {
694
a3218946bd2d Sort out log_printf() vs printf_term() mix up.
zas_
parents: 673
diff changeset
344 log_printf(_("failed to open collection (write) \"%s\"\n"), path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
348 secure_fprintf(ssi, "%s collection\n", GQ_COLLECTION_MARKER);
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
349 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
350
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 collection_update_geometry(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 if (cd->window_read)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 {
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
354 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
355 }
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 work = cd->list;
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
358 while (work && secsave_errno == SS_ERR_NONE)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 CollectInfo *ci = work->data;
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
361 secure_fprintf(ssi, "\"%s\"\n", ci->fd->path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
365 secure_fprintf(ssi, "#end\n");
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366
312
07def8e708e1 Use secure save feature when saving collections.
zas_
parents: 288
diff changeset
367 if (secure_close(ssi))
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368 {
694
a3218946bd2d Sort out log_printf() vs printf_term() mix up.
zas_
parents: 673
diff changeset
369 log_printf(_("error saving collection file: %s\nerror: %s\n"), path,
403
2649a28d31b6 Introduce printf_term() macro and use it.
zas_
parents: 366
diff changeset
370 secsave_strerror(secsave_errno));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 if (!cd->path || strcmp(path, cd->path) != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 gchar *buf = cd->path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377 cd->path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378 path = cd->path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 g_free(buf);
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 g_free(cd->name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 cd->name = g_strdup(filename_from_path(cd->path));
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 collection_path_changed(cd);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 cd->changed = FALSE;
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 return TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392 gint collection_save(CollectionData *cd, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 if (collection_save_private(cd, path))
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 layout_recent_add_path(cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 return TRUE;
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 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 gint collection_load_only_geometry(CollectionData *cd, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 {
359
96fb24f948b7 Merge collection_load_only_geometry() into collection_load().
zas_
parents: 358
diff changeset
405 return collection_load(cd, path, COLLECTION_LOAD_GEOMETRY);
9
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
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 * collection manager
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 */
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 #define COLLECT_MANAGER_ACTIONS_PER_IDLE 1000
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 #define COLLECT_MANAGER_FLUSH_DELAY 10000
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 struct _CollectManagerEntry
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 gchar *path;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
421 GList *add_list;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
422 GHashTable *oldpath_hash;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
423 GHashTable *newpath_hash;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
424 gboolean empty;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 typedef enum {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 COLLECTION_MANAGER_UPDATE,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 COLLECTION_MANAGER_ADD,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 COLLECTION_MANAGER_REMOVE
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 } CollectManagerType;
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 typedef struct _CollectManagerAction CollectManagerAction;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 struct _CollectManagerAction
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 gchar *oldpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 gchar *newpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 CollectManagerType type;
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 gint ref;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445 static GList *collection_manager_entry_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 static GList *collection_manager_action_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447 static GList *collection_manager_action_tail = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 static gint collection_manager_timer_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449
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 static CollectManagerAction *collect_manager_action_new(const gchar *oldpath, const gchar *newpath,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 CollectManagerType type)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454 CollectManagerAction *action;
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 = g_new0(CollectManagerAction, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 action->ref = 1;
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->oldpath = g_strdup(oldpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460 action->newpath = g_strdup(newpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462 action->type = type;
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 return 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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 static void collect_manager_action_ref(CollectManagerAction *action)
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 action->ref++;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 static void collect_manager_action_unref(CollectManagerAction *action)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 action->ref--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 if (action->ref > 0) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478 g_free(action->oldpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479 g_free(action->newpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 g_free(action);
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
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
483 static void collect_manager_entry_free_data(CollectManagerEntry *entry)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
484 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
487 work = entry->add_list;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490 CollectManagerAction *action;
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 action = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495 collect_manager_action_unref(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 }
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
497 g_list_free(entry->add_list);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
498 g_hash_table_destroy(entry->oldpath_hash);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
499 g_hash_table_destroy(entry->newpath_hash);
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
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
502 static void collect_manager_entry_init_data(CollectManagerEntry *entry)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
503 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
504 entry->add_list = NULL;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
505 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
506 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
507 entry->empty = TRUE;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
508
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
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
511 static CollectManagerEntry *collect_manager_entry_new(const gchar *path)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
512 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
513 CollectManagerEntry *entry;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
514
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
515 entry = g_new0(CollectManagerEntry, 1);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
516 entry->path = g_strdup(path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
517 collect_manager_entry_init_data(entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
518
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
519 collection_manager_entry_list = g_list_append(collection_manager_entry_list, entry);
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 return entry;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
522 }
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
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
525 static void collect_manager_entry_free(CollectManagerEntry *entry)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
526 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
527 collection_manager_entry_list = g_list_remove(collection_manager_entry_list, entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
528
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
529 collect_manager_entry_free_data(entry);
9
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 g_free(entry->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532 g_free(entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
534
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
535 static void collect_manager_entry_reset(CollectManagerEntry *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 collect_manager_entry_free_data(entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
538 collect_manager_entry_init_data(entry);
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
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
541 static CollectManagerEntry *collect_manager_get_entry(const gchar *path)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
542 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
543 GList *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 work = collection_manager_entry_list;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
546 while (work)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
547 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
548 CollectManagerEntry *entry;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
549
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
550 entry = work->data;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
551 work = work->next;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
552 if (strcmp(entry->path, path) == 0)
138
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 entry;
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 return NULL;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
558
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 static void collect_manager_entry_add_action(CollectManagerEntry *entry, CollectManagerAction *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
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
564 CollectManagerAction *orig_action;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
565
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
566 entry->empty = FALSE;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
567
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
568 if (action->oldpath == 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 /* add file */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
571 if (action->newpath == NULL)
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 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
574 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
575
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
576 orig_action = g_hash_table_lookup(entry->newpath_hash, action->newpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
577 if (orig_action)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
578 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
579 /* target already exists */
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
580 log_printf("collection manager failed to add another action for target %s in collection %s\n",
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
581 action->newpath, entry->path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
582 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
583 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
584 entry->add_list = g_list_append(entry->add_list, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
585 g_hash_table_insert(entry->newpath_hash, action->newpath, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
586 collect_manager_action_ref(action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
587 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
588 }
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 orig_action = g_hash_table_lookup(entry->newpath_hash, action->oldpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
591 if (orig_action)
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 /* new action with the same file */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
594 CollectManagerAction *new_action = collect_manager_action_new(orig_action->oldpath, action->newpath, action->type);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
595
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
596 if (new_action->oldpath)
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 g_hash_table_steal(entry->oldpath_hash, orig_action->oldpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
599 g_hash_table_insert(entry->oldpath_hash, new_action->oldpath, new_action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
600 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
601 else
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 GList *work = g_list_find(entry->add_list, orig_action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
604 work->data = new_action;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
605 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
606
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
607 g_hash_table_steal(entry->newpath_hash, orig_action->newpath);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
608 if (new_action->newpath)
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
609 {
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
610 g_hash_table_insert(entry->newpath_hash, new_action->newpath, new_action);
138
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 collect_manager_action_unref(orig_action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
613 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
614 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
615
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 orig_action = g_hash_table_lookup(entry->oldpath_hash, action->oldpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
618 if (orig_action)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
619 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
620 /* another action for the same source, ignore */
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
621 log_printf("collection manager failed to add another action for source %s in collection %s\n",
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
622 action->oldpath, entry->path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
623 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
624 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
625
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
626 g_hash_table_insert(entry->oldpath_hash, action->oldpath, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
627 if (action->newpath)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
628 {
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
629 g_hash_table_insert(entry->newpath_hash, action->newpath, action);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
630 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
631 collect_manager_action_ref(action);
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
235
a154d41fd666 Make collect_manager_process_action() static.
zas_
parents: 217
diff changeset
634 static gint collect_manager_process_action(CollectManagerEntry *entry, gchar **path_ptr)
138
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 gchar *path = *path_ptr;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
637 CollectManagerAction *action;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
638
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
639 if (path == NULL)
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 /* get new files */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
642 if (entry->add_list)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
643 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
644 action = entry->add_list->data;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
645 g_assert(action->oldpath == NULL);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
646 entry->add_list = g_list_remove(entry->add_list, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
647 path = g_strdup(action->newpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
648 g_hash_table_remove(entry->newpath_hash, path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
649 collect_manager_action_unref(action);
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 *path_ptr = path;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
652 return (path != NULL);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
653 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
654
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
655 action = g_hash_table_lookup(entry->oldpath_hash, path);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 403
diff changeset
656
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
657 if (action)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
658 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
659 g_free(path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
660 path = g_strdup(action->newpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
661 *path_ptr = path;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
662 return TRUE;
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
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
665 return FALSE; /* no change */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
666 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
667
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
668 static void collect_manager_refresh(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
669 {
780
44128da39e13 Drop initialization to NULL since filelist_read() will take care of it.
zas_
parents: 726
diff changeset
670 GList *list;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672 gchar *base;
783
d6a7fb4b8e7c replaced directory path with FileData* dir_fd
nadvornik
parents: 780
diff changeset
673 FileData *dir_fd;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674
711
d86748a2650a Use g_build_filename().
zas_
parents: 694
diff changeset
675 base = g_build_filename(homedir(), GQ_RC_DIR_COLLECTIONS, NULL);
783
d6a7fb4b8e7c replaced directory path with FileData* dir_fd
nadvornik
parents: 780
diff changeset
676 dir_fd = file_data_new_simple(base);
d6a7fb4b8e7c replaced directory path with FileData* dir_fd
nadvornik
parents: 780
diff changeset
677 filelist_read(dir_fd, &list, NULL);
d6a7fb4b8e7c replaced directory path with FileData* dir_fd
nadvornik
parents: 780
diff changeset
678 file_data_unref(dir_fd);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679 g_free(base);
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 work = collection_manager_entry_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682 while (work && list)
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 CollectManagerEntry *entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
685 GList *list_step;
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 entry = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
688 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
689
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
690 list_step = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
691 while (list_step && entry)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
692 {
576
9dc0513837b5 dropped path_list functions, use filelist functions everywhere
nadvornik
parents: 507
diff changeset
693 FileData *fd;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
694
576
9dc0513837b5 dropped path_list functions, use filelist functions everywhere
nadvornik
parents: 507
diff changeset
695 fd = list_step->data;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
696 list_step = list_step->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
697
576
9dc0513837b5 dropped path_list functions, use filelist functions everywhere
nadvornik
parents: 507
diff changeset
698 if (strcmp(fd->path, entry->path) == 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
699 {
576
9dc0513837b5 dropped path_list functions, use filelist functions everywhere
nadvornik
parents: 507
diff changeset
700 list = g_list_remove(list, fd);
9dc0513837b5 dropped path_list functions, use filelist functions everywhere
nadvornik
parents: 507
diff changeset
701 file_data_unref(fd);
9
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 entry = NULL;
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 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
706 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
707 collect_manager_entry_free(entry);
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 }
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
712 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
714 {
576
9dc0513837b5 dropped path_list functions, use filelist functions everywhere
nadvornik
parents: 507
diff changeset
715 FileData *fd;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
716
576
9dc0513837b5 dropped path_list functions, use filelist functions everywhere
nadvornik
parents: 507
diff changeset
717 fd = work->data;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
718 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
719
576
9dc0513837b5 dropped path_list functions, use filelist functions everywhere
nadvornik
parents: 507
diff changeset
720 collect_manager_entry_new(fd->path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
721 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
722
576
9dc0513837b5 dropped path_list functions, use filelist functions everywhere
nadvornik
parents: 507
diff changeset
723 filelist_free(list);
9
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
726 static void collect_manager_process_actions(gint max)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
727 {
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
728 if (collection_manager_action_list) DEBUG_1("collection manager processing actions");
495
c7a2471e5c4e Introduce macros to display debug messages.
zas_
parents: 492
diff changeset
729
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730 while (collection_manager_action_list != NULL && max > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
731 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
732 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
733 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
734
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
735 action = collection_manager_action_list->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736 work = collection_manager_entry_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
737 while (work)
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 CollectManagerEntry *entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
740
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
741 entry = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
742 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
743
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
744 if (action->type == COLLECTION_MANAGER_UPDATE)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
745 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
746 collect_manager_entry_add_action(entry, action);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
747 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
748 else if (action->oldpath && action->newpath &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
749 strcmp(action->newpath, entry->path) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
750 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
751 /* convert action to standard add format */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
752 g_free(action->newpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
753 if (action->type == COLLECTION_MANAGER_ADD)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
754 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
755 action->newpath = action->oldpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
756 action->oldpath = NULL;
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 else if (action->type == COLLECTION_MANAGER_REMOVE)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
759 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
760 action->newpath = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
761 }
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
762 collect_manager_entry_add_action(entry, action);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
763 }
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 max--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
766 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
767
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
768 if (action->type != COLLECTION_MANAGER_UPDATE &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
769 action->oldpath && action->newpath)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
770 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
771 log_printf("collection manager failed to %s %s for collection %s\n",
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
772 (action->type == COLLECTION_MANAGER_ADD) ? "add" : "remove",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
773 action->oldpath, action->newpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
774 }
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 if (collection_manager_action_tail == collection_manager_action_list)
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_tail = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
779 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
780 collection_manager_action_list = g_list_remove(collection_manager_action_list, action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
781 collect_manager_action_unref(action);
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 }
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 static gint collect_manager_process_entry(CollectManagerEntry *entry)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
786 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
787 CollectionData *cd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
788 gint success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
789
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
790 if (entry->empty) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
791
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
792 cd = collection_new(entry->path);
358
384eed18df04 Use flags for collection_load*().
zas_
parents: 333
diff changeset
793 success = collection_load_private(cd, entry->path, COLLECTION_LOAD_NONE);
9
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 collection_unref(cd);
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 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
798 }
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 static gint collect_manager_process_entry_list(void)
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 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
803
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
804 work = collection_manager_entry_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
805 while (work)
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 CollectManagerEntry *entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
808
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
809 entry = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
810 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
811 if (collect_manager_process_entry(entry)) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
812 }
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 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
815 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
816
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
817
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
818
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
819 static gint collect_manager_process_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
820 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
821 if (collection_manager_action_list) collect_manager_refresh();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
822 collect_manager_process_actions(COLLECT_MANAGER_ACTIONS_PER_IDLE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
823 if (collection_manager_action_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 (collect_manager_process_entry_list()) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
826
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
827 DEBUG_1("collection manager is up to date");
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
828 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
829 }
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 static gint collect_manager_timer_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
832 {
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
833 DEBUG_1("collection manager timer expired");
9
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 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
836
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
837 collection_manager_timer_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
838 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
839 }
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 static void collect_manager_timer_push(gint stop)
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 (collection_manager_timer_id != -1)
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 if (!stop) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
846
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
847 g_source_remove(collection_manager_timer_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
848 collection_manager_timer_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
849 }
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 if (!stop)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
852 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
853 collection_manager_timer_id = g_timeout_add(COLLECT_MANAGER_FLUSH_DELAY,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
854 collect_manager_timer_cb, NULL);
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
855 DEBUG_1("collection manager timer started");
9
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 }
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 static void collect_manager_add_action(CollectManagerAction *action)
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 if (!action) return;
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 /* 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
864
827
e5172386f229 Revert patches 759 and 760.
zas_
parents: 803
diff changeset
865 if (collection_manager_action_tail)
e5172386f229 Revert patches 759 and 760.
zas_
parents: 803
diff changeset
866 {
e5172386f229 Revert patches 759 and 760.
zas_
parents: 803
diff changeset
867 collection_manager_action_tail = g_list_append(collection_manager_action_tail, action);
e5172386f229 Revert patches 759 and 760.
zas_
parents: 803
diff changeset
868 collection_manager_action_tail = collection_manager_action_tail->next;
e5172386f229 Revert patches 759 and 760.
zas_
parents: 803
diff changeset
869 }
e5172386f229 Revert patches 759 and 760.
zas_
parents: 803
diff changeset
870 else
e5172386f229 Revert patches 759 and 760.
zas_
parents: 803
diff changeset
871 {
e5172386f229 Revert patches 759 and 760.
zas_
parents: 803
diff changeset
872 collection_manager_action_list = g_list_append(collection_manager_action_list, action);
e5172386f229 Revert patches 759 and 760.
zas_
parents: 803
diff changeset
873 collection_manager_action_tail = collection_manager_action_list;
e5172386f229 Revert patches 759 and 760.
zas_
parents: 803
diff changeset
874 }
9
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 collect_manager_timer_push(FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
877 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
878
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
879 void collect_manager_moved(FileData *fd)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
880 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
881 CollectManagerAction *action;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
882 const gchar *oldpath = fd->change->source;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
883 const gchar *newpath = fd->change->dest;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
884
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
885 action = collect_manager_action_new(oldpath, newpath, COLLECTION_MANAGER_UPDATE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
886 collect_manager_add_action(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
887 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
888
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
889 void collect_manager_add(FileData *fd, const gchar *collection)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
890 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
891 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
892 CollectWindow *cw;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
893
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
894 if (!fd || !collection) return;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
895
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
896 cw = collection_window_find_by_path(collection);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
897 if (cw)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
898 {
799
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
899 if (collection_list_find_fd(cw->cd->list, fd) == NULL)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
900 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
901 collection_add(cw->cd, fd, FALSE);
9
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 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
904 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
905
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
906 action = collect_manager_action_new(fd->path, collection, COLLECTION_MANAGER_ADD);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
907 collect_manager_add_action(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
908 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
909
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
910 void collect_manager_remove(FileData *fd, const gchar *collection)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
911 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
912 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
913 CollectWindow *cw;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
914
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
915 if (!fd || !collection) return;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
916
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
917 cw = collection_window_find_by_path(collection);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
918 if (cw)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
919 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
920 while (collection_remove(cw->cd, fd));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
921 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
922 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
923
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
924 action = collect_manager_action_new(fd->path, collection, COLLECTION_MANAGER_REMOVE);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
925 collect_manager_add_action(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
926 }
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 void collect_manager_flush(void)
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 collect_manager_timer_push(TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
931
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
932 DEBUG_1("collection manager flushing");
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
933 while (collect_manager_process_cb(NULL));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
934 }
799
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
935
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
936 void collect_manager_notify_cb(FileData *fd, NotifyType type, gpointer data)
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
937 {
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
938
803
764fd82dd099 better check for notify type
nadvornik
parents: 799
diff changeset
939 if (type != NOTIFY_TYPE_CHANGE || !fd->change) return;
799
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
940
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
941 switch(fd->change->type)
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
942 {
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
943 case FILEDATA_CHANGE_MOVE:
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
944 collect_manager_moved(fd);
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
945 break;
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
946 case FILEDATA_CHANGE_COPY:
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
947 break;
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
948 case FILEDATA_CHANGE_RENAME:
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
949 collect_manager_moved(fd);
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
950 break;
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
951 case FILEDATA_CHANGE_DELETE:
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
952 break;
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
953 case FILEDATA_CHANGE_UNSPECIFIED:
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
954 break;
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
955 }
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
956
278962ba162a use the new notification for collections
nadvornik
parents: 783
diff changeset
957 }