[gnome-system-monitor] Port to Gio::Settings



commit 4f60f4de2f584f4faa777f8d0243373f3591947b
Author: Artem Vorotnikov <artem vorotnikov me>
Date:   Sat Oct 1 01:18:36 2016 +0300

    Port to Gio::Settings

 src/application.cpp    |  171 ++++++++++++++++++++----------------------------
 src/application.h      |    2 +-
 src/disks.cpp          |   18 +----
 src/interface.cpp      |   55 ++++++++--------
 src/memmaps.cpp        |    8 +--
 src/openfiles.cpp      |    2 +-
 src/prefsdialog.cpp    |   33 ++++-----
 src/proctable.cpp      |   42 +++++-------
 src/smooth_refresh.cpp |   25 ++-----
 src/smooth_refresh.h   |   16 ++---
 src/util.cpp           |   10 +--
 src/util.h             |    5 +-
 12 files changed, 155 insertions(+), 232 deletions(-)
---
diff --git a/src/application.cpp b/src/application.cpp
index b650cc7..facdf3a 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -21,11 +21,9 @@
 #include "disks.h"
 
 static void
-cb_solaris_mode_changed (GSettings *settings, const gchar *key, gpointer data)
+cb_solaris_mode_changed (Gio::Settings& settings, Glib::ustring key, GsmApplication* app)
 {
-    GsmApplication *app = static_cast<GsmApplication *>(data);
-
-    app->config.solaris_mode = g_settings_get_boolean(settings, key);
+    app->config.solaris_mode = settings.get_boolean(key);
     app->cpu_graph->clear_background();
     if (app->timeout) {
         proctable_update (app);
@@ -33,58 +31,49 @@ cb_solaris_mode_changed (GSettings *settings, const gchar *key, gpointer data)
 }
 
 static void
-cb_draw_stacked_changed (GSettings *settings, const gchar *key, gpointer data)
+cb_draw_stacked_changed (Gio::Settings& settings, Glib::ustring key, GsmApplication* app)
 {
-    GsmApplication *app = static_cast<GsmApplication *>(data);
-
-    app->config.draw_stacked = g_settings_get_boolean(settings, key);
+    app->config.draw_stacked = settings.get_boolean(key);
     app->cpu_graph->clear_background();
     load_graph_reset(app->cpu_graph);
 }
 
-
 static void
-cb_network_in_bits_changed (GSettings *settings, const gchar *key, gpointer data)
+cb_network_in_bits_changed (Gio::Settings& settings, Glib::ustring key, GsmApplication* app)
 {
-    GsmApplication *app = static_cast<GsmApplication *>(data);
-
-    app->config.network_in_bits = g_settings_get_boolean(settings, key);
+    app->config.network_in_bits = settings.get_boolean(key);
     // force scale to be redrawn
     app->net_graph->clear_background();
 }
 
 static void
-cb_timeouts_changed (GSettings *settings, const gchar *key, gpointer data)
+cb_timeouts_changed (Gio::Settings& settings, Glib::ustring key, GsmApplication* app)
 {
-    GsmApplication *app = static_cast<GsmApplication *>(data);
-
-    if (strcmp (key, GSM_SETTING_PROCESS_UPDATE_INTERVAL) == 0) {
-        app->config.update_interval = g_settings_get_int (settings, key);
+    if (key == GSM_SETTING_PROCESS_UPDATE_INTERVAL) {
+        app->config.update_interval = settings.get_int (key);
 
         app->smooth_refresh->reset();
         if (app->timeout) {
             proctable_reset_timeout (app);
         }
-    } else if (strcmp (key, GSM_SETTING_GRAPH_UPDATE_INTERVAL) == 0) {
-        app->config.graph_update_interval = g_settings_get_int (settings, key);
+    } else if (key == GSM_SETTING_GRAPH_UPDATE_INTERVAL) {
+        app->config.graph_update_interval = settings.get_int (key);
         load_graph_change_speed(app->cpu_graph,
                                 app->config.graph_update_interval);
         load_graph_change_speed(app->mem_graph,
                                 app->config.graph_update_interval);
         load_graph_change_speed(app->net_graph,
                                 app->config.graph_update_interval);
-    } else if (strcmp (key, GSM_SETTING_DISKS_UPDATE_INTERVAL) == 0) {
-        app->config.disks_update_interval = g_settings_get_int (settings, key);
+    } else if (key == GSM_SETTING_DISKS_UPDATE_INTERVAL) {
+        app->config.disks_update_interval = settings.get_int (key);
         disks_reset_timeout (app);
     }
 }
 
 static void
-apply_cpu_color_settings(GSettings *settings, gpointer data)
+apply_cpu_color_settings(Gio::Settings& settings, GsmApplication* app)
 {
-    GsmApplication *app = static_cast<GsmApplication *>(data);
-
-    GVariant *cpu_colors_var = g_settings_get_value (settings, GSM_SETTING_CPU_COLORS);
+    GVariant *cpu_colors_var = g_settings_get_value (settings.gobj (), GSM_SETTING_CPU_COLORS);
     gsize n = g_variant_n_children(cpu_colors_var);
 
     gchar *color;
@@ -112,7 +101,7 @@ apply_cpu_color_settings(GSettings *settings, gpointer data)
     full = g_variant_builder_end(&builder);
     // if the user has more cores than colors stored in the gsettings, store the newly built gvariant in 
gsettings
     if (n < static_cast<guint>(app->config.num_cpus)) {
-        g_settings_set_value(settings, GSM_SETTING_CPU_COLORS, full);
+        g_settings_set_value(settings.gobj (), GSM_SETTING_CPU_COLORS, full);
     } else {
         g_variant_unref(full);
     }
@@ -121,11 +110,9 @@ apply_cpu_color_settings(GSettings *settings, gpointer data)
 }
 
 static void
-cb_color_changed (GSettings *settings, const gchar *key, gpointer data)
+cb_color_changed (Gio::Settings& settings, Glib::ustring key, GsmApplication* app)
 {
-    GsmApplication *app = static_cast<GsmApplication *>(data);
-
-    if (strcmp (key, GSM_SETTING_CPU_COLORS) == 0) {
+    if (key == GSM_SETTING_CPU_COLORS) {
         apply_cpu_color_settings(settings, app);
         for (int i = 0; i < app->config.num_cpus; i++) {
             if(!gdk_rgba_equal(&app->cpu_graph->colors[i], &app->config.cpu_color[i])) {
@@ -136,93 +123,75 @@ cb_color_changed (GSettings *settings, const gchar *key, gpointer data)
         return;
     }
 
-    gchar *color = g_settings_get_string (settings, key);
-    if (strcmp (key, GSM_SETTING_MEM_COLOR) == 0) {
-        gdk_rgba_parse (&app->config.mem_color, color);
+    auto color = settings.get_string (key);
+    if (key == GSM_SETTING_MEM_COLOR) {
+        gdk_rgba_parse (&app->config.mem_color, color.c_str ());
         app->mem_graph->colors.at(0) = app->config.mem_color;
-    } else if (strcmp (key, GSM_SETTING_SWAP_COLOR) == 0) {
-        gdk_rgba_parse (&app->config.swap_color, color);
+    } else if (key == GSM_SETTING_SWAP_COLOR) {
+        gdk_rgba_parse (&app->config.swap_color, color.c_str ());
         app->mem_graph->colors.at(1) = app->config.swap_color;
-    } else if (strcmp (key, GSM_SETTING_NET_IN_COLOR) == 0) {
-        gdk_rgba_parse (&app->config.net_in_color, color);
+    } else if (key == GSM_SETTING_NET_IN_COLOR) {
+        gdk_rgba_parse (&app->config.net_in_color, color.c_str ());
         app->net_graph->colors.at(0) = app->config.net_in_color;
-    } else if (strcmp (key, GSM_SETTING_NET_OUT_COLOR) == 0) {
-        gdk_rgba_parse (&app->config.net_out_color, color);
+    } else if (key == GSM_SETTING_NET_OUT_COLOR) {
+        gdk_rgba_parse (&app->config.net_out_color, color.c_str ());
         app->net_graph->colors.at(1) = app->config.net_out_color;
     }
-    g_free (color);
 }
 
 void
 GsmApplication::load_settings()
 {
-    gchar *color;
     glibtop_cpu cpu;
 
-    settings = g_settings_new (GSM_GSETTINGS_SCHEMA);
+    this->settings = Gio::Settings::create (GSM_GSETTINGS_SCHEMA);
 
-    config.solaris_mode = g_settings_get_boolean (settings, GSM_SETTING_SOLARIS_MODE);
-    g_signal_connect (settings, "changed::" GSM_SETTING_SOLARIS_MODE,
-                      G_CALLBACK (cb_solaris_mode_changed), this);
+    config.solaris_mode = this->settings->get_boolean (GSM_SETTING_SOLARIS_MODE);
+    this->settings->signal_changed(GSM_SETTING_SOLARIS_MODE).connect ([this](const Glib::ustring& key) {
+        cb_solaris_mode_changed (*this->settings.operator->(), key, this);
+    });
 
-    config.draw_stacked = g_settings_get_boolean (settings, GSM_SETTING_DRAW_STACKED);
-    g_signal_connect (settings, "changed::" GSM_SETTING_DRAW_STACKED,
-                      G_CALLBACK (cb_draw_stacked_changed), this);
+    config.draw_stacked = this->settings->get_boolean (GSM_SETTING_DRAW_STACKED);
+    this->settings->signal_changed(GSM_SETTING_DRAW_STACKED).connect ([this](const Glib::ustring& key) {
+        cb_draw_stacked_changed (*this->settings.operator->(), key, this);
+    });
 
-    config.network_in_bits = g_settings_get_boolean (settings, GSM_SETTING_NETWORK_IN_BITS);
-    g_signal_connect (settings, "changed::" GSM_SETTING_NETWORK_IN_BITS,
-                      G_CALLBACK (cb_network_in_bits_changed), this);
+    config.network_in_bits = this->settings->get_boolean (GSM_SETTING_NETWORK_IN_BITS);
+    this->settings->signal_changed (GSM_SETTING_NETWORK_IN_BITS).connect ([this](const Glib::ustring& key) {
+        cb_network_in_bits_changed (*this->settings.operator->(), key, this);
+    });
 
-    config.update_interval = g_settings_get_int (settings, GSM_SETTING_PROCESS_UPDATE_INTERVAL);
-    g_signal_connect (settings, "changed::" GSM_SETTING_PROCESS_UPDATE_INTERVAL,
-                      G_CALLBACK (cb_timeouts_changed), this);
-    config.graph_update_interval = g_settings_get_int (settings, GSM_SETTING_GRAPH_UPDATE_INTERVAL);
-    g_signal_connect (settings, "changed::" GSM_SETTING_GRAPH_UPDATE_INTERVAL,
-                      G_CALLBACK (cb_timeouts_changed), this);
-    config.disks_update_interval = g_settings_get_int (settings, GSM_SETTING_DISKS_UPDATE_INTERVAL);
-    g_signal_connect (settings, "changed::" GSM_SETTING_DISKS_UPDATE_INTERVAL,
-                      G_CALLBACK (cb_timeouts_changed), this);
+    auto cbtc = [this](const Glib::ustring& key) { cb_timeouts_changed(*this->settings.operator->(), key, 
this); };
+    config.update_interval = this->settings->get_int (GSM_SETTING_PROCESS_UPDATE_INTERVAL);
+    this->settings->signal_changed (GSM_SETTING_PROCESS_UPDATE_INTERVAL).connect (cbtc);
+    config.graph_update_interval = this->settings->get_int (GSM_SETTING_GRAPH_UPDATE_INTERVAL);
+    this->settings->signal_changed (GSM_SETTING_GRAPH_UPDATE_INTERVAL).connect (cbtc);
+    config.disks_update_interval = this->settings->get_int (GSM_SETTING_DISKS_UPDATE_INTERVAL);
+    this->settings->signal_changed (GSM_SETTING_DISKS_UPDATE_INTERVAL).connect (cbtc);
 
     glibtop_get_cpu (&cpu);
     frequency = cpu.frequency;
 
     config.num_cpus = glibtop_get_sysinfo()->ncpu; // or server->ncpu + 1
 
-    apply_cpu_color_settings (settings, this);
-    g_signal_connect (settings, "changed::" GSM_SETTING_CPU_COLORS,
-                      G_CALLBACK (cb_color_changed), this);
-
-    color = g_settings_get_string (settings, GSM_SETTING_MEM_COLOR);
-    if (!color)
-        color = g_strdup ("#000000ff0082");
-    g_signal_connect (settings, "changed::" GSM_SETTING_MEM_COLOR,
-                      G_CALLBACK (cb_color_changed), this);
-    gdk_rgba_parse (&config.mem_color, color);
-    g_free (color);
-
-    color = g_settings_get_string (settings, GSM_SETTING_SWAP_COLOR);
-    if (!color)
-        color = g_strdup ("#00b6000000ff");
-    g_signal_connect (settings, "changed::" GSM_SETTING_SWAP_COLOR,
-                      G_CALLBACK (cb_color_changed), this);
-    gdk_rgba_parse (&config.swap_color, color);
-    g_free (color);
-
-    color = g_settings_get_string (settings, GSM_SETTING_NET_IN_COLOR);
-    if (!color)
-        color = g_strdup ("#000000f200f2");
-    g_signal_connect (settings, "changed::" GSM_SETTING_NET_IN_COLOR,
-                      G_CALLBACK (cb_color_changed), this);
-    gdk_rgba_parse (&config.net_in_color, color);
-    g_free (color);
-
-    color = g_settings_get_string (settings, GSM_SETTING_NET_OUT_COLOR);
-    if (!color)
-        color = g_strdup ("#00f2000000c1");
-    g_signal_connect (settings, "changed::" GSM_SETTING_NET_OUT_COLOR,
-                      G_CALLBACK (cb_color_changed), this);
-    gdk_rgba_parse (&config.net_out_color, color);
-    g_free (color);
+    apply_cpu_color_settings (*this->settings.operator->(), this);
+
+    auto mem_color = this->settings->get_string (GSM_SETTING_MEM_COLOR);
+    gdk_rgba_parse (&config.mem_color, mem_color.empty () ? "#000000ff0082" : mem_color.c_str ());
+
+    auto swap_color = this->settings->get_string (GSM_SETTING_SWAP_COLOR);
+    gdk_rgba_parse (&config.swap_color, swap_color.empty () ? "#00b6000000ff" : swap_color.c_str ());
+
+    auto net_in_color = this->settings->get_string (GSM_SETTING_NET_IN_COLOR);
+    gdk_rgba_parse (&config.net_in_color, net_in_color.empty () ? "#000000f200f2" : net_in_color.c_str ());
+
+    auto net_out_color = this->settings->get_string (GSM_SETTING_NET_OUT_COLOR);
+    gdk_rgba_parse (&config.net_out_color, net_out_color.empty () ? "#00f2000000c1" : net_out_color.c_str 
());
+
+    auto cbcc = [this](const Glib::ustring& key) { cb_color_changed(*this->settings.operator->(), key, 
this); };
+    for (auto k : {GSM_SETTING_CPU_COLORS, GSM_SETTING_MEM_COLOR, GSM_SETTING_SWAP_COLOR, 
GSM_SETTING_NET_IN_COLOR, GSM_SETTING_NET_OUT_COLOR}) {
+        this->settings->signal_changed (k).connect(cbcc);
+    }
 }
 
 
@@ -288,10 +257,10 @@ GsmApplication::save_config ()
 
     maximized = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (main_window))) & 
GDK_WINDOW_STATE_MAXIMIZED;
 
-    g_settings_set (settings, GSM_SETTING_WINDOW_STATE, "(iiii)",
+    g_settings_set (settings->gobj (), GSM_SETTING_WINDOW_STATE, "(iiii)",
                     width, height, xpos, ypos);
 
-    g_settings_set_boolean (settings, GSM_SETTING_MAXIMIZED, maximized);
+    settings->set_boolean (GSM_SETTING_MAXIMIZED, maximized);
 }
 
 int GsmApplication::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>& command_line)
@@ -319,11 +288,11 @@ int GsmApplication::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLi
     }
 
     if (option_group.show_processes_tab)
-        g_settings_set_string (settings, GSM_SETTING_CURRENT_TAB, "processes");
+        this->settings->set_string (GSM_SETTING_CURRENT_TAB, "processes");
     else if (option_group.show_resources_tab)
-        g_settings_set_string (settings, GSM_SETTING_CURRENT_TAB, "resources");
+        this->settings->set_string (GSM_SETTING_CURRENT_TAB, "resources");
     else if (option_group.show_file_systems_tab)
-        g_settings_set_string (settings, GSM_SETTING_CURRENT_TAB, "disks");
+        this->settings->set_string (GSM_SETTING_CURRENT_TAB, "disks");
     else if (option_group.print_version)
 
     on_activate ();
diff --git a/src/application.h b/src/application.h
index 895321e..857fdce 100644
--- a/src/application.h
+++ b/src/application.h
@@ -229,7 +229,7 @@ public:
 
     PrettyTable      *pretty_table;
 
-    GSettings        *settings;
+    Glib::RefPtr<Gio::Settings> settings;
     GtkApplicationWindow *main_window;
 
     unsigned         frequency;
diff --git a/src/disks.cpp b/src/disks.cpp
index 4d4803b..d1933de 100644
--- a/src/disks.cpp
+++ b/src/disks.cpp
@@ -238,7 +238,7 @@ disks_update(GsmApplication *app)
     gboolean show_all_fs;
 
     list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app->disk_list)));
