[gnome-disk-utility/new-ui] Move GduFormatDialog into libgdu-gtk and make Palimpsest use it too
- From: David Zeuthen <davidz src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-disk-utility/new-ui] Move GduFormatDialog into libgdu-gtk and make Palimpsest use it too
- Date: Sat, 3 Oct 2009 20:27:30 +0000 (UTC)
commit c685ab9126c6ad8f18eb8b452b5124b653ec6f95
Author: David Zeuthen <davidz redhat com>
Date: Sat Oct 3 16:23:30 2009 -0400
Move GduFormatDialog into libgdu-gtk and make Palimpsest use it too
src/format-tool/Makefile.am | 1 -
src/format-tool/gdu-format-dialog.c | 443 ---------------
src/format-tool/gdu-format-tool.c | 8 +-
src/gdu-gtk/Makefile.am | 2 +
src/gdu-gtk/gdu-confirmation-dialog.c | 36 +-
src/gdu-gtk/gdu-confirmation-dialog.h | 9 +-
src/gdu-gtk/gdu-dialog.c | 13 +
src/gdu-gtk/gdu-dialog.h | 1 +
src/gdu-gtk/gdu-edit-partition-dialog.c | 15 +-
src/gdu-gtk/gdu-format-dialog.c | 639 ++++++++++++++++++++++
src/{format-tool => gdu-gtk}/gdu-format-dialog.h | 30 +-
src/gdu-gtk/gdu-gtk-enums.h | 15 +
src/gdu-gtk/gdu-gtk-enumtypes.h | 2 +
src/gdu-gtk/gdu-gtk-types.h | 1 +
src/gdu-gtk/gdu-gtk.h | 1 +
src/palimpsest/gdu-section-volumes.c | 139 +++++-
16 files changed, 874 insertions(+), 481 deletions(-)
---
diff --git a/src/format-tool/Makefile.am b/src/format-tool/Makefile.am
index 0ccfd42..0b4f92c 100644
--- a/src/format-tool/Makefile.am
+++ b/src/format-tool/Makefile.am
@@ -36,7 +36,6 @@ libexec_PROGRAMS = gdu-format-tool
gdu_format_tool_SOURCES = \
gdu-format-tool.c \
- gdu-format-dialog.h gdu-format-dialog.c \
gdu-format-progress-dialog.h gdu-format-progress-dialog.c \
$(NULL)
diff --git a/src/format-tool/gdu-format-tool.c b/src/format-tool/gdu-format-tool.c
index 5a90a24..5bffae3 100644
--- a/src/format-tool/gdu-format-tool.c
+++ b/src/format-tool/gdu-format-tool.c
@@ -34,7 +34,6 @@
#include <gtk/gtk.h>
#include <stdlib.h>
-#include "gdu-format-dialog.h"
#include "gdu-format-progress-dialog.h"
typedef struct
@@ -330,8 +329,12 @@ main (int argc, char *argv[])
gdu_device_get_device_file (device));
}
- dialog = gdu_format_dialog_new (NULL, GDU_VOLUME (volume));
+ dialog = gdu_format_dialog_new (NULL, /* no parent window */
+ volume,
+ GDU_FORMAT_DIALOG_FLAGS_SIMPLE |
+ GDU_FORMAT_DIALOG_FLAGS_DISK_UTILITY_BUTTON);
gtk_window_set_title (GTK_WINDOW (dialog), format_desc);
+ gtk_window_set_icon_name (GTK_WINDOW (dialog), "nautilus-gdu");
gtk_widget_show_all (dialog);
response = gtk_dialog_run (GTK_DIALOG (dialog));
@@ -371,7 +374,6 @@ main (int argc, char *argv[])
take_ownership = (g_strcmp0 (fs_type, "vfat") != 0);
-
format_data = g_new0 (FormatData, 1);
format_data->loop = loop;
format_data->error = NULL;
diff --git a/src/gdu-gtk/Makefile.am b/src/gdu-gtk/Makefile.am
index 6af26f1..0a523d8 100644
--- a/src/gdu-gtk/Makefile.am
+++ b/src/gdu-gtk/Makefile.am
@@ -46,6 +46,7 @@ libgdu_gtkinclude_HEADERS = \
gdu-button-table.h \
gdu-dialog.h \
gdu-edit-partition-dialog.h \
+ gdu-format-dialog.h \
$(NULL)
libgdu_gtk_la_SOURCES = \
@@ -69,6 +70,7 @@ libgdu_gtk_la_SOURCES = \
gdu-button-table.h gdu-button-table.c \
gdu-dialog.h gdu-dialog.c \
gdu-edit-partition-dialog.h gdu-edit-partition-dialog.c \
+ gdu-format-dialog.h gdu-format-dialog.c \
$(NULL)
libgdu_gtk_la_CPPFLAGS = \
diff --git a/src/gdu-gtk/gdu-confirmation-dialog.c b/src/gdu-gtk/gdu-confirmation-dialog.c
index 2915d77..1c0df37 100644
--- a/src/gdu-gtk/gdu-confirmation-dialog.c
+++ b/src/gdu-gtk/gdu-confirmation-dialog.c
@@ -32,13 +32,15 @@
struct GduConfirmationDialogPrivate
{
- gchar *message;
+ gchar *message;
+ gchar *button_text;
};
enum
{
PROP_0,
PROP_MESSAGE,
+ PROP_BUTTON_TEXT
};
@@ -68,6 +70,10 @@ gdu_confirmation_dialog_get_property (GObject *object,
g_value_set_string (value, dialog->priv->message);
break;
+ case PROP_BUTTON_TEXT:
+ g_value_set_string (value, dialog->priv->button_text);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -87,6 +93,10 @@ gdu_confirmation_dialog_set_property (GObject *object,
dialog->priv->message = g_value_dup_string (value);
break;
+ case PROP_BUTTON_TEXT:
+ dialog->priv->button_text = g_value_dup_string (value);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -125,7 +135,7 @@ gdu_confirmation_dialog_constructed (GObject *object)
GTK_RESPONSE_CANCEL);
gtk_dialog_add_button (GTK_DIALOG (dialog),
- GTK_STOCK_DELETE,
+ dialog->priv->button_text,
GTK_RESPONSE_OK);
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
@@ -210,6 +220,16 @@ gdu_confirmation_dialog_class_init (GduConfirmationDialogClass *klass)
G_PARAM_READABLE |
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property (object_class,
+ PROP_BUTTON_TEXT,
+ g_param_spec_string ("button-text",
+ NULL,
+ NULL,
+ GTK_STOCK_DELETE,
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
}
static void
@@ -221,39 +241,45 @@ gdu_confirmation_dialog_init (GduConfirmationDialog *dialog)
GtkWidget *
gdu_confirmation_dialog_new (GtkWindow *parent,
GduPresentable *presentable,
- const gchar *message)
+ const gchar *message,
+ const gchar *button_text)
{
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,
+ "button-text", button_text,
NULL));
}
GtkWidget *
gdu_confirmation_dialog_for_drive (GtkWindow *parent,
GduDevice *device,
- const gchar *message)
+ const gchar *message,
+ const gchar *button_text)
{
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,
+ "button-text", button_text,
NULL));
}
GtkWidget *
gdu_confirmation_dialog_for_volume (GtkWindow *parent,
GduDevice *device,
- const gchar *message)
+ const gchar *message,
+ const gchar *button_text)
{
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,
+ "button-text", button_text,
NULL));
}
diff --git a/src/gdu-gtk/gdu-confirmation-dialog.h b/src/gdu-gtk/gdu-confirmation-dialog.h
index a1af8f6..c14f76c 100644
--- a/src/gdu-gtk/gdu-confirmation-dialog.h
+++ b/src/gdu-gtk/gdu-confirmation-dialog.h
@@ -57,13 +57,16 @@ struct GduConfirmationDialogClass
GType gdu_confirmation_dialog_get_type (void) G_GNUC_CONST;
GtkWidget *gdu_confirmation_dialog_new (GtkWindow *parent,
GduPresentable *presentable,
- const gchar *message);
+ const gchar *message,
+ const gchar *button_text);
GtkWidget *gdu_confirmation_dialog_for_drive (GtkWindow *parent,
GduDevice *device,
- const gchar *message);
+ const gchar *message,
+ const gchar *button_text);
GtkWidget *gdu_confirmation_dialog_for_volume (GtkWindow *parent,
GduDevice *device,
- const gchar *message);
+ const gchar *message,
+ const gchar *button_text);
G_END_DECLS
diff --git a/src/gdu-gtk/gdu-dialog.c b/src/gdu-gtk/gdu-dialog.c
index 6704945..2c32c63 100644
--- a/src/gdu-gtk/gdu-dialog.c
+++ b/src/gdu-gtk/gdu-dialog.c
@@ -36,6 +36,7 @@ struct GduDialogPrivate
{
GduPresentable *presentable;
GduDevice *device;
+ GduPool *pool;
};
enum
@@ -59,6 +60,9 @@ gdu_dialog_finalize (GObject *object)
if (dialog->priv->device != NULL) {
g_object_unref (dialog->priv->device);
}
+ if (dialog->priv->pool != NULL) {
+ g_object_unref (dialog->priv->pool);
+ }
if (G_OBJECT_CLASS (gdu_dialog_parent_class)->finalize != NULL)
G_OBJECT_CLASS (gdu_dialog_parent_class)->finalize (object);
@@ -99,6 +103,7 @@ gdu_dialog_set_property (GObject *object,
g_warn_if_fail (dialog->priv->presentable == NULL);
dialog->priv->presentable = g_value_dup_object (value);
dialog->priv->device = gdu_presentable_get_device (dialog->priv->presentable);
+ dialog->priv->pool = gdu_presentable_get_pool (dialog->priv->presentable);
}
break;
@@ -109,6 +114,7 @@ gdu_dialog_set_property (GObject *object,
g_warn_if_fail (dialog->priv->presentable == NULL);
dialog->priv->presentable = gdu_pool_get_drive_by_device (pool, device);
dialog->priv->device = gdu_presentable_get_device (dialog->priv->presentable);
+ dialog->priv->pool = gdu_presentable_get_pool (dialog->priv->presentable);
g_object_unref (pool);
}
break;
@@ -120,6 +126,7 @@ gdu_dialog_set_property (GObject *object,
g_warn_if_fail (dialog->priv->presentable == NULL);
dialog->priv->presentable = gdu_pool_get_volume_by_device (pool, device);
dialog->priv->device = gdu_presentable_get_device (dialog->priv->presentable);
+ dialog->priv->pool = gdu_presentable_get_pool (dialog->priv->presentable);
g_object_unref (pool);
}
break;
@@ -190,4 +197,10 @@ gdu_dialog_get_device (GduDialog *dialog)
return dialog->priv->device;
}
+GduPool *
+gdu_dialog_get_pool (GduDialog *dialog)
+{
+ return dialog->priv->pool;
+}
+
/* ---------------------------------------------------------------------------------------------------- */
diff --git a/src/gdu-gtk/gdu-dialog.h b/src/gdu-gtk/gdu-dialog.h
index 61a2d8d..868209b 100644
--- a/src/gdu-gtk/gdu-dialog.h
+++ b/src/gdu-gtk/gdu-dialog.h
@@ -56,6 +56,7 @@ struct GduDialogClass
GType gdu_dialog_get_type (void) G_GNUC_CONST;
GduPresentable *gdu_dialog_get_presentable (GduDialog *dialog);
GduDevice *gdu_dialog_get_device (GduDialog *dialog);
+GduPool *gdu_dialog_get_pool (GduDialog *dialog);
G_END_DECLS
diff --git a/src/gdu-gtk/gdu-edit-partition-dialog.c b/src/gdu-gtk/gdu-edit-partition-dialog.c
index 293dfec..5e88891 100644
--- a/src/gdu-gtk/gdu-edit-partition-dialog.c
+++ b/src/gdu-gtk/gdu-edit-partition-dialog.c
@@ -253,8 +253,8 @@ gdu_edit_partition_dialog_constructed (GObject *object)
GtkWidget *image;
GtkWidget *label;
gchar *s;
+ gchar *s2;
GIcon *icon;
- gchar *drive_vpd_name;
GduPresentable *p;
GduDevice *d;
GduPool *pool;
@@ -265,8 +265,8 @@ gdu_edit_partition_dialog_constructed (GObject *object)
gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
gtk_dialog_add_button (GTK_DIALOG (dialog),
- GTK_STOCK_CLOSE,
- GTK_RESPONSE_CLOSE);
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL);
gtk_dialog_add_button (GTK_DIALOG (dialog),
GTK_STOCK_APPLY,
@@ -292,12 +292,11 @@ gdu_edit_partition_dialog_constructed (GObject *object)
drive_device = gdu_pool_get_by_object_path (pool, gdu_device_partition_get_slave (d));
drive = gdu_pool_get_drive_by_device (pool, drive_device);
- drive_vpd_name = gdu_presentable_get_vpd_name (drive);
- s = g_strdup_printf (_("Edit partition %d of %s"),
- gdu_device_partition_get_number (d),
- drive_vpd_name);
+ s2 = gdu_presentable_get_vpd_name (gdu_dialog_get_presentable (GDU_DIALOG (dialog)));
+ s = g_strdup_printf (_("Edit %s"), s2);
gtk_window_set_title (GTK_WINDOW (dialog), s);
g_free (s);
+ g_free (s2);
/* --- */
@@ -386,8 +385,6 @@ gdu_edit_partition_dialog_constructed (GObject *object)
g_object_unref (drive);
g_object_unref (pool);
- g_free (drive_vpd_name);
-
update (dialog);
if (G_OBJECT_CLASS (gdu_edit_partition_dialog_parent_class)->constructed != NULL)
diff --git a/src/gdu-gtk/gdu-format-dialog.c b/src/gdu-gtk/gdu-format-dialog.c
new file mode 100644
index 0000000..69c21b7
--- /dev/null
+++ b/src/gdu-gtk/gdu-format-dialog.c
@@ -0,0 +1,639 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * format-window.c
+ *
+ * Copyright (C) 2008-2009 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Author: Tomas Bzatek <tbzatek redhat com>
+ * David Zeuthen <davidz redhat com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+#include <gdu/gdu.h>
+#include <gdu-gtk/gdu-gtk.h>
+
+#include "gdu-format-dialog.h"
+
+struct GduFormatDialogPrivate
+{
+ GduFormatDialogFlags flags;
+
+ GtkWidget *fs_label_entry;
+ GtkWidget *fs_type_combo_box;
+ GtkWidget *take_ownership_check_button;
+ GtkWidget *encrypt_check_button;
+
+ gchar *fs_type;
+ gchar **fs_options;
+ gboolean encrypt;
+ gboolean take_ownership;
+
+ gulong removed_signal_handler_id;
+};
+
+enum
+{
+ PROP_0,
+ PROP_FLAGS,
+ PROP_FS_TYPE,
+ PROP_FS_OPTIONS,
+ PROP_FS_LABEL,
+ PROP_ENCRYPT,
+ PROP_TAKE_OWNERSHIP,
+};
+
+static void gdu_format_dialog_constructed (GObject *object);
+
+G_DEFINE_TYPE (GduFormatDialog, gdu_format_dialog, GDU_TYPE_DIALOG)
+
+static void
+gdu_format_dialog_finalize (GObject *object)
+{
+ GduFormatDialog *dialog = GDU_FORMAT_DIALOG (object);
+
+ g_free (dialog->priv->fs_type);
+ g_strfreev (dialog->priv->fs_options);
+
+ if (dialog->priv->removed_signal_handler_id > 0) {
+ g_signal_handler_disconnect (gdu_dialog_get_presentable (GDU_DIALOG (dialog)),
+ dialog->priv->removed_signal_handler_id);
+ }
+
+ if (G_OBJECT_CLASS (gdu_format_dialog_parent_class)->finalize != NULL)
+ G_OBJECT_CLASS (gdu_format_dialog_parent_class)->finalize (object);
+}
+
+static void
+gdu_format_dialog_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GduFormatDialog *dialog = GDU_FORMAT_DIALOG (object);
+
+ switch (property_id) {
+ case PROP_FLAGS:
+ g_value_set_flags (value, dialog->priv->flags);
+ break;
+
+ case PROP_FS_TYPE:
+ g_value_take_string (value, dialog->priv->fs_type);
+ break;
+
+ case PROP_FS_LABEL:
+ g_value_take_string (value, gdu_format_dialog_get_fs_label (dialog));
+ break;
+
+ case PROP_FS_OPTIONS:
+ g_value_take_boxed (value, gdu_format_dialog_get_fs_options (dialog));
+ break;
+
+ case PROP_ENCRYPT:
+ g_value_set_boolean (value, gdu_format_dialog_get_encrypt (dialog));
+ break;
+
+ case PROP_TAKE_OWNERSHIP:
+ g_value_set_boolean (value, gdu_format_dialog_get_take_ownership (dialog));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gdu_format_dialog_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GduFormatDialog *dialog = GDU_FORMAT_DIALOG (object);
+
+ switch (property_id) {
+ case PROP_FLAGS:
+ dialog->priv->flags = g_value_get_flags (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gdu_format_dialog_class_init (GduFormatDialogClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (GduFormatDialogPrivate));
+
+ object_class->get_property = gdu_format_dialog_get_property;
+ object_class->set_property = gdu_format_dialog_set_property;
+ object_class->constructed = gdu_format_dialog_constructed;
+ object_class->finalize = gdu_format_dialog_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_FLAGS,
+ g_param_spec_flags ("flags",
+ _("Flags"),
+ _("Flags specifying the behavior of the dialog"),
+ GDU_TYPE_FORMAT_DIALOG_FLAGS,
+ GDU_FORMAT_DIALOG_FLAGS_NONE,
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property (object_class,
+ PROP_FS_TYPE,
+ g_param_spec_string ("fs-type",
+ _("Filesystem type"),
+ _("The selected filesystem type"),
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property (object_class,
+ PROP_FS_LABEL,
+ g_param_spec_string ("fs-label",
+ _("Filesystem label"),
+ _("The requested filesystem label"),
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property (object_class,
+ PROP_FS_OPTIONS,
+ g_param_spec_boxed ("fs-options",
+ _("Filesystem options"),
+ _("The options to use for creating the filesystem"),
+ G_TYPE_STRV,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property (object_class,
+ PROP_ENCRYPT,
+ g_param_spec_boolean ("encrypt",
+ _("Encryption"),
+ _("Whether the volume should be encrypted"),
+ FALSE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property (object_class,
+ PROP_TAKE_OWNERSHIP,
+ g_param_spec_boolean ("take-ownership",
+ _("Take Ownership"),
+ _("Whether the filesystem should be owned by the user"),
+ FALSE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+}
+
+static void
+gdu_format_dialog_init (GduFormatDialog *dialog)
+{
+ dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog, GDU_TYPE_FORMAT_DIALOG, GduFormatDialogPrivate);
+}
+
+GtkWidget *
+gdu_format_dialog_new (GtkWindow *parent,
+ GduPresentable *presentable,
+ GduFormatDialogFlags flags)
+{
+ return GTK_WIDGET (g_object_new (GDU_TYPE_FORMAT_DIALOG,
+ "transient-for", parent,
+ "presentable", presentable,
+ "flags", flags,
+ NULL));
+}
+
+GtkWidget *
+gdu_format_dialog_for_drive (GtkWindow *parent,
+ GduDevice *device,
+ GduFormatDialogFlags flags)
+{
+ return GTK_WIDGET (g_object_new (GDU_TYPE_FORMAT_DIALOG,
+ "transient-for", parent,
+ "drive-device", device,
+ "flags", flags,
+ NULL));
+}
+
+GtkWidget *
+gdu_format_dialog_for_volume (GtkWindow *parent,
+ GduDevice *device,
+ GduFormatDialogFlags flags)
+{
+ return GTK_WIDGET (g_object_new (GDU_TYPE_FORMAT_DIALOG,
+ "transient-for", parent,
+ "volume-device", device,
+ "flags", flags,
+ NULL));
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+gchar *
+gdu_format_dialog_get_fs_type (GduFormatDialog *dialog)
+{
+ g_return_val_if_fail (GDU_IS_FORMAT_DIALOG (dialog), NULL);
+ return g_strdup (dialog->priv->fs_type);
+}
+
+gchar *
+gdu_format_dialog_get_fs_label (GduFormatDialog *dialog)
+{
+ g_return_val_if_fail (GDU_IS_FORMAT_DIALOG (dialog), NULL);
+ return g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->priv->fs_label_entry)));
+}
+
+gchar **
+gdu_format_dialog_get_fs_options (GduFormatDialog *dialog)
+{
+ g_return_val_if_fail (GDU_IS_FORMAT_DIALOG (dialog), NULL);
+ return g_strdupv (dialog->priv->fs_options);
+}
+
+gboolean
+gdu_format_dialog_get_encrypt (GduFormatDialog *dialog)
+{
+ g_return_val_if_fail (GDU_IS_FORMAT_DIALOG (dialog), FALSE);
+ return dialog->priv->encrypt;
+}
+
+gboolean
+gdu_format_dialog_get_take_ownership (GduFormatDialog *dialog)
+{
+ g_return_val_if_fail (GDU_IS_FORMAT_DIALOG (dialog), FALSE);
+ return dialog->priv->take_ownership;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+update (GduFormatDialog *dialog)
+{
+ GduKnownFilesystem *kfs;
+ gint max_label_len;
+
+ /* keep in sync with where combo box is constructed in constructed() */
+ if (dialog->priv->flags & GDU_FORMAT_DIALOG_FLAGS_SIMPLE) {
+ g_free (dialog->priv->fs_type);
+ switch (gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->fs_type_combo_box))) {
+ case 0:
+ dialog->priv->fs_type = g_strdup ("vfat");
+ dialog->priv->encrypt = FALSE;
+ dialog->priv->take_ownership = FALSE;
+ break;
+ case 1:
+ dialog->priv->fs_type = g_strdup ("ext2");
+ dialog->priv->encrypt = FALSE;
+ dialog->priv->take_ownership = TRUE;
+ break;
+ case 2:
+ dialog->priv->fs_type = g_strdup ("ext4");
+ dialog->priv->encrypt = FALSE;
+ dialog->priv->take_ownership = TRUE;
+ break;
+ case 3:
+ dialog->priv->fs_type = g_strdup ("vfat");
+ dialog->priv->encrypt = TRUE;
+ dialog->priv->take_ownership = FALSE;
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ } else {
+ dialog->priv->fs_type = gdu_util_fstype_combo_box_get_selected (dialog->priv->fs_type_combo_box);
+ dialog->priv->encrypt = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->encrypt_check_button));
+ dialog->priv->take_ownership = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->take_ownership_check_button));
+ }
+
+ max_label_len = 0;
+ kfs = gdu_pool_get_known_filesystem_by_id (gdu_dialog_get_pool (GDU_DIALOG (dialog)), dialog->priv->fs_type);
+ if (kfs != NULL) {
+ max_label_len = gdu_known_filesystem_get_max_label_len (kfs);
+ g_object_unref (kfs);
+
+ if (! (dialog->priv->flags & GDU_FORMAT_DIALOG_FLAGS_SIMPLE)) {
+ if (gdu_known_filesystem_get_supports_unix_owners (kfs)) {
+ gtk_widget_show (dialog->priv->take_ownership_check_button);
+ } else {
+ gtk_widget_hide (dialog->priv->take_ownership_check_button);
+ dialog->priv->take_ownership = FALSE;
+ }
+ }
+ }
+ gtk_entry_set_max_length (GTK_ENTRY (dialog->priv->fs_label_entry), max_label_len);
+ if (max_label_len == 0) {
+ gtk_widget_set_sensitive (dialog->priv->fs_label_entry, FALSE);
+ gtk_entry_set_text (GTK_ENTRY (dialog->priv->fs_label_entry), "");
+ } else {
+ gtk_widget_set_sensitive (dialog->priv->fs_label_entry, TRUE);
+ }
+
+ if (! (dialog->priv->flags & GDU_FORMAT_DIALOG_FLAGS_SIMPLE)) {
+ if (g_strcmp0 (dialog->priv->fs_type, "empty") == 0 ||
+ g_strcmp0 (dialog->priv->fs_type, "msdos_extended_partition") == 0) {
+ gtk_widget_hide (dialog->priv->encrypt_check_button);
+ dialog->priv->encrypt = FALSE;
+ } else {
+ gtk_widget_show (dialog->priv->encrypt_check_button);
+ }
+ }
+}
+
+static void
+on_combo_box_changed (GtkWidget *combo_box,
+ gpointer user_data)
+{
+ GduFormatDialog *dialog = GDU_FORMAT_DIALOG (user_data);
+ update (dialog);
+}
+
+static void
+on_take_ownership_check_button_toggled (GtkToggleButton *toggle_button,
+ gpointer user_data)
+{
+ GduFormatDialog *dialog = GDU_FORMAT_DIALOG (user_data);
+ update (dialog);
+}
+
+static void
+on_encrypt_check_button_toggled (GtkToggleButton *toggle_button,
+ gpointer user_data)
+{
+ GduFormatDialog *dialog = GDU_FORMAT_DIALOG (user_data);
+ update (dialog);
+}
+
+static void
+on_fs_label_entry_activated (GtkWidget *combo_box,
+ gpointer user_data)
+{
+ GduFormatDialog *dialog = GDU_FORMAT_DIALOG (user_data);
+
+ gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_presentable_removed (GduPresentable *presentable,
+ gpointer user_data)
+{
+ GduFormatDialog *dialog = GDU_FORMAT_DIALOG (user_data);
+
+ gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+gdu_format_dialog_constructed (GObject *object)
+{
+ GduFormatDialog *dialog = GDU_FORMAT_DIALOG (object);
+ GtkWidget *content_area;
+ GtkWidget *button;
+ GtkWidget *icon;
+ GtkWidget *label;
+ GtkWidget *hbox;
+ GtkWidget *image;
+ GtkWidget *table;
+ GtkWidget *entry;
+ GtkWidget *combo_box;
+ GtkWidget *vbox2;
+ GdkPixbuf *pixbuf;
+ gint row;
+ gboolean ret;
+ GtkWidget *align;
+ gchar *s;
+ gchar *s2;
+ GtkWidget *check_button;
+
+ ret = FALSE;
+
+ pixbuf = gdu_util_get_pixbuf_for_presentable (gdu_dialog_get_presentable (GDU_DIALOG (dialog)),
+ GTK_ICON_SIZE_DIALOG);
+
+ gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
+ gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 0);
+ gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5);
+ gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 6);
+
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+
+ s2 = gdu_presentable_get_vpd_name (gdu_dialog_get_presentable (GDU_DIALOG (dialog)));
+ /* Translators: Format is a verb here. The %s is the name of the volume */
+ s = g_strdup_printf (_("Format %s"), s2);
+ gtk_window_set_title (GTK_WINDOW (dialog), s);
+ g_free (s);
+ g_free (s2);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ /* Translators: Format is used as a verb here */
+ _("_Format"),
+ GTK_RESPONSE_OK);
+
+ if (dialog->priv->flags & GDU_FORMAT_DIALOG_FLAGS_DISK_UTILITY_BUTTON) {
+ button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Disk _Utility"), GTK_RESPONSE_ACCEPT);
+ icon = gtk_image_new_from_icon_name ("palimpsest", GTK_ICON_SIZE_BUTTON);
+ gtk_button_set_image (GTK_BUTTON (button), icon);
+ gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))),
+ button,
+ TRUE);
+ gtk_widget_set_tooltip_text (button, _("Use Disk Utility to format volume"));
+ }
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+ gtk_container_set_border_width (GTK_CONTAINER (content_area), 10);
+
+ /* icon and text labels */
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (content_area), hbox, FALSE, TRUE, 0);
+
+ image = gtk_image_new_from_pixbuf (pixbuf);
+ gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
+ gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, TRUE, 12);
+
+ align = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 12, 0, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), align, TRUE, TRUE, 0);
+
+ vbox2 = gtk_vbox_new (FALSE, 6);
+ gtk_container_add (GTK_CONTAINER (align), vbox2);
+
+ row = 0;
+
+ table = gtk_table_new (2, 2, FALSE);
+ gtk_table_set_col_spacings (GTK_TABLE (table), 12);
+ gtk_table_set_row_spacings (GTK_TABLE (table), 6);
+ gtk_box_pack_start (GTK_BOX (vbox2), table, FALSE, FALSE, 0);
+
+ /* filesystem type */
+ label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ /* Translators: 'type' means 'filesystem type' here. */
+ gtk_label_set_markup_with_mnemonic (GTK_LABEL (label), _("_Type:"));
+ gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row + 1,
+ GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
+ if (dialog->priv->flags & GDU_FORMAT_DIALOG_FLAGS_SIMPLE) {
+ /* keep in sync with on_combo_box_changed() */
+ combo_box = gtk_combo_box_new_text ();
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box),
+ _("Compatible with all systems (FAT)"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box),
+ _("Compatible with Linux (ext2)"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box),
+ _("Compatible with Linux (ext4)"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box),
+ _("Encrypted, compatible with Linux (FAT)"));
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
+ dialog->priv->fs_type = g_strdup ("vfat");
+ dialog->priv->fs_options = NULL;
+ dialog->priv->encrypt = FALSE;
+ dialog->priv->take_ownership = FALSE;
+ } else {
+ combo_box = gdu_util_fstype_combo_box_create (gdu_dialog_get_pool (GDU_DIALOG (dialog)), "mbr");
+ gdu_util_fstype_combo_box_select (combo_box, "ext4");
+ dialog->priv->fs_type = g_strdup ("ext4");
+ dialog->priv->fs_options = NULL;
+ dialog->priv->encrypt = FALSE;
+ dialog->priv->take_ownership = TRUE;
+ }
+ gtk_table_attach (GTK_TABLE (table), combo_box, 1, 2, row, row +1,
+ GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo_box);
+ dialog->priv->fs_type_combo_box = combo_box;
+ row++;
+
+ /* filesystem label */
+ label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ /* Translators: 'name' means 'filesystem label' here. */
+ gtk_label_set_markup_with_mnemonic (GTK_LABEL (label), _("_Name:"));
+ gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row + 1,
+ GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
+ entry = gtk_entry_new ();
+ /* Translators: Keep length of translation of "New Volume" to less than 16 characters */
+ gtk_entry_set_text (GTK_ENTRY (entry), _("New Volume"));
+ gtk_table_attach (GTK_TABLE (table), entry, 1, 2, row, row + 1,
+ GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
+ dialog->priv->fs_label_entry = entry;
+ row++;
+
+ g_signal_connect (dialog->priv->fs_type_combo_box,
+ "changed",
+ G_CALLBACK (on_combo_box_changed),
+ dialog);
+
+ g_signal_connect (dialog->priv->fs_label_entry,
+ "activate",
+ G_CALLBACK (on_fs_label_entry_activated),
+ dialog);
+
+ if (! (dialog->priv->flags & GDU_FORMAT_DIALOG_FLAGS_SIMPLE)) {
+ check_button = gtk_check_button_new_with_mnemonic (_("T_ake ownership of filesystem"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);
+ gtk_widget_set_tooltip_text (check_button,
+ _("The selected file system has a concept of file ownership. "
+ "If checked, the created file system will be owned by you. "
+ "If not checked, only the super user can access the file system."));
+ gtk_box_pack_start (GTK_BOX (vbox2), check_button, FALSE, FALSE, 0);
+ dialog->priv->take_ownership_check_button = check_button;
+
+ check_button = gtk_check_button_new_with_mnemonic (_("_Encrypt underlying device"));
+ gtk_widget_set_tooltip_text (check_button,
+ _("Encryption protects your data, requiring a "
+ "passphrase to be entered before the file system can be "
+ "used. May decrease performance and may not be compatible if "
+ "you use the media on other operating systems."));
+ gtk_box_pack_start (GTK_BOX (vbox2), check_button, FALSE, FALSE, 0);
+ dialog->priv->encrypt_check_button = check_button;
+
+ /* visibility is controlled in update() */
+ gtk_widget_set_no_show_all (dialog->priv->take_ownership_check_button, TRUE);
+ gtk_widget_set_no_show_all (dialog->priv->encrypt_check_button, TRUE);
+
+ g_signal_connect (dialog->priv->take_ownership_check_button,
+ "toggled",
+ G_CALLBACK (on_take_ownership_check_button_toggled),
+ dialog);
+
+ g_signal_connect (dialog->priv->encrypt_check_button,
+ "toggled",
+ G_CALLBACK (on_encrypt_check_button_toggled),
+ dialog);
+
+ /* TODO: we want to also expose fs create options */
+ }
+
+ update (dialog);
+
+#if 0
+ hbox = gtk_hbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
+ image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
+ gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+ label = gtk_label_new (NULL);
+ s = g_strconcat ("<i>",
+ _("Warning: All data on the volume will be irrevocably lost."),
+ "</i>",
+ NULL);
+ gtk_label_set_markup (GTK_LABEL (label), 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 (hbox), label, FALSE, FALSE, 0);
+#endif
+
+ /* nuke dialog if device is yanked */
+ dialog->priv->removed_signal_handler_id = g_signal_connect (gdu_dialog_get_presentable (GDU_DIALOG (dialog)),
+ "removed",
+ G_CALLBACK (on_presentable_removed),
+ dialog);
+
+ gtk_widget_grab_focus (dialog->priv->fs_label_entry);
+ gtk_editable_select_region (GTK_EDITABLE (dialog->priv->fs_label_entry), 0, 1000);
+
+ if (G_OBJECT_CLASS (gdu_format_dialog_parent_class)->constructed != NULL)
+ G_OBJECT_CLASS (gdu_format_dialog_parent_class)->constructed (object);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
diff --git a/src/format-tool/gdu-format-dialog.h b/src/gdu-gtk/gdu-format-dialog.h
similarity index 61%
rename from src/format-tool/gdu-format-dialog.h
rename to src/gdu-gtk/gdu-format-dialog.h
index 64fcc5d..51cb814 100644
--- a/src/format-tool/gdu-format-dialog.h
+++ b/src/gdu-gtk/gdu-format-dialog.h
@@ -27,12 +27,10 @@
#define __GDU_FORMAT_DIALOG_H
#include <gtk/gtk.h>
-#include <gdu/gdu.h>
+#include <gdu-gtk/gdu-gtk.h>
G_BEGIN_DECLS
-/* TODO: move to libgdu-gtk */
-
#define GDU_TYPE_FORMAT_DIALOG gdu_format_dialog_get_type()
#define GDU_FORMAT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDU_TYPE_FORMAT_DIALOG, GduFormatDialog))
#define GDU_FORMAT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDU_TYPE_FORMAT_DIALOG, GduFormatDialogClass))
@@ -40,13 +38,12 @@ G_BEGIN_DECLS
#define GDU_IS_FORMAT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDU_TYPE_FORMAT_DIALOG))
#define GDU_FORMAT_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDU_TYPE_FORMAT_DIALOG, GduFormatDialogClass))
-typedef struct GduFormatDialog GduFormatDialog;
typedef struct GduFormatDialogClass GduFormatDialogClass;
typedef struct GduFormatDialogPrivate GduFormatDialogPrivate;
struct GduFormatDialog
{
- GtkDialog parent;
+ GduDialog parent;
/*< private >*/
GduFormatDialogPrivate *priv;
@@ -54,15 +51,24 @@ struct GduFormatDialog
struct GduFormatDialogClass
{
- GtkDialogClass parent_class;
+ GduDialogClass parent_class;
};
-GType gdu_format_dialog_get_type (void) G_GNUC_CONST;
-GtkWidget* gdu_format_dialog_new (GtkWindow *parent,
- GduVolume *volume);
-gchar *gdu_format_dialog_get_fs_type (GduFormatDialog *dialog);
-gchar *gdu_format_dialog_get_fs_label (GduFormatDialog *dialog);
-gboolean gdu_format_dialog_get_encrypt (GduFormatDialog *dialog);
+GType gdu_format_dialog_get_type (void) G_GNUC_CONST;
+GtkWidget *gdu_format_dialog_new (GtkWindow *parent,
+ GduPresentable *presentable,
+ GduFormatDialogFlags flags);
+GtkWidget *gdu_format_dialog_for_drive (GtkWindow *parent,
+ GduDevice *device,
+ GduFormatDialogFlags flags);
+GtkWidget *gdu_format_dialog_for_volume (GtkWindow *parent,
+ GduDevice *device,
+ GduFormatDialogFlags flags);
+gchar *gdu_format_dialog_get_fs_type (GduFormatDialog *dialog);
+gchar *gdu_format_dialog_get_fs_label (GduFormatDialog *dialog);
+gchar **gdu_format_dialog_get_fs_options (GduFormatDialog *dialog);
+gboolean gdu_format_dialog_get_encrypt (GduFormatDialog *dialog);
+gboolean gdu_format_dialog_get_take_ownership (GduFormatDialog *dialog);
G_END_DECLS
diff --git a/src/gdu-gtk/gdu-gtk-enums.h b/src/gdu-gtk/gdu-gtk-enums.h
index 938f36c..481ea72 100644
--- a/src/gdu-gtk/gdu-gtk-enums.h
+++ b/src/gdu-gtk/gdu-gtk-enums.h
@@ -74,4 +74,19 @@ typedef enum {
GDU_POOL_TREE_MODEL_FLAGS_NO_UNALLOCATABLE_DRIVES = (1<<2),
} GduPoolTreeModelFlags;
+/**
+ * GduFormatDialogFlags:
+ * @GDU_FORMAT_DIALOG_FLAGS_NONE: No flags set.
+ * @GDU_FORMAT_DIALOG_FLAGS_SIMPLE: Show a simple form of the dialog.
+ * @GDU_FORMAT_DIALOG_FLAGS_DISK_UTILITY_BUTTON: Show a "Disk Utility" button.
+ *
+ * Flags used when creating a #GduFormatDialog.
+ */
+typedef enum {
+ GDU_FORMAT_DIALOG_FLAGS_NONE = 0,
+ GDU_FORMAT_DIALOG_FLAGS_SIMPLE = (1<<0),
+ GDU_FORMAT_DIALOG_FLAGS_DISK_UTILITY_BUTTON = (1<<1),
+} GduFormatDialogFlags;
+
+
#endif /* GDU_GTK_ENUMS_H */
diff --git a/src/gdu-gtk/gdu-gtk-enumtypes.h b/src/gdu-gtk/gdu-gtk-enumtypes.h
index 35aa1c6..c3b4642 100644
--- a/src/gdu-gtk/gdu-gtk-enumtypes.h
+++ b/src/gdu-gtk/gdu-gtk-enumtypes.h
@@ -15,6 +15,8 @@ GType gdu_pool_tree_view_flags_get_type (void) G_GNUC_CONST;
#define GDU_TYPE_POOL_TREE_VIEW_FLAGS (gdu_pool_tree_view_flags_get_type ())
GType gdu_pool_tree_model_flags_get_type (void) G_GNUC_CONST;
#define GDU_TYPE_POOL_TREE_MODEL_FLAGS (gdu_pool_tree_model_flags_get_type ())
+GType gdu_format_dialog_flags_get_type (void) G_GNUC_CONST;
+#define GDU_TYPE_FORMAT_DIALOG_FLAGS (gdu_format_dialog_flags_get_type ())
G_END_DECLS
#endif /* __GDU_GTK_ENUM_TYPES_H__ */
diff --git a/src/gdu-gtk/gdu-gtk-types.h b/src/gdu-gtk/gdu-gtk-types.h
index b17089d..f3f38db 100644
--- a/src/gdu-gtk/gdu-gtk-types.h
+++ b/src/gdu-gtk/gdu-gtk-types.h
@@ -53,6 +53,7 @@ typedef struct GduButtonElement GduButtonElement;
typedef struct GduButtonTable GduButtonTable;
typedef struct GduDialog GduDialog;
typedef struct GduEditPartitionDialog GduEditPartitionDialog;
+typedef struct GduFormatDialog GduFormatDialog;
G_END_DECLS
diff --git a/src/gdu-gtk/gdu-gtk.h b/src/gdu-gtk/gdu-gtk.h
index d549100..5131701 100644
--- a/src/gdu-gtk/gdu-gtk.h
+++ b/src/gdu-gtk/gdu-gtk.h
@@ -45,6 +45,7 @@
#include <gdu-gtk/gdu-button-table.h>
#include <gdu-gtk/gdu-dialog.h>
#include <gdu-gtk/gdu-edit-partition-dialog.h>
+#include <gdu-gtk/gdu-format-dialog.h>
#undef __GDU_GTK_INSIDE_GDU_GTK_H
G_BEGIN_DECLS
diff --git a/src/palimpsest/gdu-section-volumes.c b/src/palimpsest/gdu-section-volumes.c
index f8b60da..7ef4971 100644
--- a/src/palimpsest/gdu-section-volumes.c
+++ b/src/palimpsest/gdu-section-volumes.c
@@ -227,7 +227,8 @@ on_partition_delete_button_clicked (GduButtonElement *button_element,
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?"));
+ _("Are you sure you want to delete the partition?"),
+ _("_Delete"));
gtk_widget_show_all (dialog);
response = gtk_dialog_run (GTK_DIALOG (dialog));
if (response == GTK_RESPONSE_OK) {
@@ -246,6 +247,135 @@ on_partition_delete_button_clicked (GduButtonElement *button_element,
/* ---------------------------------------------------------------------------------------------------- */
+
+typedef struct {
+ GduShell *shell;
+ GduPresentable *presentable;
+ char *encrypt_passphrase;
+ gboolean save_in_keyring;
+ gboolean save_in_keyring_session;
+} CreateFilesystemData;
+
+static void
+create_filesystem_data_free (CreateFilesystemData *data)
+{
+ if (data->shell != NULL)
+ g_object_unref (data->shell);
+ if (data->presentable != NULL)
+ g_object_unref (data->presentable);
+ if (data->encrypt_passphrase != NULL) {
+ memset (data->encrypt_passphrase, '\0', strlen (data->encrypt_passphrase));
+ g_free (data->encrypt_passphrase);
+ }
+ g_free (data);
+}
+
+static void
+filesystem_create_op_callback (GduDevice *device,
+ GError *error,
+ gpointer user_data)
+{
+ CreateFilesystemData *data = user_data;
+
+ if (error != NULL) {
+ gdu_shell_raise_error (data->shell,
+ data->presentable,
+ error,
+ _("Error creating filesystem"));
+ g_error_free (error);
+ } else if (data->encrypt_passphrase != NULL) {
+ /* now set the passphrase if requested */
+ if (data->save_in_keyring || data->save_in_keyring_session) {
+ gdu_util_save_secret (device,
+ data->encrypt_passphrase,
+ data->save_in_keyring_session);
+ }
+ }
+ if (data != NULL)
+ create_filesystem_data_free (data);
+}
+
+static void
+on_format_button_clicked (GduButtonElement *button_element,
+ gpointer user_data)
+{
+ GduSectionVolumes *section = GDU_SECTION_VOLUMES (user_data);
+ GduPresentable *v;
+ GduDevice *d;
+ GtkWindow *toplevel;
+ GtkWidget *dialog;
+ GtkWidget *confirmation_dialog;
+ gint response;
+
+ v = NULL;
+ dialog = NULL;
+ confirmation_dialog = 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_format_dialog_new (toplevel,
+ v,
+ GDU_FORMAT_DIALOG_FLAGS_NONE);
+ gtk_widget_show_all (dialog);
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_hide (dialog);
+ if (response == GTK_RESPONSE_OK) {
+ confirmation_dialog = gdu_confirmation_dialog_new (toplevel,
+ v,
+ _("Are you sure you want to format the volume?"),
+ _("_Format"));
+ gtk_widget_show_all (confirmation_dialog);
+ response = gtk_dialog_run (GTK_DIALOG (confirmation_dialog));
+ gtk_widget_hide (confirmation_dialog);
+ if (response == GTK_RESPONSE_OK) {
+ CreateFilesystemData *data;
+
+ data = g_new0 (CreateFilesystemData, 1);
+ data->shell = g_object_ref (gdu_section_get_shell (GDU_SECTION (section)));
+ data->presentable = g_object_ref (v);
+
+ if (gdu_format_dialog_get_encrypt (GDU_FORMAT_DIALOG (dialog))) {
+ data->encrypt_passphrase = gdu_util_dialog_ask_for_new_secret (
+ gdu_shell_get_toplevel (gdu_section_get_shell (GDU_SECTION (section))),
+ &data->save_in_keyring,
+ &data->save_in_keyring_session);
+ if (data->encrypt_passphrase == NULL) {
+ create_filesystem_data_free (data);
+ goto out;
+ }
+ }
+
+ gdu_device_op_filesystem_create (d,
+ gdu_format_dialog_get_fs_type (GDU_FORMAT_DIALOG (dialog)),
+ gdu_format_dialog_get_fs_label (GDU_FORMAT_DIALOG (dialog)),
+ data->encrypt_passphrase,
+ gdu_format_dialog_get_take_ownership (GDU_FORMAT_DIALOG (dialog)),
+ filesystem_create_op_callback,
+ data);
+
+ }
+ }
+ out:
+ if (dialog != NULL)
+ gtk_widget_destroy (dialog);
+ if (confirmation_dialog != NULL)
+ gtk_widget_destroy (confirmation_dialog);
+
+ if (d != NULL)
+ g_object_unref (d);
+ if (v != NULL)
+ g_object_unref (v);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
static void
partition_modify_op_callback (GduDevice *device,
GError *error,
@@ -521,6 +651,7 @@ gdu_section_volumes_update (GduSection *_section)
/* ---------------------------------------------------------------------------------------------------- */
/* populate according to usage */
+ show_format_button = TRUE;
if (g_strcmp0 (usage, "filesystem") == 0) {
gdu_details_element_set_text (section->priv->usage_element, _("Filesystem"));
s = gdu_util_get_fstype_for_display (gdu_device_id_get_type (d),
@@ -561,7 +692,6 @@ gdu_section_volumes_update (GduSection *_section)
show_fs_check_button = TRUE;
- show_format_button = TRUE;
} else if (g_strcmp0 (usage, "") == 0 &&
d != NULL && gdu_device_is_partition (d) &&
g_strcmp0 (gdu_device_partition_get_scheme (d), "mbr") == 0 &&
@@ -570,7 +700,7 @@ gdu_section_volumes_update (GduSection *_section)
g_strcmp0 (gdu_device_partition_get_type (d), "0x85") == 0)) {
gdu_details_element_set_text (section->priv->usage_element, _("Container for Logical Partitions"));
- show_format_button = TRUE;
+ show_format_button = FALSE;
} else if (GDU_IS_VOLUME_HOLE (v)) {
GduDevice *drive_device;
gdu_details_element_set_text (section->priv->usage_element, _("Unallocated Space"));
@@ -580,6 +710,7 @@ gdu_section_volumes_update (GduSection *_section)
g_object_unref (drive_device);
show_partition_create_button = TRUE;
+ show_format_button = FALSE;
}
gdu_button_element_set_visible (section->priv->fs_mount_button, show_fs_mount_button);
@@ -703,12 +834,10 @@ gdu_section_volumes_constructed (GObject *object)
button_element = gdu_button_element_new ("nautilus-gdu",
_("Fo_rmat Volume"),
_("Format the volume"));
-#if 0
g_signal_connect (button_element,
"clicked",
G_CALLBACK (on_format_button_clicked),
section);
-#endif
g_ptr_array_add (button_elements, button_element);
section->priv->format_button = button_element;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]