diff --git a/sflphone-client-gnome/src/contacts/history.c b/sflphone-client-gnome/src/contacts/history.c index ea807892450ca1f849fef11d4d4132cb79d3fdbf..37e1ca62fcfba0295e63c07eb17e3f3aab72a54a 100644 --- a/sflphone-client-gnome/src/contacts/history.c +++ b/sflphone-client-gnome/src/contacts/history.c @@ -28,7 +28,7 @@ GtkWidget * history_searchbar_widget; static GtkTreeModel* history_create_filter (GtkTreeModel*); static gboolean history_is_visible (GtkTreeModel*, GtkTreeIter*, gpointer); -void history_search (GtkEntry* entry UNUSED) +void history_search (SearchType search_type) { if(history_filter != NULL) { 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 { if (SHOW_SEARCHBAR) { - GValue val; + GValue val, obj; + callable_obj_t *history_entry = NULL; gchar* text = NULL; gchar* search = (gchar*)gtk_entry_get_text(GTK_ENTRY(history_searchbar_widget)); 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); if(G_VALUE_HOLDS_STRING(&val)){ text = (gchar *)g_value_get_string(&val); } - if(text != NULL ){ - return g_regex_match_simple(search, text, G_REGEX_CASELESS, 0); + + // 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); + 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 (&obj); + return TRUE; } return TRUE; diff --git a/sflphone-client-gnome/src/contacts/history.h b/sflphone-client-gnome/src/contacts/history.h index e4265a3690b7183a656ae16ac4fb8d58ca2837a9..a05cf9fff8017943ec812dd32450a1fde41f5e93 100644 --- a/sflphone-client-gnome/src/contacts/history.h +++ b/sflphone-client-gnome/src/contacts/history.h @@ -27,11 +27,17 @@ #include <gtk/gtk.h> #include <sflphone_const.h> +typedef enum { + SEARCH_ALL, + SEARCH_MISSED, + SEARCH_INCOMING, + SEARCH_OUTGOING +} SearchType; + /** * Execute a search in history */ -void -history_search(GtkEntry* entry UNUSED); +void history_search (SearchType search_type); /** * Initialize history diff --git a/sflphone-client-gnome/src/contacts/searchbar.c b/sflphone-client-gnome/src/contacts/searchbar.c index f6e60fa77444b298c77a28ade5964cb3ee78d5a4..0cdf4d5a08e58771c52106c2c7089962e4d7de02 100644 --- a/sflphone-client-gnome/src/contacts/searchbar.c +++ b/sflphone-client-gnome/src/contacts/searchbar.c @@ -28,6 +28,7 @@ const GdkColor GRAY_COLOR = { 0, 30000, 30000, 30000 }; GtkWidget * searchbox; + static GtkWidget *menu = NULL; 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 addressbook_search (entry); } else if (active_calltree == history) { - history_search (entry); + history_search (HistorySearchType); } } 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_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY, "Search all\n" @@ -50,6 +53,8 @@ static void search_all (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); gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, pixbuf); gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY, @@ -59,6 +64,8 @@ static void search_by_missed (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); gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, pixbuf); gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY, @@ -68,6 +75,8 @@ static void search_by_incoming (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); gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, pixbuf); gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY, @@ -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) { - 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, event->button, event->time); else 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 @@ -102,7 +114,7 @@ focus_on_searchbar_in(){ // gtk_widget_grab_focus(GTK_WIDGET(sw)); focus_is_on_searchbar = TRUE; } - + void searchbar_init(calltab_t *tab) { if (g_strcasecmp (tab->_name, CONTACTS) == 0) @@ -128,7 +140,12 @@ GtkWidget* history_searchbar_new (void) searchbox = gtk_entry_new(); 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, "notify::text", G_CALLBACK (text_changed_cb), NULL); //g_signal_connect (searchbox, "activate", G_CALLBACK (activate_cb), NULL); // Set up the search icon @@ -173,7 +190,7 @@ GtkWidget* history_searchbar_new (void) sexy_icon_entry_set_icon( SEXY_ICON_ENTRY(searchbox), SEXY_ICON_ENTRY_PRIMARY , GTK_IMAGE(image) ); sexy_icon_entry_add_clear_button( SEXY_ICON_ENTRY(searchbox) ); #endif - + 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_CALLBACK (focus_on_searchbar_in), NULL); @@ -193,10 +210,22 @@ GtkWidget* contacts_searchbar_new () { ret = gtk_hbox_new(FALSE, 0); #if GTK_CHECK_VERSION(2,16,0) + + GdkPixbuf *pixbuf; 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_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); #else @@ -209,8 +238,6 @@ GtkWidget* contacts_searchbar_new () { sexy_icon_entry_add_clear_button( SEXY_ICON_ENTRY(searchbox) ); #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 (G_OBJECT (searchbox), "focus-in-event", @@ -220,8 +247,6 @@ GtkWidget* contacts_searchbar_new () { gtk_box_pack_start(GTK_BOX(ret), searchbox, TRUE, TRUE, 0); - //history_set_searchbar_widget(searchbox); - return ret; } @@ -232,3 +257,8 @@ void activateWaitingLayer() { void deactivateWaitingLayer() { gtk_widget_hide(waitingLayer); } + +SearchType get_current_history_search_type (void) +{ + return HistorySearchType; +} diff --git a/sflphone-client-gnome/src/contacts/searchbar.h b/sflphone-client-gnome/src/contacts/searchbar.h index 0b16b3dcc1bfe48e5c09d7c040f3243706a3a96b..8354dac96a1905b19667191181dbe9e83ff0623d 100644 --- a/sflphone-client-gnome/src/contacts/searchbar.h +++ b/sflphone-client-gnome/src/contacts/searchbar.h @@ -43,6 +43,8 @@ GdkPixbuf *waitingPixOff; +SearchType HistorySearchType; + /** * Create a new search bar with "type" passed in * parameter @@ -50,6 +52,9 @@ GdkPixbuf *waitingPixOff; GtkWidget* history_searchbar_new (void); GtkWidget* contacts_searchbar_new (void); +SearchType get_current_history_search_type (void); + + /** * Initialize a specific search bar */