-    show_all_fs = g_settings_get_boolean (app->settings, GSM_SETTING_SHOW_ALL_FS);
+    show_all_fs = app->settings->get_boolean (GSM_SETTING_SHOW_ALL_FS);
     entries = glibtop_get_mountlist (&mountlist, show_all_fs);
 
     remove_old_disks(GTK_TREE_MODEL(list), entries, mountlist.number);
@@ -336,15 +336,6 @@ cb_disk_list_destroying (GtkWidget *self, gpointer data)
                                           data);
 }
 
-static void
-cb_show_all_fs_changed (GSettings *settings, const gchar *key, gpointer data)
-{
-    GsmApplication *app = (GsmApplication *) data;
-
-    disks_update (app);
-    disks_reset_timeout (app);
-}
-
 
 void
 create_disk_view(GsmApplication *app, GtkBuilder *builder)
@@ -367,8 +358,6 @@ create_disk_view(GsmApplication *app, GtkBuilder *builder)
         N_("Used")
     };
 
-    GSettings * settings = g_settings_get_child (app->settings, GSM_SETTINGS_CHILD_DISKS);
-
     scrolled = GTK_SCROLLED_WINDOW (gtk_builder_get_object (builder, "disks_scrolled"));
 
     model = gtk_list_store_new(DISK_N_COLUMNS,      /* n columns */
@@ -382,7 +371,7 @@ create_disk_view(GsmApplication *app, GtkBuilder *builder)
                                GDK_TYPE_PIXBUF,     /* DISK_ICON */
                                G_TYPE_INT           /* DISK_USED_PERCENTAGE */
         );
-    disk_tree = gsm_tree_view_new (settings, TRUE);
+    disk_tree = gsm_tree_view_new (g_settings_get_child (app->settings->gobj(), GSM_SETTINGS_CHILD_DISKS), 
TRUE);
     gtk_tree_view_set_model (GTK_TREE_VIEW (disk_tree), GTK_TREE_MODEL (model));
 
     g_signal_connect(G_OBJECT(disk_tree), "row-activated", G_CALLBACK(open_dir), NULL);
@@ -478,8 +467,7 @@ create_disk_view(GsmApplication *app, GtkBuilder *builder)
     g_signal_connect (G_OBJECT (model), "sort-column-changed",
                       G_CALLBACK (cb_sort_changed), app);
 
-    g_signal_connect (app->settings, "changed::" GSM_SETTING_SHOW_ALL_FS,
-                      G_CALLBACK (cb_show_all_fs_changed), app);
+    app->settings->signal_changed(GSM_SETTING_SHOW_ALL_FS).connect ([app](const Glib::ustring&) { 
disks_update (app); disks_reset_timeout (app); });
 
     gtk_widget_show (GTK_WIDGET (disk_tree));
 }
diff --git a/src/interface.cpp b/src/interface.cpp
index 8ba9475..af2c922 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -98,10 +98,10 @@ void
 cb_cpu_color_changed (GsmColorButton *cp, gpointer data)
 {
     guint cpu_i = GPOINTER_TO_UINT (data);
-    GSettings *settings = g_settings_new (GSM_GSETTINGS_SCHEMA);
+    auto settings = Gio::Settings::create (GSM_GSETTINGS_SCHEMA);
 
     /* Get current values */
-    GVariant *cpu_colors_var = g_settings_get_value (settings, GSM_SETTING_CPU_COLORS);
+    GVariant *cpu_colors_var = g_settings_get_value (settings->gobj(), GSM_SETTING_CPU_COLORS);
     gsize children_n = g_variant_n_children(cpu_colors_var);
 
     /* Create builder to contruct new setting with updated value for cpu i */
@@ -123,11 +123,10 @@ cb_cpu_color_changed (GsmColorButton *cp, gpointer data)
     }
 
     /* Just set the value and let the changed::cpu-colors signal callback do the rest. */
