From 6638472fdbeee7c135c822ada01d09f407ca18e6 Mon Sep 17 00:00:00 2001 From: Xan Lopez Date: Thu, 25 Oct 2007 20:01:00 +0000 Subject: Move title/address update on open-uri signal to EphyEmbed. Also refactor some common code in ephy-embed-utils.c svn path=/trunk/; revision=7562 --- embed/Makefile.am | 2 + embed/ephy-embed-utils.c | 119 ++++++++++++++++++++++++++++++++++++++++ embed/ephy-embed-utils.h | 37 +++++++++++++ embed/ephy-embed.c | 21 +++++++ embed/ephy-embed.h | 8 ++- embed/mozilla/mozilla-embed.cpp | 44 +++++++++++++++ src/ephy-tab.c | 64 --------------------- 7 files changed, 230 insertions(+), 65 deletions(-) create mode 100644 embed/ephy-embed-utils.c create mode 100644 embed/ephy-embed-utils.h diff --git a/embed/Makefile.am b/embed/Makefile.am index d1ddcb38b..209eb74e6 100644 --- a/embed/Makefile.am +++ b/embed/Makefile.am @@ -31,6 +31,7 @@ INST_H_FILES = \ ephy-embed-prefs.h \ ephy-embed-single.h \ ephy-embed-shell.h \ + ephy-embed-utils.h \ ephy-history.h \ ephy-password-manager.h \ ephy-permission-manager.h @@ -53,6 +54,7 @@ libephyembed_la_SOURCES = \ ephy-embed-persist.c \ ephy-embed-single.c \ ephy-embed-shell.c \ + ephy-embed-utils.c \ ephy-encodings.c \ ephy-favicon-cache.c \ ephy-history.c \ diff --git a/embed/ephy-embed-utils.c b/embed/ephy-embed-utils.c new file mode 100644 index 000000000..ae8fd8826 --- /dev/null +++ b/embed/ephy-embed-utils.c @@ -0,0 +1,119 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright © 2000-2003 Marco Pesenti Gritti + * Copyright © 2003, 2004, 2005 Christian Persch + * Copyright © 2004 Crispin Flowerday + * Copyright © 2004 Adam Hooper + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $Id: + */ + +#include "ephy-string.h" +#include + +#include + +#include "ephy-embed-utils.h" + +char* +ephy_embed_utils_link_message_parse (char *message) +{ + + char *status_message; + char **splitted_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++; + } + + g_free (status_message); + g_strfreev (splitted_message); + + return g_string_free (tmp, FALSE); + } + else + { + return status_message; + } +} + +/** + * ephy_embed_utils_get_title_composite: + * @embed: an #EphyEmbed + * + * Returns the title of the web page loaded in @embed. + * + * This differs from #ephy_embed_utils_get_title in that this function + * will return a special title while the page is still loading. + * + * Return value: @embed's web page's title. Will never be %NULL. + **/ +const char * +ephy_embed_utils_get_title_composite (EphyEmbed *embed) +{ + const char *title = ""; + const char *loading_title; + gboolean is_loading, is_blank; + + g_return_val_if_fail (EPHY_IS_EMBED (embed), NULL); + + is_loading = ephy_embed_get_load_status (embed); + is_blank = ephy_embed_get_is_blank (embed); + loading_title = ephy_embed_get_loading_title (embed); + + if (is_blank) + { + title = _("Blank page"); + } + else if (is_loading && + loading_title != NULL) + { + title = loading_title; + } + else + { + title = ephy_embed_get_title (embed); + } + + return title != NULL ? title : ""; +} + diff --git a/embed/ephy-embed-utils.h b/embed/ephy-embed-utils.h new file mode 100644 index 000000000..861231e0f --- /dev/null +++ b/embed/ephy-embed-utils.h @@ -0,0 +1,37 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright © 2000-2003 Marco Pesenti Gritti + * Copyright © 2003, 2004, 2005 Christian Persch + * Copyright © 2004 Crispin Flowerday + * Copyright © 2004 Adam Hooper + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $Id: + */ + +#ifndef EPHY_EMBED_UTILS_H +#define EPHY_EMBED_UTILS_H + +#include "ephy-embed.h" + +G_BEGIN_DECLS + +char * ephy_embed_utils_link_message_parse (char *message); +const char * ephy_embed_utils_get_title_composite (EphyEmbed *embed); + +G_END_DECLS + +#endif diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index 0a822ee11..6c6d4cdd8 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -1273,3 +1273,24 @@ ephy_embed_get_icon_address (EphyEmbed *embed) return iface->get_icon_address (embed); } +/** + * ephy_embed_get_is_blank: + * @embed: an #EphyEmbed + * + * Returns whether the @embed's address is "blank". + * + * Return value: %TRUE if the @embed's address is "blank" + **/ +gboolean +ephy_embed_get_is_blank (EphyEmbed *embed) +{ + EphyEmbedIface *iface = EPHY_EMBED_GET_IFACE (embed); + return iface->get_is_blank (embed); +} + +const char * +ephy_embed_get_loading_title (EphyEmbed *embed) +{ + EphyEmbedIface *iface = EPHY_EMBED_GET_IFACE (embed); + return iface->get_loading_title (embed); +} diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h index 87d78f20d..61d3ab735 100644 --- a/embed/ephy-embed.h +++ b/embed/ephy-embed.h @@ -254,6 +254,8 @@ struct _EphyEmbedIface const char * (* get_status_message) (EphyEmbed *embed); GdkPixbuf * (* get_icon) (EphyEmbed *embed); const char * (* get_icon_address) (EphyEmbed *embed); + gboolean (* get_is_blank) (EphyEmbed *embed); + const char * (* get_loading_title) (EphyEmbed *embed); }; GType ephy_embed_net_state_get_type (void); @@ -285,7 +287,6 @@ const char *ephy_embed_get_title (EphyEmbed *embed); char *ephy_embed_get_location (EphyEmbed *embed, gboolean toplevel); - const char *ephy_embed_get_link_message (EphyEmbed *embed); char *ephy_embed_get_js_status (EphyEmbed *embed); @@ -375,6 +376,11 @@ const char * ephy_embed_get_status_message (EphyEmbed *embed); GdkPixbuf * ephy_embed_get_icon (EphyEmbed *embed); const char * ephy_embed_get_icon_address (EphyEmbed *embed); +/* Is blank */ +gboolean ephy_embed_get_is_blank (EphyEmbed *embed); + +const char * ephy_embed_get_loading_title (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 4ac762617..16ef8245f 100644 --- a/embed/mozilla/mozilla-embed.cpp +++ b/embed/mozilla/mozilla-embed.cpp @@ -105,6 +105,9 @@ static void mozilla_embed_set_icon_address (MozillaEmbed *embed, static void mozilla_embed_favicon_cb (EphyEmbed *embed, const char *address, MozillaEmbed *membed); +static gboolean mozilla_embed_open_uri_cb (EphyEmbed *embed, + const char *uri, + MozillaEmbed *membed); static void impl_set_typed_address (EphyEmbed *embed, const char *address, EphyEmbedAddressExpire expire); @@ -439,6 +442,9 @@ mozilla_embed_init (MozillaEmbed *embed) g_signal_connect_object (embed, "ge_favicon", G_CALLBACK (mozilla_embed_favicon_cb), embed, (GConnectFlags)0); + g_signal_connect_object (embed, "open_uri", + G_CALLBACK (mozilla_embed_open_uri_cb), + embed,(GConnectFlags) 0); cache = EPHY_FAVICON_CACHE (ephy_embed_shell_get_favicon_cache (embed_shell)); @@ -1195,6 +1201,22 @@ impl_get_link_message (EphyEmbed *embed) return priv->link_message; } +static gboolean +impl_get_is_blank (EphyEmbed *embed) +{ + MozillaEmbedPrivate *priv = MOZILLA_EMBED (embed)->priv; + + return priv->is_blank; +} + +static const char* +impl_get_loading_title (EphyEmbed *embed) +{ + MozillaEmbedPrivate *priv = MOZILLA_EMBED (embed)->priv; + + return priv->loading_title; +} + static void mozilla_embed_set_address (MozillaEmbed *embed, char *address) { @@ -2224,6 +2246,26 @@ mozilla_embed_title_change_cb (EphyEmbed *embed, g_object_thaw_notify (object); } +static gboolean +mozilla_embed_open_uri_cb (EphyEmbed *embed, + const char *uri, + MozillaEmbed *membed) +{ + MozillaEmbedPrivate *priv = membed->priv; + + /* Set the address here if we have a blank page. + * See bug #147840. + */ + if (priv->is_blank) + { + mozilla_embed_set_address (membed, g_strdup (uri)); + mozilla_embed_set_loading_title (membed, uri, TRUE); + } + + /* allow load to proceed */ + return FALSE; +} + static EphyEmbedSecurityLevel mozilla_embed_security_level (PRUint32 state) { @@ -2303,6 +2345,8 @@ ephy_embed_iface_init (EphyEmbedIface *iface) iface->set_typed_address = impl_set_typed_address; iface->get_address = impl_get_address; iface->get_status_message = impl_get_status_message; + iface->get_is_blank = impl_get_is_blank; + iface->get_loading_title = impl_get_loading_title; } static void diff --git a/src/ephy-tab.c b/src/ephy-tab.c index 60056cddd..3f0db4291 100644 --- a/src/ephy-tab.c +++ b/src/ephy-tab.c @@ -801,26 +801,6 @@ ephy_tab_set_size (EphyTab *tab, /* Private callbacks for embed signals */ -static gboolean -ephy_tab_open_uri_cb (EphyEmbed *embed, - const char *uri, - EphyTab *tab) -{ - EphyTabPrivate *priv = tab->priv; - - /* Set the address here if we have a blank page. - * See bug #147840. - */ - if (priv->is_blank) - { - ephy_embed_set_address (embed, g_strdup (uri)); - ephy_embed_set_loading_title (embed, uri, TRUE); - } - - /* allow load to proceed */ - return FALSE; -} - static void ephy_tab_content_change_cb (EphyEmbed *embed, const char *address, EphyTab *tab) { @@ -1072,9 +1052,6 @@ 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, "open_uri", - G_CALLBACK (ephy_tab_open_uri_cb), - tab, 0); g_signal_connect_object (embed, "ge_new_window", G_CALLBACK (ephy_tab_new_window_cb), tab, 0); @@ -1089,47 +1066,6 @@ ephy_tab_init (EphyTab *tab) tab, 0); } -/** - * ephy_tab_get_title_composite: - * @tab: an #EphyTab - * - * Returns the title of the web page loaded in @tab. - * - * This differs from #ephy_tab_get_title in that this function - * will return a special title while the page is still loading. - * - * Return value: @tab's web page's title. Will never be %NULL. - **/ -const char * -ephy_tab_get_title_composite (EphyTab *tab) -{ - EphyTabPrivate *priv; - const char *title = ""; - gboolean is_loading; - - g_return_val_if_fail (EPHY_IS_TAB (tab), NULL); - - priv = tab->priv; - - is_loading = ephy_embed_get_load_status (ephy_tab_get_embed (tab)); - - if (priv->is_blank) - { - title = _("Blank page"); - } - else if (is_loading && - priv->loading_title != NULL) - { - title = priv->loading_title; - } - else - { - title = priv->title; - } - - return title != NULL ? title : ""; -} - /* private */ guint _ephy_tab_get_id (EphyTab *tab) -- cgit v1.2.3