Mercurial > pidgin.yaz
comparison src/gtkft.c @ 11010:9fe9c7e00666
[gaim-migrate @ 12871]
sf patch #1207058, from Dave Ahlswede (with tweaks by me)
Enable opening received files in GNOME by using gnome-open
Thank to grim and rlaager for help testing.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 14 Jun 2005 04:13:11 +0000 |
parents | accfd1f1f80d |
children | 50224ac8184d |
comparison
equal
deleted
inserted
replaced
11009:926d2ff72899 | 11010:9fe9c7e00666 |
---|---|
290 | 290 |
291 if (gaim_xfer_is_completed(xfer)) { | 291 if (gaim_xfer_is_completed(xfer)) { |
292 gtk_widget_hide(dialog->stop_button); | 292 gtk_widget_hide(dialog->stop_button); |
293 gtk_widget_show(dialog->remove_button); | 293 gtk_widget_show(dialog->remove_button); |
294 | 294 |
295 #ifdef _WIN32 /* Only supported in Win32 right now */ | 295 #ifdef _WIN32 |
296 /* If using Win32... */ | |
296 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { | 297 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { |
297 gtk_widget_set_sensitive(dialog->open_button, TRUE); | 298 gtk_widget_set_sensitive(dialog->open_button, TRUE); |
298 } else { | 299 } else { |
299 gtk_widget_set_sensitive(dialog->open_button, FALSE); | 300 gtk_widget_set_sensitive(dialog->open_button, FALSE); |
300 } | 301 } |
302 #else | |
303 /* If using GNOME, use gnome-open */ | |
304 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE && gaim_running_gnome()) { | |
305 gtk_widget_set_sensitive(dialog->open_button, TRUE); | |
306 } else { | |
307 gtk_widget_set_sensitive (dialog->open_button, FALSE); | |
308 } | |
301 #endif | 309 #endif |
302 gtk_widget_set_sensitive(dialog->pause_button, FALSE); | 310 gtk_widget_set_sensitive(dialog->pause_button, FALSE); |
303 gtk_widget_set_sensitive(dialog->resume_button, FALSE); | 311 gtk_widget_set_sensitive(dialog->resume_button, FALSE); |
304 | 312 |
305 gtk_widget_set_sensitive(dialog->remove_button, TRUE); | 313 gtk_widget_set_sensitive(dialog->remove_button, TRUE); |
404 } | 412 } |
405 | 413 |
406 static void | 414 static void |
407 open_button_cb(GtkButton *button, GaimGtkXferDialog *dialog) | 415 open_button_cb(GtkButton *button, GaimGtkXferDialog *dialog) |
408 { | 416 { |
409 #ifdef _WIN32 /* Only supported in Win32 right now */ | 417 #ifdef _WIN32 |
418 /* If using Win32... */ | |
410 int code; | 419 int code; |
411 if (G_WIN32_HAVE_WIDECHAR_API ()) { | 420 if (G_WIN32_HAVE_WIDECHAR_API ()) { |
412 wchar_t *wc_filename = g_utf8_to_utf16( | 421 wchar_t *wc_filename = g_utf8_to_utf16( |
413 gaim_xfer_get_local_filename( | 422 gaim_xfer_get_local_filename( |
414 dialog->selected_xfer), | 423 dialog->selected_xfer), |
415 -1, NULL, NULL, NULL); | 424 -1, NULL, NULL, NULL); |
416 | 425 |
417 code = (int) ShellExecuteW(NULL, NULL, wc_filename, NULL, NULL, | 426 code = (int) ShellExecuteW(NULL, NULL, wc_filename, NULL, NULL, |
418 SW_SHOW); | 427 SW_SHOW); |
419 | 428 |
420 g_free(wc_filename); | 429 g_free(wc_filename); |
421 } else { | 430 } else { |
422 char *l_filename = g_locale_from_utf8( | 431 char *l_filename = g_locale_from_utf8( |
423 gaim_xfer_get_local_filename( | 432 gaim_xfer_get_local_filename( |
424 dialog->selected_xfer), | 433 dialog->selected_xfer), |
425 -1, NULL, NULL, NULL); | 434 -1, NULL, NULL, NULL); |
426 | 435 |
427 code = (int) ShellExecuteA(NULL, NULL, l_filename, NULL, NULL, | 436 code = (int) ShellExecuteA(NULL, NULL, l_filename, NULL, NULL, |
428 SW_SHOW); | 437 SW_SHOW); |
429 | 438 |
430 g_free(l_filename); | 439 g_free(l_filename); |
431 } | 440 } |
432 | 441 |
433 if (code == SE_ERR_ASSOCINCOMPLETE || code == SE_ERR_NOASSOC) | 442 if (code == SE_ERR_ASSOCINCOMPLETE || code == SE_ERR_NOASSOC) |
434 { | 443 { |
435 gaim_notify_error(NULL, NULL, | 444 gaim_notify_error(dialog, NULL, |
436 _("There is no application configured to open this type of file."), NULL); | 445 _("There is no application configured to open this type of file."), NULL); |
437 } | 446 } |
438 else if (code < 32) | 447 else if (code < 32) |
439 { | 448 { |
440 gaim_notify_error(NULL, NULL, | 449 gaim_notify_error(dialog, NULL, |
441 _("An error occurred while opening the file."), NULL); | 450 _("An error occurred while opening the file."), NULL); |
442 gaim_debug_warning("ft", "filename: %s; code: %d\n", | 451 gaim_debug_warning("ft", "filename: %s; code: %d\n", |
443 gaim_xfer_get_local_filename(dialog->selected_xfer), code); | 452 gaim_xfer_get_local_filename(dialog->selected_xfer), code); |
453 } | |
454 #else | |
455 /* If using GNOME, use gnome-open */ | |
456 if (gaim_running_gnome()) | |
457 { | |
458 char *command = NULL; | |
459 char *tmp = NULL; | |
460 GError *error = NULL; | |
461 | |
462 command = g_strdup_printf("gnome-open \"%s\"", | |
463 gaim_xfer_get_local_filename(dialog->selected_xfer)); | |
464 | |
465 if (gaim_program_is_valid(command)) | |
466 { | |
467 gint exit_status; | |
468 if (!g_spawn_command_line_sync(command, NULL, NULL, &exit_status, &error)) | |
469 { | |
470 tmp = g_strdup_printf(_("Error launching %s: %s"), | |
471 gaim_xfer_get_local_filename(dialog->selected_xfer), | |
472 error->message); | |
473 gaim_notify_error(dialog, NULL, _("Unable to open file."), tmp); | |
474 g_free(tmp); | |
475 g_error_free(error); | |
476 } | |
477 if (exit_status != 0) | |
478 { | |
479 char *primary = g_strdup_printf(_("Error running %s"), command); | |
480 char *secondary = g_strdup_printf(_("Process returned error code %d"), | |
481 exit_status); | |
482 gaim_notify_error(dialog, NULL, primary, secondary); | |
483 g_free(tmp); | |
484 } | |
485 } | |
444 } | 486 } |
445 #endif | 487 #endif |
446 } | 488 } |
447 | 489 |
448 static void | 490 static void |
783 void | 825 void |
784 gaim_gtkxfer_dialog_destroy(GaimGtkXferDialog *dialog) | 826 gaim_gtkxfer_dialog_destroy(GaimGtkXferDialog *dialog) |
785 { | 827 { |
786 g_return_if_fail(dialog != NULL); | 828 g_return_if_fail(dialog != NULL); |
787 | 829 |
830 gaim_notify_close_with_handle(dialog); | |
831 | |
788 gtk_widget_destroy(dialog->window); | 832 gtk_widget_destroy(dialog->window); |
789 | 833 |
790 g_free(dialog); | 834 g_free(dialog); |
791 } | 835 } |
792 | 836 |
800 | 844 |
801 void | 845 void |
802 gaim_gtkxfer_dialog_hide(GaimGtkXferDialog *dialog) | 846 gaim_gtkxfer_dialog_hide(GaimGtkXferDialog *dialog) |
803 { | 847 { |
804 g_return_if_fail(dialog != NULL); | 848 g_return_if_fail(dialog != NULL); |
849 | |
850 gaim_notify_close_with_handle(dialog); | |
805 | 851 |
806 gtk_widget_hide(dialog->window); | 852 gtk_widget_hide(dialog->window); |
807 } | 853 } |
808 | 854 |
809 void | 855 void |
1090 gaim_prefs_add_bool("/gaim/gtk/filetransfer/clear_finished", TRUE); | 1136 gaim_prefs_add_bool("/gaim/gtk/filetransfer/clear_finished", TRUE); |
1091 gaim_prefs_add_bool("/gaim/gtk/filetransfer/keep_open", FALSE); | 1137 gaim_prefs_add_bool("/gaim/gtk/filetransfer/keep_open", FALSE); |
1092 } | 1138 } |
1093 | 1139 |
1094 void | 1140 void |
1141 gaim_gtk_xfers_uninit(void) | |
1142 { | |
1143 gaim_gtkxfer_dialog_destroy(xfer_dialog); | |
1144 } | |
1145 | |
1146 void | |
1095 gaim_set_gtkxfer_dialog(GaimGtkXferDialog *dialog) | 1147 gaim_set_gtkxfer_dialog(GaimGtkXferDialog *dialog) |
1096 { | 1148 { |
1097 xfer_dialog = dialog; | 1149 xfer_dialog = dialog; |
1098 } | 1150 } |
1099 | 1151 |