if (msg->message) ms_free(msg->message);
if (msg->external_body_url) ms_free(msg->external_body_url);
if (msg->from) linphone_address_destroy(msg->from);
+ if (msg->to) linphone_address_destroy(msg->to);
if (msg->custom_headers) sal_custom_header_free(msg->custom_headers);
ms_free(msg);
}
MSList *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message);
void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr);
void linphone_chat_room_delete_history(LinphoneChatRoom *cr);
+int linphone_chat_room_get_unread_messages_count(LinphoneChatRoom *cr);
LinphoneCore* linphone_chat_room_get_lc(LinphoneChatRoom *cr);
void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud);
void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr);
LinphoneChatMessageState linphone_chat_message_get_state(const LinphoneChatMessage* message);
const char* linphone_chat_message_state_to_string(const LinphoneChatMessageState state);
LinphoneChatMessage* linphone_chat_message_clone(const LinphoneChatMessage* message);
+void linphone_chat_message_destroy(LinphoneChatMessage* msg);
void linphone_chat_message_set_from(LinphoneChatMessage* message, const LinphoneAddress* from);
const LinphoneAddress* linphone_chat_message_get_from(const LinphoneChatMessage* message);
const LinphoneAddress* linphone_chat_message_get_to(const LinphoneChatMessage* message);
int linphone_core_get_video_dscp(const LinphoneCore *lc);
-
#ifdef __cplusplus
}
#endif
}\r
\r
void linphone_sql_request_message(sqlite3 *db,const char *stmt,LinphoneChatRoom *cr){\r
- char* errmsg;\r
+ char* errmsg=NULL;\r
int ret;\r
ret=sqlite3_exec(db,stmt,callback,cr,&errmsg);\r
if(ret != SQLITE_OK) {\r
printf("Error in creation: %s.\n", errmsg);\r
+ sqlite3_free(errmsg);\r
}\r
}\r
\r
void linphone_chat_message_store(LinphoneChatMessage *msg){\r
LinphoneCore *lc=linphone_chat_room_get_lc(msg->chat_room);\r
if (lc->db){\r
- const char *peer=msg->chat_room->peer;\r
+ char *peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(msg->chat_room));\r
char *local_contact=linphone_address_as_string_uri_only(linphone_chat_message_get_local_address(msg));\r
char datebuf[26];\r
char *buf=sqlite3_mprintf("insert into history values(NULL,%Q,%Q,%i,%Q,%Q,%i,%i);",\r
linphone_sql_request(lc->db,buf);\r
sqlite3_free(buf);\r
ms_free(local_contact);\r
+ ms_free(peer);\r
}\r
}\r
\r
\r
if (lc->db==NULL) return ;\r
\r
+ char *peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr));\r
char *buf=sqlite3_mprintf("update history set read=%i where remoteContact = %Q;",\r
- read,cr->peer);\r
+ read,peer);\r
linphone_sql_request(lc->db,buf);\r
sqlite3_free(buf);\r
+ ms_free(peer);\r
+}\r
+\r
+int linphone_chat_room_get_unread_messages_count(LinphoneChatRoom *cr){\r
+ LinphoneCore *lc=linphone_chat_room_get_lc(cr);\r
+ int numrows=0;\r
+ \r
+ if (lc->db==NULL) return 0;\r
+ \r
+ char *peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr));\r
+ char *buf=sqlite3_mprintf("select count(*) from history where remoteContact = %Q and read = 0;",peer);\r
+ sqlite3_stmt *selectStatement;\r
+ int returnValue = sqlite3_prepare_v2(lc->db,buf,-1,&selectStatement,NULL);\r
+ if (returnValue == SQLITE_OK){\r
+ if(sqlite3_step(selectStatement) == SQLITE_ROW){\r
+ numrows= sqlite3_column_int(selectStatement, 0);\r
+ }\r
+ }\r
+ sqlite3_finalize(selectStatement);\r
+ sqlite3_free(buf);\r
+ ms_free(peer);\r
+ return numrows;\r
}\r
\r
void linphone_chat_room_delete_history(LinphoneChatRoom *cr){\r
LinphoneCore *lc=cr->lc;\r
\r
if (lc->db==NULL) return ;\r
- char *buf=sqlite3_mprintf("delete from history where remoteContact = %Q;",cr->peer);\r
+ \r
+ char *peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr));\r
+ char *buf=sqlite3_mprintf("delete from history where remoteContact = %Q;",peer);\r
linphone_sql_request(lc->db,buf);\r
sqlite3_free(buf);\r
+ ms_free(peer);\r
}\r
\r
MSList *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message){\r
MSList *ret;\r
\r
if (lc->db==NULL) return NULL;\r
- \r
+ char *peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr));\r
cr->messages_hist = NULL;\r
- char *buf=sqlite3_mprintf("select * from history where remoteContact = %Q order by id DESC limit %i ;",cr->peer,nb_message);\r
+ char *buf=sqlite3_mprintf("select * from history where remoteContact = %Q order by id DESC limit %i ;",peer,nb_message);\r
linphone_sql_request_message(lc->db,buf,cr);\r
sqlite3_free(buf);\r
ret=cr->messages_hist;\r
cr->messages_hist=NULL;\r
+ ms_free(peer);\r
return ret;\r
}\r
\r
}\r
\r
void linphone_create_table(sqlite3* db){\r
- char* errmsg;\r
+ char* errmsg=NULL;\r
int ret;\r
ret=sqlite3_exec(db,"CREATE TABLE if not exists history (id INTEGER PRIMARY KEY AUTOINCREMENT, localContact TEXT NOT NULL, remoteContact TEXT NOT NULL, direction INTEGER, message TEXT, time TEXT NOT NULL, read INTEGER, status INTEGER);",\r
0,0,&errmsg);\r
if(ret != SQLITE_OK) {\r
printf("Error in creation: %s.\n", errmsg);\r
+ sqlite3_free(errmsg);\r
}\r
}\r
\r
void linphone_core_message_storage_close(LinphoneCore *lc){\r
}\r
\r
+int linphone_chat_room_get_unread_messages_count(LinphoneChatRoom *cr){\r
+ return 0;\r
+}\r
+\r
#endif\r
gtk_tree_view_append_column (v,c);
}
+void call_log_selection_changed(GtkTreeView *v){
+ GtkTreeSelection *select;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+
+ select = gtk_tree_view_get_selection(v);
+ if (gtk_tree_selection_get_selected (select, &model, &iter)){
+ GtkTreePath *path=gtk_tree_model_get_path(model,&iter);
+ gtk_tree_view_collapse_all(v);
+ gtk_tree_view_expand_row(v,path,TRUE);
+ gtk_tree_path_free(path);
+ }
+}
+
void linphone_gtk_call_log_update(GtkWidget *w){
GtkTreeView *v=GTK_TREE_VIEW(linphone_gtk_get_widget(w,"logs_view"));
GtkTreeStore *store;
const MSList *logs;
+ GtkTreeSelection *select;
store=(GtkTreeStore*)gtk_tree_view_get_model(v);
if (store==NULL){
gtk_tree_view_set_model(v,GTK_TREE_MODEL(store));
g_object_unref(G_OBJECT(store));
fill_renderers(GTK_TREE_VIEW(linphone_gtk_get_widget(w,"logs_view")));
+ 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);
// 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")));
}
g_return_if_fail(w!=NULL);
gtk_notebook_remove_page(GTK_NOTEBOOK(nb),idx);
- linphone_gtk_create_chat_picture(FALSE);
+ //linphone_gtk_create_chat_picture(FALSE);
g_object_set_data(G_OBJECT(friendlist),"chatview",NULL);
g_object_set_data(G_OBJECT(w),"from_message",NULL);
g_object_set_data(G_OBJECT(w),"cr",NULL);
}
}
+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;
g_object_set_data(G_OBJECT(chat_view),"from_message",NULL);
ms_free(from_str);
ms_free(with_str);
+ linphone_gtk_free_list(messages);
}
}
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);
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");
- char *from_str=linphone_address_as_string(linphone_chat_room_get_peer_address (cr2));
+ 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;
linphone_chat_room_mark_as_read(cr);
- if(g_strcmp0(from_str,uri_str)!=0){
+ 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;
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);
+ messages=linphone_chat_room_get_history(cr,NB_MSG_HIST);
g_object_set_data(G_OBJECT(chat_view),"from_message",uri_str);
display_history_message(chat_view,messages,uri);
}
LinphoneChatMessage *msg){
GtkWidget *main_window=linphone_gtk_get_main_window();
GtkWidget *friendlist=linphone_gtk_get_widget(main_window,"contact_list");
- GtkWidget *w;
+ GtkWidget *w;
+ gboolean send=TRUE;
+ char *from=linphone_address_as_string(linphone_chat_message_get_from(msg));
w=(GtkWidget*)g_object_get_data(G_OBJECT(friendlist),"chatview");
if(w!=NULL){
- linphone_gtk_load_chatroom(room,linphone_chat_message_get_from(msg),w);
+ char *from_chatview=(char *)g_object_get_data(G_OBJECT(w),"from");
+ if(g_strcmp0(from,from_chatview)==0){
+ send=TRUE;
+ } else {
+ send=FALSE;
+ }
+ ms_free(from_chatview);
} else {
w=linphone_gtk_init_chatroom(room,linphone_chat_message_get_from(msg));
g_object_set_data(G_OBJECT(friendlist),"chatview",(gpointer)w);
- char *from=linphone_address_as_string(linphone_chat_message_get_from(msg));
g_object_set_data(G_OBJECT(friendlist),"from",from);
}
get_display_name(linphone_chat_message_get_from(msg));
}
}
#endif
- linphone_gtk_push_text(w,linphone_chat_message_get_from(msg),
+ if(send){
+ linphone_gtk_push_text(w,linphone_chat_message_get_from(msg),
FALSE,room,msg,FALSE);
- linphone_gtk_update_chat_picture();
+ } else {
+ linphone_gtk_show_friends();
+ //linphone_gtk_friend_list_update_message(msg);
+ }
+ ms_free(from);
+ //linphone_gtk_update_chat_picture();
+ //TODO: update la zone de notification dans les contacts (problème : lors du refresh de la liste
+ //connaitre tous les contacts qui ont des messages non lus ...
//gtk_window_present(GTK_WINDOW(w));
/*gtk_window_set_urgency_hint(GTK_WINDOW(w),TRUE);*/
}
FRIEND_ICON,
FRIEND_CALL,
FRIEND_CHAT,
- FRIEND_CHAT_CONVERSATION,
+ FRIEND_NB_UNREAD_MSG,
FRIEND_LIST_NCOL
};
GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(w,"viewswitch");
const LinphoneAddress *uri;
gtk_tree_model_get (model, &iter,FRIEND_ID , &lf, -1);
+ gtk_tree_model_get (model, &iter,FRIEND_CHATROOM , &cr, -1);
uri=linphone_friend_get_address(lf);
- if(cr == NULL){
+ if(cr==NULL){
cr=linphone_gtk_create_chatroom(uri);
+ gtk_list_store_set(store,&iter,FRIEND_CHATROOM,cr,-1);
}
page=(GtkWidget*)g_object_get_data(G_OBJECT(friendlist),"chatview");
g_object_set_data(G_OBJECT(friendlist),"from",linphone_address_as_string(uri));
linphone_gtk_create_chat_picture(FALSE);
g_idle_add((GSourceFunc)grab_focus,linphone_gtk_get_widget(page,"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);
}
}
linphone_gtk_init_bookmark_icon();
store = gtk_list_store_new(FRIEND_LIST_NCOL,GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER,
- G_TYPE_POINTER, G_TYPE_STRING, GDK_TYPE_PIXBUF, GDK_TYPE_PIXBUF, GDK_TYPE_PIXBUF, G_TYPE_STRING);
+ G_TYPE_POINTER, G_TYPE_STRING, GDK_TYPE_PIXBUF, GDK_TYPE_PIXBUF, GDK_TYPE_PIXBUF,
+ G_TYPE_STRING, G_TYPE_STRING);
gtk_tree_view_set_model(GTK_TREE_VIEW(friendlist),GTK_TREE_MODEL(store));
g_object_unref(G_OBJECT(store));
gtk_tree_view_column_set_clickable(column,TRUE);
gtk_tree_view_column_set_expand(column,TRUE);
gtk_tree_view_column_set_max_width(column,60);
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_tree_view_column_pack_start(column,renderer,TRUE);
+ gtk_tree_view_column_add_attribute (column,renderer,"text",FRIEND_NB_UNREAD_MSG);
+
gtk_tree_view_append_column (GTK_TREE_VIEW (friendlist), column);
-
/* Call column*/
renderer = gtk_cell_renderer_pixbuf_new();
column = gtk_tree_view_column_new_with_attributes (_("Call"),renderer,"pixbuf",FRIEND_CALL,NULL);
//const gchar *search=NULL;
//gboolean lookup=FALSE;
MSList *sorted;
+ LinphoneChatRoom *cr=NULL;
linphone_gtk_show_directory_search();
const char *name=linphone_address_get_display_name(f_uri);
const char *display=name;
char *escaped=NULL;
+ char buf[26]={0};
+ int nbmsg=0;
+
/*if (lookup){
if (strstr(uri,search)==NULL){
ms_free(uri);
FRIEND_PRESENCE_IMG, send_subscribe ? create_status_picture(linphone_friend_get_status(lf)) : NULL,
-1);
+ gtk_tree_model_get(gtk_tree_view_get_model(GTK_TREE_VIEW(friendlist)),&iter,FRIEND_CHATROOM,&cr,-1);
+ if(cr!=NULL){
+ nbmsg=linphone_chat_room_get_unread_messages_count(cr);
+ if(nbmsg != 0){
+ sprintf(buf,"%i",nbmsg);
+ }
+ } else {
+ cr=linphone_gtk_create_chatroom(f_uri);
+ gtk_list_store_set(store,&iter,FRIEND_CHATROOM,cr,-1);
+ nbmsg=linphone_chat_room_get_unread_messages_count(cr);
+ if(nbmsg != 0){
+ sprintf(buf,"%i",nbmsg);
+ }
+
+ }
+
gtk_list_store_set(store,&iter,FRIEND_CALL,create_call_picture(),-1);
gtk_list_store_set(store,&iter,FRIEND_CHAT,create_chat_picture(),-1);
-
+ gtk_list_store_set(store,&iter,FRIEND_NB_UNREAD_MSG,buf,-1);
escaped=g_markup_escape_text(uri,-1);
gtk_list_store_set(store,&iter,FRIEND_SIP_ADDRESS,escaped,-1);
g_free(escaped);
}
gint get_col_number_from_tree_view_column (GtkTreeViewColumn *col){
- GList *cols;
- gint num;
- g_return_val_if_fail ( col != NULL, -1 );
- g_return_val_if_fail ( col->tree_view != NULL, -1 );
- cols = gtk_tree_view_get_columns(GTK_TREE_VIEW(col->tree_view));
- num = g_list_index(cols, (gpointer) col);
- g_list_free(cols);
-
- return num;
-}
+ GList *cols;
+ gint num;
+ g_return_val_if_fail ( col != NULL, -1 );
+ g_return_val_if_fail ( col->tree_view != NULL, -1 );
+ cols = gtk_tree_view_get_columns(GTK_TREE_VIEW(col->tree_view));
+ num = g_list_index(cols, (gpointer) col);
+ g_list_free(cols);
-int longueur_list (GtkTreeView *tree_view){
- GtkTreeIter iter;
- int i=0;
- GtkTreeModel *model=gtk_tree_view_get_model(tree_view);
- if (gtk_tree_model_get_iter_first(model,&iter)) {
- do{
- i++;
- }while(gtk_tree_model_iter_next(model,&iter));
- }
- return i;
+ return num;
}
static gint tree_view_get_cell_from_pos(GtkTreeView *view, guint x, guint y){
GtkTreeViewColumn *col = NULL;
GList *node, *columns;
gint colx = 0;
- gint coly = longueur_list(view);
- gint height=0;
+ GtkTreePath *path;
+ GtkTreeViewDropPosition pos;
g_return_val_if_fail ( view != NULL, 0 );
columns = gtk_tree_view_get_columns(view);
- for (node = columns; node != NULL && col == NULL; node = node->next){
- GtkTreeViewColumn *checkcol = (GtkTreeViewColumn*) node->data;
- gtk_tree_view_column_cell_get_size(checkcol,NULL,NULL,NULL,NULL,&height);
- if (x >= colx && x < (colx + checkcol->width) && y < (height+2)*coly){
- col = checkcol;
- gint num = get_col_number_from_tree_view_column(col);
+ gtk_tree_view_get_dest_row_at_pos(view,x,y,&path,&pos);
+ if(path != NULL){
+ for (node = columns; node != NULL && col == NULL; node = node->next){
+ GtkTreeViewColumn *checkcol = (GtkTreeViewColumn*) node->data;
+ if (x >= colx && x < (colx + checkcol->width)){
+ col = checkcol;
+ gint num = get_col_number_from_tree_view_column(col);
return num;
- }
- else {
- colx += checkcol->width;
+ } else {
+ colx += checkcol->width;
}
- }
- g_list_free(columns);
+ }
+ }
+ g_list_free(columns);
return 0;
}
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);