[gnome-disk-utility/new-ui] Add a GduConfirmationDialog and use it for deleting partitions



commit 919f4592daacb02150b1bdd8284ac536de46f62c
Author: David Zeuthen <davidz redhat com>
Date:   Sat Oct 3 13:19:35 2009 -0400

    Add a GduConfirmationDialog and use it for deleting partitions

 doc/gnome-disk-utility-docs.xml       |    1 +
 doc/gnome-disk-utility.types          |    1 +
 src/gdu-gtk/Makefile.am               |    2 +
 src/gdu-gtk/gdu-confirmation-dialog.c |  260 +++++++++++++++++++++++++++++++++
 src/gdu-gtk/gdu-confirmation-dialog.h |   70 +++++++++
 src/gdu-gtk/gdu-gtk-types.h           |    1 +
 src/gdu-gtk/gdu-gtk.h                 |    1 +
 src/palimpsest/gdu-section-volumes.c  |   62 ++++++++-
 8 files changed, 396 insertions(+), 2 deletions(-)
---
diff --git a/doc/gnome-disk-utility-docs.xml b/doc/gnome-disk-utility-docs.xml
index 2aa6839..0eaca35 100644
--- a/doc/gnome-disk-utility-docs.xml
+++ b/doc/gnome-disk-utility-docs.xml
@@ -82,6 +82,7 @@
     <xi:include href="xml/gdu-create-linux-md-dialog.xml"/>
     <xi:include href="xml/gdu-edit-partition-dialog.xml"/>
     <xi:include href="xml/gdu-error-dialog.xml"/>
+    <xi:include href="xml/gdu-confirmation-dialog.xml"/>
     <xi:include href="xml/gdu-gtk-enums.xml"/>
     <xi:include href="xml/gdu-gtk-enumtypes.xml"/>
     <xi:include href="xml/gdu-gtk.xml"/>
diff --git a/doc/gnome-disk-utility.types b/doc/gnome-disk-utility.types
index 8bf88c8..34688e7 100644
--- a/doc/gnome-disk-utility.types
+++ b/doc/gnome-disk-utility.types
@@ -25,3 +25,4 @@ gdu_pool_tree_view_flags_get_type
 gdu_pool_tree_model_flags_get_type
 gdu_dialog_get_type
 gdu_details_element_get_type
+gdu_confirmation_dialog_get_type
diff --git a/src/gdu-gtk/Makefile.am b/src/gdu-gtk/Makefile.am
index 5980999..6af26f1 100644
--- a/src/gdu-gtk/Makefile.am
+++ b/src/gdu-gtk/Makefile.am
@@ -41,6 +41,7 @@ libgdu_gtkinclude_HEADERS =              				\
 	gdu-details-table.h						\
 	gdu-details-element.h						\
 	gdu-error-dialog.h						\
+	gdu-confirmation-dialog.h					\
 	gdu-button-element.h						\
 	gdu-button-table.h						\
 	gdu-dialog.h							\
@@ -63,6 +64,7 @@ libgdu_gtk_la_SOURCES =                 	               				\
 	gdu-details-table.h			gdu-details-table.c			\
 	gdu-details-element.h			gdu-details-element.c			\
 	gdu-error-dialog.h			gdu-error-dialog.c			\
+	gdu-confirmation-dialog.h		gdu-confirmation-dialog.c		\
 	gdu-button-element.h			gdu-button-element.c			\
 	gdu-button-table.h			gdu-button-table.c			\
 	gdu-dialog.h				gdu-dialog.c				\
