[Xfce4-commits] <midori:master> Render completion title/ URL side by side with Granite

Christian Dywan noreply at xfce.org
Thu Dec 6 02:32:04 CET 2012


Updating branch refs/heads/master
         to 4dcba68069f6d2873427d81b9f8e0899a7873c65 (commit)
       from 1f47b2de8710f0b7db540681f4025e744cb5a5cc (commit)

commit 4dcba68069f6d2873427d81b9f8e0899a7873c65
Author: Christian Dywan <christian at twotoasts.de>
Date:   Wed Dec 5 23:39:32 2012 +0100

    Render completion title/ URL side by side with Granite
    
    Each completion shows a title before its results.
    
    This mode is (for now) Granite-only, though it's 100% GTK+.
    
    Fixes: https://bugs.launchpad.net/midori/+bug/752915

 midori/midori-completion.vala        |   18 ++-
 midori/midori-historycompletion.vala |    2 +-
 midori/midori-locationaction.c       |  459 +++++++++++++++++++---------------
 midori/midori-searchcompletion.vala  |    2 +-
 midori/midori-viewcompletion.vala    |    2 +-
 5 files changed, 273 insertions(+), 210 deletions(-)

diff --git a/midori/midori-completion.vala b/midori/midori-completion.vala
index f7d23f1..e094de2 100644
--- a/midori/midori-completion.vala
+++ b/midori/midori-completion.vala
@@ -85,7 +85,18 @@ namespace Midori {
                 current_count = 0;
             }
 
