Mercurial > hg > forks > geeqie
annotate src/collect.c @ 2878:8b1c451c8ff2
Additional remote commands
--get-filelist:[<FOLDER>] Get list of files and class
--get-filelist-recurse:[<FOLDER>] Get list of files and class recursive
--get-collection:<COLLECTION> Get collection content
--get-collection-list Get list of collections
Changed command:
--tell Print filename of current image [and Collection, if collection
being displayed]
author | Colin Clark <colin.clark@cclark.uk> |
---|---|
date | Fri, 04 Jan 2019 13:44:58 +0000 |
parents | b20a96b979a3 |
children | 2e7fd08bfbe4 |
rev | line source |
---|---|
9 | 1 /* |
2350
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
2 * Copyright (C) 2006 John Ellis |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
3 * Copyright (C) 2008 - 2016 The Geeqie Team |
9 | 4 * |
5 * Author: John Ellis | |
6 * | |
2350
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
7 * This program is free software; you can redistribute it and/or modify |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
10 * (at your option) any later version. |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
11 * |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
15 * GNU General Public License for more details. |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
16 * |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
17 * You should have received a copy of the GNU General Public License along |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
18 * with this program; if not, write to the Free Software Foundation, Inc., |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2274
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
9 | 20 */ |
21 | |
281 | 22 #include "main.h" |
9 | 23 #include "collect.h" |
24 | |
25 #include "collect-dlg.h" | |
26 #include "collect-io.h" | |
27 #include "collect-table.h" | |
28 #include "editors.h" | |
586
122fc2223b42
split filelist.c to filefilter.c and filedata.c
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
516
diff
changeset
|
29 #include "filedata.h" |
9 | 30 #include "img-view.h" |
31 #include "layout.h" | |
32 #include "layout_image.h" | |
2694 | 33 #include "layout_util.h" |
1022
d09059a8b243
Move miscellaneous functions to their own files (new misc.[ch]).
Laurent Monin <geeqie@norz.org>
parents:
816
diff
changeset
|
34 #include "misc.h" |
91
d6b6f5cfa048
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
85
diff
changeset
|
35 #include "pixbuf_util.h" |
94
7bd3d907ca2b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
91
diff
changeset
|
36 #include "print.h" |
9 | 37 #include "ui_fileops.h" |
38 #include "ui_tree_edit.h" | |
1022
d09059a8b243
Move miscellaneous functions to their own files (new misc.[ch]).
Laurent Monin <geeqie@norz.org>
parents:
816
diff
changeset
|
39 #include "utilops.h" |
648
36e8da5a771d
Move some functions from main.[ch] to new window.[ch].
Laurent Monin <geeqie@norz.org>
parents:
586
diff
changeset
|
40 #include "window.h" |
9 | 41 |
42 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
43 | |
44 | |
45 #define COLLECT_DEF_WIDTH 440 | |
46 #define COLLECT_DEF_HEIGHT 450 | |
47 | |
2583
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
48 /** |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
49 * list of paths to collections */ |
2582
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
50 |
2583
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
51 /** |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
52 * @brief List of currently open Collections. |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
53 * |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
54 * Type ::_CollectionData |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
55 */ |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
56 static GList *collection_list = NULL; |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
57 |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
58 /** |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
59 * @brief List of currently open Collection windows. |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
60 * |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
61 * Type ::_CollectWindow |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
62 */ |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
63 static GList *collection_window_list = NULL; |
9 | 64 |
65 static void collection_window_get_geometry(CollectWindow *cw); | |
66 static void collection_window_refresh(CollectWindow *cw); | |
67 static void collection_window_update_title(CollectWindow *cw); | |
68 static void collection_window_add(CollectWindow *cw, CollectInfo *ci); | |
69 static void collection_window_insert(CollectWindow *cw, CollectInfo *ci); | |
70 static void collection_window_remove(CollectWindow *cw, CollectInfo *ci); | |
71 static void collection_window_update(CollectWindow *cw, CollectInfo *ci); | |
72 | |
73 static void collection_window_close(CollectWindow *cw); | |
74 | |
799
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
75 static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data); |
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
76 |
9 | 77 /* |
78 *------------------------------------------------------------------- | |
79 * data, list handling | |
80 *------------------------------------------------------------------- | |
81 */ | |
82 | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
83 CollectInfo *collection_info_new(FileData *fd, struct stat *st, GdkPixbuf *pixbuf) |
9 | 84 { |
85 CollectInfo *ci; | |
86 | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
87 if (!fd) return NULL; |
9 | 88 |
89 ci = g_new0(CollectInfo, 1); | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
90 ci->fd = file_data_ref(fd); |
9 | 91 |
92 ci->pixbuf = pixbuf; | |
93 if (ci->pixbuf) g_object_ref(ci->pixbuf); | |
94 | |
95 return ci; | |
96 } | |
97 | |
98 void collection_info_free_thumb(CollectInfo *ci) | |
99 { | |
100 if (ci->pixbuf) g_object_unref(ci->pixbuf); | |
101 ci->pixbuf = NULL; | |
102 } | |
103 | |
104 void collection_info_free(CollectInfo *ci) | |
105 { | |
106 if (!ci) return; | |
107 | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
108 file_data_unref(ci->fd); |
9 | 109 collection_info_free_thumb(ci); |
110 g_free(ci); | |
111 } | |
112 | |
113 void collection_info_set_thumb(CollectInfo *ci, GdkPixbuf *pixbuf) | |
114 { | |
115 if (pixbuf) g_object_ref(pixbuf); | |
116 collection_info_free_thumb(ci); | |
117 ci->pixbuf = pixbuf; | |
118 } | |
119 | |
1420
6cda3d9d6a7b
Use gboolean where applicable, for the sake of consistency.
Laurent Monin <geeqie@norz.org>
parents:
1367
diff
changeset
|
120 gboolean collection_info_load_thumb(CollectInfo *ci) |
9 | 121 { |
122 if (!ci) return FALSE; | |
123 | |
124 collection_info_free_thumb(ci); | |
125 | |
673
c9c2bc042e10
Do not use printf() directly but use new wrapper function log_printf() instead.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
126 log_printf("collection_info_load_thumb not implemented!\n(because an instant thumb loader not implemented)"); |
9 | 127 return FALSE; |
128 } | |
129 | |
130 void collection_list_free(GList *list) | |
131 { | |
132 GList *work; | |
133 work = list; | |
516
768d10237b88
Convert the minority of while() to while ().
Laurent Monin <geeqie@norz.org>
parents:
513
diff
changeset
|
134 while (work) |
9 | 135 { |
136 collection_info_free((CollectInfo *)work->data); | |
137 work = work->next; | |
138 } | |
139 g_list_free(list); | |
140 } | |
141 | |
142 /* an ugly static var, well what ya gonna do ? */ | |
143 static SortType collection_list_sort_method = SORT_NAME; | |
144 | |
145 static gint collection_list_sort_cb(gconstpointer a, gconstpointer b) | |
146 { | |
147 const CollectInfo *cia = a; | |
148 const CollectInfo *cib = b; | |
149 | |
1347
84d289bde1ea
Add missing space between switch and first parenthesis.
Laurent Monin <geeqie@norz.org>
parents:
1292
diff
changeset
|
150 switch (collection_list_sort_method) |
9 | 151 { |
785
9c54f243c2c6
Use uft8_collate_key() to sort utf8 strings.
Laurent Monin <geeqie@norz.org>
parents:
753
diff
changeset
|
152 case SORT_NAME: |
9c54f243c2c6
Use uft8_collate_key() to sort utf8 strings.
Laurent Monin <geeqie@norz.org>
parents:
753
diff
changeset
|
153 break; |
9 | 154 case SORT_NONE: |
155 return 0; | |
156 break; | |
157 case SORT_SIZE: | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
158 if (cia->fd->size < cib->fd->size) return -1; |
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
159 if (cia->fd->size > cib->fd->size) return 1; |
9 | 160 return 0; |
161 break; | |
162 case SORT_TIME: | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
163 if (cia->fd->date < cib->fd->date) return -1; |
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
164 if (cia->fd->date > cib->fd->date) return 1; |
9 | 165 return 0; |
166 break; | |
2274
046675ca4d54
Applying that sort method also to collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2233
diff
changeset
|
167 case SORT_CTIME: |
046675ca4d54
Applying that sort method also to collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2233
diff
changeset
|
168 if (cia->fd->cdate < cib->fd->cdate) return -1; |
046675ca4d54
Applying that sort method also to collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2233
diff
changeset
|
169 if (cia->fd->cdate > cib->fd->cdate) return 1; |
046675ca4d54
Applying that sort method also to collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2233
diff
changeset
|
170 return 0; |
046675ca4d54
Applying that sort method also to collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2233
diff
changeset
|
171 break; |
2698
940f217da9ec
Sort/search on Exif.Photo.DateTimeDigitized
Colin Clark <colin.clark@cclark.uk>
parents:
2696
diff
changeset
|
172 case SORT_EXIFTIME: |
940f217da9ec
Sort/search on Exif.Photo.DateTimeDigitized
Colin Clark <colin.clark@cclark.uk>
parents:
2696
diff
changeset
|
173 if (cia->fd->exifdate < cib->fd->exifdate) return -1; |
940f217da9ec
Sort/search on Exif.Photo.DateTimeDigitized
Colin Clark <colin.clark@cclark.uk>
parents:
2696
diff
changeset
|
174 if (cia->fd->exifdate > cib->fd->exifdate) return 1; |
940f217da9ec
Sort/search on Exif.Photo.DateTimeDigitized
Colin Clark <colin.clark@cclark.uk>
parents:
2696
diff
changeset
|
175 break; |
940f217da9ec
Sort/search on Exif.Photo.DateTimeDigitized
Colin Clark <colin.clark@cclark.uk>
parents:
2696
diff
changeset
|
176 case SORT_EXIFTIMEDIGITIZED: |
940f217da9ec
Sort/search on Exif.Photo.DateTimeDigitized
Colin Clark <colin.clark@cclark.uk>
parents:
2696
diff
changeset
|
177 if (cia->fd->exifdate_digitized < cib->fd->exifdate_digitized) return -1; |
940f217da9ec
Sort/search on Exif.Photo.DateTimeDigitized
Colin Clark <colin.clark@cclark.uk>
parents:
2696
diff
changeset
|
178 if (cia->fd->exifdate_digitized > cib->fd->exifdate_digitized) return 1; |
940f217da9ec
Sort/search on Exif.Photo.DateTimeDigitized
Colin Clark <colin.clark@cclark.uk>
parents:
2696
diff
changeset
|
179 break; |
940f217da9ec
Sort/search on Exif.Photo.DateTimeDigitized
Colin Clark <colin.clark@cclark.uk>
parents:
2696
diff
changeset
|
180 case SORT_RATING: |
940f217da9ec
Sort/search on Exif.Photo.DateTimeDigitized
Colin Clark <colin.clark@cclark.uk>
parents:
2696
diff
changeset
|
181 if (cia->fd->rating < cib->fd->rating) return -1; |
940f217da9ec
Sort/search on Exif.Photo.DateTimeDigitized
Colin Clark <colin.clark@cclark.uk>
parents:
2696
diff
changeset
|
182 if (cia->fd->rating > cib->fd->rating) return 1; |
940f217da9ec
Sort/search on Exif.Photo.DateTimeDigitized
Colin Clark <colin.clark@cclark.uk>
parents:
2696
diff
changeset
|
183 break; |
9 | 184 case SORT_PATH: |
786
cdcd3668e870
Compare paths using utf8_collate_key() since paths are utf8-encoded.
Laurent Monin <geeqie@norz.org>
parents:
785
diff
changeset
|
185 return utf8_compare(cia->fd->path, cib->fd->path, options->file_sort.case_sensitive); |
9 | 186 break; |
2696
f090fbf9362f
Sort/search on file class
Colin Clark <colin.clark@cclark.uk>
parents:
2694
diff
changeset
|
187 case SORT_CLASS: |
f090fbf9362f
Sort/search on file class
Colin Clark <colin.clark@cclark.uk>
parents:
2694
diff
changeset
|
188 if (cia->fd->format_class < cib->fd->format_class) return -1; |
f090fbf9362f
Sort/search on file class
Colin Clark <colin.clark@cclark.uk>
parents:
2694
diff
changeset
|
189 if (cia->fd->format_class > cib->fd->format_class) return 1; |
f090fbf9362f
Sort/search on file class
Colin Clark <colin.clark@cclark.uk>
parents:
2694
diff
changeset
|
190 break; |
9 | 191 #ifdef HAVE_STRVERSCMP |
192 case SORT_NUMBER: | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
193 return strverscmp(cia->fd->name, cib->fd->name); |
9 | 194 break; |
195 #endif | |
196 default: | |
197 break; | |
198 } | |
199 | |
785
9c54f243c2c6
Use uft8_collate_key() to sort utf8 strings.
Laurent Monin <geeqie@norz.org>
parents:
753
diff
changeset
|
200 if (options->file_sort.case_sensitive) |
9c54f243c2c6
Use uft8_collate_key() to sort utf8 strings.
Laurent Monin <geeqie@norz.org>
parents:
753
diff
changeset
|
201 return strcmp(cia->fd->collate_key_name, cib->fd->collate_key_name); |
9c54f243c2c6
Use uft8_collate_key() to sort utf8 strings.
Laurent Monin <geeqie@norz.org>
parents:
753
diff
changeset
|
202 else |
9c54f243c2c6
Use uft8_collate_key() to sort utf8 strings.
Laurent Monin <geeqie@norz.org>
parents:
753
diff
changeset
|
203 return strcmp(cia->fd->collate_key_name_nocase, cib->fd->collate_key_name_nocase); |
9 | 204 } |
205 | |
206 GList *collection_list_sort(GList *list, SortType method) | |
207 { | |
208 if (method == SORT_NONE) return list; | |
209 | |
210 collection_list_sort_method = method; | |
211 | |
212 return g_list_sort(list, collection_list_sort_cb); | |
213 } | |
214 | |
1535
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
215 GList *collection_list_randomize(GList *list) |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
216 { |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
217 guint random, length, i; |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
218 gpointer tmp; |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
219 GList *nlist, *olist; |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
220 |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
221 length = g_list_length(list); |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
222 if (!length) return NULL; |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
223 |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
224 srand((unsigned int)time(NULL)); // Initialize random generator (hasn't to be that much strong) |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
225 |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
226 for (i = 0; i < length; i++) |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
227 { |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
228 random = (guint) (1.0 * length * rand()/(RAND_MAX + 1.0)); |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
229 olist = g_list_nth(list, i); |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
230 nlist = g_list_nth(list, random); |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
231 tmp = olist->data; |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
232 olist->data = nlist->data; |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
233 nlist->data = tmp; |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
234 } |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
235 |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
236 return list; |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
237 } |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
238 |
9 | 239 GList *collection_list_add(GList *list, CollectInfo *ci, SortType method) |
240 { | |
241 if (method != SORT_NONE) | |
242 { | |
243 collection_list_sort_method = method; | |
244 list = g_list_insert_sorted(list, ci, collection_list_sort_cb); | |
245 } | |
246 else | |
247 { | |
248 list = g_list_append(list, ci); | |
249 } | |
250 | |
251 return list; | |
252 } | |
253 | |
254 GList *collection_list_insert(GList *list, CollectInfo *ci, CollectInfo *insert_ci, SortType method) | |
255 { | |
256 if (method != SORT_NONE) | |
257 { | |
258 collection_list_sort_method = method; | |
259 list = g_list_insert_sorted(list, ci, collection_list_sort_cb); | |
260 } | |
261 else | |
262 { | |
263 GList *point; | |
264 | |
265 point = g_list_find(list, insert_ci); | |
266 list = uig_list_insert_link(list, point, ci); | |
267 } | |
268 | |
269 return list; | |
270 } | |
271 | |
272 GList *collection_list_remove(GList *list, CollectInfo *ci) | |
273 { | |
274 list = g_list_remove(list, ci); | |
275 collection_info_free(ci); | |
276 return list; | |
277 } | |
278 | |
799
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
279 CollectInfo *collection_list_find_fd(GList *list, FileData *fd) |
9 | 280 { |
281 GList *work = list; | |
282 | |
516
768d10237b88
Convert the minority of while() to while ().
Laurent Monin <geeqie@norz.org>
parents:
513
diff
changeset
|
283 while (work) |
9 | 284 { |
285 CollectInfo *ci = work->data; | |
799
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
286 if (ci->fd == fd) return ci; |
9 | 287 work = work->next; |
288 } | |
289 | |
290 return NULL; | |
291 } | |
292 | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
293 GList *collection_list_to_filelist(GList *list) |
9 | 294 { |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
295 GList *filelist = NULL; |
9 | 296 GList *work = list; |
297 | |
298 while (work) | |
299 { | |
300 CollectInfo *info = work->data; | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
301 filelist = g_list_prepend(filelist, file_data_ref(info->fd)); |
9 | 302 work = work->next; |
303 } | |
304 | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
305 filelist = g_list_reverse(filelist); |
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
306 return filelist; |
9 | 307 } |
308 | |
309 CollectWindow *collection_window_find(CollectionData *cd) | |
310 { | |
311 GList *work; | |
312 | |
313 work = collection_window_list; | |
314 while (work) | |
315 { | |
316 CollectWindow *cw = work->data; | |
317 if (cw->cd == cd) return cw; | |
318 work = work->next; | |
319 } | |
320 | |
321 return NULL; | |
322 } | |
323 | |
324 CollectWindow *collection_window_find_by_path(const gchar *path) | |
325 { | |
326 GList *work; | |
327 | |
328 if (!path) return NULL; | |
329 | |
330 work = collection_window_list; | |
331 while (work) | |
332 { | |
333 CollectWindow *cw = work->data; | |
334 if (cw->cd->path && strcmp(cw->cd->path, path) == 0) return cw; | |
335 work = work->next; | |
336 } | |
337 | |
338 return NULL; | |
339 } | |
340 | |
2583
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
341 /** |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
342 * @brief Checks string for existence of Collection. |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
343 * @param[in] param Filename, with or without extension of any collection |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
344 * @returns full pathname if found or NULL |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
345 * |
2582
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
346 * Return value must be freed with g_free() |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
347 */ |
2878
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
348 gchar *collection_path(const gchar *param) |
2582
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
349 { |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
350 gchar *path = NULL; |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
351 gchar *full_name = NULL; |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
352 |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
353 if (file_extension_match(param, GQ_COLLECTION_EXT)) |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
354 { |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
355 path = g_build_filename(get_collections_dir(), param, NULL); |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
356 } |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
357 else if (file_extension_match(param, NULL)) |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
358 { |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
359 full_name = g_strconcat(param, GQ_COLLECTION_EXT, NULL); |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
360 path = g_build_filename(get_collections_dir(), full_name, NULL); |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
361 } |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
362 |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
363 if (!isfile(path)) |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
364 { |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
365 g_free(path); |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
366 path = NULL; |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
367 } |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
368 |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
369 g_free(full_name); |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
370 return path; |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
371 } |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
372 |
2583
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
373 /** |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
374 * @brief Checks input string for existence of Collection. |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
375 * @param[in] param Filename with or without extension of any collection |
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
376 * @returns TRUE if found |
2582
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
377 * |
2583
6e92c0ad76f2
Change recent code comments to Doxygen style
Colin Clark <colin.clark@cclark.uk>
parents:
2582
diff
changeset
|
378 * |
2582
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
379 */ |
2878
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
380 gboolean is_collection(const gchar *param) |
2582
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
381 { |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
382 gchar *name = NULL; |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
383 |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
384 name = collection_path(param); |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
385 if (name) |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
386 { |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
387 g_free(name); |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
388 return TRUE; |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
389 } |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
390 return FALSE; |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
391 } |
03014a1eb7e7
Right-click menus - collections
Colin Clark <colin.clark@cclark.uk>
parents:
2581
diff
changeset
|
392 |
2878
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
393 /** |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
394 * @brief Creates a text list of the image paths of the contents of a Collection |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
395 * @param[in] name The name of the collection, with or wihout extension |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
396 * @param[inout] contents A GString to which the image paths are appended |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
397 * |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
398 * |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
399 */ |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
400 void collection_contents(const gchar *name, GString **contents) |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
401 { |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
402 gchar *path; |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
403 CollectionData *cd; |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
404 CollectInfo *ci; |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
405 GList *work; |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
406 FileData *fd; |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
407 |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
408 if (is_collection(name)) |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
409 { |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
410 path = collection_path(name); |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
411 cd = collection_new(""); |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
412 collection_load(cd, path, COLLECTION_LOAD_APPEND); |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
413 work = cd->list; |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
414 while (work) |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
415 { |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
416 ci = work->data; |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
417 fd = ci->fd; |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
418 *contents = g_string_append(*contents, g_strdup(fd->path)); |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
419 *contents = g_string_append(*contents, "\n"); |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
420 |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
421 work = work->next; |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
422 } |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
423 g_free(path); |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
424 collection_free(cd); |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
425 } |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
426 } |
8b1c451c8ff2
Additional remote commands
Colin Clark <colin.clark@cclark.uk>
parents:
2860
diff
changeset
|
427 |
9 | 428 /* |
429 *------------------------------------------------------------------- | |
430 * please use these to actually add/remove stuff | |
431 *------------------------------------------------------------------- | |
432 */ | |
433 | |
434 CollectionData *collection_new(const gchar *path) | |
435 { | |
436 CollectionData *cd; | |
437 static gint untitled_counter = 0; | |
438 | |
439 cd = g_new0(CollectionData, 1); | |
440 | |
441 cd->ref = 1; /* starts with a ref of 1 */ | |
442 cd->sort_method = SORT_NONE; | |
443 cd->window_w = COLLECT_DEF_WIDTH; | |
444 cd->window_h = COLLECT_DEF_HEIGHT; | |
303
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
445 cd->existence = g_hash_table_new(NULL, NULL); |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
446 |
9 | 447 if (path) |
448 { | |
449 cd->path = g_strdup(path); | |
450 cd->name = g_strdup(filename_from_path(cd->path)); | |
451 /* load it */ | |
452 } | |
453 else | |
454 { | |
455 if (untitled_counter == 0) | |
456 { | |
457 cd->name = g_strdup(_("Untitled")); | |
458 } | |
459 else | |
460 { | |
461 cd->name = g_strdup_printf(_("Untitled (%d)"), untitled_counter + 1); | |
462 } | |
463 | |
464 untitled_counter++; | |
465 } | |
466 | |
799
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
467 file_data_register_notify_func(collection_notify_cb, cd, NOTIFY_PRIORITY_MEDIUM); |
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
468 |
1367
625746ed03d8
When g_new0() is used, drop redundant initializations to NULL, FALSE or 0, second pass.
Laurent Monin <geeqie@norz.org>
parents:
1347
diff
changeset
|
469 |
625746ed03d8
When g_new0() is used, drop redundant initializations to NULL, FALSE or 0, second pass.
Laurent Monin <geeqie@norz.org>
parents:
1347
diff
changeset
|
470 collection_list = g_list_append(collection_list, cd); |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2151
diff
changeset
|
471 |
9 | 472 return cd; |
473 } | |
474 | |
475 void collection_free(CollectionData *cd) | |
476 { | |
477 if (!cd) return; | |
478 | |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
479 DEBUG_1("collection \"%s\" freed", cd->name); |
9 | 480 |
481 collection_load_stop(cd); | |
482 collection_list_free(cd->list); | |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2151
diff
changeset
|
483 |
799
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
484 file_data_unregister_notify_func(collection_notify_cb, cd); |
9 | 485 |
486 collection_list = g_list_remove(collection_list, cd); | |
487 | |
303
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
488 g_hash_table_destroy(cd->existence); |
442 | 489 |
9 | 490 g_free(cd->path); |
491 g_free(cd->name); | |
492 | |
493 g_free(cd); | |
494 } | |
495 | |
496 void collection_ref(CollectionData *cd) | |
497 { | |
498 cd->ref++; | |
499 | |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
500 DEBUG_1("collection \"%s\" ref count = %d", cd->name, cd->ref); |
9 | 501 } |
502 | |
503 void collection_unref(CollectionData *cd) | |
504 { | |
505 cd->ref--; | |
506 | |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
507 DEBUG_1("collection \"%s\" ref count = %d", cd->name, cd->ref); |
9 | 508 |
509 if (cd->ref < 1) | |
510 { | |
511 collection_free(cd); | |
512 } | |
513 } | |
514 | |
515 void collection_path_changed(CollectionData *cd) | |
516 { | |
517 collection_window_update_title(collection_window_find(cd)); | |
518 } | |
519 | |
520 gint collection_to_number(CollectionData *cd) | |
521 { | |
522 return g_list_index(collection_list, cd); | |
523 } | |
524 | |
525 CollectionData *collection_from_number(gint n) | |
526 { | |
527 return g_list_nth_data(collection_list, n); | |
528 } | |
529 | |
530 CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList **info_list) | |
531 { | |
532 CollectionData *cd; | |
816
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
533 gint collection_number; |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
534 const gchar *ptr; |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
535 |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
536 if (list) *list = NULL; |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
537 if (info_list) *info_list = NULL; |
9 | 538 |
539 if (strncmp(data, "COLLECTION:", 11) != 0) return NULL; | |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2151
diff
changeset
|
540 |
816
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
541 ptr = data + 11; |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2151
diff
changeset
|
542 |
816
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
543 collection_number = atoi(ptr); |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
544 cd = collection_from_number(collection_number); |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
545 if (!cd) return NULL; |
9 | 546 |
816
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
547 if (!list && !info_list) return cd; |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2151
diff
changeset
|
548 |
816
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
549 while (*ptr != '\0' && *ptr != '\n' ) ptr++; |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
550 if (*ptr == '\0') return cd; |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
551 ptr++; |
9 | 552 |
816
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
553 while (*ptr != '\0') |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
554 { |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
555 guint item_number; |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
556 CollectInfo *info; |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2151
diff
changeset
|
557 |
816
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
558 item_number = (guint) atoi(ptr); |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
559 while (*ptr != '\n' && *ptr != '\0') ptr++; |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
560 if (*ptr == '\0') |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
561 break; |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
562 else |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
563 while (*ptr == '\n') ptr++; |
9 | 564 |
816
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
565 info = g_list_nth_data(cd->list, item_number); |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
566 if (!info) continue; |
9 | 567 |
816
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
568 if (list) *list = g_list_append(*list, file_data_ref(info->fd)); |
dac96224a5e0
collection_from_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
815
diff
changeset
|
569 if (info_list) *info_list = g_list_append(*info_list, info); |
9 | 570 } |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2151
diff
changeset
|
571 |
9 | 572 return cd; |
573 } | |
574 | |
575 gchar *collection_info_list_to_dnd_data(CollectionData *cd, GList *list, gint *length) | |
576 { | |
577 GList *work; | |
815
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
578 GList *temp = NULL; |
9 | 579 gchar *ptr; |
815
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
580 gchar *text; |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
581 gchar *uri_text; |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
582 gint collection_number; |
9 | 583 |
815
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
584 *length = 0; |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
585 if (!list) return NULL; |
9 | 586 |
815
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
587 collection_number = collection_to_number(cd); |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
588 if (collection_number < 0) return NULL; |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
589 |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
590 text = g_strdup_printf("COLLECTION:%d\n", collection_number); |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
591 *length += strlen(text); |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
592 temp = g_list_prepend(temp, text); |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
593 |
9 | 594 work = list; |
516
768d10237b88
Convert the minority of while() to while ().
Laurent Monin <geeqie@norz.org>
parents:
513
diff
changeset
|
595 while (work) |
9 | 596 { |
815
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
597 gint item_number = g_list_index(cd->list, work->data); |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
598 |
9 | 599 work = work->next; |
815
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
600 |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
601 if (item_number < 0) continue; |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2151
diff
changeset
|
602 |
815
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
603 text = g_strdup_printf("%d\n", item_number); |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
604 temp = g_list_prepend(temp, text); |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
605 *length += strlen(text); |
9 | 606 } |
607 | |
815
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
608 *length += 1; /* ending nul char */ |
9 | 609 |
815
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
610 uri_text = g_malloc(*length); |
9 | 611 ptr = uri_text; |
612 | |
613 work = g_list_last(temp); | |
516
768d10237b88
Convert the minority of while() to while ().
Laurent Monin <geeqie@norz.org>
parents:
513
diff
changeset
|
614 while (work) |
9 | 615 { |
815
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
616 gint len; |
9 | 617 gchar *text = work->data; |
618 | |
619 work = work->prev; | |
620 | |
815
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
621 len = strlen(text); |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
622 memcpy(ptr, text, len); |
392ef0ab0370
collection_info_list_to_dnd_data(): simplify and optimize.
Laurent Monin <geeqie@norz.org>
parents:
803
diff
changeset
|
623 ptr += len; |
9 | 624 } |
625 | |
626 ptr[0] = '\0'; | |
627 | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
628 string_list_free(temp); |
9 | 629 |
630 return uri_text; | |
631 } | |
632 | |
633 gint collection_info_valid(CollectionData *cd, CollectInfo *info) | |
634 { | |
635 if (collection_to_number(cd) < 0) return FALSE; | |
636 | |
637 return (g_list_index(cd->list, info) != 0); | |
638 } | |
639 | |
640 CollectInfo *collection_next_by_info(CollectionData *cd, CollectInfo *info) | |
641 { | |
642 GList *work; | |
643 | |
644 work = g_list_find(cd->list, info); | |
645 | |
646 if (!work) return NULL; | |
647 work = work->next; | |
648 if (work) return work->data; | |
649 return NULL; | |
650 } | |
651 | |
652 CollectInfo *collection_prev_by_info(CollectionData *cd, CollectInfo *info) | |
653 { | |
654 GList *work; | |
655 | |
656 work = g_list_find(cd->list, info); | |
657 | |
658 if (!work) return NULL; | |
659 work = work->prev; | |
660 if (work) return work->data; | |
661 return NULL; | |
662 } | |
663 | |
664 CollectInfo *collection_get_first(CollectionData *cd) | |
665 { | |
666 if (cd->list) return cd->list->data; | |
667 | |
668 return NULL; | |
669 } | |
670 | |
671 CollectInfo *collection_get_last(CollectionData *cd) | |
672 { | |
673 GList *list; | |
674 | |
675 list = g_list_last(cd->list); | |
676 | |
677 if (list) return list->data; | |
678 | |
679 return NULL; | |
680 } | |
681 | |
682 void collection_set_sort_method(CollectionData *cd, SortType method) | |
683 { | |
684 if (!cd) return; | |
685 | |
686 if (cd->sort_method == method) return; | |
687 | |
688 cd->sort_method = method; | |
689 cd->list = collection_list_sort(cd->list, cd->sort_method); | |
690 if (cd->list) cd->changed = TRUE; | |
691 | |
692 collection_window_refresh(collection_window_find(cd)); | |
693 } | |
694 | |
1535
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
695 void collection_randomize(CollectionData *cd) |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
696 { |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
697 if (!cd) return; |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
698 |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
699 cd->list = collection_list_randomize(cd->list); |
1536
ed00c47adf06
Just update the internal sort method
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1535
diff
changeset
|
700 cd->sort_method = SORT_NONE; |
1535
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
701 if (cd->list) cd->changed = TRUE; |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
702 |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
703 collection_window_refresh(collection_window_find(cd)); |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
704 } |
4be0a5710458
Implement random sort method for collections
Klaus Ethgen <Klaus@Ethgen.de>
parents:
1498
diff
changeset
|
705 |
9 | 706 void collection_set_update_info_func(CollectionData *cd, |
707 void (*func)(CollectionData *, CollectInfo *, gpointer), gpointer data) | |
708 { | |
709 cd->info_updated_func = func; | |
710 cd->info_updated_data = data; | |
711 } | |
712 | |
303
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
713 static CollectInfo *collection_info_new_if_not_exists(CollectionData *cd, struct stat *st, FileData *fd) |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
714 { |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
715 CollectInfo *ci; |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
716 |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
717 if (g_hash_table_lookup(cd->existence, fd->path)) return NULL; |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
718 |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
719 ci = collection_info_new(fd, st, NULL); |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
720 if (ci) g_hash_table_insert(cd->existence, fd->path, ""); |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
721 return ci; |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
722 } |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
723 |
1420
6cda3d9d6a7b
Use gboolean where applicable, for the sake of consistency.
Laurent Monin <geeqie@norz.org>
parents:
1367
diff
changeset
|
724 gboolean collection_add_check(CollectionData *cd, FileData *fd, gboolean sorted, gboolean must_exist) |
9 | 725 { |
726 struct stat st; | |
1420
6cda3d9d6a7b
Use gboolean where applicable, for the sake of consistency.
Laurent Monin <geeqie@norz.org>
parents:
1367
diff
changeset
|
727 gboolean valid; |
9 | 728 |
2233
083592055bcd
Fix crash when loading collection listing inexistent files.
Laurent Monin <zas@norz.org>
parents:
2185
diff
changeset
|
729 if (!fd) return FALSE; |
083592055bcd
Fix crash when loading collection listing inexistent files.
Laurent Monin <zas@norz.org>
parents:
2185
diff
changeset
|
730 |
083592055bcd
Fix crash when loading collection listing inexistent files.
Laurent Monin <zas@norz.org>
parents:
2185
diff
changeset
|
731 g_assert(fd->magick == FD_MAGICK); |
083592055bcd
Fix crash when loading collection listing inexistent files.
Laurent Monin <zas@norz.org>
parents:
2185
diff
changeset
|
732 |
9 | 733 if (must_exist) |
734 { | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
735 valid = (stat_utf8(fd->path, &st) && !S_ISDIR(st.st_mode)); |
9 | 736 } |
737 else | |
738 { | |
739 valid = TRUE; | |
740 st.st_size = 0; | |
741 st.st_mtime = 0; | |
742 } | |
743 | |
744 if (valid) | |
745 { | |
746 CollectInfo *ci; | |
303
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
747 |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
748 ci = collection_info_new_if_not_exists(cd, &st, fd); |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
749 if (!ci) return FALSE; |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
750 DEBUG_3("add to collection: %s", fd->path); |
303
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
751 |
9 | 752 cd->list = collection_list_add(cd->list, ci, sorted ? cd->sort_method : SORT_NONE); |
753 cd->changed = TRUE; | |
754 | |
755 if (!sorted || cd->sort_method == SORT_NONE) | |
756 { | |
757 collection_window_add(collection_window_find(cd), ci); | |
758 } | |
759 else | |
760 { | |
761 collection_window_insert(collection_window_find(cd), ci); | |
762 } | |
763 } | |
764 | |
765 return valid; | |
766 } | |
767 | |
1420
6cda3d9d6a7b
Use gboolean where applicable, for the sake of consistency.
Laurent Monin <geeqie@norz.org>
parents:
1367
diff
changeset
|
768 gboolean collection_add(CollectionData *cd, FileData *fd, gboolean sorted) |
9 | 769 { |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
770 return collection_add_check(cd, fd, sorted, TRUE); |
9 | 771 } |
772 | |
1420
6cda3d9d6a7b
Use gboolean where applicable, for the sake of consistency.
Laurent Monin <geeqie@norz.org>
parents:
1367
diff
changeset
|
773 gboolean collection_insert(CollectionData *cd, FileData *fd, CollectInfo *insert_ci, gboolean sorted) |
9 | 774 { |
775 struct stat st; | |
776 | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
777 if (!insert_ci) return collection_add(cd, fd, sorted); |
9 | 778 |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
779 if (stat_utf8(fd->path, &st) >= 0 && !S_ISDIR(st.st_mode)) |
9 | 780 { |
781 CollectInfo *ci; | |
303
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
782 |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
783 ci = collection_info_new_if_not_exists(cd, &st, fd); |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
784 if (!ci) return FALSE; |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
785 |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
786 DEBUG_3("insert in collection: %s", fd->path); |
303
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
787 |
9 | 788 cd->list = collection_list_insert(cd->list, ci, insert_ci, sorted ? cd->sort_method : SORT_NONE); |
789 cd->changed = TRUE; | |
790 | |
791 collection_window_insert(collection_window_find(cd), ci); | |
792 | |
793 return TRUE; | |
794 } | |
795 | |
796 return FALSE; | |
797 } | |
798 | |
1420
6cda3d9d6a7b
Use gboolean where applicable, for the sake of consistency.
Laurent Monin <geeqie@norz.org>
parents:
1367
diff
changeset
|
799 gboolean collection_remove(CollectionData *cd, FileData *fd) |
9 | 800 { |
801 CollectInfo *ci; | |
802 | |
799
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
803 ci = collection_list_find_fd(cd->list, fd); |
9 | 804 |
805 if (!ci) return FALSE; | |
806 | |
303
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
807 g_hash_table_remove(cd->existence, fd->path); |
dd8e3d1267cc
Prevent multiple insertion of the same file in a collection.
Laurent Monin <geeqie@norz.org>
parents:
289
diff
changeset
|
808 |
9 | 809 cd->list = g_list_remove(cd->list, ci); |
810 cd->changed = TRUE; | |
811 | |
812 collection_window_remove(collection_window_find(cd), ci); | |
813 collection_info_free(ci); | |
814 | |
815 return TRUE; | |
816 } | |
817 | |
818 static void collection_remove_by_info(CollectionData *cd, CollectInfo *info) | |
819 { | |
820 if (!info || !g_list_find(cd->list, info)) return; | |
821 | |
822 cd->list = g_list_remove(cd->list, info); | |
823 cd->changed = (cd->list != NULL); | |
824 | |
825 collection_window_remove(collection_window_find(cd), info); | |
826 collection_info_free(info); | |
827 } | |
828 | |
829 void collection_remove_by_info_list(CollectionData *cd, GList *list) | |
830 { | |
831 GList *work; | |
832 | |
833 if (!list) return; | |
834 | |
835 if (!list->next) | |
836 { | |
837 /* more efficient (in collect-table) to remove a single item this way */ | |
838 collection_remove_by_info(cd, (CollectInfo *)list->data); | |
839 return; | |
840 } | |
841 | |
842 work = list; | |
516
768d10237b88
Convert the minority of while() to while ().
Laurent Monin <geeqie@norz.org>
parents:
513
diff
changeset
|
843 while (work) |
9 | 844 { |
845 cd->list = collection_list_remove(cd->list, work->data); | |
846 work = work->next; | |
847 } | |
848 cd->changed = (cd->list != NULL); | |
849 | |
850 collection_window_refresh(collection_window_find(cd)); | |
851 } | |
852 | |
1420
6cda3d9d6a7b
Use gboolean where applicable, for the sake of consistency.
Laurent Monin <geeqie@norz.org>
parents:
1367
diff
changeset
|
853 gboolean collection_rename(CollectionData *cd, FileData *fd) |
9 | 854 { |
855 CollectInfo *ci; | |
799
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
856 ci = collection_list_find_fd(cd->list, fd); |
9 | 857 |
858 if (!ci) return FALSE; | |
859 | |
860 cd->changed = TRUE; | |
861 | |
862 collection_window_update(collection_window_find(cd), ci); | |
863 | |
864 return TRUE; | |
865 } | |
866 | |
867 void collection_update_geometry(CollectionData *cd) | |
868 { | |
869 collection_window_get_geometry(collection_window_find(cd)); | |
870 } | |
871 | |
872 /* | |
873 *------------------------------------------------------------------- | |
874 * simple maintenance for renaming, deleting | |
875 *------------------------------------------------------------------- | |
876 */ | |
877 | |
799
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
878 static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data) |
9 | 879 { |
799
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
880 CollectionData *cd = data; |
9 | 881 |
1432
7f454e7d07a3
improved notification system
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1420
diff
changeset
|
882 if (!(type & NOTIFY_CHANGE) || !fd->change) return; |
1498
2b0712dcf139
improved debug messages
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1436
diff
changeset
|
883 |
2b0712dcf139
improved debug messages
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1436
diff
changeset
|
884 DEBUG_1("Notify collection: %s %04x", fd->path, type); |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2151
diff
changeset
|
885 |
1347
84d289bde1ea
Add missing space between switch and first parenthesis.
Laurent Monin <geeqie@norz.org>
parents:
1292
diff
changeset
|
886 switch (fd->change->type) |
9 | 887 { |
799
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
888 case FILEDATA_CHANGE_MOVE: |
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
889 case FILEDATA_CHANGE_RENAME: |
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
890 collection_rename(cd, fd); |
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
891 break; |
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
892 case FILEDATA_CHANGE_COPY: |
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
893 break; |
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
894 case FILEDATA_CHANGE_DELETE: |
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
895 while (collection_remove(cd, fd)); |
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
896 break; |
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
897 case FILEDATA_CHANGE_UNSPECIFIED: |
1211
cc4d3023ced3
most of the metadata options now works
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1176
diff
changeset
|
898 case FILEDATA_CHANGE_WRITE_METADATA: |
799
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
899 break; |
9 | 900 } |
799
e8085600fd69
use the new notification for collections
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
786
diff
changeset
|
901 |
9 | 902 } |
903 | |
904 | |
905 /* | |
906 *------------------------------------------------------------------- | |
907 * window key presses | |
908 *------------------------------------------------------------------- | |
909 */ | |
910 | |
1420
6cda3d9d6a7b
Use gboolean where applicable, for the sake of consistency.
Laurent Monin <geeqie@norz.org>
parents:
1367
diff
changeset
|
911 static gboolean collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data) |
9 | 912 { |
913 CollectWindow *cw = data; | |
1420
6cda3d9d6a7b
Use gboolean where applicable, for the sake of consistency.
Laurent Monin <geeqie@norz.org>
parents:
1367
diff
changeset
|
914 gboolean stop_signal = FALSE; |
9 | 915 GList *list; |
916 | |
917 if (event->state & GDK_CONTROL_MASK) | |
918 { | |
85
f5f7943f2f60
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
919 stop_signal = TRUE; |
9 | 920 switch (event->keyval) |
921 { | |
922 case '1': | |
923 case '2': | |
924 case '3': | |
925 case '4': | |
926 case '5': | |
927 case '6': | |
928 case '7': | |
929 case '8': | |
930 case '9': | |
931 case '0': | |
932 break; | |
933 case 'A': case 'a': | |
934 if (event->state & GDK_SHIFT_MASK) | |
935 { | |
936 collection_table_unselect_all(cw->table); | |
937 } | |
938 else | |
939 { | |
940 collection_table_select_all(cw->table); | |
941 } | |
942 break; | |
943 case 'L': case 'l': | |
944 list = layout_list(NULL); | |
945 if (list) | |
946 { | |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
947 collection_table_add_filelist(cw->table, list); |
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
948 filelist_free(list); |
9 | 949 } |
950 break; | |
951 case 'C': case 'c': | |
952 file_util_copy(NULL, collection_table_selection_get_list(cw->table), NULL, cw->window); | |
953 break; | |
954 case 'M': case 'm': | |
955 file_util_move(NULL, collection_table_selection_get_list(cw->table), NULL, cw->window); | |
956 break; | |
957 case 'R': case 'r': | |
958 file_util_rename(NULL, collection_table_selection_get_list(cw->table), cw->window); | |
959 break; | |
960 case 'D': case 'd': | |
2860
b20a96b979a3
Fix #437: Delete to standard Trash directory
Colin Clark <colin.clark@cclark.uk>
parents:
2793
diff
changeset
|
961 options->file_ops.safe_delete_enable = TRUE; |
9 | 962 file_util_delete(NULL, collection_table_selection_get_list(cw->table), cw->window); |
963 break; | |
964 case 'S': case 's': | |
965 collection_dialog_save_as(NULL, cw->cd); | |
966 break; | |
967 case 'W': case 'w': | |
968 collection_window_close(cw); | |
969 break; | |
970 default: | |
85
f5f7943f2f60
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
971 stop_signal = FALSE; |
9 | 972 break; |
973 } | |
974 } | |
975 else | |
976 { | |
85
f5f7943f2f60
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
977 stop_signal = TRUE; |
9 | 978 switch (event->keyval) |
979 { | |
2036
472c094c0154
changed GDK_<key> to GDK_KEY_<key>
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
2034
diff
changeset
|
980 case GDK_KEY_Return: case GDK_KEY_KP_Enter: |
9 | 981 layout_image_set_collection(NULL, cw->cd, |
982 collection_table_get_focus_info(cw->table)); | |
983 break; | |
984 case 'V': case 'v': | |
985 view_window_new_from_collection(cw->cd, | |
986 collection_table_get_focus_info(cw->table)); | |
987 break; | |
988 case 'S': case 's': | |
989 if (!cw->cd->path) | |
990 { | |
991 collection_dialog_save_as(NULL, cw->cd); | |
442 | 992 } |
9 | 993 else if (!collection_save(cw->cd, cw->cd->path)) |
994 { | |
673
c9c2bc042e10
Do not use printf() directly but use new wrapper function log_printf() instead.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
995 log_printf("failed saving to collection path: %s\n", cw->cd->path); |
9 | 996 } |
997 break; | |
998 case 'A': case 'a': | |
85
f5f7943f2f60
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
999 collection_dialog_append(NULL, cw->cd); |
9 | 1000 break; |
1001 case 'N': case 'n': | |
1002 collection_set_sort_method(cw->cd, SORT_NAME); | |
1003 break; | |
1004 #ifdef HAVE_STRVERSCMP | |
1005 case 'I': case 'i': | |
1006 collection_set_sort_method(cw->cd, SORT_NUMBER); | |
1007 break; | |
1008 #endif | |
1009 case 'D': case 'd': | |
1010 collection_set_sort_method(cw->cd, SORT_TIME); | |
1011 break; | |
1012 case 'B': case 'b': | |
1013 collection_set_sort_method(cw->cd, SORT_SIZE); | |
1014 break; | |
1015 case 'P': case 'p': | |
94
7bd3d907ca2b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
91
diff
changeset
|
1016 if (event->state & GDK_SHIFT_MASK) |
7bd3d907ca2b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
91
diff
changeset
|
1017 { |
7bd3d907ca2b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
91
diff
changeset
|
1018 CollectInfo *info; |
7bd3d907ca2b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
91
diff
changeset
|
1019 |
7bd3d907ca2b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
91
diff
changeset
|
1020 info = collection_table_get_focus_info(cw->table); |
7bd3d907ca2b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
91
diff
changeset
|
1021 |
138
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
1022 print_window_new(info->fd, collection_table_selection_get_list(cw->table), |
5be5d1c53016
replaced gchar* path with FileData *fd
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
94
diff
changeset
|
1023 collection_list_to_filelist(cw->cd->list), cw->window); |
94
7bd3d907ca2b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
91
diff
changeset
|
1024 } |
7bd3d907ca2b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
91
diff
changeset
|
1025 else |
7bd3d907ca2b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
91
diff
changeset
|
1026 { |
7bd3d907ca2b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
91
diff
changeset
|
1027 collection_set_sort_method(cw->cd, SORT_PATH); |
7bd3d907ca2b
Thu Nov 2 17:51:31 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
91
diff
changeset
|
1028 } |
9 | 1029 break; |
2423 | 1030 case 'R': case 'r': |
1031 if (event->state & GDK_MOD1_MASK) | |
1032 { | |
1033 options->collections.rectangular_selection = !(options->collections.rectangular_selection); | |
1034 } | |
1035 break; | |
2036
472c094c0154
changed GDK_<key> to GDK_KEY_<key>
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
2034
diff
changeset
|
1036 case GDK_KEY_Delete: case GDK_KEY_KP_Delete: |
9 | 1037 list = g_list_copy(cw->table->selection); |
1038 if (list) | |
1039 { | |
1040 collection_remove_by_info_list(cw->cd, list); | |
1041 g_list_free(list); | |
1042 } | |
1043 else | |
1044 { | |
1045 collection_remove_by_info(cw->cd, collection_table_get_focus_info(cw->table)); | |
1046 } | |
1047 break; | |
1048 default: | |
85
f5f7943f2f60
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
1049 stop_signal = FALSE; |
9 | 1050 break; |
1051 } | |
1052 } | |
2694 | 1053 if (!stop_signal && is_help_key(event)) |
1054 { | |
1055 help_window_show("GuideCollections.html"); | |
1056 stop_signal = TRUE; | |
1057 } | |
1058 | |
9 | 1059 return stop_signal; |
1060 } | |
1061 | |
1062 /* | |
1063 *------------------------------------------------------------------- | |
1064 * window | |
1065 *------------------------------------------------------------------- | |
1066 */ | |
1067 static void collection_window_get_geometry(CollectWindow *cw) | |
1068 { | |
1069 CollectionData *cd; | |
2034
9297985567b5
use accessor functions
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
2021
diff
changeset
|
1070 GdkWindow *window; |
9 | 1071 |
1072 if (!cw) return; | |
1073 | |
1074 cd = cw->cd; | |
2034
9297985567b5
use accessor functions
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
2021
diff
changeset
|
1075 window = gtk_widget_get_window(cw->window); |
9297985567b5
use accessor functions
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
2021
diff
changeset
|
1076 gdk_window_get_position(window, &cd->window_x, &cd->window_y); |
9297985567b5
use accessor functions
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
2021
diff
changeset
|
1077 cd->window_w = gdk_window_get_width(window); |
9297985567b5
use accessor functions
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
2021
diff
changeset
|
1078 cd->window_h = gdk_window_get_height(window); |
9 | 1079 cd->window_read = TRUE; |
1080 } | |
1081 | |
1082 static void collection_window_refresh(CollectWindow *cw) | |
1083 { | |
1084 if (!cw) return; | |
1085 | |
1086 collection_table_refresh(cw->table); | |
1087 } | |
1088 | |
1089 static void collection_window_update_title(CollectWindow *cw) | |
1090 { | |
1176
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1091 gboolean free_name = FALSE; |
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1092 gchar *name; |
9 | 1093 gchar *buf; |
1094 | |
1095 if (!cw) return; | |
1096 | |
1176
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1097 if (file_extension_match(cw->cd->name, GQ_COLLECTION_EXT)) |
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1098 { |
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1099 name = remove_extension_from_path(cw->cd->name); |
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1100 free_name = TRUE; |
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1101 } |
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1102 else |
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1103 { |
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1104 name = cw->cd->name; |
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1105 } |
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1106 |
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1107 buf = g_strdup_printf(_("%s - Collection - %s"), name, GQ_APPNAME); |
0a61b5ce9d20
Hide .gqv extension from collection name in collection window title and recent menu list.
Laurent Monin <geeqie@norz.org>
parents:
1174
diff
changeset
|
1108 if (free_name) g_free(name); |
9 | 1109 gtk_window_set_title(GTK_WINDOW(cw->window), buf); |
1110 g_free(buf); | |
1111 } | |
1112 | |
1113 static void collection_window_update_info(CollectionData *cd, CollectInfo *ci, gpointer data) | |
1114 { | |
1115 CollectWindow *cw = data; | |
1116 | |
1117 collection_table_file_update(cw->table, ci); | |
1118 } | |
1119 | |
1120 static void collection_window_add(CollectWindow *cw, CollectInfo *ci) | |
1121 { | |
1122 if (!cw) return; | |
1123 | |
1124 if (!ci->pixbuf) collection_load_thumb_idle(cw->cd); | |
1125 collection_table_file_add(cw->table, ci); | |
1126 } | |
1127 | |
1128 static void collection_window_insert(CollectWindow *cw, CollectInfo *ci) | |
1129 { | |
1130 if (!cw) return; | |
1131 | |
1132 if (!ci->pixbuf) collection_load_thumb_idle(cw->cd); | |
1133 collection_table_file_insert(cw->table, ci); | |
1134 if (!cw) return; | |
1135 } | |
1136 | |
1137 static void collection_window_remove(CollectWindow *cw, CollectInfo *ci) | |
1138 { | |
1139 if (!cw) return; | |
1140 | |
1141 collection_table_file_remove(cw->table, ci); | |
1142 } | |
1143 | |
1144 static void collection_window_update(CollectWindow *cw, CollectInfo *ci) | |
1145 { | |
1146 if (!cw) return; | |
1147 | |
1148 collection_table_file_update(cw->table, ci); | |
1149 collection_table_file_update(cw->table, NULL); | |
1150 } | |
1151 | |
1152 static void collection_window_close_final(CollectWindow *cw) | |
1153 { | |
1154 if (cw->close_dialog) return; | |
1155 | |
1156 collection_window_list = g_list_remove(collection_window_list, cw); | |
1157 collection_window_get_geometry(cw); | |
1158 | |
1159 gtk_widget_destroy(cw->window); | |
1160 | |
1161 collection_set_update_info_func(cw->cd, NULL, NULL); | |
1162 collection_unref(cw->cd); | |
1163 | |
1164 g_free(cw); | |
1165 } | |
1166 | |
1167 static void collection_close_save_cb(GenericDialog *gd, gpointer data) | |
1168 { | |
1169 CollectWindow *cw = data; | |
1170 | |
1171 cw->close_dialog = NULL; | |
1172 generic_dialog_close(gd); | |
1173 | |
1174 if (!cw->cd->path) | |
442 | 1175 { |
9 | 1176 collection_dialog_save_close(NULL, cw->cd); |
1177 return; | |
1178 } | |
1179 else if (!collection_save(cw->cd, cw->cd->path)) | |
1180 { | |
1181 gchar *buf; | |
1182 buf = g_strdup_printf(_("Failed to save the collection:\n%s"), cw->cd->path); | |
1183 warning_dialog(_("Save Failed"), buf, GTK_STOCK_DIALOG_ERROR, cw->window); | |
1184 g_free(buf); | |
1185 return; | |
1186 } | |
1187 | |
1188 collection_window_close_final(cw); | |
1189 } | |
1190 | |
1191 static void collection_close_close_cb(GenericDialog *gd, gpointer data) | |
1192 { | |
1193 CollectWindow *cw = data; | |
1194 | |
1195 cw->close_dialog = NULL; | |
1196 generic_dialog_close(gd); | |
1197 | |
1198 collection_window_close_final(cw); | |
1199 } | |
1200 | |
1201 static void collection_close_cancel_cb(GenericDialog *gd, gpointer data) | |
1202 { | |
1203 CollectWindow *cw = data; | |
1204 | |
1205 cw->close_dialog = NULL; | |
1206 generic_dialog_close(gd); | |
1207 } | |
1208 | |
1209 static void collection_close_dlg_show(CollectWindow *cw) | |
1210 { | |
1211 GenericDialog *gd; | |
1212 | |
1213 if (cw->close_dialog) | |
1214 { | |
1215 gtk_window_present(GTK_WINDOW(cw->close_dialog)); | |
1216 return; | |
1217 } | |
1218 | |
1219 gd = generic_dialog_new(_("Close collection"), | |
1174
f809d57aed0c
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.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
1220 "close_collection", cw->window, FALSE, |
9 | 1221 collection_close_cancel_cb, cw); |
1222 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION, | |
1223 _("Close collection"), | |
2587
c6f9494f6be1
Fix #508: Copy and Move windows scale incorrectly
cclark <colin.clark@cclark.uk>
parents:
2583
diff
changeset
|
1224 _("Collection has been modified.\nSave first?"), TRUE); |
9 | 1225 |
1226 generic_dialog_add_button(gd, GTK_STOCK_SAVE, NULL, collection_close_save_cb, TRUE); | |
1227 generic_dialog_add_button(gd, GTK_STOCK_DELETE, _("_Discard"), collection_close_close_cb, FALSE); | |
1228 | |
1229 cw->close_dialog = gd->dialog; | |
1230 | |
1231 gtk_widget_show(gd->dialog); | |
1232 } | |
1233 | |
1234 static void collection_window_close(CollectWindow *cw) | |
1235 { | |
1236 if (!cw->cd->changed && !cw->close_dialog) | |
1237 { | |
1238 collection_window_close_final(cw); | |
1239 return; | |
1240 } | |
1241 | |
1242 collection_close_dlg_show(cw); | |
1243 } | |
1244 | |
1245 void collection_window_close_by_collection(CollectionData *cd) | |
1246 { | |
1247 CollectWindow *cw; | |
1248 | |
1249 cw = collection_window_find(cd); | |
1250 if (cw) collection_window_close_final(cw); | |
1251 } | |
1252 | |
2595
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1253 /** |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1254 * @brief Check if any Collection windows have unsaved data |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1255 * @returns TRUE if unsaved data exists |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1256 * |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1257 * Also saves window geometry for Collection windows that have |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1258 * no unsaved data |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1259 */ |
1420
6cda3d9d6a7b
Use gboolean where applicable, for the sake of consistency.
Laurent Monin <geeqie@norz.org>
parents:
1367
diff
changeset
|
1260 gboolean collection_window_modified_exists(void) |
9 | 1261 { |
1262 GList *work; | |
2595
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1263 gboolean ret; |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1264 |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1265 ret = FALSE; |
9 | 1266 |
1267 work = collection_window_list; | |
1268 while (work) | |
1269 { | |
1270 CollectWindow *cw = work->data; | |
2595
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1271 if (cw->cd->changed) |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1272 { |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1273 ret = TRUE; |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1274 } |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1275 else |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1276 { |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1277 if (!collection_save(cw->table->cd, cw->table->cd->path)) |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1278 { |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1279 log_printf("failed saving to collection path: %s\n", cw->table->cd->path); |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1280 } |
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1281 } |
9 | 1282 work = work->next; |
1283 } | |
1284 | |
2595
7b75f6d95758
Save Collection window geometry
Colin Clark <colin.clark@cclark.uk>
parents:
2587
diff
changeset
|
1285 return ret; |
9 | 1286 } |
1287 | |
1420
6cda3d9d6a7b
Use gboolean where applicable, for the sake of consistency.
Laurent Monin <geeqie@norz.org>
parents:
1367
diff
changeset
|
1288 static gboolean collection_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data) |
9 | 1289 { |
1290 CollectWindow *cw = data; | |
1291 collection_window_close(cw); | |
1292 | |
1293 return TRUE; | |
1294 } | |
1295 | |
1296 CollectWindow *collection_window_new(const gchar *path) | |
1297 { | |
1298 CollectWindow *cw; | |
1299 GtkWidget *vbox; | |
1300 GtkWidget *frame; | |
1301 GtkWidget *status_label; | |
1302 GtkWidget *extra_label; | |
1303 GdkGeometry geometry; | |
1304 | |
2581
e6847b39721f
Bug fix: Collection in multiple windows
Colin Clark <colin.clark@cclark.uk>
parents:
2472
diff
changeset
|
1305 /* If the collection is already opened in another window, return that one */ |
e6847b39721f
Bug fix: Collection in multiple windows
Colin Clark <colin.clark@cclark.uk>
parents:
2472
diff
changeset
|
1306 cw = collection_window_find_by_path(path); |
e6847b39721f
Bug fix: Collection in multiple windows
Colin Clark <colin.clark@cclark.uk>
parents:
2472
diff
changeset
|
1307 if (cw) |
e6847b39721f
Bug fix: Collection in multiple windows
Colin Clark <colin.clark@cclark.uk>
parents:
2472
diff
changeset
|
1308 { |
e6847b39721f
Bug fix: Collection in multiple windows
Colin Clark <colin.clark@cclark.uk>
parents:
2472
diff
changeset
|
1309 return cw; |
e6847b39721f
Bug fix: Collection in multiple windows
Colin Clark <colin.clark@cclark.uk>
parents:
2472
diff
changeset
|
1310 } |
e6847b39721f
Bug fix: Collection in multiple windows
Colin Clark <colin.clark@cclark.uk>
parents:
2472
diff
changeset
|
1311 |
9 | 1312 cw = g_new0(CollectWindow, 1); |
1313 | |
1314 collection_window_list = g_list_append(collection_window_list, cw); | |
1315 | |
1316 cw->cd = collection_new(path); | |
1317 | |
289
d4d7e7aa0d88
Simplify and unify gtk_window creation with the help of
Laurent Monin <geeqie@norz.org>
parents:
288
diff
changeset
|
1318 cw->window = window_new(GTK_WINDOW_TOPLEVEL, "collection", PIXBUF_INLINE_ICON_BOOK, NULL, NULL); |
9 | 1319 |
1029
b1a912dee214
Use a constant for minimal window size. Set it to 32 for all dialogs.
Laurent Monin <geeqie@norz.org>
parents:
1022
diff
changeset
|
1320 geometry.min_width = DEFAULT_MINIMAL_WINDOW_SIZE; |
b1a912dee214
Use a constant for minimal window size. Set it to 32 for all dialogs.
Laurent Monin <geeqie@norz.org>
parents:
1022
diff
changeset
|
1321 geometry.min_height = DEFAULT_MINIMAL_WINDOW_SIZE; |
9 | 1322 geometry.base_width = COLLECT_DEF_WIDTH; |
1323 geometry.base_height = COLLECT_DEF_HEIGHT; | |
1324 gtk_window_set_geometry_hints(GTK_WINDOW(cw->window), NULL, &geometry, | |
1325 GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); | |
1326 | |
2793 | 1327 if (options->collections_on_top) |
1328 { | |
1329 gtk_window_set_keep_above(GTK_WINDOW(cw->window), TRUE); | |
1330 } | |
9 | 1331 |
1436
13d61fe760fb
completely separated global and layout window options
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1432
diff
changeset
|
1332 if (options->save_window_positions && path && collection_load_only_geometry(cw->cd, path)) |
9 | 1333 { |
1334 gtk_window_set_default_size(GTK_WINDOW(cw->window), cw->cd->window_w, cw->cd->window_h); | |
2472
11455ee1aaf3
Eliminate a FIXME: Collection window position
Colin Clark <colin.clark@cclark.uk>
parents:
2439
diff
changeset
|
1335 gtk_window_move(GTK_WINDOW(cw->window), cw->cd->window_x, cw->cd->window_y); |
9 | 1336 } |
1337 else | |
1338 { | |
1339 gtk_window_set_default_size(GTK_WINDOW(cw->window), COLLECT_DEF_WIDTH, COLLECT_DEF_HEIGHT); | |
1340 } | |
1341 | |
1342 gtk_window_set_resizable(GTK_WINDOW(cw->window), TRUE); | |
1343 collection_window_update_title(cw); | |
513
6743a5928e09
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
Laurent Monin <geeqie@norz.org>
parents:
512
diff
changeset
|
1344 gtk_container_set_border_width(GTK_CONTAINER(cw->window), 0); |
9 | 1345 |
1346 g_signal_connect(G_OBJECT(cw->window), "delete_event", | |
1347 G_CALLBACK(collection_window_delete), cw); | |
1348 | |
513
6743a5928e09
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
Laurent Monin <geeqie@norz.org>
parents:
512
diff
changeset
|
1349 g_signal_connect(G_OBJECT(cw->window), "key_press_event", |
9 | 1350 G_CALLBACK(collection_window_keypress), cw); |
1351 | |
1352 vbox = gtk_vbox_new(FALSE, 0); | |
1353 gtk_container_add(GTK_CONTAINER(cw->window), vbox); | |
1354 gtk_widget_show(vbox); | |
1355 | |
1356 cw->table = collection_table_new(cw->cd); | |
1357 gtk_box_pack_start(GTK_BOX(vbox), cw->table->scrolled, TRUE, TRUE, 0); | |
1358 gtk_widget_show(cw->table->scrolled); | |
1359 | |
1360 cw->status_box = gtk_hbox_new(TRUE, 0); | |
1361 gtk_box_pack_start(GTK_BOX(vbox), cw->status_box, FALSE, FALSE, 0); | |
1362 gtk_widget_show(cw->status_box); | |
1363 | |
1364 frame = gtk_frame_new(NULL); | |
1365 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
1366 gtk_box_pack_start(GTK_BOX(cw->status_box), frame, TRUE, TRUE, 0); | |
1367 gtk_widget_show(frame); | |
1368 | |
1369 status_label = gtk_label_new(""); | |
1370 gtk_container_add(GTK_CONTAINER(frame), status_label); | |
1371 gtk_widget_show(status_label); | |
1372 | |
1373 extra_label = gtk_progress_bar_new(); | |
1374 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(extra_label), 0.0); | |
2439 | 1375 #if GTK_CHECK_VERSION(3,0,0) |
1376 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(extra_label), ""); | |
1377 gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(extra_label), TRUE); | |
1378 #endif | |
9 | 1379 gtk_box_pack_start(GTK_BOX(cw->status_box), extra_label, TRUE, TRUE, 0); |
1380 gtk_widget_show(extra_label); | |
1381 | |
1382 collection_table_set_labels(cw->table, status_label, extra_label); | |
1383 | |
1384 gtk_widget_show(cw->window); | |
1385 gtk_widget_grab_focus(cw->table->listview); | |
1386 | |
1387 collection_set_update_info_func(cw->cd, collection_window_update_info, cw); | |
1388 | |
726
5166ed61c537
Use G_DIR_SEPARATOR where applicable.
Laurent Monin <geeqie@norz.org>
parents:
673
diff
changeset
|
1389 if (path && *path == G_DIR_SEPARATOR) collection_load_begin(cw->cd, NULL, COLLECTION_LOAD_NONE); |
9 | 1390 |
1391 return cw; | |
1392 } | |
1055
4bbdfab3c89a
Adding a vim modeline to all files - patch by Klaus Ethgen
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1029
diff
changeset
|
1393 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |