mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-24 03:02:10 +01:00
Merge branch '1931-bookmark-file-y2038' into 'master'
Resolve "GBookmarkFile API involves time_t" Closes #1931 See merge request GNOME/glib!1511
This commit is contained in:
commit
3d0e1f5c85
@ -2369,11 +2369,15 @@ g_bookmark_file_get_mime_type
|
|||||||
g_bookmark_file_get_is_private
|
g_bookmark_file_get_is_private
|
||||||
g_bookmark_file_get_icon
|
g_bookmark_file_get_icon
|
||||||
g_bookmark_file_get_added
|
g_bookmark_file_get_added
|
||||||
|
g_bookmark_file_get_added_date_time
|
||||||
g_bookmark_file_get_modified
|
g_bookmark_file_get_modified
|
||||||
|
g_bookmark_file_get_modified_date_time
|
||||||
g_bookmark_file_get_visited
|
g_bookmark_file_get_visited
|
||||||
|
g_bookmark_file_get_visited_date_time
|
||||||
g_bookmark_file_get_groups
|
g_bookmark_file_get_groups
|
||||||
g_bookmark_file_get_applications
|
g_bookmark_file_get_applications
|
||||||
g_bookmark_file_get_app_info
|
g_bookmark_file_get_app_info
|
||||||
|
g_bookmark_file_get_application_info
|
||||||
|
|
||||||
<SUBSECTION>
|
<SUBSECTION>
|
||||||
g_bookmark_file_set_title
|
g_bookmark_file_set_title
|
||||||
@ -2382,10 +2386,14 @@ g_bookmark_file_set_mime_type
|
|||||||
g_bookmark_file_set_is_private
|
g_bookmark_file_set_is_private
|
||||||
g_bookmark_file_set_icon
|
g_bookmark_file_set_icon
|
||||||
g_bookmark_file_set_added
|
g_bookmark_file_set_added
|
||||||
|
g_bookmark_file_set_added_date_time
|
||||||
g_bookmark_file_set_groups
|
g_bookmark_file_set_groups
|
||||||
g_bookmark_file_set_modified
|
g_bookmark_file_set_modified
|
||||||
|
g_bookmark_file_set_modified_date_time
|
||||||
g_bookmark_file_set_visited
|
g_bookmark_file_set_visited
|
||||||
|
g_bookmark_file_set_visited_date_time
|
||||||
g_bookmark_file_set_app_info
|
g_bookmark_file_set_app_info
|
||||||
|
g_bookmark_file_set_application_info
|
||||||
g_bookmark_file_add_group
|
g_bookmark_file_add_group
|
||||||
g_bookmark_file_add_application
|
g_bookmark_file_add_application
|
||||||
g_bookmark_file_remove_group
|
g_bookmark_file_remove_group
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include "gconvert.h"
|
#include "gconvert.h"
|
||||||
#include "gdataset.h"
|
#include "gdataset.h"
|
||||||
|
#include "gdatetime.h"
|
||||||
#include "gerror.h"
|
#include "gerror.h"
|
||||||
#include "gfileutils.h"
|
#include "gfileutils.h"
|
||||||
#include "ghash.h"
|
#include "ghash.h"
|
||||||
@ -86,7 +87,7 @@
|
|||||||
*
|
*
|
||||||
* The important caveat of bookmark files is that when you add a new
|
* The important caveat of bookmark files is that when you add a new
|
||||||
* bookmark you must also add the application that is registering it, using
|
* bookmark you must also add the application that is registering it, using
|
||||||
* g_bookmark_file_add_application() or g_bookmark_file_set_app_info().
|
* g_bookmark_file_add_application() or g_bookmark_file_set_application_info().
|
||||||
* If a bookmark has no applications then it won't be dumped when creating
|
* If a bookmark has no applications then it won't be dumped when creating
|
||||||
* the on disk representation, using g_bookmark_file_to_data() or
|
* the on disk representation, using g_bookmark_file_to_data() or
|
||||||
* g_bookmark_file_to_file().
|
* g_bookmark_file_to_file().
|
||||||
@ -165,7 +166,7 @@ struct _BookmarkAppInfo
|
|||||||
|
|
||||||
guint count;
|
guint count;
|
||||||
|
|
||||||
time_t stamp;
|
GDateTime *stamp; /* (owned) */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _BookmarkMetadata
|
struct _BookmarkMetadata
|
||||||
@ -190,9 +191,9 @@ struct _BookmarkItem
|
|||||||
gchar *title;
|
gchar *title;
|
||||||
gchar *description;
|
gchar *description;
|
||||||
|
|
||||||
time_t added;
|
GDateTime *added; /* (owned) */
|
||||||
time_t modified;
|
GDateTime *modified; /* (owned) */
|
||||||
time_t visited;
|
GDateTime *visited; /* (owned) */
|
||||||
|
|
||||||
BookmarkMetadata *metadata;
|
BookmarkMetadata *metadata;
|
||||||
};
|
};
|
||||||
@ -245,10 +246,9 @@ static void g_bookmark_file_add_item (GBookmarkFile *bookmark,
|
|||||||
BookmarkItem *item,
|
BookmarkItem *item,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
static gboolean timestamp_from_iso8601 (const gchar *iso_date,
|
static gboolean timestamp_from_iso8601 (const gchar *iso_date,
|
||||||
time_t *out_timestamp,
|
GDateTime **out_date_time,
|
||||||
GError **error);
|
GError **error);
|
||||||
static gchar *timestamp_to_iso8601 (time_t timestamp);
|
|
||||||
|
|
||||||
/********************************
|
/********************************
|
||||||
* BookmarkAppInfo *
|
* BookmarkAppInfo *
|
||||||
@ -267,7 +267,7 @@ bookmark_app_info_new (const gchar *name)
|
|||||||
retval->name = g_strdup (name);
|
retval->name = g_strdup (name);
|
||||||
retval->exec = NULL;
|
retval->exec = NULL;
|
||||||
retval->count = 0;
|
retval->count = 0;
|
||||||
retval->stamp = 0;
|
retval->stamp = NULL;
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@ -280,6 +280,7 @@ bookmark_app_info_free (BookmarkAppInfo *app_info)
|
|||||||
|
|
||||||
g_free (app_info->name);
|
g_free (app_info->name);
|
||||||
g_free (app_info->exec);
|
g_free (app_info->exec);
|
||||||
|
g_clear_pointer (&app_info->stamp, g_date_time_unref);
|
||||||
|
|
||||||
g_slice_free (BookmarkAppInfo, app_info);
|
g_slice_free (BookmarkAppInfo, app_info);
|
||||||
}
|
}
|
||||||
@ -297,7 +298,7 @@ bookmark_app_info_dump (BookmarkAppInfo *app_info)
|
|||||||
|
|
||||||
name = g_markup_escape_text (app_info->name, -1);
|
name = g_markup_escape_text (app_info->name, -1);
|
||||||
exec = g_markup_escape_text (app_info->exec, -1);
|
exec = g_markup_escape_text (app_info->exec, -1);
|
||||||
modified = timestamp_to_iso8601 (app_info->stamp);
|
modified = g_date_time_format_iso8601 (app_info->stamp);
|
||||||
count = g_strdup_printf ("%u", app_info->count);
|
count = g_strdup_printf ("%u", app_info->count);
|
||||||
|
|
||||||
retval = g_strconcat (" "
|
retval = g_strconcat (" "
|
||||||
@ -511,9 +512,9 @@ bookmark_item_new (const gchar *uri)
|
|||||||
item->title = NULL;
|
item->title = NULL;
|
||||||
item->description = NULL;
|
item->description = NULL;
|
||||||
|
|
||||||
item->added = (time_t) -1;
|
item->added = NULL;
|
||||||
item->modified = (time_t) -1;
|
item->modified = NULL;
|
||||||
item->visited = (time_t) -1;
|
item->visited = NULL;
|
||||||
|
|
||||||
item->metadata = NULL;
|
item->metadata = NULL;
|
||||||
|
|
||||||
@ -533,9 +534,20 @@ bookmark_item_free (BookmarkItem *item)
|
|||||||
if (item->metadata)
|
if (item->metadata)
|
||||||
bookmark_metadata_free (item->metadata);
|
bookmark_metadata_free (item->metadata);
|
||||||
|
|
||||||
|
g_clear_pointer (&item->added, g_date_time_unref);
|
||||||
|
g_clear_pointer (&item->modified, g_date_time_unref);
|
||||||
|
g_clear_pointer (&item->visited, g_date_time_unref);
|
||||||
|
|
||||||
g_slice_free (BookmarkItem, item);
|
g_slice_free (BookmarkItem, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
bookmark_item_touch_modified (BookmarkItem *item)
|
||||||
|
{
|
||||||
|
g_clear_pointer (&item->modified, g_date_time_unref);
|
||||||
|
item->modified = g_date_time_new_now_utc ();
|
||||||
|
}
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
bookmark_item_dump (BookmarkItem *item)
|
bookmark_item_dump (BookmarkItem *item)
|
||||||
{
|
{
|
||||||
@ -555,9 +567,9 @@ bookmark_item_dump (BookmarkItem *item)
|
|||||||
|
|
||||||
retval = g_string_sized_new (4096);
|
retval = g_string_sized_new (4096);
|
||||||
|
|
||||||
added = timestamp_to_iso8601 (item->added);
|
added = g_date_time_format_iso8601 (item->added);
|
||||||
modified = timestamp_to_iso8601 (item->modified);
|
modified = g_date_time_format_iso8601 (item->modified);
|
||||||
visited = timestamp_to_iso8601 (item->visited);
|
visited = g_date_time_format_iso8601 (item->visited);
|
||||||
|
|
||||||
escaped_uri = g_markup_escape_text (item->uri, -1);
|
escaped_uri = g_markup_escape_text (item->uri, -1);
|
||||||
|
|
||||||
@ -883,6 +895,7 @@ parse_application_element (GMarkupParseContext *context,
|
|||||||
else
|
else
|
||||||
ai->count = 1;
|
ai->count = 1;
|
||||||
|
|
||||||
|
g_clear_pointer (&ai->stamp, g_date_time_unref);
|
||||||
if (modified != NULL)
|
if (modified != NULL)
|
||||||
{
|
{
|
||||||
if (!timestamp_from_iso8601 (modified, &ai->stamp, error))
|
if (!timestamp_from_iso8601 (modified, &ai->stamp, error))
|
||||||
@ -894,9 +907,9 @@ parse_application_element (GMarkupParseContext *context,
|
|||||||
* it for backward compatibility
|
* it for backward compatibility
|
||||||
*/
|
*/
|
||||||
if (stamp)
|
if (stamp)
|
||||||
ai->stamp = (time_t) atol (stamp);
|
ai->stamp = g_date_time_new_from_unix_utc (atol (stamp));
|
||||||
else
|
else
|
||||||
ai->stamp = time (NULL);
|
ai->stamp = g_date_time_new_now_utc ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1599,25 +1612,11 @@ out:
|
|||||||
* Misc *
|
* Misc *
|
||||||
**************/
|
**************/
|
||||||
|
|
||||||
/* converts a Unix timestamp in a ISO 8601 compliant string; you
|
|
||||||
* should free the returned string.
|
|
||||||
*/
|
|
||||||
static gchar *
|
|
||||||
timestamp_to_iso8601 (time_t timestamp)
|
|
||||||
{
|
|
||||||
GDateTime *dt = g_date_time_new_from_unix_utc (timestamp);
|
|
||||||
gchar *iso8601_string = g_date_time_format_iso8601 (dt);
|
|
||||||
g_date_time_unref (dt);
|
|
||||||
|
|
||||||
return g_steal_pointer (&iso8601_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
timestamp_from_iso8601 (const gchar *iso_date,
|
timestamp_from_iso8601 (const gchar *iso_date,
|
||||||
time_t *out_timestamp,
|
GDateTime **out_date_time,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gint64 time_val;
|
|
||||||
GDateTime *dt = g_date_time_new_from_iso8601 (iso_date, NULL);
|
GDateTime *dt = g_date_time_new_from_iso8601 (iso_date, NULL);
|
||||||
if (dt == NULL)
|
if (dt == NULL)
|
||||||
{
|
{
|
||||||
@ -1626,10 +1625,7 @@ timestamp_from_iso8601 (const gchar *iso_date,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_val = g_date_time_to_unix (dt);
|
*out_date_time = g_steal_pointer (&dt);
|
||||||
g_date_time_unref (dt);
|
|
||||||
|
|
||||||
*out_timestamp = time_val;
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2040,11 +2036,11 @@ g_bookmark_file_add_item (GBookmarkFile *bookmark,
|
|||||||
item->uri,
|
item->uri,
|
||||||
item);
|
item);
|
||||||
|
|
||||||
if (item->added == (time_t) -1)
|
if (item->added == NULL)
|
||||||
item->added = time (NULL);
|
item->added = g_date_time_new_now_utc ();
|
||||||
|
|
||||||
if (item->modified == (time_t) -1)
|
if (item->modified == NULL)
|
||||||
item->modified = time (NULL);
|
item->modified = g_date_time_new_now_utc ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2194,7 +2190,7 @@ g_bookmark_file_set_title (GBookmarkFile *bookmark,
|
|||||||
g_free (item->title);
|
g_free (item->title);
|
||||||
item->title = g_strdup (title);
|
item->title = g_strdup (title);
|
||||||
|
|
||||||
item->modified = time (NULL);
|
bookmark_item_touch_modified (item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2281,7 +2277,7 @@ g_bookmark_file_set_description (GBookmarkFile *bookmark,
|
|||||||
g_free (item->description);
|
g_free (item->description);
|
||||||
item->description = g_strdup (description);
|
item->description = g_strdup (description);
|
||||||
|
|
||||||
item->modified = time (NULL);
|
bookmark_item_touch_modified (item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2362,7 +2358,7 @@ g_bookmark_file_set_mime_type (GBookmarkFile *bookmark,
|
|||||||
g_free (item->metadata->mime_type);
|
g_free (item->metadata->mime_type);
|
||||||
|
|
||||||
item->metadata->mime_type = g_strdup (mime_type);
|
item->metadata->mime_type = g_strdup (mime_type);
|
||||||
item->modified = time (NULL);
|
bookmark_item_touch_modified (item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2448,7 +2444,7 @@ g_bookmark_file_set_is_private (GBookmarkFile *bookmark,
|
|||||||
item->metadata = bookmark_metadata_new ();
|
item->metadata = bookmark_metadata_new ();
|
||||||
|
|
||||||
item->metadata->is_private = (is_private == TRUE);
|
item->metadata->is_private = (is_private == TRUE);
|
||||||
item->modified = time (NULL);
|
bookmark_item_touch_modified (item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2511,16 +2507,41 @@ g_bookmark_file_get_is_private (GBookmarkFile *bookmark,
|
|||||||
* If no bookmark for @uri is found then it is created.
|
* If no bookmark for @uri is found then it is created.
|
||||||
*
|
*
|
||||||
* Since: 2.12
|
* Since: 2.12
|
||||||
|
* Deprecated: 2.66: Use g_bookmark_file_set_added_date_time() instead, as
|
||||||
|
* `time_t` is deprecated due to the year 2038 problem.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
g_bookmark_file_set_added (GBookmarkFile *bookmark,
|
g_bookmark_file_set_added (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
time_t added)
|
time_t added)
|
||||||
|
{
|
||||||
|
GDateTime *added_dt = (added != (time_t) -1) ? g_date_time_new_from_unix_utc (added) : g_date_time_new_now_utc ();
|
||||||
|
g_bookmark_file_set_added_date_time (bookmark, uri, added_dt);
|
||||||
|
g_date_time_unref (added_dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_bookmark_file_set_added_date_time:
|
||||||
|
* @bookmark: a #GBookmarkFile
|
||||||
|
* @uri: a valid URI
|
||||||
|
* @added: a #GDateTime
|
||||||
|
*
|
||||||
|
* Sets the time the bookmark for @uri was added into @bookmark.
|
||||||
|
*
|
||||||
|
* If no bookmark for @uri is found then it is created.
|
||||||
|
*
|
||||||
|
* Since: 2.66
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
g_bookmark_file_set_added_date_time (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
GDateTime *added)
|
||||||
{
|
{
|
||||||
BookmarkItem *item;
|
BookmarkItem *item;
|
||||||
|
|
||||||
g_return_if_fail (bookmark != NULL);
|
g_return_if_fail (bookmark != NULL);
|
||||||
g_return_if_fail (uri != NULL);
|
g_return_if_fail (uri != NULL);
|
||||||
|
g_return_if_fail (added != NULL);
|
||||||
|
|
||||||
item = g_bookmark_file_lookup_item (bookmark, uri);
|
item = g_bookmark_file_lookup_item (bookmark, uri);
|
||||||
if (!item)
|
if (!item)
|
||||||
@ -2529,11 +2550,10 @@ g_bookmark_file_set_added (GBookmarkFile *bookmark,
|
|||||||
g_bookmark_file_add_item (bookmark, item, NULL);
|
g_bookmark_file_add_item (bookmark, item, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (added == (time_t) -1)
|
g_clear_pointer (&item->added, g_date_time_unref);
|
||||||
time (&added);
|
item->added = g_date_time_ref (added);
|
||||||
|
g_clear_pointer (&item->modified, g_date_time_unref);
|
||||||
item->added = added;
|
item->modified = g_date_time_ref (added);
|
||||||
item->modified = added;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2550,25 +2570,52 @@ g_bookmark_file_set_added (GBookmarkFile *bookmark,
|
|||||||
* Returns: a timestamp
|
* Returns: a timestamp
|
||||||
*
|
*
|
||||||
* Since: 2.12
|
* Since: 2.12
|
||||||
|
* Deprecated: 2.66: Use g_bookmark_file_get_added_date_time() instead, as
|
||||||
|
* `time_t` is deprecated due to the year 2038 problem.
|
||||||
*/
|
*/
|
||||||
time_t
|
time_t
|
||||||
g_bookmark_file_get_added (GBookmarkFile *bookmark,
|
g_bookmark_file_get_added (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
GError **error)
|
GError **error)
|
||||||
|
{
|
||||||
|
GDateTime *added = g_bookmark_file_get_added_date_time (bookmark, uri, error);
|
||||||
|
return (added != NULL) ? g_date_time_to_unix (added) : (time_t) -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_bookmark_file_get_added_date_time:
|
||||||
|
* @bookmark: a #GBookmarkFile
|
||||||
|
* @uri: a valid URI
|
||||||
|
* @error: return location for a #GError, or %NULL
|
||||||
|
*
|
||||||
|
* Gets the time the bookmark for @uri was added to @bookmark
|
||||||
|
*
|
||||||
|
* In the event the URI cannot be found, %NULL is returned and
|
||||||
|
* @error is set to #G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): a #GDateTime
|
||||||
|
*
|
||||||
|
* Since: 2.66
|
||||||
|
*/
|
||||||
|
GDateTime *
|
||||||
|
g_bookmark_file_get_added_date_time (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
BookmarkItem *item;
|
BookmarkItem *item;
|
||||||
|
|
||||||
g_return_val_if_fail (bookmark != NULL, (time_t) -1);
|
g_return_val_if_fail (bookmark != NULL, NULL);
|
||||||
g_return_val_if_fail (uri != NULL, (time_t) -1);
|
g_return_val_if_fail (uri != NULL, NULL);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
item = g_bookmark_file_lookup_item (bookmark, uri);
|
item = g_bookmark_file_lookup_item (bookmark, uri);
|
||||||
if (!item)
|
if (!item)
|
||||||
{
|
{
|
||||||
g_set_error (error, G_BOOKMARK_FILE_ERROR,
|
g_set_error (error, G_BOOKMARK_FILE_ERROR,
|
||||||
G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND,
|
G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND,
|
||||||
_("No bookmark found for URI “%s”"),
|
_("No bookmark found for URI “%s”"),
|
||||||
uri);
|
uri);
|
||||||
return (time_t) -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return item->added;
|
return item->added;
|
||||||
@ -2587,19 +2634,49 @@ g_bookmark_file_get_added (GBookmarkFile *bookmark,
|
|||||||
* The "modified" time should only be set when the bookmark's meta-data
|
* The "modified" time should only be set when the bookmark's meta-data
|
||||||
* was actually changed. Every function of #GBookmarkFile that
|
* was actually changed. Every function of #GBookmarkFile that
|
||||||
* modifies a bookmark also changes the modification time, except for
|
* modifies a bookmark also changes the modification time, except for
|
||||||
* g_bookmark_file_set_visited().
|
* g_bookmark_file_set_visited_date_time().
|
||||||
*
|
*
|
||||||
* Since: 2.12
|
* Since: 2.12
|
||||||
|
* Deprecated: 2.66: Use g_bookmark_file_set_modified_date_time() instead, as
|
||||||
|
* `time_t` is deprecated due to the year 2038 problem.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
g_bookmark_file_set_modified (GBookmarkFile *bookmark,
|
g_bookmark_file_set_modified (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
time_t modified)
|
time_t modified)
|
||||||
|
{
|
||||||
|
GDateTime *modified_dt = (modified != (time_t) -1) ? g_date_time_new_from_unix_utc (modified) : g_date_time_new_now_utc ();
|
||||||
|
g_bookmark_file_set_modified_date_time (bookmark, uri, modified_dt);
|
||||||
|
g_date_time_unref (modified_dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_bookmark_file_set_modified_date_time:
|
||||||
|
* @bookmark: a #GBookmarkFile
|
||||||
|
* @uri: a valid URI
|
||||||
|
* @modified: a #GDateTime
|
||||||
|
*
|
||||||
|
* Sets the last time the bookmark for @uri was last modified.
|
||||||
|
*
|
||||||
|
* If no bookmark for @uri is found then it is created.
|
||||||
|
*
|
||||||
|
* The "modified" time should only be set when the bookmark's meta-data
|
||||||
|
* was actually changed. Every function of #GBookmarkFile that
|
||||||
|
* modifies a bookmark also changes the modification time, except for
|
||||||
|
* g_bookmark_file_set_visited_date_time().
|
||||||
|
*
|
||||||
|
* Since: 2.66
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
g_bookmark_file_set_modified_date_time (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
GDateTime *modified)
|
||||||
{
|
{
|
||||||
BookmarkItem *item;
|
BookmarkItem *item;
|
||||||
|
|
||||||
g_return_if_fail (bookmark != NULL);
|
g_return_if_fail (bookmark != NULL);
|
||||||
g_return_if_fail (uri != NULL);
|
g_return_if_fail (uri != NULL);
|
||||||
|
g_return_if_fail (modified != NULL);
|
||||||
|
|
||||||
item = g_bookmark_file_lookup_item (bookmark, uri);
|
item = g_bookmark_file_lookup_item (bookmark, uri);
|
||||||
if (!item)
|
if (!item)
|
||||||
@ -2608,10 +2685,8 @@ g_bookmark_file_set_modified (GBookmarkFile *bookmark,
|
|||||||
g_bookmark_file_add_item (bookmark, item, NULL);
|
g_bookmark_file_add_item (bookmark, item, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modified == (time_t) -1)
|
g_clear_pointer (&item->modified, g_date_time_unref);
|
||||||
time (&modified);
|
item->modified = g_date_time_ref (modified);
|
||||||
|
|
||||||
item->modified = modified;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2628,25 +2703,52 @@ g_bookmark_file_set_modified (GBookmarkFile *bookmark,
|
|||||||
* Returns: a timestamp
|
* Returns: a timestamp
|
||||||
*
|
*
|
||||||
* Since: 2.12
|
* Since: 2.12
|
||||||
|
* Deprecated: 2.66: Use g_bookmark_file_get_modified_date_time() instead, as
|
||||||
|
* `time_t` is deprecated due to the year 2038 problem.
|
||||||
*/
|
*/
|
||||||
time_t
|
time_t
|
||||||
g_bookmark_file_get_modified (GBookmarkFile *bookmark,
|
g_bookmark_file_get_modified (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
GError **error)
|
GError **error)
|
||||||
|
{
|
||||||
|
GDateTime *modified = g_bookmark_file_get_modified_date_time (bookmark, uri, error);
|
||||||
|
return (modified != NULL) ? g_date_time_to_unix (modified) : (time_t) -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_bookmark_file_get_modified_date_time:
|
||||||
|
* @bookmark: a #GBookmarkFile
|
||||||
|
* @uri: a valid URI
|
||||||
|
* @error: return location for a #GError, or %NULL
|
||||||
|
*
|
||||||
|
* Gets the time when the bookmark for @uri was last modified.
|
||||||
|
*
|
||||||
|
* In the event the URI cannot be found, %NULL is returned and
|
||||||
|
* @error is set to #G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): a #GDateTime
|
||||||
|
*
|
||||||
|
* Since: 2.66
|
||||||
|
*/
|
||||||
|
GDateTime *
|
||||||
|
g_bookmark_file_get_modified_date_time (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
BookmarkItem *item;
|
BookmarkItem *item;
|
||||||
|
|
||||||
g_return_val_if_fail (bookmark != NULL, (time_t) -1);
|
g_return_val_if_fail (bookmark != NULL, NULL);
|
||||||
g_return_val_if_fail (uri != NULL, (time_t) -1);
|
g_return_val_if_fail (uri != NULL, NULL);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
item = g_bookmark_file_lookup_item (bookmark, uri);
|
item = g_bookmark_file_lookup_item (bookmark, uri);
|
||||||
if (!item)
|
if (!item)
|
||||||
{
|
{
|
||||||
g_set_error (error, G_BOOKMARK_FILE_ERROR,
|
g_set_error (error, G_BOOKMARK_FILE_ERROR,
|
||||||
G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND,
|
G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND,
|
||||||
_("No bookmark found for URI “%s”"),
|
_("No bookmark found for URI “%s”"),
|
||||||
uri);
|
uri);
|
||||||
return (time_t) -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return item->modified;
|
return item->modified;
|
||||||
@ -2663,22 +2765,53 @@ g_bookmark_file_get_modified (GBookmarkFile *bookmark,
|
|||||||
* If no bookmark for @uri is found then it is created.
|
* If no bookmark for @uri is found then it is created.
|
||||||
*
|
*
|
||||||
* The "visited" time should only be set if the bookmark was launched,
|
* The "visited" time should only be set if the bookmark was launched,
|
||||||
* either using the command line retrieved by g_bookmark_file_get_app_info()
|
* either using the command line retrieved by g_bookmark_file_get_application_info()
|
||||||
* or by the default application for the bookmark's MIME type, retrieved
|
* or by the default application for the bookmark's MIME type, retrieved
|
||||||
* using g_bookmark_file_get_mime_type(). Changing the "visited" time
|
* using g_bookmark_file_get_mime_type(). Changing the "visited" time
|
||||||
* does not affect the "modified" time.
|
* does not affect the "modified" time.
|
||||||
*
|
*
|
||||||
* Since: 2.12
|
* Since: 2.12
|
||||||
|
* Deprecated: 2.66: Use g_bookmark_file_set_visited_date_time() instead, as
|
||||||
|
* `time_t` is deprecated due to the year 2038 problem.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
g_bookmark_file_set_visited (GBookmarkFile *bookmark,
|
g_bookmark_file_set_visited (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
time_t visited)
|
time_t visited)
|
||||||
|
{
|
||||||
|
GDateTime *visited_dt = (visited != (time_t) -1) ? g_date_time_new_from_unix_utc (visited) : g_date_time_new_now_utc ();
|
||||||
|
g_bookmark_file_set_visited_date_time (bookmark, uri, visited_dt);
|
||||||
|
g_date_time_unref (visited_dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_bookmark_file_set_visited_date_time:
|
||||||
|
* @bookmark: a #GBookmarkFile
|
||||||
|
* @uri: a valid URI
|
||||||
|
* @visited: a #GDateTime
|
||||||
|
*
|
||||||
|
* Sets the time the bookmark for @uri was last visited.
|
||||||
|
*
|
||||||
|
* If no bookmark for @uri is found then it is created.
|
||||||
|
*
|
||||||
|
* The "visited" time should only be set if the bookmark was launched,
|
||||||
|
* either using the command line retrieved by g_bookmark_file_get_application_info()
|
||||||
|
* or by the default application for the bookmark's MIME type, retrieved
|
||||||
|
* using g_bookmark_file_get_mime_type(). Changing the "visited" time
|
||||||
|
* does not affect the "modified" time.
|
||||||
|
*
|
||||||
|
* Since: 2.66
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
g_bookmark_file_set_visited_date_time (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
GDateTime *visited)
|
||||||
{
|
{
|
||||||
BookmarkItem *item;
|
BookmarkItem *item;
|
||||||
|
|
||||||
g_return_if_fail (bookmark != NULL);
|
g_return_if_fail (bookmark != NULL);
|
||||||
g_return_if_fail (uri != NULL);
|
g_return_if_fail (uri != NULL);
|
||||||
|
g_return_if_fail (visited != NULL);
|
||||||
|
|
||||||
item = g_bookmark_file_lookup_item (bookmark, uri);
|
item = g_bookmark_file_lookup_item (bookmark, uri);
|
||||||
if (!item)
|
if (!item)
|
||||||
@ -2687,10 +2820,8 @@ g_bookmark_file_set_visited (GBookmarkFile *bookmark,
|
|||||||
g_bookmark_file_add_item (bookmark, item, NULL);
|
g_bookmark_file_add_item (bookmark, item, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (visited == (time_t) -1)
|
g_clear_pointer (&item->visited, g_date_time_unref);
|
||||||
time (&visited);
|
item->visited = g_date_time_ref (visited);
|
||||||
|
|
||||||
item->visited = visited;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2707,25 +2838,52 @@ g_bookmark_file_set_visited (GBookmarkFile *bookmark,
|
|||||||
* Returns: a timestamp.
|
* Returns: a timestamp.
|
||||||
*
|
*
|
||||||
* Since: 2.12
|
* Since: 2.12
|
||||||
|
* Deprecated: 2.66: Use g_bookmark_file_get_visited_date_time() instead, as
|
||||||
|
* `time_t` is deprecated due to the year 2038 problem.
|
||||||
*/
|
*/
|
||||||
time_t
|
time_t
|
||||||
g_bookmark_file_get_visited (GBookmarkFile *bookmark,
|
g_bookmark_file_get_visited (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
GError **error)
|
GError **error)
|
||||||
|
{
|
||||||
|
GDateTime *visited = g_bookmark_file_get_visited_date_time (bookmark, uri, error);
|
||||||
|
return (visited != NULL) ? g_date_time_to_unix (visited) : (time_t) -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_bookmark_file_get_visited_date_time:
|
||||||
|
* @bookmark: a #GBookmarkFile
|
||||||
|
* @uri: a valid URI
|
||||||
|
* @error: return location for a #GError, or %NULL
|
||||||
|
*
|
||||||
|
* Gets the time the bookmark for @uri was last visited.
|
||||||
|
*
|
||||||
|
* In the event the URI cannot be found, %NULL is returned and
|
||||||
|
* @error is set to #G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): a #GDateTime
|
||||||
|
*
|
||||||
|
* Since: 2.66
|
||||||
|
*/
|
||||||
|
GDateTime *
|
||||||
|
g_bookmark_file_get_visited_date_time (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
BookmarkItem *item;
|
BookmarkItem *item;
|
||||||
|
|
||||||
g_return_val_if_fail (bookmark != NULL, (time_t) -1);
|
g_return_val_if_fail (bookmark != NULL, NULL);
|
||||||
g_return_val_if_fail (uri != NULL, (time_t) -1);
|
g_return_val_if_fail (uri != NULL, NULL);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
item = g_bookmark_file_lookup_item (bookmark, uri);
|
item = g_bookmark_file_lookup_item (bookmark, uri);
|
||||||
if (!item)
|
if (!item)
|
||||||
{
|
{
|
||||||
g_set_error (error, G_BOOKMARK_FILE_ERROR,
|
g_set_error (error, G_BOOKMARK_FILE_ERROR,
|
||||||
G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND,
|
G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND,
|
||||||
_("No bookmark found for URI “%s”"),
|
_("No bookmark found for URI “%s”"),
|
||||||
uri);
|
uri);
|
||||||
return (time_t) -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return item->visited;
|
return item->visited;
|
||||||
@ -2822,7 +2980,7 @@ g_bookmark_file_add_group (GBookmarkFile *bookmark,
|
|||||||
item->metadata->groups = g_list_prepend (item->metadata->groups,
|
item->metadata->groups = g_list_prepend (item->metadata->groups,
|
||||||
g_strdup (group));
|
g_strdup (group));
|
||||||
|
|
||||||
item->modified = time (NULL);
|
bookmark_item_touch_modified (item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2884,7 +3042,7 @@ g_bookmark_file_remove_group (GBookmarkFile *bookmark,
|
|||||||
g_free (l->data);
|
g_free (l->data);
|
||||||
g_list_free_1 (l);
|
g_list_free_1 (l);
|
||||||
|
|
||||||
item->modified = time (NULL);
|
bookmark_item_touch_modified (item);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -2941,7 +3099,7 @@ g_bookmark_file_set_groups (GBookmarkFile *bookmark,
|
|||||||
g_strdup (groups[i]));
|
g_strdup (groups[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
item->modified = time (NULL);
|
bookmark_item_touch_modified (item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3057,6 +3215,7 @@ g_bookmark_file_add_application (GBookmarkFile *bookmark,
|
|||||||
{
|
{
|
||||||
BookmarkItem *item;
|
BookmarkItem *item;
|
||||||
gchar *app_name, *app_exec;
|
gchar *app_name, *app_exec;
|
||||||
|
GDateTime *stamp;
|
||||||
|
|
||||||
g_return_if_fail (bookmark != NULL);
|
g_return_if_fail (bookmark != NULL);
|
||||||
g_return_if_fail (uri != NULL);
|
g_return_if_fail (uri != NULL);
|
||||||
@ -3078,13 +3237,16 @@ g_bookmark_file_add_application (GBookmarkFile *bookmark,
|
|||||||
else
|
else
|
||||||
app_exec = g_strjoin (" ", g_get_prgname(), "%u", NULL);
|
app_exec = g_strjoin (" ", g_get_prgname(), "%u", NULL);
|
||||||
|
|
||||||
g_bookmark_file_set_app_info (bookmark, uri,
|
stamp = g_date_time_new_now_utc ();
|
||||||
app_name,
|
|
||||||
app_exec,
|
|
||||||
-1,
|
|
||||||
(time_t) -1,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
|
g_bookmark_file_set_application_info (bookmark, uri,
|
||||||
|
app_name,
|
||||||
|
app_exec,
|
||||||
|
-1,
|
||||||
|
stamp,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
g_date_time_unref (stamp);
|
||||||
g_free (app_exec);
|
g_free (app_exec);
|
||||||
g_free (app_name);
|
g_free (app_name);
|
||||||
}
|
}
|
||||||
@ -3123,12 +3285,12 @@ g_bookmark_file_remove_application (GBookmarkFile *bookmark,
|
|||||||
g_return_val_if_fail (name != NULL, FALSE);
|
g_return_val_if_fail (name != NULL, FALSE);
|
||||||
|
|
||||||
set_error = NULL;
|
set_error = NULL;
|
||||||
retval = g_bookmark_file_set_app_info (bookmark, uri,
|
retval = g_bookmark_file_set_application_info (bookmark, uri,
|
||||||
name,
|
name,
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
(time_t) -1,
|
NULL,
|
||||||
&set_error);
|
&set_error);
|
||||||
if (set_error)
|
if (set_error)
|
||||||
{
|
{
|
||||||
g_propagate_error (error, set_error);
|
g_propagate_error (error, set_error);
|
||||||
@ -3204,7 +3366,7 @@ g_bookmark_file_has_application (GBookmarkFile *bookmark,
|
|||||||
* be expanded as the local file name retrieved from the bookmark's
|
* be expanded as the local file name retrieved from the bookmark's
|
||||||
* URI; "\%u", which will be expanded as the bookmark's URI.
|
* URI; "\%u", which will be expanded as the bookmark's URI.
|
||||||
* The expansion is done automatically when retrieving the stored
|
* The expansion is done automatically when retrieving the stored
|
||||||
* command line using the g_bookmark_file_get_app_info() function.
|
* command line using the g_bookmark_file_get_application_info() function.
|
||||||
* @count is the number of times the application has registered the
|
* @count is the number of times the application has registered the
|
||||||
* bookmark; if is < 0, the current registration count will be increased
|
* bookmark; if is < 0, the current registration count will be increased
|
||||||
* by one, if is 0, the application with @name will be removed from
|
* by one, if is 0, the application with @name will be removed from
|
||||||
@ -3224,6 +3386,8 @@ g_bookmark_file_has_application (GBookmarkFile *bookmark,
|
|||||||
* changed.
|
* changed.
|
||||||
*
|
*
|
||||||
* Since: 2.12
|
* Since: 2.12
|
||||||
|
* Deprecated: 2.66: Use g_bookmark_file_set_application_info() instead, as
|
||||||
|
* `time_t` is deprecated due to the year 2038 problem.
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
g_bookmark_file_set_app_info (GBookmarkFile *bookmark,
|
g_bookmark_file_set_app_info (GBookmarkFile *bookmark,
|
||||||
@ -3233,6 +3397,67 @@ g_bookmark_file_set_app_info (GBookmarkFile *bookmark,
|
|||||||
gint count,
|
gint count,
|
||||||
time_t stamp,
|
time_t stamp,
|
||||||
GError **error)
|
GError **error)
|
||||||
|
{
|
||||||
|
GDateTime *stamp_dt = (stamp != (time_t) -1) ? g_date_time_new_from_unix_utc (stamp) : g_date_time_new_now_utc ();
|
||||||
|
gboolean retval;
|
||||||
|
retval = g_bookmark_file_set_application_info (bookmark, uri, name, exec, count,
|
||||||
|
stamp_dt, error);
|
||||||
|
g_date_time_unref (stamp_dt);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_bookmark_file_set_application_info:
|
||||||
|
* @bookmark: a #GBookmarkFile
|
||||||
|
* @uri: a valid URI
|
||||||
|
* @name: an application's name
|
||||||
|
* @exec: an application's command line
|
||||||
|
* @count: the number of registrations done for this application
|
||||||
|
* @stamp: (nullable): the time of the last registration for this application,
|
||||||
|
* which may be %NULL if @count is 0
|
||||||
|
* @error: return location for a #GError or %NULL
|
||||||
|
*
|
||||||
|
* Sets the meta-data of application @name inside the list of
|
||||||
|
* applications that have registered a bookmark for @uri inside
|
||||||
|
* @bookmark.
|
||||||
|
*
|
||||||
|
* You should rarely use this function; use g_bookmark_file_add_application()
|
||||||
|
* and g_bookmark_file_remove_application() instead.
|
||||||
|
*
|
||||||
|
* @name can be any UTF-8 encoded string used to identify an
|
||||||
|
* application.
|
||||||
|
* @exec can have one of these two modifiers: "\%f", which will
|
||||||
|
* be expanded as the local file name retrieved from the bookmark's
|
||||||
|
* URI; "\%u", which will be expanded as the bookmark's URI.
|
||||||
|
* The expansion is done automatically when retrieving the stored
|
||||||
|
* command line using the g_bookmark_file_get_application_info() function.
|
||||||
|
* @count is the number of times the application has registered the
|
||||||
|
* bookmark; if is < 0, the current registration count will be increased
|
||||||
|
* by one, if is 0, the application with @name will be removed from
|
||||||
|
* the list of registered applications.
|
||||||
|
* @stamp is the Unix time of the last registration.
|
||||||
|
*
|
||||||
|
* If you try to remove an application by setting its registration count to
|
||||||
|
* zero, and no bookmark for @uri is found, %FALSE is returned and
|
||||||
|
* @error is set to #G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND; similarly,
|
||||||
|
* in the event that no application @name has registered a bookmark
|
||||||
|
* for @uri, %FALSE is returned and error is set to
|
||||||
|
* #G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED. Otherwise, if no bookmark
|
||||||
|
* for @uri is found, one is created.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if the application's meta-data was successfully
|
||||||
|
* changed.
|
||||||
|
*
|
||||||
|
* Since: 2.66
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
g_bookmark_file_set_application_info (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
const char *name,
|
||||||
|
const char *exec,
|
||||||
|
int count,
|
||||||
|
GDateTime *stamp,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
BookmarkItem *item;
|
BookmarkItem *item;
|
||||||
BookmarkAppInfo *ai;
|
BookmarkAppInfo *ai;
|
||||||
@ -3241,6 +3466,8 @@ g_bookmark_file_set_app_info (GBookmarkFile *bookmark,
|
|||||||
g_return_val_if_fail (uri != NULL, FALSE);
|
g_return_val_if_fail (uri != NULL, FALSE);
|
||||||
g_return_val_if_fail (name != NULL, FALSE);
|
g_return_val_if_fail (name != NULL, FALSE);
|
||||||
g_return_val_if_fail (exec != NULL, FALSE);
|
g_return_val_if_fail (exec != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (count == 0 || stamp != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||||
|
|
||||||
item = g_bookmark_file_lookup_item (bookmark, uri);
|
item = g_bookmark_file_lookup_item (bookmark, uri);
|
||||||
if (!item)
|
if (!item)
|
||||||
@ -3290,7 +3517,7 @@ g_bookmark_file_set_app_info (GBookmarkFile *bookmark,
|
|||||||
g_hash_table_remove (item->metadata->apps_by_name, ai->name);
|
g_hash_table_remove (item->metadata->apps_by_name, ai->name);
|
||||||
bookmark_app_info_free (ai);
|
bookmark_app_info_free (ai);
|
||||||
|
|
||||||
item->modified = time (NULL);
|
bookmark_item_touch_modified (item);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -3299,10 +3526,8 @@ g_bookmark_file_set_app_info (GBookmarkFile *bookmark,
|
|||||||
else
|
else
|
||||||
ai->count += 1;
|
ai->count += 1;
|
||||||
|
|
||||||
if (stamp != (time_t) -1)
|
g_clear_pointer (&ai->stamp, g_date_time_unref);
|
||||||
ai->stamp = stamp;
|
ai->stamp = g_date_time_ref (stamp);
|
||||||
else
|
|
||||||
ai->stamp = time (NULL);
|
|
||||||
|
|
||||||
if (exec && exec[0] != '\0')
|
if (exec && exec[0] != '\0')
|
||||||
{
|
{
|
||||||
@ -3310,7 +3535,7 @@ g_bookmark_file_set_app_info (GBookmarkFile *bookmark,
|
|||||||
ai->exec = g_shell_quote (exec);
|
ai->exec = g_shell_quote (exec);
|
||||||
}
|
}
|
||||||
|
|
||||||
item->modified = time (NULL);
|
bookmark_item_touch_modified (item);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -3379,7 +3604,7 @@ expand_exec_line (const gchar *exec_fmt,
|
|||||||
* @error: return location for a #GError, or %NULL
|
* @error: return location for a #GError, or %NULL
|
||||||
*
|
*
|
||||||
* Gets the registration information of @app_name for the bookmark for
|
* Gets the registration information of @app_name for the bookmark for
|
||||||
* @uri. See g_bookmark_file_set_app_info() for more information about
|
* @uri. See g_bookmark_file_set_application_info() for more information about
|
||||||
* the returned data.
|
* the returned data.
|
||||||
*
|
*
|
||||||
* The string returned in @app_exec must be freed.
|
* The string returned in @app_exec must be freed.
|
||||||
@ -3395,6 +3620,8 @@ expand_exec_line (const gchar *exec_fmt,
|
|||||||
* Returns: %TRUE on success.
|
* Returns: %TRUE on success.
|
||||||
*
|
*
|
||||||
* Since: 2.12
|
* Since: 2.12
|
||||||
|
* Deprecated: 2.66: Use g_bookmark_file_get_application_info() instead, as
|
||||||
|
* `time_t` is deprecated due to the year 2038 problem.
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
g_bookmark_file_get_app_info (GBookmarkFile *bookmark,
|
g_bookmark_file_get_app_info (GBookmarkFile *bookmark,
|
||||||
@ -3404,6 +3631,56 @@ g_bookmark_file_get_app_info (GBookmarkFile *bookmark,
|
|||||||
guint *count,
|
guint *count,
|
||||||
time_t *stamp,
|
time_t *stamp,
|
||||||
GError **error)
|
GError **error)
|
||||||
|
{
|
||||||
|
GDateTime *stamp_dt = NULL;
|
||||||
|
gboolean retval;
|
||||||
|
|
||||||
|
retval = g_bookmark_file_get_application_info (bookmark, uri, name, exec, count, &stamp_dt, error);
|
||||||
|
if (!retval)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (stamp != NULL)
|
||||||
|
*stamp = g_date_time_to_unix (stamp_dt);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_bookmark_file_get_application_info:
|
||||||
|
* @bookmark: a #GBookmarkFile
|
||||||
|
* @uri: a valid URI
|
||||||
|
* @name: an application's name
|
||||||
|
* @exec: (out) (optional): return location for the command line of the application, or %NULL
|
||||||
|
* @count: (out) (optional): return location for the registration count, or %NULL
|
||||||
|
* @stamp: (out) (optional) (transfer none): return location for the last registration time, or %NULL
|
||||||
|
* @error: return location for a #GError, or %NULL
|
||||||
|
*
|
||||||
|
* Gets the registration information of @app_name for the bookmark for
|
||||||
|
* @uri. See g_bookmark_file_set_application_info() for more information about
|
||||||
|
* the returned data.
|
||||||
|
*
|
||||||
|
* The string returned in @app_exec must be freed.
|
||||||
|
*
|
||||||
|
* In the event the URI cannot be found, %FALSE is returned and
|
||||||
|
* @error is set to #G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND. In the
|
||||||
|
* event that no application with name @app_name has registered a bookmark
|
||||||
|
* for @uri, %FALSE is returned and error is set to
|
||||||
|
* #G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED. In the event that unquoting
|
||||||
|
* the command line fails, an error of the #G_SHELL_ERROR domain is
|
||||||
|
* set and %FALSE is returned.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE on success.
|
||||||
|
*
|
||||||
|
* Since: 2.66
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
g_bookmark_file_get_application_info (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
const char *name,
|
||||||
|
char **exec,
|
||||||
|
unsigned int *count,
|
||||||
|
GDateTime **stamp,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
BookmarkItem *item;
|
BookmarkItem *item;
|
||||||
BookmarkAppInfo *ai;
|
BookmarkAppInfo *ai;
|
||||||
@ -3411,6 +3688,7 @@ g_bookmark_file_get_app_info (GBookmarkFile *bookmark,
|
|||||||
g_return_val_if_fail (bookmark != NULL, FALSE);
|
g_return_val_if_fail (bookmark != NULL, FALSE);
|
||||||
g_return_val_if_fail (uri != NULL, FALSE);
|
g_return_val_if_fail (uri != NULL, FALSE);
|
||||||
g_return_val_if_fail (name != NULL, FALSE);
|
g_return_val_if_fail (name != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||||
|
|
||||||
item = g_bookmark_file_lookup_item (bookmark, uri);
|
item = g_bookmark_file_lookup_item (bookmark, uri);
|
||||||
if (!item)
|
if (!item)
|
||||||
@ -3615,7 +3893,7 @@ g_bookmark_file_move_item (GBookmarkFile *bookmark,
|
|||||||
|
|
||||||
g_free (item->uri);
|
g_free (item->uri);
|
||||||
item->uri = g_strdup (new_uri);
|
item->uri = g_strdup (new_uri);
|
||||||
item->modified = time (NULL);
|
bookmark_item_touch_modified (item);
|
||||||
|
|
||||||
g_hash_table_replace (bookmark->items_by_uri, item->uri, item);
|
g_hash_table_replace (bookmark->items_by_uri, item->uri, item);
|
||||||
|
|
||||||
@ -3676,7 +3954,7 @@ g_bookmark_file_set_icon (GBookmarkFile *bookmark,
|
|||||||
else
|
else
|
||||||
item->metadata->icon_mime = g_strdup ("application/octet-stream");
|
item->metadata->icon_mime = g_strdup ("application/octet-stream");
|
||||||
|
|
||||||
item->modified = time (NULL);
|
bookmark_item_touch_modified (item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#error "Only <glib.h> can be included directly."
|
#error "Only <glib.h> can be included directly."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <glib/gdatetime.h>
|
||||||
#include <glib/gerror.h>
|
#include <glib/gerror.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@ -162,7 +163,7 @@ gchar ** g_bookmark_file_get_applications (GBookmarkFile *bookmark,
|
|||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
gsize *length,
|
gsize *length,
|
||||||
GError **error);
|
GError **error);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_set_application_info)
|
||||||
gboolean g_bookmark_file_set_app_info (GBookmarkFile *bookmark,
|
gboolean g_bookmark_file_set_app_info (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
const gchar *name,
|
const gchar *name,
|
||||||
@ -170,7 +171,15 @@ gboolean g_bookmark_file_set_app_info (GBookmarkFile *bookmark,
|
|||||||
gint count,
|
gint count,
|
||||||
time_t stamp,
|
time_t stamp,
|
||||||
GError **error);
|
GError **error);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_2_66
|
||||||
|
gboolean g_bookmark_file_set_application_info (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
const char *name,
|
||||||
|
const char *exec,
|
||||||
|
int count,
|
||||||
|
GDateTime *stamp,
|
||||||
|
GError **error);
|
||||||
|
GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_get_application_info)
|
||||||
gboolean g_bookmark_file_get_app_info (GBookmarkFile *bookmark,
|
gboolean g_bookmark_file_get_app_info (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
const gchar *name,
|
const gchar *name,
|
||||||
@ -178,6 +187,14 @@ gboolean g_bookmark_file_get_app_info (GBookmarkFile *bookmark,
|
|||||||
guint *count,
|
guint *count,
|
||||||
time_t *stamp,
|
time_t *stamp,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
GLIB_AVAILABLE_IN_2_66
|
||||||
|
gboolean g_bookmark_file_get_application_info (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
const char *name,
|
||||||
|
char **exec,
|
||||||
|
unsigned int *count,
|
||||||
|
GDateTime **stamp,
|
||||||
|
GError **error);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_ALL
|
||||||
void g_bookmark_file_set_is_private (GBookmarkFile *bookmark,
|
void g_bookmark_file_set_is_private (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
@ -197,30 +214,54 @@ gboolean g_bookmark_file_get_icon (GBookmarkFile *bookmark,
|
|||||||
gchar **href,
|
gchar **href,
|
||||||
gchar **mime_type,
|
gchar **mime_type,
|
||||||
GError **error);
|
GError **error);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_set_added_date_time)
|
||||||
void g_bookmark_file_set_added (GBookmarkFile *bookmark,
|
void g_bookmark_file_set_added (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
time_t added);
|
time_t added);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_2_66
|
||||||
|
void g_bookmark_file_set_added_date_time (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
GDateTime *added);
|
||||||
|
GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_get_added_date_time)
|
||||||
time_t g_bookmark_file_get_added (GBookmarkFile *bookmark,
|
time_t g_bookmark_file_get_added (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
GError **error);
|
GError **error);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_2_66
|
||||||
|
GDateTime *g_bookmark_file_get_added_date_time (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
GError **error);
|
||||||
|
GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_set_modified_date_time)
|
||||||
void g_bookmark_file_set_modified (GBookmarkFile *bookmark,
|
void g_bookmark_file_set_modified (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
time_t modified);
|
time_t modified);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_2_66
|
||||||
|
void g_bookmark_file_set_modified_date_time (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
GDateTime *modified);
|
||||||
|
GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_get_modified_date_time)
|
||||||
time_t g_bookmark_file_get_modified (GBookmarkFile *bookmark,
|
time_t g_bookmark_file_get_modified (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
GError **error);
|
GError **error);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_2_66
|
||||||
|
GDateTime *g_bookmark_file_get_modified_date_time (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
GError **error);
|
||||||
|
GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_set_visited_date_time)
|
||||||
void g_bookmark_file_set_visited (GBookmarkFile *bookmark,
|
void g_bookmark_file_set_visited (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
time_t visited);
|
time_t visited);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_2_66
|
||||||
|
void g_bookmark_file_set_visited_date_time (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
GDateTime *visited);
|
||||||
|
GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_get_visited_date_time)
|
||||||
time_t g_bookmark_file_get_visited (GBookmarkFile *bookmark,
|
time_t g_bookmark_file_get_visited (GBookmarkFile *bookmark,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
GLIB_AVAILABLE_IN_2_66
|
||||||
|
GDateTime *g_bookmark_file_get_visited_date_time (GBookmarkFile *bookmark,
|
||||||
|
const char *uri,
|
||||||
|
GError **error);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_ALL
|
||||||
gboolean g_bookmark_file_has_item (GBookmarkFile *bookmark,
|
gboolean g_bookmark_file_has_item (GBookmarkFile *bookmark,
|
||||||
const gchar *uri);
|
const gchar *uri);
|
||||||
|
@ -127,7 +127,7 @@ test_misc (void)
|
|||||||
gboolean res;
|
gboolean res;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gchar *s;
|
gchar *s;
|
||||||
time_t before, after, t;
|
GDateTime *before, *after, *t;
|
||||||
gchar *cmd, *exec;
|
gchar *cmd, *exec;
|
||||||
guint count;
|
guint count;
|
||||||
|
|
||||||
@ -196,47 +196,55 @@ test_misc (void)
|
|||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
|
|
||||||
time (&before);
|
before = g_date_time_new_now_utc ();
|
||||||
|
|
||||||
g_bookmark_file_set_added (bookmark,
|
g_bookmark_file_set_added_date_time (bookmark,
|
||||||
"file:///tmp/schedule3.ps",
|
"file:///tmp/schedule3.ps",
|
||||||
(time_t)-1);
|
before);
|
||||||
t = g_bookmark_file_get_added (bookmark,
|
t = g_bookmark_file_get_added_date_time (bookmark,
|
||||||
"file:///tmp/schedule3.ps",
|
"file:///tmp/schedule3.ps",
|
||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
time (&after);
|
after = g_date_time_new_now_utc ();
|
||||||
g_assert_cmpint (before, <=, t);
|
g_assert_cmpint (g_date_time_compare (before, t), <=, 0);
|
||||||
g_assert_cmpint (t, <=, after);
|
g_assert_cmpint (g_date_time_compare (t, after), <=, 0);
|
||||||
|
|
||||||
time (&before);
|
g_date_time_unref (after);
|
||||||
|
g_date_time_unref (before);
|
||||||
|
|
||||||
g_bookmark_file_set_modified (bookmark,
|
before = g_date_time_new_now_utc ();
|
||||||
"file:///tmp/schedule4.ps",
|
|
||||||
(time_t)-1);
|
g_bookmark_file_set_modified_date_time (bookmark,
|
||||||
t = g_bookmark_file_get_modified (bookmark,
|
"file:///tmp/schedule4.ps",
|
||||||
"file:///tmp/schedule4.ps",
|
before);
|
||||||
&error);
|
t = g_bookmark_file_get_modified_date_time (bookmark,
|
||||||
|
"file:///tmp/schedule4.ps",
|
||||||
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
time (&after);
|
after = g_date_time_new_now_utc ();
|
||||||
g_assert_cmpint (before, <=, t);
|
g_assert_cmpint (g_date_time_compare (before, t), <=, 0);
|
||||||
g_assert_cmpint (t, <=, after);
|
g_assert_cmpint (g_date_time_compare (t, after), <=, 0);
|
||||||
|
|
||||||
time (&before);
|
g_date_time_unref (after);
|
||||||
|
g_date_time_unref (before);
|
||||||
|
|
||||||
g_bookmark_file_set_visited (bookmark,
|
before = g_date_time_new_now_utc ();
|
||||||
"file:///tmp/schedule5.ps",
|
|
||||||
(time_t)-1);
|
g_bookmark_file_set_visited_date_time (bookmark,
|
||||||
t = g_bookmark_file_get_visited (bookmark,
|
"file:///tmp/schedule5.ps",
|
||||||
"file:///tmp/schedule5.ps",
|
before);
|
||||||
&error);
|
t = g_bookmark_file_get_visited_date_time (bookmark,
|
||||||
|
"file:///tmp/schedule5.ps",
|
||||||
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
time (&after);
|
after = g_date_time_new_now_utc ();
|
||||||
g_assert_cmpint (before, <=, t);
|
g_assert_cmpint (g_date_time_compare (before, t), <=, 0);
|
||||||
g_assert_cmpint (t, <=, after);
|
g_assert_cmpint (g_date_time_compare (t, after), <=, 0);
|
||||||
|
g_date_time_unref (after);
|
||||||
|
g_date_time_unref (before);
|
||||||
|
|
||||||
g_bookmark_file_set_icon (bookmark,
|
g_bookmark_file_set_icon (bookmark,
|
||||||
"file:///tmp/schedule6.ps",
|
"file:///tmp/schedule6.ps",
|
||||||
@ -271,16 +279,16 @@ test_misc (void)
|
|||||||
g_assert_false (res);
|
g_assert_false (res);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
|
|
||||||
time (&before);
|
before = g_date_time_new_now_utc ();
|
||||||
|
|
||||||
g_bookmark_file_add_application (bookmark,
|
g_bookmark_file_add_application (bookmark,
|
||||||
"file:///tmp/schedule7.ps",
|
"file:///tmp/schedule7.ps",
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
res = g_bookmark_file_get_app_info (bookmark,
|
res = g_bookmark_file_get_application_info (bookmark,
|
||||||
"file:///tmp/schedule7.ps",
|
"file:///tmp/schedule7.ps",
|
||||||
g_get_application_name (),
|
g_get_application_name (),
|
||||||
&exec, &count, &t,
|
&exec, &count, &t,
|
||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
cmd = g_strconcat (g_get_prgname (), " file:///tmp/schedule7.ps", NULL);
|
cmd = g_strconcat (g_get_prgname (), " file:///tmp/schedule7.ps", NULL);
|
||||||
@ -288,13 +296,111 @@ test_misc (void)
|
|||||||
g_free (cmd);
|
g_free (cmd);
|
||||||
g_free (exec);
|
g_free (exec);
|
||||||
g_assert_cmpuint (count, ==, 1);
|
g_assert_cmpuint (count, ==, 1);
|
||||||
time (&after);
|
|
||||||
g_assert_cmpint (before, <=, t);
|
after = g_date_time_new_now_utc ();
|
||||||
g_assert_cmpint (t, <=, after);
|
g_assert_cmpint (g_date_time_compare (before, t), <=, 0);
|
||||||
|
g_assert_cmpint (g_date_time_compare (t, after), <=, 0);
|
||||||
|
|
||||||
|
g_date_time_unref (after);
|
||||||
|
g_date_time_unref (before);
|
||||||
|
|
||||||
g_bookmark_file_free (bookmark);
|
g_bookmark_file_free (bookmark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_deprecated (void)
|
||||||
|
{
|
||||||
|
GBookmarkFile *file = NULL;
|
||||||
|
GError *local_error = NULL;
|
||||||
|
time_t t, now;
|
||||||
|
gboolean retval;
|
||||||
|
|
||||||
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||||
|
|
||||||
|
now = time (NULL);
|
||||||
|
file = g_bookmark_file_new ();
|
||||||
|
|
||||||
|
/* added */
|
||||||
|
g_bookmark_file_set_added (file, "file://test", -1);
|
||||||
|
t = g_bookmark_file_get_added (file, "file://test", &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_cmpint (t, >=, now);
|
||||||
|
|
||||||
|
g_bookmark_file_set_added (file, "file://test", 1234);
|
||||||
|
t = g_bookmark_file_get_added (file, "file://test", &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_cmpint (t, ==, 1234);
|
||||||
|
|
||||||
|
t = g_bookmark_file_get_added (file, "file://not-exist", &local_error);
|
||||||
|
g_assert_error (local_error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
|
||||||
|
g_assert_cmpint (t, ==, (time_t) -1);
|
||||||
|
g_clear_error (&local_error);
|
||||||
|
|
||||||
|
/* modified */
|
||||||
|
g_bookmark_file_set_modified (file, "file://test", -1);
|
||||||
|
t = g_bookmark_file_get_modified (file, "file://test", &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_cmpint (t, >=, now);
|
||||||
|
|
||||||
|
g_bookmark_file_set_modified (file, "file://test", 1234);
|
||||||
|
t = g_bookmark_file_get_modified (file, "file://test", &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_cmpint (t, ==, 1234);
|
||||||
|
|
||||||
|
t = g_bookmark_file_get_modified (file, "file://not-exist", &local_error);
|
||||||
|
g_assert_error (local_error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
|
||||||
|
g_assert_cmpint (t, ==, (time_t) -1);
|
||||||
|
g_clear_error (&local_error);
|
||||||
|
|
||||||
|
/* visited */
|
||||||
|
g_bookmark_file_set_visited (file, "file://test", -1);
|
||||||
|
t = g_bookmark_file_get_visited (file, "file://test", &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_cmpint (t, >=, now);
|
||||||
|
|
||||||
|
g_bookmark_file_set_visited (file, "file://test", 1234);
|
||||||
|
t = g_bookmark_file_get_visited (file, "file://test", &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_cmpint (t, ==, 1234);
|
||||||
|
|
||||||
|
t = g_bookmark_file_get_visited (file, "file://not-exist", &local_error);
|
||||||
|
g_assert_error (local_error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
|
||||||
|
g_assert_cmpint (t, ==, (time_t) -1);
|
||||||
|
g_clear_error (&local_error);
|
||||||
|
|
||||||
|
/* set app info */
|
||||||
|
retval = g_bookmark_file_set_app_info (file, "file://test", "app", "/path/to/app", 1, -1, &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_true (retval);
|
||||||
|
|
||||||
|
retval = g_bookmark_file_get_app_info (file, "file://test", "app", NULL, NULL, &t, &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_true (retval);
|
||||||
|
g_assert_cmpint (t, >=, now);
|
||||||
|
|
||||||
|
retval = g_bookmark_file_set_app_info (file, "file://test", "app", "/path/to/app", 1, 1234, &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_true (retval);
|
||||||
|
|
||||||
|
retval = g_bookmark_file_get_app_info (file, "file://test", "app", NULL, NULL, &t, &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_true (retval);
|
||||||
|
g_assert_cmpint (t, ==, 1234);
|
||||||
|
|
||||||
|
retval = g_bookmark_file_get_app_info (file, "file://test", "app", NULL, NULL, NULL, &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_true (retval);
|
||||||
|
|
||||||
|
retval = g_bookmark_file_get_app_info (file, "file://not-exist", "app", NULL, NULL, &t, &local_error);
|
||||||
|
g_assert_error (local_error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
|
||||||
|
g_assert_false (retval);
|
||||||
|
g_clear_error (&local_error);
|
||||||
|
|
||||||
|
g_bookmark_file_free (file);
|
||||||
|
|
||||||
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
test_load (GBookmarkFile *bookmark,
|
test_load (GBookmarkFile *bookmark,
|
||||||
const gchar *filename)
|
const gchar *filename)
|
||||||
@ -349,8 +455,8 @@ test_modify (GBookmarkFile *bookmark)
|
|||||||
{
|
{
|
||||||
gchar *text;
|
gchar *text;
|
||||||
guint count;
|
guint count;
|
||||||
time_t stamp;
|
GDateTime *stamp;
|
||||||
time_t now;
|
GDateTime *now = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gchar **groups;
|
gchar **groups;
|
||||||
gsize length;
|
gsize length;
|
||||||
@ -380,17 +486,17 @@ test_modify (GBookmarkFile *bookmark)
|
|||||||
g_bookmark_file_set_title (bookmark, TEST_URI_0, "a title");
|
g_bookmark_file_set_title (bookmark, TEST_URI_0, "a title");
|
||||||
g_bookmark_file_set_description (bookmark, TEST_URI_0, "a description");
|
g_bookmark_file_set_description (bookmark, TEST_URI_0, "a description");
|
||||||
g_bookmark_file_set_is_private (bookmark, TEST_URI_0, TRUE);
|
g_bookmark_file_set_is_private (bookmark, TEST_URI_0, TRUE);
|
||||||
time (&now);
|
now = g_date_time_new_now_utc ();
|
||||||
g_bookmark_file_set_added (bookmark, TEST_URI_0, now);
|
g_bookmark_file_set_added_date_time (bookmark, TEST_URI_0, now);
|
||||||
g_bookmark_file_set_visited (bookmark, TEST_URI_0, now);
|
g_bookmark_file_set_visited_date_time (bookmark, TEST_URI_0, now);
|
||||||
g_bookmark_file_set_icon (bookmark, TEST_URI_0, "testicon", "image/png");
|
g_bookmark_file_set_icon (bookmark, TEST_URI_0, "testicon", "image/png");
|
||||||
|
|
||||||
/* Check the modification date by itself, as it’s updated whenever we modify
|
/* Check the modification date by itself, as it’s updated whenever we modify
|
||||||
* other properties. */
|
* other properties. */
|
||||||
g_bookmark_file_set_modified (bookmark, TEST_URI_0, now);
|
g_bookmark_file_set_modified_date_time (bookmark, TEST_URI_0, now);
|
||||||
stamp = g_bookmark_file_get_modified (bookmark, TEST_URI_0, &error);
|
stamp = g_bookmark_file_get_modified_date_time (bookmark, TEST_URI_0, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert_cmpint (stamp, ==, now);
|
g_assert_cmpint (g_date_time_compare (stamp, now), ==, 0);
|
||||||
|
|
||||||
text = g_bookmark_file_get_title (bookmark, TEST_URI_0, &error);
|
text = g_bookmark_file_get_title (bookmark, TEST_URI_0, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
@ -402,12 +508,12 @@ test_modify (GBookmarkFile *bookmark)
|
|||||||
g_free (text);
|
g_free (text);
|
||||||
g_assert_true (g_bookmark_file_get_is_private (bookmark, TEST_URI_0, &error));
|
g_assert_true (g_bookmark_file_get_is_private (bookmark, TEST_URI_0, &error));
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
stamp = g_bookmark_file_get_added (bookmark, TEST_URI_0, &error);
|
stamp = g_bookmark_file_get_added_date_time (bookmark, TEST_URI_0, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert_cmpint (stamp, ==, now);
|
g_assert_cmpint (g_date_time_compare (stamp, now), ==, 0);
|
||||||
stamp = g_bookmark_file_get_visited (bookmark, TEST_URI_0, &error);
|
stamp = g_bookmark_file_get_visited_date_time (bookmark, TEST_URI_0, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert_cmpint (stamp, ==, now);
|
g_assert_cmpint (g_date_time_compare (stamp, now), ==, 0);
|
||||||
g_assert_true (g_bookmark_file_get_icon (bookmark, TEST_URI_0, &icon, &mime, &error));
|
g_assert_true (g_bookmark_file_get_icon (bookmark, TEST_URI_0, &icon, &mime, &error));
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert_cmpstr (icon, ==, "testicon");
|
g_assert_cmpstr (icon, ==, "testicon");
|
||||||
@ -425,13 +531,13 @@ test_modify (GBookmarkFile *bookmark)
|
|||||||
g_bookmark_file_get_is_private (bookmark, TEST_URI_1, &error);
|
g_bookmark_file_get_is_private (bookmark, TEST_URI_1, &error);
|
||||||
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
|
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
g_bookmark_file_get_added (bookmark, TEST_URI_1, &error);
|
g_bookmark_file_get_added_date_time (bookmark, TEST_URI_1, &error);
|
||||||
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
|
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
g_bookmark_file_get_modified (bookmark, TEST_URI_1, &error);
|
g_bookmark_file_get_modified_date_time (bookmark, TEST_URI_1, &error);
|
||||||
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
|
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
g_bookmark_file_get_visited (bookmark, TEST_URI_1, &error);
|
g_bookmark_file_get_visited_date_time (bookmark, TEST_URI_1, &error);
|
||||||
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
|
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
if (g_test_verbose ())
|
if (g_test_verbose ())
|
||||||
@ -445,14 +551,14 @@ test_modify (GBookmarkFile *bookmark)
|
|||||||
TEST_APP_NAME,
|
TEST_APP_NAME,
|
||||||
TEST_APP_EXEC);
|
TEST_APP_EXEC);
|
||||||
g_assert_true (g_bookmark_file_has_application (bookmark, TEST_URI_0, TEST_APP_NAME, NULL));
|
g_assert_true (g_bookmark_file_has_application (bookmark, TEST_URI_0, TEST_APP_NAME, NULL));
|
||||||
g_bookmark_file_get_app_info (bookmark, TEST_URI_0, TEST_APP_NAME,
|
g_bookmark_file_get_application_info (bookmark, TEST_URI_0, TEST_APP_NAME,
|
||||||
&text,
|
&text,
|
||||||
&count,
|
&count,
|
||||||
&stamp,
|
&stamp,
|
||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert_cmpuint (count, ==, 1);
|
g_assert_cmpuint (count, ==, 1);
|
||||||
g_assert_cmpint (stamp, ==, g_bookmark_file_get_modified (bookmark, TEST_URI_0, NULL));
|
g_assert_cmpint (g_date_time_compare (stamp, g_bookmark_file_get_modified_date_time (bookmark, TEST_URI_0, NULL)), <=, 0);
|
||||||
g_free (text);
|
g_free (text);
|
||||||
g_assert_true (g_bookmark_file_remove_application (bookmark, TEST_URI_0, TEST_APP_NAME, &error));
|
g_assert_true (g_bookmark_file_remove_application (bookmark, TEST_URI_0, TEST_APP_NAME, &error));
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
@ -463,11 +569,11 @@ test_modify (GBookmarkFile *bookmark)
|
|||||||
g_assert_cmpstr (apps[0], ==, TEST_APP_NAME);
|
g_assert_cmpstr (apps[0], ==, TEST_APP_NAME);
|
||||||
g_strfreev (apps);
|
g_strfreev (apps);
|
||||||
|
|
||||||
g_bookmark_file_get_app_info (bookmark, TEST_URI_0, "fail",
|
g_bookmark_file_get_application_info (bookmark, TEST_URI_0, "fail",
|
||||||
&text,
|
&text,
|
||||||
&count,
|
&count,
|
||||||
&stamp,
|
&stamp,
|
||||||
&error);
|
&error);
|
||||||
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED);
|
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
|
|
||||||
@ -509,6 +615,8 @@ test_modify (GBookmarkFile *bookmark)
|
|||||||
if (g_test_verbose ())
|
if (g_test_verbose ())
|
||||||
g_printerr ("ok\n");
|
g_printerr ("ok\n");
|
||||||
|
|
||||||
|
g_date_time_unref (now);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,6 +671,7 @@ main (int argc, char *argv[])
|
|||||||
g_test_add_func ("/bookmarks/to-file", test_to_file);
|
g_test_add_func ("/bookmarks/to-file", test_to_file);
|
||||||
g_test_add_func ("/bookmarks/move-item", test_move_item);
|
g_test_add_func ("/bookmarks/move-item", test_move_item);
|
||||||
g_test_add_func ("/bookmarks/misc", test_misc);
|
g_test_add_func ("/bookmarks/misc", test_misc);
|
||||||
|
g_test_add_func ("/bookmarks/deprecated", test_deprecated);
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
path = g_test_build_filename (G_TEST_DIST, "bookmarks", NULL);
|
path = g_test_build_filename (G_TEST_DIST, "bookmarks", NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user