"Fossies" - the Fresh Open Source Software Archive

Member "seahorse-3.34/pgp/seahorse-gpgme-secret-deleter.c" (1 Oct 2019, 5947 Bytes) of package /linux/privat/seahorse-3.34.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "seahorse-gpgme-secret-deleter.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes reports: 3.31.91_vs_3.32 or 3.30.1.1_vs_3.32.

    1 /*
    2  * Seahorse
    3  *
    4  * Copyright (C) 2011 Collabora Ltd.
    5  *
    6  * This program is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU Lesser General Public License as
    8  * published by the Free Software Foundation; either version 2.1 of
    9  * the License, or (at your option) any later version.
   10  *
   11  * This program is distributed in the hope that it will be useful, but
   12  * WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14  * Lesser General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU Lesser General Public
   17  * License along with this program; if not, see
   18  * <http://www.gnu.org/licenses/>.
   19  *
   20  * Author: Stef Walter <stefw@collabora.co.uk>
   21  */
   22 
   23 #include "config.h"
   24 
   25 #include "seahorse-gpgme.h"
   26 #include "seahorse-gpgme-key-op.h"
   27 #include "seahorse-gpgme-secret-deleter.h"
   28 
   29 #include "seahorse-common.h"
   30 
   31 #include <glib/gi18n.h>
   32 
   33 #define SEAHORSE_GPGME_SECRET_DELETER_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), SEAHORSE_TYPE_GPGME_SECRET_DELETER, SeahorseGpgmeSecretDeleterClass))
   34 #define SEAHORSE_IS_GPGME_SECRET_DELETER_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), SEAHORSE_TYPE_GPGME_SECRET_DELETER))
   35 #define SEAHORSE_GPGME_SECRET_DELETER_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), SEAHORSE_TYPE_GPGME_SECRET_DELETER, SeahorseGpgmeSecretDeleterClass))
   36 
   37 typedef struct _SeahorseGpgmeSecretDeleterClass SeahorseGpgmeSecretDeleterClass;
   38 
   39 struct _SeahorseGpgmeSecretDeleter {
   40     SeahorseDeleter parent;
   41     SeahorseGpgmeKey *key;
   42     GList *keys;
   43 };
   44 
   45 struct _SeahorseGpgmeSecretDeleterClass {
   46     SeahorseDeleterClass parent_class;
   47 };
   48 
   49 G_DEFINE_TYPE (SeahorseGpgmeSecretDeleter, seahorse_gpgme_secret_deleter, SEAHORSE_TYPE_DELETER);
   50 
   51 static GtkDialog *
   52 seahorse_gpgme_secret_deleter_create_confirm (SeahorseDeleter *deleter,
   53                                            GtkWindow *parent)
   54 {
   55     SeahorseGpgmeSecretDeleter *self = SEAHORSE_GPGME_SECRET_DELETER (deleter);
   56     GtkDialog *dialog;
   57     g_autofree gchar *prompt = NULL;
   58 
   59     prompt = g_strdup_printf (_("Are you sure you want to permanently delete %s?"),
   60                               seahorse_object_get_label (SEAHORSE_OBJECT (self->key)));
   61 
   62     dialog = seahorse_delete_dialog_new (parent, "%s", prompt);
   63 
   64     seahorse_delete_dialog_set_check_label (SEAHORSE_DELETE_DIALOG (dialog), _("I understand that this secret key will be permanently deleted."));
   65     seahorse_delete_dialog_set_check_require (SEAHORSE_DELETE_DIALOG (dialog), TRUE);
   66 
   67     return g_object_ref (dialog);
   68 }
   69 
   70 static GList *
   71 seahorse_gpgme_secret_deleter_get_objects (SeahorseDeleter *deleter)
   72 {
   73     SeahorseGpgmeSecretDeleter *self = SEAHORSE_GPGME_SECRET_DELETER (deleter);
   74     return self->keys;
   75 }
   76 
   77 static gboolean
   78 seahorse_gpgme_secret_deleter_add_object (SeahorseDeleter *deleter,
   79                                           GObject *object)
   80 {
   81     SeahorseGpgmeSecretDeleter *self = SEAHORSE_GPGME_SECRET_DELETER (deleter);
   82 
   83     if (!SEAHORSE_GPGME_IS_KEY (object))
   84         return FALSE;
   85     if (self->key)
   86         return FALSE;
   87     if (seahorse_object_get_usage (SEAHORSE_OBJECT (object)) != SEAHORSE_USAGE_PRIVATE_KEY)
   88         return FALSE;
   89     self->key = SEAHORSE_GPGME_KEY (g_object_ref (object));
   90     self->keys = g_list_append (self->keys, object);
   91     return TRUE;
   92 }
   93 
   94 static void
   95 seahorse_gpgme_secret_deleter_delete_async (SeahorseDeleter *deleter,
   96                                             GCancellable *cancellable,
   97                                             GAsyncReadyCallback callback,
   98                                             gpointer user_data)
   99 {
  100     SeahorseGpgmeSecretDeleter *self = SEAHORSE_GPGME_SECRET_DELETER (deleter);
  101     g_autoptr(GTask) task = NULL;
  102     g_autoptr(GError) error = NULL;
  103     gpgme_error_t gerr;
  104 
  105     task = g_task_new (self, cancellable, callback, user_data);
  106 
  107     gerr = seahorse_gpgme_key_op_delete_pair (self->key);
  108     if (seahorse_gpgme_propagate_error (gerr, &error)) {
  109         g_task_return_error (task, g_steal_pointer (&error));
  110         return;
  111     }
  112 
  113     g_task_return_boolean (task, TRUE);
  114 }
  115 
  116 static gboolean
  117 seahorse_gpgme_secret_deleter_delete_finish (SeahorseDeleter *deleter,
  118                                              GAsyncResult *result,
  119                                              GError **error)
  120 {
  121     SeahorseGpgmeSecretDeleter *self = SEAHORSE_GPGME_SECRET_DELETER (deleter);
  122 
  123     g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
  124 
  125     return g_task_propagate_boolean (G_TASK (result), error);
  126 }
  127 
  128 static void
  129 seahorse_gpgme_secret_deleter_init (SeahorseGpgmeSecretDeleter *self)
  130 {
  131 }
  132 
  133 static void
  134 seahorse_gpgme_secret_deleter_finalize (GObject *obj)
  135 {
  136     SeahorseGpgmeSecretDeleter *self = SEAHORSE_GPGME_SECRET_DELETER (obj);
  137 
  138     g_clear_object (&self->key);
  139     g_list_free (self->keys);
  140 
  141     G_OBJECT_CLASS (seahorse_gpgme_secret_deleter_parent_class)->finalize (obj);
  142 }
  143 
  144 static void
  145 seahorse_gpgme_secret_deleter_class_init (SeahorseGpgmeSecretDeleterClass *klass)
  146 {
  147     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  148     SeahorseDeleterClass *deleter_class = SEAHORSE_DELETER_CLASS (klass);
  149 
  150     gobject_class->finalize = seahorse_gpgme_secret_deleter_finalize;
  151 
  152     deleter_class->add_object = seahorse_gpgme_secret_deleter_add_object;
  153     deleter_class->create_confirm = seahorse_gpgme_secret_deleter_create_confirm;
  154     deleter_class->delete = seahorse_gpgme_secret_deleter_delete_async;
  155     deleter_class->delete_finish = seahorse_gpgme_secret_deleter_delete_finish;
  156     deleter_class->get_objects = seahorse_gpgme_secret_deleter_get_objects;
  157 }
  158 
  159 SeahorseDeleter *
  160 seahorse_gpgme_secret_deleter_new (SeahorseGpgmeKey *key)
  161 {
  162     SeahorseDeleter *deleter;
  163 
  164     deleter = g_object_new (SEAHORSE_TYPE_GPGME_SECRET_DELETER, NULL);
  165     if (!seahorse_deleter_add_object (deleter, G_OBJECT (key)))
  166         g_assert_not_reached ();
  167 
  168     return deleter;
  169 }