summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-12-18 22:02:14 +0100
committerinfirit <[email protected]>2014-12-18 22:02:14 +0100
commitc133c2c81935f77ac35d341e2cb5378222b2ea55 (patch)
tree37b37bc6e250df281134b004fe6f309763e0548c /src
parent89a5256bf2b7292e0fcbd6c7fb0d5a3901271645 (diff)
downloadmate-system-monitor-c133c2c81935f77ac35d341e2cb5378222b2ea55.tar.bz2
mate-system-monitor-c133c2c81935f77ac35d341e2cb5378222b2ea55.tar.xz
Add custom sort method for numerical columns with descending sort first
Taken from GSM commit: b439f813ceaf6ce6e82cd490c734c67aeb1f2028 From: Robert Roth <[email protected]> Gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=557122
Diffstat (limited to 'src')
-rw-r--r--src/proctable.cpp24
-rw-r--r--src/util.cpp43
-rw-r--r--src/util.h2
3 files changed, 65 insertions, 4 deletions
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 63cd572..8f993d0 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -357,7 +357,6 @@ proctable_new (ProcData * const procdata)
GUINT_TO_POINTER(i),
NULL);
break;
-
case COL_VMSIZE:
case COL_MEMRES:
case COL_MEMSHARED:
@@ -394,12 +393,33 @@ proctable_new (ProcData * const procdata)
&procman::priority_cell_data_func,
GUINT_TO_POINTER(COL_NICE),
NULL);
+ break;
+ default:
+ gtk_tree_view_column_set_attributes(col, cell, "text", i, NULL);
+ break;
+ }
+
+ // sorting
+ switch (i) {
+ case COL_MEMXSERVER:
+ case COL_VMSIZE:
+ case COL_MEMRES:
+ case COL_MEMSHARED:
+ case COL_MEM:
+ case COL_MEMWRITABLE:
+ case COL_CPU:
+ case COL_CPU_TIME:
+ case COL_START_TIME:
+ gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), i,
+ procman::number_compare_func, GUINT_TO_POINTER(i),
+ NULL);
+ break;
+ case COL_PRIORITY:
gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), i,
procman::priority_compare_func,
GUINT_TO_POINTER(COL_NICE), NULL);
break;
default:
- gtk_tree_view_column_set_attributes(col, cell, "text", i, NULL);
break;
}
diff --git a/src/util.cpp b/src/util.cpp
index ac4405f..8e2f7f4 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -305,6 +305,31 @@ static double get_relative_time(void)
return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec;
}
+static
+guint64 get_size_from_column(GtkTreeModel* model, GtkTreeIter* first,
+ const guint index)
+{
+ GValue value = { 0 };
+ gtk_tree_model_get_value(model, first, index, &value);
+
+ guint64 size;
+ switch (G_VALUE_TYPE(&value)) {
+ case G_TYPE_UINT:
+ size = g_value_get_uint(&value);
+ break;
+ 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);
+ return size;
+}
void
procman_debug_real(const char *file, int line, const char *func,
@@ -517,6 +542,22 @@ namespace procman
return result;
}
+ gint number_compare_func(GtkTreeModel* model, GtkTreeIter* first,
+ GtkTreeIter* second, gpointer user_data)
+ {
+ const guint index = GPOINTER_TO_UINT(user_data);
+
+ guint64 size1, size2;
+ size1 = get_size_from_column(model, first, index);
+ size2 = get_size_from_column(model, second, index);
+
+ if ( size2 > size1 )
+ return 1;
+ else if ( size2 < size1 )
+ return -1;
+ return 0;
+ }
+
template<>
void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value)
{
@@ -531,8 +572,6 @@ namespace procman
}
-
-
std::string format_rate(guint64 rate, guint64 max_rate, bool want_bits)
{
char* bytes = procman::format_size(rate, max_rate, want_bits);
diff --git a/src/util.h b/src/util.h
index 8d044ce..22a9a14 100644
--- a/src/util.h
+++ b/src/util.h
@@ -104,6 +104,8 @@ namespace procman
gpointer user_data);
gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first,
GtkTreeIter* second, gpointer user_data);
+ gint number_compare_func(GtkTreeModel* model, GtkTreeIter* first,
+ GtkTreeIter* second, gpointer user_data);
template<typename T>