diff --git a/midori/midori-browser.c b/midori/midori-browser.c index caa81ed6..33da510a 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -302,15 +302,13 @@ _midori_browser_update_interface (MidoriBrowser* browser) } katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading); - /* FIXME: This won't work due to a bug in GtkIconEntry */ - /* if (view && midori_view_get_news_feeds (MIDORI_VIEW (view))) - gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY ( - gtk_bin_get_child (GTK_BIN (browser->location))), - GTK_ICON_ENTRY_SECONDARY, STOCK_NEWS_FEED); + action = _action_by_name (browser, "Location"); + if (g_object_get_data (G_OBJECT (view), "news-feeds")) + midori_location_action_set_secondary_icon ( + MIDORI_LOCATION_ACTION (action), STOCK_NEWS_FEED); else - gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY ( - gtk_bin_get_child (GTK_BIN (browser->location))), - GTK_ICON_ENTRY_SECONDARY, NULL);*/ + midori_location_action_set_secondary_icon ( + MIDORI_LOCATION_ACTION (action), GTK_STOCK_INFO); } static void @@ -418,7 +416,7 @@ midori_view_notify_load_status_cb (GtkWidget* view, midori_location_action_set_uri ( MIDORI_LOCATION_ACTION (action), uri); 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"); } @@ -446,20 +444,6 @@ midori_view_context_ready_cb (GtkWidget* view, 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 midori_view_notify_title_cb (GtkWidget* view, GParamSpec* pspec, @@ -1135,8 +1119,6 @@ _midori_browser_add_tab (MidoriBrowser* browser, midori_view_notify_progress_cb, browser, "signal::context-ready", midori_view_context_ready_cb, browser, - /* "signal::news-feed-ready", - midori_view_news_feed_ready_cb, browser, */ "signal::notify::title", midori_view_notify_title_cb, browser, "signal::notify::zoom-level", @@ -2581,63 +2563,19 @@ _action_location_submit_uri (GtkAction* action, 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 _action_location_secondary_icon_released (GtkAction* action, GtkWidget* widget, MidoriBrowser* browser) { - MidoriView* view; - KatzeArray* news_feeds; - GtkWidget* menu; - guint n, i; - KatzeItem* feed; - const gchar* uri; - const gchar* title; - GtkWidget* menuitem; + GtkWidget* view; - view = (MidoriView*)midori_browser_get_current_tab (browser); - if (view) + if ((view = midori_browser_get_current_tab (browser))) { - news_feeds = NULL /* midori_view_get_news_feeds (view) */; - n = news_feeds ? katze_array_get_length (news_feeds) : 0; - if (n) - { - 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); - } + const gchar* uri = midori_view_get_display_uri (MIDORI_VIEW (view)); + /* FIXME: Support a user chosen feed reader */ + if (1) + sokoke_spawn_program ("liferea-add-feed", uri); } } diff --git a/midori/midori-view.c b/midori/midori-view.c index fb1290c3..3ac7c304 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -622,31 +622,6 @@ webkit_web_view_progress_changed_cb (WebKitWebView* web_view, 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 webkit_web_frame_load_done_cb (WebKitWebFrame* web_frame, gboolean success, @@ -683,28 +658,29 @@ webkit_web_view_load_finished_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, MidoriView* view) { - /* JSContextRef js_context; - GjsValue* value; - GjsValue* document; - GjsValue* links; */ - g_object_freeze_notify (G_OBJECT (view)); view->progress = 1.0; g_object_notify (G_OBJECT (view), "progress"); 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); - 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); */ + g_object_thaw_notify (G_OBJECT (view)); } static void diff --git a/midori/sokoke.c b/midori/sokoke.c index 4303ff40..3ef3bc37 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -47,11 +47,14 @@ sokoke_js_string_utf8 (JSStringRef js_string) return string_utf8; } -JSValueRef +gchar* sokoke_js_script_eval (JSContextRef js_context, const gchar* script, gchar** exception) { + gchar* value; + JSStringRef js_value_string; + g_return_val_if_fail (js_context, FALSE); g_return_val_if_fail (script, FALSE); @@ -68,7 +71,11 @@ sokoke_js_script_eval (JSContextRef js_context, js_value = JSValueMakeNull (js_context); } 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 diff --git a/midori/sokoke.h b/midori/sokoke.h index 72f1305e..0360ab1f 100644 --- a/midori/sokoke.h +++ b/midori/sokoke.h @@ -18,7 +18,7 @@ #include -JSValueRef +gchar* sokoke_js_script_eval (JSContextRef js_context, const gchar* script, gchar** exception);