[gnome-disk-utility] Add a way to change the name of a Volume Group



commit 362da34911215f911b1b32e46bd026aebb004071
Author: David Zeuthen <davidz redhat com>
Date:   Tue Jan 12 07:10:27 2010 -0500

    Add a way to change the name of a Volume Group

 src/gdu/gdu-callbacks.h                            |    4 +
 src/gdu/gdu-pool.c                                 |   42 ++++++++++-
 src/gdu/gdu-pool.h                                 |    6 ++
 .../gdu-section-linux-lvm2-volume-group.c          |   80 ++++++++++++++++++++
 4 files changed, 131 insertions(+), 1 deletions(-)
---
diff --git a/src/gdu/gdu-callbacks.h b/src/gdu/gdu-callbacks.h
index e5dcd36..f47d060 100644
--- a/src/gdu/gdu-callbacks.h
+++ b/src/gdu/gdu-callbacks.h
@@ -176,6 +176,10 @@ typedef void (*GduPoolLinuxLvm2LVStartCompletedFunc) (GduPool    *pool,
                                                       GError     *error,
                                                       gpointer    user_data);
 
+typedef void (*GduPoolLinuxLvm2VGSetNameCompletedFunc) (GduPool    *pool,
+                                                        GError     *error,
+                                                        gpointer    user_data);
+
 /* ---------------------------------------------------------------------------------------------------- */
 /* GduDrive */
 
diff --git a/src/gdu/gdu-pool.c b/src/gdu/gdu-pool.c
index 5344c2c..6ab4d45 100644
--- a/src/gdu/gdu-pool.c
+++ b/src/gdu/gdu-pool.c
@@ -2834,7 +2834,6 @@ gdu_pool_op_linux_lvm2_vg_stop (GduPool *pool,
                                                           data);
 }
 
