Mercurial > geeqie.yaz
annotate src/collect-dlg.c @ 1225:3e5f52382573
fixed previous change
author | nadvornik |
---|---|
date | Fri, 26 Dec 2008 17:38:52 +0000 |
parents | 404168a124aa |
children | 8b89e3ff286b |
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 | |
1174
0bea79d87065
Drop useless wmclass stuff. Gtk will take care of it and as said in the documentation using gtk_window_set_wmclass() is sort of pointless.
zas_
parents:
1145
diff
changeset
|
69 gd = file_util_gen_dlg(_("Overwrite File"), "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; | |
1199
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
121 gboolean err = FALSE; |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
122 gchar *text = NULL; |
9 | 123 |
1199
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
124 if (!isname(fd->dest_path)) |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
125 { |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
126 err = TRUE; |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
127 text = g_strdup_printf(_("No such file '%s'."), fd->dest_path); |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
128 } |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
129 if (!err && isdir(fd->dest_path)) |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
130 { |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
131 err = TRUE; |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
132 text = g_strdup_printf(_("'%s' is a directory, not a collection file."), fd->dest_path); |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
133 } |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
134 if (!err && !access_file(fd->dest_path, R_OK)) |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
135 { |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
136 err = TRUE; |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
137 text = g_strdup_printf(_("You do not have read permissions on the file '%s'."), fd->dest_path); |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
138 } |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
139 |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
140 if (err) { |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
141 if (text) |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
142 { |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
143 file_util_warning_dialog(_("Can not open collection file"), text, GTK_STOCK_DIALOG_ERROR, NULL); |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
144 g_free(text); |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
145 } |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
146 return; |
404168a124aa
Display error dialog with appropriate message when user is trying to open an invalid collection file.
zas_
parents:
1174
diff
changeset
|
147 } |
9 | 148 |
149 if (append) | |
150 { | |
151 collection_load(cd, fd->dest_path, TRUE); | |
152 collection_unref(cd); | |
153 } | |
154 else | |
155 { | |
156 collection_window_new(fd->dest_path); | |
157 } | |
158 | |
159 file_dialog_sync_history(fd, TRUE); | |
160 file_dialog_close(fd); | |
161 } | |
162 | |
163 static void collection_load_cb(FileDialog *fd, gpointer data) | |
164 { | |
165 real_collection_button_pressed(fd, data, FALSE); | |
166 } | |
167 | |
168 static void collection_append_cb(FileDialog *fd, gpointer data) | |
169 { | |
170 real_collection_button_pressed(fd, data, TRUE); | |
171 } | |
172 | |
173 static void collection_save_or_load_dialog_close_cb(FileDialog *fd, gpointer data) | |
174 { | |
175 CollectionData *cd = data; | |
176 | |
177 if (cd) collection_unref(cd); | |
178 file_dialog_close(fd); | |
179 } | |
180 | |
181 static void collection_save_or_load_dialog(const gchar *path, | |
182 gint type, CollectionData *cd) | |
183 { | |
184 FileDialog *fd; | |
185 GtkWidget *parent = NULL; | |
186 CollectWindow *cw; | |
187 const gchar *title; | |
188 const gchar *btntext; | |
1002 | 189 gpointer btnfunc; |
9 | 190 const gchar *stock_id; |
191 | |
192 if (type == DIALOG_SAVE || type == DIALOG_SAVE_CLOSE) | |
193 { | |
194 if (!cd) return; | |
195 title = _("Save collection"); | |
196 btntext = NULL; | |
197 btnfunc = collection_save_cb; | |
198 stock_id = GTK_STOCK_SAVE; | |
199 } | |
200 else if (type == DIALOG_LOAD) | |
201 { | |
202 title = _("Open collection"); | |
203 btntext = NULL; | |
204 btnfunc = collection_load_cb; | |
205 stock_id = GTK_STOCK_OPEN; | |
206 } | |
207 else | |
208 { | |
209 if (!cd) return; | |
210 title = _("Append collection"); | |
211 btntext = _("_Append"); | |
212 btnfunc = collection_append_cb; | |
213 stock_id = GTK_STOCK_ADD; | |
214 } | |
215 | |
216 if (cd) collection_ref(cd); | |
217 | |
218 cw = collection_window_find(cd); | |
219 if (cw) parent = cw->window; | |
220 | |
1174
0bea79d87065
Drop useless wmclass stuff. Gtk will take care of it and as said in the documentation using gtk_window_set_wmclass() is sort of pointless.
zas_
parents:
1145
diff
changeset
|
221 fd = file_util_file_dlg(title, "dlg_collection", parent, |
9 | 222 collection_save_or_load_dialog_close_cb, cd); |
223 | |
224 generic_dialog_add_message(GENERIC_DIALOG(fd), NULL, title, NULL); | |
225 file_dialog_add_button(fd, stock_id, btntext, btnfunc, TRUE); | |
226 | |
1145
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
227 file_dialog_add_path_widgets(fd, get_collections_dir(), path, |
781
2d2cca2bceb0
Replace hardcoded collection filename extension by a macro (GQ_COLLECTION_EXT).
zas_
parents:
711
diff
changeset
|
228 "collection_load_save", GQ_COLLECTION_EXT, _("Collection Files")); |
9 | 229 |
230 fd->type = type; | |
231 | |
232 gtk_widget_show(GENERIC_DIALOG(fd)->dialog); | |
233 } | |
234 | |
235 void collection_dialog_save_as(gchar *path, CollectionData *cd) | |
236 { | |
237 #if 0 | |
238 if (!cd->list) | |
239 { | |
240 GtkWidget *parent = NULL; | |
241 CollectWindow *cw; | |
242 | |
243 cw = collection_window_find(cd); | |
244 if (cw) parent = cw->window; | |
245 file_util_warning_dialog(_("Collection empty"), | |
246 _("The current collection is empty, save aborted."), | |
247 GTK_STOCK_DIALOG_INFO, parent); | |
248 return; | |
249 } | |
250 #endif | |
251 | |
252 if (!path) path = cd->path; | |
253 if (!path) path = cd->name; | |
254 | |
255 collection_save_or_load_dialog(path, DIALOG_SAVE, cd); | |
256 } | |
257 | |
258 void collection_dialog_save_close(gchar *path, CollectionData *cd) | |
259 { | |
260 if (!path) path = cd->path; | |
261 if (!path) path = cd->name; | |
262 | |
263 collection_save_or_load_dialog(path, DIALOG_SAVE_CLOSE, cd); | |
264 } | |
265 | |
266 void collection_dialog_load(gchar *path) | |
267 { | |
268 collection_save_or_load_dialog(path, DIALOG_LOAD, NULL); | |
269 } | |
270 | |
271 void collection_dialog_append(gchar *path, CollectionData *cd) | |
272 { | |
273 collection_save_or_load_dialog(path, DIALOG_APPEND, cd); | |
274 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1002
diff
changeset
|
275 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |