diff --git a/sflphone-gtk/src/Makefile.am b/sflphone-gtk/src/Makefile.am index 0fa08ce0dfbde977e3576ce6bc4f378d206bf676..0eb7fc44a17b213927cff3eefcccd0f41dc8dd57 100644 --- a/sflphone-gtk/src/Makefile.am +++ b/sflphone-gtk/src/Makefile.am @@ -12,6 +12,7 @@ sflphone_gtk_SOURCES = \ menus.c \ calltab.c \ calltree.c \ + historyfilter.c \ actions.c \ configwindow.c \ accountlist.c \ @@ -25,7 +26,7 @@ sflphone_gtk_SOURCES = \ noinst_HEADERS = actions.h dbus.h sflnotify.h mainwindow.h calllist.h dialpad.h codeclist.h assistant.h\ callmanager-glue.h errors.h sflphone_const.h configurationmanager-glue.h instance-glue.h menus.h calltab.h calltree.h configwindow.h \ - accountlist.h accountwindow.h marshaller.h sliders.h statusicon.h timestamp.h + historyfilter.h accountlist.h accountwindow.h marshaller.h sliders.h statusicon.h timestamp.h EXTRA_DIST = marshaller.list sflphone_gtk_LDADD = $(DEPS_LIBS) -lnotify diff --git a/sflphone-gtk/src/actions.c b/sflphone-gtk/src/actions.c index d01744c1edee66e5859ca7da0e7a41d2cc35ee39..af871771972ea424cb4643a4faa3242559a95ceb 100644 --- a/sflphone-gtk/src/actions.c +++ b/sflphone-gtk/src/actions.c @@ -25,6 +25,7 @@ #include <menus.h> #include <statusicon.h> #include <calltab.h> +#include <historyfilter.h> #include <gtk/gtk.h> #include <string.h> @@ -194,6 +195,7 @@ sflphone_init() int i; current_calls = calltab_init(); history = calltab_init(); + histfilter = create_filter(GTK_TREE_MODEL(history->store)); account_list_init (); codec_list_init(); if(!dbus_connect ()){ diff --git a/sflphone-gtk/src/calltab.h b/sflphone-gtk/src/calltab.h index cbeab8f43466e92d6d1726a2dff1993fa1fad03d..dcc47b2605551556b6085ca6b67fab3021697d65 100644 --- a/sflphone-gtk/src/calltab.h +++ b/sflphone-gtk/src/calltab.h @@ -23,6 +23,7 @@ #include <calllist.h> #include <gtk/gtk.h> +GtkTreeModel* histfilter; calltab_t* calltab_init(); diff --git a/sflphone-gtk/src/calltree.c b/sflphone-gtk/src/calltree.c index e99b5b194a3b1fdcf16e66ce893233eb19f9d5ef..c6eff868684cfb2a9cf579ccaf92c597aaf00088 100644 --- a/sflphone-gtk/src/calltree.c +++ b/sflphone-gtk/src/calltree.c @@ -137,21 +137,22 @@ unhold( GtkWidget *widget, gpointer data ) toggle_history(GtkToggleToolButton *toggle_tool_button, gpointer user_data) { - GtkTreeSelection *sel; - if(history_shown){ - active_calltree = current_calls; - gtk_widget_hide(history->tree); - gtk_widget_show(current_calls->tree); - history_shown = FALSE; - }else{ - active_calltree = history; - gtk_widget_hide(current_calls->tree); - gtk_widget_show(history->tree); - history_shown = TRUE; - } - sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (active_calltree->view)); - g_signal_emit_by_name(sel, "changed"); - toolbar_update_buttons(); + GtkTreeSelection *sel; + if(history_shown){ + active_calltree = current_calls; + gtk_widget_hide(history->tree); + gtk_widget_show(current_calls->tree); + history_shown = FALSE; + }else{ + active_calltree = history; + gtk_widget_hide(current_calls->tree); + gtk_widget_show(history->tree); + history_shown = TRUE; + } + sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (active_calltree->view)); + g_signal_emit_by_name(sel, "changed"); + toolbar_update_buttons(); + gtk_tree_model_filter_refilter(histfilter); } diff --git a/sflphone-gtk/src/calltree.h b/sflphone-gtk/src/calltree.h index fe7fc19635b4f753603b50c27cb79244ef67b122..84c5736e23240b3494584a3a83b0c908d3791017 100644 --- a/sflphone-gtk/src/calltree.h +++ b/sflphone-gtk/src/calltree.h @@ -31,6 +31,8 @@ * @brief The GtkTreeView that list calls in the main window. */ +GtkToolItem * historyButton; + calltab_t* active_calltree; /** * Create a new widget calltree diff --git a/sflphone-gtk/src/historyfilter.c b/sflphone-gtk/src/historyfilter.c new file mode 100644 index 0000000000000000000000000000000000000000..e058c5d660a1c3a7a6be1c47aa0f0bb8917e4d2d --- /dev/null +++ b/sflphone-gtk/src/historyfilter.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2007 Savoir-Faire Linux inc. + * Author: Antoine Reversat <antoine.reversat@savoirfairelinux.com> + * + * 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. + * + * 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. + * + * 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. + */ + +#include <gtk/gtk.h> +#include <historyfilter.h> +#include <calltree.h> + +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); +} + +gboolean +is_visible(GtkTreeModel* model, GtkTreeIter* iter, gpointer data) +{ + GValue val = {0, }; + gchar* text; + gchar* search = gtk_entry_get_text(GTK_ENTRY(filter_entry)); + 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 && g_ascii_strncasecmp(search, "Search", 6) != 0){ + return g_regex_match_simple(search, text, G_REGEX_CASELESS, 0); + } + return TRUE; +} + +void +filter_entry_changed(GtkEntry* entry, gchar* arg1, gpointer data) +{ + gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(historyButton), TRUE); + gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(histfilter)); +} + +void +clear_filter_entry_if_default(GtkWidget* widget, gpointer user_data) +{ + if(g_ascii_strncasecmp(gtk_entry_get_text(GTK_ENTRY(filter_entry)), "Search", 6) == 0) + gtk_entry_set_text(GTK_ENTRY(filter_entry), ""); + +} + +void +clear_filter_entry(GtkButton* button, + gpointer user_data) +{ + gtk_entry_set_text(GTK_ENTRY(filter_entry), ""); +} + +GtkWidget* +create_filter_entry() +{ + GtkWidget* clear_button = gtk_button_new(); + GtkWidget* ret = gtk_hbox_new(FALSE, 0); + GtkWidget* clear_img = gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_SMALL_TOOLBAR); + + gtk_button_set_image(GTK_BUTTON(clear_button), clear_img); + g_signal_connect(GTK_BUTTON(clear_button), "clicked", G_CALLBACK(clear_filter_entry), NULL); + + filter_entry = gtk_entry_new(); + gtk_entry_set_text(GTK_ENTRY(filter_entry), "Search"); + 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); + gtk_box_pack_start(GTK_BOX(ret), clear_button, FALSE, FALSE, 0); + return ret; +} diff --git a/sflphone-gtk/src/historyfilter.h b/sflphone-gtk/src/historyfilter.h new file mode 100644 index 0000000000000000000000000000000000000000..744cdd2ba566c5fffbb1a1ef38796b6e750c3735 --- /dev/null +++ b/sflphone-gtk/src/historyfilter.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2007 Savoir-Faire Linux inc. + * Author: Antoine Reversat <antoine.reversat@savoirfairelinux.com> + * + * 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. + * + * 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. + * + * 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. + */ + +#ifndef __HFILTER_H__ +#define __HFILTER_H__ + +#include <calllist.h> +#include <gtk/gtk.h> + + + +GtkWidget * filter_entry; + +GtkTreeModel* create_filter(GtkTreeModel* child); + +gboolean is_visible(GtkTreeModel* model, GtkTreeIter* iter, gpointer data); +GtkWidget* create_filter_entry(); +#endif diff --git a/sflphone-gtk/src/mainwindow.c b/sflphone-gtk/src/mainwindow.c index 64806d876baa28c9d40c33ea822c1daf719a0b21..a7e9cd9ecf2c70a808b3b5e879af437f3755fbf1 100644 --- a/sflphone-gtk/src/mainwindow.c +++ b/sflphone-gtk/src/mainwindow.c @@ -27,6 +27,7 @@ #include <mainwindow.h> #include <menus.h> #include <sliders.h> +#include <historyfilter.h> #include <gtk/gtk.h> @@ -131,8 +132,8 @@ create_main_window () */ g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (on_delete), NULL); - g_signal_connect (G_OBJECT (window), "key-press-event", - G_CALLBACK (on_key_released), NULL); + //g_signal_connect (G_OBJECT (window), "key-press-event", + // G_CALLBACK (on_key_released), NULL); /* Create an accel group for window's shortcuts */ accelGroup = gtk_accel_group_new (); @@ -146,7 +147,9 @@ create_main_window () gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); widget = create_toolbar(); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); + gtk_box_pack_start (GTK_BOX (vbox), create_filter_entry(), FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/); gtk_box_pack_start (GTK_BOX (vbox), current_calls->tree, TRUE /*expand*/, TRUE /*fill*/, 0 /*padding*/); gtk_box_pack_start (GTK_BOX (vbox), history->tree, TRUE /*expand*/, TRUE /*fill*/, 0 /*padding*/); @@ -179,6 +182,7 @@ create_main_window () gtk_widget_hide(history->tree); //gtk_widget_show(current_calls->tree); + gtk_tree_view_set_model(GTK_TREE_VIEW(history->view), GTK_TREE_MODEL(histfilter)); // Configuration wizard if (account_list_get_size() == 0) {