[epiphany/overview] ephy-embed: add title property



commit 9e07a8a3d43f816b6059a772a63603a616672082
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Mon Aug 20 16:27:47 2012 +0300

    ephy-embed: add title property
    
    This property has either the title of the page or just "New tab" if
    the embed is in overview mode.

 embed/ephy-embed.c |   72 ++++++++++++++++++++++++++++++++++++++++++++++++---
 embed/ephy-embed.h |    1 +
 2 files changed, 68 insertions(+), 5 deletions(-)
---
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 542240f..8580c0e 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -43,12 +43,15 @@
 #include <webkit/webkit.h>
 #endif
 
-static void     ephy_embed_constructed      (GObject *object);
+static void     ephy_embed_constructed        (GObject *object);
 #ifndef HAVE_WEBKIT2
-static gboolean ephy_embed_inspect_show_cb  (WebKitWebInspector *inspector,
-                                             EphyEmbed *embed);
-static gboolean ephy_embed_inspect_close_cb (WebKitWebInspector *inspector,
-                                             EphyEmbed *embed);
+static gboolean ephy_embed_inspect_show_cb    (WebKitWebInspector *inspector,
+                                               EphyEmbed *embed);
+static gboolean ephy_embed_inspect_close_cb   (WebKitWebInspector *inspector,
+                                               EphyEmbed *embed);
+static void     ephy_embed_set_title_internal (EphyEmbed *embed,
+                                               const char *title);
+
 #endif
 
 #define EPHY_EMBED_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_EMBED, EphyEmbedPrivate))
@@ -81,6 +84,8 @@ struct _EphyEmbedPrivate
 
   GtkWidget *overview;
   guint overview_mode : 1;
+  char *title;
+
   GSList *messages;
   GSList *keys;
 
@@ -102,6 +107,7 @@ enum
 {
   PROP_0,
   PROP_OVERVIEW_MODE,
+  PROP_TITLE,
 };
 
 G_DEFINE_TYPE (EphyEmbed, ephy_embed, GTK_TYPE_BOX)
@@ -348,6 +354,20 @@ ephy_embed_leaving_fullscreen (EphyEmbed *embed)
 }
 
 static void
+notify_title_cb (GObject *object,
+                 GParamSpec *pspec,
+                 EphyEmbed *embed)
+{
+  EphyWebView *web_view = EPHY_WEB_VIEW (object);
+
+  if (embed->priv->overview_mode)
+    return;
+
+  ephy_embed_set_title_internal (embed,
+                                 ephy_web_view_get_title (EPHY_WEB_VIEW (web_view)));
+}
+
+static void
 ephy_embed_dispose (GObject *object)
 {
   EphyEmbed *embed = EPHY_EMBED (object);
@@ -435,6 +455,8 @@ ephy_embed_finalize (GObject *object)
 
   g_free (embed->priv->fullscreen_string);
 
+  g_free (embed->priv->title);
+
   G_OBJECT_CLASS (ephy_embed_parent_class)->finalize (object);
 }
 
@@ -451,6 +473,9 @@ ephy_embed_set_property (GObject *object,
   case PROP_OVERVIEW_MODE:
     ephy_embed_set_overview_mode (embed, g_value_get_boolean (value));
     break;
+  case PROP_TITLE:
+    ephy_embed_set_title_internal (embed, g_value_get_string (value));
+    break;
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     break;
@@ -470,6 +495,9 @@ ephy_embed_get_property (GObject *object,
   case PROP_OVERVIEW_MODE:
     g_value_set_boolean (value, ephy_embed_get_overview_mode (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;
@@ -497,6 +525,14 @@ ephy_embed_class_init (EphyEmbedClass *klass)
                                                          FALSE,
                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
+  g_object_class_install_property (object_class,
+                                   PROP_TITLE,
+                                   g_param_spec_string ("title",
+                                                        "Embed title",
+                                                        "Title of this embed",
+                                                        "",
+                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
   g_type_class_add_private (G_OBJECT_CLASS (klass), sizeof(EphyEmbedPrivate));
 }
 
@@ -914,6 +950,7 @@ ephy_embed_constructed (GObject *object)
                     "signal::download-requested", G_CALLBACK (download_requested_cb), embed,
                     "signal::entering-fullscreen", G_CALLBACK (entering_fullscreen_cb), embed,
                     "signal::leaving-fullscreen", G_CALLBACK (leaving_fullscreen_cb), embed,
+                    "signal::notify::title", G_CALLBACK (notify_title_cb), embed,
                     NULL);
 #endif
 
@@ -1100,6 +1137,27 @@ ephy_embed_get_container (EphyEmbed *embed)
 
   return gtk_widget_get_parent (GTK_WIDGET (embed));
 }
+
+static void
+ephy_embed_set_title_internal (EphyEmbed *embed,
+                               const char *title)
+{
+  if (embed->priv->title)
+    g_free (embed->priv->title);
+
+  embed->priv->title = g_strdup (title);
+
+  g_object_notify (G_OBJECT (embed), "title");
+}
+
+const char *
+ephy_embed_get_title (EphyEmbed *embed)
+{
+  g_return_val_if_fail (EPHY_IS_EMBED (embed), NULL);
+
+  return embed->priv->title;
+}
+
 void
 ephy_embed_set_overview_mode (EphyEmbed *embed, gboolean overview_mode)
 {
@@ -1114,6 +1172,10 @@ ephy_embed_set_overview_mode (EphyEmbed *embed, gboolean overview_mode)
 
   priv->overview_mode = overview_mode;
 
+  ephy_embed_set_title_internal (embed,
+                                 overview_mode ? _("New tab") :
+                                 ephy_web_view_get_title (EPHY_WEB_VIEW (priv->web_view)));
+
   g_object_notify (G_OBJECT (embed), "overview-mode");
 }
 
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index defdcbc..51b61a1 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -67,6 +67,7 @@ void         ephy_embed_set_overview_mode        (EphyEmbed *embed,
                                                   gboolean   overview_mode);
 gboolean     ephy_embed_get_overview_mode        (EphyEmbed *embed);
 EphyOverview*ephy_embed_get_overview             (EphyEmbed *embed);
+const char  *ephy_embed_get_title                (EphyEmbed *embed);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]