Mercurial > gftp.yaz
comparison src/gtk/view_dialog.c @ 905:c2be64b831d9
2007-3-26 Brian Masney <masneyb@gftp.org>
* src/gtk/view_dialog.c - fixed codepage related issue in the view/edit
file feature (from Alexander Orlov <alxorlov@pochta.ru>)
author | masneyb |
---|---|
date | Wed, 28 Mar 2007 02:31:06 +0000 |
parents | 14476a8a4d2b |
children |
comparison
equal
deleted
inserted
replaced
904:c6232185a1e5 | 905:c2be64b831d9 |
---|---|
150 *endpos = ' '; | 150 *endpos = ' '; |
151 pos = endpos + 1; | 151 pos = endpos + 1; |
152 } | 152 } |
153 argv = g_realloc (argv, (gulong) (n + 3) * sizeof (char *)); | 153 argv = g_realloc (argv, (gulong) (n + 3) * sizeof (char *)); |
154 argv[n] = g_strdup (pos); | 154 argv[n] = g_strdup (pos); |
155 argv[n + 1] = g_strdup (filename); | 155 |
156 if (wdata != NULL) | |
157 { | |
158 if ((argv[n + 1] = gftp_filename_from_utf8 (wdata->request, filename, NULL)) == NULL) | |
159 argv[n + 1] = g_strdup (filename); | |
160 } | |
161 else | |
162 argv[n + 1] = g_strdup (filename); | |
163 | |
156 argv[n + 2] = NULL; | 164 argv[n + 2] = NULL; |
157 | 165 |
158 newproc = NULL; | 166 newproc = NULL; |
159 switch ((ret = fork ())) | 167 switch ((ret = fork ())) |
160 { | 168 { |
210 GtkAdjustment * vadj; | 218 GtkAdjustment * vadj; |
211 GList * templist; | 219 GList * templist; |
212 size_t stlen; | 220 size_t stlen; |
213 int doclose; | 221 int doclose; |
214 ssize_t n; | 222 ssize_t n; |
223 char * non_utf8; | |
215 #if GTK_MAJOR_VERSION > 1 | 224 #if GTK_MAJOR_VERSION > 1 |
216 GtkTextBuffer * textbuf; | 225 GtkTextBuffer * textbuf; |
217 GtkTextIter iter; | 226 GtkTextIter iter; |
218 #endif | 227 #endif |
219 | 228 |
238 | 247 |
239 if (wdata != NULL) | 248 if (wdata != NULL) |
240 { | 249 { |
241 gftp_lookup_request_option (wdata->request, "view_program", &view_program); | 250 gftp_lookup_request_option (wdata->request, "view_program", &view_program); |
242 gftp_lookup_request_option (wdata->request, "edit_program", &edit_program); | 251 gftp_lookup_request_option (wdata->request, "edit_program", &edit_program); |
252 if ((non_utf8 = gftp_filename_from_utf8 (wdata->request, filename, NULL)) == NULL) /* freeme later! */ | |
253 non_utf8 = filename; | |
243 } | 254 } |
244 else | 255 else |
245 { | 256 { |
246 gftp_lookup_global_option ("view_program", &view_program); | 257 gftp_lookup_global_option ("view_program", &view_program); |
247 gftp_lookup_global_option ("edit_program", &edit_program); | 258 gftp_lookup_global_option ("edit_program", &edit_program); |
259 non_utf8 = filename; | |
248 } | 260 } |
249 | 261 |
250 if (viewedit && *view_program != '\0') | 262 if (viewedit && *view_program != '\0') |
251 { | 263 { |
252 /* Open the file with the default file viewer */ | 264 /* Open the file with the default file viewer */ |
253 fork_process (view_program, filename, fd, remote_filename, viewedit, | 265 fork_process (view_program, filename, fd, remote_filename, viewedit, |
254 del_file, dontupload, wdata); | 266 del_file, dontupload, wdata); |
267 if (non_utf8 != filename && non_utf8) | |
268 g_free (non_utf8); | |
255 return; | 269 return; |
256 } | 270 } |
257 else if (!viewedit && *edit_program != '\0') | 271 else if (!viewedit && *edit_program != '\0') |
258 { | 272 { |
259 /* Open the file with the default file editor */ | 273 /* Open the file with the default file editor */ |
260 newproc = fork_process (edit_program, filename, fd, remote_filename, | 274 newproc = fork_process (edit_program, filename, fd, remote_filename, |
261 viewedit, del_file, dontupload, wdata); | 275 viewedit, del_file, dontupload, wdata); |
262 stat (filename, &newproc->st); | 276 stat (non_utf8, &newproc->st); |
277 if (non_utf8 != filename && non_utf8) | |
278 g_free (non_utf8); | |
263 return; | 279 return; |
264 } | 280 } |
265 | 281 |
266 ftp_log (gftp_logging_misc, NULL, _("Viewing file %s\n"), filename); | 282 ftp_log (gftp_logging_misc, NULL, _("Viewing file %s\n"), filename); |
267 | 283 |
268 if (fd == 0) | 284 if (fd == 0) |
269 { | 285 { |
270 if ((fd = open (filename, O_RDONLY)) < 0) | 286 if ((fd = open (non_utf8, O_RDONLY)) < 0) |
271 { | 287 { |
272 ftp_log (gftp_logging_error, NULL, | 288 ftp_log (gftp_logging_error, NULL, |
273 _("View: Cannot open file %s: %s\n"), filename, | 289 _("View: Cannot open file %s: %s\n"), non_utf8, |
274 g_strerror (errno)); | 290 g_strerror (errno)); |
291 if (non_utf8 != filename && non_utf8) | |
292 g_free (non_utf8); | |
275 return; | 293 return; |
276 } | 294 } |
277 doclose = 1; | 295 doclose = 1; |
278 } | 296 } |
279 else | 297 else |
282 doclose = 0; | 300 doclose = 0; |
283 } | 301 } |
284 | 302 |
285 if (del_file) | 303 if (del_file) |
286 { | 304 { |
287 if (unlink (filename) == 0) | 305 if (unlink (non_utf8) == 0) |
288 ftp_log (gftp_logging_misc, NULL, _("Successfully removed %s\n"), | 306 ftp_log (gftp_logging_misc, NULL, _("Successfully removed %s\n"), |
289 filename); | 307 filename); |
290 else | 308 else |
291 ftp_log (gftp_logging_error, NULL, | 309 ftp_log (gftp_logging_error, NULL, |
292 _("Error: Could not remove file %s: %s\n"), filename, | 310 _("Error: Could not remove file %s: %s\n"), filename, |
293 g_strerror (errno)); | 311 g_strerror (errno)); |
294 } | 312 } |
313 | |
314 if (non_utf8 != filename && non_utf8) | |
315 g_free (non_utf8); | |
295 | 316 |
296 #if GTK_MAJOR_VERSION == 1 | 317 #if GTK_MAJOR_VERSION == 1 |
297 dialog = gtk_dialog_new (); | 318 dialog = gtk_dialog_new (); |
298 gtk_window_set_title (GTK_WINDOW (dialog), filename); | 319 gtk_window_set_title (GTK_WINDOW (dialog), filename); |
299 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), | 320 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), |