-    g_settings_set_value (settings, GSM_SETTING_CPU_COLORS,
-                          g_variant_builder_end(&builder));
+    settings->set_value (GSM_SETTING_CPU_COLORS, Glib::wrap (g_variant_builder_end(&builder)));
 }
 
-static void change_settings_color(GSettings *settings, const char *key,
+static void change_settings_color(Gio::Settings& settings, const char *key,
                                   GsmColorButton *cp)
 {
     GdkRGBA c;
@@ -135,7 +134,7 @@ static void change_settings_color(GSettings *settings, const char *key,
 
     gsm_color_button_get_color(cp, &c);
     color = gdk_rgba_to_string (&c);
-    g_settings_set_string (settings, key, color);
+    settings.set_string (key, color);
     g_free (color);
 }
 
@@ -143,7 +142,7 @@ static void
 cb_mem_color_changed (GsmColorButton *cp, gpointer data)
 {
     GsmApplication *app = (GsmApplication *) data;
-    change_settings_color (app->settings, GSM_SETTING_MEM_COLOR, cp);
+    change_settings_color (*app->settings.operator->(), GSM_SETTING_MEM_COLOR, cp);
 }
 
 
@@ -151,21 +150,21 @@ static void
 cb_swap_color_changed (GsmColorButton *cp, gpointer data)
 {
     GsmApplication *app = (GsmApplication *) data;
-    change_settings_color (app->settings, GSM_SETTING_SWAP_COLOR, cp);
+    change_settings_color (*app->settings.operator->(), GSM_SETTING_SWAP_COLOR, cp);
 }
 
 static void
 cb_net_in_color_changed (GsmColorButton *cp, gpointer data)
 {
     GsmApplication *app = (GsmApplication *) data;
-    change_settings_color (app->settings, GSM_SETTING_NET_IN_COLOR, cp);
+    change_settings_color (*app->settings.operator->(), GSM_SETTING_NET_IN_COLOR, cp);
 }
 
 static void
 cb_net_out_color_changed (GsmColorButton *cp, gpointer data)
 {
     GsmApplication *app = (GsmApplication *) data;
-    change_settings_color(app->settings, GSM_SETTING_NET_OUT_COLOR, cp);
+    change_settings_color(*app->settings.operator->(), GSM_SETTING_NET_OUT_COLOR, cp);
 }
 
 static void
@@ -383,7 +382,7 @@ on_activate_refresh (GSimpleAction *, GVariant *, gpointer data)
 
 static void
 kill_process_with_confirmation (GsmApplication *app, int signal) {
-    gboolean kill_dialog = g_settings_get_boolean (app->settings, GSM_SETTING_SHOW_KILL_DIALOG);
+    gboolean kill_dialog = app->settings->get_boolean(GSM_SETTING_SHOW_KILL_DIALOG);
 
     if (kill_dialog)
         procdialog_create_kill_dialog (app, signal);
@@ -469,8 +468,9 @@ change_show_page_state (GSimpleAction *action, GVariant *state, gpointer data)
 {
     GsmApplication *app = (GsmApplication *) data;
 
+    auto state_var = Glib::wrap(state, true);
     g_simple_action_set_state (action, state);
-    g_settings_set_value (app->settings, GSM_SETTING_CURRENT_TAB, state);
+    app->settings->set_value (GSM_SETTING_CURRENT_TAB, state_var);
 }
 
 static void
@@ -478,8 +478,9 @@ change_show_processes_state (GSimpleAction *action, GVariant *state, gpointer da
 {
     GsmApplication *app = (GsmApplication *) data;
 
+    auto state_var = Glib::wrap(state, true);
     g_simple_action_set_state (action, state);
-    g_settings_set_value (app->settings, GSM_SETTING_SHOW_WHOSE_PROCESSES, state);
+    app->settings->set_value (GSM_SETTING_SHOW_WHOSE_PROCESSES, state_var);
 }
 
 static void
@@ -487,8 +488,9 @@ change_show_dependencies_state (GSimpleAction *action, GVariant *state, gpointer
 {
     GsmApplication *app = (GsmApplication *) data;
 
+    auto state_var = Glib::wrap(state, true);
     g_simple_action_set_state (action, state);
-    g_settings_set_value (app->settings, GSM_SETTING_SHOW_DEPENDENCIES, state);
+    app->settings->set_value (GSM_SETTING_SHOW_DEPENDENCIES, state_var);
 }
 
 static void
@@ -585,34 +587,33 @@ static gboolean
 cb_main_window_state_changed (GtkWidget *window, GdkEventWindowState *event, gpointer data)
 {
     GsmApplication *app = (GsmApplication *) data;
-    gchar * current_page = g_settings_get_string (app->settings, GSM_SETTING_CURRENT_TAB);
+    auto current_page = app->settings->get_string (GSM_SETTING_CURRENT_TAB);
     if (event->new_window_state & GDK_WINDOW_STATE_BELOW ||
         event->new_window_state & GDK_WINDOW_STATE_ICONIFIED ||
         event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN)
     {
-        if (strcmp (current_page, "processes") == 0) {
+        if (current_page == "processes") {
             proctable_freeze (app);
-        } else if (strcmp (current_page, "resources") == 0) {
+        } else if (current_page == "resources") {
             load_graph_stop (app->cpu_graph);
             load_graph_stop (app->mem_graph);
             load_graph_stop (app->net_graph);
-        } else if (strcmp (current_page, "disks") == 0) {
+        } else if (current_page == "disks") {
             disks_freeze (app);
         }
     } else  {
-        if (strcmp (current_page, "processes") == 0) {
+        if (current_page == "processes") {
             proctable_update (app);
             proctable_thaw (app);
-        } else if (strcmp (current_page, "resources") == 0) {
+        } else if (current_page == "resources") {
             load_graph_start (app->cpu_graph);
             load_graph_start (app->mem_graph);
             load_graph_start (app->net_graph);
-        } else if (strcmp (current_page, "disks") == 0) {
+        } else if (current_page == "disks") {
             disks_update (app);
             disks_thaw (app);
         }
     }
-    g_free (current_page);
     return FALSE;
 }
 
@@ -650,14 +651,14 @@ create_main_window (GsmApplication *app)
         gtk_box_pack_start (mainbox, GTK_WIDGET (headerbar), FALSE, FALSE, 0);
     }
 
-    g_settings_get (app->settings, GSM_SETTING_WINDOW_STATE, "(iiii)",
+    g_settings_get (app->settings->gobj(), GSM_SETTING_WINDOW_STATE, "(iiii)",
                     &width, &height, &xpos, &ypos);
     width = CLAMP (width, 50, gdk_screen_width ());
     height = CLAMP (height, 50, gdk_screen_height ());
 
     gtk_window_set_default_size (GTK_WINDOW (main_window), width, height);
     gtk_window_move (GTK_WINDOW (main_window), xpos, ypos);
-    if (g_settings_get_boolean (app->settings, GSM_SETTING_MAXIMIZED))
+    if (app->settings->get_boolean (GSM_SETTING_MAXIMIZED))
         gtk_window_maximize (GTK_WINDOW (main_window));
 
     app->process_menu_button = process_menu_button = GTK_MENU_BUTTON (gtk_builder_get_object (builder, 
"process_menu_button"));
@@ -706,7 +707,7 @@ create_main_window (GsmApplication *app)
     
     create_disk_view (app, builder);
 
-    g_settings_bind (app->settings, GSM_SETTING_CURRENT_TAB, stack, "visible-child-name", 
G_SETTINGS_BIND_DEFAULT);
+    g_settings_bind (app->settings->gobj (), GSM_SETTING_CURRENT_TAB, stack, "visible-child-name", 
G_SETTINGS_BIND_DEFAULT);
 
     g_signal_connect (G_OBJECT (stack), "notify::visible-child",
                       G_CALLBACK (cb_change_current_page), app);
@@ -722,13 +723,13 @@ create_main_window (GsmApplication *app)
     action = g_action_map_lookup_action (G_ACTION_MAP (main_window),
                                          "show-dependencies");
     g_action_change_state (action,
-                           g_settings_get_value (app->settings, GSM_SETTING_SHOW_DEPENDENCIES));
+                           g_settings_get_value (app->settings->gobj (), GSM_SETTING_SHOW_DEPENDENCIES));
 
 
     action = g_action_map_lookup_action (G_ACTION_MAP (main_window),
                                          "show-whose-processes");
     g_action_change_state (action,
-                           g_settings_get_value (app->settings, GSM_SETTING_SHOW_WHOSE_PROCESSES));
+                           g_settings_get_value (app->settings->gobj (), GSM_SETTING_SHOW_WHOSE_PROCESSES));
 
     gtk_widget_show (GTK_WIDGET (main_window));
     
diff --git a/src/memmaps.cpp b/src/memmaps.cpp
index 9de7a3c..9fe95fb 100644
--- a/src/memmaps.cpp
+++ b/src/memmaps.cpp
@@ -345,13 +345,13 @@ create_memmapsdata (GsmApplication *app)
                                 G_TYPE_UINT64 /* MMAP_COL_INODE      */
         );
 
-    GSettings *settings = g_settings_get_child (app->settings, GSM_SETTINGS_CHILD_MEMMAP);
+    auto settings = g_settings_get_child (app->settings->gobj (), GSM_SETTINGS_CHILD_MEMMAP);
 
     tree = gsm_tree_view_new (settings, FALSE);
     gtk_tree_view_set_model (GTK_TREE_VIEW (tree), GTK_TREE_MODEL (model));
     g_object_unref (G_OBJECT (model));
 
-    gchar *font = get_monospace_system_font_name ();
+    auto font = get_monospace_system_font_name ();
 
     for (i = 0; i < MMAP_COL_MAX; i++) {
         GtkCellRenderer *cell;
@@ -390,13 +390,11 @@ create_memmapsdata (GsmApplication *app)
             case MMAP_COL_VMEND:
             case MMAP_COL_FLAGS:
             case MMAP_COL_VMOFFSET:
-                g_object_set (cell, "font", font, NULL);
+                g_object_set (cell, "font", font.c_str (), NULL);
                 break;
         }
     }
 
-    g_free (font);
-
     return new MemMapsData(tree);
 }
 
diff --git a/src/openfiles.cpp b/src/openfiles.cpp
index 9505da5..750ea05 100644
--- a/src/openfiles.cpp
+++ b/src/openfiles.cpp
@@ -260,7 +260,7 @@ create_openfiles_tree (GsmApplication *app)
                                 G_TYPE_POINTER      /* open_files_entry */
         );
 
-    GSettings *settings = g_settings_get_child (app->settings, GSM_SETTINGS_CHILD_OPEN_FILES);
+    auto settings = g_settings_get_child (app->settings->gobj (), GSM_SETTINGS_CHILD_OPEN_FILES);
 
     tree = gsm_tree_view_new (settings, FALSE);
     gtk_tree_view_set_model (GTK_TREE_VIEW (tree), GTK_TREE_MODEL (model));
diff --git a/src/prefsdialog.cpp b/src/prefsdialog.cpp
index ecee87b..1e24b34 100644
--- a/src/prefsdialog.cpp
+++ b/src/prefsdialog.cpp
@@ -45,8 +45,7 @@ private:
     {
         int new_value = int(1000 * gtk_spin_button_get_value(spin));
 
-        g_settings_set_int(GsmApplication::get()->settings,
-                           this->key.c_str(), new_value);
+        GsmApplication::get()->settings->set_int(this->key, new_value);
 
         procman_debug("set %s to %d", this->key.c_str(), new_value);
     }
@@ -62,8 +61,7 @@ field_toggled (const gchar *gsettings_parent, gchar *path_str, gpointer data)
     GtkTreeIter iter;
     GtkTreeViewColumn *column;
     gboolean toggled;
-    GSettings *settings = g_settings_get_child (GsmApplication::get()->settings, gsettings_parent);
-    gchar *key;
+    auto settings = GsmApplication::get()->settings->get_child (gsettings_parent);
     int id;
 
     if (!path)
@@ -79,9 +77,8 @@ field_toggled (const gchar *gsettings_parent, gchar *path_str, gpointer data)
 
     id = gtk_tree_view_column_get_sort_column_id (column);
 
-    key = g_strdup_printf ("col-%d-visible", id);
-    g_settings_set_boolean (settings, key, !toggled);
-    g_free (key);
+    auto key = Glib::ustring::compose ("col-%1-visible", id);
+    settings->set_boolean (key, !toggled);
 
     gtk_tree_path_free (path);
 
@@ -236,20 +233,20 @@ create_preferences_dialog (GsmApplication *app)
                       G_CALLBACK (SBU::callback), &interval_updater);
 
     smooth_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "smooth_button"));
