diff options
author | monsta <[email protected]> | 2016-03-02 14:44:15 +0300 |
---|---|---|
committer | monsta <[email protected]> | 2016-03-02 14:49:11 +0300 |
commit | e44f2e847ddb5db5b6944f6c2f993981adbd3ad4 (patch) | |
tree | 871df644b8dbd6d4861d42421e1b03790ff3c490 /src | |
parent | 2e5e07b81f18fa4b3cfa8dfdbb08d716d58845ce (diff) | |
download | mate-system-monitor-e44f2e847ddb5db5b6944f6c2f993981adbd3ad4.tar.bz2 mate-system-monitor-e44f2e847ddb5db5b6944f6c2f993981adbd3ad4.tar.xz |
disks: implement saving and loading width and visibility of columns
adapted from
https://git.gnome.org/browse/gnome-system-monitor/commit/?id=f589439a966151b2589bca21a4d6b40455eb201a
with necessary changes from https://github.com/mate-desktop/mate-system-monitor/commit/eebc190a5aeb6ebaf5c3a868b68434679adddc74
Diffstat (limited to 'src')
-rw-r--r-- | src/disks.cpp | 41 | ||||
-rw-r--r-- | src/org.mate.system-monitor.gschema.xml.in | 56 | ||||
-rw-r--r-- | src/procdialogs.cpp | 29 | ||||
-rw-r--r-- | src/procman.cpp | 25 |
4 files changed, 130 insertions, 21 deletions
diff --git a/src/disks.cpp b/src/disks.cpp index 2431727..302098a 100644 --- a/src/disks.cpp +++ b/src/disks.cpp @@ -285,6 +285,44 @@ open_dir(GtkTreeView *tree_view, g_free(dir); } +static guint timeout_id = 0; +static GtkTreeViewColumn *current_column; + +static gboolean +save_column_width (gpointer data) +{ + gint width; + gchar *key; + int id; + GSettings *settings; + + settings = g_settings_get_child (G_SETTINGS (data), "disktreenew"); + id = gtk_tree_view_column_get_sort_column_id (current_column); + width = gtk_tree_view_column_get_width (current_column); + + key = g_strdup_printf ("col-%d-width", id); + g_settings_set_int(settings, key, width); + g_free (key); + + if (timeout_id) { + g_source_remove (timeout_id); + timeout_id = 0; + } + + return FALSE; +} + +static void +cb_disks_column_resized(GtkWidget *widget, GParamSpec *pspec, gpointer data) +{ + current_column = GTK_TREE_VIEW_COLUMN(widget); + + if (timeout_id) + g_source_remove (timeout_id); + + timeout_id = g_timeout_add (250, save_column_width, data); +} + GtkWidget * create_disk_view(ProcData *procdata) { @@ -355,6 +393,7 @@ create_disk_view(ProcData *procdata) gtk_tree_view_column_set_resizable(col, TRUE); gtk_tree_view_column_set_min_width (col, 30); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); + g_signal_connect(G_OBJECT(col), "notify::fixed-width", G_CALLBACK(cb_disks_column_resized), procdata->settings); gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col); /* sizes - used */ @@ -369,6 +408,7 @@ create_disk_view(ProcData *procdata) gtk_tree_view_column_set_resizable(col, TRUE); gtk_tree_view_column_set_min_width (col, 30); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); + g_signal_connect(G_OBJECT(col), "notify::fixed-width", G_CALLBACK(cb_disks_column_resized), procdata->settings); gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col); switch (i) { @@ -411,6 +451,7 @@ create_disk_view(ProcData *procdata) gtk_tree_view_column_set_resizable(col, TRUE); gtk_tree_view_column_set_min_width (col, 150); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); + g_signal_connect(G_OBJECT(col), "notify::fixed-width", G_CALLBACK(cb_disks_column_resized), procdata->settings); gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col); /* numeric sort */ diff --git a/src/org.mate.system-monitor.gschema.xml.in b/src/org.mate.system-monitor.gschema.xml.in index 063ffa4..c69bee0 100644 --- a/src/org.mate.system-monitor.gschema.xml.in +++ b/src/org.mate.system-monitor.gschema.xml.in @@ -353,6 +353,62 @@ <default>[ 0 ]</default> <summary>Disk view columns order</summary> </key> + <key name="col-0-width" type="i"> + <default>100</default> + <summary>Width of disk view 'Device' column</summary> + </key> + <key name="col-0-visible" type="b"> + <default>true</default> + <summary>Show disk view 'Device' column on startup</summary> + </key> + <key name="col-1-width" type="i"> + <default>100</default> + <summary>Width of disk view 'Directory' column</summary> + </key> + <key name="col-1-visible" type="b"> + <default>true</default> + <summary>Show disk view 'Directory' column on startup</summary> + </key> + <key name="col-2-width" type="i"> + <default>50</default> + <summary>Width of disk view 'Type' column</summary> + </key> + <key name="col-2-visible" type="b"> + <default>true</default> + <summary>Show disk view 'Type' column on startup</summary> + </key> + <key name="col-3-width" type="i"> + <default>80</default> + <summary>Width of disk view 'Total' column</summary> + </key> + <key name="col-3-visible" type="b"> + <default>true</default> + <summary>Show disk view 'Total' column on startup</summary> + </key> + <key name="col-4-width" type="i"> + <default>80</default> + <summary>Width of disk view 'Free' column</summary> + </key> + <key name="col-4-visible" type="b"> + <default>true</default> + <summary>Show disk view 'Free' column on startup</summary> + </key> + <key name="col-5-width" type="i"> + <default>80</default> + <summary>Width of disk view 'Available' column</summary> + </key> + <key name="col-5-visible" type="b"> + <default>true</default> + <summary>Show disk view 'Available' column on startup</summary> + </key> + <key name="col-6-width" type="i"> + <default>300</default> + <summary>Width of disk view 'Used' column</summary> + </key> + <key name="col-6-visible" type="b"> + <default>true</default> + <summary>Show disk view 'Used' column on startup</summary> + </key> </schema> <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.mate.system-monitor.memmapstree" path="/org/mate/system-monitor/memmapstree/"> <key name="sort-col" type="i"> diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp index f76d639..96cf39c 100644 --- a/src/procdialogs.cpp +++ b/src/procdialogs.cpp @@ -355,17 +355,15 @@ private: }; - - static void -field_toggled (GtkCellRendererToggle *cell, gchar *path_str, gpointer data) +field_toggled (const gchar *child_schema, GtkCellRendererToggle *cell, gchar *path_str, gpointer data) { GtkTreeModel *model = static_cast<GtkTreeModel*>(data); GtkTreePath *path = gtk_tree_path_new_from_string (path_str); GtkTreeIter iter; GtkTreeViewColumn *column; gboolean toggled; - GSettings *settings = g_settings_get_child (ProcData::get_instance()->settings, "proctree"); + GSettings *settings = g_settings_get_child (ProcData::get_instance()->settings, child_schema); gchar *key; int id; @@ -387,11 +385,22 @@ field_toggled (GtkCellRendererToggle *cell, gchar *path_str, gpointer data) g_free (key); gtk_tree_path_free (path); +} + +static void +proc_field_toggled (GtkCellRendererToggle *cell, gchar *path_str, gpointer data) +{ + field_toggled ("proctree", cell, path_str, data); +} +static void +disk_field_toggled (GtkCellRendererToggle *cell, gchar *path_str, gpointer data) +{ + field_toggled ("disktreenew", cell, path_str, data); } static GtkWidget * -create_field_page(GtkWidget *tree, const char* text) +create_field_page(GtkWidget *tree, const gchar *child_schema, const gchar *text) { GtkWidget *vbox; GtkWidget *scrolled; @@ -433,7 +442,11 @@ create_field_page(GtkWidget *tree, const char* text) gtk_tree_view_column_set_attributes (column, cell, "active", 0, NULL); - g_signal_connect (G_OBJECT (cell), "toggled", G_CALLBACK (field_toggled), model); + if (g_strcmp0 (child_schema, "proctree") == 0) + g_signal_connect (G_OBJECT (cell), "toggled", G_CALLBACK (proc_field_toggled), model); + else if (g_strcmp0 (child_schema, "disktreenew") == 0) + g_signal_connect (G_OBJECT (cell), "toggled", G_CALLBACK (disk_field_toggled), model); + gtk_tree_view_column_set_clickable (column, TRUE); gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); @@ -663,7 +676,7 @@ procdialog_create_preferences_dialog (ProcData *procdata) label = gtk_label_new (" "); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - vbox2 = create_field_page (procdata->tree, _("Process i_nformation shown in list:")); + vbox2 = create_field_page (procdata->tree, "proctree", _("Process i_nformation shown in list:")); gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0); sys_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); @@ -823,7 +836,7 @@ procdialog_create_preferences_dialog (ProcData *procdata) label = gtk_label_new (" "); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - vbox3 = create_field_page (procdata->disk_list, _("File system i_nformation shown in list:")); + vbox3 = create_field_page (procdata->disk_list, "disktreenew", _("File system i_nformation shown in list:")); gtk_box_pack_start (GTK_BOX (hbox), vbox3, TRUE, TRUE, 0); gtk_widget_show_all (dialog); diff --git a/src/procman.cpp b/src/procman.cpp index b9343eb..ea50cb2 100644 --- a/src/procman.cpp +++ b/src/procman.cpp @@ -399,7 +399,8 @@ procman_get_tree_state (GSettings *settings, GtkWidget *tree, const gchar *child columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (tree)); - if(!g_strcmp0(child_schema, "proctree")) + if (g_strcmp0(child_schema, "proctree") == 0 || + g_strcmp0(child_schema, "disktreenew") == 0) { for (it = columns; it; it = it->next) { @@ -421,19 +422,17 @@ procman_get_tree_state (GSettings *settings, GtkWidget *tree, const gchar *child g_free (key); column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree), id); - if(!column) continue; - gtk_tree_view_column_set_visible (column, visible); - if (visible) { - /* ensure column is really visible */ - width = MAX(width, 20); - gtk_tree_view_column_set_fixed_width(column, width); - } - } - } + if (column == NULL) + continue; + + gtk_tree_view_column_set_visible (column, visible); + if (visible) { + /* ensure column is really visible */ + width = MAX(width, 20); + gtk_tree_view_column_set_fixed_width(column, width); + } + } - if(!g_strcmp0(child_schema, "proctree") || - !g_strcmp0(child_schema, "disktreenew")) - { GVariant *value; GVariantIter iter; int sortIndex; |