Add compatibility wrappers for GLib APIs introduced after 2.38: pattern matching helpers, GFileInfo modification time handling, and GBookmarkFile recent-file metadata.
Use the newer GDateTime and renamed pattern APIs when available, while falling back to the older time_t/GTimeVal and pattern APIs with older GLib versions. Internally, recent timestamps continue to be stored as gint64 where possible.
This commit is contained in:
parent
db6ebcde3b
commit
a5e2391f2e
7 changed files with 212 additions and 52 deletions
|
|
@ -24,6 +24,7 @@
|
|||
#include "gtkmarshalers.h"
|
||||
#include "gtkwindow.h" /* in lack of GtkAcceleratable */
|
||||
#include "gtkintl.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkalias.h"
|
||||
|
||||
#include <glib/gstdio.h>
|
||||
|
|
@ -772,7 +773,7 @@ gtk_accel_map_foreach (gpointer data,
|
|||
gboolean changed = entry->accel_key != entry->std_accel_key || entry->accel_mods != entry->std_accel_mods;
|
||||
|
||||
for (node = accel_filters; node; node = node->next)
|
||||
if (g_pattern_spec_match_string (node->data, entry->accel_path))
|
||||
if (_gtk_pattern_spec_match_string (node->data, entry->accel_path))
|
||||
goto skip_accel;
|
||||
foreach_func (data, entry->accel_path, entry->accel_key, entry->accel_mods, changed);
|
||||
skip_accel:
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include "gtkkeyhash.h"
|
||||
#include "gtkwidget.h"
|
||||
#include "gtkrc.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkalias.h"
|
||||
|
||||
|
||||
|
|
@ -1109,7 +1110,7 @@ binding_match_activate (GSList *pspec_list,
|
|||
}
|
||||
else
|
||||
{
|
||||
if (g_pattern_spec_match (pspec->pspec, path_length, path, path_reversed))
|
||||
if (_gtk_pattern_spec_match (pspec->pspec, path_length, path, path_reversed))
|
||||
binding_set = pspec->user_data;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8015,18 +8015,31 @@ file_system_model_set (GtkFileSystemModel *model,
|
|||
case MODEL_COL_MTIME:
|
||||
case MODEL_COL_MTIME_TEXT:
|
||||
{
|
||||
GDateTime *dt;
|
||||
gint64 tv = 0;
|
||||
|
||||
if (info == NULL)
|
||||
break;
|
||||
|
||||
dt = g_file_info_get_modification_date_time (info);
|
||||
if (dt)
|
||||
{
|
||||
tv = g_date_time_to_unix (dt);
|
||||
g_date_time_unref (dt);
|
||||
}
|
||||
/* GLib 2.62 replaced the old GTimeVal API with GDateTime. */
|
||||
#if GLIB_CHECK_VERSION (2, 62, 0)
|
||||
{
|
||||
GDateTime *dt;
|
||||
|
||||
dt = g_file_info_get_modification_date_time (info);
|
||||
if (dt)
|
||||
{
|
||||
tv = g_date_time_to_unix (dt);
|
||||
g_date_time_unref (dt);
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
GTimeVal timeval;
|
||||
|
||||
g_file_info_get_modification_time (info, &timeval);
|
||||
tv = timeval.tv_sec;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (column == MODEL_COL_MTIME)
|
||||
g_value_set_int64 (value, tv);
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkalias.h"
|
||||
|
||||
/* --- defines --- */
|
||||
|
|
@ -1184,9 +1185,9 @@ gtk_item_factory_create_menu_entries (guint n_entries,
|
|||
entry.accelerator = entries[i].accelerator;
|
||||
entry.callback = (GtkItemFactoryCallback)entries[i].callback;
|
||||
entry.callback_action = 0;
|
||||
if (g_pattern_spec_match_string (pspec_separator, path))
|
||||
if (_gtk_pattern_spec_match_string (pspec_separator, path))
|
||||
entry.item_type = "<Separator>";
|
||||
else if (!g_pattern_spec_match_string (pspec_check, path))
|
||||
else if (!_gtk_pattern_spec_match_string (pspec_check, path))
|
||||
entry.item_type = NULL;
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,6 +31,22 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
/* GLib 2.70 renamed the old g_pattern_match*() APIs.
|
||||
* Keep the old names for older GLib versions.
|
||||
*/
|
||||
#if GLIB_CHECK_VERSION (2, 70, 0)
|
||||
#define _gtk_pattern_spec_match(pspec, string_length, string, string_reversed) \
|
||||
g_pattern_spec_match ((pspec), (string_length), (string), (string_reversed))
|
||||
#define _gtk_pattern_spec_match_string(pspec, string) \
|
||||
g_pattern_spec_match_string ((pspec), (string))
|
||||
#else
|
||||
#define _gtk_pattern_spec_match(pspec, string_length, string, string_reversed) \
|
||||
g_pattern_match ((pspec), (string_length), (string), (string_reversed))
|
||||
#define _gtk_pattern_spec_match_string(pspec, string) \
|
||||
g_pattern_match_string ((pspec), (string))
|
||||
#endif
|
||||
|
||||
/* GLib 2.68 added g_memdup2() as a gsize-safe replacement for
|
||||
* g_memdup(). The old g_memdup() takes the allocation size as guint,
|
||||
* which can truncate a gsize value on platforms where gsize is wider.
|
||||
|
|
|
|||
|
|
@ -1887,7 +1887,7 @@ gtk_rc_styles_match (GSList *rc_styles,
|
|||
}
|
||||
else
|
||||
{
|
||||
if (g_pattern_spec_match (rc_set->pspec, path_length, path, path_reversed))
|
||||
if (_gtk_pattern_spec_match (rc_set->pspec, path_length, path, path_reversed))
|
||||
rc_styles = g_slist_append (rc_styles, rc_set);
|
||||
}
|
||||
}
|
||||
|
|
@ -4814,7 +4814,7 @@ match_widget_class_recursive (GSList *list,
|
|||
* just compare the pspec.
|
||||
*/
|
||||
if (list->next == NULL)
|
||||
return g_pattern_spec_match (path_elt->elt.pspec, length, path, path_reversed);
|
||||
return _gtk_pattern_spec_match (path_elt->elt.pspec, length, path, path_reversed);
|
||||
|
||||
class_elt = (PathElt *)list->next->data;
|
||||
g_assert (class_elt->type != PATH_ELT_PSPEC);
|
||||
|
|
@ -4854,7 +4854,7 @@ match_widget_class_recursive (GSList *list,
|
|||
old_char = class_start[0];
|
||||
class_start[0] = '\0';
|
||||
|
||||
if (g_pattern_spec_match (path_elt->elt.pspec, class_start - path, path, path_reversed + length - (class_start - path)))
|
||||
if (_gtk_pattern_spec_match (path_elt->elt.pspec, class_start - path, path, path_reversed + length - (class_start - path)))
|
||||
{
|
||||
if (class_end != NULL)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -539,6 +539,147 @@ gtk_recent_manager_monitor_changed (GFileMonitor *monitor,
|
|||
}
|
||||
}
|
||||
|
||||
/* GLib 2.66 added GDateTime-based GBookmarkFile APIs. Older GLib
|
||||
* versions only provide time_t-based APIs, so keep the conversion local
|
||||
* to GtkRecentManager while storing timestamps internally as gint64.
|
||||
*
|
||||
* The old GLib fallback is limited by time_t on platforms where time_t is
|
||||
* still 32-bit; the GDateTime path remains used whenever GLib provides it.
|
||||
*/
|
||||
static gint64
|
||||
gtk_recent_bookmark_file_get_added_time (GBookmarkFile *bookmarks,
|
||||
const gchar *uri)
|
||||
{
|
||||
#if GLIB_CHECK_VERSION (2, 66, 0)
|
||||
GDateTime *dt;
|
||||
gint64 result;
|
||||
|
||||
dt = g_bookmark_file_get_added_date_time (bookmarks, uri, NULL);
|
||||
result = dt ? g_date_time_to_unix (dt) : -1;
|
||||
|
||||
if (dt)
|
||||
g_date_time_unref (dt);
|
||||
|
||||
return result;
|
||||
#else
|
||||
return g_bookmark_file_get_added (bookmarks, uri, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static gint64
|
||||
gtk_recent_bookmark_file_get_modified_time (GBookmarkFile *bookmarks,
|
||||
const gchar *uri)
|
||||
{
|
||||
#if GLIB_CHECK_VERSION (2, 66, 0)
|
||||
GDateTime *dt;
|
||||
gint64 result;
|
||||
|
||||
dt = g_bookmark_file_get_modified_date_time (bookmarks, uri, NULL);
|
||||
result = dt ? g_date_time_to_unix (dt) : -1;
|
||||
|
||||
if (dt)
|
||||
g_date_time_unref (dt);
|
||||
|
||||
return result;
|
||||
#else
|
||||
return g_bookmark_file_get_modified (bookmarks, uri, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static gint64
|
||||
gtk_recent_bookmark_file_get_visited_time (GBookmarkFile *bookmarks,
|
||||
const gchar *uri)
|
||||
{
|
||||
#if GLIB_CHECK_VERSION (2, 66, 0)
|
||||
GDateTime *dt;
|
||||
gint64 result;
|
||||
|
||||
dt = g_bookmark_file_get_visited_date_time (bookmarks, uri, NULL);
|
||||
result = dt ? g_date_time_to_unix (dt) : -1;
|
||||
|
||||
if (dt)
|
||||
g_date_time_unref (dt);
|
||||
|
||||
return result;
|
||||
#else
|
||||
return g_bookmark_file_get_visited (bookmarks, uri, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_recent_bookmark_file_get_application_info (GBookmarkFile *bookmarks,
|
||||
const gchar *uri,
|
||||
const gchar *name,
|
||||
gchar **exec,
|
||||
guint *count,
|
||||
gint64 *stamp,
|
||||
GError **error)
|
||||
{
|
||||
#if GLIB_CHECK_VERSION (2, 66, 0)
|
||||
GDateTime *dt = NULL;
|
||||
gboolean res;
|
||||
|
||||
if (stamp)
|
||||
*stamp = -1;
|
||||
|
||||
res = g_bookmark_file_get_application_info (bookmarks, uri, name,
|
||||
exec, count, &dt, error);
|
||||
|
||||
if (stamp && dt)
|
||||
*stamp = g_date_time_to_unix (dt);
|
||||
|
||||
if (dt)
|
||||
g_date_time_unref (dt);
|
||||
|
||||
return res;
|
||||
#else
|
||||
time_t old_stamp = (time_t) -1;
|
||||
gboolean res;
|
||||
|
||||
if (stamp)
|
||||
*stamp = -1;
|
||||
|
||||
res = g_bookmark_file_get_app_info (bookmarks, uri, name,
|
||||
exec, count, &old_stamp, error);
|
||||
|
||||
if (stamp && res)
|
||||
*stamp = old_stamp;
|
||||
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_recent_bookmark_file_set_application_info (GBookmarkFile *bookmarks,
|
||||
const gchar *uri,
|
||||
const gchar *name,
|
||||
const gchar *exec,
|
||||
guint count,
|
||||
gint64 stamp,
|
||||
GError **error)
|
||||
{
|
||||
#if GLIB_CHECK_VERSION (2, 66, 0)
|
||||
GDateTime *dt = NULL;
|
||||
gboolean res;
|
||||
|
||||
if (stamp != -1)
|
||||
dt = g_date_time_new_from_unix_utc (stamp);
|
||||
|
||||
res = g_bookmark_file_set_application_info (bookmarks, uri, name,
|
||||
exec, count, dt, error);
|
||||
|
||||
if (dt)
|
||||
g_date_time_unref (dt);
|
||||
|
||||
return res;
|
||||
#else
|
||||
return g_bookmark_file_set_app_info (bookmarks, uri, name,
|
||||
exec, count,
|
||||
recent_time_to_time_t (stamp),
|
||||
error);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* get_default_recent_file:
|
||||
*
|
||||
|
|
@ -630,21 +771,20 @@ get_default_recent_file (void)
|
|||
apps = g_bookmark_file_get_applications (bf_old, uris[i], &n_apps, NULL);
|
||||
for (j = 0; j < n_apps; j++)
|
||||
{
|
||||
char *exec;
|
||||
guint count;
|
||||
GDateTime *stamp;
|
||||
char *exec = NULL;
|
||||
guint count = 0;
|
||||
gint64 stamp = -1;
|
||||
|
||||
g_bookmark_file_get_application_info (bf_old, uris[i], apps[j],
|
||||
&exec,
|
||||
&count,
|
||||
&stamp,
|
||||
NULL);
|
||||
|
||||
g_bookmark_file_set_application_info (bf_new, uris[i], apps[j],
|
||||
exec,
|
||||
count,
|
||||
stamp,
|
||||
NULL);
|
||||
if (gtk_recent_bookmark_file_get_application_info (bf_old, uris[i], apps[j],
|
||||
&exec,
|
||||
&count,
|
||||
&stamp,
|
||||
NULL))
|
||||
gtk_recent_bookmark_file_set_application_info (bf_new, uris[i], apps[j],
|
||||
exec,
|
||||
count,
|
||||
stamp,
|
||||
NULL);
|
||||
|
||||
g_free (exec);
|
||||
}
|
||||
|
|
@ -1292,19 +1432,9 @@ build_recent_info (GBookmarkFile *bookmarks,
|
|||
|
||||
info->is_private = g_bookmark_file_get_is_private (bookmarks, info->uri, NULL);
|
||||
|
||||
{
|
||||
GDateTime *added;
|
||||
GDateTime *modified;
|
||||
GDateTime *visited;
|
||||
|
||||
added = g_bookmark_file_get_added_date_time (bookmarks, info->uri, NULL);
|
||||
modified = g_bookmark_file_get_modified_date_time (bookmarks, info->uri, NULL);
|
||||
visited = g_bookmark_file_get_visited_date_time (bookmarks, info->uri, NULL);
|
||||
|
||||
info->added = added ? g_date_time_to_unix (added) : -1;
|
||||
info->modified = modified ? g_date_time_to_unix (modified) : -1;
|
||||
info->visited = visited ? g_date_time_to_unix (visited) : -1;
|
||||
}
|
||||
info->added = gtk_recent_bookmark_file_get_added_time (bookmarks, info->uri);
|
||||
info->modified = gtk_recent_bookmark_file_get_modified_time (bookmarks, info->uri);
|
||||
info->visited = gtk_recent_bookmark_file_get_visited_time (bookmarks, info->uri);
|
||||
|
||||
groups = g_bookmark_file_get_groups (bookmarks, info->uri, &groups_len, NULL);
|
||||
for (i = 0; i < groups_len; i++)
|
||||
|
|
@ -1321,24 +1451,24 @@ build_recent_info (GBookmarkFile *bookmarks,
|
|||
{
|
||||
gchar *app_name, *app_exec;
|
||||
guint count;
|
||||
GDateTime *stamp;
|
||||
gint64 stamp;
|
||||
RecentAppInfo *app_info;
|
||||
gboolean res;
|
||||
|
||||
app_name = apps[i];
|
||||
|
||||
res = g_bookmark_file_get_application_info (bookmarks, info->uri, app_name,
|
||||
&app_exec,
|
||||
&count,
|
||||
&stamp,
|
||||
NULL);
|
||||
res = gtk_recent_bookmark_file_get_application_info (bookmarks, info->uri, app_name,
|
||||
&app_exec,
|
||||
&count,
|
||||
&stamp,
|
||||
NULL);
|
||||
if (!res)
|
||||
continue;
|
||||
|
||||
app_info = recent_app_info_new (app_name);
|
||||
app_info->exec = app_exec;
|
||||
app_info->count = count;
|
||||
app_info->stamp = g_date_time_to_unix (stamp);
|
||||
app_info->stamp = stamp;
|
||||
|
||||
info->applications = g_slist_prepend (info->applications, app_info);
|
||||
g_hash_table_replace (info->apps_lookup, app_info->name, app_info);
|
||||
|
|
@ -1638,12 +1768,10 @@ gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
|
|||
for (i = 0; i < n_uris; i++)
|
||||
{
|
||||
const gchar *uri = uris[i];
|
||||
GDateTime *modified_date_time;
|
||||
time_t modified;
|
||||
gint item_age;
|
||||
|
||||
modified_date_time = g_bookmark_file_get_modified_date_time (priv->recent_items, uri, NULL);
|
||||
modified = modified_date_time ? g_date_time_to_unix (modified_date_time) : (time_t) -1;
|
||||
modified = recent_time_to_time_t (gtk_recent_bookmark_file_get_modified_time (priv->recent_items, uri));
|
||||
|
||||
if (recent_time_get_days_elapsed (now, modified, &item_age) &&
|
||||
item_age > age)
|
||||
|
|
|
|||
Loading…
Reference in a new issue