-    g_settings_bind(app->settings, SmoothRefresh::KEY.c_str(), smooth_button, "active", 
G_SETTINGS_BIND_DEFAULT);
+    g_settings_bind(app->settings->gobj (), SmoothRefresh::KEY.c_str(), smooth_button, "active", 
G_SETTINGS_BIND_DEFAULT);
 
     check_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "check_button"));
-    g_settings_bind (app->settings, GSM_SETTING_SHOW_KILL_DIALOG,
+    g_settings_bind (app->settings->gobj (), GSM_SETTING_SHOW_KILL_DIALOG,
                      check_button, "active",
                      G_SETTINGS_BIND_DEFAULT);
 
     GtkCheckButton *solaris_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "solaris_button"));
-    g_settings_bind (app->settings, GSM_SETTING_SOLARIS_MODE,
+    g_settings_bind (app->settings->gobj (), GSM_SETTING_SOLARIS_MODE,
                      solaris_button, "active",
                      G_SETTINGS_BIND_DEFAULT);
 
     GtkCheckButton *draw_stacked_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, 
"draw_stacked_button"));
-    g_settings_bind (app->settings, GSM_SETTING_DRAW_STACKED,
+    g_settings_bind (app->settings->gobj (), GSM_SETTING_DRAW_STACKED,
                      draw_stacked_button, "active",
                      G_SETTINGS_BIND_DEFAULT);
 
@@ -265,7 +262,7 @@ create_preferences_dialog (GsmApplication *app)
                       &graph_interval_updater);
 
     GtkCheckButton *bits_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "bits_button"));
