From: Margaux Clerc Date: Thu, 21 Mar 2013 16:12:16 +0000 (+0100) Subject: menu in call log view with call, chat and add contact X-Git-Url: http://sjero.net/git/?p=linphone;a=commitdiff_plain;h=ccd8bbb69c37b855affe784e5868b250a5620932 menu in call log view with call, chat and add contact --- diff --git a/coreapi/linphonefriend.h b/coreapi/linphonefriend.h index ab75b7bf..6eb2ab2a 100644 --- a/coreapi/linphonefriend.h +++ b/coreapi/linphonefriend.h @@ -132,6 +132,13 @@ void linphone_friend_destroy(LinphoneFriend *lf); */ int linphone_friend_set_addr(LinphoneFriend *fr, const LinphoneAddress* address); +/** + * set the display name for this friend + * @param lf #LinphoneFriend object + * @param name + */ +int linphone_friend_set_name(LinphoneFriend *lf, const char *name); + /** * get address of this friend * @param lf #LinphoneFriend object diff --git a/gtk/call_logs.ui b/gtk/call_logs.ui index 34c6ba3b..23184841 100644 --- a/gtk/call_logs.ui +++ b/gtk/call_logs.ui @@ -82,7 +82,9 @@ True True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK False + diff --git a/gtk/calllogs.c b/gtk/calllogs.c index ce4695dd..2ca86bea 100644 --- a/gtk/calllogs.c +++ b/gtk/calllogs.c @@ -47,6 +47,145 @@ void call_log_selection_changed(GtkTreeView *v){ } } +void linphone_gtk_call_log_chat_selected(GtkWidget *w){ + GtkTreeSelection *select; + GtkTreeIter iter; + + select=gtk_tree_view_get_selection(GTK_TREE_VIEW(w)); + if (select!=NULL){ + GtkTreeModel *model=NULL; + if (gtk_tree_selection_get_selected (select,&model,&iter)){ + gpointer pla; + LinphoneAddress *la; + gtk_tree_model_get(model,&iter,2,&pla,-1); + la=(LinphoneAddress*)pla; + if (la!=NULL){ + linphone_gtk_tree_view_set_chat_conversation(la); + } + } + } +} + +void linphone_gtk_call_log_add_contact(GtkWidget *w){ + GtkTreeSelection *select; + GtkTreeIter iter; + + select=gtk_tree_view_get_selection(GTK_TREE_VIEW(w)); + if (select!=NULL){ + GtkTreeModel *model=NULL; + if (gtk_tree_selection_get_selected (select,&model,&iter)){ + gpointer pla; + LinphoneAddress *la; + LinphoneFriend *lf; + gtk_tree_model_get(model,&iter,2,&pla,-1); + la=(LinphoneAddress*)pla; + if (la!=NULL){ + char *uri=linphone_address_as_string(la); + lf=linphone_friend_new_with_addr(uri); + linphone_gtk_show_contact(lf); + ms_free(uri); + } + } + } +} + +static bool_t put_selection_to_uribar(GtkWidget *treeview){ + GtkTreeSelection *sel; + + sel=gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + if (sel!=NULL){ + GtkTreeModel *model=NULL; + GtkTreeIter iter; + if (gtk_tree_selection_get_selected (sel,&model,&iter)){ + gpointer pla; + LinphoneAddress *la; + char *tmp; + gtk_tree_model_get(model,&iter,2,&pla,-1); + la=(LinphoneAddress*)pla; + tmp=linphone_address_as_string (la); + gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(linphone_gtk_get_main_window(),"uribar")),tmp); + ms_free(tmp); + return TRUE; + } + } + return FALSE; +} + +static void linphone_gtk_call_selected(GtkTreeView *treeview){ + put_selection_to_uribar(GTK_WIDGET(treeview)); + linphone_gtk_start_call(linphone_gtk_get_widget(gtk_widget_get_toplevel(GTK_WIDGET(treeview)), + "start_call")); +} + +static GtkWidget *linphone_gtk_create_call_log_menu(GtkWidget *call_log){ + GtkWidget *menu=gtk_menu_new(); + GtkWidget *menu_item; + gchar *call_label=NULL; + gchar *text_label=NULL; + gchar *name=NULL; + GtkWidget *image; + GtkTreeSelection *select; + GtkTreeIter iter; + + select=gtk_tree_view_get_selection(GTK_TREE_VIEW(call_log)); + if (select!=NULL){ + GtkTreeModel *model=NULL; + if (gtk_tree_selection_get_selected (select,&model,&iter)){ + gpointer pla; + LinphoneAddress *la; + gtk_tree_model_get(model,&iter,2,&pla,-1); + la=(LinphoneAddress*)pla; + name=linphone_address_as_string(la); + call_label=g_strdup_printf(_("Call %s"),name); + text_label=g_strdup_printf(_("Send text to %s"),name); + g_free(name); + } + } + if (call_label){ + menu_item=gtk_image_menu_item_new_with_label(call_label); + image=gtk_image_new_from_stock(GTK_STOCK_NETWORK,GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item),image); + gtk_widget_show(image); + gtk_widget_show(menu_item); + gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item); + g_signal_connect_swapped(G_OBJECT(menu_item),"activate",(GCallback)linphone_gtk_call_selected,call_log); + } + if (text_label){ + menu_item=gtk_image_menu_item_new_with_label(text_label); + image=gtk_image_new_from_stock(GTK_STOCK_NETWORK,GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item),image); + gtk_widget_show(image); + gtk_widget_show(menu_item); + gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item); + g_signal_connect_swapped(G_OBJECT(menu_item),"activate",(GCallback)linphone_gtk_call_log_chat_selected,call_log); + } + + menu_item=gtk_image_menu_item_new_from_stock(GTK_STOCK_ADD,NULL); + gtk_widget_show(menu_item); + gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item); + g_signal_connect_swapped(G_OBJECT(menu_item),"activate",(GCallback)linphone_gtk_call_log_add_contact,call_log); + gtk_widget_show(menu); + gtk_menu_attach_to_widget(GTK_MENU(menu),call_log, NULL); + + if (call_label) g_free(call_label); + if (text_label) g_free(text_label); + return menu; +} + +gboolean linphone_gtk_call_log_popup_contact(GtkWidget *list, GdkEventButton *event){ + GtkWidget *m=linphone_gtk_create_call_log_menu(list); + gtk_menu_popup (GTK_MENU (m), NULL, NULL, NULL, NULL, + event ? event->button : 0, event ? event->time : gtk_get_current_event_time()); + return TRUE; +} + +gboolean linphone_gtk_call_log_button_pressed(GtkWidget *widget, GdkEventButton *event){ + if (event->button == 3 && event->type == GDK_BUTTON_PRESS){ + return linphone_gtk_call_log_popup_contact(widget, event); + } + return FALSE; +} + void linphone_gtk_call_log_update(GtkWidget *w){ GtkTreeView *v=GTK_TREE_VIEW(linphone_gtk_get_widget(w,"logs_view")); GtkTreeStore *store; @@ -62,6 +201,7 @@ void linphone_gtk_call_log_update(GtkWidget *w){ select=gtk_tree_view_get_selection(v); gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); g_signal_connect_swapped(G_OBJECT(select),"changed",(GCallback)call_log_selection_changed,v); + g_signal_connect(G_OBJECT(v),"button-press-event",(GCallback)linphone_gtk_call_log_button_pressed,NULL); // gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(w,"call_back_button")), // create_pixmap (linphone_gtk_get_ui_config("callback_button","status-green.png"))); } @@ -149,28 +289,6 @@ void linphone_gtk_call_log_update(GtkWidget *w){ } -static bool_t put_selection_to_uribar(GtkWidget *treeview){ - GtkTreeSelection *sel; - - sel=gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); - if (sel!=NULL){ - GtkTreeModel *model=NULL; - GtkTreeIter iter; - if (gtk_tree_selection_get_selected (sel,&model,&iter)){ - gpointer pla; - LinphoneAddress *la; - char *tmp; - gtk_tree_model_get(model,&iter,2,&pla,-1); - la=(LinphoneAddress*)pla; - tmp=linphone_address_as_string (la); - gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(linphone_gtk_get_main_window(),"uribar")),tmp); - ms_free(tmp); - return TRUE; - } - } - return FALSE; -} - void linphone_gtk_history_row_activated(GtkWidget *treeview){ if (put_selection_to_uribar(treeview)){ GtkWidget *mw=linphone_gtk_get_main_window(); @@ -207,8 +325,6 @@ void linphone_gtk_call_log_response(GtkWidget *w, guint response_id){ gtk_widget_destroy(w); } - - GtkWidget * linphone_gtk_show_call_logs(void){ GtkWidget *mw=linphone_gtk_get_main_window(); @@ -223,5 +339,4 @@ GtkWidget * linphone_gtk_show_call_logs(void){ linphone_gtk_call_log_update(w); }else gtk_window_present(GTK_WINDOW(w)); return w; -} - +} \ No newline at end of file diff --git a/gtk/friendlist.c b/gtk/friendlist.c index e1012f7c..9f5a935b 100644 --- a/gtk/friendlist.c +++ b/gtk/friendlist.c @@ -195,16 +195,21 @@ void linphone_gtk_create_chat_picture(gboolean active){ GtkTreeModel *model=gtk_tree_view_get_model(GTK_TREE_VIEW(friendlist)); if (gtk_tree_model_get_iter_first(model,&iter)) { do{ - if(!active){ + //if(!active){ gtk_list_store_set(GTK_LIST_STORE(model),&iter,FRIEND_CHAT,create_chat_picture(),-1); - } else { - gtk_list_store_set(GTK_LIST_STORE(model),&iter,FRIEND_CHAT,create_active_chat_picture(),-1); - } + //} else { + // gtk_list_store_set(GTK_LIST_STORE(model),&iter,FRIEND_CHAT,create_active_chat_picture(),-1); + //} }while(gtk_tree_model_iter_next(model,&iter)); } } -void linphone_gtk_update_chat_picture(){ +static gboolean grab_focus(GtkWidget *w){ + gtk_widget_grab_focus(w); + return FALSE; +} + +void linphone_gtk_tree_view_set_chat_conversation(LinphoneAddress *la){ GtkTreeIter iter; GtkListStore *store=NULL; GtkWidget *w = linphone_gtk_get_main_window(); @@ -212,28 +217,56 @@ void linphone_gtk_update_chat_picture(){ GtkTreeModel *model=gtk_tree_view_get_model(GTK_TREE_VIEW(friendlist)); GtkWidget *chat_view=(GtkWidget*)g_object_get_data(G_OBJECT(friendlist),"chatview"); LinphoneFriend *lf=NULL; - char *uri=(char *)g_object_get_data(G_OBJECT(friendlist),"from"); - store=GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(friendlist))); - if (gtk_tree_model_get_iter_first(model,&iter)) { - do{ - gtk_tree_model_get (model, &iter,FRIEND_ID , &lf, -1); - if(chat_view!=NULL){ - if(uri !=NULL) { - if(g_strcmp0(linphone_address_as_string(linphone_friend_get_address(lf)), - uri)==0){ - gtk_list_store_set(store,&iter,FRIEND_CHAT,create_active_chat_picture(),-1); + LinphoneChatRoom *cr=NULL; + GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(w,"viewswitch"); + char *la_str=linphone_address_as_string(la); + + lf=linphone_core_get_friend_by_address(linphone_gtk_get_core(),la_str); + if(lf==NULL){ + cr=linphone_gtk_create_chatroom(la); + g_object_set_data(G_OBJECT(friendlist),"from",la_str); + if(chat_view==NULL){ + chat_view=linphone_gtk_init_chatroom(cr,la); + g_object_set_data(G_OBJECT(friendlist),"chatview",(gpointer)chat_view); + } else { + linphone_gtk_load_chatroom(cr,la,chat_view); + } + gtk_notebook_set_current_page(notebook,gtk_notebook_page_num(notebook,chat_view)); + linphone_gtk_create_chat_picture(FALSE); + g_idle_add((GSourceFunc)grab_focus,linphone_gtk_get_widget(chat_view,"text_entry")); + } else { + store=GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(friendlist))); + if (gtk_tree_model_get_iter_first(model,&iter)) { + do{ + const LinphoneAddress *uri; + char *lf_str; + gtk_tree_model_get (model, &iter,FRIEND_ID , &lf, -1); + uri=linphone_friend_get_address(lf); + lf_str=linphone_address_as_string(uri); + if( g_strcmp0(lf_str,la_str)==0){ + gtk_tree_model_get (model, &iter,FRIEND_CHATROOM , &cr, -1); + if(cr==NULL){ + cr=linphone_gtk_create_chatroom(uri); + gtk_list_store_set(store,&iter,FRIEND_CHATROOM,cr,-1); + } + g_object_set_data(G_OBJECT(friendlist),"from",linphone_address_as_string(uri)); + if(chat_view==NULL){ + chat_view=linphone_gtk_init_chatroom(cr,uri); + g_object_set_data(G_OBJECT(friendlist),"chatview",(gpointer)chat_view); } else { - gtk_list_store_set(store,&iter,FRIEND_CHAT,create_chat_picture(),-1); + linphone_gtk_load_chatroom(cr,uri,chat_view); } + gtk_notebook_set_current_page(notebook,gtk_notebook_page_num(notebook,chat_view)); + linphone_gtk_create_chat_picture(FALSE); + g_idle_add((GSourceFunc)grab_focus,linphone_gtk_get_widget(chat_view,"text_entry")); + gtk_list_store_set(store,&iter,FRIEND_CHAT,create_active_chat_picture(),-1); + gtk_list_store_set(store,&iter,FRIEND_NB_UNREAD_MSG,"",-1); + break; } - } - }while(gtk_tree_model_iter_next(model,&iter)); + }while(gtk_tree_model_iter_next(model,&iter)); + } } -} - -static gboolean grab_focus(GtkWidget *w){ - gtk_widget_grab_focus(w); - return FALSE; + } void linphone_gtk_chat_selected(GtkWidget *item){ @@ -734,7 +767,6 @@ void linphone_gtk_show_friends(void){ if(nbmsg != 0){ sprintf(buf,"%i",nbmsg); } - } gtk_list_store_set(store,&iter,FRIEND_CALL,create_call_picture(),-1); @@ -743,7 +775,7 @@ void linphone_gtk_show_friends(void){ escaped=g_markup_escape_text(uri,-1); gtk_list_store_set(store,&iter,FRIEND_SIP_ADDRESS,escaped,-1); g_free(escaped); - linphone_gtk_update_chat_picture(); + //linphone_gtk_update_chat_picture(); //bi=linphone_friend_get_info(lf); /*if (bi!=NULL && bi->image_data!=NULL){ GdkPixbuf *pbuf= @@ -787,6 +819,7 @@ void linphone_gtk_contact_cancel(GtkWidget *button){ void linphone_gtk_contact_ok(GtkWidget *button){ GtkWidget *w=gtk_widget_get_toplevel(button); LinphoneFriend *lf=(LinphoneFriend*)g_object_get_data(G_OBJECT(w),"friend_ref"); + LinphoneFriend *lf2; char *fixed_uri=NULL; gboolean show_presence=FALSE,allow_presence=FALSE; const gchar *name,*uri; @@ -811,16 +844,20 @@ void linphone_gtk_contact_ok(GtkWidget *button){ LinphoneAddress* friend_address = linphone_address_new(fixed_uri); linphone_address_set_display_name(friend_address,name); linphone_friend_set_addr(lf,friend_address); - ms_free(fixed_uri); linphone_address_destroy(friend_address); linphone_friend_send_subscribe(lf,show_presence); linphone_friend_set_inc_subscribe_policy(lf,allow_presence==TRUE ? LinphoneSPAccept : LinphoneSPDeny); if (linphone_friend_in_list(lf)) { linphone_friend_done(lf); - }else{ - linphone_core_add_friend(linphone_gtk_get_core(),lf); + } else { + lf2=linphone_core_get_friend_by_address(linphone_gtk_get_core(),fixed_uri); + if(lf2==NULL){ + linphone_friend_set_name(lf,name); + linphone_core_add_friend(linphone_gtk_get_core(),lf); + } } + ms_free(fixed_uri); linphone_gtk_show_friends(); gtk_widget_destroy(w); } @@ -997,6 +1034,4 @@ gboolean linphone_gtk_contact_list_button_pressed(GtkWidget *widget, GdkEventBut void linphone_gtk_buddy_info_updated(LinphoneCore *lc, LinphoneFriend *lf){ /*refresh the entire list*/ linphone_gtk_show_friends(); -} - - +} \ No newline at end of file diff --git a/gtk/linphone.h b/gtk/linphone.h index a7d7da50..ccdebea6 100644 --- a/gtk/linphone.h +++ b/gtk/linphone.h @@ -153,3 +153,4 @@ void linphone_gtk_unmonitor_usb(void); gchar *linphone_gtk_get_record_path(const LinphoneAddress *address, gboolean is_conference); void linphone_gtk_friend_list_update_message(LinphoneChatMessage *msg); +void linphone_gtk_tree_view_set_chat_conversation(LinphoneAddress *la); diff --git a/gtk/main.ui b/gtk/main.ui index e1c8c912..0b27240e 100644 --- a/gtk/main.ui +++ b/gtk/main.ui @@ -313,7 +313,6 @@ True False - label center @@ -368,7 +367,6 @@ True False - label True