[gnome-software/gnome-3-24] Limit search entry to 100 characters.



commit a13d539993bd0322da8bb85af6d84ab5f468b4f3
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        |   12 ++++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-software.ui b/src/gnome-software.ui
index aa17a46..c551ceb 100644
--- a/src/gnome-software.ui
+++ b/src/gnome-software.ui
@@ -284,6 +284,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 7819c6e..5834ed1 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -79,6 +79,7 @@ typedef struct
        gboolean                 profile_mode;
        gboolean                 in_mode_change;
        GsPage                  *page_last;
+       gchar                   *last_search;
 } GsShellPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GsShell, gs_shell, G_TYPE_OBJECT)
@@ -602,6 +603,16 @@ search_changed_handler (GObject *entry, GsShell *shell)
        const gchar *text;
 
        text = gtk_entry_get_text (GTK_ENTRY (entry));
+
+       /* 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) {
                        save_back_entry (shell);
@@ -1936,6 +1947,7 @@ gs_shell_dispose (GObject *object)
        g_clear_pointer (&priv->pages, (GDestroyNotify) g_hash_table_unref);
        g_clear_pointer (&priv->events_info_uri, (GDestroyNotify) g_free);
        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]