+static void linphone_gtk_chat_message_destroy(LinphoneChatMessage *msg){
+ linphone_chat_message_destroy(msg);
+}
+
+void linphone_gtk_free_list(MSList *messages){
+ ms_list_for_each(messages,(void (*)(void*))linphone_gtk_chat_message_destroy);
+ ms_list_free(messages);
+}
+
+void display_history_message(GtkWidget *chat_view,MSList *messages,const LinphoneAddress *with){
+ if(messages != NULL){
+ MSList *it;
+ char *from_str;
+ char *with_str;
+ gchar *tmp;
+ for(it=messages;it!=NULL;it=it->next){
+ LinphoneChatMessage *msg=(LinphoneChatMessage *)it->data;
+ from_str=linphone_address_as_string_uri_only(linphone_chat_message_get_from(msg));
+ with_str=linphone_address_as_string_uri_only(with);
+ linphone_gtk_push_text(chat_view,strcmp(from_str,with_str)==0? with :
+ linphone_chat_message_get_from(msg),
+ strcmp(from_str,with_str)==0? FALSE : TRUE,
+ linphone_chat_message_get_chat_room(msg),msg,TRUE);
+ }
+ tmp=g_object_get_data(G_OBJECT(chat_view),"from_message");
+ if (tmp){
+ g_object_set_data(G_OBJECT(chat_view),"from_message",NULL);
+ g_free(tmp);
+ }
+ ms_free(from_str);
+ ms_free(with_str);
+ linphone_gtk_free_list(messages);
+ }
+}
+
+void linphone_gtk_chat_add_contact(const LinphoneAddress *addr){
+ //LinphoneAddress *addr=(LinphoneAddress *)data;
+ LinphoneFriend *lf=NULL;
+ char *uri=linphone_address_as_string(addr);
+ lf=linphone_friend_new_with_addr(uri);
+ ms_free(uri);
+ char *fixed_uri=NULL;
+ gboolean show_presence=FALSE;
+
+ linphone_friend_set_inc_subscribe_policy(lf,LinphoneSPDeny);
+ linphone_friend_send_subscribe(lf,show_presence);
+
+ linphone_core_interpret_friend_uri(linphone_gtk_get_core(),uri,&fixed_uri);
+ if (fixed_uri==NULL){
+ linphone_gtk_display_something(GTK_MESSAGE_WARNING,_("Invalid sip contact !"));
+ return ;
+ }
+ linphone_friend_set_addr(lf,addr);
+ linphone_core_add_friend(linphone_gtk_get_core(),lf);
+ ms_free(fixed_uri);
+ linphone_gtk_show_friends();
+}
+
+GtkWidget* linphone_gtk_init_chatroom(LinphoneChatRoom *cr, const LinphoneAddress *with){
+ GtkWidget *chat_view=linphone_gtk_create_widget("main","chatroom_frame");
+ GtkWidget *main_window=linphone_gtk_get_main_window ();
+ GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch");
+ GtkWidget *text=linphone_gtk_get_widget(chat_view,"textview");
+ GdkColor color;
+ GdkColor colorb;
+ int idx;
+ GtkWidget *button;
+ GtkWidget *entry;
+ GList *list=NULL;
+ MSList *messages;
+ char *with_str;
+
+ color.red = 32512;
+ color.green = 32512;
+ color.blue = 32512;
+ colorb.red = 56832;
+ colorb.green = 60928;
+ colorb.blue = 61952;
+
+ with_str=linphone_address_as_string_uri_only(with);
+ linphone_chat_room_mark_as_read(cr);
+ gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text),GTK_WRAP_WORD_CHAR);
+ gtk_text_view_set_editable(GTK_TEXT_VIEW(text),FALSE);
+ gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text),FALSE);
+ gtk_notebook_append_page(notebook,chat_view,create_tab_chat_header(cr,with));
+ idx = gtk_notebook_page_num(notebook, chat_view);
+ gtk_notebook_set_current_page(notebook, idx);
+ gtk_widget_show(chat_view);
+ g_object_set_data(G_OBJECT(chat_view),"cr",cr);
+ g_object_set_data(G_OBJECT(chat_view),"from_message",NULL);
+ g_object_set_data(G_OBJECT(chat_view),"list",list);
+ gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)),
+ "right","justification", GTK_JUSTIFY_RIGHT,NULL);
+ gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)),
+ "left","justification", GTK_JUSTIFY_LEFT,NULL);
+ gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)),
+ "bold","weight", PANGO_WEIGHT_BOLD,NULL);
+ gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)),
+ "italic","style", PANGO_STYLE_ITALIC,NULL);
+ gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)),
+ "small","size",9*PANGO_SCALE,NULL);
+ gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)),
+ "font_grey","foreground-gdk",&color,NULL);
+ gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)),
+ "margin","indent",10,NULL);
+ gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)),
+ "bg","paragraph-background-gdk",&colorb,NULL);
+ messages = linphone_chat_room_get_history(cr,NB_MSG_HIST);
+ display_history_message(chat_view,messages,with);
+ button = linphone_gtk_get_widget(chat_view,"send");
+ g_signal_connect_swapped(G_OBJECT(button),"clicked",(GCallback)linphone_gtk_send_text,NULL);
+ entry = linphone_gtk_get_widget(chat_view,"text_entry");
+ g_signal_connect_swapped(G_OBJECT(entry),"activate",(GCallback)linphone_gtk_send_text,NULL);
+ g_signal_connect(G_OBJECT(notebook),"switch_page",(GCallback)linphone_gtk_notebook_tab_select,NULL);
+ ms_free(with_str);
+ return chat_view;
+}
+
+LinphoneChatRoom * linphone_gtk_create_chatroom(const LinphoneAddress *with){
+ LinphoneChatRoom *cr=linphone_core_create_chat_room(linphone_gtk_get_core(),linphone_address_as_string(with));
+ if (!cr) return NULL;
+ return cr;
+}
+
+void linphone_gtk_load_chatroom(LinphoneChatRoom *cr,const LinphoneAddress *uri,GtkWidget *chat_view){
+ GtkWidget *main_window=linphone_gtk_get_main_window ();
+ LinphoneChatRoom *cr2=(LinphoneChatRoom *)g_object_get_data(G_OBJECT(chat_view),"cr");
+ const LinphoneAddress *from=linphone_chat_room_get_peer_address(cr2);
+ char *from_str=linphone_address_as_string_uri_only(from);
+ char *uri_str=linphone_address_as_string(uri);
+ char *uri_only=linphone_address_as_string_uri_only(uri);
+ MSList *messages=NULL;
+
+ if(g_strcmp0(from_str,uri_only)!=0){
+ GtkTextView *text_view=GTK_TEXT_VIEW(linphone_gtk_get_widget(chat_view,"textview"));
+ GtkTextIter start;
+ GtkTextIter end;
+ GtkTextBuffer *text_buffer;
+
+ linphone_chat_room_mark_as_read(cr);
+ text_buffer=gtk_text_view_get_buffer(text_view);
+ gtk_text_buffer_get_bounds(text_buffer, &start, &end);
+ gtk_text_buffer_delete (text_buffer, &start, &end);
+ udpate_tab_chat_header(chat_view,uri,cr);
+ g_object_set_data(G_OBJECT(chat_view),"cr",cr);
+ g_object_set_data(G_OBJECT(linphone_gtk_get_widget(main_window,"contact_list")),"chatview",(gpointer)chat_view);
+ messages=linphone_chat_room_get_history(cr,NB_MSG_HIST);
+ g_object_set_data(G_OBJECT(chat_view),"from_message",g_strdup(uri_str));
+ display_history_message(chat_view,messages,uri);