Pass news feed icon clicks to the feed panel

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.
This commit is contained in:
Christian Dywan 2009-08-16 23:35:29 +02:00
parent 883007c05d
commit 04dc7fe855
3 changed files with 48 additions and 14 deletions

View file

@ -66,6 +66,11 @@ feed_app_add_browser_cb (MidoriApp* app,
MidoriBrowser* browser, MidoriBrowser* browser,
MidoriExtension* extension); MidoriExtension* extension);
static gboolean
secondary_icon_released_cb (GtkAction* action,
GtkWidget* widget,
FeedPrivate* priv);
static void static void
feed_deactivate_cb (MidoriExtension* extension, feed_deactivate_cb (MidoriExtension* extension,
FeedPrivate* priv) FeedPrivate* priv)
@ -73,6 +78,13 @@ feed_deactivate_cb (MidoriExtension* extension,
if (priv) if (priv)
{ {
MidoriApp* app = midori_extension_get_app (extension); 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, g_signal_handlers_disconnect_by_func (app,
feed_app_add_browser_cb, extension); feed_app_add_browser_cb, extension);
@ -292,28 +304,38 @@ update_feeds (FeedPrivate* priv)
return TRUE; return TRUE;
} }
static void static gboolean
secondary_icon_released_cb (GtkAction* action, secondary_icon_released_cb (GtkAction* action,
GtkWidget* widget, GtkWidget* widget,
FeedPrivate* priv) FeedPrivate* priv)
{ {
const gchar* uri; GtkWidget* view;
g_assert (KATZE_IS_ARRAY (priv->feeds)); 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 ((view = midori_browser_get_current_tab (priv->browser)))
{
const gchar* uri;
uri = g_object_get_data (G_OBJECT (view), "news-feeds");
if (uri && *uri) if (uri && *uri)
{ {
KatzeArray* feed; KatzeArray* feed;
feed = feed_add_item (priv->feeds, uri); if ((feed = feed_add_item (priv->feeds, uri)))
if (feed)
{ {
/* FIXME: Let the user know that a feed was added */
feed_save_items (priv->extension, priv->feeds); feed_save_items (priv->extension, priv->feeds);
update_feed (priv, KATZE_ITEM (feed)); update_feed (priv, KATZE_ITEM (feed));
return TRUE;
} }
} }
}
return FALSE;
} }
static void static void

View file

@ -3215,7 +3215,7 @@ _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 static gboolean
_action_location_secondary_icon_released (GtkAction* action, _action_location_secondary_icon_released (GtkAction* action,
GtkWidget* widget, GtkWidget* widget,
MidoriBrowser* browser) MidoriBrowser* browser)
@ -3245,7 +3245,10 @@ _action_location_secondary_icon_released (GtkAction* action,
} }
else else
_action_location_submit_uri (action, uri, FALSE, browser); _action_location_submit_uri (action, uri, FALSE, browser);
return TRUE;
} }
return FALSE;
} }
static void static void
@ -4887,7 +4890,7 @@ midori_browser_init (MidoriBrowser* browser)
_action_location_reset_uri, browser, _action_location_reset_uri, browser,
"signal::submit-uri", "signal::submit-uri",
_action_location_submit_uri, browser, _action_location_submit_uri, browser,
"signal::secondary-icon-released", "signal-after::secondary-icon-released",
_action_location_secondary_icon_released, browser, _action_location_secondary_icon_released, browser,
NULL); NULL);
gtk_action_group_add_action_with_accel (browser->action_group, gtk_action_group_add_action_with_accel (browser->action_group,

View file

@ -153,14 +153,23 @@ midori_location_action_class_init (MidoriLocationActionClass* class)
g_cclosure_marshal_VOID__VOID, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0); 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", signals[SECONDARY_ICON_RELEASED] = g_signal_new ("secondary-icon-released",
G_TYPE_FROM_CLASS (class), G_TYPE_FROM_CLASS (class),
(GSignalFlags) (G_SIGNAL_RUN_LAST), (GSignalFlags) (G_SIGNAL_RUN_LAST),
0, 0,
0, g_signal_accumulator_true_handled,
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT, midori_cclosure_marshal_BOOLEAN__OBJECT,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN, 1,
GTK_TYPE_WIDGET); GTK_TYPE_WIDGET);
signals[RESET_URI] = g_signal_new ("reset-uri", signals[RESET_URI] = g_signal_new ("reset-uri",