summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorMarek Kasik <mkasik@redhat.com>2013-12-19 14:52:16 +0100
committerMarek Kasik <mkasik@redhat.com>2014-01-27 16:40:43 +0100
commit8418e6422f0ec67c51d472321f4704a3a16e0368 (patch)
treefb8fff17ac732bc7b7bb3059a5480dd9d5c9eb06 /gtk
parente1b874b44f632b528cbdf9479e80ea419a4fbfaa (diff)
downloadgtk+-8418e6422f0ec67c51d472321f4704a3a16e0368.tar.gz
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
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkprintunixdialog.c87
-rw-r--r--gtk/resources/ui/gtkprintunixdialog.ui1
2 files changed, 87 insertions, 1 deletions
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index b83b10034a..0d2569bc03 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -212,6 +212,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);
@@ -758,6 +763,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);
@@ -2106,6 +2114,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/resources/ui/gtkprintunixdialog.ui b/gtk/resources/ui/gtkprintunixdialog.ui
index 3d2aec7d39..cf8cbf74c7 100644
--- a/gtk/resources/ui/gtkprintunixdialog.ui
+++ b/gtk/resources/ui/gtkprintunixdialog.ui
@@ -93,7 +93,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">