[gnome-disk-utility/udisks2-port] Factor out FS-creation to custom widget and use it when creating a partition
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-disk-utility/udisks2-port] Factor out FS-creation to custom widget and use it when creating a partition
- Date: Mon, 7 Nov 2011 23:04:16 +0000 (UTC)
commit f4bf503aad9b12d51ea11ad60f30b712baf1249e
Author: David Zeuthen <davidz redhat com>
Date: Mon Nov 7 18:02:15 2011 -0500
Factor out FS-creation to custom widget and use it when creating a partition
Signed-off-by: David Zeuthen <davidz redhat com>
data/ui/Makefile.am | 1 +
data/ui/create-partition-dialog.ui | 46 +++-
data/ui/filesystem-create.ui | 228 +++++++++++++
data/ui/format-volume-dialog.ui | 207 +------------
src/palimpsest/Makefile.am | 1 +
src/palimpsest/gducreatefilesystemwidget.c | 486 ++++++++++++++++++++++++++++
src/palimpsest/gducreatefilesystemwidget.h | 47 +++
src/palimpsest/gducreatepartitiondialog.c | 87 +++++-
src/palimpsest/gduformatvolumedialog.c | 203 ++----------
src/palimpsest/gdutypes.h | 4 +-
10 files changed, 916 insertions(+), 394 deletions(-)
---
diff --git a/data/ui/Makefile.am b/data/ui/Makefile.am
index d6afa55..3c21f6f 100644
--- a/data/ui/Makefile.am
+++ b/data/ui/Makefile.am
@@ -15,6 +15,7 @@ ui_DATA = \
format-volume-dialog.ui \
smart-dialog.ui \
create-partition-dialog.ui \
+ filesystem-create.ui \
$(NULL)
clean-local :
diff --git a/data/ui/create-partition-dialog.ui b/data/ui/create-partition-dialog.ui
index 170fd51..a335626 100644
--- a/data/ui/create-partition-dialog.ui
+++ b/data/ui/create-partition-dialog.ui
@@ -118,6 +118,7 @@
<object class="GtkScale" id="size-scale">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="hexpand">True</property>
<property name="adjustment">size-adjustment</property>
<property name="restrict_to_fill_level">False</property>
<property name="round_digits">1</property>
@@ -146,7 +147,7 @@
<property name="adjustment">size-adjustment</property>
</object>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
@@ -155,6 +156,7 @@
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="xalign">0</property>
<property name="label" translatable="yes">MB</property>
</object>
<packing>
@@ -186,7 +188,7 @@
<property name="adjustment">free-following-adjustment</property>
</object>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
@@ -195,6 +197,7 @@
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="xalign">0</property>
<property name="label" translatable="yes">MB</property>
</object>
<packing>
@@ -211,6 +214,15 @@
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -218,6 +230,36 @@
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes"><big>Contents</big></property>
+ <property name="use_markup">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="contents-box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_left">12</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">True</property>
diff --git a/data/ui/filesystem-create.ui b/data/ui/filesystem-create.ui
new file mode 100644
index 0000000..7ecf98e
--- /dev/null
+++ b/data/ui/filesystem-create.ui
@@ -0,0 +1,228 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkWindow" id="filesystem-create-dummywindow">
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkGrid" id="filesystem-create-grid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="row_spacing">6</property>
+ <property name="column_spacing">10</property>
+ <child>
+ <object class="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_Type:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">type-combobox</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBoxText" id="type-combobox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="has_tooltip">True</property>
+ <property name="tooltip_markup" translatable="yes">The kind of filesystem to create. Choose <b>Custom</b> to specify a custom filesystem type such as <i>btrfs</i>, <i>xfs</i> or <i>swap</i></property>
+ <property name="tooltip_text" translatable="yes">The kind of filesystem to create. Choose Custom to specify a custom filesystem type such as btrfs, xfs or swap</property>
+ <items>
+ <item translatable="yes">Compatible with all systems and devices (FAT)</item>
+ <item translatable="yes">Compatible with most systems (NTFS)</item>
+ <item translatable="yes">Compatible with Linux systems (ext4)</item>
+ <item translatable="yes">Encrypted, compatible with Linux systems (LUKS, ext4)</item>
+ <item translatable="yes">Custom</item>
+ </items>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_Name:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">name-entry</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="name-entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="has_tooltip">True</property>
+ <property name="tooltip_markup" translatable="yes">The name to use for the filesystem. This is useful if you want to refer to the device via a symlink in the <b>/dev/disk/by-label</b> directory</property>
+ <property name="tooltip_text" translatable="yes">The name to use for the filesystem. This is useful if you want to refer to the device via a symlink in the /dev/disk/by-label directory</property>
+ <property name="invisible_char">â</property>
+ <property name="activates_default">True</property>
+ <property name="invisible_char_set">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="filesystem-label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="no_show_all">True</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">F_ilesystem:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">filesystem-entry</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="filesystem-entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="no_show_all">True</property>
+ <property name="has_tooltip">True</property>
+ <property name="tooltip_markup" translatable="yes">The custom filesystem type to create e.g. <i>btrfs</i>, <i>xfs</i> or <i>swap</i></property>
+ <property name="tooltip_text" translatable="yes">The custom filesystem type to create e.g. btrfs, xfs or swap</property>
+ <property name="invisible_char">â</property>
+ <property name="activates_default">True</property>
+ <property name="invisible_char_set">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="passphrase-label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="no_show_all">True</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_Passphrase:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">passphrase-entry</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="confirm-passphrase-label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="no_show_all">True</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">C_onfirm Passphrase:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">confirm-passphrase-entry</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="passphrase-entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="no_show_all">True</property>
+ <property name="has_tooltip">True</property>
+ <property name="tooltip_markup" translatable="yes">Enter passphrase used to protect the data</property>
+ <property name="tooltip_text" translatable="yes">Enter passphrase used to protect the data</property>
+ <property name="visibility">False</property>
+ <property name="invisible_char">â</property>
+ <property name="activates_default">True</property>
+ <property name="invisible_char_set">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">3</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="confirm-passphrase-entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="no_show_all">True</property>
+ <property name="has_tooltip">True</property>
+ <property name="tooltip_markup" translatable="yes">Confirm passphrase entered above</property>
+ <property name="tooltip_text" translatable="yes">Confirm passphrase entered above</property>
+ <property name="visibility">False</property>
+ <property name="invisible_char">â</property>
+ <property name="activates_default">True</property>
+ <property name="invisible_char_set">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">4</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="show-passphrase-checkbutton">
+ <property name="label" translatable="yes">_Show Passphrases</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="no_show_all">True</property>
+ <property name="has_tooltip">True</property>
+ <property name="tooltip_markup" translatable="yes">Check this box to see the passphrases entered above</property>
+ <property name="tooltip_text" translatable="yes">Check this box to see the passphrases entered above</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">5</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/data/ui/format-volume-dialog.ui b/data/ui/format-volume-dialog.ui
index d150705..da635f0 100644
--- a/data/ui/format-volume-dialog.ui
+++ b/data/ui/format-volume-dialog.ui
@@ -76,218 +76,17 @@
</packing>
</child>
<child>
- <object class="GtkGrid" id="grid1">
+ <object class="GtkBox" id="contents-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
- <property name="row_spacing">6</property>
- <property name="column_spacing">10</property>
- <child>
- <object class="GtkLabel" id="label5">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">_Type:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">type-combobox</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkComboBoxText" id="type-combobox">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="has_tooltip">True</property>
- <property name="tooltip_markup" translatable="yes">The kind of filesystem to create. Choose <b>Custom</b> to specify a custom filesystem type such as <i>btrfs</i>, <i>xfs</i> or <i>swap</i></property>
- <items>
- <item translatable="yes">Compatible with all systems and devices (FAT)</item>
- <item translatable="yes">Compatible with most systems (NTFS)</item>
- <item translatable="yes">Compatible with Linux systems (ext4)</item>
- <item translatable="yes">Encrypted, compatible with Linux systems (LUKS, ext4)</item>
- <item translatable="yes">Custom</item>
- </items>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">_Name:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">name-entry</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="name-entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="tooltip_markup" translatable="yes">The name to use for the filesystem. This is useful if you want to refer to the device via a symlink in the <b>/dev/disk/by-label</b> directory</property>
- <property name="invisible_char">â</property>
- <property name="activates_default">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="filesystem-label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="no_show_all">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">F_ilesystem:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">filesystem-entry</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">2</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="filesystem-entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="no_show_all">True</property>
- <property name="tooltip_markup" translatable="yes">The custom filesystem type to create e.g. <i>btrfs</i>, <i>xfs</i> or <i>swap</i></property>
- <property name="invisible_char">â</property>
- <property name="activates_default">True</property>
- <property name="invisible_char_set">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">2</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="passphrase-label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="no_show_all">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">_Passphrase:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">passphrase-entry</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">3</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="confirm-passphrase-label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="no_show_all">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">C_onfirm Passphrase:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">confirm-passphrase-entry</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">4</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="passphrase-entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="no_show_all">True</property>
- <property name="has_tooltip">True</property>
- <property name="tooltip_markup" translatable="yes">Enter passphrase used to protect the data</property>
- <property name="visibility">False</property>
- <property name="invisible_char">â</property>
- <property name="activates_default">True</property>
- <property name="invisible_char_set">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">3</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="confirm-passphrase-entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="no_show_all">True</property>
- <property name="has_tooltip">True</property>
- <property name="tooltip_markup" translatable="yes">Confirm passphrase entered above</property>
- <property name="visibility">False</property>
- <property name="invisible_char">â</property>
- <property name="activates_default">True</property>
- <property name="invisible_char_set">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">4</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="show-passphrase-checkbutton">
- <property name="label" translatable="yes">_Show Passphrases</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="no_show_all">True</property>
- <property name="tooltip_markup" translatable="yes">Check this box to see the passphrases entered above</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
- <property name="xalign">0</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">5</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
+ <property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
diff --git a/src/palimpsest/Makefile.am b/src/palimpsest/Makefile.am
index a50bf08..e5fe658 100644
--- a/src/palimpsest/Makefile.am
+++ b/src/palimpsest/Makefile.am
@@ -39,6 +39,7 @@ palimpsest_SOURCES = \
gduunlockdialog.h gduunlockdialog.c \
gduformatvolumedialog.h gduformatvolumedialog.c \
gducreatepartitiondialog.h gducreatepartitiondialog.c \
+ gducreatefilesystemwidget.h gducreatefilesystemwidget.c \
$(enum_built_sources) \
$(NULL)
diff --git a/src/palimpsest/gducreatefilesystemwidget.c b/src/palimpsest/gducreatefilesystemwidget.c
new file mode 100644
index 0000000..e368a93
--- /dev/null
+++ b/src/palimpsest/gducreatefilesystemwidget.c
@@ -0,0 +1,486 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+#include <math.h>
+#include <gdk/gdkkeysyms.h>
+#include <gdk/gdkx.h>
+#include <stdlib.h>
+
+#include "gduapplication.h"
+#include "gduwindow.h"
+#include "gducreatefilesystemwidget.h"
+
+typedef struct _GduCreateFilesystemWidgetClass GduCreateFilesystemWidgetClass;
+struct _GduCreateFilesystemWidget
+{
+ GtkVBox parent;
+
+ GduApplication *application;
+ UDisksDrive *drive;
+
+ GtkBuilder *builder;
+ GtkWidget *grid;
+ GtkWidget *type_combobox;
+ GtkWidget *name_entry;
+ GtkWidget *filesystem_label;
+ GtkWidget *filesystem_entry;
+ GtkWidget *passphrase_label;
+ GtkWidget *passphrase_entry;
+ GtkWidget *confirm_passphrase_label;
+ GtkWidget *confirm_passphrase_entry;
+ GtkWidget *show_passphrase_checkbutton;
+
+ gchar *fstype;
+ gchar *name;
+ gchar *passphrase;
+ gboolean has_info;
+};
+
+struct _GduCreateFilesystemWidgetClass
+{
+ GtkVBoxClass parent_class;
+};
+
+enum
+{
+ PROP_0,
+ PROP_APPLICATION,
+ PROP_DRIVE,
+ PROP_FSTYPE,
+ PROP_NAME,
+ PROP_PASSPHRASE,
+ PROP_HAS_INFO
+};
+
+G_DEFINE_TYPE (GduCreateFilesystemWidget, gdu_create_filesystem_widget, GTK_TYPE_VBOX)
+
+static void
+gdu_create_filesystem_widget_finalize (GObject *object)
+{
+ GduCreateFilesystemWidget *widget = GDU_CREATE_FILESYSTEM_WIDGET (object);
+
+ g_object_unref (widget->application);
+ g_clear_object (&widget->drive);
+ g_free (widget->fstype);
+ g_free (widget->name);
+ g_free (widget->passphrase);
+
+ G_OBJECT_CLASS (gdu_create_filesystem_widget_parent_class)->finalize (object);
+}
+
+static void
+gdu_create_filesystem_widget_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GduCreateFilesystemWidget *widget = GDU_CREATE_FILESYSTEM_WIDGET (object);
+
+ switch (property_id)
+ {
+ case PROP_APPLICATION:
+ g_value_set_object (value, widget->application);
+ break;
+
+ case PROP_DRIVE:
+ g_value_set_object (value, widget->drive);
+ break;
+
+ case PROP_FSTYPE:
+ g_value_set_string (value, widget->fstype);
+ break;
+
+ case PROP_NAME:
+ g_value_set_string (value, widget->name);
+ break;
+
+ case PROP_PASSPHRASE:
+ g_value_set_string (value, widget->passphrase);
+ break;
+
+ case PROP_HAS_INFO:
+ g_value_set_boolean (value, widget->has_info);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gdu_create_filesystem_widget_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GduCreateFilesystemWidget *widget = GDU_CREATE_FILESYSTEM_WIDGET (object);
+
+ switch (property_id)
+ {
+ case PROP_APPLICATION:
+ widget->application = g_value_dup_object (value);
+ break;
+
+ case PROP_DRIVE:
+ widget->drive = g_value_dup_object (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+update (GduCreateFilesystemWidget *widget)
+{
+ gboolean show_filesystem_widgets = FALSE;
+ gboolean show_passphrase_widgets = FALSE;
+ gboolean has_info = FALSE;
+ const gchar *fstype = NULL;
+ const gchar *name = NULL;
+ const gchar *passphrase = NULL;
+
+ name = gtk_entry_get_text (GTK_ENTRY (widget->name_entry));
+ passphrase = gtk_entry_get_text (GTK_ENTRY (widget->passphrase_entry));
+
+ switch (gtk_combo_box_get_active (GTK_COMBO_BOX (widget->type_combobox)))
+ {
+ case 0:
+ fstype = "vfat";
+ has_info = TRUE;
+ break;
+
+ case 1:
+ fstype = "ntfs";
+ has_info = TRUE;
+ break;
+
+ case 2:
+ fstype = "ext4";
+ has_info = TRUE;
+ break;
+
+ case 3:
+ fstype = "ext4";
+ /* Encrypted, compatible with Linux (LUKS + ext4) */
+ show_passphrase_widgets = TRUE;
+ if (strlen (gtk_entry_get_text (GTK_ENTRY (widget->passphrase_entry))) > 0)
+ {
+ if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (widget->passphrase_entry)),
+ gtk_entry_get_text (GTK_ENTRY (widget->confirm_passphrase_entry))) == 0)
+ {
+ has_info = TRUE;
+ }
+ }
+ break;
+
+ case 4:
+ /* Custom */
+ show_filesystem_widgets = TRUE;
+ if (strlen (gtk_entry_get_text (GTK_ENTRY (widget->filesystem_entry))) > 0)
+ {
+ fstype = gtk_entry_get_text (GTK_ENTRY (widget->filesystem_entry));
+ /* TODO: maybe validate we know how to create this FS?
+ * And also make "Name" + its entry insensitive if it doesn't support labels?
+ */
+ has_info = TRUE;
+ }
+ break;
+
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ if (show_filesystem_widgets)
+ {
+ gtk_widget_show (widget->filesystem_label);
+ gtk_widget_show (widget->filesystem_entry);
+ }
+ else
+ {
+ gtk_widget_hide (widget->filesystem_label);
+ gtk_widget_hide (widget->filesystem_entry);
+ }
+
+ if (show_passphrase_widgets)
+ {
+ gtk_widget_show (widget->passphrase_label);
+ gtk_widget_show (widget->passphrase_entry);
+ gtk_widget_show (widget->confirm_passphrase_label);
+ gtk_widget_show (widget->confirm_passphrase_entry);
+ gtk_widget_show (widget->show_passphrase_checkbutton);
+ }
+ else
+ {
+ gtk_widget_hide (widget->passphrase_label);
+ gtk_widget_hide (widget->passphrase_entry);
+ gtk_widget_hide (widget->confirm_passphrase_label);
+ gtk_widget_hide (widget->confirm_passphrase_entry);
+ gtk_widget_hide (widget->show_passphrase_checkbutton);
+ }
+
+ /* update local widget state for our users */
+ g_object_freeze_notify (G_OBJECT (widget));
+ if (g_strcmp0 (widget->fstype, fstype) != 0)
+ {
+ g_free (widget->fstype);
+ widget->fstype = g_strdup (fstype);
+ g_object_notify (G_OBJECT (widget), "fstype");
+ }
+ if (g_strcmp0 (widget->name, name) != 0)
+ {
+ g_free (widget->name);
+ widget->name = g_strdup (name);
+ g_object_notify (G_OBJECT (widget), "name");
+ }
+ if (g_strcmp0 (widget->passphrase, passphrase) != 0)
+ {
+ g_free (widget->passphrase);
+ widget->passphrase = g_strdup (passphrase);
+ g_object_notify (G_OBJECT (widget), "passphrase");
+ }
+ if (widget->has_info != has_info)
+ {
+ widget->has_info = has_info;
+ g_object_notify (G_OBJECT (widget), "has-info");
+ }
+ g_object_thaw_notify (G_OBJECT (widget));
+}
+
+static void
+on_property_changed (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ GduCreateFilesystemWidget *widget = GDU_CREATE_FILESYSTEM_WIDGET (user_data);
+ update (widget);
+}
+
+
+static gboolean
+is_flash (UDisksDrive *drive)
+{
+ gboolean ret = FALSE;
+ guint n;
+ const gchar *const *media_compat;
+
+ media_compat = udisks_drive_get_media_compatibility (drive);
+ for (n = 0; media_compat != NULL && media_compat[n] != NULL; n++)
+ {
+ if (g_str_has_prefix (media_compat[n], "flash"))
+ {
+ ret = TRUE;
+ goto out;
+ }
+ }
+
+ out:
+ return ret;
+}
+
+static void
+set_defaults (GduCreateFilesystemWidget *widget)
+{
+ /* Default to FAT or NTFS for removable drives... Ext4 otherwise */
+ if (widget->drive != NULL && udisks_drive_get_removable (widget->drive))
+ {
+ /* default FAT for flash and disks/media smaller than 20G (assumed to be flash cards) */
+ if (is_flash (widget->drive) || udisks_drive_get_size (widget->drive) < 20L * 1000L*1000L*1000L)
+ {
+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget->type_combobox), 0); /* FAT */
+ }
+ else
+ {
+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget->type_combobox), 1); /* NTFS */
+ }
+ }
+ else
+ {
+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget->type_combobox), 2); /* Ext4 */
+ }
+
+ /* Translators: this is the default name for the filesystem */
+ gtk_entry_set_text (GTK_ENTRY (widget->name_entry), _("New Volume"));
+
+ /* Set 'btrfs' for the custom filesystem */
+ gtk_entry_set_text (GTK_ENTRY (widget->filesystem_entry), "btrfs");
+
+ g_object_bind_property (widget->show_passphrase_checkbutton,
+ "active",
+ widget->passphrase_entry,
+ "visibility",
+ G_BINDING_SYNC_CREATE);
+ g_object_bind_property (widget->show_passphrase_checkbutton,
+ "active",
+ widget->confirm_passphrase_entry,
+ "visibility",
+ G_BINDING_SYNC_CREATE);
+}
+
+static void
+gdu_create_filesystem_widget_constructed (GObject *object)
+{
+ GduCreateFilesystemWidget *widget = GDU_CREATE_FILESYSTEM_WIDGET (object);
+ GtkWidget *dummy_window;
+
+ dummy_window = gdu_application_new_widget (widget->application,
+ "filesystem-create.ui",
+ "filesystem-create-dummywindow",
+ &widget->builder);
+ widget->grid = GTK_WIDGET (gtk_builder_get_object (widget->builder, "filesystem-create-grid"));
+ widget->type_combobox = GTK_WIDGET (gtk_builder_get_object (widget->builder, "type-combobox"));
+ g_signal_connect (widget->type_combobox, "notify::active", G_CALLBACK (on_property_changed), widget);
+ widget->name_entry = GTK_WIDGET (gtk_builder_get_object (widget->builder, "name-entry"));
+ g_signal_connect (widget->name_entry, "notify::text", G_CALLBACK (on_property_changed), widget);
+ widget->filesystem_label = GTK_WIDGET (gtk_builder_get_object (widget->builder, "filesystem-label"));
+ widget->filesystem_entry = GTK_WIDGET (gtk_builder_get_object (widget->builder, "filesystem-entry"));
+ g_signal_connect (widget->filesystem_entry, "notify::text", G_CALLBACK (on_property_changed), widget);
+ widget->passphrase_label = GTK_WIDGET (gtk_builder_get_object (widget->builder, "passphrase-label"));
+ widget->passphrase_entry = GTK_WIDGET (gtk_builder_get_object (widget->builder, "passphrase-entry"));
+ g_signal_connect (widget->passphrase_entry, "notify::text", G_CALLBACK (on_property_changed), widget);
+ widget->confirm_passphrase_label = GTK_WIDGET (gtk_builder_get_object (widget->builder, "confirm-passphrase-label"));
+ widget->confirm_passphrase_entry = GTK_WIDGET (gtk_builder_get_object (widget->builder, "confirm-passphrase-entry"));
+ g_signal_connect (widget->confirm_passphrase_entry, "notify::text", G_CALLBACK (on_property_changed), widget);
+ widget->show_passphrase_checkbutton = GTK_WIDGET (gtk_builder_get_object (widget->builder, "show-passphrase-checkbutton"));
+ g_signal_connect (widget->show_passphrase_checkbutton, "notify::active", G_CALLBACK (on_property_changed), widget);
+
+ /* reparent and nuke the dummy window */
+ gtk_widget_reparent (widget->grid, GTK_WIDGET (widget));
+ gtk_widget_destroy (dummy_window);
+
+ set_defaults (widget);
+ update (widget);
+
+ if (G_OBJECT_CLASS (gdu_create_filesystem_widget_parent_class)->constructed != NULL)
+ G_OBJECT_CLASS (gdu_create_filesystem_widget_parent_class)->constructed (object);
+}
+
+static void
+gdu_create_filesystem_widget_class_init (GduCreateFilesystemWidgetClass *klass)
+{
+ GObjectClass *gobject_class;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->get_property = gdu_create_filesystem_widget_get_property;
+ gobject_class->set_property = gdu_create_filesystem_widget_set_property;
+ gobject_class->finalize = gdu_create_filesystem_widget_finalize;
+ gobject_class->constructed = gdu_create_filesystem_widget_constructed;
+
+ g_object_class_install_property (gobject_class, PROP_APPLICATION,
+ g_param_spec_object ("application", NULL, NULL,
+ GDU_TYPE_APPLICATION,
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_DRIVE,
+ g_param_spec_object ("drive", NULL, NULL,
+ UDISKS_TYPE_DRIVE,
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_FSTYPE,
+ g_param_spec_string ("fstype", NULL, NULL,
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_NAME,
+ g_param_spec_string ("name", NULL, NULL,
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_PASSPHRASE,
+ g_param_spec_string ("passphrase", NULL, NULL,
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_HAS_INFO,
+ g_param_spec_boolean ("has-info", NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+gdu_create_filesystem_widget_init (GduCreateFilesystemWidget *widget)
+{
+}
+
+GtkWidget *
+gdu_create_filesystem_widget_new (GduApplication *application,
+ UDisksDrive *drive)
+{
+ g_return_val_if_fail (GDU_IS_APPLICATION (application), NULL);
+ return GTK_WIDGET (g_object_new (GDU_TYPE_CREATE_FILESYSTEM_WIDGET,
+ "application", application,
+ "drive", drive,
+ NULL));
+}
+
+const gchar *
+gdu_create_filesystem_widget_get_name (GduCreateFilesystemWidget *widget)
+{
+ g_return_val_if_fail (GDU_IS_CREATE_FILESYSTEM_WIDGET (widget), NULL);
+ return widget->name;
+}
+
+const gchar *
+gdu_create_filesystem_widget_get_fstype (GduCreateFilesystemWidget *widget)
+{
+ g_return_val_if_fail (GDU_IS_CREATE_FILESYSTEM_WIDGET (widget), NULL);
+ return widget->fstype;
+}
+
+const gchar *
+gdu_create_filesystem_widget_get_passphrase (GduCreateFilesystemWidget *widget)
+{
+ g_return_val_if_fail (GDU_IS_CREATE_FILESYSTEM_WIDGET (widget), NULL);
+ return widget->passphrase;
+}
+
+gboolean
+gdu_create_filesystem_widget_get_has_info (GduCreateFilesystemWidget *widget)
+{
+ g_return_val_if_fail (GDU_IS_CREATE_FILESYSTEM_WIDGET (widget), FALSE);
+ return widget->has_info;
+}
+
+GtkWidget *
+gdu_create_filesystem_widget_get_name_entry (GduCreateFilesystemWidget *widget)
+{
+ g_return_val_if_fail (GDU_IS_CREATE_FILESYSTEM_WIDGET (widget), NULL);
+ return widget->name_entry;
+}
diff --git a/src/palimpsest/gducreatefilesystemwidget.h b/src/palimpsest/gducreatefilesystemwidget.h
new file mode 100644
index 0000000..b72a641
--- /dev/null
+++ b/src/palimpsest/gducreatefilesystemwidget.h
@@ -0,0 +1,47 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#ifndef __GDU_CREATE_FILESYSTEM_WIDGET_H__
+#define __GDU_CREATE_FILESYSTEM_WIDGET_H__
+
+#include <gtk/gtk.h>
+#include "gdutypes.h"
+
+G_BEGIN_DECLS
+
+#define GDU_TYPE_CREATE_FILESYSTEM_WIDGET gdu_create_filesystem_widget_get_type()
+#define GDU_CREATE_FILESYSTEM_WIDGET(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDU_TYPE_CREATE_FILESYSTEM_WIDGET, GduCreateFilesystemWidget))
+#define GDU_IS_CREATE_FILESYSTEM_WIDGET(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDU_TYPE_CREATE_FILESYSTEM_WIDGET))
+
+GType gdu_create_filesystem_widget_get_type (void) G_GNUC_CONST;
+GtkWidget* gdu_create_filesystem_widget_new (GduApplication *application,
+ UDisksDrive *drive);
+const gchar *gdu_create_filesystem_widget_get_name (GduCreateFilesystemWidget *widget);
+const gchar *gdu_create_filesystem_widget_get_fstype (GduCreateFilesystemWidget *widget);
+const gchar *gdu_create_filesystem_widget_get_passphrase (GduCreateFilesystemWidget *widget);
+gboolean gdu_create_filesystem_widget_get_has_info (GduCreateFilesystemWidget *widget);
+
+GtkWidget *gdu_create_filesystem_widget_get_name_entry (GduCreateFilesystemWidget *widget);
+
+G_END_DECLS
+
+#endif /* __GDU_CREATE_FILESYSTEM_WIDGET_H__ */
diff --git a/src/palimpsest/gducreatepartitiondialog.c b/src/palimpsest/gducreatepartitiondialog.c
index 33da57d..51fc671 100644
--- a/src/palimpsest/gducreatepartitiondialog.c
+++ b/src/palimpsest/gducreatepartitiondialog.c
@@ -27,6 +27,7 @@
#include "gduapplication.h"
#include "gduwindow.h"
#include "gducreatepartitiondialog.h"
+#include "gducreatefilesystemwidget.h"
/* ---------------------------------------------------------------------------------------------------- */
@@ -47,6 +48,9 @@ typedef struct
GtkAdjustment *size_adjustment;
GtkAdjustment *free_following_adjustment;
+ GtkWidget *contents_box;
+ GtkWidget *create_filesystem_widget;
+
} CreatePartitionData;
static void
@@ -72,7 +76,8 @@ create_partition_update (CreatePartitionData *data)
{
gboolean can_proceed = FALSE;
- if (gtk_adjustment_get_value (data->size_adjustment) > 0)
+ if (gtk_adjustment_get_value (data->size_adjustment) > 0 &&
+ gdu_create_filesystem_widget_get_has_info (GDU_CREATE_FILESYSTEM_WIDGET (data->create_filesystem_widget)))
can_proceed = TRUE;
gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, can_proceed);
@@ -103,6 +108,24 @@ size_binding_func (GBinding *binding,
return TRUE;
}
+static void
+format_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ CreatePartitionData *data = user_data;
+ GError *error;
+
+ error = NULL;
+ if (!udisks_block_call_format_finish (UDISKS_BLOCK (source_object),
+ res,
+ &error))
+ {
+ gdu_window_show_error (data->window, _("Error formatting partition"), error);
+ g_error_free (error);
+ }
+ create_partition_data_free (data);
+}
static void
create_partition_cb (GObject *source_object,
@@ -111,7 +134,13 @@ create_partition_cb (GObject *source_object,
{
CreatePartitionData *data = user_data;
GError *error;
- gchar *created_partition_object_path;
+ gchar *created_partition_object_path = NULL;
+ UDisksObject *partition_object = NULL;
+ UDisksBlock *partition_block;
+ GVariantBuilder options_builder;
+ const gchar *fstype;
+ const gchar *name;
+ const gchar *passphrase;
error = NULL;
if (!udisks_partition_table_call_create_partition_finish (UDISKS_PARTITION_TABLE (source_object),
@@ -121,20 +150,49 @@ create_partition_cb (GObject *source_object,
{
gdu_window_show_error (data->window, _("Error creating partition"), error);
g_error_free (error);
+ create_partition_data_free (data);
+ goto out;
}
- else
+
+ udisks_client_settle (gdu_window_get_client (data->window));
+
+ partition_object = udisks_client_get_object (gdu_window_get_client (data->window), created_partition_object_path);
+ gdu_window_select_object (data->window, partition_object);
+
+ /* OK, cool, now format the created partition */
+ partition_block = udisks_object_peek_block (partition_object);
+ if (partition_block == NULL)
{
- UDisksObject *object;
+ g_warning ("Created partition has no block interface");
+ create_partition_data_free (data);
+ goto out;
+ }
- udisks_client_settle (gdu_window_get_client (data->window));
+ fstype = gdu_create_filesystem_widget_get_fstype (GDU_CREATE_FILESYSTEM_WIDGET (data->create_filesystem_widget));
+ name = gdu_create_filesystem_widget_get_name (GDU_CREATE_FILESYSTEM_WIDGET (data->create_filesystem_widget));
+ passphrase = gdu_create_filesystem_widget_get_passphrase (GDU_CREATE_FILESYSTEM_WIDGET (data->create_filesystem_widget));
- object = udisks_client_get_object (gdu_window_get_client (data->window),
- created_partition_object_path);
- gdu_window_select_object (data->window, object);
- g_object_unref (object);
- g_free (created_partition_object_path);
+ g_variant_builder_init (&options_builder, G_VARIANT_TYPE_VARDICT);
+ if (name != NULL && strlen (name) > 0)
+ g_variant_builder_add (&options_builder, "{sv}", "label", g_variant_new_string (name));
+ if (!(g_strcmp0 (fstype, "vfat") == 0 || g_strcmp0 (fstype, "ntfs") == 0))
+ {
+ /* TODO: need a better way to determine if this should be TRUE */
+ g_variant_builder_add (&options_builder, "{sv}", "take-ownership", g_variant_new_boolean (TRUE));
}
- create_partition_data_free (data);
+ if (passphrase != NULL && strlen (passphrase) > 0)
+ g_variant_builder_add (&options_builder, "{sv}", "encrypt.passphrase", g_variant_new_string (passphrase));
+
+ udisks_block_call_format (partition_block,
+ fstype,
+ g_variant_builder_end (&options_builder),
+ NULL, /* GCancellable */
+ format_cb,
+ data);
+
+ out:
+ g_free (created_partition_object_path);
+ g_clear_object (&partition_object);
}
void
@@ -166,6 +224,13 @@ gdu_create_partition_dialog_show (GduWindow *window,
data->size_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (data->builder, "size-adjustment"));
g_signal_connect (data->size_adjustment, "notify::value", G_CALLBACK (create_partition_property_changed), data);
data->free_following_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (data->builder, "free-following-adjustment"));
+ data->contents_box = GTK_WIDGET (gtk_builder_get_object (data->builder, "contents-box"));
+ data->create_filesystem_widget = gdu_create_filesystem_widget_new (gdu_window_get_application (window), data->drive);
+ gtk_box_pack_start (GTK_BOX (data->contents_box),
+ data->create_filesystem_widget,
+ TRUE, TRUE, 0);
+ g_signal_connect (data->create_filesystem_widget, "notify::has-info",
+ G_CALLBACK (create_partition_property_changed), data);
/* The adjustments count MB, not bytes */
max_size_mb = max_size / (1000L*1000L);
diff --git a/src/palimpsest/gduformatvolumedialog.c b/src/palimpsest/gduformatvolumedialog.c
index c4df199..8a3bead 100644
--- a/src/palimpsest/gduformatvolumedialog.c
+++ b/src/palimpsest/gduformatvolumedialog.c
@@ -29,6 +29,7 @@
#include "gduformatvolumedialog.h"
#include "gduvolumegrid.h"
#include "gduutils.h"
+#include "gducreatefilesystemwidget.h"
/* ---------------------------------------------------------------------------------------------------- */
@@ -42,17 +43,9 @@ typedef struct
GtkBuilder *builder;
GtkWidget *dialog;
- GtkWidget *type_combobox;
- GtkWidget *name_entry;
- GtkWidget *filesystem_label;
- GtkWidget *filesystem_entry;
-
- GtkWidget *passphrase_label;
- GtkWidget *passphrase_entry;
- GtkWidget *confirm_passphrase_label;
- GtkWidget *confirm_passphrase_entry;
- GtkWidget *show_passphrase_checkbutton;
+ GtkWidget *contents_box;
+ GtkWidget *create_filesystem_widget;
} FormatVolumeData;
static void
@@ -75,69 +68,9 @@ format_volume_data_free (FormatVolumeData *data)
static void
format_volume_update (FormatVolumeData *data)
{
- gboolean show_filesystem_widgets = FALSE;
- gboolean show_passphrase_widgets = FALSE;
- gboolean can_proceed = FALSE;
+ gboolean can_proceed;
- switch (gtk_combo_box_get_active (GTK_COMBO_BOX (data->type_combobox)))
- {
- case 3:
- /* Encrypted, compatible with Linux (LUKS + ext4) */
- show_passphrase_widgets = TRUE;
- if (strlen (gtk_entry_get_text (GTK_ENTRY (data->passphrase_entry))) > 0)
- {
- if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (data->passphrase_entry)),
- gtk_entry_get_text (GTK_ENTRY (data->confirm_passphrase_entry))) == 0)
- {
- can_proceed = TRUE;
- }
- }
- break;
-
- case 4:
- /* Custom */
- show_filesystem_widgets = TRUE;
- if (strlen (gtk_entry_get_text (GTK_ENTRY (data->filesystem_entry))) > 0)
- {
- /* TODO: maybe validate we know how to create this FS?
- * And also make "Name" + its entry insensitive if it doesn't support labels?
- */
- can_proceed = TRUE;
- }
- break;
-
- default:
- can_proceed = TRUE;
- break;
- }
-
- if (show_filesystem_widgets)
- {
- gtk_widget_show (data->filesystem_label);
- gtk_widget_show (data->filesystem_entry);
- }
- else
- {
- gtk_widget_hide (data->filesystem_label);
- gtk_widget_hide (data->filesystem_entry);
- }
-
- if (show_passphrase_widgets)
- {
- gtk_widget_show (data->passphrase_label);
- gtk_widget_show (data->passphrase_entry);
- gtk_widget_show (data->confirm_passphrase_label);
- gtk_widget_show (data->confirm_passphrase_entry);
- gtk_widget_show (data->show_passphrase_checkbutton);
- }
- else
- {
- gtk_widget_hide (data->passphrase_label);
- gtk_widget_hide (data->passphrase_entry);
- gtk_widget_hide (data->confirm_passphrase_label);
- gtk_widget_hide (data->confirm_passphrase_entry);
- gtk_widget_hide (data->show_passphrase_checkbutton);
- }
+ can_proceed = gdu_create_filesystem_widget_get_has_info (GDU_CREATE_FILESYSTEM_WIDGET (data->create_filesystem_widget));
gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, can_proceed);
}
@@ -151,67 +84,6 @@ format_volume_property_changed (GObject *object,
format_volume_update (data);
}
-static gboolean
-is_flash (UDisksDrive *drive)
-{
- gboolean ret = FALSE;
- guint n;
- const gchar *const *media_compat;
-
- media_compat = udisks_drive_get_media_compatibility (drive);
- for (n = 0; media_compat != NULL && media_compat[n] != NULL; n++)
- {
- if (g_str_has_prefix (media_compat[n], "flash"))
- {
- ret = TRUE;
- goto out;
- }
- }
-
- out:
- return ret;
-}
-
-static void
-format_volume_populate (FormatVolumeData *data)
-{
-
- /* Default to FAT or NTFS for removable drives... Ext4 otherwise */
- if (data->drive != NULL && udisks_drive_get_removable (data->drive))
- {
- /* default FAT for flash and disks/media smaller than 20G (assumed to be flash cards) */
- if (is_flash (data->drive) || udisks_drive_get_size (data->drive) < 20L * 1000L*1000L*1000L)
- {
- gtk_combo_box_set_active (GTK_COMBO_BOX (data->type_combobox), 0); /* FAT */
- }
- else
- {
- gtk_combo_box_set_active (GTK_COMBO_BOX (data->type_combobox), 1); /* NTFS */
- }
- }
- else
- {
- gtk_combo_box_set_active (GTK_COMBO_BOX (data->type_combobox), 2); /* Ext4 */
- }
-
- /* Translators: this is the default name for the filesystem */
- gtk_entry_set_text (GTK_ENTRY (data->name_entry), _("New Volume"));
-
- /* Set 'btrfs' for the custom filesystem */
- gtk_entry_set_text (GTK_ENTRY (data->filesystem_entry), "btrfs");
-
- g_object_bind_property (data->show_passphrase_checkbutton,
- "active",
- data->passphrase_entry,
- "visibility",
- G_BINDING_SYNC_CREATE);
- g_object_bind_property (data->show_passphrase_checkbutton,
- "active",
- data->confirm_passphrase_entry,
- "visibility",
- G_BINDING_SYNC_CREATE);
-}
-
static void
format_cb (GObject *source_object,
GAsyncResult *res,
@@ -249,36 +121,34 @@ gdu_format_volume_dialog_show (GduWindow *window,
"format-volume-dialog.ui",
"format-volume-dialog",
&data->builder);
- data->type_combobox = GTK_WIDGET (gtk_builder_get_object (data->builder, "type-combobox"));
- g_signal_connect (data->type_combobox, "notify::active", G_CALLBACK (format_volume_property_changed), data);
- data->name_entry = GTK_WIDGET (gtk_builder_get_object (data->builder, "name-entry"));
- g_signal_connect (data->name_entry, "notify::text", G_CALLBACK (format_volume_property_changed), data);
- data->filesystem_label = GTK_WIDGET (gtk_builder_get_object (data->builder, "filesystem-label"));
- data->filesystem_entry = GTK_WIDGET (gtk_builder_get_object (data->builder, "filesystem-entry"));
- g_signal_connect (data->filesystem_entry, "notify::text", G_CALLBACK (format_volume_property_changed), data);
- data->passphrase_label = GTK_WIDGET (gtk_builder_get_object (data->builder, "passphrase-label"));
- data->passphrase_entry = GTK_WIDGET (gtk_builder_get_object (data->builder, "passphrase-entry"));
- g_signal_connect (data->passphrase_entry, "notify::text", G_CALLBACK (format_volume_property_changed), data);
- data->confirm_passphrase_label = GTK_WIDGET (gtk_builder_get_object (data->builder, "confirm-passphrase-label"));
- data->confirm_passphrase_entry = GTK_WIDGET (gtk_builder_get_object (data->builder, "confirm-passphrase-entry"));
- g_signal_connect (data->confirm_passphrase_entry, "notify::text", G_CALLBACK (format_volume_property_changed), data);
- data->show_passphrase_checkbutton = GTK_WIDGET (gtk_builder_get_object (data->builder, "show-passphrase-checkbutton"));
- g_signal_connect (data->show_passphrase_checkbutton, "notify::active", G_CALLBACK (format_volume_property_changed), data);
+
+ data->contents_box = GTK_WIDGET (gtk_builder_get_object (data->builder, "contents-box"));
+ data->create_filesystem_widget = gdu_create_filesystem_widget_new (gdu_window_get_application (window), data->drive);
+ gtk_box_pack_start (GTK_BOX (data->contents_box),
+ data->create_filesystem_widget,
+ TRUE, TRUE, 0);
+ g_signal_connect (data->create_filesystem_widget, "notify::has-info",
+ G_CALLBACK (format_volume_property_changed), data);
gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (window));
gtk_dialog_set_default_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK);
- format_volume_populate (data);
format_volume_update (data);
gtk_widget_show_all (data->dialog);
- gtk_widget_grab_focus (data->name_entry);
+ gtk_widget_grab_focus (gdu_create_filesystem_widget_get_name_entry (GDU_CREATE_FILESYSTEM_WIDGET (data->create_filesystem_widget)));
response = gtk_dialog_run (GTK_DIALOG (data->dialog));
if (response == GTK_RESPONSE_OK)
{
GVariantBuilder options_builder;
- const gchar *type;
+ const gchar *fstype;
+ const gchar *name;
+ const gchar *passphrase;
+
+ fstype = gdu_create_filesystem_widget_get_fstype (GDU_CREATE_FILESYSTEM_WIDGET (data->create_filesystem_widget));
+ name = gdu_create_filesystem_widget_get_name (GDU_CREATE_FILESYSTEM_WIDGET (data->create_filesystem_widget));
+ passphrase = gdu_create_filesystem_widget_get_passphrase (GDU_CREATE_FILESYSTEM_WIDGET (data->create_filesystem_widget));
gtk_widget_hide (data->dialog);
if (!gdu_window_show_confirmation (window,
@@ -288,35 +158,18 @@ gdu_format_volume_dialog_show (GduWindow *window,
goto out;
g_variant_builder_init (&options_builder, G_VARIANT_TYPE_VARDICT);
- if (strlen (gtk_entry_get_text (GTK_ENTRY (data->name_entry))) > 0)
- g_variant_builder_add (&options_builder, "{sv}", "label",
- g_variant_new_string (gtk_entry_get_text (GTK_ENTRY (data->name_entry))));
-
- switch (gtk_combo_box_get_active (GTK_COMBO_BOX (data->type_combobox)))
+ if (name != NULL && strlen (name) > 0)
+ g_variant_builder_add (&options_builder, "{sv}", "label", g_variant_new_string (name));
+ if (!(g_strcmp0 (fstype, "vfat") == 0 || g_strcmp0 (fstype, "ntfs") == 0))
{
- case 0:
- type = "vfat";
- break;
- case 1:
- type = "ntfs";
- break;
- case 2:
- type = "ext4";
- g_variant_builder_add (&options_builder, "{sv}", "take-ownership", g_variant_new_boolean (TRUE));
- break;
- case 3:
- type = "ext4";
+ /* TODO: need a better way to determine if this should be TRUE */
g_variant_builder_add (&options_builder, "{sv}", "take-ownership", g_variant_new_boolean (TRUE));
- g_variant_builder_add (&options_builder, "{sv}", "encrypt.passphrase",
- g_variant_new_string (gtk_entry_get_text (GTK_ENTRY (data->passphrase_entry))));
- break;
- case 4:
- type = gtk_entry_get_text (GTK_ENTRY (data->filesystem_entry));
- break;
}
+ if (passphrase != NULL && strlen (passphrase) > 0)
+ g_variant_builder_add (&options_builder, "{sv}", "encrypt.passphrase", g_variant_new_string (passphrase));
udisks_block_call_format (data->block,
- type,
+ fstype,
g_variant_builder_end (&options_builder),
NULL, /* GCancellable */
format_cb,
diff --git a/src/palimpsest/gdutypes.h b/src/palimpsest/gdutypes.h
index 4cdae4e..e2987a3 100644
--- a/src/palimpsest/gdutypes.h
+++ b/src/palimpsest/gdutypes.h
@@ -43,8 +43,8 @@ typedef struct _GduWindow GduWindow;
struct _GduVolumeGrid;
typedef struct _GduVolumeGrid GduVolumeGrid;
-struct _GduIScsiPathModel;
-typedef struct _GduIScsiPathModel GduIScsiPathModel;
+struct _GduCreateFilesystemWidget;
+typedef struct _GduCreateFilesystemWidget GduCreateFilesystemWidget;
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]