-            int count = 0;
+#if HAVE_GRANITE
+            if (completion.description != null) {
+                model.insert_with_values (null, completion.position,
+                    Columns.URI, "about:completion-description",
+                    Columns.MARKUP, "<b>%s</b>\n".printf (Markup.escape_text (completion.description)),
+                    Columns.ICON, null,
+                    Columns.BACKGROUND, null,
+                    Columns.YALIGN, 0.25);
+            }
+#endif
+
+            int count = 1;
             foreach (var suggestion in suggestions) {
                 model.insert_with_values (null, completion.position + count,
                     Columns.URI, suggestion.uri,
@@ -125,6 +136,8 @@ namespace Midori {
         }
 
         public bool can_action (string action) {
+            if (action == "about:completion-description")
+                return true;
             foreach (var completion in completions)
                 if (completion.can_action (action))
                     return true;
@@ -132,6 +145,9 @@ namespace Midori {
         }
 
         public async void action (string action, string text) {
+            if (action == "about:completion-description")
+                return;
+
             if (cancellable != null)
                 cancellable.cancel ();
             cancellable = new Cancellable ();
diff --git a/midori/midori-historycompletion.vala b/midori/midori-historycompletion.vala
index 2bc761f..d7e756f 100644
--- a/midori/midori-historycompletion.vala
+++ b/midori/midori-historycompletion.vala
@@ -18,7 +18,7 @@ namespace Midori {
         unowned Sqlite.Database db;
 
         public HistoryCompletion () {
-            GLib.Object (description: "Bookmarks and history");
+            GLib.Object (description: _("History"));
         }
 
         public override void prepare (GLib.Object app) {
diff --git a/midori/midori-locationaction.c b/midori/midori-locationaction.c
index aa685bc..c8fa3ea 100644
--- a/midori/midori-locationaction.c
+++ b/midori/midori-locationaction.c
@@ -104,13 +104,6 @@ midori_location_action_disconnect_proxy (GtkAction* action,
                                          GtkWidget* proxy);
 
 static void
-midori_location_entry_render_text_cb (GtkCellLayout*   layout,
-                                      GtkCellRenderer* renderer,
-                                      GtkTreeModel*    model,
-                                      GtkTreeIter*     iter,
-                                      gpointer         data);
-
-static void
 midori_location_action_popdown_completion (MidoriLocationAction* location_action);
 
 static void
@@ -231,6 +224,239 @@ midori_location_action_class_init (MidoriLocationActionClass* class)
                                      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 }
 
+static gchar*
+midori_location_entry_render_uri (gchar**      keys,
+                                  const gchar* uri_escaped)
+{
+    gchar* uri_unescaped = midori_uri_unescape (uri_escaped);
+    gchar* uri = g_strescape (uri_unescaped, NULL);
+    g_free (uri_unescaped);
+
+    gchar* stripped_uri = midori_uri_strip_prefix_for_display (uri);
+    gchar* temp;
+    gchar* temp_iter = temp = g_utf8_strdown (stripped_uri, -1);
+    gchar* desc_iter = stripped_uri;
+    gint key_idx = 0;
+    gchar* key = keys[key_idx];
+    gint offset = 0;
+    gchar* start;
+    gchar* desc_uri = NULL;
+    while (key && (start = strstr (temp_iter, key)) && start)
+    {
+        gsize len = strlen (key);
+        if (len)
+        {
+            offset = (start - temp_iter);
+            gchar* skey = g_strndup (desc_iter + offset, len);
+            gchar** parts = g_strsplit (desc_iter, skey, 2);
+            if (parts[0] && parts[1])
+                desc_uri = g_markup_printf_escaped ("%s<b>%s</b>", parts[0], skey);
+            g_strfreev (parts);
+            g_free (skey);
+
+            offset += len;
+            temp_iter += offset;
+            desc_iter += offset;
+        }
+        key_idx++;
+        key = keys[key_idx];
+        if (key == NULL)
+            break;
+    }
+    if (key)
+        katze_assign (desc_uri, NULL);
+    if (desc_uri)
+    {
+        gchar* temp_markup = g_markup_escape_text (desc_iter, -1);
+        gchar* temp_concat = g_strconcat (desc_uri, temp_markup, NULL);
+        g_free (temp_markup);
+        katze_assign (desc_uri, temp_concat);
+    }
+    else
+        desc_uri = g_markup_escape_text (stripped_uri, -1);
+    g_free (temp);
+    g_free (stripped_uri);
+    return desc_uri;
+}
+
+static gchar*
+midori_location_entry_render_title (gchar**      keys,
+                                    const gchar* title)
+{
+    gchar* temp;
+    gchar* temp_iter = temp = g_utf8_strdown (title, -1);
+    const gchar* desc_iter = title;
+    gint key_idx = 0;
+    gchar* key = keys[key_idx];
+    gint offset = 0;
+    gchar* start;
+    gchar* desc_title = NULL;
+    while (key && (start = strstr (temp_iter, key)) && start)
+    {
+        gsize len = strlen (key);
+        if (len)
+        {
+            offset = (start - temp_iter);
+            gchar* skey = g_strndup (desc_iter + offset, len);
+            gchar** parts = g_strsplit (desc_iter, skey, 2);
+            if (parts[0] && parts[1])
+                desc_title = g_markup_printf_escaped ("%s<b>%s</b>", parts[0], skey);
+            g_strfreev (parts);
+            g_free (skey);
+
+            offset += len;
+            temp_iter += offset;
+            desc_iter += offset;
+        }
+        key_idx++;
+        key = keys[key_idx];
+        if (key == NULL)
+            break;
+    }
+    if (key)
+        katze_assign (desc_title, NULL);
+    if (desc_title)
+    {
+        gchar* temp_markup = g_markup_escape_text (desc_iter, -1);
+        gchar* temp_concat = g_strconcat (desc_title, temp_markup, NULL);
+        g_free (temp_markup);
+        katze_assign (desc_title, temp_concat);
+    }
+    else
+        desc_title = g_markup_escape_text (title, -1);
+    g_free (temp);
+    return desc_title;
+}
+
+#ifdef HAVE_GRANITE
+static void
+midori_location_entry_render_title_cb (GtkCellLayout*   layout,
+                                       GtkCellRenderer* renderer,
+                                       GtkTreeModel*    model,
+                                       GtkTreeIter*     iter,
+                                       gpointer         data)
+{
+    MidoriLocationAction* action = data;
+    gchar* title;
+    gchar* background;
+    gchar* desc;
+
+    gtk_tree_model_get (model, iter,
+        MIDORI_AUTOCOMPLETER_COLUMNS_MARKUP, &title,
+        MIDORI_AUTOCOMPLETER_COLUMNS_BACKGROUND, &background,
+        -1);
+
+    if (strchr (title, '\n')) /* A search engine or action suggestion */
+    {
+        gchar** parts = g_strsplit (title, "\n", 2);
+        desc = g_strdup (parts[0]);
+        g_strfreev (parts);
+        g_free (background);
+    }
+    else
+    {
+        gchar* key = g_utf8_strdown (action->key ? action->key : "", -1);
+        gchar** keys = g_strsplit_set (key, " %", -1);
+        g_free (key);
+        desc = midori_location_entry_render_title (keys, title);
+        g_strfreev (keys);
+    }
+
+    g_object_set (renderer, "markup", desc,
+        "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+    g_free (desc);
+    g_free (title);
+}
+
+static void
+midori_location_entry_render_uri_cb (GtkCellLayout*   layout,
+                                     GtkCellRenderer* renderer,
+                                     GtkTreeModel*    model,
+                                     GtkTreeIter*     iter,
+                                     gpointer         data)
+{
+    MidoriLocationAction* action = data;
+    gchar* title;
+    gchar* uri_escaped;
+    gchar* background;
+    gchar* desc;
+
+    gtk_tree_model_get (model, iter,
+        MIDORI_AUTOCOMPLETER_COLUMNS_MARKUP, &title,
+        MIDORI_AUTOCOMPLETER_COLUMNS_URI, &uri_escaped,
+        MIDORI_AUTOCOMPLETER_COLUMNS_BACKGROUND, &background,
+        -1);
+
+    if (strchr (title, '\n')) /* A search engine or action suggestion */
+    {
+        gchar** parts = g_strsplit (title, "\n", 2);
+        desc = g_strdup (parts[1]);
+        g_strfreev (parts);
+        g_free (background);
+    }
+    else
+    {
+        gchar* key = g_utf8_strdown (action->key ? action->key : "", -1);
+        gchar** keys = g_strsplit_set (key, " %", -1);
+        g_free (key);
+        desc = midori_location_entry_render_uri (keys, uri_escaped);
+        g_strfreev (keys);
+        g_free (uri_escaped);
+    }
+
+    g_object_set (renderer, "markup", desc,
+        "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+    g_free (desc);
+    g_free (title);
+}
+#else
+static void
+midori_location_entry_render_text_cb (GtkCellLayout*   layout,
+                                      GtkCellRenderer* renderer,
+                                      GtkTreeModel*    model,
+                                      GtkTreeIter*     iter,
+                                      gpointer         data)
+{
+    MidoriLocationAction* action = data;
+    gchar* uri_escaped;
+    gchar* title;
+    gchar* background;
+    gchar* desc;
+
+    gtk_tree_model_get (model, iter,
+        MIDORI_AUTOCOMPLETER_COLUMNS_URI, &uri_escaped,
+        MIDORI_AUTOCOMPLETER_COLUMNS_MARKUP, &title,
+        MIDORI_AUTOCOMPLETER_COLUMNS_BACKGROUND, &background,
+        -1);
+
+    if (strchr (title, '\n')) /* A search engine or action suggestion */
+    {
+        desc = title;
+        g_free (uri_escaped);
+        g_free (background);
+    }
+    else
+    {
+        gchar* key = g_utf8_strdown (action->key ? action->key : "", -1);
+        gchar** keys = g_strsplit_set (key, " %", -1);
+        g_free (key);
+        gchar* desc_uri = midori_location_entry_render_uri (keys, uri_escaped);
+        gchar* desc_title = midori_location_entry_render_title (keys, title);
+        desc = g_strdup_printf ("%s\n<span color='gray45'>%s</span>", desc_title, desc_uri);
+        g_free (uri_escaped);
+        g_free (title);
+        g_strfreev (keys);
+        g_free (desc_uri);
+        g_free (desc_title);
+    }
+
+    g_object_set (renderer, "markup", desc,
+        "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+    g_free (desc);
+}
+#endif
+
+
 static void
 midori_location_action_popup_position (MidoriLocationAction* action,
                                        gint                  matches)
@@ -488,16 +714,33 @@ midori_location_action_popup_timeout_cb (gpointer data)
             "cell-background", MIDORI_AUTOCOMPLETER_COLUMNS_BACKGROUND,
             NULL);
         renderer = gtk_cell_renderer_text_new ();
-        gtk_cell_renderer_set_fixed_size (renderer, 1, -1);
-        gtk_cell_renderer_text_set_fixed_height_from_font (
-            GTK_CELL_RENDERER_TEXT (renderer), 2);
+        #if HAVE_GRANITE
+        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, FALSE);
+        #else
         gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, TRUE);
+        #endif
         gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), renderer,
             "cell-background", MIDORI_AUTOCOMPLETER_COLUMNS_BACKGROUND,
             NULL);
+        #if HAVE_GRANITE
+        gtk_tree_view_column_set_expand (column, TRUE);
+        gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), renderer,
+            midori_location_entry_render_title_cb, action, NULL);
+
+        renderer = gtk_cell_renderer_text_new ();
+        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, TRUE);
+        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), renderer,
+            "cell-background", MIDORI_AUTOCOMPLETER_COLUMNS_BACKGROUND, NULL);
+        gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), renderer,
+            midori_location_entry_render_uri_cb, action, NULL);
+        #else
+        gtk_cell_renderer_set_fixed_size (renderer, 1, -1);
+        gtk_cell_renderer_text_set_fixed_height_from_font (
+            GTK_CELL_RENDERER_TEXT (renderer), 2);
         gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), renderer,
                                             midori_location_entry_render_text_cb,
                                             action, NULL);
