Mercurial > geeqie
annotate src/collect.c @ 1347:79937bc55f3a
Add missing space between switch and first parenthesis.
author | zas_ |
---|---|
date | Sat, 28 Feb 2009 20:52:51 +0000 |
parents | 4a3ae0e6f1eb |
children | fe4da037be21 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
94
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
3 * (C) 2006 John Ellis |
1284 | 4 * Copyright (C) 2008 - 2009 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
281 | 14 #include "main.h" |
9 | 15 #include "collect.h" |
16 | |
17 #include "collect-dlg.h" | |
18 #include "collect-io.h" | |
19 #include "collect-table.h" | |
20 #include "editors.h" | |
586 | 21 #include "filedata.h" |
9 | 22 #include "img-view.h" |
23 #include "layout.h" | |
24 #include "layout_image.h" | |
1022
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
816
diff
changeset
|
25 #include "misc.h" |
91
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
85
diff
changeset
|
26 #include "pixbuf_util.h" |
94
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
27 #include "print.h" |
9 | 28 #include "ui_fileops.h" |
29 #include "ui_tree_edit.h" | |
1022
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
816
diff
changeset
|
30 #include "utilops.h" |
648
e34c1002e553
Move some functions from main.[ch] to new window.[ch].
zas_
parents:
586
diff
changeset
|
31 #include "window.h" |
9 | 32 |
33 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
34 | |
35 | |
36 #define COLLECT_DEF_WIDTH 440 | |
37 #define COLLECT_DEF_HEIGHT 450 | |
38 | |
39 static GList *collection_list = NULL; | |
40 static GList *collection_window_list = NULL; | |
41 | |
42 static void collection_window_get_geometry(CollectWindow *cw); | |
43 static void collection_window_refresh(CollectWindow *cw); | |
44 static void collection_window_update_title(CollectWindow *cw); | |
45 static void collection_window_add(CollectWindow *cw, CollectInfo *ci); | |
46 static void collection_window_insert(CollectWindow *cw, CollectInfo *ci); | |
47 static void collection_window_remove(CollectWindow *cw, CollectInfo *ci); | |
48 static void collection_window_update(CollectWindow *cw, CollectInfo *ci); | |
49 | |
50 static void collection_window_close(CollectWindow *cw); | |
51 | |
799 | 52 static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data); |
53 | |
9 | 54 /* |
55 *------------------------------------------------------------------- | |
56 * data, list handling | |
57 *------------------------------------------------------------------- | |
58 */ | |
59 | |
138 | 60 CollectInfo *collection_info_new(FileData *fd, struct stat *st, GdkPixbuf *pixbuf) |
9 | 61 { |
62 CollectInfo *ci; | |
63 | |
138 | 64 if (!fd) return NULL; |
9 | 65 |
66 ci = g_new0(CollectInfo, 1); | |
138 | 67 ci->fd = file_data_ref(fd); |
9 | 68 |
69 ci->pixbuf = pixbuf; | |
70 if (ci->pixbuf) g_object_ref(ci->pixbuf); | |
71 | |
72 return ci; | |
73 } | |
74 | |
75 void collection_info_free_thumb(CollectInfo *ci) | |
76 { | |
77 if (ci->pixbuf) g_object_unref(ci->pixbuf); | |
78 ci->pixbuf = NULL; | |
79 } | |
80 | |
81 void collection_info_free(CollectInfo *ci) | |
82 { | |
83 if (!ci) return; | |
84 | |
138 | 85 file_data_unref(ci->fd); |
9 | 86 collection_info_free_thumb(ci); |
87 g_free(ci); | |
88 } | |
89 | |
90 void collection_info_set_thumb(CollectInfo *ci, GdkPixbuf *pixbuf) | |
91 { | |
92 if (pixbuf) g_object_ref(pixbuf); | |
93 collection_info_free_thumb(ci); | |
94 ci->pixbuf = pixbuf; | |
95 } | |
96 | |
97 gint collection_info_load_thumb(CollectInfo *ci) | |
98 { | |
99 if (!ci) return FALSE; | |
100 | |
101 collection_info_free_thumb(ci); | |
102 | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
103 log_printf("collection_info_load_thumb not implemented!\n(because an instant thumb loader not implemented)"); |
9 | 104 return FALSE; |
442 | 105 #if 0 |
138 | 106 if (create_thumbnail(ci->fd->path, &ci->pixmap, &ci->mask) < 0) return FALSE; |
9 | 107 |
108 if (ci->pixmap) gdk_pixmap_ref(ci->pixmap); | |
109 if (ci->mask) gdk_bitmap_ref(ci->mask); | |
110 | |
111 return TRUE; | |
112 #endif | |
113 } | |
114 | |
115 void collection_list_free(GList *list) | |
116 { | |
117 GList *work; | |
118 work = list; | |
516 | 119 while (work) |
9 | 120 { |
121 collection_info_free((CollectInfo *)work->data); | |
122 work = work->next; | |
123 } | |
124 g_list_free(list); | |
125 } | |
126 | |
127 /* an ugly static var, well what ya gonna do ? */ | |
128 static SortType collection_list_sort_method = SORT_NAME; | |
129 | |
130 static gint collection_list_sort_cb(gconstpointer a, gconstpointer b) | |
131 { | |
132 const CollectInfo *cia = a; | |
133 const CollectInfo *cib = b; | |
134 | |
1347
79937bc55f3a
Add missing space between switch and first parenthesis.
zas_
parents:
1292
diff
changeset
|
135 switch (collection_list_sort_method) |
9 | 136 { |
785 | 137 case SORT_NAME: |
138 break; | |
9 | 139 case SORT_NONE: |
140 return 0; | |
141 break; | |
142 case SORT_SIZE: | |
138 | 143 if (cia->fd->size < cib->fd->size) return -1; |
144 if (cia->fd->size > cib->fd->size) return 1; | |
9 | 145 return 0; |
146 break; | |
147 case SORT_TIME: | |
138 | 148 if (cia->fd->date < cib->fd->date) return -1; |
149 if (cia->fd->date > cib->fd->date) return 1; | |
9 | 150 return 0; |
151 break; | |
152 case SORT_PATH: | |
786
a20ff446347e
Compare paths using utf8_collate_key() since paths are utf8-encoded.
zas_
parents:
785
diff
changeset
|
153 return utf8_compare(cia->fd->path, cib->fd->path, options->file_sort.case_sensitive); |
9 | 154 break; |
155 #ifdef HAVE_STRVERSCMP | |
156 case SORT_NUMBER: | |
138 | 157 return strverscmp(cia->fd->name, cib->fd->name); |
9 | 158 break; |
159 #endif | |
160 default: | |
161 break; | |
162 } | |
163 | |
785 | 164 if (options->file_sort.case_sensitive) |
165 return strcmp(cia->fd->collate_key_name, cib->fd->collate_key_name); | |
166 else | |
167 return strcmp(cia->fd->collate_key_name_nocase, cib->fd->collate_key_name_nocase); | |
9 | 168 } |
169 | |
170 GList *collection_list_sort(GList *list, SortType method) | |
171 { | |
172 if (method == SORT_NONE) return list; | |
173 | |
174 collection_list_sort_method = method; | |
175 | |
176 return g_list_sort(list, collection_list_sort_cb); | |
177 } | |
178 | |
179 GList *collection_list_add(GList *list, CollectInfo *ci, SortType method) | |
180 { | |
181 if (method != SORT_NONE) | |
182 { | |
183 collection_list_sort_method = method; | |
184 list = g_list_insert_sorted(list, ci, collection_list_sort_cb); | |
185 } | |
186 else | |
187 { | |
188 list = g_list_append(list, ci); | |
189 } | |
190 | |
191 return list; | |
192 } | |
193 | |
194 GList *collection_list_insert(GList *list, CollectInfo *ci, CollectInfo *insert_ci, SortType method) | |
195 { | |
196 if (method != SORT_NONE) | |
197 { | |
198 collection_list_sort_method = method; | |
199 list = g_list_insert_sorted(list, ci, collection_list_sort_cb); | |
200 } | |
201 else | |
202 { | |
203 GList *point; | |
204 | |
205 point = g_list_find(list, insert_ci); | |
206 list = uig_list_insert_link(list, point, ci); | |
207 } | |
208 | |
209 return list; | |
210 } | |
211 | |
212 GList *collection_list_remove(GList *list, CollectInfo *ci) | |
213 { | |
214 list = g_list_remove(list, ci); | |
215 collection_info_free(ci); | |
216 return list; | |
217 } | |
218 | |
799 | 219 CollectInfo *collection_list_find_fd(GList *list, FileData *fd) |
9 | 220 { |
221 GList *work = list; | |
222 | |
516 | 223 while (work) |
9 | 224 { |
225 CollectInfo *ci = work->data; | |
799 | 226 if (ci->fd == fd) return ci; |
9 | 227 work = work->next; |
228 } | |
229 | |
230 return NULL; | |
231 } | |
232 | |
233 #if 0 | |
234 static GList *collection_list_find_link(GList *list, gchar *path) | |
235 { | |
236 GList *work = list; | |
237 | |
516 | 238 while (work) |
9 | 239 { |
240 CollectInfo *ci = work->data; | |
138 | 241 if (strcmp(ci->fd->path, path) == 0) return work; |
9 | 242 work = work->next; |
243 } | |
244 | |
245 return NULL; | |
246 } | |
247 | |
248 static gint collection_list_find_index(GList *list, gchar *path) | |
249 { | |
250 gint c = 0; | |
251 GList *work = list; | |
252 | |
516 | 253 while (work) |
9 | 254 { |
255 CollectInfo *ci = work->data; | |
138 | 256 if (strcmp(ci->fd->path, path) == 0) return c; |
9 | 257 work = work->next; |
258 c++; | |
259 } | |
260 | |
261 return -1; | |
262 } | |
263 #endif | |
264 | |
138 | 265 GList *collection_list_to_filelist(GList *list) |
9 | 266 { |
138 | 267 GList *filelist = NULL; |
9 | 268 GList *work = list; |
269 | |
270 while (work) | |
271 { | |
272 CollectInfo *info = work->data; | |
138 | 273 filelist = g_list_prepend(filelist, file_data_ref(info->fd)); |
9 | 274 work = work->next; |
275 } | |
276 | |
138 | 277 filelist = g_list_reverse(filelist); |
278 return filelist; | |
9 | 279 } |
280 | |
281 CollectWindow *collection_window_find(CollectionData *cd) | |
282 { | |
283 GList *work; | |
284 | |
285 work = collection_window_list; | |
286 while (work) | |
287 { | |
288 CollectWindow *cw = work->data; | |
289 if (cw->cd == cd) return cw; | |
290 work = work->next; | |
291 } | |
292 | |
293 return NULL; | |
294 } | |
295 | |
296 CollectWindow *collection_window_find_by_path(const gchar *path) | |
297 { | |
298 GList *work; | |
299 | |
300 if (!path) return NULL; | |
301 | |
302 work = collection_window_list; | |
303 while (work) | |
304 { | |
305 CollectWindow *cw = work->data; | |
306 if (cw->cd->path && strcmp(cw->cd->path, path) == 0) return cw; | |
307 work = work->next; | |
308 } | |
309 | |
310 return NULL; | |
311 } | |
312 | |
313 /* | |
314 *------------------------------------------------------------------- | |
315 * please use these to actually add/remove stuff | |
316 *------------------------------------------------------------------- | |
317 */ | |
318 | |
319 CollectionData *collection_new(const gchar *path) | |
320 { | |
321 CollectionData *cd; | |
322 static gint untitled_counter = 0; | |
323 | |
324 cd = g_new0(CollectionData, 1); | |
325 | |
326 collection_list = g_list_append(collection_list, cd); | |
327 | |
328 cd->ref = 1; /* starts with a ref of 1 */ | |
329 | |
330 cd->list = NULL; | |
331 cd->sort_method = SORT_NONE; | |
332 cd->thumb_loader = NULL; | |
333 cd->info_updated_func = NULL; | |
334 | |
335 cd->window_read = FALSE; | |
336 cd->window_x = 0; | |
337 cd->window_y = 0; | |
338 cd->window_w = COLLECT_DEF_WIDTH; | |
339 cd->window_h = COLLECT_DEF_HEIGHT; | |
340 | |
341 cd->changed = FALSE; | |
342 | |
303
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
343 cd->existence = g_hash_table_new(NULL, NULL); |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
344 |
9 | 345 if (path) |
346 { | |
347 cd->path = g_strdup(path); | |
348 cd->name = g_strdup(filename_from_path(cd->path)); | |
349 /* load it */ | |
350 } | |
351 else | |
352 { | |
353 cd->path = NULL; | |
354 | |
355 if (untitled_counter == 0) | |
356 { | |
357 cd->name = g_strdup(_("Untitled")); | |
358 } | |
359 else | |
360 { | |
361 cd->name = g_strdup_printf(_("Untitled (%d)"), untitled_counter + 1); | |
362 } | |
363 | |
364 untitled_counter++; | |
365 } | |
366 | |
799 | 367 file_data_register_notify_func(collection_notify_cb, cd, NOTIFY_PRIORITY_MEDIUM); |
368 | |
9 | 369 return cd; |
370 } | |
371 | |
372 void collection_free(CollectionData *cd) | |
373 { | |
374 if (!cd) return; | |
375 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
376 DEBUG_1("collection \"%s\" freed", cd->name); |
9 | 377 |
378 collection_load_stop(cd); | |
379 collection_list_free(cd->list); | |
799 | 380 |
381 file_data_unregister_notify_func(collection_notify_cb, cd); | |
9 | 382 |
383 collection_list = g_list_remove(collection_list, cd); | |
384 | |
303
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
385 g_hash_table_destroy(cd->existence); |
442 | 386 |
9 | 387 g_free(cd->path); |
388 g_free(cd->name); | |
389 | |
390 g_free(cd); | |
391 } | |
392 | |
393 void collection_ref(CollectionData *cd) | |
394 { | |
395 cd->ref++; | |
396 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
397 DEBUG_1("collection \"%s\" ref count = %d", cd->name, cd->ref); |
9 | 398 } |
399 | |
400 void collection_unref(CollectionData *cd) | |
401 { | |
402 cd->ref--; | |
403 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
404 DEBUG_1("collection \"%s\" ref count = %d", cd->name, cd->ref); |
9 | 405 |
406 if (cd->ref < 1) | |
407 { | |
408 collection_free(cd); | |
409 } | |
410 } | |
411 | |
412 void collection_path_changed(CollectionData *cd) | |
413 { | |
414 collection_window_update_title(collection_window_find(cd)); | |
415 } | |
416 | |
417 gint collection_to_number(CollectionData *cd) | |
418 { | |
419 return g_list_index(collection_list, cd); | |
420 } | |
421 | |
422 CollectionData *collection_from_number(gint n) | |
423 { | |
424 return g_list_nth_data(collection_list, n); | |
425 } | |
426 | |
427 CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList **info_list) | |
428 { | |
429 CollectionData *cd; | |
816 | 430 gint collection_number; |
431 const gchar *ptr; | |
432 | |
433 if (list) *list = NULL; | |
434 if (info_list) *info_list = NULL; | |
9 | 435 |
436 if (strncmp(data, "COLLECTION:", 11) != 0) return NULL; | |
816 | 437 |
438 ptr = data + 11; | |
439 | |
440 collection_number = atoi(ptr); | |
441 cd = collection_from_number(collection_number); | |
442 if (!cd) return NULL; | |
9 | 443 |
816 | 444 if (!list && !info_list) return cd; |
445 | |
446 while (*ptr != '\0' && *ptr != '\n' ) ptr++; | |
447 if (*ptr == '\0') return cd; | |
448 ptr++; | |
9 | 449 |
816 | 450 while (*ptr != '\0') |
451 { | |
452 guint item_number; | |
453 CollectInfo *info; | |
454 | |
455 item_number = (guint) atoi(ptr); | |
456 while (*ptr != '\n' && *ptr != '\0') ptr++; | |
457 if (*ptr == '\0') | |
458 break; | |
459 else | |
460 while (*ptr == '\n') ptr++; | |
9 | 461 |
816 | 462 info = g_list_nth_data(cd->list, item_number); |
463 if (!info) continue; | |
9 | 464 |
816 | 465 if (list) *list = g_list_append(*list, file_data_ref(info->fd)); |
466 if (info_list) *info_list = g_list_append(*info_list, info); | |
9 | 467 } |
816 | 468 |
9 | 469 return cd; |
470 } | |
471 | |
472 gchar *collection_info_list_to_dnd_data(CollectionData *cd, GList *list, gint *length) | |
473 { | |
474 GList *work; | |
815
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
475 GList *temp = NULL; |
9 | 476 gchar *ptr; |
815
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
477 gchar *text; |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
478 gchar *uri_text; |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
479 gint collection_number; |
9 | 480 |
815
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
481 *length = 0; |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
482 if (!list) return NULL; |
9 | 483 |
815
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
484 collection_number = collection_to_number(cd); |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
485 if (collection_number < 0) return NULL; |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
486 |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
487 text = g_strdup_printf("COLLECTION:%d\n", collection_number); |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
488 *length += strlen(text); |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
489 temp = g_list_prepend(temp, text); |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
490 |
9 | 491 work = list; |
516 | 492 while (work) |
9 | 493 { |
815
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
494 gint item_number = g_list_index(cd->list, work->data); |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
495 |
9 | 496 work = work->next; |
815
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
497 |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
498 if (item_number < 0) continue; |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
499 |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
500 text = g_strdup_printf("%d\n", item_number); |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
501 temp = g_list_prepend(temp, text); |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
502 *length += strlen(text); |
9 | 503 } |
504 | |
815
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
505 *length += 1; /* ending nul char */ |
9 | 506 |
815
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
507 uri_text = g_malloc(*length); |
9 | 508 ptr = uri_text; |
509 | |
510 work = g_list_last(temp); | |
516 | 511 while (work) |
9 | 512 { |
815
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
513 gint len; |
9 | 514 gchar *text = work->data; |
515 | |
516 work = work->prev; | |
517 | |
815
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
518 len = strlen(text); |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
519 memcpy(ptr, text, len); |
7daea970a89a
collection_info_list_to_dnd_data(): simplify and optimize.
zas_
parents:
803
diff
changeset
|
520 ptr += len; |
9 | 521 } |
522 | |
523 ptr[0] = '\0'; | |
524 | |
138 | 525 string_list_free(temp); |
9 | 526 |
527 return uri_text; | |
528 } | |
529 | |
530 gint collection_info_valid(CollectionData *cd, CollectInfo *info) | |
531 { | |
532 if (collection_to_number(cd) < 0) return FALSE; | |
533 | |
534 return (g_list_index(cd->list, info) != 0); | |
535 } | |
536 | |
537 CollectInfo *collection_next_by_info(CollectionData *cd, CollectInfo *info) | |
538 { | |
539 GList *work; | |
540 | |
541 work = g_list_find(cd->list, info); | |
542 | |
543 if (!work) return NULL; | |
544 work = work->next; | |
545 if (work) return work->data; | |
546 return NULL; | |
547 } | |
548 | |
549 CollectInfo *collection_prev_by_info(CollectionData *cd, CollectInfo *info) | |
550 { | |
551 GList *work; | |
552 | |
553 work = g_list_find(cd->list, info); | |
554 | |
555 if (!work) return NULL; | |
556 work = work->prev; | |
557 if (work) return work->data; | |
558 return NULL; | |
559 } | |
560 | |
561 CollectInfo *collection_get_first(CollectionData *cd) | |
562 { | |
563 if (cd->list) return cd->list->data; | |
564 | |
565 return NULL; | |
566 } | |
567 | |
568 CollectInfo *collection_get_last(CollectionData *cd) | |
569 { | |
570 GList *list; | |
571 | |
572 list = g_list_last(cd->list); | |
573 | |
574 if (list) return list->data; | |
575 | |
576 return NULL; | |
577 } | |
578 | |
579 void collection_set_sort_method(CollectionData *cd, SortType method) | |
580 { | |
581 if (!cd) return; | |
582 | |
583 if (cd->sort_method == method) return; | |
584 | |
585 cd->sort_method = method; | |
586 cd->list = collection_list_sort(cd->list, cd->sort_method); | |
587 if (cd->list) cd->changed = TRUE; | |
588 | |
589 collection_window_refresh(collection_window_find(cd)); | |
590 } | |
591 | |
592 void collection_set_update_info_func(CollectionData *cd, | |
593 void (*func)(CollectionData *, CollectInfo *, gpointer), gpointer data) | |
594 { | |
595 cd->info_updated_func = func; | |
596 cd->info_updated_data = data; | |
597 } | |
598 | |
303
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
599 static CollectInfo *collection_info_new_if_not_exists(CollectionData *cd, struct stat *st, FileData *fd) |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
600 { |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
601 CollectInfo *ci; |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
602 |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
603 if (g_hash_table_lookup(cd->existence, fd->path)) return NULL; |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
604 |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
605 ci = collection_info_new(fd, st, NULL); |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
606 if (ci) g_hash_table_insert(cd->existence, fd->path, ""); |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
607 return ci; |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
608 } |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
609 |
138 | 610 gint collection_add_check(CollectionData *cd, FileData *fd, gint sorted, gint must_exist) |
9 | 611 { |
612 struct stat st; | |
613 gint valid; | |
614 | |
615 if (must_exist) | |
616 { | |
138 | 617 valid = (stat_utf8(fd->path, &st) && !S_ISDIR(st.st_mode)); |
9 | 618 } |
619 else | |
620 { | |
621 valid = TRUE; | |
622 st.st_size = 0; | |
623 st.st_mtime = 0; | |
624 } | |
625 | |
626 if (valid) | |
627 { | |
628 CollectInfo *ci; | |
303
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
629 |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
630 ci = collection_info_new_if_not_exists(cd, &st, fd); |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
631 if (!ci) return FALSE; |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
632 DEBUG_3("add to collection: %s", fd->path); |
303
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
633 |
9 | 634 cd->list = collection_list_add(cd->list, ci, sorted ? cd->sort_method : SORT_NONE); |
635 cd->changed = TRUE; | |
636 | |
637 if (!sorted || cd->sort_method == SORT_NONE) | |
638 { | |
639 collection_window_add(collection_window_find(cd), ci); | |
640 } | |
641 else | |
642 { | |
643 collection_window_insert(collection_window_find(cd), ci); | |
644 } | |
645 } | |
646 | |
647 return valid; | |
648 } | |
649 | |
138 | 650 gint collection_add(CollectionData *cd, FileData *fd, gint sorted) |
9 | 651 { |
138 | 652 return collection_add_check(cd, fd, sorted, TRUE); |
9 | 653 } |
654 | |
138 | 655 gint collection_insert(CollectionData *cd, FileData *fd, CollectInfo *insert_ci, gint sorted) |
9 | 656 { |
657 struct stat st; | |
658 | |
138 | 659 if (!insert_ci) return collection_add(cd, fd, sorted); |
9 | 660 |
138 | 661 if (stat_utf8(fd->path, &st) >= 0 && !S_ISDIR(st.st_mode)) |
9 | 662 { |
663 CollectInfo *ci; | |
303
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
664 |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
665 ci = collection_info_new_if_not_exists(cd, &st, fd); |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
666 if (!ci) return FALSE; |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
667 |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
668 DEBUG_3("insert in collection: %s", fd->path); |
303
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
669 |
9 | 670 cd->list = collection_list_insert(cd->list, ci, insert_ci, sorted ? cd->sort_method : SORT_NONE); |
671 cd->changed = TRUE; | |
672 | |
673 collection_window_insert(collection_window_find(cd), ci); | |
674 | |
675 return TRUE; | |
676 } | |
677 | |
678 return FALSE; | |
679 } | |
680 | |
138 | 681 gint collection_remove(CollectionData *cd, FileData *fd) |
9 | 682 { |
683 CollectInfo *ci; | |
684 | |
799 | 685 ci = collection_list_find_fd(cd->list, fd); |
9 | 686 |
687 if (!ci) return FALSE; | |
688 | |
303
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
689 g_hash_table_remove(cd->existence, fd->path); |
6ff0bc50ac46
Prevent multiple insertion of the same file in a collection.
zas_
parents:
289
diff
changeset
|
690 |
9 | 691 cd->list = g_list_remove(cd->list, ci); |
692 cd->changed = TRUE; | |
693 | |
694 collection_window_remove(collection_window_find(cd), ci); | |
695 collection_info_free(ci); | |
696 | |
697 return TRUE; | |
698 } | |
699 | |
700 static void collection_remove_by_info(CollectionData *cd, CollectInfo *info) | |
701 { | |
702 if (!info || !g_list_find(cd->list, info)) return; | |
703 | |
704 cd->list = g_list_remove(cd->list, info); | |
705 cd->changed = (cd->list != NULL); | |
706 | |
707 collection_window_remove(collection_window_find(cd), info); | |
708 collection_info_free(info); | |
709 } | |
710 | |
711 void collection_remove_by_info_list(CollectionData *cd, GList *list) | |
712 { | |
713 GList *work; | |
714 | |
715 if (!list) return; | |
716 | |
717 if (!list->next) | |
718 { | |
719 /* more efficient (in collect-table) to remove a single item this way */ | |
720 collection_remove_by_info(cd, (CollectInfo *)list->data); | |
721 return; | |
722 } | |
723 | |
724 work = list; | |
516 | 725 while (work) |
9 | 726 { |
727 cd->list = collection_list_remove(cd->list, work->data); | |
728 work = work->next; | |
729 } | |
730 cd->changed = (cd->list != NULL); | |
731 | |
732 collection_window_refresh(collection_window_find(cd)); | |
733 } | |
734 | |
138 | 735 gint collection_rename(CollectionData *cd, FileData *fd) |
9 | 736 { |
737 CollectInfo *ci; | |
799 | 738 ci = collection_list_find_fd(cd->list, fd); |
9 | 739 |
740 if (!ci) return FALSE; | |
741 | |
742 cd->changed = TRUE; | |
743 | |
744 collection_window_update(collection_window_find(cd), ci); | |
745 | |
746 return TRUE; | |
747 } | |
748 | |
749 void collection_update_geometry(CollectionData *cd) | |
750 { | |
751 collection_window_get_geometry(collection_window_find(cd)); | |
752 } | |
753 | |
754 /* | |
755 *------------------------------------------------------------------- | |
756 * simple maintenance for renaming, deleting | |
757 *------------------------------------------------------------------- | |
758 */ | |
759 | |
799 | 760 static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data) |
9 | 761 { |
799 | 762 CollectionData *cd = data; |
9 | 763 |
803 | 764 if (type != NOTIFY_TYPE_CHANGE || !fd->change) return; |
799 | 765 |
1347
79937bc55f3a
Add missing space between switch and first parenthesis.
zas_
parents:
1292
diff
changeset
|
766 switch (fd->change->type) |
9 | 767 { |
799 | 768 case FILEDATA_CHANGE_MOVE: |
769 case FILEDATA_CHANGE_RENAME: | |
770 collection_rename(cd, fd); | |
771 break; | |
772 case FILEDATA_CHANGE_COPY: | |
773 break; | |
774 case FILEDATA_CHANGE_DELETE: | |
775 while (collection_remove(cd, fd)); | |
776 break; | |
777 case FILEDATA_CHANGE_UNSPECIFIED: | |
1211 | 778 case FILEDATA_CHANGE_WRITE_METADATA: |
799 | 779 break; |
9 | 780 } |
799 | 781 |
9 | 782 } |
783 | |
784 | |
785 /* | |
786 *------------------------------------------------------------------- | |
787 * window key presses | |
788 *------------------------------------------------------------------- | |
789 */ | |
790 | |
791 static gint collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
792 { | |
793 CollectWindow *cw = data; | |
794 gint stop_signal = FALSE; | |
795 gint edit_val = -1; | |
796 GList *list; | |
797 | |
798 if (event->state & GDK_CONTROL_MASK) | |
799 { | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
800 stop_signal = TRUE; |
9 | 801 switch (event->keyval) |
802 { | |
803 case '1': | |
804 edit_val = 0; | |
805 break; | |
806 case '2': | |
807 edit_val = 1; | |
808 break; | |
809 case '3': | |
810 edit_val = 2; | |
811 break; | |
812 case '4': | |
813 edit_val = 3; | |
814 break; | |
815 case '5': | |
816 edit_val = 4; | |
817 break; | |
818 case '6': | |
819 edit_val = 5; | |
820 break; | |
821 case '7': | |
822 edit_val = 6; | |
823 break; | |
824 case '8': | |
825 edit_val = 7; | |
826 break; | |
827 case '9': | |
828 edit_val = 8; | |
829 break; | |
830 case '0': | |
831 edit_val = 9; | |
832 break; | |
833 case 'A': case 'a': | |
834 if (event->state & GDK_SHIFT_MASK) | |
835 { | |
836 collection_table_unselect_all(cw->table); | |
837 } | |
838 else | |
839 { | |
840 collection_table_select_all(cw->table); | |
841 } | |
842 break; | |
843 case 'L': case 'l': | |
844 list = layout_list(NULL); | |
845 if (list) | |
846 { | |
138 | 847 collection_table_add_filelist(cw->table, list); |
848 filelist_free(list); | |
9 | 849 } |
850 break; | |
851 case 'C': case 'c': | |
852 file_util_copy(NULL, collection_table_selection_get_list(cw->table), NULL, cw->window); | |
853 break; | |
854 case 'M': case 'm': | |
855 file_util_move(NULL, collection_table_selection_get_list(cw->table), NULL, cw->window); | |
856 break; | |
857 case 'R': case 'r': | |
858 file_util_rename(NULL, collection_table_selection_get_list(cw->table), cw->window); | |
859 break; | |
860 case 'D': case 'd': | |
861 file_util_delete(NULL, collection_table_selection_get_list(cw->table), cw->window); | |
862 break; | |
863 case 'S': case 's': | |
864 collection_dialog_save_as(NULL, cw->cd); | |
865 break; | |
866 case 'W': case 'w': | |
867 collection_window_close(cw); | |
868 break; | |
869 default: | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
870 stop_signal = FALSE; |
9 | 871 break; |
872 } | |
873 } | |
874 else | |
875 { | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
876 stop_signal = TRUE; |
9 | 877 switch (event->keyval) |
878 { | |
879 case GDK_Return: case GDK_KP_Enter: | |
880 layout_image_set_collection(NULL, cw->cd, | |
881 collection_table_get_focus_info(cw->table)); | |
882 break; | |
883 case 'V': case 'v': | |
884 view_window_new_from_collection(cw->cd, | |
885 collection_table_get_focus_info(cw->table)); | |
886 break; | |
887 case 'S': case 's': | |
888 if (!cw->cd->path) | |
889 { | |
890 collection_dialog_save_as(NULL, cw->cd); | |
442 | 891 } |
9 | 892 else if (!collection_save(cw->cd, cw->cd->path)) |
893 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
894 log_printf("failed saving to collection path: %s\n", cw->cd->path); |
9 | 895 } |
896 break; | |
897 case 'A': case 'a': | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
898 collection_dialog_append(NULL, cw->cd); |
9 | 899 break; |
900 case 'N': case 'n': | |
901 collection_set_sort_method(cw->cd, SORT_NAME); | |
902 break; | |
903 #ifdef HAVE_STRVERSCMP | |
904 case 'I': case 'i': | |
905 collection_set_sort_method(cw->cd, SORT_NUMBER); | |
906 break; | |
907 #endif | |
908 case 'D': case 'd': | |
909 collection_set_sort_method(cw->cd, SORT_TIME); | |
910 break; | |
911 case 'B': case 'b': | |
912 collection_set_sort_method(cw->cd, SORT_SIZE); | |
913 break; | |
914 case 'P': case 'p': | |
94
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
915 if (event->state & GDK_SHIFT_MASK) |
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
916 { |
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
917 CollectInfo *info; |
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
918 |
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
919 info = collection_table_get_focus_info(cw->table); |
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
920 |
138 | 921 print_window_new(info->fd, collection_table_selection_get_list(cw->table), |
922 collection_list_to_filelist(cw->cd->list), cw->window); | |
94
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
923 } |
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
924 else |
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
925 { |
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
926 collection_set_sort_method(cw->cd, SORT_PATH); |
50dc5a14d37b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
927 } |
9 | 928 break; |
929 case GDK_Delete: case GDK_KP_Delete: | |
930 list = g_list_copy(cw->table->selection); | |
931 if (list) | |
932 { | |
933 collection_remove_by_info_list(cw->cd, list); | |
934 g_list_free(list); | |
935 } | |
936 else | |
937 { | |
938 collection_remove_by_info(cw->cd, collection_table_get_focus_info(cw->table)); | |
939 } | |
940 break; | |
941 default: | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
942 stop_signal = FALSE; |
9 | 943 break; |
944 } | |
945 } | |
1272 | 946 #if 0 |
9 | 947 if (edit_val != -1) |
948 { | |
949 list = collection_table_selection_get_list(cw->table); | |
753 | 950 file_util_start_editor_from_filelist(edit_val, list, cw->window); |
138 | 951 filelist_free(list); |
9 | 952 } |
1272 | 953 #endif |
9 | 954 return stop_signal; |
955 } | |
956 | |
957 /* | |
958 *------------------------------------------------------------------- | |
959 * window | |
960 *------------------------------------------------------------------- | |
961 */ | |
962 static void collection_window_get_geometry(CollectWindow *cw) | |
963 { | |
964 CollectionData *cd; | |
965 | |
966 if (!cw) return; | |
967 | |
968 cd = cw->cd; | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
507
diff
changeset
|
969 gdk_window_get_position(cw->window->window, &cd->window_x, &cd->window_y); |
9 | 970 gdk_drawable_get_size(cw->window->window, &cd->window_w, &cd->window_h); |
971 cd->window_read = TRUE; | |
972 } | |
973 | |
974 static void collection_window_refresh(CollectWindow *cw) | |
975 { | |
976 if (!cw) return; | |
977 | |
978 collection_table_refresh(cw->table); | |
979 } | |
980 | |
981 static void collection_window_update_title(CollectWindow *cw) | |
982 { | |
1176
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
983 gboolean free_name = FALSE; |
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
984 gchar *name; |
9 | 985 gchar *buf; |
986 | |
987 if (!cw) return; | |
988 | |
1176
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
989 if (file_extension_match(cw->cd->name, GQ_COLLECTION_EXT)) |
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
990 { |
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
991 name = remove_extension_from_path(cw->cd->name); |
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
992 free_name = TRUE; |
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
993 } |
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
994 else |
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
995 { |
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
996 name = cw->cd->name; |
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
997 } |
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
998 |
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
999 buf = g_strdup_printf(_("%s - Collection - %s"), name, GQ_APPNAME); |
d3e51e1a02f8
Hide .gqv extension from collection name in collection window title and recent menu list.
zas_
parents:
1174
diff
changeset
|
1000 if (free_name) g_free(name); |
9 | 1001 gtk_window_set_title(GTK_WINDOW(cw->window), buf); |
1002 g_free(buf); | |
1003 } | |
1004 | |
1005 static void collection_window_update_info(CollectionData *cd, CollectInfo *ci, gpointer data) | |
1006 { | |
1007 CollectWindow *cw = data; | |
1008 | |
1009 collection_table_file_update(cw->table, ci); | |
1010 } | |
1011 | |
1012 static void collection_window_add(CollectWindow *cw, CollectInfo *ci) | |
1013 { | |
1014 if (!cw) return; | |
1015 | |
1016 if (!ci->pixbuf) collection_load_thumb_idle(cw->cd); | |
1017 collection_table_file_add(cw->table, ci); | |
1018 } | |
1019 | |
1020 static void collection_window_insert(CollectWindow *cw, CollectInfo *ci) | |
1021 { | |
1022 if (!cw) return; | |
1023 | |
1024 if (!ci->pixbuf) collection_load_thumb_idle(cw->cd); | |
1025 collection_table_file_insert(cw->table, ci); | |
1026 if (!cw) return; | |
1027 } | |
1028 | |
1029 #if 0 | |
1030 static void collection_window_move(CollectWindow *cw, CollectInfo *ci) | |
1031 { | |
1032 if (!cw) return; | |
1033 } | |
1034 #endif | |
1035 | |
1036 static void collection_window_remove(CollectWindow *cw, CollectInfo *ci) | |
1037 { | |
1038 if (!cw) return; | |
1039 | |
1040 collection_table_file_remove(cw->table, ci); | |
1041 } | |
1042 | |
1043 static void collection_window_update(CollectWindow *cw, CollectInfo *ci) | |
1044 { | |
1045 if (!cw) return; | |
1046 | |
1047 collection_table_file_update(cw->table, ci); | |
1048 collection_table_file_update(cw->table, NULL); | |
1049 } | |
1050 | |
1051 static void collection_window_close_final(CollectWindow *cw) | |
1052 { | |
1053 if (cw->close_dialog) return; | |
1054 | |
1055 collection_window_list = g_list_remove(collection_window_list, cw); | |
1056 collection_window_get_geometry(cw); | |
1057 | |
1058 gtk_widget_destroy(cw->window); | |
1059 | |
1060 collection_set_update_info_func(cw->cd, NULL, NULL); | |
1061 collection_unref(cw->cd); | |
1062 | |
1063 g_free(cw); | |
1064 } | |
1065 | |
1066 static void collection_close_save_cb(GenericDialog *gd, gpointer data) | |
1067 { | |
1068 CollectWindow *cw = data; | |
1069 | |
1070 cw->close_dialog = NULL; | |
1071 generic_dialog_close(gd); | |
1072 | |
1073 if (!cw->cd->path) | |
442 | 1074 { |
9 | 1075 collection_dialog_save_close(NULL, cw->cd); |
1076 return; | |
1077 } | |
1078 else if (!collection_save(cw->cd, cw->cd->path)) | |
1079 { | |
1080 gchar *buf; | |
1081 buf = g_strdup_printf(_("Failed to save the collection:\n%s"), cw->cd->path); | |
1082 warning_dialog(_("Save Failed"), buf, GTK_STOCK_DIALOG_ERROR, cw->window); | |
1083 g_free(buf); | |
1084 return; | |
1085 } | |
1086 | |
1087 collection_window_close_final(cw); | |
1088 } | |
1089 | |
1090 static void collection_close_close_cb(GenericDialog *gd, gpointer data) | |
1091 { | |
1092 CollectWindow *cw = data; | |
1093 | |
1094 cw->close_dialog = NULL; | |
1095 generic_dialog_close(gd); | |
1096 | |
1097 collection_window_close_final(cw); | |
1098 } | |
1099 | |
1100 static void collection_close_cancel_cb(GenericDialog *gd, gpointer data) | |
1101 { | |
1102 CollectWindow *cw = data; | |
1103 | |
1104 cw->close_dialog = NULL; | |
1105 generic_dialog_close(gd); | |
1106 } | |
1107 | |
1108 static void collection_close_dlg_show(CollectWindow *cw) | |
1109 { | |
1110 GenericDialog *gd; | |
1111 | |
1112 if (cw->close_dialog) | |
1113 { | |
1114 gtk_window_present(GTK_WINDOW(cw->close_dialog)); | |
1115 return; | |
1116 } | |
1117 | |
1118 gd = generic_dialog_new(_("Close collection"), | |
1174
0bea79d87065
Drop useless wmclass stuff. Gtk will take care of it and as said in the documentation using gtk_window_set_wmclass() is sort of pointless.
zas_
parents:
1055
diff
changeset
|
1119 "close_collection", cw->window, FALSE, |
9 | 1120 collection_close_cancel_cb, cw); |
1121 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION, | |
1122 _("Close collection"), | |
1123 _("Collection has been modified.\nSave first?")); | |
1124 | |
1125 generic_dialog_add_button(gd, GTK_STOCK_SAVE, NULL, collection_close_save_cb, TRUE); | |
1126 generic_dialog_add_button(gd, GTK_STOCK_DELETE, _("_Discard"), collection_close_close_cb, FALSE); | |
1127 | |
1128 cw->close_dialog = gd->dialog; | |
1129 | |
1130 gtk_widget_show(gd->dialog); | |
1131 } | |
1132 | |
1133 static void collection_window_close(CollectWindow *cw) | |
1134 { | |
1135 if (!cw->cd->changed && !cw->close_dialog) | |
1136 { | |
1137 collection_window_close_final(cw); | |
1138 return; | |
1139 } | |
1140 | |
1141 collection_close_dlg_show(cw); | |
1142 } | |
1143 | |
1144 void collection_window_close_by_collection(CollectionData *cd) | |
1145 { | |
1146 CollectWindow *cw; | |
1147 | |
1148 cw = collection_window_find(cd); | |
1149 if (cw) collection_window_close_final(cw); | |
1150 } | |
1151 | |
1152 gint collection_window_modified_exists(void) | |
1153 { | |
1154 GList *work; | |
1155 | |
1156 work = collection_window_list; | |
1157 while (work) | |
1158 { | |
1159 CollectWindow *cw = work->data; | |
1160 if (cw->cd->changed) return TRUE; | |
1161 work = work->next; | |
1162 } | |
1163 | |
1164 return FALSE; | |
1165 } | |
1166 | |
1167 static gint collection_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data) | |
1168 { | |
1169 CollectWindow *cw = data; | |
1170 collection_window_close(cw); | |
1171 | |
1172 return TRUE; | |
1173 } | |
1174 | |
1175 CollectWindow *collection_window_new(const gchar *path) | |
1176 { | |
1177 CollectWindow *cw; | |
1178 GtkWidget *vbox; | |
1179 GtkWidget *frame; | |
1180 GtkWidget *status_label; | |
1181 GtkWidget *extra_label; | |
1182 GdkGeometry geometry; | |
1183 | |
1184 cw = g_new0(CollectWindow, 1); | |
1185 | |
1186 cw->close_dialog = NULL; | |
1187 | |
1188 collection_window_list = g_list_append(collection_window_list, cw); | |
1189 | |
1190 cw->cd = collection_new(path); | |
1191 | |
289
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
1192 cw->window = window_new(GTK_WINDOW_TOPLEVEL, "collection", PIXBUF_INLINE_ICON_BOOK, NULL, NULL); |
9 | 1193 |
1029
1a4b18c58556
Use a constant for minimal window size. Set it to 32 for all dialogs.
zas_
parents:
1022
diff
changeset
|
1194 geometry.min_width = DEFAULT_MINIMAL_WINDOW_SIZE; |
1a4b18c58556
Use a constant for minimal window size. Set it to 32 for all dialogs.
zas_
parents:
1022
diff
changeset
|
1195 geometry.min_height = DEFAULT_MINIMAL_WINDOW_SIZE; |
9 | 1196 geometry.base_width = COLLECT_DEF_WIDTH; |
1197 geometry.base_height = COLLECT_DEF_HEIGHT; | |
1198 gtk_window_set_geometry_hints(GTK_WINDOW(cw->window), NULL, &geometry, | |
1199 GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); | |
1200 | |
1201 | |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
318
diff
changeset
|
1202 if (options->layout.save_window_positions && path && collection_load_only_geometry(cw->cd, path)) |
9 | 1203 { |
1204 /* FIXME: x, y is not implemented */ | |
1205 gtk_window_set_default_size(GTK_WINDOW(cw->window), cw->cd->window_w, cw->cd->window_h); | |
1206 } | |
1207 else | |
1208 { | |
1209 gtk_window_set_default_size(GTK_WINDOW(cw->window), COLLECT_DEF_WIDTH, COLLECT_DEF_HEIGHT); | |
1210 } | |
1211 | |
1212 gtk_window_set_resizable(GTK_WINDOW(cw->window), TRUE); | |
1213 collection_window_update_title(cw); | |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
1214 gtk_container_set_border_width(GTK_CONTAINER(cw->window), 0); |
9 | 1215 |
1216 g_signal_connect(G_OBJECT(cw->window), "delete_event", | |
1217 G_CALLBACK(collection_window_delete), cw); | |
1218 | |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
1219 g_signal_connect(G_OBJECT(cw->window), "key_press_event", |
9 | 1220 G_CALLBACK(collection_window_keypress), cw); |
1221 | |
1222 vbox = gtk_vbox_new(FALSE, 0); | |
1223 gtk_container_add(GTK_CONTAINER(cw->window), vbox); | |
1224 gtk_widget_show(vbox); | |
1225 | |
1226 cw->table = collection_table_new(cw->cd); | |
1227 gtk_box_pack_start(GTK_BOX(vbox), cw->table->scrolled, TRUE, TRUE, 0); | |
1228 gtk_widget_show(cw->table->scrolled); | |
1229 | |
1230 cw->status_box = gtk_hbox_new(TRUE, 0); | |
1231 gtk_box_pack_start(GTK_BOX(vbox), cw->status_box, FALSE, FALSE, 0); | |
1232 gtk_widget_show(cw->status_box); | |
1233 | |
1234 frame = gtk_frame_new(NULL); | |
1235 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
1236 gtk_box_pack_start(GTK_BOX(cw->status_box), frame, TRUE, TRUE, 0); | |
1237 gtk_widget_show(frame); | |
1238 | |
1239 status_label = gtk_label_new(""); | |
1240 gtk_container_add(GTK_CONTAINER(frame), status_label); | |
1241 gtk_widget_show(status_label); | |
1242 | |
1243 extra_label = gtk_progress_bar_new(); | |
1244 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(extra_label), 0.0); | |
1245 gtk_box_pack_start(GTK_BOX(cw->status_box), extra_label, TRUE, TRUE, 0); | |
1246 gtk_widget_show(extra_label); | |
1247 | |
1248 collection_table_set_labels(cw->table, status_label, extra_label); | |
1249 | |
1250 gtk_widget_show(cw->window); | |
1251 gtk_widget_grab_focus(cw->table->listview); | |
1252 | |
1253 collection_set_update_info_func(cw->cd, collection_window_update_info, cw); | |
1254 | |
726 | 1255 if (path && *path == G_DIR_SEPARATOR) collection_load_begin(cw->cd, NULL, COLLECTION_LOAD_NONE); |
9 | 1256 |
1257 return cw; | |
1258 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1029
diff
changeset
|
1259 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |