[seahorse/expires-created-datetime] pgp: Use GDateTime for expiry/creation dates




commit 75969718010c7f2927393de077e6f852fb2fbc4a
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Feb 21 19:11:01 2021 +0100

    pgp: Use GDateTime for expiry/creation dates

 pgp/seahorse-gpgme-add-subkey.c     |   4 +-
 pgp/seahorse-gpgme-add-subkey.h     |   2 +-
 pgp/seahorse-gpgme-expires-dialog.c |  30 ++--
 pgp/seahorse-gpgme-key-op.c         | 275 +++++++++++++++++++-----------------
 pgp/seahorse-gpgme-key-op.h         |  40 +++---
 pgp/seahorse-gpgme-subkey.c         |  17 ++-
 pgp/seahorse-hkp-source.c           |   8 +-
 pgp/seahorse-ldap-source.c          |   9 +-
 pgp/seahorse-pgp-key-properties.c   |  53 ++++---
 pgp/seahorse-pgp-key.c              |  10 +-
 pgp/seahorse-pgp-key.h              |   4 +-
 pgp/seahorse-pgp-subkey.c           |  58 ++++----
 pgp/seahorse-pgp-subkey.h           |  24 ++--
 13 files changed, 289 insertions(+), 245 deletions(-)
---
diff --git a/pgp/seahorse-gpgme-add-subkey.c b/pgp/seahorse-gpgme-add-subkey.c
index 7803d778..2ddd88ed 100644
--- a/pgp/seahorse-gpgme-add-subkey.c
+++ b/pgp/seahorse-gpgme-add-subkey.c
@@ -132,7 +132,7 @@ seahorse_gpgme_add_subkey_get_active_type (SeahorseGpgmeAddSubkey *self)
     }
 }
 
-gulong
+GDateTime *
 seahorse_gpgme_add_subkey_get_expires (SeahorseGpgmeAddSubkey *self)
 {
     time_t expires;
@@ -144,7 +144,7 @@ seahorse_gpgme_add_subkey_get_expires (SeahorseGpgmeAddSubkey *self)
 
     egg_datetime_get_as_time_t (EGG_DATETIME (self->expires_datetime),
                                 &expires);
-    return expires;
+    return g_date_time_new_from_unix_utc (expires);
 }
 
 guint
