[virt-tools-list] [PATCH 1/2] Fix "Do not ask me again" checkbox settings saving

Hans de Goede hdegoede at redhat.com
Wed Feb 6 16:40:40 UTC 2013


The code block for saving was below this check:

    if (priv->session) {
        virt_viewer_session_close(VIRT_VIEWER_SESSION(priv->session));
        if (priv->connected) {
            priv->quiting = TRUE;
            return;
        }
    }

Which means it never executes when quiting virt-viewer while conneced, causing
the "Do not ask me again" checkbox settings to not be saved.

This patch fixes this by moving the saving code to virt_viewer_app_finalize()
which also nice balances it with the loading code in virt_viewer_app_init().

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 src/virt-viewer-app.c | 47 +++++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 20 deletions(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index f5d78a9..731cfbf 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -223,9 +223,6 @@ virt_viewer_app_simple_message_dialog(VirtViewerApp *self,
 void
 virt_viewer_app_quit(VirtViewerApp *self)
 {
-    GError *error = NULL;
-    gchar *data;
-
     g_return_if_fail(VIRT_VIEWER_IS_APP(self));
     VirtViewerAppPrivate *priv = self->priv;
 
@@ -237,20 +234,6 @@ virt_viewer_app_quit(VirtViewerApp *self)
         }
     }
 
-    {
-        gchar *dir = g_path_get_dirname(priv->config_file);
-        if (g_mkdir_with_parents(dir, S_IRWXU) == -1)
-            g_warning("failed to create config directory");
-        g_free(dir);
-    }
-
-    if ((data = g_key_file_to_data(priv->config, NULL, &error)) == NULL ||
-        !g_file_set_contents(priv->config_file, data, -1, &error)) {
-        g_warning("Couldn't save configuration: %s", error->message);
-        g_clear_error(&error);
-    }
-    g_free(data);
-
     gtk_main_quit();
 }
 
@@ -1340,15 +1323,38 @@ virt_viewer_app_dispose (GObject *object)
     priv->guri = NULL;
     g_free(priv->title);
     priv->title = NULL;
-    g_free(priv->config_file);
-    priv->config_file = NULL;
-    g_clear_pointer(&priv->config, g_key_file_free);
 
     virt_viewer_app_free_connect_info(self);
 
     G_OBJECT_CLASS (virt_viewer_app_parent_class)->dispose (object);
 }
 
+static void
+virt_viewer_app_finalize (GObject *object)
+{
+    VirtViewerApp *self = VIRT_VIEWER_APP(object);
+    VirtViewerAppPrivate *priv = self->priv;
+    GError *error = NULL;
+    gchar *data, *dir;
+
+    dir = g_path_get_dirname(priv->config_file);
+    if (g_mkdir_with_parents(dir, S_IRWXU) == -1)
+        g_warning("failed to create config directory");
+    g_free(dir);
+
+    if ((data = g_key_file_to_data(priv->config, NULL, &error)) == NULL ||
+        !g_file_set_contents(priv->config_file, data, -1, &error)) {
+        g_warning("Couldn't save configuration: %s", error->message);
+        g_clear_error(&error);
+    }
+    g_free(data);
+
+    g_clear_pointer(&priv->config, g_key_file_free);
+    g_free(priv->config_file);
+
+    G_OBJECT_CLASS (virt_viewer_app_parent_class)->finalize (object);
+}
+
 static gboolean
 virt_viewer_app_default_start(VirtViewerApp *self)
 {
@@ -1423,6 +1429,7 @@ virt_viewer_app_class_init (VirtViewerAppClass *klass)
     object_class->get_property = virt_viewer_app_get_property;
     object_class->set_property = virt_viewer_app_set_property;
     object_class->dispose = virt_viewer_app_dispose;
+    object_class->finalize = virt_viewer_app_finalize;
 
     klass->start = virt_viewer_app_default_start;
     klass->initial_connect = virt_viewer_app_default_initial_connect;
-- 
1.8.1




More information about the virt-tools-list mailing list