diff --git a/src/gdu-gtk/gdu-confirmation-dialog.c b/src/gdu-gtk/gdu-confirmation-dialog.c
new file mode 100644
index 0000000..2915d77
--- /dev/null
+++ b/src/gdu-gtk/gdu-confirmation-dialog.c
@@ -0,0 +1,260 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/* gdu-confirmation-dialog.c
+ *
+ * Copyright (C) 2009 David Zeuthen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <glib/gi18n.h>
+#include <atasmart.h>
+#include <glib/gstdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "gdu-confirmation-dialog.h"
+
+struct GduConfirmationDialogPrivate
+{
+        gchar          *message;
+};
+
+enum
+{
+        PROP_0,
+        PROP_MESSAGE,
+};
+
+
+G_DEFINE_TYPE (GduConfirmationDialog, gdu_confirmation_dialog, GDU_TYPE_DIALOG)
+
+static void
+gdu_confirmation_dialog_finalize (GObject *object)
+{
+        GduConfirmationDialog *dialog = GDU_CONFIRMATION_DIALOG (object);
+
+        g_free (dialog->priv->message);
+
+        if (G_OBJECT_CLASS (gdu_confirmation_dialog_parent_class)->finalize != NULL)
+                G_OBJECT_CLASS (gdu_confirmation_dialog_parent_class)->finalize (object);
+}
+
+static void
+gdu_confirmation_dialog_get_property (GObject    *object,
+                                      guint       property_id,
+                                      GValue     *value,
+                                      GParamSpec *pspec)
+{
+        GduConfirmationDialog *dialog = GDU_CONFIRMATION_DIALOG (object);
+
+        switch (property_id) {
+        case PROP_MESSAGE:
+                g_value_set_string (value, dialog->priv->message);
+                break;
+
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                break;
+        }
+}
+
+static void
+gdu_confirmation_dialog_set_property (GObject      *object,
+                                      guint         property_id,
+                                      const GValue *value,
+                                      GParamSpec   *pspec)
+{
+        GduConfirmationDialog *dialog = GDU_CONFIRMATION_DIALOG (object);
+
+        switch (property_id) {
+        case PROP_MESSAGE:
+                dialog->priv->message = g_value_dup_string (value);
+                break;
+
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                break;
+        }
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+gdu_confirmation_dialog_constructed (GObject *object)
+{
+        GduConfirmationDialog *dialog = GDU_CONFIRMATION_DIALOG (object);
+        GtkWidget *content_area;
+        GtkWidget *hbox;
+        GtkWidget *vbox;
+        GtkWidget *image;
+        GtkWidget *label;
+        gchar *s;
+        GIcon *icon;
+        GEmblem *emblem;
+        GIcon *confirmation_icon;
+        GIcon *emblemed_icon;
+        gchar *name;
+        gchar *vpd_name;
+
+        icon = NULL;
+        name = NULL;
+        vpd_name = NULL;
+
+        gtk_window_set_title (GTK_WINDOW (dialog), _(""));
+        gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+        gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
+
+        gtk_dialog_add_button (GTK_DIALOG (dialog),
+                               GTK_STOCK_CANCEL,
+                               GTK_RESPONSE_CANCEL);
+
+        gtk_dialog_add_button (GTK_DIALOG (dialog),
+                               GTK_STOCK_DELETE,
+                               GTK_RESPONSE_OK);
+
+        content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+
+        icon = gdu_presentable_get_icon (gdu_dialog_get_presentable (GDU_DIALOG (dialog)));
+        confirmation_icon = g_themed_icon_new (GTK_STOCK_DIALOG_WARNING);
+        emblem = g_emblem_new (icon);
+        emblemed_icon = g_emblemed_icon_new (confirmation_icon,
+                                             emblem);
+
+        hbox = gtk_hbox_new (FALSE, 12);
+        gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
+
+        image = gtk_image_new_from_gicon (emblemed_icon,
+                                          GTK_ICON_SIZE_DIALOG);
+        gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
+        gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+
+        vbox = gtk_vbox_new (FALSE, 12);
+        gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
+
+        s = g_strdup_printf ("<big><big><b>%s</b></big></big>",
+                             dialog->priv->message);
+        label = gtk_label_new (NULL);
+        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+        gtk_label_set_markup (GTK_LABEL (label), s);
+        g_free (s);
+        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+        name = gdu_presentable_get_name (gdu_dialog_get_presentable (GDU_DIALOG (dialog)));
+        vpd_name = gdu_presentable_get_vpd_name (gdu_dialog_get_presentable (GDU_DIALOG (dialog)));
+        if (GDU_IS_VOLUME (gdu_dialog_get_presentable (GDU_DIALOG (dialog)))) {
+                s = g_strdup_printf (_("This operation concerns the volume \"%s\" (%s)"),
+                                     name,
+                                     vpd_name);
+        } else if (GDU_IS_DRIVE (gdu_dialog_get_presentable (GDU_DIALOG (dialog)))) {
+                s = g_strdup_printf (_("This operation concerns the drive \"%s\" (%s)"),
+                                     name,
+                                     vpd_name);
+        } else {
+                s = g_strdup_printf (_("This operation concerns \"%s\" (%s)"),
+                                     name,
+                                     vpd_name);
+        }
+
+        label = gtk_label_new (s);
+        g_free (s);
+        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+	gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+        g_object_unref (icon);
+        g_object_unref (emblem);
+        g_object_unref (confirmation_icon);
+        g_object_unref (emblemed_icon);
+
+        g_free (name);
+        g_free (vpd_name);
+
+        if (G_OBJECT_CLASS (gdu_confirmation_dialog_parent_class)->constructed != NULL)
+                G_OBJECT_CLASS (gdu_confirmation_dialog_parent_class)->constructed (object);
+}
+
+static void
+gdu_confirmation_dialog_class_init (GduConfirmationDialogClass *klass)
+{
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+        g_type_class_add_private (klass, sizeof (GduConfirmationDialogPrivate));
+
+        object_class->get_property = gdu_confirmation_dialog_get_property;
+        object_class->set_property = gdu_confirmation_dialog_set_property;
+        object_class->constructed  = gdu_confirmation_dialog_constructed;
+        object_class->finalize     = gdu_confirmation_dialog_finalize;
+
+        g_object_class_install_property (object_class,
+                                         PROP_MESSAGE,
+                                         g_param_spec_string ("message",
+                                                              NULL,
+                                                              NULL,
+                                                              NULL,
+                                                              G_PARAM_READABLE |
+                                                              G_PARAM_WRITABLE |
+                                                              G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+gdu_confirmation_dialog_init (GduConfirmationDialog *dialog)
+{
+        dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog, GDU_TYPE_CONFIRMATION_DIALOG, GduConfirmationDialogPrivate);
+}
+
+GtkWidget *
+gdu_confirmation_dialog_new (GtkWindow      *parent,
+                             GduPresentable *presentable,
+                             const gchar    *message)
+{
+        g_return_val_if_fail (GDU_IS_PRESENTABLE (presentable), NULL);
+        return GTK_WIDGET (g_object_new (GDU_TYPE_CONFIRMATION_DIALOG,
+                                         "transient-for", parent,
+                                         "presentable", presentable,
+                                         "message", message,
+                                         NULL));
+}
+
+GtkWidget *
+gdu_confirmation_dialog_for_drive (GtkWindow      *parent,
+                                   GduDevice      *device,
+                                   const gchar    *message)
+{
+        g_return_val_if_fail (GDU_IS_DEVICE (device), NULL);
+        return GTK_WIDGET (g_object_new (GDU_TYPE_CONFIRMATION_DIALOG,
+                                         "transient-for", parent,
+                                         "drive-device", device,
+                                         "message", message,
+                                         NULL));
+}
+
+GtkWidget *
+gdu_confirmation_dialog_for_volume (GtkWindow      *parent,
+                                    GduDevice      *device,
+                                    const gchar    *message)
+{
+        g_return_val_if_fail (GDU_IS_DEVICE (device), NULL);
+        return GTK_WIDGET (g_object_new (GDU_TYPE_CONFIRMATION_DIALOG,
+                                         "transient-for", parent,
+                                         "volume-device", device,
+                                         "message", message,
+                                         NULL));
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
diff --git a/src/gdu-gtk/gdu-confirmation-dialog.h b/src/gdu-gtk/gdu-confirmation-dialog.h
new file mode 100644
index 0000000..a1af8f6
--- /dev/null
+++ b/src/gdu-gtk/gdu-confirmation-dialog.h
@@ -0,0 +1,70 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/* gdu-confirmation-dialog.h
+ *
+ * Copyright (C) 2009 David Zeuthen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#if !defined (__GDU_GTK_INSIDE_GDU_GTK_H) && !defined (GDU_GTK_COMPILATION)
+#confirmation "Only <gdu-gtk/gdu-gtk.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef __GDU_CONFIRMATION_DIALOG_H
+#define __GDU_CONFIRMATION_DIALOG_H
+
+#include <gdu-gtk/gdu-gtk-types.h>
+#include <gdu-gtk/gdu-dialog.h>
+
+G_BEGIN_DECLS
+
+#define GDU_TYPE_CONFIRMATION_DIALOG            gdu_confirmation_dialog_get_type()
+#define GDU_CONFIRMATION_DIALOG(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDU_TYPE_CONFIRMATION_DIALOG, GduConfirmationDialog))
+#define GDU_CONFIRMATION_DIALOG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GDU_TYPE_CONFIRMATION_DIALOG, GduConfirmationDialogClass))
+#define GDU_IS_CONFIRMATION_DIALOG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDU_TYPE_CONFIRMATION_DIALOG))
+#define GDU_IS_CONFIRMATION_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDU_TYPE_CONFIRMATION_DIALOG))
+#define GDU_CONFIRMATION_DIALOG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GDU_TYPE_CONFIRMATION_DIALOG, GduConfirmationDialogClass))
+
+typedef struct GduConfirmationDialogClass   GduConfirmationDialogClass;
+typedef struct GduConfirmationDialogPrivate GduConfirmationDialogPrivate;
+
+struct GduConfirmationDialog
+{
+        GduDialog parent;
+
+        /*< private >*/
+        GduConfirmationDialogPrivate *priv;
+};
+
+struct GduConfirmationDialogClass
+{
+        GduDialogClass parent_class;
+};
+
+GType       gdu_confirmation_dialog_get_type   (void) G_GNUC_CONST;
+GtkWidget  *gdu_confirmation_dialog_new        (GtkWindow      *parent,
+                                                GduPresentable *presentable,
+                                                const gchar    *message);
+GtkWidget  *gdu_confirmation_dialog_for_drive  (GtkWindow      *parent,
+                                                GduDevice      *device,
+                                                const gchar    *message);
+GtkWidget  *gdu_confirmation_dialog_for_volume (GtkWindow      *parent,
+                                                GduDevice      *device,
+                                                const gchar    *message);
+
+G_END_DECLS
+
+#endif /* __GDU_CONFIRMATION_DIALOG_H */
diff --git a/src/gdu-gtk/gdu-gtk-types.h b/src/gdu-gtk/gdu-gtk-types.h
index 134d432..b17089d 100644
--- a/src/gdu-gtk/gdu-gtk-types.h
+++ b/src/gdu-gtk/gdu-gtk-types.h
@@ -48,6 +48,7 @@ typedef struct GduVolumeGrid               GduVolumeGrid;
 typedef struct GduDetailsTable             GduDetailsTable;
 typedef struct GduDetailsElement           GduDetailsElement;
 typedef struct GduErrorDialog              GduErrorDialog;
