annotate src/collect-io.c @ 143:0d1bf3ac6cd8

improved FileDataChangeInfo structure, check for another file operation in progress
author nadvornik
date Mon, 08 Oct 2007 19:41:49 +0000
parents 71e1ebee420e
children f6e307c7bad6
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 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
2 * GQview
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
3 * (C) 2004 John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
4 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13 #include "gqview.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14 #include "collect-io.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16 #include "collect.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17 #include "layout_util.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
18 #include "rcfile.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include "thumb.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20 #include "ui_fileops.h"
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
21 #include "filelist.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24 #define GQVIEW_COLLECTION_MARKER "#GQview"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26 #define GQVIEW_COLLECTION_FAIL_MIN 300
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27 #define GQVIEW_COLLECTION_FAIL_PERCENT 98
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
28
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
29 typedef struct _CollectManagerEntry CollectManagerEntry;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31 static void collection_load_thumb_step(CollectionData *cd);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
32 static gint collection_save_private(CollectionData *cd, const gchar *path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
33
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
34 static CollectManagerEntry *collect_manager_get_entry(const gchar *path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
35 static void collect_manager_entry_reset(CollectManagerEntry *entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
36
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39 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
40 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 gint nx, ny, nw, nh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 if(sscanf(buffer, "%d %d %d %d", &nx, &ny, &nw, &nh) != 4) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45 *x = nx;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46 *y = ny;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 *w = nw;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 *h = nh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 static gint collection_load_private(CollectionData *cd, const gchar *path, gint append, gint flush)
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 gchar s_buf[2048];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56 FILE *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 gint official = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 gint success = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 guint total = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61 guint fail = 0;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
62 gboolean changed = FALSE;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
63 CollectManagerEntry *entry = NULL;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65 collection_load_stop(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
67 if (flush)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
68 collect_manager_flush();
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
69 else
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
70 entry = collect_manager_get_entry(path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 if (!append)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74 collection_list_free(cd->list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75 cd->list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78 if (!path && !cd->path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80 if (!path) path = cd->path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82 /* load it */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84 f = fopen(pathl, "r");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86 if (!f)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
88 printf("Failed to open collection file: \"%s\"\n", path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92 while (fgets(s_buf, sizeof(s_buf), f))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 if (s_buf[0]=='#')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97 if (strncasecmp(s_buf, GQVIEW_COLLECTION_MARKER, strlen(GQVIEW_COLLECTION_MARKER)) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99 /* Looks like an official collection, allow unchecked input.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100 * All this does is allow adding files that may not exist,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 * which is needed for the collection manager to work.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102 * Also unofficial files abort after too many invalid entries.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 official = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106 else if (strncmp(s_buf, "#geometry:", 10 ) == 0 &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107 scan_geometry(s_buf + 10, &cd->window_x, &cd->window_y, &cd->window_w, &cd->window_h) )
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 cd->window_read = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111 continue;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 if (s_buf[0]=='\n') continue;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 buf = quoted_value(s_buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 if (buf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 gint valid;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
119
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
120 if (!flush)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
121 changed |= collect_manager_process_action(entry, &buf);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
122
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
123 valid = (buf[0] == '/' && collection_add_check(cd, file_data_new_simple(buf), FALSE, TRUE));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 total++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 if (!valid && !official)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
129 fail++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130 if (fail > GQVIEW_COLLECTION_FAIL_MIN &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131 fail * 100 / total > GQVIEW_COLLECTION_FAIL_PERCENT)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 printf("Too many invalid filenames in unoffical collection file, closing: %s\n", path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134 success = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
136 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 fclose(f);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
142
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
143 if (!flush)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
144 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
145 gchar *buf = NULL;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
146 while (collect_manager_process_action(entry, &buf))
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
147 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
148 collection_add_check(cd, file_data_new_simple(buf), FALSE, TRUE);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
149 changed = TRUE;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
150 g_free(buf);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
151 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
152 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154 cd->list = collection_list_sort(cd->list, cd->sort_method);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
155
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
156 if (!flush && changed && success)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
157 collection_save_private(cd, path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
158
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
159 if (!flush)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
160 collect_manager_entry_reset(entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
161
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 if (!append) cd->changed = FALSE;
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 return success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 }
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 gint collection_load(CollectionData *cd, const gchar *path, gint append)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169 if (collection_load_private(cd, path, append, TRUE))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171 layout_recent_add_path(cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 return FALSE;
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 static void collection_load_thumb_do(CollectionData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 GdkPixbuf *pixbuf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 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
183
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 pixbuf = thumb_loader_get_pixbuf(cd->thumb_loader, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185 collection_info_set_thumb(cd->thumb_info, pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 g_object_unref(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188 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
189 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 static void collection_load_thumb_error_cb(ThumbLoader *tl, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 CollectionData *cd = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 collection_load_thumb_do(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 collection_load_thumb_step(cd);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 static void collection_load_thumb_done_cb(ThumbLoader *tl, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 CollectionData *cd = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
203 collection_load_thumb_do(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204 collection_load_thumb_step(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
206
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
207 static void collection_load_thumb_step(CollectionData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
210 CollectInfo *ci;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
211
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212 if (!cd->list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214 collection_load_stop(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 work = cd->list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 ci = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 /* find first unloaded thumb */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 while (work && ci->pixbuf)
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 ci = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 if (!ci || ci->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 /* done */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 collection_load_stop(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 /* send a NULL CollectInfo to notify end */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 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
235
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237 }
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 /* setup loader and call it */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 cd->thumb_info = ci;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241 thumb_loader_free(cd->thumb_loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242 cd->thumb_loader = thumb_loader_new(thumb_max_width, thumb_max_height);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243 thumb_loader_set_callbacks(cd->thumb_loader,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244 collection_load_thumb_done_cb,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245 collection_load_thumb_error_cb,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 /* start it */
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
250 if (!thumb_loader_start(cd->thumb_loader, ci->fd->path))
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252 /* error, handle it, do next */
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
253 if (debug) printf("error loading thumb for %s\n", ci->fd->path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 collection_load_thumb_do(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 collection_load_thumb_step(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259 void collection_load_thumb_idle(CollectionData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
260 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
261 if (!cd->thumb_loader) collection_load_thumb_step(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 gint collection_load_begin(CollectionData *cd, const gchar *path, gint append)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
266 if (!collection_load(cd, path, append)) return FALSE;
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 collection_load_thumb_idle(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
269
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
270 return TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
273 void collection_load_stop(CollectionData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
274 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
275 if (!cd->thumb_loader) return;
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 thumb_loader_free(cd->thumb_loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 cd->thumb_loader = NULL;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
281 static gint collection_save_private(CollectionData *cd, const gchar *path)
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 FILE *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285 gchar *tmp_path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
286 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287 mode_t save_mask;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289 if (!path && !cd->path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 if (!path)
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 path = cd->path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 }
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 tmp_path = unique_filename(path, ".tmp", "_", 3);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297 if (!tmp_path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 pathl = path_from_utf8(tmp_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 save_mask = umask(0077);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 f = fopen(pathl, "w");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302 umask(save_mask);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 g_free(pathl);
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 (!f)
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 /* file open failed */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 printf("failed to open collection (write) \"%s\"\n", tmp_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 g_free(tmp_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313 fprintf(f, "%s collection\n", GQVIEW_COLLECTION_MARKER);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 fprintf(f, "#created with GQview version %s\n", VERSION);
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 collection_update_geometry(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317 if (cd->window_read)
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 fprintf(f, "#geometry: %d %d %d %d\n", cd->window_x, cd->window_y, cd->window_w, cd->window_h);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322 work = cd->list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 while (work)
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 CollectInfo *ci = work->data;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
326 if (fprintf(f, "\"%s\"\n", ci->fd->path) < 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328 fclose(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329 printf("Error writing to %s\n", tmp_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 unlink_file(tmp_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331 g_free(tmp_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
335 }
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 fprintf(f, "#end\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339 fclose(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 copy_file_attributes(path, tmp_path, TRUE, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 if (!rename_file(tmp_path, path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 printf("collection save unable to rename %s to %s\n", tmp_path, path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345 unlink_file(tmp_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 g_free(tmp_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 g_free(tmp_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 if (!cd->path || strcmp(path, cd->path) != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354 gchar *buf = cd->path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 cd->path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356 path = cd->path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 g_free(cd->name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 cd->name = g_strdup(filename_from_path(cd->path));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
361
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362 collection_path_changed(cd);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
365 cd->changed = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
367 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370 gint collection_save(CollectionData *cd, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372 if (collection_save_private(cd, path))
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 layout_recent_add_path(cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 }
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 gint collection_load_only_geometry(CollectionData *cd, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383 gchar s_buf[2048];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 FILE *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 gchar *pathl;
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 if (!path && !cd->path) return 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 if (!path) path = cd->path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 /* load it */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 f = fopen(pathl, "r");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 if (!f) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 while (fgets(s_buf, sizeof(s_buf), f))
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 if (s_buf[0]=='#' &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 strncmp(s_buf, "#geometry:", 10 ) == 0 &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 scan_geometry(s_buf + 10, &cd->window_x, &cd->window_y, &cd->window_w, &cd->window_h) )
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 cd->window_read = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 fclose(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 return TRUE;
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 fclose(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412
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 * collection manager
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 #define COLLECT_MANAGER_ACTIONS_PER_IDLE 1000
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 #define COLLECT_MANAGER_FLUSH_DELAY 10000
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422 struct _CollectManagerEntry
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 gchar *path;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
425 GList *add_list;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
426 GHashTable *oldpath_hash;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
427 GHashTable *newpath_hash;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
428 gboolean empty;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 typedef enum {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432 COLLECTION_MANAGER_UPDATE,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 COLLECTION_MANAGER_ADD,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 COLLECTION_MANAGER_REMOVE
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435 } CollectManagerType;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 typedef struct _CollectManagerAction CollectManagerAction;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 struct _CollectManagerAction
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440 gchar *oldpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 gchar *newpath;
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 CollectManagerType type;
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 gint ref;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 static GList *collection_manager_entry_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450 static GList *collection_manager_action_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 static GList *collection_manager_action_tail = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 static gint collection_manager_timer_id = -1;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455 static CollectManagerAction *collect_manager_action_new(const gchar *oldpath, const gchar *newpath,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 CollectManagerType type)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460 action = g_new0(CollectManagerAction, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 action->ref = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463 action->oldpath = g_strdup(oldpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464 action->newpath = g_strdup(newpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 action->type = type;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
468 return action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 }
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 static void collect_manager_action_ref(CollectManagerAction *action)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 action->ref++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 static void collect_manager_action_unref(CollectManagerAction *action)
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 action->ref--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 if (action->ref > 0) return;
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 g_free(action->oldpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483 g_free(action->newpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
484 g_free(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 }
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 static void collect_manager_entry_free_data(CollectManagerEntry *entry)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
491 work = entry->add_list;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 action = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 collect_manager_action_unref(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500 }
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
501 g_list_free(entry->add_list);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
502 g_hash_table_destroy(entry->oldpath_hash);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
503 g_hash_table_destroy(entry->newpath_hash);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
504 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
505
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
506 static void collect_manager_entry_init_data(CollectManagerEntry *entry)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
507 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
508 entry->add_list = NULL;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
509 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
510 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
511 entry->empty = TRUE;
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 }
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 static CollectManagerEntry *collect_manager_entry_new(const gchar *path)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
516 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
517 CollectManagerEntry *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 entry = g_new0(CollectManagerEntry, 1);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
520 entry->path = g_strdup(path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
521 collect_manager_entry_init_data(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 collection_manager_entry_list = g_list_append(collection_manager_entry_list, entry);
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 return 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
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 static void collect_manager_entry_free(CollectManagerEntry *entry)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
530 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
531 GList *work;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
532
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
533 collection_manager_entry_list = g_list_remove(collection_manager_entry_list, entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
534
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
535 collect_manager_entry_free_data(entry);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
537 g_free(entry->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 g_free(entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
541 static void collect_manager_entry_reset(CollectManagerEntry *entry)
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 collect_manager_entry_free_data(entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
544 collect_manager_entry_init_data(entry);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
545 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
546
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
547 static CollectManagerEntry *collect_manager_get_entry(const gchar *path)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
548 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
549 GList *work;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
550
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
551 work = collection_manager_entry_list;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
552 while (work)
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 CollectManagerEntry *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 entry = work->data;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
557 work = work->next;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
558 if (strcmp(entry->path, path) == 0)
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 return entry;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
561 }
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 return NULL;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
564
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
565 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
566
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
567 static void collect_manager_entry_add_action(CollectManagerEntry *entry, CollectManagerAction *action)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
568 {
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 CollectManagerAction *orig_action;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
571
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
572 entry->empty = FALSE;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
573
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
574 if (action->oldpath == NULL)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
575 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
576 /* add file */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
577 if (action->newpath == NULL)
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 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
580 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
581
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
582 orig_action = g_hash_table_lookup(entry->newpath_hash, action->newpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
583 if (orig_action)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
584 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
585 /* target already exists */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
586 printf("collection manager failed to add another action for target %s in collection %s\n",
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
587 action->newpath, entry->path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
588 return;
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 entry->add_list = g_list_append(entry->add_list, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
591 g_hash_table_insert(entry->newpath_hash, action->newpath, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
592 collect_manager_action_ref(action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
593 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
594 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
595
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
596 orig_action = g_hash_table_lookup(entry->newpath_hash, action->oldpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
597 if (orig_action)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
598 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
599 /* new action with the same file */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
600 CollectManagerAction *new_action = collect_manager_action_new(orig_action->oldpath, action->newpath, action->type);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
601
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
602 if (new_action->oldpath)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
603 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
604 g_hash_table_steal(entry->oldpath_hash, orig_action->oldpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
605 g_hash_table_insert(entry->oldpath_hash, new_action->oldpath, new_action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
606 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
607 else
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
608 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
609 GList *work = g_list_find(entry->add_list, orig_action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
610 work->data = new_action;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
611 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
612
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
613 g_hash_table_steal(entry->newpath_hash, orig_action->newpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
614 if (new_action->newpath)
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 g_hash_table_insert(entry->newpath_hash, new_action->newpath, new_action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
617 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
618 collect_manager_action_unref(orig_action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
619 return;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
620 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
621
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
622
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
623 orig_action = g_hash_table_lookup(entry->oldpath_hash, action->oldpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
624 if (orig_action)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
625 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
626 /* another action for the same source, ignore */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
627 printf("collection manager failed to add another action for source %s in collection %s\n",
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
628 action->oldpath, entry->path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
629 return;
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
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
632 g_hash_table_insert(entry->oldpath_hash, action->oldpath, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
633 if (action->newpath)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
634 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
635 g_hash_table_insert(entry->newpath_hash, action->newpath, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
636 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
637 collect_manager_action_ref(action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
638 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
639
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
640 gint collect_manager_process_action(CollectManagerEntry *entry, gchar **path_ptr)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
641 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
642 gchar *path = *path_ptr;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
643 CollectManagerAction *action;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
644
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
645 if (path == NULL)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
646 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
647 /* get new files */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
648 if (entry->add_list)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
649 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
650 action = entry->add_list->data;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
651 g_assert(action->oldpath == NULL);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
652 entry->add_list = g_list_remove(entry->add_list, action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
653 path = g_strdup(action->newpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
654 g_hash_table_remove(entry->newpath_hash, path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
655 collect_manager_action_unref(action);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
656 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
657 *path_ptr = path;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
658 return (path != NULL);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
659 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
660
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
661 action = g_hash_table_lookup(entry->oldpath_hash, path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
662
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
663 if (action)
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 g_free(path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
666 path = g_strdup(action->newpath);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
667 *path_ptr = path;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
668 return TRUE;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
669 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
670
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
671 return FALSE; /* no change */
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
672 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
673
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674 static void collect_manager_refresh(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
675 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676 GList *list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678 gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680 base = g_strconcat(homedir(), "/", GQVIEW_RC_DIR_COLLECTIONS, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 path_list(base, &list, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682 g_free(base);
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 work = collection_manager_entry_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
685 while (work && list)
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 CollectManagerEntry *entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
688 GList *list_step;
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 entry = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
691 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
692
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
693 list_step = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
694 while (list_step && entry)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
695 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
696 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
697
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
698 path = list_step->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
699 list_step = list_step->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
700
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
701 if (strcmp(path, entry->path) == 0)
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 list = g_list_remove(list, path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
705
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
706 entry = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
707 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
708 else
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 collect_manager_entry_free(entry);
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 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
714
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
715 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
716 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
717 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
718 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
719
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
720 path = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
721 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
722
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
723 collect_manager_entry_new(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
724 g_free(path);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
727 g_list_free(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
728 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
729
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730 static void collect_manager_process_actions(gint max)
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 if (debug && collection_manager_action_list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
733 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
734 printf("collection manager processing actions\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
735 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
737 while (collection_manager_action_list != NULL && max > 0)
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 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
740 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
741
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
742 action = collection_manager_action_list->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
743 work = collection_manager_entry_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
744 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
745 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
746 CollectManagerEntry *entry;
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 entry = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
749 work = work->next;
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 if (action->type == COLLECTION_MANAGER_UPDATE)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
752 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
753 collect_manager_entry_add_action(entry, action);
9
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 else if (action->oldpath && action->newpath &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
756 strcmp(action->newpath, entry->path) == 0)
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 /* convert action to standard add format */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
759 g_free(action->newpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
760 if (action->type == COLLECTION_MANAGER_ADD)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
761 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
762 action->newpath = action->oldpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
763 action->oldpath = NULL;
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 else if (action->type == COLLECTION_MANAGER_REMOVE)
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 action->newpath = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
768 }
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
769 collect_manager_entry_add_action(entry, action);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
770 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
771
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
772 max--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
773 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
774
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
775 if (action->type != COLLECTION_MANAGER_UPDATE &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
776 action->oldpath && action->newpath)
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 printf("collection manager failed to %s %s for collection %s\n",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
779 (action->type == COLLECTION_MANAGER_ADD) ? "add" : "remove",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
780 action->oldpath, action->newpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
781 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
782
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
783 if (collection_manager_action_tail == collection_manager_action_list)
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 collection_manager_action_tail = NULL;
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 collection_manager_action_list = g_list_remove(collection_manager_action_list, action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
788 collect_manager_action_unref(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
789 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
790 }
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 static gint collect_manager_process_entry(CollectManagerEntry *entry)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
793 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
794 CollectionData *cd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
795 gint success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
796
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
797 if (entry->empty) return FALSE;
9
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 cd = collection_new(entry->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
800 success = collection_load_private(cd, entry->path, FALSE, FALSE);
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 collection_unref(cd);
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 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
805 }
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 static gint collect_manager_process_entry_list(void)
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 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
810
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
811 work = collection_manager_entry_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
812 while (work)
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 CollectManagerEntry *entry;
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 entry = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
817 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
818 if (collect_manager_process_entry(entry)) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
819 }
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 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
822 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
823
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
824
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
825
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
826 static gint collect_manager_process_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
827 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
828 if (collection_manager_action_list) collect_manager_refresh();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
829 collect_manager_process_actions(COLLECT_MANAGER_ACTIONS_PER_IDLE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
830 if (collection_manager_action_list) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
831
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
832 if (collect_manager_process_entry_list()) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
833
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
834 if (debug) printf("collection manager is up to date\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
835 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
838 static gint collect_manager_timer_cb(gpointer data)
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 if (debug) printf("collection manager timer expired\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
841
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
842 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
843
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
844 collection_manager_timer_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
845 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
848 static void collect_manager_timer_push(gint stop)
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 if (collection_manager_timer_id != -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
851 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
852 if (!stop) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
853
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
854 g_source_remove(collection_manager_timer_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
855 collection_manager_timer_id = -1;
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 if (!stop)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
859 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
860 collection_manager_timer_id = g_timeout_add(COLLECT_MANAGER_FLUSH_DELAY,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
861 collect_manager_timer_cb, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
862 if (debug) printf("collection manager timer started\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
863 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
864 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
865
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
866 static void collect_manager_add_action(CollectManagerAction *action)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
867 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
868 if (!action) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
869
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
870 /* 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
871
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
872 if (collection_manager_action_tail)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
873 {
66
ebbff299ad0d Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
874 collection_manager_action_tail = g_list_append(collection_manager_action_tail, action);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
875 collection_manager_action_tail = collection_manager_action_tail->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
876 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
877 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
878 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
879 collection_manager_action_list = g_list_append(collection_manager_action_list, action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
880 collection_manager_action_tail = collection_manager_action_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
881 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
882
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
883 collect_manager_timer_push(FALSE);
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
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
886 void collect_manager_moved(FileData *fd)
9
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 CollectManagerAction *action;
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
889 const gchar *oldpath = fd->change->source;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
890 const gchar *newpath = fd->change->dest;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
891
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
892 action = collect_manager_action_new(oldpath, newpath, COLLECTION_MANAGER_UPDATE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
893 collect_manager_add_action(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
894 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
895
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
896 void collect_manager_add(FileData *fd, const gchar *collection)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
897 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
898 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
899 CollectWindow *cw;
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 if (!fd || !collection) return;
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 cw = collection_window_find_by_path(collection);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
904 if (cw)
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 if (collection_list_find(cw->cd->list, fd->path) == NULL)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
907 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
908 collection_add(cw->cd, fd, FALSE);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
909 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
910 return;
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
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
913 action = collect_manager_action_new(fd->path, collection, COLLECTION_MANAGER_ADD);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
914 collect_manager_add_action(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
915 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
916
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
917 void collect_manager_remove(FileData *fd, const gchar *collection)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
918 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
919 CollectManagerAction *action;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
920 CollectWindow *cw;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
921
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
922 if (!fd || !collection) return;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
923
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
924 cw = collection_window_find_by_path(collection);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
925 if (cw)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
926 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
927 while (collection_remove(cw->cd, fd));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
928 return;
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
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 66
diff changeset
931 action = collect_manager_action_new(fd->path, collection, COLLECTION_MANAGER_REMOVE);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
932 collect_manager_add_action(action);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
933 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
934
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
935 void collect_manager_flush(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
936 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
937 collect_manager_timer_push(TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
938
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
939 if (debug) printf("collection manager flushing\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
940 while (collect_manager_process_cb(NULL));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
941 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
942