[gnome-disk-utility] Convey free space for mounted volumes
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-disk-utility] Convey free space for mounted volumes
- Date: Wed, 9 Jan 2013 17:39:45 +0000 (UTC)
commit f6107df3d6cde5243dba37b6d1eac8a41306d457
Author: David Zeuthen <zeuthen gmail com>
Date: Wed Jan 9 12:39:23 2013 -0500
Convey free space for mounted volumes
http://people.freedesktop.org/~david/disks-free-space.png
Signed-off-by: David Zeuthen <zeuthen gmail com>
src/disks/gduvolumegrid.c | 23 +++++++++++++++++++++++
src/disks/gduwindow.c | 34 ++++++++++++++++++++++++++++++----
src/libgdu/gduutils.c | 40 +++++++++++++++++++++++++++++++++++++++-
src/libgdu/gduutils.h | 4 ++++
4 files changed, 96 insertions(+), 5 deletions(-)
---
diff --git a/src/disks/gduvolumegrid.c b/src/disks/gduvolumegrid.c
index fd4373a..0d71cb7 100644
--- a/src/disks/gduvolumegrid.c
+++ b/src/disks/gduvolumegrid.c
@@ -43,6 +43,7 @@ struct GridElement
UDisksObject *object;
gint64 offset;
gint64 size;
+ gint64 unused;
GList *embedded_elements;
GridElement *parent;
@@ -804,6 +805,24 @@ render_element (GduVolumeGrid *grid,
gtk_render_frame (context, cr, x, y, w, h);
if (is_focused && is_grid_focused)
gtk_render_focus (context, cr, x + 2, y + 2, w - 4, h - 4);
+ if (element->unused > 0)
+ {
+ gdouble unused_height = element->unused * h / element->size;
+ cairo_pattern_t *gradient;
+ cairo_save (cr);
+ gradient = cairo_pattern_create_linear (x, y + unused_height - 10, x, y + unused_height);
+ cairo_pattern_add_color_stop_rgba (gradient, 0.0, 1.0, 1.0, 1.0, 0.25);
+ cairo_pattern_add_color_stop_rgba (gradient, 1.0, 1.0, 1.0, 1.0, 0.00);
+ cairo_set_source (cr, gradient);
+ cairo_pattern_destroy (gradient);
+ cairo_rectangle (cr,
+ x,
+ y,
+ w,
+ unused_height);
+ cairo_fill (cr);
+ cairo_restore (cr);
+ }
gtk_style_context_restore (context);
/* icons */
@@ -1655,6 +1674,10 @@ grid_element_set_details (GduVolumeGrid *grid,
mount_points = udisks_filesystem_get_mount_points (filesystem);
if (g_strv_length ((gchar **) mount_points) > 0)
element->show_mounted = TRUE;
+
+ element->unused = gdu_utils_get_unused_for_block (grid->client, block);
+ if (element->unused < 0)
+ element->unused = 0;
}
else if (g_strcmp0 (usage, "other") == 0 && g_strcmp0 (type, "swap") == 0)
{
diff --git a/src/disks/gduwindow.c b/src/disks/gduwindow.c
index 867e127..257685e 100644
--- a/src/disks/gduwindow.c
+++ b/src/disks/gduwindow.c
@@ -3154,6 +3154,7 @@ update_device_page_for_block (GduWindow *window,
UDisksObject *drive_object;
UDisksDrive *drive = NULL;
GList *jobs = NULL;
+ gint64 unused_space = -1;
read_only = udisks_block_get_read_only (block);
partition = udisks_object_peek_partition (object);
@@ -3189,6 +3190,8 @@ update_device_page_for_block (GduWindow *window,
}
}
+ unused_space = gdu_utils_get_unused_for_block (window->client, block);
+
if (partition != NULL && !read_only)
show_flags->volume_buttons |= SHOW_FLAGS_VOLUME_BUTTONS_PARTITION_DELETE;
@@ -3225,10 +3228,33 @@ update_device_page_for_block (GduWindow *window,
g_free (s);
if (size > 0)
{
- set_size (window,
- "devtab-size-label",
- "devtab-size-value-label",
- size, SET_MARKUP_FLAGS_HYPHEN_IF_EMPTY);
+ if (unused_space > 0)
+ {
+ s2 = udisks_client_get_size_for_display (window->client, unused_space, FALSE, FALSE);
+ s3 = udisks_client_get_size_for_display (window->client, size, FALSE, FALSE);
+ /* Translators: Shown in 'Size' field for a filesystem where we know the amount of unused
+ * space.
+ * The first %s is a short string with the size (e.g. '69 GB (68,719,476,736 bytes)').
+ * The second %s is a short string with the space free (e.g. '43 GB').
+ * The %f is the percentage in use (e.g. 62.2).
+ */
+ s = g_strdup_printf (_("%s â %s free (%.1f%% full)"), s3, s2,
+ 100.0 * (size - unused_space) / size);
+ g_free (s3);
+ g_free (s2);
+ set_markup (window,
+ "devtab-size-label",
+ "devtab-size-value-label",
+ s, SET_MARKUP_FLAGS_NONE);
+ g_free (s);
+ }
+ else
+ {
+ set_size (window,
+ "devtab-size-label",
+ "devtab-size-value-label",
+ size, SET_MARKUP_FLAGS_HYPHEN_IF_EMPTY);
+ }
}
else
{
diff --git a/src/libgdu/gduutils.c b/src/libgdu/gduutils.c
index 1913d74..d3d1498 100644
--- a/src/libgdu/gduutils.c
+++ b/src/libgdu/gduutils.c
@@ -9,8 +9,8 @@
#include "config.h"
#include <glib/gi18n.h>
-
#include <math.h>
+#include <sys/statvfs.h>
#include "gduutils.h"
@@ -1021,3 +1021,41 @@ gdu_utils_is_in_use (UDisksClient *client,
return ret;
}
+/* ---------------------------------------------------------------------------------------------------- */
+
+gint64
+gdu_utils_get_unused_for_block (UDisksClient *client,
+ UDisksBlock *block)
+{
+ gint64 ret = -1;
+ UDisksFilesystem *filesystem = NULL;
+ UDisksObject *object = NULL;
+ const gchar *const *mount_points = NULL;
+ struct statvfs statvfs_buf;
+
+ object = (UDisksObject *) g_dbus_interface_get_object (G_DBUS_INTERFACE (block));
+ if (object == NULL)
+ goto out;
+
+ filesystem = udisks_object_peek_filesystem (object);
+ if (filesystem == NULL)
+ {
+ /* TODO: Look at UDisksFilesystem property set from the udev db populated by blkid(8) */
+ goto out;
+ }
+
+ mount_points = udisks_filesystem_get_mount_points (filesystem);
+ if (mount_points == NULL || mount_points[0] == NULL)
+ goto out;
+
+ if (statvfs (mount_points[0], &statvfs_buf) != 0)
+ {
+ g_warning ("Error calling statvfs on path %s: %m", mount_points[0]);
+ goto out;
+ }
+
+ ret = ((gint64) statvfs_buf.f_bfree) * ((gint64) statvfs_buf.f_bsize);
+
+ out:
+ return ret;
+}
diff --git a/src/libgdu/gduutils.h b/src/libgdu/gduutils.h
index 75274ba..d22fbfa 100644
--- a/src/libgdu/gduutils.h
+++ b/src/libgdu/gduutils.h
@@ -73,6 +73,10 @@ gchar *gdu_utils_get_pretty_uri (GFile *file);
gboolean gdu_utils_is_in_use (UDisksClient *client,
UDisksObject *object);
+gint64 gdu_utils_get_unused_for_block (UDisksClient *client,
+ UDisksBlock *block);
+
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]