[gnome-disk-utility/filesystem-label-suggestion] Suggest filesystem label when formatting
- From: Kai Lüke <kailueke src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-disk-utility/filesystem-label-suggestion] Suggest filesystem label when formatting
- Date: Sun, 7 Apr 2019 23:50:57 +0000 (UTC)
commit a177be608e32b3ba496b8f7954f6f4acf63d8f8c
Author: Kai Lüke <kailueke riseup net>
Date: Sun Apr 7 23:40:38 2019 +0200
Suggest filesystem label when formatting
The format dialog required the used to specify
the filesystem label in order to proceed.
Lift this restriction and provide a default
filesystem label based on a heuristic device identifier
and the partition size.
Original discussion in:
https://gitlab.gnome.org/GNOME/gnome-disk-utility/merge_requests/5
src/disks/gducreatefilesystempage.c | 84 ++++++++++++++++++++++++++++++++-----
src/disks/gducreatefilesystempage.h | 6 ++-
src/disks/gducreateformatdialog.c | 6 ++-
3 files changed, 83 insertions(+), 13 deletions(-)
---
diff --git a/src/disks/gducreatefilesystempage.c b/src/disks/gducreatefilesystempage.c
index c4b5cd8d..faf579ed 100644
--- a/src/disks/gducreatefilesystempage.c
+++ b/src/disks/gducreatefilesystempage.c
@@ -29,7 +29,9 @@ struct _GduCreateFilesystemPagePrivate
GtkRadioButton *all_radiobutton;
GtkRadioButton *other_radiobutton;
- gboolean complete;
+ UDisksClient *client;
+ UDisksDrive *drive;
+ UDisksObject *object;
};
enum
@@ -52,15 +54,10 @@ gdu_create_filesystem_page_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- GduCreateFilesystemPage *page = GDU_CREATE_FILESYSTEM_PAGE (object);
- GduCreateFilesystemPagePrivate *priv;
-
- priv = gdu_create_filesystem_page_get_instance_private (page);
-
switch (property_id)
{
case PROP_COMPLETE:
- g_value_set_boolean (value, priv->complete);
+ g_value_set_boolean (value, TRUE);
break;
default:
@@ -162,9 +159,6 @@ on_fs_name_changed (GObject *object, GParamSpec *pspec, gpointer user_data)
priv = gdu_create_filesystem_page_get_instance_private (page);
- priv->complete = gtk_entry_get_text_length (priv->name_entry) > 0; /* require a label */
- g_object_notify (G_OBJECT (page), "complete");
-
_gtk_entry_buffer_truncate_bytes (gtk_entry_get_buffer (priv->name_entry),
gdu_utils_get_max_label_length (gdu_create_filesystem_page_get_fs
(page)));
}
@@ -182,14 +176,82 @@ on_fs_type_changed (GtkToggleButton *object, gpointer user_data)
g_object_notify (G_OBJECT (page), "complete");
}
+void
+gdu_create_filesystem_page_fill_name (GduCreateFilesystemPage *page, guint64 size_info)
+{
+ GduCreateFilesystemPagePrivate *priv;
+ gchar *size_display;
+ UDisksObjectInfo *info;
+ gchar *identification;
+ gchar *name;
+
+ /* Suggest an appropriate name for the filesystem, combining an identifier and the size.
+ * Start with the vendor, and if not available, fallback to the model or the UDisks object name.
+ * Take only the first part of the model. If no model information is available, look at
+ * the UDisks object name, which might be a path to a device mapper mount point or a loopback
+ * file, and just take the last part (only until a delimiter is observed).
+ */
+ priv = gdu_create_filesystem_page_get_instance_private (page);
+ size_display = udisks_client_get_size_for_display (priv->client, size_info, FALSE, FALSE);
+ info = udisks_client_get_object_info (priv->client, priv->object);
+ identification = g_strdup (priv->drive != NULL ? udisks_drive_get_vendor (priv->drive) : "");
+ if (identification == NULL || strlen (identification) == 0)
+ {
+ gchar **maybe_long_name;
+
+ maybe_long_name = g_strsplit_set (priv->drive != NULL ? udisks_drive_get_model (priv->drive) : "", "_-
/", 0);
+ if (maybe_long_name != NULL)
+ {
+ g_free (identification);
+ identification = g_strdup (maybe_long_name[0]);
+ }
+
+ g_strfreev (maybe_long_name);
+ }
+ if (identification == NULL || strlen (identification) == 0)
+ {
+ gchar **maybe_path_name;
+
+ maybe_path_name = g_strsplit (udisks_object_info_get_name (info), "/", 0);
+ if (maybe_path_name != NULL)
+ {
+ gchar **maybe_uuid;
+
+ maybe_uuid = g_strsplit_set (maybe_path_name[g_strv_length (maybe_path_name) - 1], "-_ ", 0);
+ if (maybe_uuid != NULL)
+ {
+ g_free (identification);
+ identification = g_strdup (maybe_uuid[0]);
+ }
+
+ g_strfreev (maybe_uuid);
+ }
+
+ g_strfreev (maybe_path_name);
+ }
+
+ name = g_strdup_printf ("%s %s", identification, size_display); /* No translation needed. */
+ gtk_entry_set_text (priv->name_entry, name);
+ _gtk_entry_buffer_truncate_bytes (gtk_entry_get_buffer (priv->name_entry),
+ gdu_utils_get_max_label_length (gdu_create_filesystem_page_get_fs
(page)));
+
+ g_free (size_display);
+ g_free (identification);
+ g_free (name);
+ g_object_unref (info);
+}
+
GduCreateFilesystemPage *
-gdu_create_filesystem_page_new (UDisksClient *client, gboolean show_custom, UDisksDrive *drive)
+gdu_create_filesystem_page_new (UDisksClient *client, gboolean show_custom, UDisksDrive *drive, UDisksObject
*object)
{
GduCreateFilesystemPage *page;
GduCreateFilesystemPagePrivate *priv;
page = g_object_new (GDU_TYPE_CREATE_FILESYSTEM_PAGE, NULL);
priv = gdu_create_filesystem_page_get_instance_private (page);
+ priv->client = client;
+ priv->drive = drive;
+ priv->object = object;
g_signal_connect (priv->name_entry, "notify::text", G_CALLBACK (on_fs_name_changed), page);
g_signal_connect (priv->internal_encrypt_checkbutton, "toggled", G_CALLBACK (on_fs_type_changed), page);
g_signal_connect (priv->internal_radiobutton, "toggled", G_CALLBACK (on_fs_type_changed), page);
diff --git a/src/disks/gducreatefilesystempage.h b/src/disks/gducreatefilesystempage.h
index af38c055..9963fb8c 100644
--- a/src/disks/gducreatefilesystempage.h
+++ b/src/disks/gducreatefilesystempage.h
@@ -19,7 +19,8 @@ G_DECLARE_FINAL_TYPE (GduCreateFilesystemPage, gdu_create_filesystem_page, GDU,
GduCreateFilesystemPage *gdu_create_filesystem_page_new (UDisksClient *client,
gboolean show_custom,
- UDisksDrive *drive);
+ UDisksDrive *drive,
+ UDisksObject *object);
const gchar * gdu_create_filesystem_page_get_name (GduCreateFilesystemPage *page);
@@ -31,6 +32,9 @@ gboolean gdu_create_filesystem_page_is_encrypted (GduCreateFiles
const gchar * gdu_create_filesystem_page_get_erase (GduCreateFilesystemPage *page);
+void gdu_create_filesystem_page_fill_name (GduCreateFilesystemPage *page,
+ guint64 size_info);
+
G_END_DECLS
#endif /* __GDU_CREATE_FILESYSTEM_PAGE_H__ */
diff --git a/src/disks/gducreateformatdialog.c b/src/disks/gducreateformatdialog.c
index 626b9489..e2c53c82 100644
--- a/src/disks/gducreateformatdialog.c
+++ b/src/disks/gducreateformatdialog.c
@@ -104,6 +104,7 @@ update_dialog (GtkWidget *widget, GParamSpec *child_property, CreateFormatData *
gboolean complete = FALSE;
GtkWidget *child;
gpointer page = NULL;
+ guint64 size_info = 0;
g_value_init (&title, G_TYPE_STRING);
child = gtk_stack_get_child_by_name (data->stack, data->current);
@@ -134,6 +135,9 @@ update_dialog (GtkWidget *widget, GParamSpec *child_property, CreateFormatData *
if (gdu_create_filesystem_page_is_encrypted (data->filesystem_page))
data->next = PASSWORD_PAGE;
+
+ size_info = data->add_partition ? gdu_create_partition_page_get_size (data->partition_page) :
udisks_block_get_size (data->block);
+ gdu_create_filesystem_page_fill_name (data->filesystem_page, size_info);
}
else if (g_strcmp0 (data->current, OTHER_PAGE) == 0)
{
@@ -440,7 +444,7 @@ gdu_create_format_show (UDisksClient *client,
data->partition_page = NULL;
}
- data->filesystem_page = gdu_create_filesystem_page_new (data->client, show_custom, data->drive);
+ data->filesystem_page = gdu_create_filesystem_page_new (data->client, show_custom, data->drive,
data->object);
gtk_stack_add_titled (data->stack, GTK_WIDGET (data->filesystem_page), FORMAT_PAGE, _("Format Volume"));
g_signal_connect (data->filesystem_page, "notify::complete", G_CALLBACK (update_dialog), data);
data->other_page = gdu_create_other_page_new (data->client);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]