diff options
author | Xan Lopez <xan@src.gnome.org> | 2007-10-26 04:00:34 +0800 |
---|---|---|
committer | Xan Lopez <xan@src.gnome.org> | 2007-10-26 04:00:34 +0800 |
commit | 929c43cd4cadadb2d1ddc26fd2d0500867d9ea75 (patch) | |
tree | 29f40b4ed449ca09cc3fff1639562fabc9e76212 | |
parent | 51a7dc7dd4e0871d0da50228a163a1b124aeda1c (diff) | |
download | gsoc2013-epiphany-929c43cd4cadadb2d1ddc26fd2d0500867d9ea75.tar gsoc2013-epiphany-929c43cd4cadadb2d1ddc26fd2d0500867d9ea75.tar.gz gsoc2013-epiphany-929c43cd4cadadb2d1ddc26fd2d0500867d9ea75.tar.bz2 gsoc2013-epiphany-929c43cd4cadadb2d1ddc26fd2d0500867d9ea75.tar.lz gsoc2013-epiphany-929c43cd4cadadb2d1ddc26fd2d0500867d9ea75.tar.xz gsoc2013-epiphany-929c43cd4cadadb2d1ddc26fd2d0500867d9ea75.tar.zst gsoc2013-epiphany-929c43cd4cadadb2d1ddc26fd2d0500867d9ea75.zip |
Move status-message and logic of link-message to EphyEmbed.
Create a property for link-message in EphyEmbed too.
svn path=/trunk/; revision=7560
-rw-r--r-- | embed/ephy-embed.c | 37 | ||||
-rw-r--r-- | embed/ephy-embed.h | 8 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed.cpp | 322 | ||||
-rw-r--r-- | src/ephy-tab.c | 362 |
4 files changed, 357 insertions, 372 deletions
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index ae6ea6d74..882c9bfd6 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -485,7 +485,18 @@ ephy_embed_base_init (gpointer g_class) "The embed's title", _("Blank page"), G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - + g_object_interface_install_property (g_class, + g_param_spec_string ("status message", + "Status Message", + "The embed's statusbar message", + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); + g_object_interface_install_property (g_class, + g_param_spec_string ("link-message", + "Link Message", + "The embed's link message", + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); initialized = TRUE; } @@ -685,7 +696,7 @@ ephy_embed_get_location (EphyEmbed *embed, * * Return value: the URL of the link over which the mouse is hovering **/ -char * +const char * ephy_embed_get_link_message (EphyEmbed *embed) { EphyEmbedIface *iface = EPHY_EMBED_GET_IFACE (embed); @@ -1196,3 +1207,25 @@ ephy_embed_get_address (EphyEmbed *embed) return iface->get_address (embed); } +/** + * ephy_embed_get_status_message: + * @embed: an #EphyEmbed + * + * Returns the message displayed in @embed's #EphyWindow's + * #EphyStatusbar. If the user is hovering the mouse over a hyperlink, + * this function will return the same value as + * ephy_embed_get_link_message(). Otherwise, it will return a network + * status message, or NULL. + * + * The message returned has a limited lifetime, and so should be copied with + * g_strdup() if it must be stored. + * + * Return value: The current statusbar message + **/ +const char * +ephy_embed_get_status_message (EphyEmbed *embed) +{ + EphyEmbedIface *iface = EPHY_EMBED_GET_IFACE (embed); + return iface->get_status_message (embed); +} + diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h index 70058eec6..0dc9cfa72 100644 --- a/embed/ephy-embed.h +++ b/embed/ephy-embed.h @@ -199,7 +199,7 @@ struct _EphyEmbedIface const char * (* get_title) (EphyEmbed *embed); char * (* get_location) (EphyEmbed *embed, gboolean toplevel); - char * (* get_link_message) (EphyEmbed *embed); + const char * (* get_link_message) (EphyEmbed *embed); char * (* get_js_status) (EphyEmbed *embed); int (* shistory_n_items) (EphyEmbed *embed); void (* shistory_get_nth) (EphyEmbed *embed, @@ -251,6 +251,7 @@ struct _EphyEmbedIface const char *address, EphyEmbedAddressExpire expire); const char * (* get_address) (EphyEmbed *embed); + const char * (* get_status_message) (EphyEmbed *embed); }; GType ephy_embed_net_state_get_type (void); @@ -283,7 +284,7 @@ const char *ephy_embed_get_title (EphyEmbed *embed); char *ephy_embed_get_location (EphyEmbed *embed, gboolean toplevel); -char *ephy_embed_get_link_message (EphyEmbed *embed); +const char *ephy_embed_get_link_message (EphyEmbed *embed); char *ephy_embed_get_js_status (EphyEmbed *embed); @@ -364,6 +365,9 @@ void ephy_embed_set_typed_address (EphyEmbed *embed, /* Address */ const char * ephy_embed_get_address (EphyEmbed *embed); +/* Status messages */ +const char * ephy_embed_get_status_message (EphyEmbed *embed); + /* Encoding */ char *ephy_embed_get_encoding (EphyEmbed *embed); diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp index 7adbcceb6..6f8b5c612 100644 --- a/embed/mozilla/mozilla-embed.cpp +++ b/embed/mozilla/mozilla-embed.cpp @@ -89,8 +89,13 @@ static void mozilla_embed_zoom_change_cb (EphyEmbed *embed, MozillaEmbed *membed); static void mozilla_embed_title_change_cb (EphyEmbed *embed, MozillaEmbed *membed); +static void mozilla_embed_link_message_cb (EphyEmbed *embed, + MozillaEmbed *membed); static void mozilla_embed_set_title (MozillaEmbed *embed, char *title); +static void mozilla_embed_set_loading_title (MozillaEmbed *embed, + const char *title, + gboolean is_address); static void impl_set_typed_address (EphyEmbed *embed, const char *address, EphyEmbedAddressExpire expire); @@ -108,6 +113,8 @@ typedef enum } MozillaEmbedLoadState; #define MAX_TITLE_LENGTH 512 /* characters */ +#define RELOAD_DELAY 250 /* ms */ +#define RELOAD_DELAY_MAX_TICKS 40 /* RELOAD_DELAY * RELOAD_DELAY_MAX_TICKS = 10 s */ struct MozillaEmbedPrivate { @@ -135,6 +142,12 @@ struct MozillaEmbedPrivate int cur_requests; int total_requests; char *status_message; + char *link_message; + + /* File watch */ + GnomeVFSMonitorHandle *monitor; + guint reload_scheduled_id; + guint reload_delay_ticks; }; #define WINDOWWATCHER_CONTRACTID "@mozilla.org/embedcomp/window-watcher;1" @@ -144,10 +157,12 @@ enum PROP_0, PROP_ADDRESS, PROP_DOCUMENT_TYPE, + PROP_LINK_MESSAGE, PROP_LOAD_PROGRESS, PROP_LOAD_STATUS, PROP_NAVIGATION, PROP_SECURITY, + PROP_STATUS_MESSAGE, PROP_TITLE, PROP_TYPED_ADDRESS, PROP_ZOOM @@ -266,6 +281,9 @@ mozilla_embed_get_property (GObject *object, case PROP_ZOOM: g_value_set_float (value, priv->zoom); break; + case PROP_LINK_MESSAGE: + g_value_set_string (value, priv->link_message); + break; case PROP_LOAD_PROGRESS: g_value_set_int (value, priv->load_percent); break; @@ -275,6 +293,9 @@ mozilla_embed_get_property (GObject *object, case PROP_NAVIGATION: g_value_set_flags (value, priv->nav_flags); break; + case PROP_STATUS_MESSAGE: + g_value_set_string (value, priv->status_message); + break; case PROP_TITLE: g_value_set_string (value, priv->title); break; @@ -304,8 +325,10 @@ mozilla_embed_set_property (GObject *object, case PROP_DOCUMENT_TYPE: case PROP_LOAD_PROGRESS: case PROP_LOAD_STATUS: + case PROP_LINK_MESSAGE: case PROP_NAVIGATION: case PROP_SECURITY: + case PROP_STATUS_MESSAGE: case PROP_ZOOM: /* read only */ break; @@ -343,6 +366,8 @@ mozilla_embed_class_init (MozillaEmbedClass *klass) g_object_class_override_property (object_class, PROP_ADDRESS, "address"); g_object_class_override_property (object_class, PROP_TYPED_ADDRESS, "typed-address"); g_object_class_override_property (object_class, PROP_TITLE, "title"); + g_object_class_override_property (object_class, PROP_STATUS_MESSAGE, "message"); + g_object_class_override_property (object_class, PROP_LINK_MESSAGE, "link-message"); g_type_class_add_private (object_class, sizeof(MozillaEmbedPrivate)); } @@ -384,6 +409,9 @@ mozilla_embed_init (MozillaEmbed *embed) g_signal_connect_object (embed, "title", G_CALLBACK (mozilla_embed_title_change_cb), embed, (GConnectFlags) 0); + g_signal_connect_object (embed, "link_message", + G_CALLBACK (mozilla_embed_link_message_cb), + embed, (GConnectFlags)0); priv->document_type = EPHY_EMBED_DOCUMENT_HTML; priv->security_level = EPHY_EMBED_STATE_IS_UNKNOWN; @@ -437,6 +465,8 @@ mozilla_embed_finalize (GObject *object) g_free (embed->priv->typed_address); g_free (embed->priv->title); g_free (embed->priv->loading_title); + g_free (embed->priv->status_message); + g_free (embed->priv->link_message); G_OBJECT_CLASS (mozilla_embed_parent_class)->finalize (object); @@ -629,12 +659,6 @@ impl_get_title (EphyEmbed *embed) } static char * -impl_get_link_message (EphyEmbed *embed) -{ - return gtk_moz_embed_get_link_message (GTK_MOZ_EMBED (embed)); -} - -static char * impl_get_js_status (EphyEmbed *embed) { return gtk_moz_embed_get_js_status (GTK_MOZ_EMBED (embed)); @@ -1101,6 +1125,33 @@ impl_get_address (EphyEmbed *embed) return priv->address ? priv->address : "about:blank"; } +static const char* +impl_get_status_message (EphyEmbed *embed) +{ + MozillaEmbedPrivate *priv = MOZILLA_EMBED (embed)->priv; + + if (priv->link_message && priv->link_message[0] != '\0') + { + return priv->link_message; + } + else if (priv->status_message) + { + return priv->status_message; + } + else + { + return NULL; + } +} + +static const char* +impl_get_link_message (EphyEmbed *embed) +{ + MozillaEmbedPrivate *priv = MOZILLA_EMBED (embed)->priv; + + return priv->link_message; +} + static void mozilla_embed_set_address (MozillaEmbed *embed, char *address) { @@ -1127,14 +1178,272 @@ mozilla_embed_set_address (MozillaEmbed *embed, char *address) } static void +mozilla_embed_file_monitor_cancel (MozillaEmbed *embed) +{ + MozillaEmbedPrivate *priv = embed->priv; + + if (priv->monitor != NULL) + { + LOG ("Cancelling file monitor"); + + gnome_vfs_monitor_cancel (priv->monitor); + priv->monitor = NULL; + } + + if (priv->reload_scheduled_id != 0) + { + LOG ("Cancelling scheduled reload"); + + g_source_remove (priv->reload_scheduled_id); + priv->reload_scheduled_id = 0; + } + + priv->reload_delay_ticks = 0; +} + +static gboolean +ephy_file_monitor_reload_cb (MozillaEmbed *embed) +{ + MozillaEmbedPrivate *priv = embed->priv; + + if (priv->reload_delay_ticks > 0) + { + priv->reload_delay_ticks--; + + /* Run again */ + return TRUE; + } + + if (priv->is_loading) + { + /* Wait a bit to reload if we're still loading! */ + priv->reload_delay_ticks = RELOAD_DELAY_MAX_TICKS / 2; + + /* Run again */ + return TRUE; + } + + priv->reload_scheduled_id = 0; + + LOG ("Reloading file '%s'", impl_get_address (embed)); + + impl_reload (EPHY_EMBED (embed), TRUE); + + /* don't run again */ + return FALSE; +} + +static void +mozilla_embed_file_monitor_cb (GnomeVFSMonitorHandle *handle, + const gchar *monitor_uri, + const gchar *info_uri, + GnomeVFSMonitorEventType event_type, + MozillaEmbed *embed) +{ + gboolean uri_is_directory; + gboolean should_reload; + char* local_path; + MozillaEmbedPrivate *priv = embed->priv; + + LOG ("File '%s' has changed, scheduling reload", monitor_uri); + + local_path = gnome_vfs_get_local_path_from_uri(monitor_uri); + uri_is_directory = g_file_test(local_path, G_FILE_TEST_IS_DIR); + g_free(local_path); + + switch (event_type) + { + /* These events will always trigger a reload: */ + case GNOME_VFS_MONITOR_EVENT_CHANGED: + case GNOME_VFS_MONITOR_EVENT_CREATED: + should_reload = TRUE; + break; + + /* These events will only trigger a reload for directories: */ + case GNOME_VFS_MONITOR_EVENT_DELETED: + case GNOME_VFS_MONITOR_EVENT_METADATA_CHANGED: + should_reload = uri_is_directory; + break; + + /* These events don't trigger a reload: */ + case GNOME_VFS_MONITOR_EVENT_STARTEXECUTING: + case GNOME_VFS_MONITOR_EVENT_STOPEXECUTING: + default: + should_reload = FALSE; + break; + } + + if (should_reload) { + /* We make a lot of assumptions here, but basically we know + * that we just have to reload, by construction. + * Delay the reload a little bit so we don't endlessly + * reload while a file is written. + */ + if (priv->reload_delay_ticks == 0) + { + priv->reload_delay_ticks = 1; + } + else + { + /* Exponential backoff */ + priv->reload_delay_ticks = MIN (priv->reload_delay_ticks * 2, + RELOAD_DELAY_MAX_TICKS); + } + + if (priv->reload_scheduled_id == 0) + { + priv->reload_scheduled_id = + g_timeout_add (RELOAD_DELAY, + (GSourceFunc) ephy_file_monitor_reload_cb, embed); + } + } +} + +static void +mozilla_embed_update_file_monitor (MozillaEmbed *embed, + const gchar *address) +{ + MozillaEmbedPrivate *priv = embed->priv; + GnomeVFSMonitorHandle *handle = NULL; + gboolean local; + char* local_path; + GnomeVFSMonitorType monitor_type; + + if (priv->monitor != NULL && + priv->address != NULL && address != NULL && + strcmp (priv->address, address) == 0) + + { + /* same address, no change needed */ + return; + } + + mozilla_embed_file_monitor_cancel (embed); + + local = g_str_has_prefix (address, "file://"); + if (local == FALSE) return; + + local_path = gnome_vfs_get_local_path_from_uri(address); + monitor_type = g_file_test(local_path, G_FILE_TEST_IS_DIR) + ? GNOME_VFS_MONITOR_DIRECTORY + : GNOME_VFS_MONITOR_FILE; + g_free(local_path); + + if (gnome_vfs_monitor_add (&handle, address, + monitor_type, + (GnomeVFSMonitorCallback) mozilla_embed_file_monitor_cb, + embed) == GNOME_VFS_OK) + { + LOG ("Installed monitor for file '%s'", address); + + priv->monitor = handle; + } +} + +static void +mozilla_embed_set_link_message (MozillaEmbed *embed, + char *link_message) +{ + char *status_message; + char **splitted_message; + MozillaEmbedPrivate *priv = embed->priv; + + g_free (priv->link_message); + status_message = ephy_string_blank_chr (link_message); + + if (status_message && g_str_has_prefix (status_message, "mailto:")) + { + int i = 1; + char *p; + GString *tmp; + + /* We first want to eliminate all the things after "?", like + * cc, subject and alike. + */ + + p = strchr (status_message, '?'); + if (p != NULL) *p = '\0'; + + /* Then we also want to check if there is more than an email address + * in the mailto: list. + */ + + splitted_message = g_strsplit_set (status_message, ";", -1); + tmp = g_string_new (g_strdup_printf (_("Send an email message to “%s”"), + (splitted_message[0] + 7))); + + while (splitted_message [i] != NULL) + { + g_string_append_printf (tmp, ", “%s”", splitted_message[i]); + i++; + } + + priv->link_message = g_string_free (tmp, FALSE); + + g_free (status_message); + g_strfreev (splitted_message); + } + else + { + priv->link_message = status_message; + } + + g_object_notify (G_OBJECT (embed), "status-message"); + g_object_notify (G_OBJECT (embed), "link-message"); +} + +static void mozilla_embed_location_changed_cb (GtkMozEmbed *embed, MozillaEmbed *membed) { char *location; + GObject *object = G_OBJECT (embed); location = gtk_moz_embed_get_location (embed); g_signal_emit_by_name (membed, "ge_location", location); g_free (location); + + g_object_freeze_notify (object); + + /* do this up here so we still have the old address around */ + mozilla_embed_update_file_monitor (membed, location); + + /* Do not expose about:blank to the user, an empty address + bar will do better */ + if (location == NULL || location[0] == '\0' || + strcmp (location, "about:blank") == 0) + { + mozilla_embed_set_address (membed, NULL); + mozilla_embed_set_title (membed, NULL); + } + else + { + char *embed_address; + + /* we do this to get rid of an eventual password in the URL */ + embed_address = impl_get_location (EPHY_EMBED (embed), TRUE); + mozilla_embed_set_address (membed, embed_address); + mozilla_embed_set_loading_title (membed, embed_address, TRUE); + } + + mozilla_embed_set_link_message (membed, NULL); +#if 0 + mozilla_embed_set_icon_address (embed, NULL); +#endif + mozilla_embed_update_navigation_flags (membed); + + g_object_notify (object, "title"); + + g_object_thaw_notify (object); +} + +static void +mozilla_embed_link_message_cb (EphyEmbed *embed, + MozillaEmbed *membed) +{ + char *link_message = gtk_moz_embed_get_link_message (GTK_MOZ_EMBED (membed)); + mozilla_embed_set_link_message (membed, link_message); + g_free (link_message); } static gboolean @@ -1872,6 +2181,7 @@ ephy_embed_iface_init (EphyEmbedIface *iface) iface->get_typed_address = impl_get_typed_address; iface->set_typed_address = impl_set_typed_address; iface->get_address = impl_get_address; + iface->get_status_message = impl_get_status_message; } static void diff --git a/src/ephy-tab.c b/src/ephy-tab.c index 58637ab5b..57e4137ae 100644 --- a/src/ephy-tab.c +++ b/src/ephy-tab.c @@ -73,15 +73,11 @@ #define EPHY_TAB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TAB, EphyTabPrivate)) #define MAX_HIDDEN_POPUPS 5 -#define RELOAD_DELAY 250 /* ms */ -#define RELOAD_DELAY_MAX_TICKS 40 /* RELOAD_DELAY * RELOAD_DELAY_MAX_TICKS = 10 s */ struct _EphyTabPrivate { guint id; - char *status_message; - char *link_message; char *icon_address; GdkPixbuf *icon; int width; @@ -89,11 +85,6 @@ struct _EphyTabPrivate GSList *hidden_popups; GSList *shown_popups; guint idle_resize_handler; - - /* File watch */ - GnomeVFSMonitorHandle *monitor; - guint reload_scheduled_id; - guint reload_delay_ticks; }; static void ephy_tab_class_init (EphyTabClass *klass); @@ -106,7 +97,6 @@ enum PROP_0, PROP_ICON, PROP_ICON_ADDRESS, - PROP_MESSAGE, PROP_HIDDEN_POPUP_COUNT, PROP_POPUPS_ALLOWED, }; @@ -129,8 +119,6 @@ static GArray *tabs_id_array = NULL; static guint n_tabs = 0; /* internal functions, accessible only from this file */ -static void ephy_tab_set_link_message (EphyTab *tab, - char *message); static guint popup_blocker_n_hidden (EphyTab *tab); static gboolean ephy_tab_get_popups_allowed (EphyTab *tab); static void ephy_tab_set_popups_allowed (EphyTab *tab, @@ -196,7 +184,6 @@ ephy_tab_set_property (GObject *object, ephy_tab_set_icon_address (tab, g_value_get_string (value)); break; case PROP_ICON: - case PROP_MESSAGE: case PROP_HIDDEN_POPUP_COUNT: /* read only */ break; @@ -220,9 +207,6 @@ ephy_tab_get_property (GObject *object, case PROP_ICON_ADDRESS: g_value_set_string (value, priv->icon_address); break; - case PROP_MESSAGE: - g_value_set_string (value, ephy_tab_get_status_message (tab)); - break; case PROP_HIDDEN_POPUP_COUNT: g_value_set_int (value, popup_blocker_n_hidden (tab)); break; @@ -339,14 +323,6 @@ ephy_tab_class_init (EphyTabClass *class) (G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB))); g_object_class_install_property (object_class, - PROP_MESSAGE, - g_param_spec_string ("message", - "Message", - "The tab's statusbar message", - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_HIDDEN_POPUP_COUNT, g_param_spec_int ("hidden-popup-count", "Number of Blocked Popups", @@ -686,8 +662,6 @@ ephy_tab_finalize (GObject *object) } g_free (priv->icon_address); - g_free (priv->link_message); - g_free (priv->status_message); popups_manager_reset (tab); G_OBJECT_CLASS (parent_class)->finalize (object); @@ -752,79 +726,6 @@ ephy_tab_new (void) return EPHY_TAB (g_object_new (EPHY_TYPE_TAB, NULL)); } -static void -ephy_tab_set_link_message (EphyTab *tab, char *message) -{ - char *status_message; - char **splitted_message; - g_return_if_fail (EPHY_IS_TAB (tab)); - - g_free (tab->priv->link_message); - status_message = ephy_string_blank_chr (message); - - if (status_message && g_str_has_prefix (status_message, "mailto:")) - { - int i = 1; - char *p; - GString *tmp; - - /* We first want to eliminate all the things after "?", like - * cc, subject and alike. - */ - - p = strchr (status_message, '?'); - if (p != NULL) *p = '\0'; - - /* Then we also want to check if there is more than an email address - * in the mailto: list. - */ - - splitted_message = g_strsplit_set (status_message, ";", -1); - tmp = g_string_new (g_strdup_printf (_("Send an email message to “%s”"), - (splitted_message[0] + 7))); - - while (splitted_message [i] != NULL) - { - g_string_append_printf (tmp, ", “%s”", splitted_message[i]); - i++; - } - - tab->priv->link_message = g_string_free (tmp, FALSE); - - g_free (status_message); - g_strfreev (splitted_message); - } - else - { - tab->priv->link_message = status_message; - } - - g_object_notify (G_OBJECT (tab), "message"); -} - -/** - * ephy_tab_get_link_message: - * @tab: an #EphyTab - * - * Returns the message displayed in @tab's #EphyWindow's #EphyStatusbar when - * the user hovers the mouse over a hyperlink. - * - * The message returned has a limited lifetime, and so should be copied with - * g_strdup() if it must be stored. - * - * Listen to the "link_message" signal on the @tab's #EphyEmbed to be notified - * when the link message changes. - * - * Return value: The current link statusbar message - **/ -const char * -ephy_tab_get_link_message (EphyTab *tab) -{ - g_return_val_if_fail (EPHY_IS_TAB (tab), NULL); - - return tab->priv->link_message; -} - /** * ephy_tab_get_embed: * @tab: an #EphyTab @@ -1005,176 +906,6 @@ ephy_tab_set_icon_address (EphyTab *tab, g_object_notify (object, "icon-address"); } -static void -ephy_tab_file_monitor_cancel (EphyTab *tab) -{ - EphyTabPrivate *priv = tab->priv; - - if (priv->monitor != NULL) - { - LOG ("Cancelling file monitor"); - - gnome_vfs_monitor_cancel (priv->monitor); - priv->monitor = NULL; - } - - if (priv->reload_scheduled_id != 0) - { - LOG ("Cancelling scheduled reload"); - - g_source_remove (priv->reload_scheduled_id); - priv->reload_scheduled_id = 0; - } - - priv->reload_delay_ticks = 0; -} - -static gboolean -ephy_file_monitor_reload_cb (EphyTab *tab) -{ - EphyTabPrivate *priv = tab->priv; - EphyEmbed *embed; - gboolean is_loading; - - if (priv->reload_delay_ticks > 0) - { - priv->reload_delay_ticks--; - - /* Run again */ - return TRUE; - } - - is_loading = ephy_embed_get_load_status (ephy_tab_get_embed (tab)); - - if (is_loading) - { - /* Wait a bit to reload if we're still loading! */ - priv->reload_delay_ticks = RELOAD_DELAY_MAX_TICKS / 2; - - /* Run again */ - return TRUE; - } - - priv->reload_scheduled_id = 0; - - embed = ephy_tab_get_embed (tab); - if (embed == NULL) return FALSE; - - LOG ("Reloading file '%s'", ephy_embed_get_address (embed)); - - ephy_embed_reload (embed, TRUE); - - /* don't run again */ - return FALSE; -} - -static void -ephy_tab_file_monitor_cb (GnomeVFSMonitorHandle *handle, - const gchar *monitor_uri, - const gchar *info_uri, - GnomeVFSMonitorEventType event_type, - EphyTab *tab) -{ - gboolean uri_is_directory; - gboolean should_reload; - char* local_path; - EphyTabPrivate *priv = tab->priv; - - LOG ("File '%s' has changed, scheduling reload", monitor_uri); - - local_path = gnome_vfs_get_local_path_from_uri(monitor_uri); - uri_is_directory = g_file_test(local_path, G_FILE_TEST_IS_DIR); - g_free(local_path); - - switch (event_type) - { - /* These events will always trigger a reload: */ - case GNOME_VFS_MONITOR_EVENT_CHANGED: - case GNOME_VFS_MONITOR_EVENT_CREATED: - should_reload = TRUE; - break; - - /* These events will only trigger a reload for directories: */ - case GNOME_VFS_MONITOR_EVENT_DELETED: - case GNOME_VFS_MONITOR_EVENT_METADATA_CHANGED: - should_reload = uri_is_directory; - break; - - /* These events don't trigger a reload: */ - case GNOME_VFS_MONITOR_EVENT_STARTEXECUTING: - case GNOME_VFS_MONITOR_EVENT_STOPEXECUTING: - default: - should_reload = FALSE; - break; - } - - if (should_reload) { - /* We make a lot of assumptions here, but basically we know - * that we just have to reload, by construction. - * Delay the reload a little bit so we don't endlessly - * reload while a file is written. - */ - if (priv->reload_delay_ticks == 0) - { - priv->reload_delay_ticks = 1; - } - else - { - /* Exponential backoff */ - priv->reload_delay_ticks = MIN (priv->reload_delay_ticks * 2, - RELOAD_DELAY_MAX_TICKS); - } - - if (priv->reload_scheduled_id == 0) - { - priv->reload_scheduled_id = - g_timeout_add (RELOAD_DELAY, - (GSourceFunc) ephy_file_monitor_reload_cb, tab); - } - } -} - -static void -ephy_tab_update_file_monitor (EphyTab *tab, - const gchar *address) -{ - EphyTabPrivate *priv = tab->priv; - GnomeVFSMonitorHandle *handle = NULL; - gboolean local; - char* local_path; - GnomeVFSMonitorType monitor_type; - - if (priv->monitor != NULL && - priv->address != NULL && address != NULL && - strcmp (priv->address, address) == 0) - - { - /* same address, no change needed */ - return; - } - - ephy_tab_file_monitor_cancel (tab); - - local = g_str_has_prefix (address, "file://"); - if (local == FALSE) return; - - local_path = gnome_vfs_get_local_path_from_uri(address); - monitor_type = g_file_test(local_path, G_FILE_TEST_IS_DIR) - ? GNOME_VFS_MONITOR_DIRECTORY - : GNOME_VFS_MONITOR_FILE; - g_free(local_path); - - if (gnome_vfs_monitor_add (&handle, address, - monitor_type, - (GnomeVFSMonitorCallback) ephy_tab_file_monitor_cb, - tab) == GNOME_VFS_OK) - { - LOG ("Installed monitor for file '%s'", address); - - priv->monitor = handle; - } -} - /** * ephy_tab_get_icon: * @tab: an #EphyTab @@ -1222,13 +953,6 @@ ephy_tab_favicon_cb (EphyEmbed *embed, ephy_tab_set_icon_address (tab, address); } -static void -ephy_tab_link_message_cb (EphyEmbed *embed, - EphyTab *tab) -{ - ephy_tab_set_link_message (tab, ephy_embed_get_link_message (embed)); -} - static gboolean ephy_tab_open_uri_cb (EphyEmbed *embed, const char *uri, @@ -1249,49 +973,6 @@ ephy_tab_open_uri_cb (EphyEmbed *embed, return FALSE; } -#if 0 -static void -ephy_tab_address_cb (EphyEmbed *embed, - const char *address, - EphyTab *tab) -{ - GObject *object = G_OBJECT (tab); - - LOG ("ephy_tab_address_cb tab %p address %s", tab, address); - - g_object_freeze_notify (object); - - /* do this up here so we still have the old address around */ - ephy_tab_update_file_monitor (tab, address); - - /* Do not expose about:blank to the user, an empty address - bar will do better */ - if (address == NULL || address[0] == '\0' || - strcmp (address, "about:blank") == 0) - { - ephy_tab_set_address (tab, NULL); - ephy_tab_set_title (tab, embed, NULL); - } - else - { - char *embed_address; - - /* we do this to get rid of an eventual password in the URL */ - embed_address = ephy_embed_get_location (embed, TRUE); - ephy_tab_set_address (tab, embed_address); - ephy_tab_set_loading_title (tab, embed_address, TRUE); - } - - ephy_tab_set_link_message (tab, NULL); - ephy_tab_set_icon_address (tab, NULL); - ephy_embed_update_navigation_flags (embed); - - g_object_notify (object, "title"); - - g_object_thaw_notify (object); -} -#endif - static void ephy_tab_content_change_cb (EphyEmbed *embed, const char *address, EphyTab *tab) { @@ -1539,7 +1220,6 @@ ephy_tab_init (EphyTab *tab) tab->priv->height = -1; priv->icon_address = NULL; priv->icon = NULL; - priv->reload_delay_ticks = 0; embed = ephy_embed_factory_new_object (EPHY_TYPE_EMBED); g_assert (embed != NULL); @@ -1547,15 +1227,9 @@ ephy_tab_init (EphyTab *tab) gtk_container_add (GTK_CONTAINER (tab), GTK_WIDGET (embed)); gtk_widget_show (GTK_WIDGET (embed)); - g_signal_connect_object (embed, "link_message", - G_CALLBACK (ephy_tab_link_message_cb), - tab, 0); g_signal_connect_object (embed, "open_uri", G_CALLBACK (ephy_tab_open_uri_cb), tab, 0); - g_signal_connect_object (embed, "ge_location", - G_CALLBACK (ephy_tab_address_cb), - tab, 0); g_signal_connect_object (embed, "ge_new_window", G_CALLBACK (ephy_tab_new_window_cb), tab, 0); @@ -1580,42 +1254,6 @@ ephy_tab_init (EphyTab *tab) } /** - * ephy_tab_get_status_message: - * @tab: an #EphyTab - * - * Returns the message displayed in @tab's #EphyWindow's - * #EphyStatusbar. If the user is hovering the mouse over a hyperlink, - * this function will return the same value as - * ephy_tab_get_link_message(). Otherwise, it will return a network - * status message, or NULL. - * - * The message returned has a limited lifetime, and so should be copied with - * g_strdup() if it must be stored. - * - * Listen to "notify::message" to be notified when the message property changes. - * - * Return value: The current statusbar message - **/ -const char * -ephy_tab_get_status_message (EphyTab *tab) -{ - g_return_val_if_fail (EPHY_IS_TAB (tab), NULL); - - if (tab->priv->link_message && tab->priv->link_message[0] != '\0') - { - return tab->priv->link_message; - } - else if (tab->priv->status_message) - { - return tab->priv->status_message; - } - else - { - return NULL; - } -} - -/** * ephy_tab_get_title_composite: * @tab: an #EphyTab * |