Commit f0c45c90 authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Show errors on unmount/eject failing.

2007-12-07  Alexander Larsson  <alexl@redhat.com>

        * libnautilus-private/nautilus-file-operations.[ch]:
        * src/file-manager/fm-tree-view.c:
        * src/nautilus-places-sidebar.c:
	Show errors on unmount/eject failing.


svn path=/trunk/; revision=13504
parent 48757eb4
2007-12-07 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.[ch]:
* src/file-manager/fm-tree-view.c:
* src/nautilus-places-sidebar.c:
Show errors on unmount/eject failing.
2007-12-07 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.[ch]:
......
......@@ -662,11 +662,28 @@ custom_time_skip (va_list *va)
va_arg (*va, int);
}
static char *
custom_volume_to_string (char *format, va_list va)
{
GVolume *volume;
volume = va_arg (va, GVolume *);
return g_volume_get_name (volume);
}
static void
custom_volume_skip (va_list *va)
{
va_arg (*va, GVolume *);
}
static EelPrintfHandler handlers[] = {
{ 'F', custom_full_name_to_string, custom_full_name_skip },
{ 'B', custom_basename_to_string, custom_basename_skip },
{ 'S', custom_size_to_string, custom_size_skip },
{ 'T', custom_time_to_string, custom_time_skip },
{ 'V', custom_volume_to_string, custom_volume_skip },
{ 0 }
};
......@@ -1679,9 +1696,8 @@ nautilus_file_operations_delete (GList *files,
typedef struct {
gboolean eject;
NautilusUnmountCallback callback;
gpointer user_data;
GVolume *volume;
GtkWindow *parent_window;
} UnmountData;
static void
......@@ -1691,20 +1707,26 @@ unmount_volume_callback (GObject *source_object,
{
UnmountData *data = user_data;
GError *error;
char *primary;
error = NULL;
g_volume_unmount_finish (G_VOLUME (source_object),
res, &error);
if (data->callback) {
data->callback (error, data->user_data);
}
if (error) {
/* TODO: Display dialog */
if (!g_volume_unmount_finish (G_VOLUME (source_object),
res, &error)) {
if (data->eject) {
primary = f (_("Unable to eject %V"), source_object);
} else {
primary = f (_("Unable to unmount %V"), source_object);
}
eel_show_error_dialog (primary,
error->message,
data->parent_window);
g_free (primary);
g_error_free (error);
}
if (data->parent_window) {
g_object_unref (data->parent_window);
}
g_object_unref (data->volume);
g_free (data);
}
......@@ -1806,9 +1828,6 @@ has_trash_files (GVolume *volume)
for (l = dirs; l != NULL; l = l->next) {
dir = l->data;
g_print ("dir: %s\n", g_file_get_path (dir));
if (dir_has_files (dir)) {
res = TRUE;
break;
......@@ -1870,19 +1889,16 @@ prompt_empty_trash (GtkWindow *parent_window)
void
nautilus_file_operations_unmount_volume (GtkWindow *parent_window,
GVolume *volume,
gboolean eject,
NautilusUnmountCallback callback,
gpointer user_data)
gboolean eject)
{
UnmountData *data;
int response;
g_print ("nautilus_file_operations_unmount_volume\n");
data = g_new0 (UnmountData, 1);
if (parent_window) {
data->parent_window = g_object_ref (parent_window);
}
data->eject = eject;
data->callback = callback;
data->user_data = user_data;
data->volume = g_object_ref (volume);
if (has_trash_files (volume)) {
......@@ -1902,8 +1918,8 @@ nautilus_file_operations_unmount_volume (GtkWindow *parent_
NULL);
return;
} else if (response == GTK_RESPONSE_CANCEL) {
if (data->callback) {
data->callback (NULL, user_data);
if (data->parent_window) {
g_object_unref (data->parent_window);
}
g_object_unref (data->volume);
g_free (data);
......
......@@ -38,8 +38,6 @@ typedef void (* NautilusCreateCallback) (GFile *new_file,
typedef void (* NautilusOpCallback) (gpointer callback_data);
typedef void (* NautilusDeleteCallback) (GHashTable *debuting_uris,
gpointer callback_data);
typedef void (* NautilusUnmountCallback) (GError *error,
gpointer callback_data);
/* FIXME: int copy_action should be an enum */
......@@ -90,9 +88,7 @@ void nautilus_file_set_permissions_recursive (const char *di
void nautilus_file_operations_unmount_volume (GtkWindow *parent_window,
GVolume *volume,
gboolean eject,
NautilusUnmountCallback callback,
gpointer user_data);
gboolean eject);
void nautilus_file_operations_copy (GList *files,
......
......@@ -745,7 +745,7 @@ button_pressed_callback (GtkTreeView *treeview, GdkEventButton *event,
volume = fm_tree_model_get_volume_for_root_node_file (view->details->child_model, view->details->popup_file);
if (volume) {
show_unmount = TRUE;
show_unmount = g_volume_can_unmount (volume) || g_volume_can_eject (volume);
unmount_is_eject = g_volume_can_eject (volume);
}
......@@ -1098,8 +1098,7 @@ fm_tree_view_unmount_cb (GtkWidget *menu_item,
if (volume != NULL) {
nautilus_file_operations_unmount_volume (fm_tree_view_get_containing_window (view),
volume,
g_volume_can_eject (volume),
NULL, NULL);
g_volume_can_eject (volume));
}
}
......
......@@ -1343,11 +1343,9 @@ unmount_shortcut_cb (GtkMenuItem *item,
if (volume != NULL) {
GtkWidget *toplevel;
/* TODO-gio: Handle callbacks etc */
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (sidebar->tree_view));
nautilus_file_operations_unmount_volume (GTK_WINDOW (toplevel),
volume, FALSE, NULL, sidebar);
volume, FALSE);
}
if (volume != NULL) {
g_object_unref (volume);
......@@ -1375,8 +1373,12 @@ eject_shortcut_cb (GtkMenuItem *item,
-1);
if (volume != NULL) {
/* TODO-gio: Handle callbacks etc */
g_volume_eject (volume, NULL, NULL, sidebar);
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (sidebar->tree_view));
nautilus_file_operations_unmount_volume (GTK_WINDOW (toplevel),
volume,
TRUE);
} else if (drive != NULL) {
/* TODO-gio: Handle callbacks etc */
g_drive_eject (drive, NULL, NULL, sidebar);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment