historyfilter.c 2.94 KB
Newer Older
1
/*
Emmanuel Milou's avatar
Emmanuel Milou committed
2
 *  Copyright (C) 2008 Savoir-Faire Linux inc.
3
 *  Author: Antoine Reversat <antoine.reversat@savoirfairelinux.com>
4
 *
5 6 7 8
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
9
 *
10 11 12 13
 *  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 General Public License for more details.
14
 *
15 16 17 18 19
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

20 21
#include <string.h>

22
#include <historyfilter.h>
areversat's avatar
areversat committed
23
#include <calltree.h>
24 25 26 27 28 29 30

GtkTreeModel*
create_filter(GtkTreeModel* child)
{
	GtkTreeModel* ret = gtk_tree_model_filter_new(child, NULL);
	gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(ret), is_visible, NULL, NULL);
	return GTK_TREE_MODEL(ret);
31
}
32 33

gboolean
34
is_visible(GtkTreeModel* model, GtkTreeIter* iter, gpointer data UNUSED)
35
{
Emmanuel Milou's avatar
Emmanuel Milou committed
36 37
  if( SHOW_SEARCHBAR )
  {
38 39
	GValue val;

40
	gchar* text = NULL;
41
	gchar* search = (gchar*)gtk_entry_get_text(GTK_ENTRY(filter_entry));
42
    memset (&val, 0, sizeof(val));
43 44 45
	gtk_tree_model_get_value(GTK_TREE_MODEL(model), iter, 1, &val);
	if(G_VALUE_HOLDS_STRING(&val)){
		text = (gchar *)g_value_get_string(&val);
areversat's avatar
areversat committed
46
 	}
Emmanuel Milou's avatar
Emmanuel Milou committed
47
	if(text != NULL && g_ascii_strncasecmp(search, _("Search"), 6) != 0){
areversat's avatar
areversat committed
48 49
		return g_regex_match_simple(search, text, G_REGEX_CASELESS, 0);
 	}
50
    g_value_unset (&val);
areversat's avatar
areversat committed
51
	return TRUE;
Emmanuel Milou's avatar
Emmanuel Milou committed
52 53
  }
  return TRUE;
54
}
areversat's avatar
areversat committed
55 56

void
57
filter_entry_changed(GtkEntry* entry UNUSED, gchar* arg1 UNUSED, gpointer data UNUSED)
58
{
Julien Bonjean's avatar
Julien Bonjean committed
59 60 61 62 63 64 65
  //printf("%s\n",gtk_entry_get_text(GTK_ENTRY(entry)));

  if(active_calltree == current_calls)
    switch_tab(contacts);
  else
    refresh_tab(active_calltree);

areversat's avatar
areversat committed
66 67 68
}

void
69
clear_filter_entry_if_default(GtkWidget* widget UNUSED, gpointer user_data UNUSED)
areversat's avatar
areversat committed
70
{
Emmanuel Milou's avatar
Emmanuel Milou committed
71
	if(g_ascii_strncasecmp(gtk_entry_get_text(GTK_ENTRY(filter_entry)), _("Search"), 6) == 0)
areversat's avatar
areversat committed
72 73 74 75
		gtk_entry_set_text(GTK_ENTRY(filter_entry), "");
}

GtkWidget*
76
create_filter_entry()
areversat's avatar
areversat committed
77
{
78
	GtkWidget* image;
areversat's avatar
areversat committed
79
	GtkWidget* ret = gtk_hbox_new(FALSE, 0);
80

81
	filter_entry = sexy_icon_entry_new();
82
	//filter_entry = gtk_entry_new();
83
	image = gtk_image_new_from_stock( GTK_STOCK_FIND , GTK_ICON_SIZE_SMALL_TOOLBAR);
84
	sexy_icon_entry_set_icon( SEXY_ICON_ENTRY(filter_entry), SEXY_ICON_ENTRY_PRIMARY , GTK_IMAGE(image) );
85
	sexy_icon_entry_add_clear_button( SEXY_ICON_ENTRY(filter_entry) );
86
	gtk_entry_set_text(GTK_ENTRY(filter_entry), _("Search"));
areversat's avatar
areversat committed
87 88 89 90 91
	g_signal_connect(GTK_ENTRY(filter_entry), "changed", G_CALLBACK(filter_entry_changed), NULL);
	g_signal_connect(GTK_ENTRY(filter_entry), "grab-focus", G_CALLBACK(clear_filter_entry_if_default), NULL);

	gtk_box_pack_start(GTK_BOX(ret), filter_entry, TRUE, TRUE, 0);
	return ret;
92
}