[gtk+/gtk-3-10] printing: Enable search through locations in printers list
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-10] printing: Enable search through locations in printers list
- Date: Sun, 6 Apr 2014 03:40:06 +0000 (UTC)
commit 9c03a6a351f82a5f5b22460773f013e6f61d89d8
Author: Marek Kasik <mkasik redhat com>
Date: Thu Dec 19 14:52:16 2013 +0100
printing: Enable search through locations in printers list
Add printer_compare() function for comparing printers according
to their names and locations. It is possible to search by multiple
keys separated by space or tabulator using logical conjunction.
Based on patch by William Hua.
https://bugzilla.gnome.org/show_bug.cgi?id=692931
gtk/gtkprintunixdialog.c | 87 +++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkprintunixdialog.ui | 1 -
2 files changed, 87 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index 1ab4d0a..94fdec0 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -208,6 +208,11 @@ static gboolean set_active_printer (GtkPrintUnixDialog *dialog,
const gchar *printer_name);
static void redraw_page_layout_preview (GtkPrintUnixDialog *dialog);
static void load_print_backends (GtkPrintUnixDialog *dialog);
+static gboolean printer_compare (GtkTreeModel *model,
+ gint column,
+ const gchar *key,
+ GtkTreeIter *iter,
+ gpointer search_data);
/* GtkBuildable */
static void gtk_print_unix_dialog_buildable_init (GtkBuildableIface *iface);
@@ -760,6 +765,9 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
GTK_SORT_ASCENDING);
+ gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (priv->printer_treeview),
+ printer_compare, NULL, NULL);
+
gtk_tree_view_column_set_cell_data_func (priv->printer_icon_column,
priv->printer_icon_renderer,
set_cell_sensitivity_func, NULL, NULL);
@@ -2083,6 +2091,85 @@ selected_printer_changed (GtkTreeSelection *selection,
g_object_notify ( G_OBJECT(dialog), "selected-printer");
}
+static gboolean
+printer_compare (GtkTreeModel *model,
+ gint column,
+ const gchar *key,
+ GtkTreeIter *iter,
+ gpointer search_data)
+{
+ gboolean matches = FALSE;
+
+ if (key != NULL)
+ {
+ gchar *name = NULL;
+ gchar *location = NULL;
+ gchar *casefold_key = NULL;
+ gchar *casefold_name = NULL;
+ gchar *casefold_location = NULL;
+ gchar **keys;
+ gchar *tmp1, *tmp2;
+ gint i;
+
+ gtk_tree_model_get (model, iter,
+ PRINTER_LIST_COL_NAME, &name,
+ PRINTER_LIST_COL_LOCATION, &location,
+ -1);
+
+ casefold_key = g_utf8_casefold (key, -1);
+
+ if (name != NULL)
+ {
+ casefold_name = g_utf8_casefold (name, -1);
+ g_free (name);
+ }
+
+ if (location != NULL)
+ {
+ casefold_location = g_utf8_casefold (location, -1);
+ g_free (location);
+ }
+
+ if (casefold_name != NULL ||
+ casefold_location != NULL)
+ {
+ keys = g_strsplit_set (casefold_key, " \t", 0);
+ if (keys != NULL)
+ {
+ matches = TRUE;
+
+ for (i = 0; keys[i] != NULL; i++)
+ {
+ if (keys[i][0] != '\0')
+ {
+ tmp1 = tmp2 = NULL;
+
+ if (casefold_name != NULL)
+ tmp1 = g_strstr_len (casefold_name, -1, keys[i]);
+
+ if (casefold_location != NULL)
+ tmp2 = g_strstr_len (casefold_location, -1, keys[i]);
+
+ if (tmp1 == NULL && tmp2 == NULL)
+ {
+ matches = FALSE;
+ break;
+ }
+ }
+ }
+
+ g_strfreev (keys);
+ }
+ }
+
+ g_free (casefold_location);
+ g_free (casefold_name);
+ g_free (casefold_key);
+ }
+
+ return !matches;
+}
+
static void
update_collate_icon (GtkToggleButton *toggle_button,
GtkPrintUnixDialog *dialog)
diff --git a/gtk/gtkprintunixdialog.ui b/gtk/gtkprintunixdialog.ui
index c6df82f..5093d2b 100644
--- a/gtk/gtkprintunixdialog.ui
+++ b/gtk/gtkprintunixdialog.ui
@@ -149,7 +149,6 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">printer_list_filter</property>
- <property name="search_column">1</property>
<signal name="row-activated" handler="emit_ok_response" swapped="no"/>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]