[Xfce4-commits] <midori:master> 2.26 guarded GDateTime everywhere, more consistent code
Christian Dywan
noreply at xfce.org
Thu Dec 6 02:32:01 CET 2012
Updating branch refs/heads/master
to ab1d8a381fd1b0d48d0d262407fc6c788abf8c14 (commit)
from f9f4815b6c18813db358109a930b500c53e26b29 (commit)
commit ab1d8a381fd1b0d48d0d262407fc6c788abf8c14
Author: Christian Dywan <christian at twotoasts.de>
Date: Wed Dec 5 21:12:30 2012 +0100
2.26 guarded GDateTime everywhere, more consistent code
extensions/cookie-manager/cookie-manager-page.c | 23 ++++++++-----
extensions/feed-panel/feed-panel.c | 41 ++++++++++------------
extensions/status-clock.c | 37 +++++++++++---------
panels/midori-history.c | 2 +
4 files changed, 55 insertions(+), 48 deletions(-)
diff --git a/extensions/cookie-manager/cookie-manager-page.c b/extensions/cookie-manager/cookie-manager-page.c
index 186e310..a12b884 100644
--- a/extensions/cookie-manager/cookie-manager-page.c
+++ b/extensions/cookie-manager/cookie-manager-page.c
@@ -650,25 +650,28 @@ static void cm_tree_drag_data_get_cb(GtkWidget *widget, GdkDragContext *drag_con
static gchar *cm_get_cookie_description_text(SoupCookie *cookie)
{
- static gchar date_fmt[512];
gchar *expires;
gchar *text;
- time_t expiration_time;
- const struct tm *tm;
g_return_val_if_fail(cookie != NULL, NULL);
if (cookie->expires != NULL)
{
- expiration_time = soup_date_to_time_t(cookie->expires);
- tm = localtime(&expiration_time);
- /* even if some gcc versions complain about "%c", there is nothing wrong with and here we
- * want to use it */
+ time_t expiration_time = soup_date_to_time_t(cookie->expires);
+ #if GLIB_CHECK_VERSION (2, 26, 0)
+ GDateTime* date = g_date_time_new_from_unix_local(expiration_time);
+ expires = g_date_time_format(date, "%c");
+ g_date_time_unref(date);
+ #else
+ static gchar date_fmt[512];
+ const struct tm *tm = localtime(&expiration_time);
+ /* Some GCC versions falsely complain about "%c" */
strftime(date_fmt, sizeof(date_fmt), "%c", tm);
- expires = date_fmt;
+ expires = g_strdup(date_fmt);
+ #endif
}
else
- expires = _("At the end of the session");
+ expires = g_strdup(_("At the end of the session"));
text = g_markup_printf_escaped(
_("<b>Host</b>: %s\n<b>Name</b>: %s\n<b>Value</b>: %s\n<b>Path</b>: %s\n"
@@ -677,8 +680,10 @@ static gchar *cm_get_cookie_description_text(SoupCookie *cookie)
cookie->name,
cookie->value,
cookie->path,
+ /* i18n: is this cookie secure (SSL)? yes/ no */
cookie->secure ? _("Yes") : _("No"),
expires);
+ g_free(expires);
return text;
}
diff --git a/extensions/feed-panel/feed-panel.c b/extensions/feed-panel/feed-panel.c
index de0d457..ca4c529 100644
--- a/extensions/feed-panel/feed-panel.c
+++ b/extensions/feed-panel/feed-panel.c
@@ -358,45 +358,42 @@ feed_panel_cursor_or_row_changed_cb (GtkTreeView* treeview,
if (KATZE_IS_ARRAY (item))
{
- gint64 date;
-
text = NULL;
if (!uri)
text = g_strdup (katze_item_get_text (KATZE_ITEM (item)));
else
{
- KatzeItem* parent;
- const gchar* puri;
-
- parent = katze_item_get_parent (item);
+ KatzeItem* parent = katze_item_get_parent (item);
+ gint64 added = katze_item_get_added (item);
g_assert (KATZE_IS_ARRAY (parent));
- date = katze_item_get_added (item);
- puri = katze_item_get_uri (parent);
- if (date)
+ if (added)
{
- time_t date_t;
- const struct tm* tm;
- static gchar date_format[512];
- gchar* last_updated;
-
- date_t = (time_t)date;
- tm = localtime (&date_t);
- /* Some gcc versions complain about "%c" for no reason */
- strftime (date_format, sizeof (date_format), "%c", tm);
+ #if GLIB_CHECK_VERSION (2, 26, 0)
+ GDateTime* date = g_date_time_new_from_unix_local (added);
+ gchar* pretty = g_date_time_format (date, "%c");
+ g_date_time_unref (date);
+ #else
+ static gchar date_fmt[512];
+ const struct tm *tm = localtime (&added);
+ /* Some GCC versions falsely complain about "%c" */
+ strftime (date_fmt, sizeof (date_fmt), "%c", tm);
+ gchar* pretty = g_strdup (date_fmt);
+ #endif
+
/* i18n: The local date a feed was last updated */
- last_updated = g_strdup_printf (C_("Feed", "Last updated: %s."),
- date_format);
+ gchar* last_updated = g_strdup_printf (C_("Feed", "Last updated: %s."), pretty);
text = g_strdup_printf (
"<html><head><title>feed</title></head>"
"<body><h3>%s</h3><p />%s</body></html>",
- puri, last_updated);
+ parent->uri, last_updated);
+ g_free (pretty);
g_free (last_updated);
}
else
{
text = g_strdup_printf (
"<html><head><title>feed</title></head>"
- "<body><h3>%s</h3></body></html>", puri);
+ "<body><h3>%s</h3></body></html>", parent->uri);
}
}
webkit_web_view_load_html_string (
diff --git a/extensions/status-clock.c b/extensions/status-clock.c
index 639f2ff..f76dbf6 100644
--- a/extensions/status-clock.c
+++ b/extensions/status-clock.c
@@ -43,23 +43,26 @@ clock_set_timeout (MidoriBrowser* browser,
static gboolean
clock_set_current_time (MidoriBrowser* browser)
{
- MidoriExtension* extension;
- GtkWidget* label;
- const gchar* format;
- struct tm *tm;
- time_t rawtime;
- char datestring[60];
guint interval;
-
- extension = g_object_get_data (G_OBJECT (browser), "clock-extension");
- label = g_object_get_data (G_OBJECT (browser), "clock-label");
- format = midori_extension_get_string (extension, "format");
-
- rawtime = time (NULL);
- tm = localtime (&rawtime);
-
- strftime (datestring, 60, format, tm);
- gtk_label_set_label (GTK_LABEL (label), datestring);
+ MidoriExtension* extension = g_object_get_data (G_OBJECT (browser), "clock-extension");
+ GtkWidget* label = g_object_get_data (G_OBJECT (browser), "clock-label");
+ const gchar* format = midori_extension_get_string (extension, "format");
+
+ #if GLIB_CHECK_VERSION (2, 26, 0)
+ GDateTime* date = g_date_time_new_now_local ();
+ gint seconds = g_date_time_get_seconds (date);
+ gchar* pretty = g_date_time_format (date, format);
+ gtk_label_set_label (GTK_LABEL (label), pretty);
+ g_free (pretty);
+ g_date_time_unref (date);
+ #else
+ time_t rawtime = time (NULL);
+ struct tm *tm = localtime (&rawtime);
+ gint seconds = tm->tm_sec;
+ char date_fmt[512];
+ strftime (date_fmt, sizeof (date_fmt), format, tm);
+ gtk_label_set_label (GTK_LABEL (label), date_fmt);
+ #endif
if (g_strstr_len (format, -1, "%c")
|| g_strstr_len (format, -1, "%N")
@@ -71,7 +74,7 @@ clock_set_current_time (MidoriBrowser* browser)
interval = 1;
else
/* FIXME: Occasionally there are more than 60 seconds in a minute. */
- interval = MAX (60 - tm->tm_sec, 1);
+ interval = MAX (60 - seconds, 1);
clock_set_timeout (browser, interval);
diff --git a/panels/midori-history.c b/panels/midori-history.c
index c1bb181..3248750 100644
--- a/panels/midori-history.c
+++ b/panels/midori-history.c
@@ -165,6 +165,8 @@ midori_history_format_date (KatzeItem *item)
sdate = g_strdup (_("A week ago"));
else
sdate = g_date_time_format (then, "%x");
+ g_date_time_unref (now);
+ g_date_time_unref (then);
#else
gchar token[50];
time_t current_time;
More information about the Xfce4-commits
mailing list