Skip to content
Snippets Groups Projects
Commit 7b17b1bd authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

[#961] Enable to search in the history according to the call type

parent d61d0c0f
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ GtkWidget * history_searchbar_widget; ...@@ -28,7 +28,7 @@ GtkWidget * history_searchbar_widget;
static GtkTreeModel* history_create_filter (GtkTreeModel*); static GtkTreeModel* history_create_filter (GtkTreeModel*);
static gboolean history_is_visible (GtkTreeModel*, GtkTreeIter*, gpointer); static gboolean history_is_visible (GtkTreeModel*, GtkTreeIter*, gpointer);
void history_search (GtkEntry* entry UNUSED) void history_search (SearchType search_type)
{ {
if(history_filter != NULL) { if(history_filter != NULL) {
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (history_filter)); gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (history_filter));
...@@ -60,20 +60,47 @@ static gboolean history_is_visible (GtkTreeModel* model, GtkTreeIter* iter, gpoi ...@@ -60,20 +60,47 @@ static gboolean history_is_visible (GtkTreeModel* model, GtkTreeIter* iter, gpoi
{ {
if (SHOW_SEARCHBAR) if (SHOW_SEARCHBAR)
{ {
GValue val; GValue val, obj;
callable_obj_t *history_entry = NULL;
gchar* text = NULL; gchar* text = NULL;
gchar* search = (gchar*)gtk_entry_get_text(GTK_ENTRY(history_searchbar_widget)); gchar* search = (gchar*)gtk_entry_get_text(GTK_ENTRY(history_searchbar_widget));
memset (&val, 0, sizeof(val)); memset (&val, 0, sizeof(val));
memset (&obj, 0, sizeof(obj));
// Fetch the call description
gtk_tree_model_get_value (GTK_TREE_MODEL(model), iter, 1, &val); gtk_tree_model_get_value (GTK_TREE_MODEL(model), iter, 1, &val);
if(G_VALUE_HOLDS_STRING(&val)){ if(G_VALUE_HOLDS_STRING(&val)){
text = (gchar *)g_value_get_string(&val); text = (gchar *)g_value_get_string(&val);
} }
if(text != NULL ){
// Fetch the call type
gtk_tree_model_get_value (GTK_TREE_MODEL(model), iter, 2, &obj);
if (G_VALUE_HOLDS_POINTER (&obj)){
history_entry = (gpointer) g_value_get_pointer (&obj);
}
if(text != NULL)
{
if (history_entry)
{
// Filter according to the type of call
// MISSED, INCOMING, OUTGOING, ALL
if ((int)get_current_history_search_type () == SEARCH_ALL)
return g_regex_match_simple(search, text, G_REGEX_CASELESS, 0); return g_regex_match_simple(search, text, G_REGEX_CASELESS, 0);
else
{
// We need a match on the history_state_t and the current search type
if ( (history_entry->_history_state + 1) == (int)get_current_history_search_type ())
return g_regex_match_simple(search, text, G_REGEX_CASELESS, 0);
}
}
} }
// Clean up
g_value_unset (&val); g_value_unset (&val);
g_value_unset (&obj);
return TRUE; return TRUE;
} }
return TRUE; return TRUE;
......
...@@ -27,11 +27,17 @@ ...@@ -27,11 +27,17 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <sflphone_const.h> #include <sflphone_const.h>
typedef enum {
SEARCH_ALL,
SEARCH_MISSED,
SEARCH_INCOMING,
SEARCH_OUTGOING
} SearchType;
/** /**
* Execute a search in history * Execute a search in history
*/ */
void void history_search (SearchType search_type);
history_search(GtkEntry* entry UNUSED);
/** /**
* Initialize history * Initialize history
......
...@@ -28,6 +28,7 @@ const GdkColor GRAY_COLOR = { 0, 30000, 30000, 30000 }; ...@@ -28,6 +28,7 @@ const GdkColor GRAY_COLOR = { 0, 30000, 30000, 30000 };
GtkWidget * searchbox; GtkWidget * searchbox;
static GtkWidget *menu = NULL; static GtkWidget *menu = NULL;
void searchbar_entry_changed (GtkEntry* entry, gchar* arg1 UNUSED, gpointer data UNUSED) void searchbar_entry_changed (GtkEntry* entry, gchar* arg1 UNUSED, gpointer data UNUSED)
...@@ -36,12 +37,14 @@ void searchbar_entry_changed (GtkEntry* entry, gchar* arg1 UNUSED, gpointer data ...@@ -36,12 +37,14 @@ void searchbar_entry_changed (GtkEntry* entry, gchar* arg1 UNUSED, gpointer data
addressbook_search (entry); addressbook_search (entry);
} }
else if (active_calltree == history) { else if (active_calltree == history) {
history_search (entry); history_search (HistorySearchType);
} }
} }
static void search_all (GtkWidget *item, GtkEntry *entry) static void search_all (GtkWidget *item, GtkEntry *entry)
{ {
HistorySearchType = SEARCH_ALL;
gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_FIND); gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_FIND);
gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY, gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY,
"Search all\n" "Search all\n"
...@@ -50,6 +53,8 @@ static void search_all (GtkWidget *item, GtkEntry *entry) ...@@ -50,6 +53,8 @@ static void search_all (GtkWidget *item, GtkEntry *entry)
static void search_by_missed (GtkWidget *item, GtkEntry *entry) static void search_by_missed (GtkWidget *item, GtkEntry *entry)
{ {
HistorySearchType = SEARCH_MISSED;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/missed.svg", NULL); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/missed.svg", NULL);
gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, pixbuf); gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, pixbuf);
gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY, gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY,
...@@ -59,6 +64,8 @@ static void search_by_missed (GtkWidget *item, GtkEntry *entry) ...@@ -59,6 +64,8 @@ static void search_by_missed (GtkWidget *item, GtkEntry *entry)
static void search_by_incoming (GtkWidget *item, GtkEntry *entry) static void search_by_incoming (GtkWidget *item, GtkEntry *entry)
{ {
HistorySearchType = SEARCH_INCOMING;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/incoming.svg", NULL); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/incoming.svg", NULL);
gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, pixbuf); gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, pixbuf);
gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY, gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY,
...@@ -68,6 +75,8 @@ static void search_by_incoming (GtkWidget *item, GtkEntry *entry) ...@@ -68,6 +75,8 @@ static void search_by_incoming (GtkWidget *item, GtkEntry *entry)
static void search_by_outgoing (GtkWidget *item, GtkEntry *entry) static void search_by_outgoing (GtkWidget *item, GtkEntry *entry)
{ {
HistorySearchType = SEARCH_OUTGOING;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/outgoing.svg", NULL); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/outgoing.svg", NULL);
gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, pixbuf); gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, pixbuf);
gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY, gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY,
...@@ -77,16 +86,19 @@ static void search_by_outgoing (GtkWidget *item, GtkEntry *entry) ...@@ -77,16 +86,19 @@ static void search_by_outgoing (GtkWidget *item, GtkEntry *entry)
static void icon_press_cb (GtkEntry *entry, gint position, GdkEventButton *event, gpointer data) static void icon_press_cb (GtkEntry *entry, gint position, GdkEventButton *event, gpointer data)
{ {
if (position == GTK_ENTRY_ICON_PRIMARY) if (position == GTK_ENTRY_ICON_PRIMARY && active_calltree == history)
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
event->button, event->time); event->button, event->time);
else else
gtk_entry_set_text (entry, ""); gtk_entry_set_text (entry, "");
} }
static void activate_cb (GtkEntry *entry, GtkButton *button) static void text_changed_cb (GtkEntry *entry, GParamSpec *pspec)
{ {
history_search (entry); gboolean has_text;
has_text = gtk_entry_get_text_length (entry) > 0;
gtk_entry_set_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY, has_text);
} }
void void
...@@ -128,7 +140,12 @@ GtkWidget* history_searchbar_new (void) ...@@ -128,7 +140,12 @@ GtkWidget* history_searchbar_new (void)
searchbox = gtk_entry_new(); searchbox = gtk_entry_new();
gtk_entry_set_icon_from_stock (GTK_ENTRY (searchbox), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR); gtk_entry_set_icon_from_stock (GTK_ENTRY (searchbox), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
// Set the clean insensitive
text_changed_cb (GTK_ENTRY (searchbox), NULL);
g_signal_connect (searchbox, "icon-press", G_CALLBACK (icon_press_cb), NULL); g_signal_connect (searchbox, "icon-press", G_CALLBACK (icon_press_cb), NULL);
g_signal_connect (searchbox, "notify::text", G_CALLBACK (text_changed_cb), NULL);
//g_signal_connect (searchbox, "activate", G_CALLBACK (activate_cb), NULL); //g_signal_connect (searchbox, "activate", G_CALLBACK (activate_cb), NULL);
// Set up the search icon // Set up the search icon
...@@ -194,9 +211,21 @@ GtkWidget* contacts_searchbar_new () { ...@@ -194,9 +211,21 @@ GtkWidget* contacts_searchbar_new () {
#if GTK_CHECK_VERSION(2,16,0) #if GTK_CHECK_VERSION(2,16,0)
GdkPixbuf *pixbuf;
searchbox = gtk_entry_new(); searchbox = gtk_entry_new();
gtk_entry_set_icon_from_stock (GTK_ENTRY (searchbox), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR); gtk_entry_set_icon_from_stock (GTK_ENTRY (searchbox), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
gtk_entry_set_icon_from_stock (GTK_ENTRY (searchbox), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_FIND); pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/stock_person.svg", NULL);
gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (searchbox), GTK_ENTRY_ICON_PRIMARY, pixbuf);
gtk_entry_set_icon_tooltip_text (GTK_ENTRY (searchbox), GTK_ENTRY_ICON_PRIMARY,
"Search contacts\n"
"GNOME evolution backend");
// Set the clean insensitive
text_changed_cb (GTK_ENTRY (searchbox), NULL);
g_signal_connect (searchbox, "notify::text", G_CALLBACK (text_changed_cb), NULL);
g_signal_connect (searchbox, "icon-press", G_CALLBACK (icon_press_cb), NULL); g_signal_connect (searchbox, "icon-press", G_CALLBACK (icon_press_cb), NULL);
#else #else
...@@ -209,8 +238,6 @@ GtkWidget* contacts_searchbar_new () { ...@@ -209,8 +238,6 @@ GtkWidget* contacts_searchbar_new () {
sexy_icon_entry_add_clear_button( SEXY_ICON_ENTRY(searchbox) ); sexy_icon_entry_add_clear_button( SEXY_ICON_ENTRY(searchbox) );
#endif #endif
gtk_widget_modify_text(searchbox, GTK_STATE_NORMAL, &GRAY_COLOR);
g_signal_connect_after(GTK_ENTRY(searchbox), "changed", G_CALLBACK(searchbar_entry_changed), NULL); g_signal_connect_after(GTK_ENTRY(searchbox), "changed", G_CALLBACK(searchbar_entry_changed), NULL);
g_signal_connect_after (G_OBJECT (searchbox), "focus-in-event", g_signal_connect_after (G_OBJECT (searchbox), "focus-in-event",
...@@ -220,8 +247,6 @@ GtkWidget* contacts_searchbar_new () { ...@@ -220,8 +247,6 @@ GtkWidget* contacts_searchbar_new () {
gtk_box_pack_start(GTK_BOX(ret), searchbox, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(ret), searchbox, TRUE, TRUE, 0);
//history_set_searchbar_widget(searchbox);
return ret; return ret;
} }
...@@ -232,3 +257,8 @@ void activateWaitingLayer() { ...@@ -232,3 +257,8 @@ void activateWaitingLayer() {
void deactivateWaitingLayer() { void deactivateWaitingLayer() {
gtk_widget_hide(waitingLayer); gtk_widget_hide(waitingLayer);
} }
SearchType get_current_history_search_type (void)
{
return HistorySearchType;
}
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
GdkPixbuf *waitingPixOff; GdkPixbuf *waitingPixOff;
SearchType HistorySearchType;
/** /**
* Create a new search bar with "type" passed in * Create a new search bar with "type" passed in
* parameter * parameter
...@@ -50,6 +52,9 @@ GdkPixbuf *waitingPixOff; ...@@ -50,6 +52,9 @@ GdkPixbuf *waitingPixOff;
GtkWidget* history_searchbar_new (void); GtkWidget* history_searchbar_new (void);
GtkWidget* contacts_searchbar_new (void); GtkWidget* contacts_searchbar_new (void);
SearchType get_current_history_search_type (void);
/** /**
* Initialize a specific search bar * Initialize a specific search bar
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment