diff --git a/extensions/feed-panel/feed-atom.c b/extensions/feed-panel/feed-atom.c index def46f61..de905f2f 100644 --- a/extensions/feed-panel/feed-atom.c +++ b/extensions/feed-panel/feed-atom.c @@ -138,6 +138,31 @@ atom_get_link (KatzeItem* item, } } +static gchar* +atom_get_title (FeedParser* fparser) +{ + if (!katze_item_get_name (fparser->item)) + { + gchar* type; + + type = (gchar*)xmlGetProp (fparser->node, BAD_CAST "type"); + if (type) + { + gchar* content = NULL; + + if (g_str_equal (type, "html") || + g_str_equal (type, "xhtml")) + content = feed_get_element_markup (fparser); + + xmlFree (type); + + if (content) + return content; + } + } + return feed_get_element_string (fparser); +} + static void atom_preparse_entry (FeedParser* fparser) { @@ -161,7 +186,7 @@ atom_parse_entry (FeedParser* fparser) } else if (!xmlStrcmp (node->name, BAD_CAST "title")) { - content = feed_get_element_string (fparser); + content = atom_get_title (fparser); katze_item_set_name (fparser->item, content); } else if (!xmlStrcmp (node->name, BAD_CAST "summary")) @@ -249,7 +274,7 @@ atom_parse_feed (FeedParser* fparser) } else if (!xmlStrcmp (node->name, BAD_CAST "title")) { - content = feed_get_element_string (fparser); + content = atom_get_title (fparser); katze_item_set_name (fparser->item, content); } else if (!xmlStrcmp (node->name, BAD_CAST "subtitle")) diff --git a/extensions/feed-panel/feed-panel.c b/extensions/feed-panel/feed-panel.c index 0c818bc7..bbef14f6 100644 --- a/extensions/feed-panel/feed-panel.c +++ b/extensions/feed-panel/feed-panel.c @@ -121,9 +121,9 @@ feed_panel_treeview_render_text_cb (GtkTreeViewColumn* column, g_assert (KATZE_IS_ITEM (item)); title = katze_item_get_name (item); - if (!title) + if (!title || !*title || g_str_equal (title, " ")) title = katze_item_get_text (item); - if (!title) + if (!title || !*title || g_str_equal (title, " ")) title = katze_item_get_uri (item); g_object_set (renderer, "text", title, NULL); @@ -377,23 +377,24 @@ feed_panel_cursor_or_row_changed_cb (GtkTreeView* treeview, text = g_strdup (katze_item_get_text (KATZE_ITEM (item))); else { + KatzeItem* parent; + const gchar* puri; + + parent = katze_item_get_parent (item); + g_assert (KATZE_IS_ARRAY (parent)); date = katze_item_get_added (item); + puri = katze_item_get_uri (parent); if (date) { time_t date_t; const struct tm* tm; static gchar date_format[512]; - const gchar* puri; - KatzeItem* parent; 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); - parent = katze_item_get_parent (item); - g_assert (KATZE_IS_ARRAY (parent)); - puri = katze_item_get_uri (parent); /* i18n: The local date a feed was last updated */ last_updated = g_strdup_printf (C_("Feed", "Last updated: %s."), date_format); @@ -403,6 +404,12 @@ feed_panel_cursor_or_row_changed_cb (GtkTreeView* treeview, puri, last_updated); g_free (last_updated); } + else + { + text = g_strdup_printf ( + "feed" + "

%s

", puri); + } } webkit_web_view_load_html_string ( WEBKIT_WEB_VIEW (panel->webview), text ? text : "", uri); @@ -413,11 +420,8 @@ feed_panel_cursor_or_row_changed_cb (GtkTreeView* treeview, else { text = katze_item_get_text (item); - if (text) - { - webkit_web_view_load_html_string ( - WEBKIT_WEB_VIEW (panel->webview), text, uri); - } + webkit_web_view_load_html_string ( + WEBKIT_WEB_VIEW (panel->webview), text ? text : "", uri); } g_object_unref (item); } diff --git a/extensions/feed-panel/feed-parse.c b/extensions/feed-panel/feed-parse.c index 442e5ed5..4c09dc64 100644 --- a/extensions/feed-panel/feed-parse.c +++ b/extensions/feed-panel/feed-parse.c @@ -30,7 +30,43 @@ feed_get_element_string (FeedParser* fparser) return g_strdup (" "); } - return (gchar* )xmlNodeListGetString (fparser->doc, node->children, 1); + return (gchar*)xmlNodeListGetString (fparser->doc, node->children, 1); +} + +void +handle_markup_chars (void* user_data, + const xmlChar* ch, + int len) +{ + gchar** markup; + gchar* temp; + + markup = (gchar**)user_data; + temp = g_strndup ((gchar*)ch, len); + *markup = (*markup) ? g_strconcat (*markup, temp, NULL) : g_strdup (temp); + g_free (temp); +} + +gchar* +feed_get_element_markup (FeedParser* fparser) +{ + gchar* markup; + const xmlChar* stag; + + markup = feed_get_element_string (fparser); + if ((stag = xmlStrchr (BAD_CAST markup, '<')) && xmlStrchr (stag, '>')) + { + gchar* text = NULL; + htmlSAXHandlerPtr psax; + + psax = g_new0 (htmlSAXHandler, 1); + psax->characters = handle_markup_chars; + htmlSAXParseDoc (BAD_CAST markup, NULL, psax, &text); + g_free (psax); + g_free (markup); + return text; + } + return markup; } gint64 diff --git a/extensions/feed-panel/feed-parse.h b/extensions/feed-panel/feed-parse.h index 493b7ef7..84ae9f19 100644 --- a/extensions/feed-panel/feed-parse.h +++ b/extensions/feed-panel/feed-parse.h @@ -20,6 +20,7 @@ #include #include +#include G_BEGIN_DECLS @@ -52,9 +53,13 @@ typedef struct _FeedParser #define feed_parser_set_error(fparser, err, msg) \ *(fparser)->error = g_error_new ( \ FEED_PARSE_ERROR, (err), (msg)) + gchar* feed_get_element_string (FeedParser* fparser); +gchar* +feed_get_element_markup (FeedParser* fparser); + gint64 feed_get_element_date (FeedParser* fparser); diff --git a/extensions/feed-panel/feed-rss.c b/extensions/feed-panel/feed-rss.c index 84fd6d3b..03843df6 100644 --- a/extensions/feed-panel/feed-rss.c +++ b/extensions/feed-panel/feed-rss.c @@ -107,7 +107,7 @@ rss_parse_item (FeedParser* fparser) } else if (!xmlStrcmp (node->name, BAD_CAST "title")) { - content = feed_get_element_string (fparser); + content = feed_get_element_markup (fparser); katze_item_set_name (fparser->item, content); } else if (!xmlStrcmp (node->name, BAD_CAST "description")) @@ -165,7 +165,7 @@ rss_parse_channel (FeedParser* fparser) if (!xmlStrcmp (node->name, BAD_CAST "title")) { - content = feed_get_element_string (fparser); + content = feed_get_element_markup (fparser); katze_item_set_name (fparser->item, content); } else if (!xmlStrcmp (node->name, BAD_CAST "description"))