-    g_settings_bind(app->settings, GSM_SETTING_NETWORK_IN_BITS,
+    g_settings_bind(app->settings->gobj (), GSM_SETTING_NETWORK_IN_BITS,
                     bits_button, "active",
                     G_SETTINGS_BIND_DEFAULT);
 
@@ -280,7 +277,7 @@ create_preferences_dialog (GsmApplication *app)
 
 
     check_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "all_devices_check"));
-    g_settings_bind (app->settings, GSM_SETTING_SHOW_ALL_FS,
+    g_settings_bind (app->settings->gobj (), GSM_SETTING_SHOW_ALL_FS,
                      check_button, "active",
                      G_SETTINGS_BIND_DEFAULT);
 
@@ -292,16 +289,14 @@ create_preferences_dialog (GsmApplication *app)
     g_signal_connect (G_OBJECT (prefs_dialog), "response",
                       G_CALLBACK (prefs_dialog_button_pressed), app);
 
-    char *current_tab = g_settings_get_string (app->settings, GSM_SETTING_CURRENT_TAB);
-    if (strcmp (current_tab, "processes") == 0)
+    auto current_tab = app->settings->get_string(GSM_SETTING_CURRENT_TAB);
+    if (current_tab == "processes")
         gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
-    else if (strcmp (current_tab, "resources") == 0)
+    else if (current_tab == "resources")
         gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
-    else if (strcmp (current_tab, "disks") == 0)
+    else if (current_tab == "disks")
         gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
 
-    g_free (current_tab);
-
     gtk_builder_connect_signals (builder, NULL);
     g_object_unref (G_OBJECT (builder));
 }
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 33c0dfb..c8dc023 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -254,7 +254,7 @@ process_visibility_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 
        // in case we are in dependencies view, we show (and expand) rows not matching the text, but having a 
