[gnome-software/wip/rancell/ubuntu-3-20-rebase: 5/12] Limit search entry to 100 characters.



commit 0c3d4b83932585cd7ddb46b821b8f2fbf7c2a16e
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri May 12 11:39:26 2017 +1200

    Limit search entry to 100 characters.
    
    The search entry can be linked to a remote server - by limiting the number of
    characters this stops accidental input (e.g. cat sitting on keyboard) from
    generating continuous searches.

 src/gnome-software.ui |    1 +
 src/gs-shell.c        |   11 +++++++++++
 2 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-software.ui b/src/gnome-software.ui
index 1d9ddad..cace04a 100644
--- a/src/gnome-software.ui
+++ b/src/gnome-software.ui
@@ -286,6 +286,7 @@
                         <property name="can_focus">True</property>
                         <property name="activates_default">True</property>
                         <property name="width_request">500</property>
+                        <property name="max_length">100</property>
                         <property name="hexpand">True</property>
                         <property name="halign">center</property>
                       </object>
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 5468c5d..bd2deb0 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -78,6 +78,7 @@ typedef struct
        GQueue                  *back_entry_stack;
        gboolean                 ignore_next_search_changed_signal;
        GPtrArray               *modal_dialogs;
+       gchar                   *last_search;
 } GsShellPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GsShell, gs_shell, G_TYPE_OBJECT)
@@ -547,6 +548,15 @@ search_changed_handler (GObject *entry, GsShell *shell)
                return;
        }
 
+       /* ignore if search text not changed. This is a workaround since GtkEntry
+         * emits changed even when the character limit is hit
+         * https://bugzilla.gnome.org/show_bug.cgi?id=782636
+         */
+       if (g_strcmp0 (text, priv->last_search) == 0)
+               return;
+       g_free (priv->last_search);
+       priv->last_search = g_strdup (text);
+
        if (strlen(text) > 2) {
                if (gs_shell_get_mode (shell) != GS_SHELL_MODE_SEARCH) {
                        gs_shell_change_mode (shell, GS_SHELL_MODE_SEARCH, NULL, NULL, TRUE);
@@ -955,6 +965,7 @@ gs_shell_dispose (GObject *object)
        g_clear_object (&priv->header_start_widget);
        g_clear_object (&priv->header_end_widget);
        g_clear_pointer (&priv->modal_dialogs, (GDestroyNotify) g_ptr_array_unref);
+       g_clear_pointer (&priv->last_search, g_free);
 
        G_OBJECT_CLASS (gs_shell_parent_class)->dispose (object);
 }


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