Mercurial > geeqie.yaz
annotate src/collect-dlg.c @ 832:a14d7da2736d
iconlist_refresh optimization
author | nadvornik |
---|---|
date | Sat, 14 Jun 2008 12:43:39 +0000 |
parents | 2d2cca2bceb0 |
children | 3096a47232ec |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
281 | 14 #include "main.h" |
9 | 15 #include "collect.h" |
16 #include "collect-dlg.h" | |
17 | |
18 #include "collect-io.h" | |
19 #include "utilops.h" | |
20 #include "ui_fileops.h" | |
21 #include "ui_tabcomp.h" | |
22 #include "ui_utildlg.h" | |
23 | |
24 | |
25 enum { | |
26 DIALOG_SAVE, | |
27 DIALOG_SAVE_CLOSE, | |
28 DIALOG_LOAD, | |
29 DIALOG_APPEND | |
30 }; | |
31 | |
32 | |
33 static gint collection_save_confirmed(FileDialog *fd, gint overwrite, CollectionData *cd); | |
34 | |
35 | |
36 static void collection_confirm_ok_cb(GenericDialog *gd, gpointer data) | |
37 { | |
38 FileDialog *fd = data; | |
39 CollectionData *cd = GENERIC_DIALOG(fd)->data; | |
40 | |
41 if (!collection_save_confirmed(fd, TRUE, cd)) | |
42 { | |
43 collection_unref(cd); | |
44 file_dialog_close(fd); | |
45 } | |
46 } | |
47 | |
48 static void collection_confirm_cancel_cb(GenericDialog *gd, gpointer data) | |
49 { | |
50 /* this is a no-op, so the cancel button is added */ | |
51 } | |
52 | |
53 static gint collection_save_confirmed(FileDialog *fd, gint overwrite, CollectionData *cd) | |
54 { | |
55 gchar *buf; | |
56 | |
57 if (isdir(fd->dest_path)) | |
58 { | |
59 buf = g_strdup_printf(_("Specified path:\n%s\nis a folder, collections are files"), fd->dest_path); | |
60 file_util_warning_dialog(_("Invalid filename"), buf, GTK_STOCK_DIALOG_INFO, GENERIC_DIALOG(fd)->dialog); | |
61 g_free(buf); | |
62 return FALSE; | |
63 } | |
64 | |
65 if (!overwrite && isfile(fd->dest_path)) | |
66 { | |
67 GenericDialog *gd; | |
68 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
196
diff
changeset
|
69 gd = file_util_gen_dlg(_("Overwrite File"), GQ_WMCLASS, "dlg_confirm", |
9 | 70 GENERIC_DIALOG(fd)->dialog, TRUE, |
71 collection_confirm_cancel_cb, fd); | |
72 | |
73 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION, | |
74 _("Overwrite existing file?"), fd->dest_path); | |
75 | |
76 generic_dialog_add_button(gd, GTK_STOCK_OK, _("_Overwrite"), collection_confirm_ok_cb, TRUE); | |
77 | |
78 gtk_widget_show(gd->dialog); | |
79 | |
80 return TRUE; | |
81 } | |
82 | |
83 if (!collection_save(cd, fd->dest_path)) | |
84 { | |
85 buf = g_strdup_printf(_("Failed to save the collection:\n%s"), fd->dest_path); | |
86 file_util_warning_dialog(_("Save Failed"), buf, GTK_STOCK_DIALOG_ERROR, GENERIC_DIALOG(fd)->dialog); | |
87 g_free(buf); | |
88 } | |
89 | |
90 collection_unref(cd); | |
91 file_dialog_sync_history(fd, TRUE); | |
92 | |
93 if (fd->type == DIALOG_SAVE_CLOSE) collection_window_close_by_collection(cd); | |
94 file_dialog_close(fd); | |
95 | |
96 return TRUE; | |
97 } | |
98 | |
99 static void collection_save_cb(FileDialog *fd, gpointer data) | |
100 { | |
101 CollectionData *cd = data; | |
102 const gchar *path; | |
103 | |
104 path = fd->dest_path; | |
442 | 105 |
605
651ae2be1031
Use g_ascii_strncasecmp() instead of strncasecmp() where applicable.
zas_
parents:
475
diff
changeset
|
106 /* FIXME: utf8 */ |
781
2d2cca2bceb0
Replace hardcoded collection filename extension by a macro (GQ_COLLECTION_EXT).
zas_
parents:
711
diff
changeset
|
107 if (!file_extension_match(path, GQ_COLLECTION_EXT)) |
9 | 108 { |
109 gchar *buf; | |
781
2d2cca2bceb0
Replace hardcoded collection filename extension by a macro (GQ_COLLECTION_EXT).
zas_
parents:
711
diff
changeset
|
110 buf = g_strconcat(path, GQ_COLLECTION_EXT, NULL); |
9 | 111 gtk_entry_set_text(GTK_ENTRY(fd->entry), buf); |
112 g_free(buf); | |
113 } | |
114 | |
115 collection_save_confirmed(fd, FALSE, cd); | |
116 } | |
117 | |
118 static void real_collection_button_pressed(FileDialog *fd, gpointer data, gint append) | |
119 { | |
120 CollectionData *cd = data; | |
121 | |
122 if (!fd->dest_path || isdir(fd->dest_path)) return; | |
123 | |
124 if (append) | |
125 { | |
126 collection_load(cd, fd->dest_path, TRUE); | |
127 collection_unref(cd); | |
128 } | |
129 else | |
130 { | |
131 collection_window_new(fd->dest_path); | |
132 } | |
133 | |
134 file_dialog_sync_history(fd, TRUE); | |
135 file_dialog_close(fd); | |
136 } | |
137 | |
138 static void collection_load_cb(FileDialog *fd, gpointer data) | |
139 { | |
140 real_collection_button_pressed(fd, data, FALSE); | |
141 } | |
142 | |
143 static void collection_append_cb(FileDialog *fd, gpointer data) | |
144 { | |
145 real_collection_button_pressed(fd, data, TRUE); | |
146 } | |
147 | |
148 static void collection_save_or_load_dialog_close_cb(FileDialog *fd, gpointer data) | |
149 { | |
150 CollectionData *cd = data; | |
151 | |
152 if (cd) collection_unref(cd); | |
153 file_dialog_close(fd); | |
154 } | |
155 | |
156 static void collection_save_or_load_dialog(const gchar *path, | |
157 gint type, CollectionData *cd) | |
158 { | |
159 FileDialog *fd; | |
160 GtkWidget *parent = NULL; | |
161 CollectWindow *cw; | |
162 const gchar *title; | |
163 const gchar *btntext; | |
164 void *btnfunc; | |
165 gchar *base; | |
166 const gchar *stock_id; | |
167 | |
168 if (type == DIALOG_SAVE || type == DIALOG_SAVE_CLOSE) | |
169 { | |
170 if (!cd) return; | |
171 title = _("Save collection"); | |
172 btntext = NULL; | |
173 btnfunc = collection_save_cb; | |
174 stock_id = GTK_STOCK_SAVE; | |
175 } | |
176 else if (type == DIALOG_LOAD) | |
177 { | |
178 title = _("Open collection"); | |
179 btntext = NULL; | |
180 btnfunc = collection_load_cb; | |
181 stock_id = GTK_STOCK_OPEN; | |
182 } | |
183 else | |
184 { | |
185 if (!cd) return; | |
186 title = _("Append collection"); | |
187 btntext = _("_Append"); | |
188 btnfunc = collection_append_cb; | |
189 stock_id = GTK_STOCK_ADD; | |
190 } | |
191 | |
192 if (cd) collection_ref(cd); | |
193 | |
194 cw = collection_window_find(cd); | |
195 if (cw) parent = cw->window; | |
196 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
196
diff
changeset
|
197 fd = file_util_file_dlg(title, GQ_WMCLASS, "dlg_collection", parent, |
9 | 198 collection_save_or_load_dialog_close_cb, cd); |
199 | |
200 generic_dialog_add_message(GENERIC_DIALOG(fd), NULL, title, NULL); | |
201 file_dialog_add_button(fd, stock_id, btntext, btnfunc, TRUE); | |
202 | |
711 | 203 base = g_build_filename(homedir(), GQ_RC_DIR_COLLECTIONS, NULL); |
9 | 204 file_dialog_add_path_widgets(fd, base, path, |
781
2d2cca2bceb0
Replace hardcoded collection filename extension by a macro (GQ_COLLECTION_EXT).
zas_
parents:
711
diff
changeset
|
205 "collection_load_save", GQ_COLLECTION_EXT, _("Collection Files")); |
9 | 206 g_free(base); |
207 | |
208 fd->type = type; | |
209 | |
210 gtk_widget_show(GENERIC_DIALOG(fd)->dialog); | |
211 } | |
212 | |
213 void collection_dialog_save_as(gchar *path, CollectionData *cd) | |
214 { | |
215 #if 0 | |
216 if (!cd->list) | |
217 { | |
218 GtkWidget *parent = NULL; | |
219 CollectWindow *cw; | |
220 | |
221 cw = collection_window_find(cd); | |
222 if (cw) parent = cw->window; | |
223 file_util_warning_dialog(_("Collection empty"), | |
224 _("The current collection is empty, save aborted."), | |
225 GTK_STOCK_DIALOG_INFO, parent); | |
226 return; | |
227 } | |
228 #endif | |
229 | |
230 if (!path) path = cd->path; | |
231 if (!path) path = cd->name; | |
232 | |
233 collection_save_or_load_dialog(path, DIALOG_SAVE, cd); | |
234 } | |
235 | |
236 void collection_dialog_save_close(gchar *path, CollectionData *cd) | |
237 { | |
238 if (!path) path = cd->path; | |
239 if (!path) path = cd->name; | |
240 | |
241 collection_save_or_load_dialog(path, DIALOG_SAVE_CLOSE, cd); | |
242 } | |
243 | |
244 void collection_dialog_load(gchar *path) | |
245 { | |
246 collection_save_or_load_dialog(path, DIALOG_LOAD, NULL); | |
247 } | |
248 | |
249 void collection_dialog_append(gchar *path, CollectionData *cd) | |
250 { | |
251 collection_save_or_load_dialog(path, DIALOG_APPEND, cd); | |
252 } |