matching child
     gboolean match = false;
-    if (g_settings_get_boolean (app->settings, GSM_SETTING_SHOW_DEPENDENCIES)) {
+    if (app->settings->get_boolean (GSM_SETTING_SHOW_DEPENDENCIES)) {
         GtkTreeIter child;
         if (gtk_tree_model_iter_children (model, &child, iter)) {
             gboolean child_match = FALSE;
@@ -296,14 +296,12 @@ proctable_clear_tree (GsmApplication * const app)
 
     update_sensitivity(app);
 }
-                                                        
+
 static void
-cb_show_dependencies_changed (GSettings *settings, const gchar *key, gpointer data)
-{
-    GsmApplication *app = (GsmApplication *) data;
+cb_show_dependencies_changed(Gio::Settings& settings, Glib::ustring key, GsmApplication* app) {
     if (app->timeout) {
         gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (app->tree),
-                                      g_settings_get_boolean (settings, GSM_SETTING_SHOW_DEPENDENCIES));
+                                          settings.get_boolean (GSM_SETTING_SHOW_DEPENDENCIES));
 
         proctable_clear_tree (app);
         proctable_update (app);
@@ -311,9 +309,7 @@ cb_show_dependencies_changed (GSettings *settings, const gchar *key, gpointer da
 }
 
 static void
-cb_show_whose_processes_changed (GSettings *settings, const gchar *key, gpointer data)
-{
-    GsmApplication *app = (GsmApplication *) data;
+cb_show_whose_processes_changed(Gio::Settings& settings, Glib::ustring key, GsmApplication* app) {
     if (app->timeout) {
         proctable_clear_tree (app);
         proctable_update (app);
@@ -362,7 +358,7 @@ proctable_new (GsmApplication * const app)
     };
 
     gint i;
-    GSettings * settings = g_settings_get_child (app->settings, GSM_SETTINGS_CHILD_PROCESSES);
+    auto settings = g_settings_get_child (app->settings->gobj (), GSM_SETTINGS_CHILD_PROCESSES);
     model = gtk_tree_store_new (NUM_COLUMNS,
                                 G_TYPE_STRING,      /* Process Name */
                                 G_TYPE_STRING,      /* User         */
@@ -402,8 +398,7 @@ proctable_new (GsmApplication * const app)
     gtk_tree_view_set_model (GTK_TREE_VIEW (proctree), GTK_TREE_MODEL (model_sort));
 
     gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (proctree), COL_TOOLTIP);
-    gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (proctree),
-                                      g_settings_get_boolean (app->settings, GSM_SETTING_SHOW_DEPENDENCIES));
+    gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (proctree), app->settings->get_boolean 
(GSM_SETTING_SHOW_DEPENDENCIES));
     gtk_tree_view_set_enable_search (GTK_TREE_VIEW (proctree), FALSE);
     g_object_unref (G_OBJECT (model));
 
@@ -603,11 +598,13 @@ proctable_new (GsmApplication * const app)
     g_signal_connect (G_OBJECT (model_sort), "sort-column-changed",
                       G_CALLBACK (cb_save_tree_state), app);
 
-    g_signal_connect (app->settings, "changed::" GSM_SETTING_SHOW_DEPENDENCIES,
-                      G_CALLBACK (cb_show_dependencies_changed), app);
+    app->settings->signal_changed(GSM_SETTING_SHOW_DEPENDENCIES).connect([app](const Glib::ustring& key) {
+        cb_show_dependencies_changed(*app->settings.operator->(), key, app);
+    });
 
-    g_signal_connect (app->settings, "changed::" GSM_SETTING_SHOW_WHOSE_PROCESSES,
-                      G_CALLBACK (cb_show_whose_processes_changed), app);
+    app->settings->signal_changed(GSM_SETTING_SHOW_WHOSE_PROCESSES).connect([app](const Glib::ustring& key) {
+        cb_show_whose_processes_changed(*app->settings.operator->(), key, app);
+    });
 
     gtk_widget_show (GTK_WIDGET (proctree));
 
@@ -790,7 +787,7 @@ insert_info_to_tree (ProcInfo *info, GsmApplication *app, bool forced = false)
     filtered = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(sorted));
     model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filtered));
     
