aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2005-08-04 04:29:26 +0800
committerChristian Persch <chpe@src.gnome.org>2005-08-04 04:29:26 +0800
commit98c2f091a837f36c61ec7889072f7034687a69bf (patch)
tree9f4b9cbaf8beb0951a582765ec4971d3d90c6acf /src
parent5725b54c776891dfcb522a96a79a145191f470da (diff)
downloadgsoc2013-epiphany-98c2f091a837f36c61ec7889072f7034687a69bf.tar
gsoc2013-epiphany-98c2f091a837f36c61ec7889072f7034687a69bf.tar.gz
gsoc2013-epiphany-98c2f091a837f36c61ec7889072f7034687a69bf.tar.bz2
gsoc2013-epiphany-98c2f091a837f36c61ec7889072f7034687a69bf.tar.lz
gsoc2013-epiphany-98c2f091a837f36c61ec7889072f7034687a69bf.tar.xz
gsoc2013-epiphany-98c2f091a837f36c61ec7889072f7034687a69bf.tar.zst
gsoc2013-epiphany-98c2f091a837f36c61ec7889072f7034687a69bf.zip
Add public function ephy_window_get_context_event() to get the
2005-08-03 Christian Persch <chpe@cvs.gnome.org> * src/ephy-window.c: (popup_menu_at_coords), (idle_unref_context_event), (set_context_event), (embed_popup_deactivate_cb), (get_name_from_address_value), (show_embed_popup), (ephy_window_dispose), (ephy_window_get_is_print_preview), (ephy_window_get_context_event): * src/ephy-window.h: * src/epiphany.defs: * src/popup-commands.c: (popup_cmd_link_in_new_window), (popup_cmd_link_in_new_tab), (popup_cmd_bookmark_link), (popup_cmd_copy_link_address), (save_property_url), (popup_cmd_open_link), (popup_cmd_set_image_as_background), (popup_cmd_copy_image_location), (popup_cmd_open_image): Add public function ephy_window_get_context_event() to get the EphyEmbedEvent for the current popup menu, instead of using an undocument g_object_get_data() call. Also fixes bug #310910. Don't printf NULL; fixes bug #309796.
Diffstat (limited to 'src')
-rw-r--r--src/ephy-window.c98
-rw-r--r--src/ephy-window.h2
-rw-r--r--src/epiphany.defs13
-rw-r--r--src/popup-commands.c81
4 files changed, 130 insertions, 64 deletions
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 7da565a2e..c8df7dc6f 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -423,6 +423,8 @@ struct _EphyWindowPrivate
guint help_message_cid;
EphyEmbedChrome chrome;
guint idle_resize_handler;
+ EphyEmbedEvent *context_event;
+ guint idle_worker;
guint browse_with_caret_notifier_id;
guint allow_popups_notifier_id;
@@ -1541,30 +1543,79 @@ static void
popup_menu_at_coords (GtkMenu *menu, gint *x, gint *y, gboolean *push_in,
gpointer user_data)
{
- GtkWidget *window = GTK_WIDGET (user_data);
- EphyEmbedEvent *event;
+ EphyWindow *window = EPHY_WINDOW (user_data);
+ EphyWindowPrivate *priv = window->priv;
guint ux, uy;
- event = g_object_get_data (G_OBJECT (window), "context_event");
- g_return_if_fail (event != NULL);
+ g_return_if_fail (priv->context_event != NULL);
- ephy_embed_event_get_coords (event, &ux, &uy);
+ ephy_embed_event_get_coords (priv->context_event, &ux, &uy);
*x = ux; *y = uy;
/* FIXME: better position the popup within the window bounds? */
- ephy_gui_sanitise_popup_position (menu, window, x, y);
+ ephy_gui_sanitise_popup_position (menu, GTK_WIDGET (window), x, y);
*push_in = TRUE;
}
+static gboolean
+idle_unref_context_event (EphyWindow *window)
+{
+ EphyWindowPrivate *priv = window->priv;
+
+ LOG ("Idle unreffing context event %p", priv->context_event);
+
+ if (priv->context_event != NULL)
+ {
+ g_object_unref (priv->context_event);
+ priv->context_event = NULL;
+ }
+
+ priv->idle_worker = 0;
+ return FALSE;
+}
+
static void
-hide_embed_popup_cb (GtkWidget *popup,
- EphyWindow *window)
+set_context_event (EphyWindow *window,
+ EphyEmbedEvent *event)
{
+ EphyWindowPrivate *priv = window->priv;
+
+ if (priv->idle_worker != 0)
+ {
+ g_source_remove (priv->idle_worker);
+ priv->idle_worker = 0;
+ }
+
+ if (priv->context_event != NULL)
+ {
+ g_object_unref (priv->context_event);
+ }
+
+ priv->context_event = event != NULL ? g_object_ref (event) : NULL;
+}
+
+static void
+embed_popup_deactivate_cb (GtkWidget *popup,
+ EphyWindow *window)
+{
+ EphyWindowPrivate *priv = window->priv;
+
+ LOG ("Deactivating popup menu");
+
enable_edit_actions_sensitivity (window);
g_signal_handlers_disconnect_by_func
- (popup, G_CALLBACK (hide_embed_popup_cb), window);
+ (popup, G_CALLBACK (embed_popup_deactivate_cb), window);
+
+ /* Unref the event from idle since we still need it
+ * from the action callbacks which will run before idle.
+ */
+ if (priv->idle_worker == 0)
+ {
+ priv->idle_worker =
+ g_idle_add ((GSourceFunc) idle_unref_context_event, window);
+ }
}
static char *
@@ -1580,7 +1631,7 @@ get_name_from_address_value (const GValue *value)
gnome_vfs_uri_unref (uri);
}
- return name;
+ return name != NULL ? name : g_strdup (_("None"));
}
static void
@@ -1766,12 +1817,10 @@ show_embed_popup (EphyWindow *window,
action = gtk_action_group_get_action (action_group, "OpenLinkInNewTab");
ephy_action_change_sensitivity_flags (action, SENS_FLAG_CONTEXT, !can_open_in_new);
- g_object_set_data_full (G_OBJECT (window), "context_event",
- g_object_ref (event),
- (GDestroyNotify)g_object_unref);
+ set_context_event (window, event);
- g_signal_connect (widget, "hide",
- G_CALLBACK (hide_embed_popup_cb), window);
+ g_signal_connect (widget, "deactivate",
+ G_CALLBACK (embed_popup_deactivate_cb), window);
button = ephy_embed_event_get_button (event);
if (button == 0)
@@ -2381,6 +2430,8 @@ ephy_window_dispose (GObject *object)
g_object_unref (priv->manager);
priv->manager = NULL;
+
+ set_context_event (window, NULL);
}
destroy_fullscreen_popup (window);
@@ -3425,3 +3476,20 @@ ephy_window_get_is_print_preview (EphyWindow *window)
return window->priv->ppv_mode;
}
+
+/**
+ * ephy_window_get_context_event:
+ * @window: an #EphyWindow
+ *
+ * Returns the #EphyEmbedEvent for the current context menu.
+ * Use this to get the event from the action callback.
+ *
+ * Return value: an #EphyEmbedEvent, or %NULL
+ **/
+EphyEmbedEvent *
+ephy_window_get_context_event (EphyWindow *window)
+{
+ g_return_val_if_fail (EPHY_IS_WINDOW (window), NULL);
+
+ return window->priv->context_event;
+}
diff --git a/src/ephy-window.h b/src/ephy-window.h
index 8a58e9ea1..48253bb75 100644
--- a/src/ephy-window.h
+++ b/src/ephy-window.h
@@ -105,6 +105,8 @@ gboolean ephy_window_get_is_popup (EphyWindow *window);
gboolean ephy_window_get_is_print_preview(EphyWindow *window);
+EphyEmbedEvent *ephy_window_get_context_event (EphyWindow *window);
+
G_END_DECLS
#endif
diff --git a/src/epiphany.defs b/src/epiphany.defs
index 4f0afed07..4f5820334 100644
--- a/src/epiphany.defs
+++ b/src/epiphany.defs
@@ -211,13 +211,6 @@
(gtype-id "EPHY_TYPE_WINDOW")
)
-(define-object MozillaEmbedEvent
- (in-module "Mozilla")
- (parent "GObject")
- (c-name "MozillaEmbedEvent")
- (gtype-id "MOZILLA_TYPE_EMBED_EVENT")
-)
-
;; Enumerations and flags ...
(define-flags EmbedEventContext
@@ -3331,6 +3324,12 @@
(return-type "gboolean")
)
+(define-method get_context_event
+ (of-object "EphyWindow")
+ (c-name "ephy_window_get_context_event")
+ (return-type "EphyEmbedEvent*")
+)
+
;; From ../embed/ephy-embed-type-builtins.h
diff --git a/src/popup-commands.c b/src/popup-commands.c
index 38b38351a..a637241cd 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -38,31 +38,20 @@
#include <libgnomevfs/gnome-vfs-ops.h>
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
-static EphyEmbedEvent *
-get_event_info (EphyWindow *window)
-{
- EphyEmbedEvent *info;
-
- info = EPHY_EMBED_EVENT (g_object_get_data
- (G_OBJECT (window), "context_event"));
- g_return_val_if_fail (info != NULL, NULL);
-
- return info;
-}
-
void
popup_cmd_link_in_new_window (GtkAction *action,
EphyWindow *window)
{
- EphyEmbedEvent *info;
+ EphyEmbedEvent *event;
EphyTab *tab;
const GValue *value;
tab = ephy_window_get_active_tab (window);
- info = get_event_info (window);
+ event = ephy_window_get_context_event (window);
+ g_return_if_fail (event != NULL);
- ephy_embed_event_get_property (info, "link", &value);
+ ephy_embed_event_get_property (event, "link", &value);
ephy_shell_new_tab (ephy_shell, NULL, tab,
g_value_get_string (value),
@@ -74,15 +63,16 @@ void
popup_cmd_link_in_new_tab (GtkAction *action,
EphyWindow *window)
{
- EphyEmbedEvent *info;
+ EphyEmbedEvent *event;
EphyTab *tab;
const GValue *value;
tab = ephy_window_get_active_tab (window);
- info = get_event_info (window);
+ event = ephy_window_get_context_event (window);
+ g_return_if_fail (event != NULL);
- ephy_embed_event_get_property (info, "link", &value);
+ ephy_embed_event_get_property (event, "link", &value);
ephy_shell_new_tab (ephy_shell, window, tab,
g_value_get_string (value),
@@ -96,7 +86,7 @@ popup_cmd_bookmark_link (GtkAction *action,
{
GtkWidget *new_bookmark;
EphyBookmarks *bookmarks;
- EphyEmbedEvent *info;
+ EphyEmbedEvent *event;
const GValue *link_title;
const GValue *link_rel;
const GValue *link;
@@ -107,13 +97,14 @@ popup_cmd_bookmark_link (GtkAction *action,
const char *rel;
gboolean is_smart;
- info = get_event_info (window);
+ event = ephy_window_get_context_event (window);
+ g_return_if_fail (event != NULL);
- ephy_embed_event_get_property (info, "link_is_smart", &link_is_smart);
- ephy_embed_event_get_property (info, "link", &link);
- ephy_embed_event_get_property (info, "link_title", &link_title);
- ephy_embed_event_get_property (info, "link_rel", &link_rel);
- ephy_embed_event_get_property (info, "linktext", &linktext);
+ ephy_embed_event_get_property (event, "link_is_smart", &link_is_smart);
+ ephy_embed_event_get_property (event, "link", &link);
+ ephy_embed_event_get_property (event, "link_title", &link_title);
+ ephy_embed_event_get_property (event, "link_rel", &link_rel);
+ ephy_embed_event_get_property (event, "linktext", &linktext);
location = g_value_get_string (link);
g_return_if_fail (location);
@@ -164,8 +155,8 @@ popup_cmd_copy_link_address (GtkAction *action,
const char *address;
const GValue *value;
- event = get_event_info (window);
- g_return_if_fail (EPHY_IS_EMBED_EVENT (event));
+ event = ephy_window_get_context_event (window);
+ g_return_if_fail (event != NULL);
context = ephy_embed_event_get_context (event);
@@ -190,17 +181,19 @@ save_property_url (GtkAction *action,
gboolean ask_dest,
const char *property)
{
- EphyEmbedEvent *info;
+ EphyEmbedEvent *event;
const char *location;
const GValue *value;
EphyEmbedPersist *persist;
EphyEmbed *embed;
+ event = ephy_window_get_context_event (window);
+ g_return_if_fail (event != NULL);
+
embed = ephy_window_get_active_embed (window);
g_return_if_fail (embed != NULL);
- info = get_event_info (window);
- ephy_embed_event_get_property (info, property, &value);
+ ephy_embed_event_get_property (event, property, &value);
location = g_value_get_string (value);
persist = EPHY_EMBED_PERSIST
@@ -224,7 +217,7 @@ void
popup_cmd_open_link (GtkAction *action,
EphyWindow *window)
{
- EphyEmbedEvent *info;
+ EphyEmbedEvent *event;
const char *location;
const GValue *value;
EphyEmbed *embed;
@@ -232,8 +225,8 @@ popup_cmd_open_link (GtkAction *action,
embed = ephy_window_get_active_embed (window);
g_return_if_fail (embed != NULL);
- info = get_event_info (window);
- ephy_embed_event_get_property (info, "link", &value);
+ event = ephy_window_get_context_event (window);
+ ephy_embed_event_get_property (event, "link", &value);
location = g_value_get_string (value);
ephy_embed_load_url (embed, location);
@@ -293,18 +286,20 @@ void
popup_cmd_set_image_as_background (GtkAction *action,
EphyWindow *window)
{
- EphyEmbedEvent *info;
+ EphyEmbedEvent *event;
const char *location;
char *dest, *base, *base_converted;
const GValue *value;
EphyEmbedPersist *persist;
EphyEmbed *embed;
+ event = ephy_window_get_context_event (window);
+ g_return_if_fail (event != NULL);
+
embed = ephy_window_get_active_embed (window);
g_return_if_fail (embed != NULL);
- info = get_event_info (window);
- ephy_embed_event_get_property (info, "image", &value);
+ ephy_embed_event_get_property (event, "image", &value);
location = g_value_get_string (value);
persist = EPHY_EMBED_PERSIST
@@ -334,12 +329,12 @@ void
popup_cmd_copy_image_location (GtkAction *action,
EphyWindow *window)
{
- EphyEmbedEvent *info;
+ EphyEmbedEvent *event;
const char *location;
const GValue *value;
- info = get_event_info (window);
- ephy_embed_event_get_property (info, "image", &value);
+ event = ephy_window_get_context_event (window);
+ ephy_embed_event_get_property (event, "image", &value);
location = g_value_get_string (value);
popup_cmd_copy_to_clipboard (window, location);
}
@@ -442,17 +437,19 @@ void
popup_cmd_open_image (GtkAction *action,
EphyWindow *window)
{
- EphyEmbedEvent *info;
+ EphyEmbedEvent *event;
const char *address;
char *scheme;
const GValue *value;
EphyEmbed *embed;
+ event = ephy_window_get_context_event (window);
+ g_return_if_fail (event != NULL);
+
embed = ephy_window_get_active_embed (window);
g_return_if_fail (embed != NULL);
- info = get_event_info (window);
- ephy_embed_event_get_property (info, "image", &value);
+ ephy_embed_event_get_property (event, "image", &value);
address = g_value_get_string (value);
scheme = gnome_vfs_get_uri_scheme (address);