[gnome-system-monitor] Use g_format_size with IEC units for memory and SI units for disk sizes. https://bugzilla.gnome.org/



commit de53e9a05cc0b047461f2437a7395cbc5d86594e
Author: Robert Roth <robert roth off gmail com>
Date:   Fri Feb 15 00:34:47 2013 +0200

    Use g_format_size with IEC units for memory and SI units for disk sizes.
    https://bugzilla.gnome.org/show_bug.cgi?id=693630

 src/disks.cpp          |    4 ++--
 src/load-graph.cpp     |    4 ++--
 src/procproperties.cpp |    2 +-
 src/util.cpp           |   37 +++++++++++++++++++++++++++++++++++--
 src/util.h             |    5 +++++
 5 files changed, 45 insertions(+), 7 deletions(-)
---
diff --git a/src/disks.cpp b/src/disks.cpp
index 939ca39..a3ec25b 100644
--- a/src/disks.cpp
+++ b/src/disks.cpp
@@ -373,7 +373,7 @@ create_disk_view(ProcmanApp *app, GtkBuilder *builder)
             case DISK_AVAIL:
                 g_object_set(cell, "xalign", 1.0f, NULL);
                 gtk_tree_view_column_set_cell_data_func(col, cell,
-                                                        &procman::size_cell_data_func,
+                                                        &procman::size_si_cell_data_func,
                                                         GUINT_TO_POINTER(i),
                                                         NULL);
                 break;
@@ -395,7 +395,7 @@ create_disk_view(ProcmanApp *app, GtkBuilder *builder)
     gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
     gtk_tree_view_column_pack_start(col, cell, FALSE);
     gtk_tree_view_column_set_cell_data_func(col, cell,
-                                            &procman::size_cell_data_func,
+                                            &procman::size_si_cell_data_func,
                                             GUINT_TO_POINTER(DISK_USED),
                                             NULL);
     gtk_tree_view_column_set_title(col, _(titles[DISK_USED]));
diff --git a/src/load-graph.cpp b/src/load-graph.cpp
index 8be60cb..8d9b86b 100644
--- a/src/load-graph.cpp
+++ b/src/load-graph.cpp
@@ -359,8 +359,8 @@ namespace
         char* total_text;
         char* text;
 
-        used_text = procman::format_size(used);
-        total_text = procman::format_size(total);
+        used_text = g_format_size_full(used, G_FORMAT_SIZE_IEC_UNITS);
+        total_text = g_format_size_full(total, G_FORMAT_SIZE_IEC_UNITS);
         if (total == 0) {
             text = g_strdup(_("not available"));
         } else {
diff --git a/src/procproperties.cpp b/src/procproperties.cpp
index 29f9fab..2cce374 100644
--- a/src/procproperties.cpp
+++ b/src/procproperties.cpp
@@ -103,7 +103,7 @@ format_memsize(guint64 size)
     if (size == 0)
         return g_strdup(_("N/A"));
     else
-        return procman::format_size(size);
+        return g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS);
 }
 
 static void
diff --git a/src/util.cpp b/src/util.cpp
index 874ede4..f06745b 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -395,7 +395,7 @@ namespace procman
 
         g_value_unset(&value);
 
-        char *str = procman::format_size(size);
+        char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS);
         g_object_set(renderer, "text", str, NULL);
         g_free(str);
     }
@@ -436,13 +436,46 @@ namespace procman
             g_free(str);
         }
         else {
-            char *str = procman::format_size(size);
+            char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS);
             g_object_set(renderer, "text", str, NULL);
             g_free(str);
         }
 
     }
+    
+    /*
+        Cell data function to format a size value with SI units (to be used only for disk size, see bugzilla 
693630)
+    */
+    void size_si_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
+                             GtkTreeModel *model, GtkTreeIter *iter,
+                             gpointer user_data)
+    {
+        const guint index = GPOINTER_TO_UINT(user_data);
 
+        guint64 size;
+        GValue value = { 0 };
+
+        gtk_tree_model_get_value(model, iter, index, &value);
+
+        switch (G_VALUE_TYPE(&value)) {
+            case G_TYPE_ULONG:
+                size = g_value_get_ulong(&value);
+                break;
+
+            case G_TYPE_UINT64:
+                size = g_value_get_uint64(&value);
+                break;
+
+            default:
+                g_assert_not_reached();
+        }
+
+        g_value_unset(&value);
+
+        char *str = g_format_size(size);
+        g_object_set(renderer, "text", str, NULL);
+        g_free(str);
+    }
 
     void duration_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
                                  GtkTreeModel *model, GtkTreeIter *iter,
diff --git a/src/util.h b/src/util.h
index 9bd4b2c..c6f33d2 100644
--- a/src/util.h
+++ b/src/util.h
@@ -88,6 +88,11 @@ namespace procman
                                 GtkTreeModel *model, GtkTreeIter *iter,
                                 gpointer user_data);
 
+    void size_si_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
+                                GtkTreeModel *model, GtkTreeIter *iter,
+                                gpointer user_data);
+
+
     void duration_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
                                  GtkTreeModel *model, GtkTreeIter *iter,
                                  gpointer user_data);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]