2 linphone, gtk-glade interface.
3 Copyright (C) 2008 Simon MORLAT (simon.morlat@linphone.org)
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <gtkosxapplication.h>
27 GtkWidget * linphone_gtk_init_chatroom(LinphoneChatRoom *cr, const char *with){
31 w=linphone_gtk_create_window("chatroom");
32 tmp=g_strdup_printf(_("Chat with %s"),with);
33 gtk_window_set_title(GTK_WINDOW(w),tmp);
35 g_object_set_data(G_OBJECT(w),"cr",cr);
37 linphone_chat_room_set_user_data(cr,w);
38 b=gtk_text_view_get_buffer(GTK_TEXT_VIEW(linphone_gtk_get_widget(w,"textlog")));
39 gtk_text_buffer_create_tag(b,"blue","foreground","blue",NULL);
40 gtk_text_buffer_create_tag(b,"green","foreground","green",NULL);
44 void linphone_gtk_create_chatroom(const char *with){
46 LinphoneChatRoom *cr=linphone_core_create_chat_room(linphone_gtk_get_core(),with);
48 linphone_gtk_init_chatroom(cr,with);
51 void linphone_gtk_chat_destroyed(GtkWidget *w){
52 LinphoneChatRoom *cr=(LinphoneChatRoom*)g_object_get_data(G_OBJECT(w),"cr");
53 linphone_chat_room_destroy(cr);
56 void linphone_gtk_chat_close(GtkWidget *button){
57 GtkWidget *w=gtk_widget_get_toplevel(button);
58 gtk_widget_destroy(w);
61 void linphone_gtk_push_text(GtkTextView *v, const char *from, const char *message, gboolean me){
62 GtkTextBuffer *b=gtk_text_view_get_buffer(v);
63 GtkTextIter iter,begin;
65 gtk_text_buffer_get_end_iter(b,&iter);
66 off=gtk_text_iter_get_offset(&iter);
67 gtk_text_buffer_insert(b,&iter,from,-1);
68 gtk_text_buffer_get_end_iter(b,&iter);
69 gtk_text_buffer_insert(b,&iter,":\t",-1);
70 gtk_text_buffer_get_end_iter(b,&iter);
71 gtk_text_buffer_get_iter_at_offset(b,&begin,off);
72 gtk_text_buffer_apply_tag_by_name(b,me ? "green" : "blue" ,&begin,&iter);
73 gtk_text_buffer_insert(b,&iter,message,-1);
74 gtk_text_buffer_get_end_iter(b,&iter);
75 gtk_text_buffer_insert(b,&iter,"\n",-1);
76 gtk_text_buffer_get_end_iter(b,&iter);
78 GtkTextMark *mark=gtk_text_buffer_create_mark(b,NULL,&iter,FALSE);
79 gtk_text_view_scroll_mark_onscreen(v,mark);
80 //gtk_text_buffer_get_end_iter(b,&iter);
81 //gtk_text_iter_forward_to_line_end(&iter);
82 //gtk_text_view_scroll_to_iter(v,&iter,0,TRUE,1.0,1.0);
85 const char* linphone_gtk_get_used_identity(){
86 LinphoneCore *lc=linphone_gtk_get_core();
87 LinphoneProxyConfig *cfg;
88 linphone_core_get_default_proxy(lc,&cfg);
89 if (cfg) return linphone_proxy_config_get_identity(cfg);
90 else return linphone_core_get_primary_contact(lc);
93 void linphone_gtk_send_text(GtkWidget *button){
94 GtkWidget *w=gtk_widget_get_toplevel(button);
95 GtkWidget *entry=linphone_gtk_get_widget(w,"text_entry");
96 LinphoneChatRoom *cr=(LinphoneChatRoom*)g_object_get_data(G_OBJECT(w),"cr");
98 entered=gtk_entry_get_text(GTK_ENTRY(entry));
99 if (strlen(entered)>0) {
100 linphone_gtk_push_text(GTK_TEXT_VIEW(linphone_gtk_get_widget(w,"textlog")),
101 linphone_gtk_get_used_identity(),
103 linphone_chat_room_send_message(cr,entered);
104 gtk_entry_set_text(GTK_ENTRY(entry),"");
108 void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message){
109 GtkWidget *w=(GtkWidget*)linphone_chat_room_get_user_data(room);
111 w=linphone_gtk_init_chatroom(room,linphone_address_as_string_uri_only(from));
115 /* Notify when a new message is send */
116 linphone_gtk_status_icon_set_blinking(TRUE);
119 linphone_gtk_push_text(GTK_TEXT_VIEW(linphone_gtk_get_widget(w,"textlog")),
120 linphone_address_as_string_uri_only(from),
122 gtk_window_present(GTK_WINDOW(w));
123 /*gtk_window_set_urgency_hint(GTK_WINDOW(w),TRUE);*/