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.
22 static GtkWidget *log_window=NULL;
23 static GStaticMutex log_mutex=G_STATIC_MUTEX_INIT;
24 static GList *log_queue=NULL;
26 typedef struct _LinphoneGtkLog{
31 void linphone_gtk_create_log_window(void){
33 log_window=linphone_gtk_create_window("log");
34 b=gtk_text_view_get_buffer(GTK_TEXT_VIEW(linphone_gtk_get_widget(log_window,"textview")));
35 gtk_text_buffer_create_tag(b,"red","foreground","red",NULL);
36 gtk_text_buffer_create_tag(b,"orange","foreground","orange",NULL);
39 void linphone_gtk_destroy_log_window(void){
40 GtkWidget *w=log_window;
41 g_static_mutex_lock(&log_mutex);
43 gtk_widget_destroy(w);
44 g_static_mutex_unlock(&log_mutex);
47 void linphone_gtk_log_show(void){
48 gtk_widget_show(log_window);
49 gtk_window_present(GTK_WINDOW(log_window));
52 static void linphone_gtk_display_log(OrtpLogLevel lev, const char *msg){
53 GtkTextIter iter,begin;
55 static GtkTextView *v=NULL;
57 const char *lname="undef";
59 if (log_window==NULL) {
63 if (v==NULL) v=GTK_TEXT_VIEW(linphone_gtk_get_widget(log_window,"textview"));
64 b=gtk_text_view_get_buffer(v);
82 g_error("Bad level !");
84 gtk_text_buffer_get_end_iter(b,&iter);
85 off=gtk_text_iter_get_offset(&iter);
86 gtk_text_buffer_insert(b,&iter,lname,-1);
87 gtk_text_buffer_get_end_iter(b,&iter);
88 gtk_text_buffer_insert(b,&iter,": ",-1);
89 gtk_text_buffer_get_end_iter(b,&iter);
90 gtk_text_buffer_insert(b,&iter,msg,-1);
91 gtk_text_buffer_get_end_iter(b,&iter);
92 gtk_text_buffer_insert(b,&iter,"\n",-1);
93 gtk_text_buffer_get_end_iter(b,&iter);
94 gtk_text_buffer_get_iter_at_offset(b,&begin,off);
95 if (lev==ORTP_ERROR || lev==ORTP_FATAL) gtk_text_buffer_apply_tag_by_name(b,"red",&begin,&iter);
96 else if (lev==ORTP_WARNING) gtk_text_buffer_apply_tag_by_name(b,"orange",&begin,&iter);
97 gtk_text_buffer_get_end_iter(b,&iter);
98 //gtk_text_view_scroll_to_iter(v,&iter,0,FALSE,0,0);
101 gboolean linphone_gtk_check_logs(){
103 g_static_mutex_lock(&log_mutex);
104 for(elem=log_queue;elem!=NULL;elem=elem->next){
105 LinphoneGtkLog *lgl=(LinphoneGtkLog*)elem->data;
106 linphone_gtk_display_log(lgl->lev,lgl->msg);
110 if (log_queue) g_list_free(log_queue);
112 g_static_mutex_unlock(&log_mutex);
116 void linphone_gtk_log_push(OrtpLogLevel lev, const char *fmt, va_list args){
117 gchar *msg=g_strdup_vprintf(fmt,args);
118 LinphoneGtkLog *lgl=g_new(LinphoneGtkLog,1);
121 g_static_mutex_lock(&log_mutex);
122 log_queue=g_list_append(log_queue,lgl);
123 g_static_mutex_unlock(&log_mutex);