[libcryptui] Add cryptui_need_to_get_keys_or_symmetric()



commit c744886a9c4c723589b8c8d6b3fb6a225c54dd21
Author: Jérémy Bobbio <lunar debian org>
Date:   Tue Jun 11 15:48:35 2013 +0000

    Add cryptui_need_to_get_keys_or_symmetric()
    
    When encryption is requested but no public keys are available, it is a viable
    option to perform symmetric instead of public key encryption. This new
    function is similar to cryptui_need_to_get_keys() but adds the possibility to
    opt for symmetric encryption.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=325803

 libcryptui/cryptui.c |   36 ++++++++++++++++++++++++++++++++++++
 libcryptui/cryptui.h |    2 ++
 2 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/libcryptui/cryptui.c b/libcryptui/cryptui.c
index dd513f5..246216a 100644
--- a/libcryptui/cryptui.c
+++ b/libcryptui/cryptui.c
@@ -276,3 +276,39 @@ cryptui_need_to_get_keys ()
         g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
     }
 }
+
+/**
+ * cryptui_need_to_get_keys_or_symmetric:
+ *
+ * This function is called when seahorse needs to be launched to generate a
+ * key or keys or import a key or keys to perform the requested operation.
+ *
+ * It returns TRUE if symmetric encrypting should be used instead of public key
+ * encryption.
+ */
+gboolean
+cryptui_need_to_get_keys_or_symmetric (void)
+{
+    GtkWidget *dialog;
+    gchar *argv[2] = {"seahorse", NULL};
+    gint response;
+
+    dialog = gtk_message_dialog_new_with_markup (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_NONE,
+                                                 _("No encryption keys were found. In order to perform 
public key encryption, the <b>Passwords and Encryption Keys</b> program can be started to create or import a 
public key. It is also possible to use a shared passphrase instead."));
+    gtk_dialog_add_buttons (GTK_DIALOG(dialog),
+                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                            _("Use a shared passphrase"), GTK_RESPONSE_REJECT,
+                            _("Create or import a key"), GTK_RESPONSE_ACCEPT,
+                            NULL);
+
+    response = gtk_dialog_run (GTK_DIALOG (dialog));
+    gtk_widget_destroy (dialog);
+    if (response == GTK_RESPONSE_ACCEPT) {
+        g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
+        return FALSE;
+    }
+    if (response == GTK_RESPONSE_REJECT) {
+        return TRUE;
+    }
+    return FALSE;
+}
diff --git a/libcryptui/cryptui.h b/libcryptui/cryptui.h
index 36c9369..df54f9a 100644
--- a/libcryptui/cryptui.h
+++ b/libcryptui/cryptui.h
@@ -162,6 +162,8 @@ gchar*              cryptui_prompt_signer (CryptUIKeyset *keyset, const gchar *t
  */
 void                cryptui_need_to_get_keys ();
 
+gboolean            cryptui_need_to_get_keys_or_symmetric (void);
+
 G_END_DECLS
 
 #endif /* __CRYPT_UI_H__ */


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