[gnome-control-center] info: use local disk space instead of just root partition
- From: William Jon McCann <mccann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] info: use local disk space instead of just root partition
- Date: Wed, 19 Jan 2011 00:28:22 +0000 (UTC)
commit 882971c368d418dabcf090f4ccb8d56f0165e5c5
Author: William Jon McCann <jmccann redhat com>
Date: Tue Jan 18 19:26:37 2011 -0500
info: use local disk space instead of just root partition
https://bugzilla.gnome.org/show_bug.cgi?id=639376
configure.ac | 1 +
panels/info/cc-info-panel.c | 91 +++++++++++++++++++++++++++++++++++++++---
panels/info/info.ui | 2 +-
3 files changed, 86 insertions(+), 8 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b223fa2..c218244 100644
--- a/configure.ac
+++ b/configure.ac
@@ -86,6 +86,7 @@ COMMON_MODULES="gtk+-3.0 >= $GTK_REQUIRED_VERSION
glib-2.0 >= $GLIB_REQUIRED_VERSION
gthread-2.0
gio-2.0
+ gio-unix-2.0
gconf-2.0
libxml-2.0
gsettings-desktop-schemas >= $DESKTOP_SCHEMAS_REQUIRED_VERSION"
diff --git a/panels/info/cc-info-panel.c b/panels/info/cc-info-panel.c
index 51f8c49..d9847d4 100644
--- a/panels/info/cc-info-panel.c
+++ b/panels/info/cc-info-panel.c
@@ -25,6 +25,8 @@
#include <glib.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gio/gunixmounts.h>
#include <glibtop/fsusage.h>
#include <glibtop/mountlist.h>
@@ -245,21 +247,96 @@ get_os_type (void)
return g_strdup_printf (_("%d-bit"), bits);
}
+#define KILOBYTE_FACTOR (G_GOFFSET_CONSTANT (1000))
+#define MEGABYTE_FACTOR (KILOBYTE_FACTOR * KILOBYTE_FACTOR)
+#define GIGABYTE_FACTOR (MEGABYTE_FACTOR * KILOBYTE_FACTOR)
+#define TERABYTE_FACTOR (GIGABYTE_FACTOR * KILOBYTE_FACTOR)
+#define PETABYTE_FACTOR (TERABYTE_FACTOR * KILOBYTE_FACTOR)
+#define EXABYTE_FACTOR (PETABYTE_FACTOR * KILOBYTE_FACTOR)
+
+static char *
+format_size_for_display (goffset size)
+{
+ if (size < (goffset) KILOBYTE_FACTOR)
+ return g_strdup_printf (g_dngettext(NULL, "%u byte", "%u bytes",(guint) size), (guint) size);
+ else
+ {
+ gdouble displayed_size;
+
+ if (size < (goffset) MEGABYTE_FACTOR)
+ {
+ displayed_size = (gdouble) size / (gdouble) KILOBYTE_FACTOR;
+ return g_strdup_printf (_("%.1f KB"), displayed_size);
+ }
+ else if (size < (goffset) GIGABYTE_FACTOR)
+ {
+ displayed_size = (gdouble) size / (gdouble) MEGABYTE_FACTOR;
+ return g_strdup_printf (_("%.1f MB"), displayed_size);
+ }
+ else if (size < (goffset) TERABYTE_FACTOR)
+ {
+ displayed_size = (gdouble) size / (gdouble) GIGABYTE_FACTOR;
+ return g_strdup_printf (_("%.1f GB"), displayed_size);
+ }
+ else if (size < (goffset) PETABYTE_FACTOR)
+ {
+ displayed_size = (gdouble) size / (gdouble) TERABYTE_FACTOR;
+ return g_strdup_printf (_("%.1f TB"), displayed_size);
+ }
+ else if (size < (goffset) EXABYTE_FACTOR)
+ {
+ displayed_size = (gdouble) size / (gdouble) PETABYTE_FACTOR;
+ return g_strdup_printf (_("%.1f PB"), displayed_size);
+ }
+ else
+ {
+ displayed_size = (gdouble) size / (gdouble) EXABYTE_FACTOR;
+ return g_strdup_printf (_("%.1f EB"), displayed_size);
+ }
+ }
+}
+
static char *
get_primary_disc_info (void)
{
guint64 total_bytes;
- struct statfs buf;
+ GList *points;
+ GList *p;
+
+ total_bytes = 0;
- if (statfs ("/", &buf) < 0)
+ points = g_unix_mount_points_get (NULL);
+ for (p = points; p != NULL; p = p->next)
{
- g_warning ("Unable to stat / filesystem: %s", g_strerror (errno));
- return NULL;
+ GUnixMountEntry *mount = p->data;
+ const char *mount_path;
+ struct statfs buf;
+
+ mount_path = g_unix_mount_get_mount_path (mount);
+
+ if (g_str_has_prefix (mount_path, "/media/")
+ || g_str_has_prefix (mount_path, g_get_home_dir ()))
+ {
+ g_free (mount);
+ continue;
+ }
+
+ if (statfs (mount_path, &buf) < 0)
+ {
+ g_warning ("Unable to stat / filesystem: %s", g_strerror (errno));
+ g_free (mount);
+ continue;
+ }
+ else
+ {
+ total_bytes += (guint64) buf.f_blocks * buf.f_bsize;
+ }
+
+ g_free (mount);
}
- else
- total_bytes = (guint64) buf.f_blocks * buf.f_bsize;
+ g_list_free (points);
- return g_format_size_for_display (total_bytes);
+ return format_size_for_display (total_bytes);
}
static char *
diff --git a/panels/info/info.ui b/panels/info/info.ui
index 38da085..fb16445 100644
--- a/panels/info/info.ui
+++ b/panels/info/info.ui
@@ -94,7 +94,7 @@
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="xalign">1</property>
- <property name="label" translatable="yes">Primary Disk</property>
+ <property name="label" translatable="yes">Disk</property>
</object>
<packing>
<property name="top_attach">4</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]