[seahorse/be9ddd5: 3/8] Added a dbus interface ("GenerateCredentials") to start the generation of a gpg key. Username, e-mai



commit 657d43996256db5c82a9131c2e19ac9ca44b9e66
Author: Thorsten Sick <thorsten sick email de>
Date:   Sat Oct 31 13:45:51 2009 +0100

    Added a dbus interface ("GenerateCredentials") to start the generation of a gpg key. Username, e-mail address and comment can be submitted over dbus.

 daemon/seahorse-service.c     |   68 +++++++++++++++++++++++++++++++++++++++++
 daemon/seahorse-service.h     |    3 ++
 daemon/seahorse-service.xml   |    7 ++++
 pgp/seahorse-gpgme-dialogs.h  |    3 +-
 pgp/seahorse-gpgme-generate.c |   12 ++++++-
 5 files changed, 90 insertions(+), 3 deletions(-)
---
diff --git a/daemon/seahorse-service.c b/daemon/seahorse-service.c
index 9bbd754..2cf6a7f 100644
--- a/daemon/seahorse-service.c
+++ b/daemon/seahorse-service.c
@@ -36,6 +36,9 @@
 #include "seahorse-source.h"
 #include "seahorse-util.h"
 
+#include "../pgp/seahorse-pgp.h"
+#include "../pgp/seahorse-gpgme-source.h"
+
 #include <gio/gio.h>
 
 #define KEYSET_PATH "/org/gnome/seahorse/keys/%s"
@@ -162,6 +165,71 @@ seahorse_service_get_keyset (SeahorseService *svc, gchar *ktype,
     return TRUE;
 }
 
