[gimp] app: change GimpSettings to store its time as gint64



commit 7d5f1e44f267e2e8c114582cbbec8417b1a1968b
Author: Michael Natterer <mitch gimp org>
Date:   Sun Jul 23 15:18:55 2017 +0200

    app: change GimpSettings to store its time as gint64
    
    and use GDateTime for handling it.

 app/core/gimpsettings.c |   37 +++++++++++++++++--------------------
 app/core/gimpsettings.h |    2 +-
 2 files changed, 18 insertions(+), 21 deletions(-)
---
diff --git a/app/core/gimpsettings.c b/app/core/gimpsettings.c
index bba7d00..4246859 100644
--- a/app/core/gimpsettings.c
+++ b/app/core/gimpsettings.c
@@ -71,15 +71,15 @@ gimp_settings_class_init (GimpSettingsClass *klass)
   viewable_class->get_description = gimp_settings_get_description;
   viewable_class->name_editable   = TRUE;
 
-  GIMP_CONFIG_PROP_UINT (object_class, PROP_TIME,
-                         "time",
-                         "Time",
-                         "Time of settings creation",
-                         0, G_MAXUINT, 0, 0);
+  GIMP_CONFIG_PROP_INT64 (object_class, PROP_TIME,
+                          "time",
+                          "Time",
+                          "Time of settings creation",
+                          0, G_MAXINT64, 0, 0);
 }
 
 static void
-gimp_settings_init (GimpSettings *config)
+gimp_settings_init (GimpSettings *settings)
 {
 }
 
@@ -89,12 +89,12 @@ gimp_settings_get_property (GObject    *object,
                             GValue     *value,
                             GParamSpec *pspec)
 {
-  GimpSettings *config = GIMP_SETTINGS (object);
+  GimpSettings *settings = GIMP_SETTINGS (object);
 
   switch (property_id)
     {
     case PROP_TIME:
-      g_value_set_uint (value, config->time);
+      g_value_set_int64 (value, settings->time);
       break;
 
     default:
@@ -109,27 +109,24 @@ gimp_settings_set_property (GObject      *object,
                             const GValue *value,
                             GParamSpec   *pspec)
 {
-  GimpSettings *config = GIMP_SETTINGS (object);
+  GimpSettings *settings = GIMP_SETTINGS (object);
 
   switch (property_id)
     {
     case PROP_TIME:
-      config->time = g_value_get_uint (value);
+      settings->time = g_value_get_int64 (value);
 
-      if (config->time > 0)
+      if (settings->time > 0)
         {
-          time_t     t;
-          struct tm  tm;
-          gchar      buf[64];
+          GDateTime *utc   = g_date_time_new_from_unix_utc (settings->time);
+          GDateTime *local = g_date_time_to_local (utc);
           gchar     *name;
 
-          t = config->time;
-          tm = *localtime (&t);
-          strftime (buf, sizeof (buf), "%Y-%m-%d %H:%M:%S", &tm);
+          name = g_date_time_format (local, "%Y-%m-%d %H:%M:%S");
+          gimp_object_take_name (GIMP_OBJECT (settings), name);
 
-          name = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
-          gimp_object_set_name (GIMP_OBJECT (config), name);
-          g_free (name);
+          g_date_time_unref (local);
+          g_date_time_unref (utc);
         }
       break;
 
diff --git a/app/core/gimpsettings.h b/app/core/gimpsettings.h
index d31aa73..0235b98 100644
--- a/app/core/gimpsettings.h
+++ b/app/core/gimpsettings.h
@@ -39,7 +39,7 @@ struct _GimpSettings
 {
   GimpViewable  parent_instance;
 
-  guint         time;
+  gint64        time;
 };
 
 struct _GimpSettingsClass


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