-
 /* ---------------------------------------------------------------------------------------------------- */
 
 typedef struct {
@@ -2881,6 +2880,47 @@ gdu_pool_op_linux_lvm2_lv_start (GduPool *pool,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+
+typedef struct {
+        GduPool *pool;
+        GduPoolLinuxLvm2VGStopCompletedFunc callback;
+        gpointer user_data;
+} LinuxLvm2VGSetNameData;
+
+static void
+op_linux_lvm2_vg_set_name_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
+{
+        LinuxLvm2VGSetNameData *data = user_data;
+        _gdu_error_fixup (error);
+        if (data->callback != NULL)
+                data->callback (data->pool, error, data->user_data);
+        g_object_unref (data->pool);
+        g_free (data);
+}
+
+void
+gdu_pool_op_linux_lvm2_vg_set_name (GduPool *pool,
+                                    const gchar *uuid,
+                                    const gchar *new_name,
+                                    GduPoolLinuxLvm2VGSetNameCompletedFunc callback,
+                                    gpointer user_data)
+{
+        LinuxLvm2VGSetNameData *data;
+
+        data = g_new0 (LinuxLvm2VGSetNameData, 1);
+        data->pool = g_object_ref (pool);
+        data->callback = callback;
+        data->user_data = user_data;
+
+        org_freedesktop_UDisks_linux_lvm2_vg_set_name_async (pool->priv->proxy,
+                                                             uuid,
+                                                             new_name,
+                                                             op_linux_lvm2_vg_set_name_cb,
+                                                             data);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 /**
  * gdu_pool_get_daemon_version:
  * @pool: A #GduPool.
diff --git a/src/gdu/gdu-pool.h b/src/gdu/gdu-pool.h
index c9135e3..1aecad3 100644
--- a/src/gdu/gdu-pool.h
+++ b/src/gdu/gdu-pool.h
@@ -149,6 +149,12 @@ void gdu_pool_op_linux_lvm2_lv_start (GduPool *pool,
                                       GduPoolLinuxLvm2VGStartCompletedFunc callback,
                                       gpointer user_data);
 
+void gdu_pool_op_linux_lvm2_vg_set_name (GduPool *pool,
+                                         const gchar *uuid,
+                                         const gchar *new_name,
+                                         GduPoolLinuxLvm2VGSetNameCompletedFunc callback,
+                                         gpointer user_data);
+
 G_END_DECLS
 
 #endif /* __GDU_POOL_H */
diff --git a/src/palimpsest/gdu-section-linux-lvm2-volume-group.c b/src/palimpsest/gdu-section-linux-lvm2-volume-group.c
index fa501be..095f55f 100644
--- a/src/palimpsest/gdu-section-linux-lvm2-volume-group.c
+++ b/src/palimpsest/gdu-section-linux-lvm2-volume-group.c
@@ -44,6 +44,7 @@ struct _GduSectionLinuxLvm2VolumeGroupPrivate
 
         GduButtonElement *vg_start_button;
         GduButtonElement *vg_stop_button;
+        GduButtonElement *vg_edit_name_button;
 };
 
 G_DEFINE_TYPE (GduSectionLinuxLvm2VolumeGroup, gdu_section_linux_lvm2_volume_group, GDU_TYPE_SECTION)
@@ -154,6 +155,73 @@ on_lvm2_vg_stop_button_clicked (GduButtonElement *button_element,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
+lvm2_vg_set_name_op_callback (GduPool   *pool,
+                              GError    *error,
+                              gpointer   user_data)
+{
+        GduShell *shell = GDU_SHELL (user_data);
+
+        if (error != NULL) {
+                GtkWidget *dialog;
+                dialog = gdu_error_dialog_new (GTK_WINDOW (gdu_shell_get_toplevel (shell)),
+                                               NULL,
+                                               _("Error setting name for Volume Group"),
+                                               error);
+                gtk_widget_show_all (dialog);
+                gtk_window_present (GTK_WINDOW (dialog));
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+                g_error_free (error);
+        }
+        g_object_unref (shell);
+}
+
+static void
+on_vg_edit_name_clicked (GduButtonElement *button_element,
+                         gpointer          user_data)
+{
+        GduSectionLinuxLvm2VolumeGroup *section = GDU_SECTION_LINUX_LVM2_VOLUME_GROUP (user_data);
+        GduLinuxLvm2VolumeGroup *vg;
+        GduPool *pool;
+        const gchar *uuid;
+        gchar *vg_name;
+        GtkWindow *toplevel;
+        GtkWidget *dialog;
+        gint response;
+
+        vg = GDU_LINUX_LVM2_VOLUME_GROUP (gdu_section_get_presentable (GDU_SECTION (section)));
+        pool = gdu_presentable_get_pool (GDU_PRESENTABLE (vg));
+        uuid = gdu_linux_lvm2_volume_group_get_uuid (vg);
+        vg_name = gdu_presentable_get_name (GDU_PRESENTABLE (vg));
+
+        toplevel = GTK_WINDOW (gdu_shell_get_toplevel (gdu_section_get_shell (GDU_SECTION (section))));
+        dialog = gdu_edit_name_dialog_new (toplevel,
+                                           GDU_PRESENTABLE (vg),
+                                           vg_name,
+                                           256,
+                                           _("Choose a new Volume Group name."),
+                                           _("_Name:"));
+        gtk_widget_show_all (dialog);
+        response = gtk_dialog_run (GTK_DIALOG (dialog));
+        if (response == GTK_RESPONSE_APPLY) {
+                gchar *new_name;
+                new_name = gdu_edit_name_dialog_get_name (GDU_EDIT_NAME_DIALOG (dialog));
+                gdu_pool_op_linux_lvm2_vg_set_name (pool,
+                                                    uuid,
+                                                    new_name,
+                                                    lvm2_vg_set_name_op_callback,
+                                                    g_object_ref (gdu_section_get_shell (GDU_SECTION (section))));
+                g_free (new_name);
+        }
+        gtk_widget_destroy (dialog);
+
+        g_object_unref (pool);
+        g_free (vg_name);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
 gdu_section_linux_lvm2_volume_group_update (GduSection *_section)
 {
         GduSectionLinuxLvm2VolumeGroup *section = GDU_SECTION_LINUX_LVM2_VOLUME_GROUP (_section);
@@ -336,6 +404,18 @@ gdu_section_linux_lvm2_volume_group_constructed (GObject *object)
         section->priv->vg_stop_button = button_element;
         g_ptr_array_add (elements, button_element);
 
+        /* TODO: better icon */
+        button_element = gdu_button_element_new (GTK_STOCK_BOLD,
+                                                 _("Edit _Name"),
+                                                 _("Change the Volume Group name"));
+        g_signal_connect (button_element,
+                          "clicked",
+                          G_CALLBACK (on_vg_edit_name_clicked),
+                          section);
+        g_ptr_array_add (elements, button_element);
+        section->priv->vg_edit_name_button = button_element;
+
+
         gdu_button_table_set_elements (GDU_BUTTON_TABLE (table), elements);
         g_ptr_array_unref (elements);
 



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