+typedef struct GduConfirmationDialog       GduConfirmationDialog;
 typedef struct GduButtonElement            GduButtonElement;
 typedef struct GduButtonTable              GduButtonTable;
 typedef struct GduDialog                   GduDialog;
diff --git a/src/gdu-gtk/gdu-gtk.h b/src/gdu-gtk/gdu-gtk.h
index d670170..d549100 100644
--- a/src/gdu-gtk/gdu-gtk.h
+++ b/src/gdu-gtk/gdu-gtk.h
@@ -40,6 +40,7 @@
 #include <gdu-gtk/gdu-details-table.h>
 #include <gdu-gtk/gdu-details-element.h>
 #include <gdu-gtk/gdu-error-dialog.h>
+#include <gdu-gtk/gdu-confirmation-dialog.h>
 #include <gdu-gtk/gdu-button-element.h>
 #include <gdu-gtk/gdu-button-table.h>
 #include <gdu-gtk/gdu-dialog.h>
diff --git a/src/palimpsest/gdu-section-volumes.c b/src/palimpsest/gdu-section-volumes.c
index d00fee5..f8b60da 100644
--- a/src/palimpsest/gdu-section-volumes.c
+++ b/src/palimpsest/gdu-section-volumes.c
@@ -187,6 +187,66 @@ on_mount_button_clicked (GduButtonElement *button_element,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
+partition_delete_op_callback (GduDevice *device,
+                              GError    *error,
+                              gpointer   user_data)
+{
+        GduShell *shell = GDU_SHELL (user_data);
+
+        if (error != NULL) {
+                gdu_shell_raise_error (shell,
+                                       NULL,
+                                       error,
+                                       _("Error deleting partition"));
+                g_error_free (error);
+        }
+        g_object_unref (shell);
+}
+
+static void
+on_partition_delete_button_clicked (GduButtonElement *button_element,
+                                    gpointer          user_data)
+{
+        GduSectionVolumes *section = GDU_SECTION_VOLUMES (user_data);
+        GduPresentable *v;
+        GduDevice *d;
+        GtkWindow *toplevel;
+        GtkWidget *dialog;
+        gint response;
+
+        v = NULL;
+
+        v = gdu_volume_grid_get_selected (GDU_VOLUME_GRID (section->priv->grid));
+        if (v == NULL)
+                goto out;
+
+        d = gdu_presentable_get_device (v);
+        if (d == NULL)
+                goto out;
+
+        toplevel = GTK_WINDOW (gdu_shell_get_toplevel (gdu_section_get_shell (GDU_SECTION (section))));
+        dialog = gdu_confirmation_dialog_new (toplevel,
+                                              v,
+                                              _("Are you sure you want to delete the partition?"));
+        gtk_widget_show_all (dialog);
+        response = gtk_dialog_run (GTK_DIALOG (dialog));
+        if (response == GTK_RESPONSE_OK) {
+                gdu_device_op_partition_delete (d,
+                                                partition_delete_op_callback,
+                                                g_object_ref (gdu_section_get_shell (GDU_SECTION (section))));
+        }
+        gtk_widget_destroy (dialog);
+
+ out:
+        if (d != NULL)
+                g_object_unref (d);
+        if (v != NULL)
+                g_object_unref (v);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
 partition_modify_op_callback (GduDevice *device,
                               GError    *error,
                               gpointer   user_data)
@@ -665,12 +725,10 @@ gdu_section_volumes_constructed (GObject *object)
         button_element = gdu_button_element_new (GTK_STOCK_DELETE,
                                                  _("D_elete Partition"),
                                                  _("Delete the partition"));
-#if 0
         g_signal_connect (button_element,
                           "clicked",
                           G_CALLBACK (on_partition_delete_button_clicked),
                           section);
-#endif
         g_ptr_array_add (button_elements, button_element);
         section->priv->partition_delete_button = button_element;
 



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