Display the news feed icon again

The code for looking up news feeds on websites was disabled
and is now back in simplified form. 'liferea-add-feed' is
hardcoded for the moment.
This commit is contained in:
Christian Dywan 2009-04-13 22:40:57 +02:00
parent 94c1d3c713
commit c27642e912
4 changed files with 39 additions and 118 deletions

View file

@ -302,15 +302,13 @@ _midori_browser_update_interface (MidoriBrowser* browser)
} }
katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading); katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading);
/* FIXME: This won't work due to a bug in GtkIconEntry */ action = _action_by_name (browser, "Location");
/* if (view && midori_view_get_news_feeds (MIDORI_VIEW (view))) if (g_object_get_data (G_OBJECT (view), "news-feeds"))
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY ( midori_location_action_set_secondary_icon (
gtk_bin_get_child (GTK_BIN (browser->location))), MIDORI_LOCATION_ACTION (action), STOCK_NEWS_FEED);
GTK_ICON_ENTRY_SECONDARY, STOCK_NEWS_FEED);
else else
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY ( midori_location_action_set_secondary_icon (
gtk_bin_get_child (GTK_BIN (browser->location))), MIDORI_LOCATION_ACTION (action), GTK_STOCK_INFO);
GTK_ICON_ENTRY_SECONDARY, NULL);*/
} }
static void static void
@ -418,7 +416,7 @@ midori_view_notify_load_status_cb (GtkWidget* view,
midori_location_action_set_uri ( midori_location_action_set_uri (
MIDORI_LOCATION_ACTION (action), uri); MIDORI_LOCATION_ACTION (action), uri);
midori_location_action_set_secondary_icon ( midori_location_action_set_secondary_icon (
MIDORI_LOCATION_ACTION (action), NULL); MIDORI_LOCATION_ACTION (action), GTK_STOCK_INFO);
g_object_notify (G_OBJECT (browser), "uri"); g_object_notify (G_OBJECT (browser), "uri");
} }
@ -446,20 +444,6 @@ midori_view_context_ready_cb (GtkWidget* view,
g_signal_emit (browser, signals[CONTEXT_READY], 0, js_context); g_signal_emit (browser, signals[CONTEXT_READY], 0, js_context);
} }
/*
static void
midori_web_view_news_feed_ready_cb (MidoriWebView* web_view,
const gchar* href,
const gchar* type,
const gchar* title,
MidoriBrowser* browser)
{
if (web_view == (MidoriWebView*)midori_browser_get_current_web_view (browser))
midori_location_action_set_secondary_icon (MIDORI_LOCATION_ACTION (
_action_by_name (browser, "Location")), STOCK_NEWS_FEED);
}
*/
static void static void
midori_view_notify_title_cb (GtkWidget* view, midori_view_notify_title_cb (GtkWidget* view,
GParamSpec* pspec, GParamSpec* pspec,
@ -1135,8 +1119,6 @@ _midori_browser_add_tab (MidoriBrowser* browser,
midori_view_notify_progress_cb, browser, midori_view_notify_progress_cb, browser,
"signal::context-ready", "signal::context-ready",
midori_view_context_ready_cb, browser, midori_view_context_ready_cb, browser,
/* "signal::news-feed-ready",
midori_view_news_feed_ready_cb, browser, */
"signal::notify::title", "signal::notify::title",
midori_view_notify_title_cb, browser, midori_view_notify_title_cb, browser,
"signal::notify::zoom-level", "signal::notify::zoom-level",
@ -2581,63 +2563,19 @@ _action_location_submit_uri (GtkAction* action,
gtk_widget_grab_focus (midori_browser_get_current_tab (browser)); gtk_widget_grab_focus (midori_browser_get_current_tab (browser));
} }
static void
midori_browser_menu_feed_item_activate_cb (GtkWidget* widget,
MidoriBrowser* browser)
{
const gchar* uri;
uri = g_object_get_data (G_OBJECT (widget), "uri");
midori_browser_set_current_uri (browser, uri);
}
static void static void
_action_location_secondary_icon_released (GtkAction* action, _action_location_secondary_icon_released (GtkAction* action,
GtkWidget* widget, GtkWidget* widget,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
MidoriView* view; GtkWidget* view;
KatzeArray* news_feeds;
GtkWidget* menu;
guint n, i;
KatzeItem* feed;
const gchar* uri;
const gchar* title;
GtkWidget* menuitem;
view = (MidoriView*)midori_browser_get_current_tab (browser); if ((view = midori_browser_get_current_tab (browser)))
if (view)
{ {
news_feeds = NULL /* midori_view_get_news_feeds (view) */; const gchar* uri = midori_view_get_display_uri (MIDORI_VIEW (view));
n = news_feeds ? katze_array_get_length (news_feeds) : 0; /* FIXME: Support a user chosen feed reader */
if (n) if (1)
{ sokoke_spawn_program ("liferea-add-feed", uri);
menu = gtk_menu_new ();
for (i = 0; i < n; i++)
{
if (!(feed = katze_array_get_nth_item (news_feeds, i)))
continue;
uri = katze_item_get_uri (feed);
title = katze_item_get_name (feed);
if (!(title && *title))
title = uri;
menuitem = sokoke_image_menu_item_new_ellipsized (title);
/* FIXME: Get the real icon */
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (
menuitem), gtk_image_new_from_stock (STOCK_NEWS_FEED,
GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
g_object_set_data_full (G_OBJECT (menuitem),
"uri", g_strup ((gchar*)uri), g_free);
g_signal_connect (menuitem, "activate",
G_CALLBACK (midori_browser_menu_feed_item_activate_cb),
browser);
gtk_widget_show (menuitem);
}
sokoke_widget_popup (widget, GTK_MENU (menu), NULL,
SOKOKE_MENU_POSITION_CURSOR);
}
} }
} }

View file

@ -622,31 +622,6 @@ webkit_web_view_progress_changed_cb (WebKitWebView* web_view,
g_object_notify (G_OBJECT (view), "progress"); g_object_notify (G_OBJECT (view), "progress");
} }
/*static void
gjs_value_links_foreach_cb (GjsValue* link,
MidoriView* view)
{
const gchar* type;
if (gjs_value_is_object (link) && gjs_value_has_attribute (link, "href"))
{
if (gjs_value_has_attribute (link, "type"))
{
type = gjs_value_get_attribute_string (link, "type");
if (!strcmp (type, "application/rss+xml")
|| !strcmp (type, "application/x.atom+xml")
|| !strcmp (type, "application/atom+xml"))
{
katze_array_add_item (view->news_feeds, link);
g_signal_emit (view, signals[NEWS_FEED_READY],
gjs_value_get_attribute_string (link, "href"), type,
gjs_value_has_attribute (link, "title")
? gjs_value_get_attribute_string (link, "title") : NULL);
}
}
}
}*/
static void static void
webkit_web_frame_load_done_cb (WebKitWebFrame* web_frame, webkit_web_frame_load_done_cb (WebKitWebFrame* web_frame,
gboolean success, gboolean success,
@ -683,28 +658,29 @@ webkit_web_view_load_finished_cb (WebKitWebView* web_view,
WebKitWebFrame* web_frame, WebKitWebFrame* web_frame,
MidoriView* view) MidoriView* view)
{ {
/* JSContextRef js_context;
GjsValue* value;
GjsValue* document;
GjsValue* links; */
g_object_freeze_notify (G_OBJECT (view)); g_object_freeze_notify (G_OBJECT (view));
view->progress = 1.0; view->progress = 1.0;
g_object_notify (G_OBJECT (view), "progress"); g_object_notify (G_OBJECT (view), "progress");
midori_view_update_load_status (view, MIDORI_LOAD_FINISHED); midori_view_update_load_status (view, MIDORI_LOAD_FINISHED);
g_object_thaw_notify (G_OBJECT (view)); /* FIXME: Do this conditional on whether there's a custom feed reader */
if (1)
{
JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
gchar* value = sokoke_js_script_eval (js_context,
"function feeds (l) { var f = new Array (); for (i in l) "
"{ var t = l[i].type; "
"if (t && (t.indexOf ('rss') != -1 || t.indexOf ('atom') != -1)) "
"f.push (l[i].href); } return f; }"
"feeds (document.getElementsByTagName ('link'))", NULL);
g_object_set_data (G_OBJECT (view), "news-feeds",
value && *value ? (void*)1 : (void*)0);
/* Ensure load-status is notified again, whether it changed or not */
g_object_notify (G_OBJECT (view), "load-status");
}
/* js_context = webkit_web_frame_get_global_context (web_frame); g_object_thaw_notify (G_OBJECT (view));
value = gjs_value_new (js_context, NULL);
document = gjs_value_get_by_name (value, "document");
links = gjs_value_get_elements_by_tag_name (document, "link");
katze_array_clear (view->news_feeds);
gjs_value_foreach (links, (GjsCallback)gjs_value_links_foreach_cb, view);
g_object_unref (links);
g_object_unref (document);
g_object_unref (value); */
} }
static void static void

View file

@ -47,11 +47,14 @@ sokoke_js_string_utf8 (JSStringRef js_string)
return string_utf8; return string_utf8;
} }
JSValueRef gchar*
sokoke_js_script_eval (JSContextRef js_context, sokoke_js_script_eval (JSContextRef js_context,
const gchar* script, const gchar* script,
gchar** exception) gchar** exception)
{ {
gchar* value;
JSStringRef js_value_string;
g_return_val_if_fail (js_context, FALSE); g_return_val_if_fail (js_context, FALSE);
g_return_val_if_fail (script, FALSE); g_return_val_if_fail (script, FALSE);
@ -68,7 +71,11 @@ sokoke_js_script_eval (JSContextRef js_context,
js_value = JSValueMakeNull (js_context); js_value = JSValueMakeNull (js_context);
} }
JSStringRelease (js_script); JSStringRelease (js_script);
return js_value;
js_value_string = JSValueToStringCopy (js_context, js_value, NULL);
value = sokoke_js_string_utf8 (js_value_string);
JSStringRelease (js_value_string);
return value;
} }
static void static void

View file

@ -18,7 +18,7 @@
#include <JavaScriptCore/JavaScript.h> #include <JavaScriptCore/JavaScript.h>
JSValueRef gchar*
sokoke_js_script_eval (JSContextRef js_context, sokoke_js_script_eval (JSContextRef js_context,
const gchar* script, const gchar* script,
gchar** exception); gchar** exception);