Commit c79c8583 authored by Simon Morlat's avatar Simon Morlat
Browse files

improve log window

parent bc525844
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy toplevel-contextual -->
<object class="GtkDialog" id="log">
<property name="width_request">540</property>
<property name="height_request">290</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Linphone debug window</property>
<property name="window_position">center-on-parent</property>
<property name="type_hint">normal</property>
<property name="deletable">False</property>
<property name="has_separator">False</property>
<signal name="response" handler="gtk_widget_hide"/>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<object class="GtkBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<property name="vscrollbar_policy">automatic</property>
<property name="window_placement">bottom-left</property>
<property name="window_placement_set">True</property>
<property name="shadow_type">in</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<property name="layout_style">spread</property>
<child>
<object class="GtkTextView" id="textview">
<object class="GtkCheckButton" id="scroll_to_end">
<property name="label" translatable="yes">Scroll to end</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">False</property>
<property name="wrap_mode">word</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="xalign">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="linphone_gtk_log_scroll_to_end" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
<placeholder/>
<object class="GtkButton" id="button2">
<property name="label">gtk-clear</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="linphone_gtk_log_clear" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
......@@ -52,25 +62,51 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="linphone_gtk_log_hide"/>
<signal name="clicked" handler="linphone_gtk_log_hide" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="pack_type">end</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<property name="window_placement">bottom-left</property>
<property name="window_placement_set">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTextView" id="textview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">False</property>
<property name="wrap_mode">word</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">scroll_to_end</action-widget>
<action-widget response="0">button2</action-widget>
<action-widget response="0">button1</action-widget>
</action-widgets>
</object>
......
......@@ -239,18 +239,12 @@ void linphone_gtk_log_show(void){
gtk_window_present(GTK_WINDOW(log_window));
}
static void linphone_gtk_display_log(OrtpLogLevel lev, const char *msg){
static void linphone_gtk_display_log(GtkTextView *v, OrtpLogLevel lev, const char *msg){
GtkTextIter iter,begin;
int off;
static GtkTextView *v=NULL;
GtkTextBuffer *b;
const char *lname="undef";
if (log_window==NULL) {
return;
}
if (v==NULL) v=GTK_TEXT_VIEW(linphone_gtk_get_widget(log_window,"textview"));
b=gtk_text_view_get_buffer(v);
switch(lev){
case ORTP_DEBUG:
......@@ -285,10 +279,7 @@ static void linphone_gtk_display_log(OrtpLogLevel lev, const char *msg){
gtk_text_buffer_get_iter_at_offset(b,&begin,off);
if (lev==ORTP_ERROR || lev==ORTP_FATAL) gtk_text_buffer_apply_tag_by_name(b,"red",&begin,&iter);
else if (lev==ORTP_WARNING) gtk_text_buffer_apply_tag_by_name(b,"orange",&begin,&iter);
/*
gtk_text_buffer_get_end_iter(b,&iter);
gtk_text_view_scroll_to_iter(v,&iter,0,FALSE,0,0);
*/
while(gtk_text_buffer_get_char_count(b)>LOG_MAX_CHARS){
GtkTextIter iter_line_after;
gtk_text_buffer_get_start_iter(b,&iter);
......@@ -297,23 +288,50 @@ static void linphone_gtk_display_log(OrtpLogLevel lev, const char *msg){
gtk_text_buffer_delete(b,&iter,&iter_line_after);
}
}
}
static void stick_to_end(GtkTextView *v){
GtkTextBuffer *b;
GtkTextIter iter;
b=gtk_text_view_get_buffer(v);
gtk_text_buffer_get_end_iter(b,&iter);
gtk_text_view_scroll_to_iter(v,&iter,0,FALSE,1.0,0);
}
void linphone_gtk_log_scroll_to_end(GtkToggleButton *button){
if (gtk_toggle_button_get_active(button)){
GtkTextView *v=GTK_TEXT_VIEW(linphone_gtk_get_widget(log_window,"textview"));
stick_to_end(v);
}
}
/*
* called from Gtk main loop.
**/
gboolean linphone_gtk_check_logs(){
GList *elem;
GtkTextView *v=NULL;
if (log_window) v=GTK_TEXT_VIEW(linphone_gtk_get_widget(log_window,"textview"));
g_static_mutex_lock(&log_mutex);
for(elem=log_queue;elem!=NULL;elem=elem->next){
LinphoneGtkLog *lgl=(LinphoneGtkLog*)elem->data;
linphone_gtk_display_log(lgl->lev,lgl->msg);
if (v) linphone_gtk_display_log(v,lgl->lev,lgl->msg);
g_free(lgl->msg);
g_free(lgl);
}
if (log_queue) g_list_free(log_queue);
log_queue=NULL;
g_static_mutex_unlock(&log_mutex);
if (v)
linphone_gtk_log_scroll_to_end(GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(log_window,"scroll_to_end")));
return TRUE;
}
/*
* Called from any linphone thread.
*/
void linphone_gtk_log_push(OrtpLogLevel lev, const char *fmt, va_list args){
gchar *msg=g_strdup_vprintf(fmt,args);
LinphoneGtkLog *lgl=g_new(LinphoneGtkLog,1);
......@@ -325,3 +343,17 @@ void linphone_gtk_log_push(OrtpLogLevel lev, const char *fmt, va_list args){
g_static_mutex_unlock(&log_mutex);
}
void linphone_gtk_log_clear(void){
if (log_window){
GtkTextIter end,begin;
GtkTextView *v;
GtkTextBuffer *b;
v=GTK_TEXT_VIEW(linphone_gtk_get_widget(log_window,"textview"));
b=gtk_text_view_get_buffer(v);
gtk_text_buffer_get_start_iter(b,&begin);
gtk_text_buffer_get_end_iter(b,&end);
gtk_text_buffer_delete(b,&begin,&end);
}
}
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment