[gtk/glib-build-fix: 1/2] recentmanager: Keep up with GLib deprecations
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/glib-build-fix: 1/2] recentmanager: Keep up with GLib deprecations
- Date: Fri, 31 Jul 2020 16:19:21 +0000 (UTC)
commit 72e14bd6dd4af76fbaac4f3f5c425a61c44eb9a8
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jul 31 12:08:41 2020 -0400
recentmanager: Keep up with GLib deprecations
All the time_t based apis in GBookmarkFile have
been deprecated; use GDateTime instead. This
changes a few GtkRecentManager APIs.
gtk/gtkrecentmanager.c | 96 ++++++++++++++++++++++++--------------------------
gtk/gtkrecentmanager.h | 18 +++++-----
2 files changed, 56 insertions(+), 58 deletions(-)
---
diff --git a/gtk/gtkrecentmanager.c b/gtk/gtkrecentmanager.c
index 2422f20d85..31596a68d5 100644
--- a/gtk/gtkrecentmanager.c
+++ b/gtk/gtkrecentmanager.c
@@ -125,7 +125,7 @@ typedef struct
guint count;
- time_t stamp;
+ GDateTime *stamp;
} RecentAppInfo;
/**
@@ -144,9 +144,9 @@ struct _GtkRecentInfo
char *display_name;
char *description;
- time_t added;
- time_t modified;
- time_t visited;
+ GDateTime *added;
+ GDateTime *modified;
+ GDateTime *visited;
char *mime_type;
@@ -1096,9 +1096,9 @@ build_recent_info (GBookmarkFile *bookmarks,
info->is_private = g_bookmark_file_get_is_private (bookmarks, info->uri, NULL);
- info->added = g_bookmark_file_get_added (bookmarks, info->uri, NULL);
- info->modified = g_bookmark_file_get_modified (bookmarks, info->uri, NULL);
- info->visited = g_bookmark_file_get_visited (bookmarks, info->uri, NULL);
+ info->added = g_bookmark_file_get_added_date_time (bookmarks, info->uri, NULL);
+ info->modified = g_bookmark_file_get_modified_date_time (bookmarks, info->uri, NULL);
+ info->visited = g_bookmark_file_get_visited_date_time (bookmarks, info->uri, NULL);
groups = g_bookmark_file_get_groups (bookmarks, info->uri, &groups_len, NULL);
info->groups = g_malloc (sizeof (char *) * groups_len);
@@ -1116,17 +1116,17 @@ build_recent_info (GBookmarkFile *bookmarks,
{
char *app_name, *app_exec;
guint count;
- time_t stamp;
+ GDateTime *stamp;
RecentAppInfo *app_info;
gboolean res;
app_name = apps[i];
- res = g_bookmark_file_get_app_info (bookmarks, info->uri, app_name,
- &app_exec,
- &count,
- &stamp,
- NULL);
+ res = g_bookmark_file_get_application_info (bookmarks, info->uri, app_name,
+ &app_exec,
+ &count,
+ &stamp,
+ NULL);
if (!res)
continue;
@@ -1134,7 +1134,7 @@ build_recent_info (GBookmarkFile *bookmarks,
app_info->name= g_strdup (app_name);
app_info->exec = app_exec;
app_info->count = count;
- app_info->stamp = stamp;
+ app_info->stamp = g_date_time_ref (stamp);
g_hash_table_replace (info->apps_lookup, app_info->name, app_info);
@@ -1417,23 +1417,24 @@ gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
GtkRecentManagerPrivate *priv = manager->priv;
char **uris;
gsize n_uris, i;
- time_t now;
+ GDateTime *now;
if (G_UNLIKELY (!priv->recent_items))
return;
- now = time (NULL);
+ now = g_date_time_new_now_utc ();
uris = g_bookmark_file_get_uris (priv->recent_items, &n_uris);
for (i = 0; i < n_uris; i++)
{
const char *uri = uris[i];
- time_t modified;
+ GDateTime *modified;
int item_age;
- modified = g_bookmark_file_get_modified (priv->recent_items, uri, NULL);
- item_age = (int) ((now - modified) / (60 * 60 * 24));
+ modified = g_bookmark_file_get_modified_date_time (priv->recent_items, uri, NULL);
+
+ item_age = (int) (g_date_time_difference (now, modified) / (double)G_TIME_SPAN_DAY);
if (item_age > age)
g_bookmark_file_remove_item (priv->recent_items, uri, NULL);
}
@@ -1516,6 +1517,7 @@ gtk_recent_info_free (GtkRecentInfo *recent_info)
g_free (app_info->name);
g_free (app_info->exec);
+ g_date_time_unref (app_info->stamp);
}
g_free (recent_info->applications);
@@ -1648,16 +1650,16 @@ gtk_recent_info_get_mime_type (GtkRecentInfo *info)
* gtk_recent_info_get_added:
* @info: a #GtkRecentInfo
*
- * Gets the timestamp (seconds from system’s Epoch) when the resource
+ * Gets the the time when the resource
* was added to the recently used resources list.
*
- * Returns: the number of seconds elapsed from system’s Epoch when
- * the resource was added to the list, or -1 on failure.
+ * Returns: (transfer none): a #GDateTime for the time
+ * when the resource was added
*/
-time_t
+GDateTime *
gtk_recent_info_get_added (GtkRecentInfo *info)
{
- g_return_val_if_fail (info != NULL, (time_t) -1);
+ g_return_val_if_fail (info != NULL, NULL);
return info->added;
}
@@ -1666,16 +1668,16 @@ gtk_recent_info_get_added (GtkRecentInfo *info)
* gtk_recent_info_get_modified:
* @info: a #GtkRecentInfo
*
- * Gets the timestamp (seconds from system’s Epoch) when the meta-data
+ * Gets the time when the meta-data
* for the resource was last modified.
*
- * Returns: the number of seconds elapsed from system’s Epoch when
- * the resource was last modified, or -1 on failure.
+ * Returns: (transfer none): a #GDateTime for the time
+ * when the resource was last modified
*/
-time_t
+GDateTime *
gtk_recent_info_get_modified (GtkRecentInfo *info)
{
- g_return_val_if_fail (info != NULL, (time_t) -1);
+ g_return_val_if_fail (info != NULL, NULL);
return info->modified;
}
@@ -1684,16 +1686,16 @@ gtk_recent_info_get_modified (GtkRecentInfo *info)
* gtk_recent_info_get_visited:
* @info: a #GtkRecentInfo
*
- * Gets the timestamp (seconds from system’s Epoch) when the meta-data
+ * Gets the time when the meta-data
* for the resource was last visited.
*
- * Returns: the number of seconds elapsed from system’s Epoch when
- * the resource was last visited, or -1 on failure.
+ * Returns: (transfer none): a #GDateTime for the time
+ * when the resource was last visited
*/
-time_t
+GDateTime *
gtk_recent_info_get_visited (GtkRecentInfo *info)
{
- g_return_val_if_fail (info != NULL, (time_t) -1);
+ g_return_val_if_fail (info != NULL, NULL);
return info->visited;
}
@@ -1723,8 +1725,8 @@ gtk_recent_info_get_private_hint (GtkRecentInfo *info)
* @app_exec: (transfer none) (out): return location for the string containing
* the command line
* @count: (out): return location for the number of times this item was registered
- * @time_: (out): return location for the timestamp this item was last registered
- * for this application
+ * @stamp: (out) (transfer none): return location for the time this item was last
+ * registered for this application
*
* Gets the data regarding the application that has registered the resource
* pointed by @info.
@@ -1742,7 +1744,7 @@ gtk_recent_info_get_application_info (GtkRecentInfo *info,
const char *app_name,
const char **app_exec,
guint *count,
- time_t *time_)
+ GDateTime **stamp)
{
RecentAppInfo *ai;
@@ -1766,8 +1768,8 @@ gtk_recent_info_get_application_info (GtkRecentInfo *info,
if (count)
*count = ai->count;
- if (time_)
- *time_ = ai->stamp;
+ if (stamp)
+ *stamp = ai->stamp;
return TRUE;
}
@@ -1851,7 +1853,7 @@ char *
gtk_recent_info_last_application (GtkRecentInfo *info)
{
int i;
- time_t last_stamp = (time_t) -1;
+ GDateTime *last_stamp = NULL;
char *name = NULL;
g_return_val_if_fail (info != NULL, NULL);
@@ -1860,7 +1862,8 @@ gtk_recent_info_last_application (GtkRecentInfo *info)
{
const RecentAppInfo *ai = &info->applications[i];
- if (ai->stamp > last_stamp)
+ if (last_stamp == NULL ||
+ g_date_time_compare (ai->stamp, last_stamp) > 0)
{
name = ai->name;
last_stamp = ai->stamp;
@@ -2179,18 +2182,13 @@ gtk_recent_info_get_uri_display (GtkRecentInfo *info)
int
gtk_recent_info_get_age (GtkRecentInfo *info)
{
- time_t now, delta;
- int retval;
+ GDateTime *now;
g_return_val_if_fail (info != NULL, -1);
- now = time (NULL);
+ now = g_date_time_new_now_utc ();
- delta = now - info->modified;
-
- retval = (int) (delta / (60 * 60 * 24));
-
- return retval;
+ return (int) (g_date_time_difference (now, info->modified) / (double)G_TIME_SPAN_DAY);
}
/**
diff --git a/gtk/gtkrecentmanager.h b/gtk/gtkrecentmanager.h
index 2f32db3415..375c68c308 100644
--- a/gtk/gtkrecentmanager.h
+++ b/gtk/gtkrecentmanager.h
@@ -207,19 +207,19 @@ const char * gtk_recent_info_get_description (GtkRecentInfo *info)
GDK_AVAILABLE_IN_ALL
const char * gtk_recent_info_get_mime_type (GtkRecentInfo *info);
GDK_AVAILABLE_IN_ALL
-time_t gtk_recent_info_get_added (GtkRecentInfo *info);
+GDateTime * gtk_recent_info_get_added (GtkRecentInfo *info);
GDK_AVAILABLE_IN_ALL
-time_t gtk_recent_info_get_modified (GtkRecentInfo *info);
+GDateTime * gtk_recent_info_get_modified (GtkRecentInfo *info);
GDK_AVAILABLE_IN_ALL
-time_t gtk_recent_info_get_visited (GtkRecentInfo *info);
+GDateTime * gtk_recent_info_get_visited (GtkRecentInfo *info);
GDK_AVAILABLE_IN_ALL
-gboolean gtk_recent_info_get_private_hint (GtkRecentInfo *info);
+gboolean gtk_recent_info_get_private_hint (GtkRecentInfo *info);
GDK_AVAILABLE_IN_ALL
-gboolean gtk_recent_info_get_application_info (GtkRecentInfo *info,
- const char *app_name,
- const char **app_exec,
- guint *count,
- time_t *time_);
+gboolean gtk_recent_info_get_application_info (GtkRecentInfo *info,
+ const char *app_name,
+ const char **app_exec,
+ guint *count,
+ GDateTime **stamp);
GDK_AVAILABLE_IN_ALL
GAppInfo * gtk_recent_info_create_app_info (GtkRecentInfo *info,
const char *app_name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]