Commit 16d581bc authored by Mitchell Horne's avatar Mitchell Horne Committed by Kai Lüke

Add unmount function to edit filesystem dialog

Currently, attempting to change the label of a mounted filesystem will
fail for most filesystem types, with no warning of this presented to the
user.

Change this so that the filesystem will be unmounted prior to changing
the label if it is currently mounted and not of type extY. A warning will
be presented to the user when this is to occur.

https://bugzilla.gnome.org/show_bug.cgi?id=784619
parent acb5b1c7
......@@ -27,6 +27,13 @@ typedef struct
guint label_max_length;
} ChangeFilesystemLabelData;
typedef struct
{
GduWindow *window;
UDisksFilesystem *filesystem;
gchar *new_label;
} EditFilesystemData;
static void
change_filesystem_label_data_free (ChangeFilesystemLabelData *data)
{
......@@ -36,6 +43,17 @@ change_filesystem_label_data_free (ChangeFilesystemLabelData *data)
g_free (data);
}
static void
edit_filesystem_data_free (EditFilesystemData *data)
{
if (data->window != NULL)
g_object_unref (data->window);
if (data->filesystem != NULL)
g_object_unref (data->filesystem);
g_free (data->new_label);
g_free (data);
}
static void
on_change_filesystem_label_entry_changed (GtkEditable *editable,
gpointer user_data)
......@@ -94,6 +112,35 @@ change_filesystem_label_cb (UDisksFilesystem *filesystem,
g_object_unref (window);
}
static void
ensure_unused_cb (UDisksObject *object,
GAsyncResult *res,
gpointer user_data)
{
EditFilesystemData *data = user_data;
GError *error = NULL;
if (!gdu_window_ensure_unused_finish (data->window,
res,
&error))
{
gdu_utils_show_error (GTK_WINDOW (data->window),
_("Error unmounting filesystem"),
error);
g_error_free (error);
}
else
{
udisks_filesystem_call_set_label (data->filesystem,
data->new_label,
g_variant_new ("a{sv}", NULL), /* options */
NULL, /* cancellable */
(GAsyncReadyCallback) change_filesystem_label_cb,
g_object_ref (data->window));
}
edit_filesystem_data_free (data);
}
void
gdu_filesystem_dialog_show (GduWindow *window,
UDisksObject *object)
......@@ -102,12 +149,16 @@ gdu_filesystem_dialog_show (GduWindow *window,
GtkBuilder *builder;
GtkWidget *dialog;
GtkWidget *entry;
GtkWidget *unmount_warning_label;
UDisksBlock *block;
UDisksFilesystem *filesystem;
const gchar *label;
EditFilesystemData *filesystem_data;
ChangeFilesystemLabelData *label_data;
const gchar *label_to_set;
gchar *fstype;
const gchar *const *mount_points;
gboolean needs_unmount;
block = udisks_object_peek_block (object);
filesystem = udisks_object_peek_filesystem (object);
......@@ -119,6 +170,9 @@ gdu_filesystem_dialog_show (GduWindow *window,
"change-filesystem-label-dialog",
&builder));
entry = GTK_WIDGET (gtk_builder_get_object (builder, "change-filesystem-label-entry"));
unmount_warning_label = GTK_WIDGET (gtk_builder_get_object (builder,
"unmount-warning-label"));
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
......@@ -139,18 +193,41 @@ gdu_filesystem_dialog_show (GduWindow *window,
gtk_widget_show_all (dialog);
gtk_widget_grab_focus (entry);
mount_points = udisks_filesystem_get_mount_points (filesystem);
needs_unmount = g_strv_length ((gchar **) mount_points) > 0;
needs_unmount &= g_strcmp0 (fstype, "ext2") != 0;
needs_unmount &= g_strcmp0 (fstype, "ext3") != 0;
needs_unmount &= g_strcmp0 (fstype, "ext4") != 0;
if (!needs_unmount)
gtk_widget_hide (unmount_warning_label);
response = gtk_dialog_run (GTK_DIALOG (dialog));
if (response != GTK_RESPONSE_OK)
goto out;
label_to_set = gtk_entry_get_text (GTK_ENTRY (entry));
udisks_filesystem_call_set_label (filesystem,
label_to_set,
g_variant_new ("a{sv}", NULL), /* options */
NULL, /* cancellable */
(GAsyncReadyCallback) change_filesystem_label_cb,
g_object_ref (window));
if (needs_unmount)
{
filesystem_data = g_new (EditFilesystemData, 1);
filesystem_data->window = g_object_ref (window);
filesystem_data->filesystem = g_object_ref (filesystem);
filesystem_data->new_label = g_strdup (label_to_set);
gdu_window_ensure_unused (window,
object,
(GAsyncReadyCallback) ensure_unused_cb,
NULL, /* cancellable */
filesystem_data);
}
else
{
udisks_filesystem_call_set_label (filesystem,
label_to_set,
g_variant_new ("a{sv}", NULL), /* options */
NULL, /* cancellable */
(GAsyncReadyCallback) change_filesystem_label_cb,
g_object_ref (window));
}
out:
g_free (fstype);
......
......@@ -58,6 +58,23 @@
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="unmount-warning-label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="label" translatable="yes">This filesystem will be automatically unmounted prior to any changes.</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
......@@ -88,6 +105,7 @@
<object class="GtkEntry" id="change-filesystem-label-entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="invisible_char"></property>
<property name="activates_default">True</property>
</object>
......
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