Commit bcdc09e6 authored by Emmanuele Bassi's avatar Emmanuele Bassi Committed by Emmanuele Bassi

Do not set the timestamp value using time(), as it will be overwritten

2008-07-21  Emmanuele Bassi  <ebassi@gnome.org>

	* glib/gbookmarkfile.c:
	(bookmark_app_info_new): Do not set the timestamp value
	using time(), as it will be overwritten anyway. (#535223,
	Michael Meeks)

	(parse_application_element),
	(bookmark_app_info_dump): Support the "modified" attribute,
	which takes an ISO-formatted string instead of a Unix time
	stamp, to keep the number of g_strdup_printf() calls to a
	minimum.

	* glib/gtimer.c:
	(g_time_val_to_iso8601): Do not use strftime(): we know
	the format and contents of the ISO 8601 date format we
	use.

	* tests/bookmarks/valid-03.xbel: Add a test file for the
	modified attribute.

svn path=/trunk/; revision=7231
parent f573de59
2008-07-21 Emmanuele Bassi <ebassi@gnome.org>
* glib/gbookmarkfile.c:
(bookmark_app_info_new): Do not set the timestamp value
using time(), as it will be overwritten anyway. (#535223,
Michael Meeks)
(parse_application_element),
(bookmark_app_info_dump): Support the "modified" attribute,
which takes an ISO-formatted string instead of a Unix time
stamp, to keep the number of g_strdup_printf() calls to a
minimum.
* glib/gtimer.c:
(g_time_val_to_iso8601): Do not use strftime(): we know
the format and contents of the ISO 8601 date format we
use.
* tests/bookmarks/valid-03.xbel: Add a test file for the
modified attribute.
2008-07-19 Matthias Clasen <mclasen@redhat.com> 2008-07-19 Matthias Clasen <mclasen@redhat.com>
* glib/tests/Makefile.am: * glib/tests/Makefile.am:
......
...@@ -104,7 +104,8 @@ ...@@ -104,7 +104,8 @@
#define BOOKMARK_NAME_ATTRIBUTE "name" #define BOOKMARK_NAME_ATTRIBUTE "name"
#define BOOKMARK_EXEC_ATTRIBUTE "exec" #define BOOKMARK_EXEC_ATTRIBUTE "exec"
#define BOOKMARK_COUNT_ATTRIBUTE "count" #define BOOKMARK_COUNT_ATTRIBUTE "count"
#define BOOKMARK_TIMESTAMP_ATTRIBUTE "timestamp" #define BOOKMARK_TIMESTAMP_ATTRIBUTE "timestamp" /* deprecated by "modified" */
#define BOOKMARK_MODIFIED_ATTRIBUTE "modified"
#define BOOKMARK_HREF_ATTRIBUTE "href" #define BOOKMARK_HREF_ATTRIBUTE "href"
#define BOOKMARK_TYPE_ATTRIBUTE "type" #define BOOKMARK_TYPE_ATTRIBUTE "type"
...@@ -227,7 +228,7 @@ bookmark_app_info_new (const gchar *name) ...@@ -227,7 +228,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 = time (NULL); retval->stamp = 0;
return retval; return retval;
} }
...@@ -248,7 +249,7 @@ static gchar * ...@@ -248,7 +249,7 @@ static gchar *
bookmark_app_info_dump (BookmarkAppInfo *app_info) bookmark_app_info_dump (BookmarkAppInfo *app_info)
{ {
gchar *retval; gchar *retval;
gchar *name, *exec; gchar *name, *exec, *modified, *count;
g_warn_if_fail (app_info != NULL); g_warn_if_fail (app_info != NULL);
...@@ -257,17 +258,21 @@ bookmark_app_info_dump (BookmarkAppInfo *app_info) ...@@ -257,17 +258,21 @@ 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);
retval = g_strdup_printf (" <%s:%s %s=\"%s\" %s=\"%s\" %s=\"%ld\" %s=\"%u\"/>\n", count = g_strdup_printf ("%u", app_info->count);
BOOKMARK_NAMESPACE_NAME,
BOOKMARK_APPLICATION_ELEMENT, retval = g_strconcat (" "
BOOKMARK_NAME_ATTRIBUTE, name, "<" BOOKMARK_NAMESPACE_NAME ":" BOOKMARK_APPLICATION_ELEMENT
BOOKMARK_EXEC_ATTRIBUTE, exec, " " BOOKMARK_NAME_ATTRIBUTE "=\"", name, "\""
BOOKMARK_TIMESTAMP_ATTRIBUTE, (time_t) app_info->stamp, " " BOOKMARK_EXEC_ATTRIBUTE "=\"", exec, "\""
BOOKMARK_COUNT_ATTRIBUTE, app_info->count); " " BOOKMARK_MODIFIED_ATTRIBUTE "=\"", modified, "\""
" " BOOKMARK_COUNT_ATTRIBUTE "=\"", count, "\"/>\n",
NULL);
g_free (name); g_free (name);
g_free (exec); g_free (exec);
g_free (modified);
g_free (count);
return retval; return retval;
} }
...@@ -757,8 +762,8 @@ parse_bookmark_element (GMarkupParseContext *context, ...@@ -757,8 +762,8 @@ parse_bookmark_element (GMarkupParseContext *context,
add_error = NULL; add_error = NULL;
g_bookmark_file_add_item (parse_data->bookmark_file, g_bookmark_file_add_item (parse_data->bookmark_file,
item, item,
&add_error); &add_error);
if (add_error) if (add_error)
{ {
bookmark_item_free (item); bookmark_item_free (item);
...@@ -778,7 +783,7 @@ parse_application_element (GMarkupParseContext *context, ...@@ -778,7 +783,7 @@ parse_application_element (GMarkupParseContext *context,
const gchar **attribute_values, const gchar **attribute_values,
GError **error) GError **error)
{ {
const gchar *name, *exec, *count, *stamp; const gchar *name, *exec, *count, *stamp, *modified;
const gchar *attr; const gchar *attr;
gint i; gint i;
BookmarkItem *item; BookmarkItem *item;
...@@ -787,7 +792,7 @@ parse_application_element (GMarkupParseContext *context, ...@@ -787,7 +792,7 @@ parse_application_element (GMarkupParseContext *context,
g_warn_if_fail ((parse_data != NULL) && (parse_data->state == STATE_APPLICATION)); g_warn_if_fail ((parse_data != NULL) && (parse_data->state == STATE_APPLICATION));
i = 0; i = 0;
name = exec = count = stamp = NULL; name = exec = count = stamp = modified = NULL;
for (attr = attribute_names[i]; attr != NULL; attr = attribute_names[++i]) for (attr = attribute_names[i]; attr != NULL; attr = attribute_names[++i])
{ {
if (IS_ATTRIBUTE (attr, BOOKMARK_NAME_ATTRIBUTE)) if (IS_ATTRIBUTE (attr, BOOKMARK_NAME_ATTRIBUTE))
...@@ -798,6 +803,8 @@ parse_application_element (GMarkupParseContext *context, ...@@ -798,6 +803,8 @@ parse_application_element (GMarkupParseContext *context,
count = attribute_values[i]; count = attribute_values[i];
else if (IS_ATTRIBUTE (attr, BOOKMARK_TIMESTAMP_ATTRIBUTE)) else if (IS_ATTRIBUTE (attr, BOOKMARK_TIMESTAMP_ATTRIBUTE))
stamp = attribute_values[i]; stamp = attribute_values[i];
else if (IS_ATTRIBUTE (attr, BOOKMARK_MODIFIED_ATTRIBUTE))
modified = attribute_values[i];
else else
{ {
g_set_error (error, G_MARKUP_ERROR, g_set_error (error, G_MARKUP_ERROR,
...@@ -850,11 +857,19 @@ parse_application_element (GMarkupParseContext *context, ...@@ -850,11 +857,19 @@ parse_application_element (GMarkupParseContext *context,
ai->count = atoi (count); ai->count = atoi (count);
else else
ai->count = 1; ai->count = 1;
if (stamp) if (modified)
ai->stamp = (time_t) atol (stamp); ai->stamp = timestamp_from_iso8601 (modified);
else else
ai->stamp = time (NULL); {
/* the timestamp attribute has been deprecated but we still parse
* it for backward compatibility
*/
if (stamp)
ai->stamp = (time_t) atol (stamp);
else
ai->stamp = time (NULL);
}
} }
static void static void
...@@ -1512,7 +1527,8 @@ g_bookmark_file_dump (GBookmarkFile *bookmark, ...@@ -1512,7 +1527,8 @@ g_bookmark_file_dump (GBookmarkFile *bookmark,
goto out; goto out;
else else
retval = g_string_append (retval, "\n"); retval = g_string_append (retval, "\n");
/* the items are stored in reverse order */
for (l = g_list_last (bookmark->items); for (l = g_list_last (bookmark->items);
l != NULL; l != NULL;
l = l->prev) l = l->prev)
...@@ -1526,7 +1542,7 @@ g_bookmark_file_dump (GBookmarkFile *bookmark, ...@@ -1526,7 +1542,7 @@ g_bookmark_file_dump (GBookmarkFile *bookmark,
retval = g_string_append (retval, item_dump); retval = g_string_append (retval, item_dump);
g_free (item_dump); g_free (item_dump);
} }
out: out:
...@@ -1577,7 +1593,7 @@ timestamp_from_iso8601 (const gchar *iso_date) ...@@ -1577,7 +1593,7 @@ timestamp_from_iso8601 (const gchar *iso_date)
GQuark GQuark
g_bookmark_file_error_quark (void) g_bookmark_file_error_quark (void)
{ {
return g_quark_from_static_string ("egg-bookmark-file-error-quark"); return g_quark_from_static_string ("g-bookmark-file-error-quark");
} }
...@@ -2102,7 +2118,8 @@ g_bookmark_file_get_uris (GBookmarkFile *bookmark, ...@@ -2102,7 +2118,8 @@ g_bookmark_file_get_uris (GBookmarkFile *bookmark,
n_items = g_list_length (bookmark->items); n_items = g_list_length (bookmark->items);
uris = g_new0 (gchar *, n_items + 1); uris = g_new0 (gchar *, n_items + 1);
/* the items are stored in reverse order, so we walk the list backward */
for (l = g_list_last (bookmark->items), i = 0; l != NULL; l = l->prev) for (l = g_list_last (bookmark->items), i = 0; l != NULL; l = l->prev)
{ {
BookmarkItem *item = (BookmarkItem *) l->data; BookmarkItem *item = (BookmarkItem *) l->data;
...@@ -3615,10 +3632,11 @@ g_bookmark_file_move_item (GBookmarkFile *bookmark, ...@@ -3615,10 +3632,11 @@ g_bookmark_file_move_item (GBookmarkFile *bookmark,
* @href: the URI of the icon for the bookmark, or %NULL * @href: the URI of the icon for the bookmark, or %NULL
* @mime_type: the MIME type of the icon for the bookmark * @mime_type: the MIME type of the icon for the bookmark
* *
* Sets the icon for the bookmark for @uri. If @href is %NULL, unsets * Sets the icon for the bookmark for @uri. If @href is %NULL, unsets
* the currently set icon. * the currently set icon. @href can either be a full URL for the icon
* file or the icon name following the Icon Naming specification.
* *
* If no bookmark for @uri is found it is created. * If no bookmark for @uri is found one is created.
* *
* Since: 2.12 * Since: 2.12
*/ */
......
...@@ -430,20 +430,30 @@ g_time_val_to_iso8601 (GTimeVal *time_) ...@@ -430,20 +430,30 @@ g_time_val_to_iso8601 (GTimeVal *time_)
if (time_->tv_usec != 0) if (time_->tv_usec != 0)
{ {
#define ISO_8601_FRAC_LEN 28 /* ISO 8601 date and time format, with fractionary seconds:
#define ISO_8601_FRAC_FORMAT "%%Y-%%m-%%dT%%H:%%M:%%S.%06ldZ" * YYYY-MM-DDTHH:MM:SS.MMMMMMZ
gchar *format = g_strdup_printf (ISO_8601_FRAC_FORMAT, time_->tv_usec); */
retval = g_strdup_printf ("%d-%d-%dT%d:%d:%d.%06ldZ",
retval = g_new0 (gchar, ISO_8601_FRAC_LEN + 1); tm->tm_year + 1900,
strftime (retval, ISO_8601_FRAC_LEN, format, tm); tm->tm_mon + 1,
g_free (format); tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec,
time_->tv_usec);
} }
else else
{ {
#define ISO_8601_LEN 21 /* ISO 8601 date and time format:
#define ISO_8601_FORMAT "%Y-%m-%dT%H:%M:%SZ" * YYYY-MM-DDTHH:MM:SSZ
retval = g_new0 (gchar, ISO_8601_LEN + 1); */
strftime (retval, ISO_8601_LEN, ISO_8601_FORMAT, tm); retval = g_strdup_printf ("%d-%d-%dT%d:%d:%dZ",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
} }
return retval; return retval;
......
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xbel
PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML"
"http://www.python.org/topics/xml/dtds/xbel-1.0.dtd">
<xbel version="1.0"
xmlns:bookmark="http://www.freedesktop.org/standards/desktop-bookmarks"
xmlns:mime="http://www.freedesktop.org/standards/shared-mime-info"
>
<title>Singleton</title>
<desc>A file containing a single bookmark element</desc>
<bookmark href="file:///home/zefram/Documents/milan-stuttgart.ps" added="20050930T23:05:28Z" modified="20050930T23:05:28Z" visited="20050930T23:05:28Z">
<info>
<metadata owner="http://freedesktop.org">
<mime:mime-type type="application/postscript"/>
<bookmark:applications>
<bookmark:application name="populate-recent" exec="populate-recent --info %u" modified="2005-09-30T23:05:28Z" count="1"/>
</bookmark:applications>
</metadata>
</info>
</bookmark>
</xbel>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment