Commit d61d0c0f authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

[#961] Add popup menu on the entry primary icon for history

parent 850354ed
......@@ -236,9 +236,9 @@ gboolean sflphone_init()
{
dbus_register(getpid(), "Gtk+ Client");
current_calls = calltab_init(NULL);
contacts = calltab_init("contacts");
history = calltab_init("history");
current_calls = calltab_init(FALSE, CURRENT_CALLS);
contacts = calltab_init(TRUE, CONTACTS);
history = calltab_init(TRUE, HISTORY);
account_list_init ();
codec_list_init();
......
......@@ -36,6 +36,7 @@ typedef struct {
// Calllist vars
GQueue* callQueue;
callable_obj_t* selectedCall;
gchar *_name;
} calltab_t;
void
......
......@@ -23,8 +23,7 @@
#include <calltree.h>
#include <contacts/searchbar.h>
calltab_t*
calltab_init(gchar* searchbar_type)
calltab_t* calltab_init (gboolean searchbar_type, gchar *name)
{
calltab_t* ret;
......@@ -33,11 +32,12 @@ calltab_init(gchar* searchbar_type)
ret->store = NULL;
ret->view = NULL;
ret->tree = NULL;
ret->searchbar = NULL;
ret->searchbar = NULL;
ret->callQueue = NULL;
ret->selectedCall = NULL;
ret->_name = g_strdup (name);
calltree_create(ret, searchbar_type);
calltree_create (ret, searchbar_type);
calllist_init(ret);
......@@ -58,7 +58,12 @@ calltab_get_selected_call (calltab_t* tab)
}
void
calltab_create_searchbar(calltab_t* tab, gchar* searchbar_type)
calltab_create_searchbar (calltab_t* tab)
{
tab->searchbar = searchbar_new(searchbar_type);
if (g_strcasecmp (tab->_name, HISTORY) == 0)
tab->searchbar = history_searchbar_new ();
else if (g_strcasecmp (tab->_name, CONTACTS) == 0)
tab->searchbar = contacts_searchbar_new ();
else
ERROR ("Current calls tab does not need a searchbar\n");
}
......@@ -28,7 +28,7 @@ calltab_t* current_calls;
calltab_t* history;
calltab_t* contacts;
calltab_t* calltab_init(gchar* searchbar_type);
calltab_t* calltab_init (gboolean searchbar_type, gchar *name);
/** Mark a call as selected. There can be only one selected call. This call
* is the currently highlighted one in the list.
......@@ -42,6 +42,6 @@ callable_obj_t *
calltab_get_selected_call (calltab_t*);
void
calltab_create_searchbar(calltab_t *, gchar *);
calltab_create_searchbar (calltab_t *);
#endif
......@@ -170,7 +170,7 @@ focus_on_calltree_in(){
}
void
calltree_create (calltab_t* tab, gchar* searchbar_type)
calltree_create (calltab_t* tab, gboolean searchbar_type)
{
// GtkWidget *sw;
// GtkCellRenderer *rend;
......@@ -246,19 +246,13 @@ calltree_create (calltab_t* tab, gchar* searchbar_type)
gtk_box_pack_start(GTK_BOX(tab->tree), sw, TRUE, TRUE, 0);
// no search bar if tab is either "history" or "addressbook"
// search bar if tab is either "history" or "addressbook"
if(searchbar_type){
calltab_create_searchbar(tab,searchbar_type);
calltab_create_searchbar (tab);
gtk_box_pack_start(GTK_BOX(tab->tree), tab->searchbar, FALSE, TRUE, 0);
}
gtk_widget_show(tab->tree);
// gtk_widget_show(tab->searchbar);
//toolbar_update_buttons();
}
void
......
......@@ -33,7 +33,7 @@
* @return GtkWidget* A new widget
*/
void
calltree_create(calltab_t* tab, gchar* searchbar_type);
calltree_create(calltab_t* tab, gboolean searchbar_type);
/**
* Add a call in the calltree
......
......@@ -28,53 +28,45 @@ GtkWidget * history_searchbar_widget;
static GtkTreeModel* history_create_filter (GtkTreeModel*);
static gboolean history_is_visible (GtkTreeModel*, GtkTreeIter*, gpointer);
void
history_search(GtkEntry* entry UNUSED){
if(history_filter != NULL) {
gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(history_filter));
}
void history_search (GtkEntry* entry UNUSED)
{
if(history_filter != NULL) {
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (history_filter));
}
}
void
history_init(){
history_filter = history_create_filter(GTK_TREE_MODEL (history->store));
gtk_tree_view_set_model(GTK_TREE_VIEW (history->view), GTK_TREE_MODEL(history_filter));
void history_init (void)
{
history_filter = history_create_filter (GTK_TREE_MODEL (history->store));
gtk_tree_view_set_model (GTK_TREE_VIEW (history->view), GTK_TREE_MODEL (history_filter));
}
void history_set_searchbar_widget(GtkWidget *searchbar){
history_searchbar_widget = searchbar;
void history_set_searchbar_widget (GtkWidget *searchbar)
{
history_searchbar_widget = searchbar;
}
static GtkTreeModel*
history_create_filter (GtkTreeModel* child) {
static GtkTreeModel* history_create_filter (GtkTreeModel* child)
{
GtkTreeModel* ret;
GtkTreeModel* ret;
DEBUG("Create Filter\n");
ret = gtk_tree_model_filter_new(child, NULL);
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(ret), history_is_visible, NULL, NULL);
return GTK_TREE_MODEL(ret);
DEBUG("Create Filter\n");
ret = gtk_tree_model_filter_new (child, NULL);
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (ret), history_is_visible, NULL, NULL);
return GTK_TREE_MODEL (ret);
}
static gboolean
history_is_visible (GtkTreeModel* model, GtkTreeIter* iter, gpointer data UNUSED) {
if( SHOW_SEARCHBAR )
static gboolean history_is_visible (GtkTreeModel* model, GtkTreeIter* iter, gpointer data UNUSED)
{
if (SHOW_SEARCHBAR)
{
GValue val;
gchar* text = NULL;
gchar* search = (gchar*)gtk_entry_get_text(GTK_ENTRY(history_searchbar_widget));
memset (&val, 0, sizeof(val));
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)){
text = (gchar *)g_value_get_string(&val);
}
......@@ -84,6 +76,5 @@ history_is_visible (GtkTreeModel* model, GtkTreeIter* iter, gpointer data UNUSED
g_value_unset (&val);
return TRUE;
}
return TRUE;
}
......@@ -28,35 +28,65 @@ const GdkColor GRAY_COLOR = { 0, 30000, 30000, 30000 };
GtkWidget * searchbox;
void searchbar_entry_changed (GtkEntry* entry, gchar* arg1 UNUSED, gpointer data UNUSED){
// gtk_widget_grab_focus (GTK_WIDGET(searchbox));
static GtkWidget *menu = NULL;
void searchbar_entry_changed (GtkEntry* entry, gchar* arg1 UNUSED, gpointer data UNUSED)
{
if (active_calltree == contacts) {
addressbook_search(entry);
addressbook_search (entry);
}
else if (active_calltree == history) {
history_search(entry);
history_search (entry);
}
}
// static void
// focus_in_event(GtkWidget *widget, GdkEventFocus *event, gpointer data)
// {
// }
void searchbar_clear_entry_if_default (GtkWidget* widget, gpointer user_data UNUSED) {
DEBUG("searchbar_clear_entry_if_default\n");
gtk_widget_modify_text(widget, GTK_STATE_NORMAL, &BLACK_COLOR);
if(g_ascii_strncasecmp(gtk_entry_get_text(GTK_ENTRY(widget)), "Search history", 14) == 0
|| g_ascii_strncasecmp(gtk_entry_get_text(GTK_ENTRY(widget)), "Search contact", 14) == 0 )
gtk_entry_set_text(GTK_ENTRY(widget), "");
static void search_all (GtkWidget *item, GtkEntry *entry)
{
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"
"Click here to change the search type");
}
// gtk_widget_grab_focus (GTK_WIDGET(searchbox));1
static void search_by_missed (GtkWidget *item, GtkEntry *entry)
{
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,
"Search by missed call\n"
"Click here to change the search type");
}
static void search_by_incoming (GtkWidget *item, GtkEntry *entry)
{
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,
"Search by incoming call\n"
"Click here to change the search type");
}
static void search_by_outgoing (GtkWidget *item, GtkEntry *entry)
{
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,
"Search by outgoing call\n"
"Click here to change the search type");
}
static void icon_press_cb (GtkEntry *entry, gint position, GdkEventButton *event, gpointer data)
{
if (position == GTK_ENTRY_ICON_PRIMARY)
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)
{
history_search (entry);
}
void
......@@ -72,52 +102,116 @@ focus_on_searchbar_in(){
// gtk_widget_grab_focus(GTK_WIDGET(sw));
focus_is_on_searchbar = TRUE;
}
void
clear_icon_released(GtkEntry *entry, GtkEntryIconPosition position UNUSED, GdkEventButton *event UNUSED, gpointer data UNUSED)
void searchbar_init(calltab_t *tab)
{
DEBUG("Clear Icon Released!\n");
gtk_entry_set_text(entry, "");
}
void
searchbar_init(calltab_t *tab)
{
if (tab == contacts) {
if (g_strcasecmp (tab->_name, CONTACTS) == 0)
{
addressbook_init();
}
else if (tab == history) {
else if (g_strcasecmp (tab->_name, HISTORY) == 0)
{
history_init();
}
else
ERROR ("searchbar.c - searchbar_init should not happen within this widget\n");
}
GtkWidget* searchbar_new(gchar* searchbar_type) {
GtkWidget* history_searchbar_new (void)
{
GtkWidget *ret, *item, *image;
GtkWidget* ret = gtk_hbox_new(FALSE, 0);
ret = gtk_hbox_new(FALSE, 0);
#if GTK_CHECK_VERSION(2,16,0)
searchbox = gtk_entry_new();
gtk_entry_set_icon_from_stock (GTK_ENTRY (searchbox), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_FIND);
gtk_entry_set_icon_from_stock (GTK_ENTRY (searchbox), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
g_signal_connect_after (G_OBJECT (searchbox), "icon-release",G_CALLBACK (clear_icon_released), NULL);
g_signal_connect (searchbox, "icon-press", G_CALLBACK (icon_press_cb), NULL);
//g_signal_connect (searchbox, "activate", G_CALLBACK (activate_cb), NULL);
// Set up the search icon
search_all (NULL, GTK_ENTRY (searchbox));
// Create the menu
menu = gtk_menu_new ();
gtk_menu_attach_to_widget (GTK_MENU (menu), searchbox, NULL);
image = gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
item = gtk_image_menu_item_new_with_label ("Search all");
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
g_signal_connect (item, "activate", G_CALLBACK (search_all), searchbox);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
item = gtk_image_menu_item_new_with_label ("Search by missed call");
image = gtk_image_new_from_file (ICONS_DIR "/missed.svg");
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
g_signal_connect (item, "activate", G_CALLBACK (search_by_missed), searchbox);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
item = gtk_image_menu_item_new_with_label ("Search by incoming call");
image = gtk_image_new_from_file (ICONS_DIR "/incoming.svg");
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
g_signal_connect (item, "activate", G_CALLBACK (search_by_incoming), searchbox);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
item = gtk_image_menu_item_new_with_label ("Search by outgoing call");
image = gtk_image_new_from_file (ICONS_DIR "/outgoing.svg");
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
g_signal_connect (item, "activate", G_CALLBACK (search_by_outgoing), searchbox);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show_all (menu);
#else
GtkWidget *image;
printf("Create search bar\n");
searchbox = sexy_icon_entry_new();
image = gtk_image_new_from_stock( GTK_STOCK_FIND , GTK_ICON_SIZE_SMALL_TOOLBAR);
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);
g_signal_connect_after (G_OBJECT (searchbox), "focus-out-event",
G_CALLBACK (focus_on_searchbar_out), NULL);
gtk_box_pack_start(GTK_BOX(ret), searchbox, TRUE, TRUE, 0);
history_set_searchbar_widget(searchbox);
return ret;
}
GtkWidget* contacts_searchbar_new () {
GtkWidget *ret;
ret = gtk_hbox_new(FALSE, 0);
#if GTK_CHECK_VERSION(2,16,0)
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);
g_signal_connect (searchbox, "icon-press", G_CALLBACK (icon_press_cb), NULL);
#else
GtkWidget *image;
searchbox = sexy_icon_entry_new();
image = gtk_image_new_from_stock( GTK_STOCK_FIND , GTK_ICON_SIZE_SMALL_TOOLBAR);
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
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), "grab-focus", G_CALLBACK(searchbar_clear_entry_if_default), NULL);
g_signal_connect_after (G_OBJECT (searchbox), "focus-in-event",
G_CALLBACK (focus_on_searchbar_in), NULL);
......@@ -126,7 +220,7 @@ GtkWidget* searchbar_new(gchar* searchbar_type) {
gtk_box_pack_start(GTK_BOX(ret), searchbox, TRUE, TRUE, 0);
history_set_searchbar_widget(searchbox);
//history_set_searchbar_widget(searchbox);
return ret;
}
......
......@@ -47,7 +47,8 @@ GdkPixbuf *waitingPixOff;
* Create a new search bar with "type" passed in
* parameter
*/
GtkWidget* searchbar_new(gchar*);
GtkWidget* history_searchbar_new (void);
GtkWidget* contacts_searchbar_new (void);
/**
* Initialize a specific search bar
......
......@@ -31,6 +31,10 @@
#define LOGO ICONS_DIR "/sflphone.svg"
#define LOGO_SMALL ICONS_DIR "/sflphone_small.svg"
#define CURRENT_CALLS "current_calls"
#define HISTORY "history"
#define CONTACTS "contacts"
/** Locale */
#define _(STRING) gettext( STRING )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment