Yasumichi Akahoshi
yasum****@users*****
2005年 10月 8日 (土) 01:38:25 JST
Index: libcxp/src/cxp-utils.c diff -u libcxp/src/cxp-utils.c:1.22 libcxp/src/cxp-utils.c:1.23 --- libcxp/src/cxp-utils.c:1.22 Fri Oct 7 22:21:35 2005 +++ libcxp/src/cxp-utils.c Sat Oct 8 01:38:25 2005 @@ -1,4 +1,4 @@ -/* $Id: cxp-utils.c,v 1.22 2005/10/07 13:21:35 yasumichi Exp $ */ +/* $Id: cxp-utils.c,v 1.23 2005/10/07 16:38:25 yasumichi Exp $ */ /** * \if japanese * @file @@ -6,7 +6,7 @@ * * @author 赤星 柔充 * @date Fri Jan 21 2005 - * $Revision: 1.22 $ + * $Revision: 1.23 $ * \endif * \if english * @file @@ -14,7 +14,7 @@ * * @author Yasumichi Akahoshi * @date Fri Jan 21 2005 - * $Revision: 1.22 $ + * $Revision: 1.23 $ * \endif */ @@ -56,6 +56,7 @@ static GList *pixmaps_directories = NULL; /**< It have directory list. */ static gchar *fname_filter = NULL; static CxpMimeManager *manager = NULL; +static gint cxp_remove_file_recursive (const gchar *fullpath); /** * \if japanese @@ -391,19 +392,117 @@ /** * \if japanese + * rm -rfv を利用してディレクトリを再帰的に削除 + */ +static gint cxp_remove_file_recursive (const gchar *fullpath) +{ + const gchar *encoding; + gchar *cmd; + gchar **args; + gint sout; + gint serr; + gint exit_status = 0; + GPid pid; + GIOChannel *channel; + gchar *message; + gsize length; + GString *str; + GtkWidget *window; + GtkWidget *dialog; + GtkWidget *scrwin; + GtkWidget *text_view; + GtkTextBuffer *buffer; + GtkAdjustment* vadj; + GError *error; + + cmd = g_strdup_printf ("rm -rfv '%s'", fullpath); + g_shell_parse_argv (cmd, NULL, &args, NULL); + if (g_spawn_async_with_pipes + (NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, NULL, + &sout, &serr, &error)) + { + window = gtk_window_new (GTK_WINDOW_POPUP); + scrwin = gtk_scrolled_window_new (NULL, NULL); + gtk_container_add (GTK_CONTAINER(window), scrwin); + text_view = gtk_text_view_new (); + gtk_widget_set_size_request (window, 400, 300); + //gtk_container_add (GTK_CONTAINER(scrwin), text_view); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrwin), text_view); + gtk_widget_show_all (window); + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(text_view)); + channel = g_io_channel_unix_new (sout); + if (g_get_charset (&encoding) == FALSE) + { + g_io_channel_set_encoding (channel, encoding, NULL); + } + str = g_string_new (""); + while (g_io_channel_read_line_string (channel, str, NULL, NULL) == G_IO_STATUS_NORMAL) + { + gtk_text_buffer_insert_at_cursor (buffer, str->str, str->len); + vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW(scrwin)); + gtk_adjustment_set_value (vadj, vadj->upper); + while (g_main_context_iteration(NULL, FALSE)); + //g_print ("%s", str->str); + } + g_io_channel_shutdown (channel, FALSE, NULL); + g_io_channel_unref (channel); + channel = g_io_channel_unix_new (serr); + if (g_get_charset (&encoding) == FALSE) + { + g_io_channel_set_encoding (channel, encoding, NULL); + } + str = g_string_new (""); + if (g_io_channel_read_to_end (channel, &message, &length, NULL) == G_IO_STATUS_NORMAL) + { + if(length > 0) + { + dialog = gtk_message_dialog_new + (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "%s", message); + gtk_dialog_run (GTK_DIALOG + (dialog)); + gtk_widget_destroy (dialog); + exit_status = 1; + } + g_free (message); + } + g_io_channel_shutdown (channel, FALSE, NULL); + g_io_channel_unref (channel); + g_string_free (str, TRUE); + g_spawn_close_pid (pid); + gtk_widget_destroy (window); + } + else + { + dialog = gtk_message_dialog_new + (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "%s", error->message); + gtk_dialog_run (GTK_DIALOG + (dialog)); + gtk_widget_destroy (dialog); + exit_status = 1; + } + g_strfreev (args); +} + +/** + * \if japanese * ファイルを削除する * \endif */ gboolean cxp_remove_file (const gchar *fullpath) { GtkWidget *dialog; - GtkWidget *dialog2; gchar *filename; /* for "rm -rf" */ - gchar *error_msg; gchar *cmd; - gchar *standard_error; gint exit_status; filename = cxp_path_get_basename_of_utf8 (fullpath); @@ -428,31 +527,13 @@ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES) { - cmd = g_strdup_printf ("rm -rf '%s'", - fullpath); - g_spawn_command_line_sync (cmd, NULL, - &standard_error, - &exit_status, - NULL); - if (exit_status != 0) - { - error_msg = - g_locale_to_utf8 - (standard_error, -1, - NULL, NULL, NULL); - dialog2 = gtk_message_dialog_new - (NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "%s", error_msg); - gtk_dialog_run (GTK_DIALOG - (dialog2)); - gtk_widget_destroy (dialog2); - g_free (error_msg); - } + gtk_widget_destroy (dialog); + exit_status = cxp_remove_file_recursive (fullpath); + } + else + { + gtk_widget_destroy (dialog); } - gtk_widget_destroy (dialog); break; default: cxp_error_dialog_run_about_file (filename);