[seahorse] gpgme: KeyDeleter: don't use GSimpleAsyncResult



commit ae79faee7d52ffb033acbe88e7e7f7425eeb4e1d
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Fri Feb 22 21:41:46 2019 +0100

    gpgme: KeyDeleter: don't use GSimpleAsyncResult
    
    It was deprecated quite some time ago in favor of the simpler GTask API.

 pgp/seahorse-gpgme-key-deleter.c | 153 +++++++++++++++++++--------------------
 1 file changed, 73 insertions(+), 80 deletions(-)
---
diff --git a/pgp/seahorse-gpgme-key-deleter.c b/pgp/seahorse-gpgme-key-deleter.c
index ab2e9a71..61d52c31 100644
--- a/pgp/seahorse-gpgme-key-deleter.c
+++ b/pgp/seahorse-gpgme-key-deleter.c
@@ -1,18 +1,18 @@
-/* 
+/*
  * Seahorse
- * 
+ *
  * Copyright (C) 2011 Collabora Ltd.
  *
- * This program is free software; you can redistribute it and/or modify 
+ * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this program; if not, see
  * <http://www.gnu.org/licenses/>.
@@ -37,12 +37,12 @@
 typedef struct _SeahorseGpgmeKeyDeleterClass SeahorseGpgmeKeyDeleterClass;
 
 struct _SeahorseGpgmeKeyDeleter {
-       SeahorseDeleter parent;
-       GList *keys;
+    SeahorseDeleter parent;
+    GList *keys;
 };
 
 struct _SeahorseGpgmeKeyDeleterClass {
-       SeahorseDeleterClass parent_class;
+    SeahorseDeleterClass parent_class;
 };
 
 G_DEFINE_TYPE (SeahorseGpgmeKeyDeleter, seahorse_gpgme_key_deleter, SEAHORSE_TYPE_DELETER);
@@ -50,62 +50,60 @@ G_DEFINE_TYPE (SeahorseGpgmeKeyDeleter, seahorse_gpgme_key_deleter, SEAHORSE_TYP
 static void
 seahorse_gpgme_key_deleter_init (SeahorseGpgmeKeyDeleter *self)
 {
-
 }
 
 static void
 seahorse_gpgme_key_deleter_finalize (GObject *obj)
 {
-       SeahorseGpgmeKeyDeleter *self = SEAHORSE_GPGME_KEY_DELETER (obj);
+    SeahorseGpgmeKeyDeleter *self = SEAHORSE_GPGME_KEY_DELETER (obj);
 
-       g_list_free_full (self->keys, g_object_unref);
+    g_list_free_full (self->keys, g_object_unref);
 
-       G_OBJECT_CLASS (seahorse_gpgme_key_deleter_parent_class)->finalize (obj);
+    G_OBJECT_CLASS (seahorse_gpgme_key_deleter_parent_class)->finalize (obj);
 }
 
 static GtkDialog *
 seahorse_gpgme_key_deleter_create_confirm (SeahorseDeleter *deleter,
                                            GtkWindow *parent)
 {
-       SeahorseGpgmeKeyDeleter *self = SEAHORSE_GPGME_KEY_DELETER (deleter);
-       GtkDialog *dialog;
-       gchar *prompt;
-       guint num;
-
-       num = g_list_length (self->keys);
-       if (num == 1) {
-               prompt = g_strdup_printf (_("Are you sure you want to permanently delete %s?"),
-                                         seahorse_object_get_label (SEAHORSE_OBJECT (self->keys->data)));
-       } else {
-               prompt = g_strdup_printf (ngettext ("Are you sure you want to permanently delete %d keys?",
-                                                   "Are you sure you want to permanently delete %d keys?",
-                                                   num),
-                                         num);
-       }
-
-       dialog = seahorse_delete_dialog_new (parent, "%s", prompt);
-       g_free (prompt);
-
-       return g_object_ref (dialog);
+    SeahorseGpgmeKeyDeleter *self = SEAHORSE_GPGME_KEY_DELETER (deleter);
+    GtkDialog *dialog;
+    g_autofree gchar *prompt = NULL;
+    guint num;
+
+    num = g_list_length (self->keys);
+    if (num == 1) {
+        prompt = g_strdup_printf (_("Are you sure you want to permanently delete %s?"),
+                                  seahorse_object_get_label (SEAHORSE_OBJECT (self->keys->data)));
+    } else {
+        prompt = g_strdup_printf (ngettext ("Are you sure you want to permanently delete %d keys?",
+                                            "Are you sure you want to permanently delete %d keys?",
+                                            num),
+                                  num);
+    }
+
+    dialog = seahorse_delete_dialog_new (parent, "%s", prompt);
+
+    return g_object_ref (dialog);
 }
 
 static GList *
 seahorse_gpgme_key_deleter_get_objects (SeahorseDeleter *deleter)
 {
-       SeahorseGpgmeKeyDeleter *self = SEAHORSE_GPGME_KEY_DELETER (deleter);
-       return self->keys;
+    SeahorseGpgmeKeyDeleter *self = SEAHORSE_GPGME_KEY_DELETER (deleter);
+    return self->keys;
 }
 
 static gboolean
 seahorse_gpgme_key_deleter_add_object (SeahorseDeleter *deleter,
-                                      GObject *object)
+                                       GObject *object)
 {
-       SeahorseGpgmeKeyDeleter *self = SEAHORSE_GPGME_KEY_DELETER (deleter);
+    SeahorseGpgmeKeyDeleter *self = SEAHORSE_GPGME_KEY_DELETER (deleter);
 
-       if (!SEAHORSE_GPGME_IS_KEY (object))
-               return FALSE;
-       self->keys = g_list_append (self->keys, g_object_ref (object));
-       return TRUE;
+    if (!SEAHORSE_GPGME_IS_KEY (object))
+        return FALSE;
+    self->keys = g_list_append (self->keys, g_object_ref (object));
+    return TRUE;
 }
 
 static void
@@ -114,26 +112,25 @@ seahorse_gpgme_key_deleter_delete_async (SeahorseDeleter *deleter,
                                          GAsyncReadyCallback callback,
                                          gpointer user_data)
 {
-       SeahorseGpgmeKeyDeleter *self = SEAHORSE_GPGME_KEY_DELETER (deleter);
-       GSimpleAsyncResult *res;
-       GError *error = NULL;
-       gpgme_error_t gerr;
-       GList *l;
-
-       res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
-                                        seahorse_gpgme_key_deleter_delete_async);
-
-       for (l = self->keys; l != NULL && !g_cancellable_is_cancelled (cancellable);
-            l = g_list_next (l)) {
-               gerr = seahorse_gpgme_key_op_delete (l->data);
-               if (seahorse_gpgme_propagate_error (gerr, &error)) {
-                       g_simple_async_result_take_error (res, error);
-                       break;
-               }
-       }
-
-       g_simple_async_result_complete_in_idle (res);
-       g_object_unref (res);
+    SeahorseGpgmeKeyDeleter *self = SEAHORSE_GPGME_KEY_DELETER (deleter);
+    g_autoptr(GTask) task = NULL;
+    GList *l;
+
+    task = g_task_new (self, cancellable, callback, user_data);
+
+    for (l = self->keys; l != NULL && !g_cancellable_is_cancelled (cancellable);
+         l = g_list_next (l)) {
+        gpgme_error_t gerr;
+        g_autoptr(GError) error = NULL;
+
+        gerr = seahorse_gpgme_key_op_delete (l->data);
+        if (seahorse_gpgme_propagate_error (gerr, &error)) {
+            g_task_return_error (task, g_steal_pointer (&error));
+            return;
+        }
+    }
+
+    g_task_return_boolean (task, TRUE);
 }
 
 static gboolean
@@ -141,40 +138,36 @@ seahorse_gpgme_key_deleter_delete_finish (SeahorseDeleter *deleter,
                                           GAsyncResult *result,
                                           GError **error)
 {
-       SeahorseGpgmeKeyDeleter *self = SEAHORSE_GPGME_KEY_DELETER (deleter);
-
-       g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
-                             seahorse_gpgme_key_deleter_delete_async), FALSE);
+    SeahorseGpgmeKeyDeleter *self = SEAHORSE_GPGME_KEY_DELETER (deleter);
 
-       if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
-               return FALSE;
+    g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
 
-       return TRUE;
+    return g_task_propagate_boolean (G_TASK (result), error);
 }
 
 static void
 seahorse_gpgme_key_deleter_class_init (SeahorseGpgmeKeyDeleterClass *klass)
 {
-       GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-       SeahorseDeleterClass *deleter_class = SEAHORSE_DELETER_CLASS (klass);
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    SeahorseDeleterClass *deleter_class = SEAHORSE_DELETER_CLASS (klass);
 
-       gobject_class->finalize = seahorse_gpgme_key_deleter_finalize;
+    gobject_class->finalize = seahorse_gpgme_key_deleter_finalize;
 
-       deleter_class->add_object = seahorse_gpgme_key_deleter_add_object;
-       deleter_class->create_confirm = seahorse_gpgme_key_deleter_create_confirm;
-       deleter_class->delete = seahorse_gpgme_key_deleter_delete_async;
-       deleter_class->delete_finish = seahorse_gpgme_key_deleter_delete_finish;
-       deleter_class->get_objects = seahorse_gpgme_key_deleter_get_objects;
+    deleter_class->add_object = seahorse_gpgme_key_deleter_add_object;
+    deleter_class->create_confirm = seahorse_gpgme_key_deleter_create_confirm;
+    deleter_class->delete = seahorse_gpgme_key_deleter_delete_async;
+    deleter_class->delete_finish = seahorse_gpgme_key_deleter_delete_finish;
+    deleter_class->get_objects = seahorse_gpgme_key_deleter_get_objects;
 }
 
 SeahorseDeleter *
 seahorse_gpgme_key_deleter_new (SeahorseGpgmeKey *item)
 {
-       SeahorseDeleter *deleter;
+    SeahorseDeleter *deleter;
 
-       deleter = g_object_new (SEAHORSE_TYPE_GPGME_KEY_DELETER, NULL);
-       if (!seahorse_deleter_add_object (deleter, G_OBJECT (item)))
-               g_assert_not_reached ();
+    deleter = g_object_new (SEAHORSE_TYPE_GPGME_KEY_DELETER, NULL);
+    if (!seahorse_deleter_add_object (deleter, G_OBJECT (item)))
+        g_assert_not_reached ();
 
-       return deleter;
+    return deleter;
 }


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