-    if (g_settings_get_boolean (app->settings, GSM_SETTING_SHOW_DEPENDENCIES)) {
+    if (app->settings->get_boolean (GSM_SETTING_SHOW_DEPENDENCIES)) {
 
         ProcInfo *parent = 0;
 
@@ -1028,7 +1025,7 @@ refresh_list (GsmApplication *app, const pid_t* pid_list, const guint n)
     // pid_list == ProcInfo::all + addition
 
 
-    if (g_settings_get_boolean (app->settings, GSM_SETTING_SHOW_DEPENDENCIES)) {
+    if (app->settings->get_boolean (GSM_SETTING_SHOW_DEPENDENCIES)) {
 
         // insert process in the tree. walk through the addition list
         // (new process + process that have a new parent). This loop
@@ -1106,18 +1103,17 @@ proctable_update (GsmApplication *app)
     glibtop_cpu cpu;
     int which = 0;
     int arg = 0;
-    char *whose_processes = g_settings_get_string (app->settings, GSM_SETTING_SHOW_WHOSE_PROCESSES);
-    if (strcmp (whose_processes, "all") == 0) {
+    auto whose_processes = app->settings->get_string(GSM_SETTING_SHOW_WHOSE_PROCESSES);
+    if (whose_processes == "all") {
         which = GLIBTOP_KERN_PROC_ALL;
         arg = 0;
-    } else if (strcmp (whose_processes, "active") == 0) {
+    } else if (whose_processes == "active") {
         which = GLIBTOP_KERN_PROC_ALL | GLIBTOP_EXCLUDE_IDLE;
         arg = 0;
-    } else if (strcmp (whose_processes, "user") == 0) {
+    } else if (whose_processes == "user") {
       which = GLIBTOP_KERN_PROC_UID;
       arg = getuid ();
     }
-    g_free (whose_processes);
 
     pid_list = glibtop_get_proclist (&proclist, which, arg);
 
diff --git a/src/smooth_refresh.cpp b/src/smooth_refresh.cpp
index 1ed8a82..45f28c1 100644
--- a/src/smooth_refresh.cpp
+++ b/src/smooth_refresh.cpp
@@ -40,41 +40,28 @@ unsigned SmoothRefresh::get_own_cpu_usage()
     return usage;
 }
 
-
-
-void SmoothRefresh::status_changed(GSettings *settings,
-                                   const gchar *key,
-                                   gpointer user_data)
-{
-    static_cast<SmoothRefresh*>(user_data)->load_settings_value(key);
-}
-
-void SmoothRefresh::load_settings_value(const gchar *key)
+void SmoothRefresh::load_settings_value(Glib::ustring key)
 {
-    this->active = g_settings_get_boolean(settings, key);
+    this->active = this->settings->get_boolean(key);
 
     if (this->active)
         procman_debug("smooth_refresh is enabled");
 }
 
 
-SmoothRefresh::SmoothRefresh(GSettings *a_settings)
+SmoothRefresh::SmoothRefresh(Glib::RefPtr<Gio::Settings> a_settings)
     :
     settings(a_settings),
     active(false),
-    connection(0),
     interval(0),
     last_pcpu(0),
     last_total_time(0ULL),
     last_cpu_time(0ULL)
 {
-    this->connection = g_signal_connect(G_OBJECT(settings),
-                                        "changed::smooth-refresh",
-                                        G_CALLBACK(status_changed),
-                                        this);
+    this->connection = a_settings->signal_changed("smooth_refresh").connect([this](const Glib::ustring& key) 
{ this->load_settings_value(key); });
 
     this->reset();
-    this->load_settings_value(KEY.c_str());
+    this->load_settings_value(KEY);
 }
 
 
@@ -98,7 +85,7 @@ void SmoothRefresh::reset()
 SmoothRefresh::~SmoothRefresh()
 {
     if (this->connection)
-        g_signal_handler_disconnect(G_OBJECT(settings), this->connection);
+        this->connection.disconnect();
 }
 
 
diff --git a/src/smooth_refresh.h b/src/smooth_refresh.h
index c83693f..8dc1f97 100644
--- a/src/smooth_refresh.h
+++ b/src/smooth_refresh.h
@@ -2,8 +2,8 @@
 #ifndef _GSM_SMOOTH_REFRESH_H
 #define _GSM_SMOOTH_REFRESH_H
 
-#include <glib.h>
-#include <gio/gio.h>
+#include <giomm.h>
+#include <glibmm.h>
 #include <string>
 
 #include "util.h"
@@ -25,7 +25,7 @@ class SmoothRefresh
 
       @return : initialized SmoothRefresh
     */
-    SmoothRefresh(GSettings *a_settings);
+    SmoothRefresh(Glib::RefPtr<Gio::Settings> a_settings);
 
     ~SmoothRefresh();
 
@@ -57,11 +57,7 @@ class SmoothRefresh
 
     unsigned get_own_cpu_usage();
 
-    static void status_changed(GSettings *settings,
-                               const gchar *key,
-                               gpointer user_data);
-
-    void load_settings_value(const gchar *key);
+    void load_settings_value(Glib::ustring key);
 
     /*
       fuzzy logic:
@@ -94,9 +90,9 @@ class SmoothRefresh
       -last_cpu_time: Save last cpu and process times to compute CPU%
     */
 
-    GSettings *settings;
+    Glib::RefPtr<Gio::Settings> settings;
     bool active;
-    guint connection;
+    sigc::connection connection;
     guint interval;
     unsigned  last_pcpu;
     guint64 last_total_time;
diff --git a/src/util.cpp b/src/util.cpp
index 5650930..f35f702 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -649,14 +649,8 @@ namespace procman
 
 }
 
-gchar *
+Glib::ustring
 get_monospace_system_font_name ()
 {
-    GSettings *desktop_settings = g_settings_new ("org.gnome.desktop.interface");
-    char *font;
-
-    font = g_settings_get_string (desktop_settings, "monospace-font-name");
-    g_object_unref (desktop_settings);
-
-    return font;
+    return Gio::Settings::create ("org.gnome.desktop.interface")->get_string ("monospace-font-name");
 }
diff --git a/src/util.h b/src/util.h
index 083f247..a389b35 100644
--- a/src/util.h
+++ b/src/util.h
@@ -2,8 +2,7 @@
 #ifndef _GSM_UTIL_H_
 #define _GSM_UTIL_H_
 
-#include <glib.h>
-#include <gtk/gtk.h>
+#include <gtkmm.h>
 #include <string>
 
 using std::string;
@@ -25,7 +24,7 @@ procman_debug_real(const char *file, int line, const char *func,
 
 #define procman_debug(FMT, ...) procman_debug_real(__FILE__, __LINE__, __func__, FMT, ##__VA_ARGS__)
 
-gchar * get_monospace_system_font_name (void);
+Glib::ustring get_monospace_system_font_name (void);
 
 inline string make_string(char *c_str)
 {



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