Commit 0d89197c authored by Carlos Garcia Campos's avatar Carlos Garcia Campos Committed by Carlos Garcia Campos

ephy-web-view: Move embed-title property to EphyEmbed

Since it's the embed title what it represents. The web view already has
a title property inherited from WebKitWebView.

https://bugzilla.gnome.org/show_bug.cgi?id=725649
parent 0c6c6bce
......@@ -29,9 +29,11 @@
#include "ephy-debug.h"
#include "ephy-embed-prefs.h"
#include "ephy-embed-shell.h"
#include "ephy-embed-utils.h"
#include "ephy-find-toolbar.h"
#include "ephy-prefs.h"
#include "ephy-settings.h"
#include "ephy-string.h"
#include "ephy-web-view.h"
#include "nautilus-floating-bar.h"
......@@ -45,6 +47,8 @@ static void ephy_embed_restored_window_cb (EphyEmbedShell *shell,
#define EPHY_EMBED_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_EMBED, EphyEmbedPrivate))
#define EPHY_EMBED_STATUSBAR_TAB_MESSAGE_CONTEXT_DESCRIPTION "tab_message"
#define MAX_TITLE_LENGTH 512 /* characters */
#define EMPTY_PAGE_TITLE _("Blank page") /* Title for the empty page */
typedef struct {
gchar *text;
......@@ -64,6 +68,7 @@ struct _EphyEmbedPrivate
GtkWidget *fullscreen_message_label;
char *fullscreen_string;
char *title;
WebKitURIRequest *delayed_request;
GSList *messages;
......@@ -87,6 +92,7 @@ enum
{
PROP_0,
PROP_WEB_VIEW,
PROP_TITLE,
};
G_DEFINE_TYPE (EphyEmbed, ephy_embed, GTK_TYPE_BOX)
......@@ -240,13 +246,61 @@ remove_from_destroy_list_cb (GtkWidget *widget, EphyEmbed *embed)
embed->priv->destroy_on_transition_list = list;
}
static void
ephy_embed_set_title (EphyEmbed *embed,
const char *title)
{
EphyEmbedPrivate *priv = embed->priv;
char *new_title;
new_title = g_strdup (title);
if (new_title == NULL || g_strstrip (new_title)[0] == '\0') {
const char *address;
g_free (new_title);
new_title = NULL;
address = ephy_web_view_get_address (EPHY_WEB_VIEW (priv->web_view));
if (address && strcmp (address, "about:blank") != 0)
new_title = ephy_embed_utils_get_title_from_address (address);
if (new_title == NULL || new_title[0] == '\0') {
g_free (new_title);
new_title = g_strdup (EMPTY_PAGE_TITLE);
}
}
g_free (priv->title);
priv->title = ephy_string_shorten (new_title, MAX_TITLE_LENGTH);
g_object_notify (G_OBJECT (embed), "title");
}
static void
web_view_title_changed_cb (WebKitWebView *web_view,
GParamSpec *spec,
EphyEmbed *embed)
{
ephy_embed_set_title (embed, webkit_web_view_get_title (web_view));
}
static void
load_changed_cb (WebKitWebView *web_view,
WebKitLoadEvent load_event,
EphyEmbed *embed)
{
if (load_event == WEBKIT_LOAD_COMMITTED)
switch (load_event) {
case WEBKIT_LOAD_COMMITTED:
ephy_embed_destroy_top_widgets (embed);
break;
case WEBKIT_LOAD_FINISHED:
if (ephy_web_view_get_is_blank (EPHY_WEB_VIEW (web_view)) ||
!webkit_web_view_get_title (web_view))
ephy_embed_set_title (embed, NULL);
break;
default:
break;
}
}
static void
......@@ -368,6 +422,7 @@ ephy_embed_finalize (GObject *object)
priv->keys = NULL;
g_free (embed->priv->fullscreen_string);
g_free (priv->title);
G_OBJECT_CLASS (ephy_embed_parent_class)->finalize (object);
}
......@@ -404,6 +459,9 @@ ephy_embed_get_property (GObject *object,
case PROP_WEB_VIEW:
g_value_set_object (value, ephy_embed_get_web_view (embed));
break;
case PROP_TITLE:
g_value_set_string (value, ephy_embed_get_title (embed));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -441,6 +499,13 @@ ephy_embed_class_init (EphyEmbedClass *klass)
"The WebView contained in the embed",
EPHY_TYPE_WEB_VIEW,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_TITLE,
g_param_spec_string ("title",
"Title",
"The embed's title",
EMPTY_PAGE_TITLE,
G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
g_type_class_add_private (G_OBJECT_CLASS (klass), sizeof(EphyEmbedPrivate));
}
......@@ -688,6 +753,7 @@ ephy_embed_constructed (GObject *object)
gtk_widget_show_all (paned);
g_object_connect (priv->web_view,
"signal::notify::title", G_CALLBACK (web_view_title_changed_cb), embed,
"signal::load-changed", G_CALLBACK (load_changed_cb), embed,
"signal::enter-fullscreen", G_CALLBACK (entering_fullscreen_cb), embed,
"signal::leave-fullscreen", G_CALLBACK (leaving_fullscreen_cb), embed,
......@@ -843,3 +909,10 @@ ephy_embed_has_load_pending (EphyEmbed *embed)
return !!embed->priv->delayed_request;
}
const char *
ephy_embed_get_title (EphyEmbed *embed)
{
g_return_val_if_fail (EPHY_IS_EMBED (embed), NULL);
return embed->priv->title;
}
......@@ -64,6 +64,7 @@ void ephy_embed_leaving_fullscreen (EphyEmbed *embed);
void ephy_embed_set_delayed_load_request (EphyEmbed *embed,
WebKitURIRequest *request);
gboolean ephy_embed_has_load_pending (EphyEmbed *embed);
const char *ephy_embed_get_title (EphyEmbed *embed);
G_END_DECLS
......
......@@ -61,8 +61,6 @@
*/
#define MAX_HIDDEN_POPUPS 5
#define MAX_TITLE_LENGTH 512 /* characters */
#define EMPTY_PAGE _("Blank page") /* Title for the empty page */
#define EPHY_PAGE_TEMPLATE_ERROR "/org/gnome/epiphany/page-templates/error.html"
......@@ -80,7 +78,6 @@ struct _EphyWebViewPrivate {
char *address;
char *typed_address;
char *title;
char *loading_message;
char *link_message;
GdkPixbuf *icon;
......@@ -131,7 +128,6 @@ enum {
PROP_POPUPS_ALLOWED,
PROP_SECURITY,
PROP_STATUS_MESSAGE,
PROP_EMBED_TITLE,
PROP_TYPED_ADDRESS,
PROP_IS_BLANK,
};
......@@ -368,9 +364,6 @@ ephy_web_view_get_property (GObject *object,
case PROP_ADDRESS:
g_value_set_string (value, priv->address);
break;
case PROP_EMBED_TITLE:
g_value_set_string (value, priv->title);
break;
case PROP_TYPED_ADDRESS:
g_value_set_string (value, priv->typed_address);
break;
......@@ -430,7 +423,6 @@ ephy_web_view_set_property (GObject *object,
case PROP_NAVIGATION:
case PROP_SECURITY:
case PROP_STATUS_MESSAGE:
case PROP_EMBED_TITLE:
case PROP_IS_BLANK:
/* read only */
break;
......@@ -762,7 +754,6 @@ ephy_web_view_finalize (GObject *object)
g_free (priv->address);
g_free (priv->typed_address);
g_free (priv->title);
g_free (priv->link_message);
g_free (priv->loading_message);
......@@ -781,53 +772,27 @@ _ephy_web_view_set_is_blank (EphyWebView *view,
}
}
static void
ephy_web_view_set_title (EphyWebView *view,
const char *view_title)
{
EphyWebViewPrivate *priv = view->priv;
char *title = g_strdup (view_title);
if (title == NULL || g_strstrip (title)[0] == '\0') {
g_free (title);
title = priv->address ? ephy_embed_utils_get_title_from_address (priv->address) : NULL;
if (title == NULL || title[0] == '\0') {
g_free (title);
title = g_strdup (EMPTY_PAGE);
}
}
g_free (priv->title);
priv->title = ephy_string_shorten (title, MAX_TITLE_LENGTH);
g_object_notify (G_OBJECT (view), "embed-title");
}
static void
title_changed_cb (WebKitWebView *web_view,
GParamSpec *spec,
gpointer data)
{
const char *uri;
char *title;
const char *title;
char *title_from_address = NULL;
EphyWebView *webview = EPHY_WEB_VIEW (web_view);
EphyHistoryService *history = webview->priv->history_service;
uri = webkit_web_view_get_uri (web_view);
title = webkit_web_view_get_title (web_view);
g_object_get (web_view, "title", &title, NULL);
ephy_web_view_set_title (webview, title);
if (!title && uri)
title = ephy_embed_utils_get_title_from_address (uri);
title = title_from_address = ephy_embed_utils_get_title_from_address (uri);
if (uri && title && !ephy_web_view_is_history_frozen (webview))
ephy_history_service_set_url_title (history, uri, title, NULL, NULL, NULL);
g_free (title);
g_free (title_from_address);
}
/*
......@@ -972,19 +937,6 @@ ephy_web_view_class_init (EphyWebViewClass *klass)
"",
G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
/**
* EphyWebView:embed-title:
*
* Title for this embed.
**/
g_object_class_install_property (gobject_class,
PROP_EMBED_TITLE,
g_param_spec_string ("embed-title",
"Title",
"The view's title",
EMPTY_PAGE,
G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
/**
* EphyWebView:security-level:
*
......@@ -1545,7 +1497,6 @@ ephy_web_view_location_changed (EphyWebView *view,
if (location == NULL || location[0] == '\0') {
ephy_web_view_set_address (view, NULL);
ephy_web_view_set_title (view, EMPTY_PAGE);
} else if (g_str_has_prefix (location, EPHY_ABOUT_SCHEME":applications")) {
SoupURI *uri = soup_uri_new (location);
char *new_address;
......@@ -1655,9 +1606,6 @@ load_changed_cb (WebKitWebView *web_view,
case WEBKIT_LOAD_FINISHED:
ephy_web_view_set_loading_message (view, NULL);
if (priv->is_blank || !webkit_web_view_get_title (web_view))
ephy_web_view_set_title (view, NULL);
/* Ensure we load the icon for this web view, if available. */
_ephy_web_view_update_icon (view);
......@@ -1819,8 +1767,6 @@ ephy_web_view_load_error_page (EphyWebView *view,
}
g_free (hostname);
ephy_web_view_set_title (view, page_title);
_ephy_web_view_update_icon (view);
stylesheet = get_style_sheet ();
......@@ -1961,7 +1907,6 @@ ephy_web_view_init (EphyWebView *web_view)
priv->is_blank = TRUE;
priv->ever_committed = FALSE;
priv->title = g_strdup (EMPTY_PAGE);
priv->document_type = EPHY_WEB_VIEW_DOCUMENT_HTML;
priv->security_level = EPHY_WEB_VIEW_STATE_IS_UNKNOWN;
......@@ -2189,18 +2134,6 @@ ephy_web_view_get_address (EphyWebView *view)
return priv->address ? priv->address : "about:blank";
}
/**
* ephy_web_view_get_title:
* @view: an #EphyWebView
*
* Return value: the title of the web page displayed in @view
**/
const char *
ephy_web_view_get_title (EphyWebView *view)
{
return view->priv->title;
}
/**
* ephy_web_view_is_loading:
* @view: an #EphyWebView
......@@ -2731,7 +2664,7 @@ ephy_web_view_print (EphyWebView *view)
settings = gtk_print_settings_new ();
gtk_print_settings_set (settings,
GTK_PRINT_SETTINGS_OUTPUT_BASENAME,
ephy_web_view_get_title (view));
webkit_web_view_get_title (WEBKIT_WEB_VIEW (view)));
webkit_print_operation_set_print_settings (operation, settings);
webkit_print_operation_run_dialog (operation, NULL);
g_object_unref (operation);
......
......@@ -147,7 +147,6 @@ void ephy_web_view_get_security_level (EphyWebView
GTlsCertificate **certificate,
GTlsCertificateFlags *errors);
void ephy_web_view_print (EphyWebView *view);
const char * ephy_web_view_get_title (EphyWebView *view);
const char * ephy_web_view_get_address (EphyWebView *view);
void ephy_web_view_set_placeholder (EphyWebView *view,
......
......@@ -318,7 +318,7 @@ get_title_cb (EphyLocationEntry *entry,
embed = ephy_embed_container_get_active_child
(EPHY_EMBED_CONTAINER (controller->priv->window));
return g_strdup (ephy_web_view_get_title (ephy_embed_get_web_view (embed)));
return g_strdup (ephy_embed_get_title (embed));
}
static void
......
......@@ -507,13 +507,9 @@ sync_icon (EphyWebView *view,
}
static void
sync_label (EphyWebView *view, GParamSpec *pspec, GtkWidget *label)
sync_label (EphyEmbed *embed, GParamSpec *pspec, GtkWidget *label)
{
const char *title;
title = ephy_web_view_get_title (view);
gtk_label_set_text (GTK_LABEL (label), title);
gtk_label_set_text (GTK_LABEL (label), ephy_embed_get_title (embed));
}
static void
......@@ -633,12 +629,12 @@ build_tab_label (EphyNotebook *nb, EphyEmbed *embed)
/* Hook the label up to the tab properties */
view = ephy_embed_get_web_view (embed);
sync_icon (view, NULL, GTK_IMAGE (icon));
sync_label (view, NULL, label);
sync_label (embed, NULL, label);
sync_load_status (view, NULL, box);
g_signal_connect_object (view, "notify::icon",
G_CALLBACK (sync_icon), icon, 0);
g_signal_connect_object (view, "notify::embed-title",
g_signal_connect_object (embed, "notify::title",
G_CALLBACK (sync_label), label, 0);
g_signal_connect_object (view, "load-changed",
G_CALLBACK (load_changed_cb), box, 0);
......@@ -791,7 +787,7 @@ ephy_notebook_remove (GtkContainer *container,
g_signal_handlers_disconnect_by_func
(view, G_CALLBACK (sync_icon), tab_label_icon);
g_signal_handlers_disconnect_by_func
(view, G_CALLBACK (sync_label), tab_label_label);
(tab_widget, G_CALLBACK (sync_label), tab_label_label);
g_signal_handlers_disconnect_by_func
(view, G_CALLBACK (sync_load_status), tab_label);
......
......@@ -577,7 +577,7 @@ session_tab_new (EphyEmbed *embed)
session_tab->url = g_strdup (address);
}
session_tab->title = g_strdup (ephy_web_view_get_title (web_view));
session_tab->title = g_strdup (ephy_embed_get_title (embed));
session_tab->loading = ephy_web_view_is_loading (web_view) && !ephy_embed_has_load_pending (embed);
return session_tab;
......
......@@ -1514,7 +1514,7 @@ sync_tab_popups_allowed (EphyWebView *view,
}
static void
sync_tab_title (EphyWebView *view,
sync_tab_title (EphyEmbed *embed,
GParamSpec *pspec,
EphyWindow *window)
{
......@@ -1523,7 +1523,7 @@ sync_tab_title (EphyWebView *view,
if (priv->closing) return;
gtk_window_set_title (GTK_WINDOW(window),
ephy_web_view_get_title (view));
ephy_embed_get_title (embed));
}
static gboolean
......@@ -2251,7 +2251,7 @@ ephy_window_connect_active_embed (EphyWindow *window)
sync_tab_load_status (view, WEBKIT_LOAD_STARTED, window);
sync_tab_is_blank (view, NULL, window);
sync_tab_navigation (view, NULL, window);
sync_tab_title (view, NULL, window);
sync_tab_title (embed, NULL, window);
sync_tab_address (view, NULL, window);
sync_tab_icon (view, NULL, window);
sync_tab_popup_windows (view, NULL, window);
......@@ -2275,7 +2275,7 @@ ephy_window_connect_active_embed (EphyWindow *window)
g_signal_connect_object (view, "notify::popups-allowed",
G_CALLBACK (sync_tab_popups_allowed),
window, 0);
g_signal_connect_object (view, "notify::embed-title",
g_signal_connect_object (embed, "notify::title",
G_CALLBACK (sync_tab_title),
window, 0);
g_signal_connect_object (view, "notify::address",
......@@ -2355,7 +2355,7 @@ ephy_window_disconnect_active_embed (EphyWindow *window)
g_signal_handlers_disconnect_by_func (view,
G_CALLBACK (sync_tab_navigation),
window);
g_signal_handlers_disconnect_by_func (view,
g_signal_handlers_disconnect_by_func (embed,
G_CALLBACK (sync_tab_title),
window);
g_signal_handlers_disconnect_by_func (view,
......
......@@ -101,7 +101,7 @@ window_cmd_file_send_to (GtkAction *action,
g_return_if_fail (embed != NULL);
location = ephy_web_view_get_address (ephy_embed_get_web_view (embed));
title = ephy_web_view_get_title (ephy_embed_get_web_view (embed));
title = ephy_embed_get_title (embed);
subject = g_uri_escape_string (title, NULL, TRUE);
body = g_uri_escape_string (location, NULL, TRUE);
......@@ -212,7 +212,7 @@ window_cmd_file_bookmark_page (GtkAction *action,
ephy_bookmarks_ui_add_bookmark (GTK_WINDOW (window),
ephy_web_view_get_address (ephy_embed_get_web_view (embed)),
ephy_web_view_get_title (ephy_embed_get_web_view (embed)));
ephy_embed_get_title (embed));
}
static void
......@@ -284,13 +284,15 @@ window_cmd_file_open (GtkAction *action,
}
static char *
get_suggested_filename (EphyWebView *view)
get_suggested_filename (EphyEmbed *embed)
{
EphyWebView *view;
char *suggested_filename = NULL;
const char *mimetype;
WebKitURIResponse *response;
WebKitWebResource *web_resource;
view = ephy_embed_get_web_view (embed);
web_resource = webkit_web_view_get_main_resource (WEBKIT_WEB_VIEW (view));
response = webkit_web_resource_get_response (web_resource);
mimetype = webkit_uri_response_get_mime_type (response);
......@@ -298,7 +300,7 @@ get_suggested_filename (EphyWebView *view)
if ((g_ascii_strncasecmp (mimetype, "text/html", 9)) == 0)
{
/* Web Title will be used as suggested filename */
suggested_filename = g_strconcat (ephy_web_view_get_title (view), ".mhtml", NULL);
suggested_filename = g_strconcat (ephy_embed_get_title (embed), ".mhtml", NULL);
}
else
{
......@@ -321,7 +323,6 @@ window_cmd_file_save_as (GtkAction *action,
EphyEmbed *embed;
EphyFileChooser *dialog;
char *suggested_filename;
EphyWebView *view;
embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
g_return_if_fail (embed != NULL);
......@@ -333,8 +334,7 @@ window_cmd_file_save_as (GtkAction *action,
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
view = ephy_embed_get_web_view (embed);
suggested_filename = ephy_sanitize_filename (get_suggested_filename (view));
suggested_filename = ephy_sanitize_filename (get_suggested_filename (embed));
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), suggested_filename);
g_free (suggested_filename);
......@@ -660,7 +660,7 @@ set_default_application_title (EphyApplicationDialogData *data,
if (title == NULL || title[0] == '\0')
{
title = g_strdup (ephy_web_view_get_title (data->view));
title = g_strdup (webkit_web_view_get_title (WEBKIT_WEB_VIEW (data->view)));
}
gtk_entry_set_text (GTK_ENTRY (data->entry), title);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment