]> spindle.queued.net Git - midori/commitdiff
Display the news feed icon again
authorChristian Dywan <christian@twotoasts.de>
Mon, 13 Apr 2009 20:40:57 +0000 (22:40 +0200)
committerChristian Dywan <christian@twotoasts.de>
Mon, 13 Apr 2009 20:40:57 +0000 (22:40 +0200)
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.

midori/midori-browser.c
midori/midori-view.c
midori/sokoke.c
midori/sokoke.h

index caa81ed6c4ba195934cc067e5717fb23f5fbb6ae..33da510adf2b733892796b61a97ee9fa30279502 100644 (file)
@@ -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);
     }
 }
 
index fb1290c32b20e8af5e0e47d665a2f123892e036e..3ac7c3042c3517ba2dc7975b56d7225f302c4835 100644 (file)
@@ -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
index 4303ff40800de6690a29309f968a74ab399932fd..3ef3bc37f8b03bfcb19dd27aee8d75b2ab95b3d3 100644 (file)
@@ -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
index 72f1305eae8bbd832128a2cb80bdf7a84e147008..0360ab1fa9f5e8ad7bdae1408fa87eef9de743cf 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <JavaScriptCore/JavaScript.h>
 
-JSValueRef
+gchar*
 sokoke_js_script_eval (JSContextRef js_context,
                        const gchar* script,
                        gchar**      exception);