+        #endif
         gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
 
         action->popup = popup;
@@ -1263,202 +1506,6 @@ midori_location_action_icon_released_cb (GtkWidget*           widget,
 }
 
 static void
-midori_location_entry_render_text_cb (GtkCellLayout*   layout,
-                                      GtkCellRenderer* renderer,
-                                      GtkTreeModel*    model,
-                                      GtkTreeIter*     iter,
-                                      gpointer         data)
-{
-    MidoriLocationAction* action = data;
-    gchar* uri_escaped;
-    gchar* uri_temp;
-    gchar* uri;
-    gchar* title;
-    gchar* background;
-    gchar* desc;
-    gchar* desc_uri;
-    gchar* desc_iter;
-    gchar* temp_iter;
-    gchar* desc_title;
-    const gchar* str;
-    gchar* key;
-    gchar** keys;
-    gint key_idx;
-    gchar* start;
-    gchar* skey;
-    gchar* temp;
-    gchar* temp_concat;
-    gchar* temp_markup;
-    gchar** parts;
-    size_t offset;
-
-    gtk_tree_model_get (model, iter,
-        MIDORI_AUTOCOMPLETER_COLUMNS_URI, &uri_escaped,
-        MIDORI_AUTOCOMPLETER_COLUMNS_MARKUP, &title,
-        MIDORI_AUTOCOMPLETER_COLUMNS_BACKGROUND, &background,
-        -1);
-
-    if (background != NULL) /* A search engine or action suggestion */
-    {
-        g_object_set (renderer, "markup", title,
-            "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
-        g_free (uri_escaped);
-        g_free (title);
-        g_free (background);
-        return;
-    }
-
-    desc = desc_uri = desc_title = key = NULL;
-    if (action->key)
-        str = action->key;
-    else
-        str = "";
-
-    key = g_utf8_strdown (str, -1);
-    keys = g_strsplit_set (key, " %", -1);
-    g_free (key);
-
-    uri_temp = midori_uri_unescape (uri_escaped);
-    g_free (uri_escaped);
-    uri = g_strescape (uri_temp, NULL);
-    g_free (uri_temp);
-
-    if (G_LIKELY (uri))
-    {
-        gchar* stripped_uri = midori_uri_strip_prefix_for_display (uri);
-        temp_iter = temp = g_utf8_strdown (stripped_uri, -1);
-        desc_iter = stripped_uri;
-        key_idx = 0;
-        key = keys[key_idx];
-        offset = 0;
-        while (key && (start = strstr (temp_iter, key)) && start)
-        {
-            gsize len = strlen (key);
-            if (len)
-            {
-                offset = (start - temp_iter);
-                skey = g_strndup (desc_iter + offset, len);
-                parts = g_strsplit (desc_iter, skey, 2);
-                if (parts[0] && parts[1])
-                {
-                    if (desc_uri)
-                    {
-                        temp_markup = g_markup_printf_escaped ("%s<b>%s</b>",
-                            parts[0], skey);
-                        temp_concat = g_strconcat (desc_uri, temp_markup, NULL);
-                        g_free (temp_markup);
-                        katze_assign (desc_uri, temp_concat);
-                    }
-                    else
-                    {
-                        desc_uri = g_markup_printf_escaped ("%s<b>%s</b>",
-                            parts[0], skey);
-                    }
-                }
-                g_strfreev (parts);
-                g_free (skey);
-
-                offset += len;
-                temp_iter += offset;
-                desc_iter += offset;
-            }
-            key_idx++;
-            key = keys[key_idx];
-            if (key == NULL)
-                break;
-        }
-        if (key)
-            katze_assign (desc_uri, NULL);
-        if (desc_uri)
-        {
-            temp_markup = g_markup_escape_text (desc_iter, -1);
-            temp_concat = g_strconcat (desc_uri, temp_markup, NULL);
-            g_free (temp_markup);
-            katze_assign (desc_uri, temp_concat);
-        }
-        else
-            desc_uri = g_markup_escape_text (stripped_uri, -1);
-        g_free (temp);
-        g_free (stripped_uri);
-    }
-
-    if (G_LIKELY (title))
-    {
-        temp_iter = temp = g_utf8_strdown (title, -1);
-        desc_iter = title;
-        key_idx = 0;
-        key = keys[key_idx];
-        offset = 0;
-        while (key && (start = strstr (temp_iter, key)) && start)
-        {
-            gsize len = strlen (key);
-            if (len)
-            {
-                offset = (start - temp_iter);
-                skey = g_strndup (desc_iter + offset, len);
-                parts = g_strsplit (desc_iter, skey, 2);
-                if (parts[0] && parts[1])
-                {
-                    if (desc_title)
-                    {
-                        temp_markup = g_markup_printf_escaped ("%s<b>%s</b>",
-                            parts[0], skey);
-                        temp_concat = g_strconcat (desc_title, temp_markup, NULL);
-                        g_free (temp_markup);
-                        katze_assign (desc_title, temp_concat);
-                    }
-                    else
-                    {
-                        desc_title = g_markup_printf_escaped ("%s<b>%s</b>",
-                            parts[0], skey);
-                    }
-                }
-                g_strfreev (parts);
-                g_free (skey);
-
-                offset += len;
-                temp_iter += offset;
-                desc_iter += offset;
-            }
-            key_idx++;
-            key = keys[key_idx];
-            if (key == NULL)
-                break;
-        }
-        if (key)
-            katze_assign (desc_title, NULL);
-        if (desc_title)
-        {
-            temp_markup = g_markup_escape_text (desc_iter, -1);
-            temp_concat = g_strconcat (desc_title, temp_markup, NULL);
-            g_free (temp_markup);
-            katze_assign (desc_title, temp_concat);
-        }
-        else
-            desc_title = g_markup_escape_text (title, -1);
-        g_free (temp);
-    }
-
-    if (desc_title)
-    {
-        desc = g_strdup_printf ("%s\n<span color='gray45'>%s</span>",
-                                desc_title, desc_uri);
-        g_free (desc_uri);
-        g_free (desc_title);
-    }
-    else
-        desc = desc_uri;
-
-    g_object_set (renderer, "markup", desc,
-        "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
-
-    g_free (uri);
-    g_free (title);
-    g_strfreev (keys);
-    g_free (desc);
-}
-
-static void
 midori_location_action_paste_proceed_cb (GtkWidget* menuitem,
                                          GtkWidget* location_action)
 {
diff --git a/midori/midori-searchcompletion.vala b/midori/midori-searchcompletion.vala
index 0a5c44e..282542c 100644
--- a/midori/midori-searchcompletion.vala
+++ b/midori/midori-searchcompletion.vala
@@ -20,7 +20,7 @@ namespace Midori {
         GLib.Object search_engines;
 
         public SearchCompletion () {
-            GLib.Object (description: "Search engines");
+            GLib.Object (description: _("Search with…"));
         }
 
         public override void prepare (GLib.Object app) {
diff --git a/midori/midori-viewcompletion.vala b/midori/midori-viewcompletion.vala
index a259c85..5cb8764 100644
--- a/midori/midori-viewcompletion.vala
+++ b/midori/midori-viewcompletion.vala
@@ -15,7 +15,7 @@ namespace Midori {
         GLib.Object browsers;
 
         public ViewCompletion () {
-            GLib.Object (description: "Open tabs");
+            GLib.Object (description: _("Open tabs"));
         }
 
         public override void prepare (GLib.Object app) {


More information about the Xfce4-commits mailing list