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

Marc-André Lureau marcandre.lureau at gmail.com
Wed Feb 6 14:13:34 UTC 2013


wait, that's bad, dispose can potentially be run multiple times.

nack

On Wed, Feb 6, 2013 at 3:13 PM, Marc-André Lureau
<marcandre.lureau at gmail.com> wrote:
> ack
>
> On Wed, Feb 6, 2013 at 2:39 PM, Hans de Goede <hdegoede at redhat.com> wrote:
>> 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_dispose()
>> 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 | 33 ++++++++++++++++-----------------
>>  1 file changed, 16 insertions(+), 17 deletions(-)
>>
>> diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
>> index f5d78a9..ca401f5 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();
>>  }
>>
>> @@ -1310,6 +1293,8 @@ virt_viewer_app_dispose (GObject *object)
>>  {
>>      VirtViewerApp *self = VIRT_VIEWER_APP(object);
>>      VirtViewerAppPrivate *priv = self->priv;
>> +    GError *error = NULL;
>> +    gchar *data;
>>
>>      if (priv->windows) {
>>          GHashTable *tmp = priv->windows;
>> @@ -1340,6 +1325,20 @@ virt_viewer_app_dispose (GObject *object)
>>      priv->guri = NULL;
>>      g_free(priv->title);
>>      priv->title = NULL;
>> +
>> +    {
>> +        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);
>>      g_free(priv->config_file);
>>      priv->config_file = NULL;
>>      g_clear_pointer(&priv->config, g_key_file_free);
>> --
>> 1.8.1
>>
>> _______________________________________________
>> virt-tools-list mailing list
>> virt-tools-list at redhat.com
>> https://www.redhat.com/mailman/listinfo/virt-tools-list
>
>
>
> --
> Marc-André Lureau



-- 
Marc-André Lureau




More information about the virt-tools-list mailing list