diff --git a/pgp/seahorse-gpgme-add-subkey.h b/pgp/seahorse-gpgme-add-subkey.h
index d1ab6437..f757c00a 100644
--- a/pgp/seahorse-gpgme-add-subkey.h
+++ b/pgp/seahorse-gpgme-add-subkey.h
@@ -37,4 +37,4 @@ SeahorseKeyEncType       seahorse_gpgme_add_subkey_get_active_type   (SeahorseGp
 
 guint                    seahorse_gpgme_add_subkey_get_keysize       (SeahorseGpgmeAddSubkey *self);
 
-gulong                   seahorse_gpgme_add_subkey_get_expires       (SeahorseGpgmeAddSubkey *self);
+GDateTime *              seahorse_gpgme_add_subkey_get_expires       (SeahorseGpgmeAddSubkey *self);
diff --git a/pgp/seahorse-gpgme-expires-dialog.c b/pgp/seahorse-gpgme-expires-dialog.c
index 4a5b5ea4..80be2287 100644
--- a/pgp/seahorse-gpgme-expires-dialog.c
+++ b/pgp/seahorse-gpgme-expires-dialog.c
@@ -52,23 +52,21 @@ seahorse_gpgme_expires_dialog_response (GtkDialog *dialog, int response)
 {
     SeahorseGpgmeExpiresDialog *self = SEAHORSE_GPGME_EXPIRES_DIALOG (dialog);
     gpgme_error_t err;
-    time_t expiry = 0;
+    g_autoptr(GDateTime) expires = NULL;
+    GDateTime *old_expires;
 
     if (response != GTK_RESPONSE_OK)
         return;
 
     if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->never_expires_check))) {
-        struct tm when;
+        unsigned int y, m, d;
+        g_autoptr(GDateTime) now = NULL;
 
-        memset (&when, 0, sizeof (when));
-        gtk_calendar_get_date (GTK_CALENDAR (self->calendar),
-                               (guint*) &(when.tm_year),
-                               (guint*) &(when.tm_mon),
-                               (guint*) &(when.tm_mday));
-        when.tm_year -= 1900;
-        expiry = mktime (&when);
+        gtk_calendar_get_date (GTK_CALENDAR (self->calendar), &y, &m, &d);
+        expires = g_date_time_new_utc (y, m, d, 0, 0, 0);
+        now = g_date_time_new_now_utc ();
 
-        if (expiry <= time (NULL)) {
+        if (g_date_time_compare (expires, now) <= 0) {
             seahorse_util_show_error (self->calendar, _("Invalid expiry date"),
                                       _("The expiry date must be in the future"));
             return;
@@ -77,11 +75,13 @@ seahorse_gpgme_expires_dialog_response (GtkDialog *dialog, int response)
 
     gtk_widget_set_sensitive (gtk_dialog_get_content_area (GTK_DIALOG (self)), FALSE);
 
-    if (expiry != (time_t)seahorse_pgp_subkey_get_expires (SEAHORSE_PGP_SUBKEY (self->subkey))) {
-        err = seahorse_gpgme_key_op_set_expires (self->subkey, expiry);
-        if (!GPG_IS_OK (err))
-            seahorse_gpgme_handle_error (err, _("Couldn’t change expiry date"));
-    }
+    old_expires = seahorse_pgp_subkey_get_expires (SEAHORSE_PGP_SUBKEY (self->subkey));
+    if (expires == old_expires && (expires && g_date_time_equal (old_expires, expires)))
+        return;
+
+    err = seahorse_gpgme_key_op_set_expires (self->subkey, expires);
+    if (!GPG_IS_OK (err))
+        seahorse_gpgme_handle_error (err, _("Couldn’t change expiry date"));
 }
 
 static void
diff --git a/pgp/seahorse-gpgme-key-op.c b/pgp/seahorse-gpgme-key-op.c
index 276f6851..97e4a2b3 100644
--- a/pgp/seahorse-gpgme-key-op.c
+++ b/pgp/seahorse-gpgme-key-op.c
@@ -93,29 +93,29 @@ on_key_op_generate_complete (gpgme_error_t gerr,
  * @passphrase: Passphrase for key
  * @type: Key type. Supported types are #DSA_ELGAMAL, #DSA, #RSA_SIGN, and #RSA_RSA
  * @length: Length of key, must be within the range of @type specified by #SeahorseKeyLength
- * @expires: Expiration date of key
- * 
+ * @expires: Expiration date of key (or %NULL if none)
+ *
  * Tries to generate a new key based on given parameters.
- **/
+ */
 void
 seahorse_gpgme_key_op_generate_async (SeahorseGpgmeKeyring *keyring,
-                                      const gchar *name,
-                                      const gchar *email,
-                                      const gchar *comment,
-                                      const gchar *passphrase,
-                                      const SeahorseKeyEncType type,
-                                      const guint length,
-                                      const time_t expires,
-                                      GCancellable *cancellable,
-                                      GAsyncReadyCallback callback,
-                                      gpointer user_data)
-{
-    const gchar* key_type;
-    g_autofree gchar *common = NULL, *start = NULL, *expires_date = NULL;
+                                      const char           *name,
+                                      const char           *email,
+                                      const char           *comment,
+                                      const char           *passphrase,
+                                      SeahorseKeyEncType   type,
+                                      guint                length,
+                                      GDateTime           *expires,
+                                      GCancellable        *cancellable,
+                                      GAsyncReadyCallback  callback,
+                                      gpointer             user_data)
+{
+    const char* key_type;
+    g_autofree char *common = NULL, *start = NULL, *expires_date = NULL;
     gpgme_ctx_t gctx;
     g_autoptr(GTask) task = NULL;
     g_autoptr(GError) error = NULL;
-    const gchar *parms;
+    const char *parms;
     gpgme_error_t gerr = 0;
     g_autoptr(GSource) gsource = NULL;
 
@@ -140,8 +140,8 @@ seahorse_gpgme_key_op_generate_async (SeahorseGpgmeKeyring *keyring,
         break;
     }
 
-    if (expires != 0)
-        expires_date = seahorse_util_get_date_string (expires);
+    if (expires)
+        expires_date = g_date_time_format (expires, "%x");
     else
         expires_date = g_strdup ("0");
 
@@ -980,143 +980,156 @@ seahorse_gpgme_key_op_set_disabled (SeahorseGpgmeKey *pkey, gboolean disabled)
 
 typedef struct
 {
-       guint   index;
-       time_t  expires;
+    unsigned int index;
+    GDateTime *expires;
 } ExpireParm;
 
 typedef enum
 {
-       EXPIRE_START,
-       EXPIRE_SELECT,
-       EXPIRE_COMMAND,
-       EXPIRE_DATE,
-       EXPIRE_QUIT,
-       EXPIRE_SAVE,
-       EXPIRE_ERROR
+    EXPIRE_START,
+    EXPIRE_SELECT,
+    EXPIRE_COMMAND,
+    EXPIRE_DATE,
+    EXPIRE_QUIT,
+    EXPIRE_SAVE,
+    EXPIRE_ERROR
 } ExpireState;
 
 /* action helper for changing expiration date of a key */
 static gpgme_error_t
 edit_expire_action (guint state, gpointer data, int fd)
 {
-       ExpireParm *parm = (ExpireParm*)data;
-  
-       switch (state) {
-               /* selected key */
-               case EXPIRE_SELECT:
+    ExpireParm *parm = (ExpireParm*)data;
+    g_autofree char *expires_str = NULL;
+
+    switch (state) {
+        /* selected key */
+        case EXPIRE_SELECT:
             PRINTF ((fd, "key %d", parm->index));
-                       break;
-               case EXPIRE_COMMAND:
+            break;
+        case EXPIRE_COMMAND:
             PRINT ((fd, "expire"));
-                       break;
-               /* set date */
-               case EXPIRE_DATE:
-            PRINT ((fd, (parm->expires) ?
-                               seahorse_util_get_date_string (parm->expires) : "0"));
-                       break;
-               case EXPIRE_QUIT:
+            break;
+        /* set date */
+        case EXPIRE_DATE:
+            expires_str = parm->expires?
+                g_date_time_format (parm->expires, "%x") : g_strdup ("0");
+            PRINT ((fd, expires_str));
+            break;
+        case EXPIRE_QUIT:
             PRINT ((fd, QUIT));
-                       break;
-               case EXPIRE_SAVE:
+            break;
+        case EXPIRE_SAVE:
             PRINT ((fd, YES));
-                       break;
-               case EXPIRE_ERROR:
-                       break;
-               default:
-                       return GPG_E (GPG_ERR_GENERAL);
-       }
+            break;
+        case EXPIRE_ERROR:
+            break;
+        default:
+            return GPG_E (GPG_ERR_GENERAL);
+    }
 
     PRINT ((fd, "\n"));
-       return GPG_OK;
+    return GPG_OK;
 }
 
 /* transition helper for changing expiration date of a key */
 static guint
-edit_expire_transit (guint current_state, gpgme_status_code_t status,
-                    const gchar *args, gpointer data, gpgme_error_t *err)
+edit_expire_transit (unsigned int         current_state,
+                     gpgme_status_code_t  status,
+                     const char          *args,
+                     gpointer             data,
+                     gpgme_error_t       *err)
 {
-       guint next_state;
- 
-       switch (current_state) {
-               /* start state, selected key */
-               case EXPIRE_START:
-                       if (status == GPGME_STATUS_GET_LINE && g_str_equal (args, PROMPT))
-                               next_state = EXPIRE_SELECT;
-                       else {
+    unsigned int next_state;
+
+    switch (current_state) {
+        /* start state, selected key */
+        case EXPIRE_START:
+            if (status == GPGME_STATUS_GET_LINE && g_str_equal (args, PROMPT))
+                next_state = EXPIRE_SELECT;
+            else {
                 *err = GPG_E (GPG_ERR_GENERAL);
                 g_return_val_if_reached (EXPIRE_ERROR);
-                       }
-                       break;
-               /* selected key, do command */
-               case EXPIRE_SELECT:
-                       if (status == GPGME_STATUS_GET_LINE && g_str_equal (args, PROMPT))
-                               next_state = EXPIRE_COMMAND;
-                       else {
+            }
+            break;
+        /* selected key, do command */
+        case EXPIRE_SELECT:
+            if (status == GPGME_STATUS_GET_LINE && g_str_equal (args, PROMPT))
+                next_state = EXPIRE_COMMAND;
+            else {
                 *err = GPG_E (GPG_ERR_GENERAL);
                 g_return_val_if_reached (EXPIRE_ERROR);
-                       }
-                       break;
-               /* did command, set expires */
-               case EXPIRE_COMMAND:
-                       if (status == GPGME_STATUS_GET_LINE && g_str_equal (args, "keygen.valid"))
-                               next_state = EXPIRE_DATE;
-                       else {
+            }
+            break;
+        /* did command, set expires */
+        case EXPIRE_COMMAND:
+            if (status == GPGME_STATUS_GET_LINE && g_str_equal (args, "keygen.valid"))
+                next_state = EXPIRE_DATE;
+            else {
                 *err = GPG_E (GPG_ERR_GENERAL);
                 g_return_val_if_reached (EXPIRE_ERROR);
-                       }
-                       break;
-               /* set expires, quit */
-               case EXPIRE_DATE:
-                       if (status == GPGME_STATUS_GET_LINE && g_str_equal (args, PROMPT))
-                               next_state = EXPIRE_QUIT;
-                       else {
+            }
+            break;
+        /* set expires, quit */
+        case EXPIRE_DATE:
+            if (status == GPGME_STATUS_GET_LINE && g_str_equal (args, PROMPT))
+                next_state = EXPIRE_QUIT;
+            else {
                 *err = GPG_E (GPG_ERR_GENERAL);
                 g_return_val_if_reached (EXPIRE_ERROR);
-                       }
-                       break;
-               /* quit, save */
-               case EXPIRE_QUIT:
-                       if (status == GPGME_STATUS_GET_BOOL && g_str_equal (args, SAVE))
-                               next_state = EXPIRE_SAVE;
-                       else {
+            }
+            break;
+        /* quit, save */
+        case EXPIRE_QUIT:
+            if (status == GPGME_STATUS_GET_BOOL && g_str_equal (args, SAVE))
+                next_state = EXPIRE_SAVE;
+            else {
                 *err = GPG_E (GPG_ERR_GENERAL);
                 g_return_val_if_reached (EXPIRE_ERROR);
-                       }
-                       break;
-               /* error, quit */
-               case EXPIRE_ERROR:
-                       if (status == GPGME_STATUS_GET_LINE && g_str_equal (args, PROMPT))
-                               next_state = EXPIRE_QUIT;
-                       else
-                               next_state = EXPIRE_ERROR;
-                       break;
-               default:
+            }
+            break;
+        /* error, quit */
+        case EXPIRE_ERROR:
+            if (status == GPGME_STATUS_GET_LINE && g_str_equal (args, PROMPT))
+                next_state = EXPIRE_QUIT;
+            else
+                next_state = EXPIRE_ERROR;
+            break;
+        default:
             *err = GPG_E (GPG_ERR_GENERAL);
             g_return_val_if_reached (EXPIRE_ERROR);
-                       break;
-       }
-       return next_state;
+            break;
+    }
+    return next_state;
 }
 
 gpgme_error_t
-seahorse_gpgme_key_op_set_expires (SeahorseGpgmeSubkey *subkey, const time_t expires)
+seahorse_gpgme_key_op_set_expires (SeahorseGpgmeSubkey *subkey,
+                                   GDateTime           *expires)
 {
-       ExpireParm exp_parm;
-       SeahorseEditParm *parms;
-       gpgme_key_t key;
-       
-       g_return_val_if_fail (SEAHORSE_GPGME_IS_SUBKEY (subkey), GPG_E (GPG_ERR_WRONG_KEY_USAGE));
-       g_return_val_if_fail (expires != (time_t)seahorse_pgp_subkey_get_expires (SEAHORSE_PGP_SUBKEY 
(subkey)), GPG_E (GPG_ERR_INV_VALUE));
-       
-       key = seahorse_gpgme_subkey_get_pubkey (subkey);
-       g_return_val_if_fail (key, GPG_E (GPG_ERR_INV_VALUE));
-       
-       exp_parm.index = seahorse_pgp_subkey_get_index (SEAHORSE_PGP_SUBKEY (subkey)); 
-       exp_parm.expires = expires;
-       
-       parms = seahorse_edit_parm_new (EXPIRE_START, edit_expire_action, edit_expire_transit, &exp_parm);
-       
-       return edit_refresh_gpgme_key (NULL, key, parms);
+    GDateTime *old_expires;
+    ExpireParm exp_parm;
+    SeahorseEditParm *parms;
+    gpgme_key_t key;
+
+    g_return_val_if_fail (SEAHORSE_GPGME_IS_SUBKEY (subkey), GPG_E (GPG_ERR_WRONG_KEY_USAGE));
+
+    old_expires = seahorse_pgp_subkey_get_expires (SEAHORSE_PGP_SUBKEY (subkey));
+    g_return_val_if_fail (expires != old_expires, GPG_E (GPG_ERR_INV_VALUE));
+
+    if (expires && old_expires)
+        g_return_val_if_fail (!g_date_time_equal (old_expires, expires),
+                              GPG_E (GPG_ERR_INV_VALUE));
+
+    key = seahorse_gpgme_subkey_get_pubkey (subkey);
+    g_return_val_if_fail (key, GPG_E (GPG_ERR_INV_VALUE));
+
+    exp_parm.index = seahorse_pgp_subkey_get_index (SEAHORSE_PGP_SUBKEY (subkey)); 
+    exp_parm.expires = expires;
+
+    parms = seahorse_edit_parm_new (EXPIRE_START, edit_expire_action, edit_expire_transit, &exp_parm);
+
+    return edit_refresh_gpgme_key (NULL, key, parms);
 }
 
 typedef enum {
@@ -1317,13 +1330,13 @@ seahorse_gpgme_key_op_add_uid_finish (SeahorseGpgmeKey *pkey,
 }
 
 void
-seahorse_gpgme_key_op_add_subkey_async (SeahorseGpgmeKey *pkey,
-                                        SeahorseKeyEncType type,
-                                        guint length,
-                                        gulong expires,
-                                        GCancellable *cancellable,
-                                        GAsyncReadyCallback callback,
-                                        gpointer user_data)
+seahorse_gpgme_key_op_add_subkey_async (SeahorseGpgmeKey    *pkey,
+                                        SeahorseKeyEncType   type,
+                                        unsigned int         length,
+                                        GDateTime           *expires,
+                                        GCancellable        *cancellable,
+                                        GAsyncReadyCallback  callback,
+                                        gpointer             user_data)
 {
     g_autoptr(GTask) task = NULL;
     gpgme_ctx_t gctx;
@@ -1374,8 +1387,14 @@ seahorse_gpgme_key_op_add_subkey_async (SeahorseGpgmeKey *pkey,
             break;
     }
 
-    if (gerr == 0)
-        gerr = gpgme_op_createsubkey_start (gctx, key, algo_full, 0, expires, flags);
+    if (gerr == 0) {
+        gerr = gpgme_op_createsubkey_start (gctx,
+                                            key,
+                                            algo_full,
+                                            0,
+                                            g_date_time_to_unix (expires),
+                                            flags);
+    }
 
     if (seahorse_gpgme_propagate_error (gerr, &error)) {
         g_task_return_error (task, g_steal_pointer (&error));
diff --git a/pgp/seahorse-gpgme-key-op.h b/pgp/seahorse-gpgme-key-op.h
index 3cecd996..4ec37450 100644
--- a/pgp/seahorse-gpgme-key-op.h
+++ b/pgp/seahorse-gpgme-key-op.h
@@ -61,16 +61,16 @@ typedef enum {
 } SeahorseRevokeReason;
 
 void                  seahorse_gpgme_key_op_generate_async   (SeahorseGpgmeKeyring *keyring,
-                                                              const gchar *name,
-                                                              const gchar *email,
-                                                              const gchar *comment,
-                                                              const gchar *passphrase,
-                                                              SeahorseKeyEncType type,
-                                                              guint length,
-                                                              time_t expires,
-                                                              GCancellable *cancellable,
-                                                              GAsyncReadyCallback callback,
-                                                              gpointer user_data);
+                                                              const char           *name,
+                                                              const char           *email,
+                                                              const char           *comment,
+                                                              const char           *passphrase,
+                                                              SeahorseKeyEncType    type,
+                                                              unsigned int          length,
+                                                              GDateTime            *expires,
+                                                              GCancellable         *cancellable,
+                                                              GAsyncReadyCallback   callback,
+                                                              gpointer              user_data);
 
 gboolean              seahorse_gpgme_key_op_generate_finish  (SeahorseGpgmeKeyring *keyring,
                                                               GAsyncResult *Result,
@@ -106,7 +106,7 @@ gpgme_error_t         seahorse_gpgme_key_op_set_disabled     (SeahorseGpgmeKey *
                                                               gboolean disabled);
 
 gpgme_error_t         seahorse_gpgme_key_op_set_expires      (SeahorseGpgmeSubkey *subkey,
-                                                              time_t expires);
+                                                              GDateTime           *expires);
 
 gpgme_error_t         seahorse_gpgme_key_op_add_revoker      (SeahorseGpgmeKey *pkey, 
                                                               SeahorseGpgmeKey *revoker);
@@ -134,13 +134,13 @@ gboolean          seahorse_gpgme_key_op_make_primary_finish (SeahorseGpgmeUid *u
 
 gpgme_error_t         seahorse_gpgme_key_op_del_uid          (SeahorseGpgmeUid *uid);
 
-void              seahorse_gpgme_key_op_add_subkey_async    (SeahorseGpgmeKey *pkey,
-                                                             SeahorseKeyEncType type,
-                                                             guint length,
-                                                             gulong expires,
-                                                             GCancellable *cancellable,
-                                                             GAsyncReadyCallback callback,
-                                                             gpointer user_data);
+void              seahorse_gpgme_key_op_add_subkey_async    (SeahorseGpgmeKey     *pkey,
+                                                             SeahorseKeyEncType    type,
+                                                             unsigned int          length,
+                                                             GDateTime            *expires,
+                                                             GCancellable         *cancellable,
+                                                             GAsyncReadyCallback   callback,
+                                                             gpointer              user_data);
 
 gboolean          seahorse_gpgme_key_op_add_subkey_finish   (SeahorseGpgmeKey *pkey,
                                                              GAsyncResult *result,
@@ -154,9 +154,9 @@ gpgme_error_t         seahorse_gpgme_key_op_revoke_subkey    (SeahorseGpgmeSubke
 
 gpgme_error_t         seahorse_gpgme_key_op_photo_add        (SeahorseGpgmeKey *pkey,
                                                               const gchar *filename);
- 
+
 gpgme_error_t         seahorse_gpgme_key_op_photo_delete     (SeahorseGpgmePhoto *photo);
-                                                     
+
 gpgme_error_t         seahorse_gpgme_key_op_photos_load      (SeahorseGpgmeKey *key);
 
 gpgme_error_t         seahorse_gpgme_key_op_photo_primary    (SeahorseGpgmePhoto *photo);
diff --git a/pgp/seahorse-gpgme-subkey.c b/pgp/seahorse-gpgme-subkey.c
index 6901ce66..bc7cb29f 100644
--- a/pgp/seahorse-gpgme-subkey.c
+++ b/pgp/seahorse-gpgme-subkey.c
@@ -62,12 +62,14 @@ seahorse_gpgme_subkey_get_subkey (SeahorseGpgmeSubkey *self)
 void
 seahorse_gpgme_subkey_set_subkey (SeahorseGpgmeSubkey *self, gpgme_subkey_t subkey)
 {
-    g_autofree gchar *description = NULL, *fingerprint = NULL, *name = NULL;
+    g_autofree char *description = NULL, *fingerprint = NULL, *name = NULL;
     SeahorsePgpSubkey *base;
-    const gchar *algo_type;
+    const char *algo_type;
     GObject *obj;
     gpgme_subkey_t sub;
-    gint i, index;
+    int index;
+    g_autoptr(GDateTime) created = NULL;
+    g_autoptr(GDateTime) expires = NULL;
     guint flags;
 
     g_return_if_fail (SEAHORSE_GPGME_IS_SUBKEY (self));
@@ -75,7 +77,7 @@ seahorse_gpgme_subkey_set_subkey (SeahorseGpgmeSubkey *self, gpgme_subkey_t subk
 
     /* Make sure that this subkey is in the pubkey */
     index = -1;
-    for (i = 0, sub = self->pubkey->subkeys; sub; ++i, sub = sub->next) {
+    for (int i = 0, sub = self->pubkey->subkeys; sub; ++i, sub = sub->next) {
         if (sub == subkey) {
             index = i;
             break;
@@ -107,8 +109,11 @@ seahorse_gpgme_subkey_set_subkey (SeahorseGpgmeSubkey *self, gpgme_subkey_t subk
     seahorse_pgp_subkey_set_length (base, subkey->length);
     seahorse_pgp_subkey_set_description (base, description);
     seahorse_pgp_subkey_set_fingerprint (base, fingerprint);
-    seahorse_pgp_subkey_set_created (base, subkey->timestamp);
-    seahorse_pgp_subkey_set_expires (base, subkey->expires);
+
+    created = g_date_time_new_from_unix_utc (subkey->timestamp);
+    seahorse_pgp_subkey_set_created (base, created);
+    expires = g_date_time_new_from_unix_utc (subkey->expires);
+    seahorse_pgp_subkey_set_expires (base, expires);
 
     /* The order below is significant */
     flags = 0;
diff --git a/pgp/seahorse-hkp-source.c b/pgp/seahorse-hkp-source.c
index 85d4e98e..72a30989 100644
--- a/pgp/seahorse-hkp-source.c
+++ b/pgp/seahorse-hkp-source.c
@@ -270,6 +270,8 @@ parse_hkp_index (const char *response)
             const char *algo;
             g_autoptr (SeahorsePgpSubkey) subkey = NULL;
             long created = 0, expired = 0;
+            g_autoptr(GDateTime) created_date = NULL;
+            g_autoptr(GDateTime) expired_date = NULL;
 
             key_count++;
 
@@ -312,11 +314,13 @@ parse_hkp_index (const char *response)
                 g_debug ("HKP Parse: No created date for key on line: %s", line);
             } else {
                 created = strtol (columns[4], NULL, 10);
+                created_date = g_date_time_new_from_unix_utc (created);
             }
 
             /* expires (optional) */
             if (columns[5]) {
                 expired = strtol (columns[5], NULL, 10);
+                expired_date = g_date_time_new_from_unix_utc (expired);
             }
 
             /* set flags (optional) */
@@ -338,8 +342,8 @@ parse_hkp_index (const char *response)
             seahorse_pgp_subkey_set_fingerprint (subkey, fingerprint);
 
             seahorse_pgp_subkey_set_flags (subkey, flags);
-            seahorse_pgp_subkey_set_created (subkey, created);
-            seahorse_pgp_subkey_set_expires (subkey, expired);
+            seahorse_pgp_subkey_set_created (subkey, created_date);
+            seahorse_pgp_subkey_set_expires (subkey, expired_date);
             seahorse_pgp_subkey_set_length (subkey, strtol (columns[3], NULL, 10));
             seahorse_pgp_subkey_set_algorithm (subkey, algo);
             seahorse_pgp_key_add_subkey (key, subkey);
diff --git a/pgp/seahorse-ldap-source.c b/pgp/seahorse-ldap-source.c
index 5ceaad63..af191da5 100644
--- a/pgp/seahorse-ldap-source.c
+++ b/pgp/seahorse-ldap-source.c
@@ -747,6 +747,8 @@ search_parse_key_from_ldap_entry (SeahorseLDAPSource *self,
         g_autoptr(SeahorsePgpKey) key = NULL;
         g_autofree char *fingerprint = NULL;
         g_autoptr(SeahorsePgpUid) uid = NULL;
+        g_autoptr(GDateTime) created_date = NULL;
+        g_autoptr(GDateTime) expires_date = NULL;
         guint flags;
 
         /* Build up a subkey */
@@ -754,11 +756,14 @@ search_parse_key_from_ldap_entry (SeahorseLDAPSource *self,
         seahorse_pgp_subkey_set_keyid (subkey, fpr);
         fingerprint = seahorse_pgp_subkey_calc_fingerprint (fpr);
         seahorse_pgp_subkey_set_fingerprint (subkey, fingerprint);
-        seahorse_pgp_subkey_set_created (subkey, timestamp);
-        seahorse_pgp_subkey_set_expires (subkey, expires);
         seahorse_pgp_subkey_set_algorithm (subkey, algo);
         seahorse_pgp_subkey_set_length (subkey, length);
 
+        created_date = g_date_time_new_from_unix_utc (timestamp);
+        expires_date = g_date_time_new_from_unix_utc (timestamp);
+        seahorse_pgp_subkey_set_created (subkey, created_date);
+        seahorse_pgp_subkey_set_expires (subkey, expires_date);
+
         flags = SEAHORSE_FLAG_EXPORTABLE;
         if (revoked)
             flags |= SEAHORSE_FLAG_REVOKED;
diff --git a/pgp/seahorse-pgp-key-properties.c b/pgp/seahorse-pgp-key-properties.c
index 1bc570fc..7adbc2f0 100644
--- a/pgp/seahorse-pgp-key-properties.c
+++ b/pgp/seahorse-pgp-key-properties.c
@@ -802,16 +802,16 @@ do_owner (SeahorsePgpKeyProperties *self)
 
     /* Update the expired message */
     if (flags & SEAHORSE_FLAG_EXPIRED) {
-        gulong expires_date;
-        g_autofree gchar *message = NULL;
-        g_autofree gchar *date_str = NULL;
+        GDateTime *expires_date;
+        g_autofree char *date_str = NULL;
+        g_autofree char *message = NULL;
 
         expires_date = seahorse_pgp_key_get_expires (self->key);
-        if (expires_date == 0) {
+        if (!expires_date) {
             /* TRANSLATORS: (unknown) expiry date */
             date_str = g_strdup (_("(unknown)"));
         } else {
-            date_str = seahorse_util_get_display_date_string (expires_date);
+            date_str = g_date_time_format (expires_date, "%x");
         }
 
         message = g_strdup_printf (_("This key expired on: %s"), date_str);
@@ -988,7 +988,7 @@ on_subkeys_add (GSimpleAction *action, GVariant *param, gpointer user_data)
     int response;
     SeahorseKeyEncType type;
     guint length;
-    gulong expires;
+    g_autoptr(GDateTime) expires = NULL;
 
     g_return_if_fail (SEAHORSE_GPGME_IS_KEY (self->key));
 
@@ -1235,8 +1235,7 @@ do_details (SeahorsePgpKeyProperties *self)
     GtkTreeIter iter;
     char dbuffer[G_ASCII_DTOSTR_BUF_SIZE];
     g_autofree char *fp_label = NULL;
-    g_autofree char *created_str = NULL;
-    g_autofree char *expires_str = NULL;
+    GDateTime *created;
     const char *label;
     int trust;
     GListModel *subkeys;
@@ -1256,20 +1255,30 @@ do_details (SeahorsePgpKeyProperties *self)
     label = seahorse_pgp_key_get_algo (self->key);
     gtk_label_set_text (self->details_algo_label, label);
 
-    created_str = seahorse_util_get_display_date_string (seahorse_pgp_key_get_created (self->key));
-    gtk_label_set_text (self->details_created_label, created_str);
+    created = seahorse_pgp_key_get_created (self->key);
+    if (created) {
+        g_autofree char *created_str = NULL;
+
+        created_str = g_date_time_format (created, "%x");
+        gtk_label_set_text (self->details_created_label, created_str);
+    }
 
     g_ascii_dtostr (dbuffer, G_ASCII_DTOSTR_BUF_SIZE, seahorse_pgp_key_get_length (self->key));
     gtk_label_set_text (self->details_strength_label, dbuffer);
 
-    gulong expires = seahorse_pgp_key_get_length (self->key);
-    if (!SEAHORSE_GPGME_IS_KEY (self->key))
-        expires_str = NULL;
-    else if (expires == 0)
-        expires_str = g_strdup (C_("Expires", "Never"));
-    else
-        expires_str = seahorse_util_get_display_date_string (expires);
-    gtk_label_set_text (self->details_expires_label, expires_str);
+    if (SEAHORSE_GPGME_IS_KEY (self->key)) {
+        GDateTime *expires;
+        g_autofree char *expires_str = NULL;
+
+        expires = seahorse_pgp_key_get_expires (self->key);
+        if (expires)
+            expires_str = g_date_time_format (expires, "%x");
+        else
+            expires_str = g_strdup (C_("Expires", "Never"));
+        gtk_label_set_text (self->details_expires_label, expires_str);
+    } else {
+        gtk_label_set_text (self->details_expires_label, NULL);
+    }
 
     if (seahorse_object_get_usage (SEAHORSE_OBJECT (self->key)) == SEAHORSE_USAGE_PUBLIC_KEY) {
         gtk_widget_set_visible (GTK_WIDGET (self->indicate_trust_box),
@@ -1335,7 +1344,7 @@ do_details (SeahorsePgpKeyProperties *self)
         g_autofree char *expiration_date = NULL;
         g_autofree char *created_date = NULL;
         g_autofree char *usage = NULL;
-        gulong expires;
+        GDateTime *expires;
         guint flags;
 
         subkey = g_list_model_get_item (subkeys, i);
@@ -1352,12 +1361,12 @@ do_details (SeahorsePgpKeyProperties *self)
         else if (flags & SEAHORSE_FLAG_IS_VALID)
             status = _("Good");
 
-        if (expires == 0)
+        if (!expires)
             expiration_date = g_strdup (C_("Expires", "Never"));
         else
-            expiration_date = seahorse_util_get_display_date_string (expires);
+            expiration_date = g_date_time_format (expires, "%x");
 
-        created_date = seahorse_util_get_display_date_string (seahorse_pgp_subkey_get_created (subkey));
+        created_date = g_date_time_format (seahorse_pgp_subkey_get_created (subkey), "%x");
 
         usage = seahorse_pgp_subkey_get_usage (subkey);
 
diff --git a/pgp/seahorse-pgp-key.c b/pgp/seahorse-pgp-key.c
index 463d16c4..66cf53f3 100644
--- a/pgp/seahorse-pgp-key.c
+++ b/pgp/seahorse-pgp-key.c
@@ -471,7 +471,7 @@ seahorse_pgp_key_get_validity (SeahorsePgpKey *self)
     return validity;
 }
 
-gulong
+GDateTime *
 seahorse_pgp_key_get_expires (SeahorsePgpKey *self)
 {
     SeahorsePgpKeyPrivate *priv = seahorse_pgp_key_get_instance_private (self);
@@ -483,7 +483,7 @@ seahorse_pgp_key_get_expires (SeahorsePgpKey *self)
     return subkey? seahorse_pgp_subkey_get_expires (subkey) : 0;
 }
 
-gulong
+GDateTime *
 seahorse_pgp_key_get_created (SeahorsePgpKey *self)
 {
     SeahorsePgpKeyPrivate *priv = seahorse_pgp_key_get_instance_private (self);
@@ -607,7 +607,7 @@ seahorse_pgp_key_get_property (GObject *object, guint prop_id,
             g_value_set_string (value, _("PGP key"));
         break;
     case PROP_EXPIRES:
-        g_value_set_ulong (value, seahorse_pgp_key_get_expires (self));
+        g_value_set_boxed (value, seahorse_pgp_key_get_expires (self));
         break;
     case PROP_LENGTH:
         g_value_set_uint (value, seahorse_pgp_key_get_length (self));
@@ -693,8 +693,8 @@ seahorse_pgp_key_class_init (SeahorsePgpKeyClass *klass)
                            G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 
     obj_props[PROP_EXPIRES] =
-        g_param_spec_ulong ("expires", "Expires On", "Date this key expires on",
-                            0, G_MAXULONG, 0,
+        g_param_spec_boxed ("expires", "Expires On", "Date this key expires on",
+                            G_TYPE_DATE_TIME,
                             G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 
     obj_props[PROP_LENGTH] =
diff --git a/pgp/seahorse-pgp-key.h b/pgp/seahorse-pgp-key.h
index 7b106972..d73e152b 100644
--- a/pgp/seahorse-pgp-key.h
+++ b/pgp/seahorse-pgp-key.h
@@ -68,9 +68,9 @@ const char*       seahorse_pgp_key_get_fingerprint      (SeahorsePgpKey *self);
 
 SeahorseValidity  seahorse_pgp_key_get_validity         (SeahorsePgpKey *self);
 
-gulong            seahorse_pgp_key_get_expires          (SeahorsePgpKey *self);
+GDateTime *       seahorse_pgp_key_get_expires          (SeahorsePgpKey *self);
 
-gulong            seahorse_pgp_key_get_created          (SeahorsePgpKey *self);
+GDateTime *       seahorse_pgp_key_get_created          (SeahorsePgpKey *self);
 
 SeahorseValidity  seahorse_pgp_key_get_trust            (SeahorsePgpKey *self);
 
diff --git a/pgp/seahorse-pgp-subkey.c b/pgp/seahorse-pgp-subkey.c
index 4a3fa705..6ed51474 100644
--- a/pgp/seahorse-pgp-subkey.c
+++ b/pgp/seahorse-pgp-subkey.c
@@ -44,14 +44,14 @@ static GParamSpec *obj_props[N_PROPS] = { NULL, };
 
 typedef struct _SeahorsePgpSubkeyPrivate {
     guint index;
-    gchar *keyid;
+    char *keyid;
     guint flags;
     guint length;
-    gchar *algorithm;
-    gulong created;
-    gulong expires;
-    gchar *description;
-    gchar *fingerprint;
+    char *algorithm;
+    GDateTime *created;
+    GDateTime *expires;
+    char *description;
+    char *fingerprint;
 } SeahorsePgpSubkeyPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (SeahorsePgpSubkey, seahorse_pgp_subkey, G_TYPE_OBJECT);
@@ -212,49 +212,49 @@ seahorse_pgp_subkey_set_algorithm (SeahorsePgpSubkey *self, const gchar *algorit
     g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ALGORITHM]);
 }
 
-gulong
+GDateTime *
 seahorse_pgp_subkey_get_created (SeahorsePgpSubkey *self)
 {
-    SeahorsePgpSubkeyPrivate *priv;
+    SeahorsePgpSubkeyPrivate *priv = seahorse_pgp_subkey_get_instance_private (self);
 
     g_return_val_if_fail (SEAHORSE_PGP_IS_SUBKEY (self), 0);
 
-    priv = seahorse_pgp_subkey_get_instance_private (self);
     return priv->created;
 }
 
 void
-seahorse_pgp_subkey_set_created (SeahorsePgpSubkey *self, gulong created)
+seahorse_pgp_subkey_set_created (SeahorsePgpSubkey *self,
+                                 GDateTime         *created)
 {
-    SeahorsePgpSubkeyPrivate *priv;
+    SeahorsePgpSubkeyPrivate *priv = seahorse_pgp_subkey_get_instance_private (self);
 
     g_return_if_fail (SEAHORSE_PGP_IS_SUBKEY (self));
 
-    priv = seahorse_pgp_subkey_get_instance_private (self);
-    priv->created = created;
+    g_clear_pointer (&priv->created, g_date_time_unref);
+    priv->created = created? g_date_time_ref (created) : NULL;
     g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_CREATED]);
 }
 
-gulong
+GDateTime *
 seahorse_pgp_subkey_get_expires (SeahorsePgpSubkey *self)
 {
-    SeahorsePgpSubkeyPrivate *priv;
+    SeahorsePgpSubkeyPrivate *priv = seahorse_pgp_subkey_get_instance_private (self);
 
     g_return_val_if_fail (SEAHORSE_PGP_IS_SUBKEY (self), 0);
 
-    priv = seahorse_pgp_subkey_get_instance_private (self);
     return priv->expires;
 }
 
 void
-seahorse_pgp_subkey_set_expires (SeahorsePgpSubkey *self, gulong expires)
+seahorse_pgp_subkey_set_expires (SeahorsePgpSubkey *self,
+                                 GDateTime         *expires)
 {
-    SeahorsePgpSubkeyPrivate *priv;
+    SeahorsePgpSubkeyPrivate *priv = seahorse_pgp_subkey_get_instance_private (self);
 
     g_return_if_fail (SEAHORSE_PGP_IS_SUBKEY (self));
 
-    priv = seahorse_pgp_subkey_get_instance_private (self);
-    priv->expires = expires;
+    g_clear_pointer (&priv->expires, g_date_time_unref);
+    priv->expires = expires? g_date_time_ref (expires) : NULL;
     g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_EXPIRES]);
 }
 
@@ -378,10 +378,10 @@ seahorse_pgp_subkey_get_property (GObject *object, guint prop_id,
         g_value_set_string (value, seahorse_pgp_subkey_get_algorithm (self));
         break;
     case PROP_CREATED:
-        g_value_set_ulong (value, seahorse_pgp_subkey_get_created (self));
+        g_value_set_boxed (value, seahorse_pgp_subkey_get_created (self));
         break;
     case PROP_EXPIRES:
-        g_value_set_ulong (value, seahorse_pgp_subkey_get_expires (self));
+        g_value_set_boxed (value, seahorse_pgp_subkey_get_expires (self));
         break;
     case PROP_DESCRIPTION:
         g_value_set_string (value, seahorse_pgp_subkey_get_description (self));
@@ -415,10 +415,10 @@ seahorse_pgp_subkey_set_property (GObject *object, guint prop_id, const GValue *
         seahorse_pgp_subkey_set_algorithm (self, g_value_get_string (value));
         break;
     case PROP_CREATED:
-        seahorse_pgp_subkey_set_created (self, g_value_get_ulong (value));
+        seahorse_pgp_subkey_set_created (self, g_value_get_boxed (value));
         break;
     case PROP_EXPIRES:
-        seahorse_pgp_subkey_set_expires (self, g_value_get_ulong (value));
+        seahorse_pgp_subkey_set_expires (self, g_value_get_boxed (value));
         break;
     case PROP_FINGERPRINT:
         seahorse_pgp_subkey_set_fingerprint (self, g_value_get_string (value));
@@ -436,6 +436,8 @@ seahorse_pgp_subkey_finalize (GObject *gobject)
     SeahorsePgpSubkeyPrivate *priv
         = seahorse_pgp_subkey_get_instance_private (self);
 
+    g_clear_pointer (&priv->created, g_date_time_unref);
+    g_clear_pointer (&priv->expires, g_date_time_unref);
     g_clear_pointer (&priv->algorithm, g_free);
     g_clear_pointer (&priv->fingerprint, g_free);
     g_clear_pointer (&priv->description, g_free);
@@ -484,13 +486,13 @@ seahorse_pgp_subkey_class_init (SeahorsePgpSubkeyClass *klass)
                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
     obj_props[PROP_CREATED] =
-        g_param_spec_ulong ("created", "Created On", "Date this key was created on",
-                            0, G_MAXULONG, 0,
+        g_param_spec_boxed ("created", "Created On", "Date this key was created on",
+                            G_TYPE_DATE_TIME,
                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
     obj_props[PROP_EXPIRES] =
-        g_param_spec_ulong ("expires", "Expires On", "Date this key expires on",
-                            0, G_MAXULONG, 0,
+        g_param_spec_boxed ("expires", "Expires On", "Date this key expires on",
+                            G_TYPE_DATE_TIME,
                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
     obj_props[PROP_DESCRIPTION] =
diff --git a/pgp/seahorse-pgp-subkey.h b/pgp/seahorse-pgp-subkey.h
index 09270f06..54d78de8 100644
--- a/pgp/seahorse-pgp-subkey.h
+++ b/pgp/seahorse-pgp-subkey.h
@@ -59,29 +59,29 @@ guint               seahorse_pgp_subkey_get_length        (SeahorsePgpSubkey *se
 void                seahorse_pgp_subkey_set_length        (SeahorsePgpSubkey *self,
                                                            guint index);
 
-gchar *             seahorse_pgp_subkey_get_usage         (SeahorsePgpSubkey *self);
+char *              seahorse_pgp_subkey_get_usage         (SeahorsePgpSubkey *self);
 
-gulong              seahorse_pgp_subkey_get_created       (SeahorsePgpSubkey *self);
+GDateTime *         seahorse_pgp_subkey_get_created       (SeahorsePgpSubkey *self);
 
 void                seahorse_pgp_subkey_set_created       (SeahorsePgpSubkey *self,
-                                                           gulong created);
+                                                           GDateTime         *created);
 
-gulong              seahorse_pgp_subkey_get_expires       (SeahorsePgpSubkey *self);
+GDateTime *         seahorse_pgp_subkey_get_expires       (SeahorsePgpSubkey *self);
 
 void                seahorse_pgp_subkey_set_expires       (SeahorsePgpSubkey *self,
-                                                           gulong expires);
+                                                           GDateTime         *expires);
 
-const gchar*        seahorse_pgp_subkey_get_description   (SeahorsePgpSubkey *self);
+const char *        seahorse_pgp_subkey_get_description   (SeahorsePgpSubkey *self);
 
 void                seahorse_pgp_subkey_set_description   (SeahorsePgpSubkey *self,
-                                                           const gchar *description);
+                                                           const char        *description);
 
-gchar*              seahorse_pgp_subkey_calc_description  (const gchar *name,
-                                                           guint index);
+char *              seahorse_pgp_subkey_calc_description  (const char *name,
+                                                           guint       index);
 
-const gchar*        seahorse_pgp_subkey_get_fingerprint   (SeahorsePgpSubkey *self);
+const char *        seahorse_pgp_subkey_get_fingerprint   (SeahorsePgpSubkey *self);
 
 void                seahorse_pgp_subkey_set_fingerprint   (SeahorsePgpSubkey *self,
-                                                           const gchar *description);
+                                                           const char        *description);
 
-gchar*              seahorse_pgp_subkey_calc_fingerprint  (const gchar *raw_fingerprint);
+char *              seahorse_pgp_subkey_calc_fingerprint  (const char *raw_fingerprint);


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