]> spindle.queued.net Git - midori/commitdiff
Pass news feed icon clicks to the feed panel
authorChristian Dywan <christian@twotoasts.de>
Sun, 16 Aug 2009 21:35:29 +0000 (23:35 +0200)
committerChristian Dywan <christian@twotoasts.de>
Mon, 17 Aug 2009 00:15:21 +0000 (02:15 +0200)
The secondary-icon-released signal of the location action returns
a boolean now so a callback can indicate that it handled it. So
if the feed panel is active, it adds feeds to the panel and
suppresses the default action.

A possible crash when disabling the panel and clicking the icon
afterwards is fixed by adding a missing signal disconnection.

extensions/feed-panel/main.c
midori/midori-browser.c
midori/midori-locationaction.c

index 7e6c90bdaf111060750f7f4c37619b611a9911d4..7966a81dbcf5b9f48cb47b0cc68a1163943f6986 100644 (file)
@@ -66,6 +66,11 @@ feed_app_add_browser_cb (MidoriApp*       app,
                          MidoriBrowser*   browser,
                          MidoriExtension* extension);
 
+static gboolean
+secondary_icon_released_cb (GtkAction*     action,
+                            GtkWidget*     widget,
+                            FeedPrivate*   priv);
+
 static void
 feed_deactivate_cb (MidoriExtension* extension,
                     FeedPrivate*     priv)
@@ -73,6 +78,13 @@ feed_deactivate_cb (MidoriExtension* extension,
     if (priv)
     {
         MidoriApp* app = midori_extension_get_app (extension);
+        GtkActionGroup* action_group;
+        GtkAction* action;
+
+        action_group = midori_browser_get_action_group (priv->browser);
+        action = gtk_action_group_get_action (action_group, "Location");
+        g_signal_handlers_disconnect_by_func (action,
+                secondary_icon_released_cb, priv);
 
         g_signal_handlers_disconnect_by_func (app,
                 feed_app_add_browser_cb, extension);
@@ -292,28 +304,38 @@ update_feeds (FeedPrivate* priv)
     return TRUE;
 }
 
-static void
+static gboolean
 secondary_icon_released_cb (GtkAction*     action,
                             GtkWidget*     widget,
                             FeedPrivate*   priv)
 {
-    const gchar* uri;
+    GtkWidget* view;
 
     g_assert (KATZE_IS_ARRAY (priv->feeds));
 
-    uri = midori_location_action_get_uri (MIDORI_LOCATION_ACTION (action));
+    if (gtk_window_get_focus (GTK_WINDOW (priv->browser)) == widget)
+        return FALSE;
 
-    if (uri && *uri)
+    if ((view = midori_browser_get_current_tab (priv->browser)))
     {
-        KatzeArray* feed;
+        const gchar* uri;
 
-        feed = feed_add_item (priv->feeds, uri);
-        if (feed)
+        uri = g_object_get_data (G_OBJECT (view), "news-feeds");
+        if (uri && *uri)
         {
-            feed_save_items (priv->extension, priv->feeds);
-            update_feed (priv, KATZE_ITEM (feed));
+            KatzeArray* feed;
+
+            if ((feed = feed_add_item (priv->feeds, uri)))
+            {
+                /* FIXME: Let the user know that a feed was added */
+                feed_save_items (priv->extension, priv->feeds);
+                update_feed (priv, KATZE_ITEM (feed));
+                return TRUE;
+            }
         }
     }
+
+    return FALSE;
 }
 
 static void
index 56736771fdb083ab27ce7ec7f91839fb948e003b..09fb1f1338a0c9b2dea44c65471fb15bd2b177aa 100644 (file)
@@ -3215,7 +3215,7 @@ _action_location_submit_uri (GtkAction*     action,
     gtk_widget_grab_focus (midori_browser_get_current_tab (browser));
 }
 
-static void
+static gboolean
 _action_location_secondary_icon_released (GtkAction*     action,
                                           GtkWidget*     widget,
                                           MidoriBrowser* browser)
@@ -3245,7 +3245,10 @@ _action_location_secondary_icon_released (GtkAction*     action,
         }
         else
             _action_location_submit_uri (action, uri, FALSE, browser);
+        return TRUE;
     }
+
+    return FALSE;
 }
 
 static void
@@ -4887,7 +4890,7 @@ midori_browser_init (MidoriBrowser* browser)
                       _action_location_reset_uri, browser,
                       "signal::submit-uri",
                       _action_location_submit_uri, browser,
-                      "signal::secondary-icon-released",
+                      "signal-after::secondary-icon-released",
                       _action_location_secondary_icon_released, browser,
                       NULL);
     gtk_action_group_add_action_with_accel (browser->action_group,
index a55f252ccbb714f34ff97f7a446853b869b6ad06..6c34e3af9a584f076c5d446a206f673bd09f5b46 100644 (file)
@@ -153,14 +153,23 @@ midori_location_action_class_init (MidoriLocationActionClass* class)
                                        g_cclosure_marshal_VOID__VOID,
                                        G_TYPE_NONE, 0);
 
+    /**
+     * MidoriLocationAction:secondary-icon-released:
+     *
+     * The secondary-icon-released signal is emitted when the mouse button
+     * is released above the secondary icon.
+     *
+     * Since 0.1.10 a signal handler can return %TRUE to stop signal
+     * emission, for instance to suppress default behavior.
+     */
     signals[SECONDARY_ICON_RELEASED] = g_signal_new ("secondary-icon-released",
                                        G_TYPE_FROM_CLASS (class),
                                        (GSignalFlags) (G_SIGNAL_RUN_LAST),
                                        0,
-                                       0,
+                                       g_signal_accumulator_true_handled,
                                        NULL,
-                                       g_cclosure_marshal_VOID__OBJECT,
-                                       G_TYPE_NONE, 1,
+                                       midori_cclosure_marshal_BOOLEAN__OBJECT,
+                                       G_TYPE_BOOLEAN, 1,
                                        GTK_TYPE_WIDGET);
 
     signals[RESET_URI] = g_signal_new ("reset-uri",