Commit 882971c3 authored by William Jon McCann's avatar William Jon McCann

info: use local disk space instead of just root partition

https://bugzilla.gnome.org/show_bug.cgi?id=639376
parent e1d99ef4
...@@ -86,6 +86,7 @@ COMMON_MODULES="gtk+-3.0 >= $GTK_REQUIRED_VERSION ...@@ -86,6 +86,7 @@ COMMON_MODULES="gtk+-3.0 >= $GTK_REQUIRED_VERSION
glib-2.0 >= $GLIB_REQUIRED_VERSION glib-2.0 >= $GLIB_REQUIRED_VERSION
gthread-2.0 gthread-2.0
gio-2.0 gio-2.0
gio-unix-2.0
gconf-2.0 gconf-2.0
libxml-2.0 libxml-2.0
gsettings-desktop-schemas >= $DESKTOP_SCHEMAS_REQUIRED_VERSION" gsettings-desktop-schemas >= $DESKTOP_SCHEMAS_REQUIRED_VERSION"
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include <glib.h> #include <glib.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <gio/gio.h>
#include <gio/gunixmounts.h>
#include <glibtop/fsusage.h> #include <glibtop/fsusage.h>
#include <glibtop/mountlist.h> #include <glibtop/mountlist.h>
...@@ -245,21 +247,96 @@ get_os_type (void) ...@@ -245,21 +247,96 @@ get_os_type (void)
return g_strdup_printf (_("%d-bit"), bits); 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 * static char *
get_primary_disc_info (void) get_primary_disc_info (void)
{ {
guint64 total_bytes; guint64 total_bytes;
GList *points;
GList *p;
total_bytes = 0;
points = g_unix_mount_points_get (NULL);
for (p = points; p != NULL; p = p->next)
{
GUnixMountEntry *mount = p->data;
const char *mount_path;
struct statfs buf; struct statfs buf;
if (statfs ("/", &buf) < 0) 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_warning ("Unable to stat / filesystem: %s", g_strerror (errno));
return NULL; g_free (mount);
continue;
} }
else else
total_bytes = (guint64) buf.f_blocks * buf.f_bsize; {
total_bytes += (guint64) buf.f_blocks * buf.f_bsize;
}
g_free (mount);
}
g_list_free (points);
return g_format_size_for_display (total_bytes); return format_size_for_display (total_bytes);
} }
static char * static char *
......
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
<object class="GtkLabel" id="label5"> <object class="GtkLabel" id="label5">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">1</property> <property name="xalign">1</property>
<property name="label" translatable="yes">Primary Disk</property> <property name="label" translatable="yes">Disk</property>
</object> </object>
<packing> <packing>
<property name="top_attach">4</property> <property name="top_attach">4</property>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment