/*
* This file is a part of hildon
*
* Copyright (C) 2007-2009 Nokia Corporation.
*
* Based in OssoABookLiveSearch, OSSO Address Book.
* Author: Joergen Scheibengruber <jorgen.scheibengruber@nokia.com>
* Hildon version: Claudio Saavedra <csaavedra@igalia.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser Public License as published by
* the Free Software Foundation; version 2 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser Public License for more details.
*
*/
/**
* SECTION:hildon-live-search
* @short_description: A widget for manipulating #GtkTreeModelFilter
* instances.
*
* This widget provides a user interface for manipulating
* #GtkTreeModelFilter instances.
*
* To set a #GtkTreeFilterModel to filter with, use
* hildon_live_search_set_filter(). By default, #HildonLiveSearch
* filters on the child model of the filter model set using a case
* sensitive prefix comparison on the model's column specified by
* #HildonLiveSearch:text-column. If a more refined filtering is
* necessary, you can use hildon_live_search_set_visible_func() to
* specify a #HildonLiveSearchVisibleFunc to use.
*
*/
#include "hildon-live-search.h"
#include <hildon/hildon.h>
#include <string.h>
G_DEFINE_TYPE (HildonLiveSearch, hildon_live_search, GTK_TYPE_TOOLBAR);
#define GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), \
HILDON_TYPE_LIVE_SEARCH, \
HildonLiveSearchPrivate))
struct _HildonLiveSearchPrivate
{
GtkTreeModelFilter *filter;
GtkWidget *kb_focus_widget;
GtkWidget *entry;
GtkWidget *event_widget;
GHashTable *selection_map;
gulong key_press_id;
gulong event_widget_destroy_id;
gulong kb_focus_widget_destroy_id;
gulong idle_filter_id;
gchar *prefix;
gint text_column;
HildonLiveSearchVisibleFunc visible_func;
gpointer visible_data;
GDestroyNotify visible_destroy;
gboolean visible_func_set;
gboolean run_async;
};
enum
{
PROP_0,
PROP_FILTER,
PROP_WIDGET,
PROP_TEXT_COLUMN,
PROP_TEXT
};
enum
{
REFILTER,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static gboolean
visible_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data);
/* Private implementation */
static guint
hash_func (gconstpointer key)
{
GtkTreePath *path;
gchar *path_str;
guint val;
path = gtk_tree_row_reference_get_path ((GtkTreeRowReference *) key);
path_str = gtk_tree_path_to_string (path);
val = g_str_hash (path_str);
g_free (path_str);
gtk_tree_path_free (path);
return val;
}
static gboolean
key_equal_func (gconstpointer v1,
gconstpointer v2)
{
gboolean ret;
GtkTreePath *path1;
GtkTreePath *path2;
path1 = gtk_tree_row_reference_get_path ((GtkTreeRowReference *) v1);
path2 = gtk_tree_row_reference_get_path ((GtkTreeRowReference *) v2);
ret = gtk_tree_path_compare (path1, path2) == 0;
gtk_tree_path_free (path1);
gtk_tree_path_free (path2);
return ret;
}
/**
* selection_map_create:
* @priv: The private pimpl
*
* Adds a selection map which is useful when merging selected rows in
* a treeview, when the live search widget is used.
**/
static void
selection_map_create (HildonLiveSearchPrivate *priv)
{
if (!GTK_IS_TREE_VIEW (priv->kb_focus_widget))
return;
g_assert (priv->selection_map == NULL);
priv->selection_map = g_hash_table_new_full
(hash_func, key_equal_func,
(GDestroyNotify) gtk_tree_row_reference_free, NULL);
}
/**
* selection_map_destroy:
* @priv: The private pimpl
*
* Destroys resources associated with the selection map.
**/