+
+/**
+* seahorse_service_export_keys:
+* @svc: the seahorse context
+* @ktype: the keytype (example: "openpgp")
+* @values: key-value pairs
+* @error: the error
+*
+* DBus: GenerateCredentials
+*
+* Generates credentials. Will pop up the data input window (name, email, comment)
+* pre-filled with the supplied data. A password dialog will be next. After that
+* the key is created.
+*
+* Returns: True on success
+*/
+gboolean
+seahorse_service_generate_credentials (SeahorseService *svc, gchar *ktype,
+                                       GHashTable *values, GError **error)
+{
+    SeahorseSource *sksrc;
+    GValue  val={0};
+    GValue  *pval=NULL;
+    gchar   *name=NULL;
+    gchar   *email=NULL;
+    gchar   *comment=NULL;
+
+    sksrc = seahorse_context_find_source (seahorse_context_for_app (),
+                                          SEAHORSE_PGP_TYPE,
+                                          SEAHORSE_LOCATION_LOCAL);
+    g_return_val_if_fail (sksrc != NULL, FALSE);
+
+    pval = &val;
+
+    if (g_strcmp0 (ktype,"openpgp")==0) {
+        pval = (GValue *)g_hash_table_lookup (values,"name");
+        if ((pval) && (G_VALUE_TYPE (pval) == G_TYPE_STRING))
+            name=g_value_dup_string (pval);
+
+        pval = g_hash_table_lookup (values,"email");
+        if ((pval) && (G_VALUE_TYPE (pval) == G_TYPE_STRING))
+            email=g_value_dup_string (pval);
+
+        pval = g_hash_table_lookup (values,"comment");
+        if ((pval) && (G_VALUE_TYPE (pval) == G_TYPE_STRING))
+            comment=g_value_dup_string (pval);
+
+
+        seahorse_gpgme_generate_show (SEAHORSE_GPGME_SOURCE (sksrc),
+                                      NULL,
+                                      name,
+                                      email,
+                                      comment);
+        g_free (name);
+        name = NULL;
+        g_free (email);
+        email = NULL;
+        g_free (comment);
+        comment = NULL;
+    }
+
+    return TRUE;
+}
+
+
 /**
 * seahorse_service_import_keys:
 * @svc: the seahorse context
diff --git a/daemon/seahorse-service.h b/daemon/seahorse-service.h
index 6a519b8..f15a079 100644
--- a/daemon/seahorse-service.h
+++ b/daemon/seahorse-service.h
@@ -68,6 +68,9 @@ gboolean       seahorse_service_get_key_types         (SeahorseService *svc, gch
 gboolean        seahorse_service_get_keyset           (SeahorseService *svc, gchar *ktype, 
                                                        gchar **path, GError **error);
 
+gboolean       seahorse_service_generate_credentials  (SeahorseService *svc, gchar *ktype,
+                              GHashTable *values, GError **error);
+
 gboolean        seahorse_service_import_keys           (SeahorseService *svc, gchar *ktype, 
                                                         gchar *data, gchar ***keys, GError **error);
                               
diff --git a/daemon/seahorse-service.xml b/daemon/seahorse-service.xml
index dce01e0..eda9583 100644
--- a/daemon/seahorse-service.xml
+++ b/daemon/seahorse-service.xml
@@ -53,6 +53,13 @@
             <arg type="as" name="keys" direction="in"/>
         </method>
 -->
+
+        <method name="GenerateCredentials">
+            <annotation name="org.freedesktop.DBus.GLib.CSymbol"
+                value="seahorse_service_generate_credentials"/>
+            <arg type="s" name="keytype" direction="in"/>
+            <arg type="a{sv}" name="values" direction="in"/>
+        </method>
     </interface>
 
 </node>
diff --git a/pgp/seahorse-gpgme-dialogs.h b/pgp/seahorse-gpgme-dialogs.h
index 2882ea7..cbc1c06 100644
--- a/pgp/seahorse-gpgme-dialogs.h
+++ b/pgp/seahorse-gpgme-dialogs.h
@@ -46,7 +46,8 @@ void            seahorse_gpgme_generate_register    (void);
 void            seahorse_gpgme_generate_show        (SeahorseGpgmeSource *sksrc,
                                                      GtkWindow *parent,
                                                      const char * name,
-                                                     const char *email);
+                                                     const char *email,
+                                                     const gchar *comment);
 
 void            seahorse_gpgme_add_revoker_new      (SeahorseGpgmeKey *pkey,
                                                      GtkWindow *parent);
diff --git a/pgp/seahorse-gpgme-generate.c b/pgp/seahorse-gpgme-generate.c
index ef0b94f..2743a92 100644
--- a/pgp/seahorse-gpgme-generate.c
+++ b/pgp/seahorse-gpgme-generate.c
@@ -72,7 +72,7 @@ on_pgp_generate_key (GtkAction *action, gpointer unused)
 	sksrc = seahorse_context_find_source (seahorse_context_for_app (), SEAHORSE_PGP_TYPE, SEAHORSE_LOCATION_LOCAL);
 	g_return_if_fail (sksrc != NULL);
 	
-	seahorse_gpgme_generate_show (SEAHORSE_GPGME_SOURCE (sksrc), NULL, NULL, NULL);
+	seahorse_gpgme_generate_show (SEAHORSE_GPGME_SOURCE (sksrc), NULL, NULL, NULL, NULL);
 }
 
 static const GtkActionEntry ACTION_ENTRIES[] = {
@@ -359,12 +359,13 @@ on_gpgme_generate_algorithm_changed (GtkComboBox *combo, SeahorseWidget *swidget
  * @parent: the parent window
  * @name: The user name, can be NULL if not available
  * @email: The user's email address, can be NULL if not available
+ * @comment: The comment to add to the key. Can be NULL
  *
  * Shows the gpg key generation dialog, sets default entries.
  *
  */
 void
-seahorse_gpgme_generate_show (SeahorseGpgmeSource *sksrc, GtkWindow *parent, const gchar * name, const gchar *email)
+seahorse_gpgme_generate_show (SeahorseGpgmeSource *sksrc, GtkWindow *parent, const gchar * name, const gchar *email, const gchar *comment)
 {
     SeahorseWidget *swidget;
     GtkWidget *widget, *datetime;
@@ -390,6 +391,13 @@ seahorse_gpgme_generate_show (SeahorseGpgmeSource *sksrc, GtkWindow *parent, con
         g_return_if_fail (widget != NULL);
         gtk_entry_set_text(GTK_ENTRY(widget),email);
     }
+
+    if (comment)
+    {
+        widget = seahorse_widget_get_widget (swidget, "comment-entry");
+        g_return_if_fail (widget != NULL);
+        gtk_entry_set_text(GTK_ENTRY(widget),comment);
+    }
     
     widget = seahorse_widget_get_widget (swidget, "pgp-image");
     g_return_if_fail (widget != NULL);



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