[gnome-disk-utility] volume-menu: Add take ownership button



commit 3b5f5b8e7fe9a6c7459889d224969a510d66e858
Author: Manuel Wassermann <manuel wassermann97 gmail com>
Date:   Sun Jul 11 23:49:07 2021 +0200

    volume-menu: Add take ownership button
    
    Fixes: #207

 src/disks/gduwindow.c       | 51 +++++++++++++++++++++++++++++++++++++++++++++
 src/disks/ui/volume-menu.ui |  4 ++++
 src/libgdu/gduutils.c       | 12 +++++++++++
 src/libgdu/gduutils.h       |  2 ++
 4 files changed, 69 insertions(+)
---
diff --git a/src/disks/gduwindow.c b/src/disks/gduwindow.c
index f900fd88..239bd5a6 100644
--- a/src/disks/gduwindow.c
+++ b/src/disks/gduwindow.c
@@ -229,6 +229,7 @@ typedef enum
   SHOW_FLAGS_VOLUME_MENU_RESIZE                = (1<<9),
   SHOW_FLAGS_VOLUME_MENU_REPAIR                = (1<<10),
   SHOW_FLAGS_VOLUME_MENU_CHECK                 = (1<<11),
+  SHOW_FLAGS_VOLUME_MENU_TAKE_OWNERSHIP        = (1<<12),
 } ShowFlagsVolumeMenu;
 
 typedef struct
@@ -308,6 +309,9 @@ static void on_volume_menu_item_resize (GSimpleAction *action,
 static void on_volume_menu_item_repair (GSimpleAction *action,
                                         GVariant      *parameter,
                                         gpointer       user_data);
+static void on_volume_menu_item_take_ownership (GSimpleAction *action,
+                                                GVariant      *parameter,
+                                                gpointer       user_data);
 static void on_volume_menu_item_check (GSimpleAction *action,
                                        GVariant      *parameter,
                                        gpointer       user_data);
@@ -371,6 +375,7 @@ static const GActionEntry actions[] = {
        { "resize", on_volume_menu_item_resize },
        { "check-fs", on_volume_menu_item_check },
        { "repair-fs", on_volume_menu_item_repair },
+       { "take-ownership", on_volume_menu_item_take_ownership },
 
        { "configure-fstab", on_volume_menu_item_configure_fstab },
        { "configure-crypttab", on_volume_menu_item_configure_crypttab },
@@ -515,6 +520,9 @@ update_for_show_flags (GduWindow *window,
   g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (window),
                               "repair-fs")),
                               show_flags->volume_menu & SHOW_FLAGS_VOLUME_MENU_REPAIR);
+  g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (window),
+                              "take-ownership")),
+                               show_flags->volume_menu & SHOW_FLAGS_VOLUME_MENU_TAKE_OWNERSHIP);
   g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (window),
                               "check-fs")),
                               show_flags->volume_menu & SHOW_FLAGS_VOLUME_MENU_CHECK);
@@ -2676,6 +2684,9 @@ update_device_page_for_block (GduWindow          *window,
       if (!read_only && gdu_utils_can_repair (window->client, type, FALSE, NULL))
         show_flags->volume_menu |= SHOW_FLAGS_VOLUME_MENU_REPAIR;
 
+      if (!read_only && gdu_utils_can_take_ownership (type))
+        show_flags->volume_menu |= SHOW_FLAGS_VOLUME_MENU_TAKE_OWNERSHIP;
+
       if (gdu_utils_can_check (window->client, type, FALSE, NULL))
         show_flags->volume_menu |= SHOW_FLAGS_VOLUME_MENU_CHECK;
     }
@@ -3066,6 +3077,46 @@ on_volume_menu_item_repair (GSimpleAction *action,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+static void
+fs_take_ownership_cb (UDisksFilesystem *filesystem,
+                      GAsyncResult     *res,
+                      GduWindow        *window)
+{
+  GError *error = NULL;
+
+  if (!udisks_filesystem_call_take_ownership_finish (filesystem, res, &error))
+    {
+      gdu_utils_show_error (GTK_WINDOW (window),
+                            _("Error while taking filesystem ownership"),
+                            error);
+
+      g_error_free (error);
+    }
+}
+
+static void
+on_volume_menu_item_take_ownership (GSimpleAction *action,
+                                    GVariant      *parameter,
+                                    gpointer       user_data)
+{
+  GduWindow *window;
+  UDisksObject *object;
+  UDisksFilesystem *filesystem;
+
+  window = GDU_WINDOW (user_data);
+  object = gdu_volume_grid_get_selected_device (GDU_VOLUME_GRID (window->volume_grid));
+  g_assert (object != NULL);
+
+  filesystem = udisks_object_peek_filesystem (object);
+  udisks_filesystem_call_take_ownership (filesystem,
+                                         g_variant_new ("a{sv}", NULL),
+                                         NULL,
+                                         (GAsyncReadyCallback) fs_take_ownership_cb,
+                                         window);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 static void
 fs_check_cb (UDisksFilesystem *filesystem,
              GAsyncResult     *res,
diff --git a/src/disks/ui/volume-menu.ui b/src/disks/ui/volume-menu.ui
index b780c544..3cabc2ff 100644
--- a/src/disks/ui/volume-menu.ui
+++ b/src/disks/ui/volume-menu.ui
@@ -34,6 +34,10 @@
         <attribute name="label" translatable="yes">Rep_air Filesystem…</attribute>
         <attribute name="action">win.repair-fs</attribute>
       </item>
+      <item>
+        <attribute name="label" translatable="yes">_Take Ownership</attribute>
+        <attribute name="action">win.take-ownership</attribute>
+      </item>
     </section>
     <section>
       <item>
diff --git a/src/libgdu/gduutils.c b/src/libgdu/gduutils.c
index 997019a8..a7c437bd 100644
--- a/src/libgdu/gduutils.c
+++ b/src/libgdu/gduutils.c
@@ -1013,6 +1013,18 @@ gdu_utils_can_repair (UDisksClient *client,
   return result ? result->available : FALSE;
 }
 
+gboolean
+gdu_utils_can_take_ownership (const gchar *fstype)
+{
+  if (g_strcmp0 (fstype, "ntfs") == 0 ||
+      g_strcmp0 (fstype, "vfat") == 0 ||
+      g_strcmp0 (fstype, "exfat") == 0)
+    {
+      return FALSE;
+    }
+  return TRUE;
+}
+
 G_LOCK_DEFINE (can_check_lock);
 
 gboolean
diff --git a/src/libgdu/gduutils.h b/src/libgdu/gduutils.h
index e54a56a6..de1f7c66 100644
--- a/src/libgdu/gduutils.h
+++ b/src/libgdu/gduutils.h
@@ -98,6 +98,8 @@ gboolean gdu_utils_can_repair (UDisksClient *client,
                                gboolean      flush,
                                gchar       **missing_util_out);
 
+gboolean gdu_utils_can_take_ownership (const gchar  *fstype);
+
 gboolean gdu_utils_can_check  (UDisksClient *client,
                                const gchar  *fstype,
                                gboolean      flush,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]