[gnome-disk-utility] Use floating point in the "Create Partition" dialog
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-disk-utility] Use floating point in the "Create Partition" dialog
- Date: Tue, 4 Dec 2012 16:57:26 +0000 (UTC)
commit 89f95c44aaf8f4343f98466ed9bb0df01502527f
Author: David Zeuthen <zeuthen gmail com>
Date: Tue Dec 4 11:51:41 2012 -0500
Use floating point in the "Create Partition" dialog
If we use integral values, say creating a 320GB partition on a typical
320GB disk of size 320,072,933,376 we'll end up with 72MB unused space
at the end. This is bad (for several reasons) but the previous commit
(show all holes / unallocated bigger than 1 MiB) makes it even worse.
Signed-off-by: David Zeuthen <zeuthen gmail com>
data/ui/create-partition-dialog.ui | 2 ++
src/disks/gducreatepartitiondialog.c | 22 +++++++++++++---------
2 files changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/data/ui/create-partition-dialog.ui b/data/ui/create-partition-dialog.ui
index 5791827..3503810 100644
--- a/data/ui/create-partition-dialog.ui
+++ b/data/ui/create-partition-dialog.ui
@@ -133,6 +133,7 @@
<property name="activates_default">True</property>
<property name="invisible_char_set">True</property>
<property name="adjustment">size-adjustment</property>
+ <property name="digits">3</property>
</object>
<packing>
<property name="expand">False</property>
@@ -197,6 +198,7 @@
<property name="activates_default">True</property>
<property name="invisible_char_set">True</property>
<property name="adjustment">free-following-adjustment</property>
+ <property name="digits">3</property>
</object>
<packing>
<property name="expand">True</property>
diff --git a/src/disks/gducreatepartitiondialog.c b/src/disks/gducreatepartitiondialog.c
index 650d3f0..beccbc3 100644
--- a/src/disks/gducreatepartitiondialog.c
+++ b/src/disks/gducreatepartitiondialog.c
@@ -199,10 +199,10 @@ static void
set_unit_num (CreatePartitionData *data,
gint unit_num)
{
- guint64 unit_size;
- guint64 value_units;
- guint64 max_size_units;
- guint64 value;
+ gdouble unit_size;
+ gdouble value;
+ gdouble value_units;
+ gdouble max_size_units;
g_assert (unit_num < NUM_UNITS);
@@ -214,12 +214,12 @@ set_unit_num (CreatePartitionData *data,
}
else
{
- value = gtk_adjustment_get_value (data->size_adjustment) * unit_sizes[data->cur_unit_num];
+ value = gtk_adjustment_get_value (data->size_adjustment) * ((gdouble) unit_sizes[data->cur_unit_num]);
}
unit_size = unit_sizes[unit_num];
value_units = value / unit_size;
- max_size_units = data->max_size / unit_size;
+ max_size_units = ((gdouble) data->max_size) / unit_size;
g_object_freeze_notify (G_OBJECT (data->size_adjustment));
g_object_freeze_notify (G_OBJECT (data->free_following_adjustment));
@@ -241,6 +241,9 @@ set_unit_num (CreatePartitionData *data,
100, /* page increment */
0.0); /* page_size */
+ gtk_adjustment_set_value (data->size_adjustment, value_units);
+ gtk_adjustment_set_value (data->free_following_adjustment, max_size_units - value_units);
+
g_object_thaw_notify (G_OBJECT (data->size_adjustment));
g_object_thaw_notify (G_OBJECT (data->free_following_adjustment));
}
@@ -300,10 +303,11 @@ size_binding_func (GBinding *binding,
gpointer user_data)
{
CreatePartitionData *data = user_data;
- guint64 max_size_units;
+ gdouble max_size_units;
- max_size_units = data->max_size / unit_sizes[data->cur_unit_num];
+ max_size_units = ((gdouble) data->max_size) / unit_sizes[data->cur_unit_num];
g_value_set_double (target_value, max_size_units - g_value_get_double (source_value));
+
return TRUE;
}
@@ -516,7 +520,7 @@ gdu_create_partition_dialog_show (GduWindow *window,
partition_type = "0x05";
}
- size = floor (gtk_adjustment_get_value (data->size_adjustment)) * unit_sizes[data->cur_unit_num];
+ size = gtk_adjustment_get_value (data->size_adjustment) * unit_sizes[data->cur_unit_num];
udisks_partition_table_call_create_partition (data->table,
data->offset,
size,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]