[epiphany/gnome-3-18] location-entry: Properly normalize URI for cut/copy



commit 5dde1af2a5652c0e778efc2aa654fe765ce0a9e3
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Tue Feb 9 13:39:40 2016 -0600

    location-entry: Properly normalize URI for cut/copy
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761660

 lib/ephy-uri-helpers.c            |   19 ++++++++++++++++
 lib/ephy-uri-helpers.h            |    1 +
 lib/widgets/ephy-location-entry.c |   42 +++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/lib/ephy-uri-helpers.c b/lib/ephy-uri-helpers.c
index d4d8335..4b626e3 100644
--- a/lib/ephy-uri-helpers.c
+++ b/lib/ephy-uri-helpers.c
@@ -263,4 +263,23 @@ ephy_uri_safe_unescape (const char *uri_string)
   return decoded_uri ? decoded_uri : g_strdup (uri_string);
 }
 
+char *
+ephy_uri_normalize (const char *uri_string)
+{
+  SoupURI *uri;
+  char *encoded_uri;
+
+  if (!uri_string || !*uri_string)
+    return NULL;
+
+  uri = soup_uri_new (uri_string);
+  if (!uri)
+    return g_strdup (uri_string);
+
+  encoded_uri = soup_uri_normalize (uri_string, NULL);
+  soup_uri_free (uri);
+
+  return encoded_uri;
+}
+
 /* vim: set sw=2 ts=2 sts=2 et: */
diff --git a/lib/ephy-uri-helpers.h b/lib/ephy-uri-helpers.h
index 60a165e..6559374 100644
--- a/lib/ephy-uri-helpers.h
+++ b/lib/ephy-uri-helpers.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 
 char *ephy_remove_tracking_from_uri (const char *uri);
 char *ephy_uri_safe_unescape (const char *uri);
+char *ephy_uri_normalize (const char *uri);
 
 G_END_DECLS
 
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 629be35..4739d20 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -31,6 +31,7 @@
 #include "ephy-gui.h"
 #include "ephy-lib-type-builtins.h"
 #include "ephy-signal-accumulator.h"
+#include "ephy-uri-helpers.h"
 
 #include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
@@ -210,15 +211,56 @@ ephy_location_entry_get_preferred_width (GtkWidget       *widget,
 }
 
 static void
+ephy_location_entry_copy_clipboard (GtkEntry *entry)
+{
+       char *text;
+       gint start;
+       gint end;
+
+       if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
+               return;
+
+       text = gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
+
+       if (start == 0)
+       {
+               char *tmp = text;
+               text = ephy_uri_normalize (tmp);
+               g_free (tmp);
+       }
+
+       gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
+                                                         GDK_SELECTION_CLIPBOARD),
+                                                         text, -1);
+       g_free (text);
+}
+
+static void
+ephy_location_entry_cut_clipboard (GtkEntry *entry)
+{
+       if (!gtk_editable_get_editable (GTK_EDITABLE (entry)))
+       {
+               gtk_widget_error_bell (GTK_WIDGET (entry));
+               return;
+       }
+
+       ephy_location_entry_copy_clipboard (entry);
+       gtk_editable_delete_selection (GTK_EDITABLE (entry));
+}
+
+static void
 ephy_location_entry_class_init (EphyLocationEntryClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+       GtkEntryClass *entry_class = GTK_ENTRY_CLASS (klass);
 
        object_class->get_property = ephy_location_entry_get_property;
        object_class->set_property = ephy_location_entry_set_property;
        object_class->finalize = ephy_location_entry_finalize;
        widget_class->get_preferred_width = ephy_location_entry_get_preferred_width;
+       entry_class->copy_clipboard = ephy_location_entry_copy_clipboard;
+       entry_class->cut_clipboard = ephy_location_entry_cut_clipboard;
 
        /**
        * EphyLocationEntry:location:


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