2008-03-16 15:18:19 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com>
|
2006-08-20 22:45:29 +00:00
|
|
|
*
|
2008-03-16 15:18:19 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2008-09-23 19:11:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2008-03-16 15:18:19 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2008-09-23 19:11:04 +00:00
|
|
|
*
|
2008-03-16 21:26:05 +00:00
|
|
|
* $Id$
|
2008-03-16 15:18:19 +00:00
|
|
|
*/
|
2006-08-20 22:45:29 +00:00
|
|
|
|
2006-09-18 01:26:49 +00:00
|
|
|
#include <errno.h>
|
2007-07-19 03:55:00 +00:00
|
|
|
#include <stdio.h>
|
2006-08-20 22:45:29 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
2008-03-13 19:34:08 +00:00
|
|
|
#include <gtk/gtk.h>
|
2006-08-20 22:45:29 +00:00
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
|
2006-08-20 22:45:29 +00:00
|
|
|
#include "conf.h"
|
2007-12-27 16:21:14 +00:00
|
|
|
#include "hig.h"
|
2006-08-20 22:45:29 +00:00
|
|
|
#include "msgwin.h"
|
2008-03-16 15:18:19 +00:00
|
|
|
#include "tr-core.h"
|
2008-02-26 19:58:03 +00:00
|
|
|
#include "tr-prefs.h"
|
2006-08-20 22:45:29 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2008-03-13 19:34:08 +00:00
|
|
|
enum
|
2007-06-22 20:59:23 +00:00
|
|
|
{
|
2008-03-16 21:26:05 +00:00
|
|
|
COL_SEQUENCE,
|
2008-03-18 19:14:21 +00:00
|
|
|
COL_NAME,
|
2008-03-13 19:34:08 +00:00
|
|
|
COL_MESSAGE,
|
2008-03-16 21:26:05 +00:00
|
|
|
COL_TR_MSG,
|
2008-03-13 19:34:08 +00:00
|
|
|
N_COLUMNS
|
|
|
|
};
|
2006-08-20 22:45:29 +00:00
|
|
|
|
2008-03-13 19:34:08 +00:00
|
|
|
struct MsgData
|
2007-06-22 20:59:23 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
TrCore * core;
|
|
|
|
GtkTreeView * view;
|
|
|
|
GtkListStore * store;
|
|
|
|
GtkTreeModel * filter;
|
|
|
|
GtkTreeModel * sort;
|
|
|
|
int maxLevel;
|
|
|
|
gboolean isPaused;
|
|
|
|
guint refresh_tag;
|
2008-03-13 19:34:08 +00:00
|
|
|
};
|
2006-08-20 22:45:29 +00:00
|
|
|
|
2008-03-16 15:18:19 +00:00
|
|
|
static struct tr_msg_list * myTail = NULL;
|
|
|
|
static struct tr_msg_list * myHead = NULL;
|
2006-08-20 22:45:29 +00:00
|
|
|
|
2008-03-13 19:34:08 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2006-08-20 22:45:29 +00:00
|
|
|
|
2008-03-13 19:34:08 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
level_combo_changed_cb( GtkWidget * w,
|
|
|
|
gpointer gdata )
|
2008-03-13 19:34:08 +00:00
|
|
|
{
|
|
|
|
struct MsgData * data = gdata;
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if( gtk_combo_box_get_active_iter( GTK_COMBO_BOX( w ), &iter ) )
|
2008-03-13 19:34:08 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
int level = 0;
|
2008-03-13 19:34:08 +00:00
|
|
|
GtkTreeModel * m = gtk_combo_box_get_model( GTK_COMBO_BOX( w ) );
|
|
|
|
gtk_tree_model_get( m, &iter, 1, &level, -1 );
|
|
|
|
|
|
|
|
tr_setMessageLevel( level );
|
|
|
|
tr_core_set_pref_int( data->core, PREF_KEY_MSGLEVEL, level );
|
|
|
|
data->maxLevel = level;
|
|
|
|
gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( data->filter ) );
|
2007-06-22 20:59:23 +00:00
|
|
|
}
|
2006-08-20 22:45:29 +00:00
|
|
|
}
|
|
|
|
|
2006-09-18 01:26:49 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
doSave( GtkWindow * parent,
|
2008-03-13 19:34:08 +00:00
|
|
|
struct MsgData * data,
|
2008-09-23 19:11:04 +00:00
|
|
|
const char * filename )
|
2007-06-22 20:59:23 +00:00
|
|
|
{
|
2008-03-13 19:34:08 +00:00
|
|
|
FILE * fp = fopen( filename, "w+" );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-03-13 19:34:08 +00:00
|
|
|
if( !fp )
|
|
|
|
{
|
|
|
|
errmsg( parent,
|
2008-09-23 19:11:04 +00:00
|
|
|
_( "Couldn't save file \"%1$s\": %2$s" ),
|
|
|
|
filename, g_strerror( errno ) );
|
2008-03-13 19:34:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeIter iter;
|
2008-03-13 19:34:08 +00:00
|
|
|
GtkTreeModel * model = GTK_TREE_MODEL( data->sort );
|
|
|
|
if( gtk_tree_model_iter_children( model, &iter, NULL ) ) do
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
|
|
|
char * date;
|
|
|
|
const char * levelStr;
|
|
|
|
const struct tr_msg_list * node;
|
|
|
|
|
|
|
|
gtk_tree_model_get( model, &iter,
|
|
|
|
COL_TR_MSG, &node,
|
|
|
|
-1 );
|
|
|
|
date = gtr_localtime( node->when );
|
|
|
|
switch( node->level )
|
|
|
|
{
|
|
|
|
case TR_MSG_DBG:
|
|
|
|
levelStr = "debug"; break;
|
|
|
|
|
|
|
|
case TR_MSG_ERR:
|
|
|
|
levelStr = "error"; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
levelStr = " "; break;
|
|
|
|
}
|
|
|
|
fprintf( fp, "%s\t%s\t%s\t%s\n", date, levelStr,
|
|
|
|
( node->name ? node->name : "" ),
|
|
|
|
( node->message ? node->message : "" ) );
|
|
|
|
|
|
|
|
g_free( date );
|
2008-03-13 19:34:08 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
while( gtk_tree_model_iter_next( model, &iter ) );
|
2008-03-13 19:34:08 +00:00
|
|
|
|
|
|
|
fclose( fp );
|
2007-06-22 20:59:23 +00:00
|
|
|
}
|
2006-09-18 01:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onSaveDialogResponse( GtkWidget * d,
|
|
|
|
int response,
|
|
|
|
gpointer data )
|
2007-06-22 20:59:23 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
if( response == GTK_RESPONSE_ACCEPT )
|
|
|
|
{
|
|
|
|
char * filename =
|
|
|
|
gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( d ) );
|
|
|
|
doSave( GTK_WINDOW( d ), data, filename );
|
|
|
|
g_free( filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy( d );
|
2006-09-18 01:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onSaveRequest( GtkWidget * w,
|
|
|
|
gpointer data )
|
2007-06-22 20:59:23 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWindow * window = GTK_WINDOW( gtk_widget_get_toplevel( w ) );
|
|
|
|
GtkWidget * d = gtk_file_chooser_dialog_new( _(
|
|
|
|
"Save Log" ), window,
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SAVE,
|
|
|
|
GTK_STOCK_CANCEL,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_SAVE,
|
|
|
|
GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL );
|
|
|
|
|
|
|
|
gtk_dialog_set_alternative_button_order( GTK_DIALOG( d ),
|
|
|
|
GTK_RESPONSE_ACCEPT,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1 );
|
|
|
|
g_signal_connect( d, "response",
|
|
|
|
G_CALLBACK( onSaveDialogResponse ), data );
|
|
|
|
gtk_widget_show( d );
|
2007-06-22 20:59:23 +00:00
|
|
|
}
|
2006-09-18 01:26:49 +00:00
|
|
|
|
2007-06-22 20:59:23 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onClearRequest( GtkWidget * w UNUSED,
|
|
|
|
gpointer gdata )
|
2007-06-22 20:59:23 +00:00
|
|
|
{
|
2008-03-16 15:18:19 +00:00
|
|
|
struct MsgData * data = gdata;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-03-13 19:34:08 +00:00
|
|
|
gtk_list_store_clear( data->store );
|
2008-03-16 15:18:19 +00:00
|
|
|
tr_freeMessageList( myHead );
|
|
|
|
myHead = myTail = NULL;
|
2006-09-18 01:26:49 +00:00
|
|
|
}
|
|
|
|
|
2008-03-19 15:30:21 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onPauseToggled( GtkToggleToolButton * w,
|
|
|
|
gpointer gdata )
|
2008-03-19 15:30:21 +00:00
|
|
|
{
|
|
|
|
struct MsgData * data = gdata;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-03-19 15:30:21 +00:00
|
|
|
data->isPaused = gtk_toggle_tool_button_get_active( w );
|
|
|
|
}
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const char * label;
|
|
|
|
const char * pref;
|
|
|
|
int id;
|
2007-06-22 20:59:23 +00:00
|
|
|
} trLevels[] = {
|
2008-09-23 19:11:04 +00:00
|
|
|
{ N_( "Error" ), "error", TR_MSG_ERR },
|
|
|
|
{ N_( "Information" ), "info", TR_MSG_INF },
|
|
|
|
{ N_( "Debug" ), "debug", TR_MSG_DBG },
|
2007-06-22 20:59:23 +00:00
|
|
|
};
|
2006-08-20 22:45:29 +00:00
|
|
|
|
2008-03-13 19:34:08 +00:00
|
|
|
static const char*
|
|
|
|
getForegroundColor( int msgLevel )
|
|
|
|
{
|
|
|
|
const char * foreground;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
|
|
switch( msgLevel )
|
|
|
|
{
|
|
|
|
case TR_MSG_DBG:
|
|
|
|
foreground = "gray"; break;
|
|
|
|
|
|
|
|
case TR_MSG_INF:
|
|
|
|
foreground = "black"; break;
|
|
|
|
|
|
|
|
case TR_MSG_ERR:
|
|
|
|
foreground = "red"; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached( );
|
2008-03-13 19:34:08 +00:00
|
|
|
}
|
|
|
|
return foreground;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
renderText( GtkTreeViewColumn * column UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkCellRenderer * renderer,
|
|
|
|
GtkTreeModel * tree_model,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer gcol )
|
2008-03-13 19:34:08 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
const int col = GPOINTER_TO_INT( gcol );
|
|
|
|
char * str = NULL;
|
2008-03-16 21:26:05 +00:00
|
|
|
const struct tr_msg_list * node;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-03-16 21:26:05 +00:00
|
|
|
gtk_tree_model_get( tree_model, iter, col, &str, COL_TR_MSG, &node, -1 );
|
2008-03-13 19:34:08 +00:00
|
|
|
g_object_set( renderer, "text", str,
|
2008-09-23 19:11:04 +00:00
|
|
|
"foreground", getForegroundColor( node->level ),
|
|
|
|
"ellipsize", PANGO_ELLIPSIZE_END,
|
|
|
|
NULL );
|
2008-03-13 19:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
renderTime( GtkTreeViewColumn * column UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkCellRenderer * renderer,
|
|
|
|
GtkTreeModel * tree_model,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED )
|
2008-03-13 19:34:08 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
struct tm tm;
|
|
|
|
char buf[16];
|
2008-03-16 21:26:05 +00:00
|
|
|
const struct tr_msg_list * node;
|
2008-03-13 19:34:08 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_tree_model_get( tree_model, iter, COL_TR_MSG, &node, -1 );
|
2008-03-16 21:26:05 +00:00
|
|
|
tm = *localtime( &node->when );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_snprintf( buf, sizeof( buf ), "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
|
|
|
|
tm.tm_sec );
|
|
|
|
g_object_set ( renderer, "text", buf,
|
|
|
|
"foreground", getForegroundColor( node->level ),
|
|
|
|
NULL );
|
2008-03-13 19:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
appendColumn( GtkTreeView * view,
|
|
|
|
int col )
|
2008-03-13 19:34:08 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkCellRenderer * r;
|
2008-03-13 19:34:08 +00:00
|
|
|
GtkTreeViewColumn * c;
|
2008-09-23 19:11:04 +00:00
|
|
|
const char * title = NULL;
|
|
|
|
|
|
|
|
switch( col )
|
|
|
|
{
|
|
|
|
case COL_SEQUENCE:
|
|
|
|
title = _( "Time" ); break;
|
2008-03-13 19:34:08 +00:00
|
|
|
|
2008-03-18 19:14:21 +00:00
|
|
|
/* noun. column title for a list */
|
2008-09-23 19:11:04 +00:00
|
|
|
case COL_NAME:
|
|
|
|
title = _( "Name" ); break;
|
|
|
|
|
2008-03-18 19:14:21 +00:00
|
|
|
/* noun. column title for a list */
|
2008-09-23 19:11:04 +00:00
|
|
|
case COL_MESSAGE:
|
|
|
|
title = _( "Message" ); break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached( );
|
2008-03-13 19:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( col )
|
|
|
|
{
|
2008-03-18 19:14:21 +00:00
|
|
|
case COL_NAME:
|
2008-03-13 20:47:58 +00:00
|
|
|
r = gtk_cell_renderer_text_new( );
|
|
|
|
c = gtk_tree_view_column_new_with_attributes( title, r, NULL );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_tree_view_column_set_cell_data_func( c, r, renderText,
|
|
|
|
GINT_TO_POINTER(
|
|
|
|
col ), NULL );
|
2008-03-13 20:47:58 +00:00
|
|
|
gtk_tree_view_column_set_sizing( c, GTK_TREE_VIEW_COLUMN_FIXED );
|
|
|
|
gtk_tree_view_column_set_fixed_width( c, 200 );
|
|
|
|
gtk_tree_view_column_set_resizable( c, TRUE );
|
|
|
|
break;
|
|
|
|
|
2008-03-13 19:34:08 +00:00
|
|
|
case COL_MESSAGE:
|
|
|
|
r = gtk_cell_renderer_text_new( );
|
|
|
|
c = gtk_tree_view_column_new_with_attributes( title, r, NULL );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_tree_view_column_set_cell_data_func( c, r, renderText,
|
|
|
|
GINT_TO_POINTER(
|
|
|
|
col ), NULL );
|
2008-03-13 20:47:58 +00:00
|
|
|
gtk_tree_view_column_set_sizing( c, GTK_TREE_VIEW_COLUMN_FIXED );
|
|
|
|
gtk_tree_view_column_set_fixed_width( c, 500 );
|
|
|
|
gtk_tree_view_column_set_resizable( c, TRUE );
|
2008-03-13 19:34:08 +00:00
|
|
|
break;
|
|
|
|
|
2008-03-16 21:26:05 +00:00
|
|
|
case COL_SEQUENCE:
|
2008-03-13 19:34:08 +00:00
|
|
|
r = gtk_cell_renderer_text_new( );
|
|
|
|
c = gtk_tree_view_column_new_with_attributes( title, r, NULL );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_tree_view_column_set_cell_data_func( c, r, renderTime, NULL,
|
|
|
|
NULL );
|
2008-03-13 20:47:58 +00:00
|
|
|
gtk_tree_view_column_set_resizable( c, TRUE );
|
2008-03-13 19:34:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached( );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-03-16 21:26:05 +00:00
|
|
|
gtk_tree_view_column_set_sort_column_id( c, col );
|
2008-03-13 19:34:08 +00:00
|
|
|
gtk_tree_view_append_column( view, c );
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2008-09-23 19:11:04 +00:00
|
|
|
isRowVisible( GtkTreeModel * model,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer gdata )
|
2008-03-13 19:34:08 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
const struct MsgData * data = gdata;
|
2008-03-16 21:26:05 +00:00
|
|
|
const struct tr_msg_list * node;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-03-16 21:26:05 +00:00
|
|
|
gtk_tree_model_get( model, iter, COL_TR_MSG, &node, -1 );
|
|
|
|
return node->level <= data->maxLevel;
|
2008-03-13 19:34:08 +00:00
|
|
|
}
|
|
|
|
|
2008-03-16 15:18:19 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onWindowDestroyed( gpointer gdata,
|
|
|
|
GObject * deadWindow UNUSED )
|
2008-03-16 15:18:19 +00:00
|
|
|
{
|
|
|
|
struct MsgData * data = gdata;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-03-16 15:18:19 +00:00
|
|
|
g_source_remove( data->refresh_tag );
|
|
|
|
g_free( data );
|
|
|
|
}
|
|
|
|
|
|
|
|
static tr_msg_list *
|
2008-09-23 19:11:04 +00:00
|
|
|
addMessages( GtkListStore * store,
|
|
|
|
struct tr_msg_list * head )
|
2008-03-16 15:18:19 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
const char * default_name = g_get_application_name( );
|
2008-03-19 15:30:21 +00:00
|
|
|
static unsigned int sequence = 1;
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_msg_list * i;
|
2008-03-16 15:18:19 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
for( i = head; i; i = i->next )
|
2008-03-16 15:18:19 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter unused;
|
|
|
|
|
|
|
|
gtk_list_store_insert_with_values( store, &unused, 0,
|
2008-03-16 21:26:05 +00:00
|
|
|
COL_TR_MSG, i,
|
2008-09-23 19:11:04 +00:00
|
|
|
COL_NAME,
|
|
|
|
( i->name ? i->name :
|
|
|
|
default_name ),
|
2008-03-16 15:18:19 +00:00
|
|
|
COL_MESSAGE, i->message,
|
|
|
|
COL_SEQUENCE, sequence++,
|
|
|
|
-1 );
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
if( !i->next )
|
|
|
|
break;
|
2008-03-16 15:18:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return i; /* tail */
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
onRefresh( gpointer gdata )
|
|
|
|
{
|
2008-03-19 15:30:21 +00:00
|
|
|
struct MsgData * data = gdata;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-03-19 15:30:21 +00:00
|
|
|
if( !data->isPaused )
|
2008-03-16 15:18:19 +00:00
|
|
|
{
|
2008-03-19 15:30:21 +00:00
|
|
|
tr_msg_list * msgs = tr_getQueuedMessages( );
|
|
|
|
if( msgs )
|
|
|
|
{
|
|
|
|
/* add the new messages and append them to the end of
|
|
|
|
* our persistent list */
|
|
|
|
tr_msg_list * tail = addMessages( data->store, msgs );
|
|
|
|
if( myTail )
|
|
|
|
myTail->next = msgs;
|
|
|
|
else
|
|
|
|
myHead = msgs;
|
|
|
|
myTail = tail;
|
|
|
|
}
|
2008-03-16 15:18:19 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-03-19 15:30:21 +00:00
|
|
|
static GtkWidget*
|
|
|
|
debug_level_combo_new( void )
|
2007-06-22 20:59:23 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
unsigned int i;
|
|
|
|
int ii;
|
|
|
|
int curlevel;
|
|
|
|
GtkWidget * levels;
|
|
|
|
GtkListStore * store;
|
2008-03-16 15:18:19 +00:00
|
|
|
GtkCellRenderer * renderer;
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
store = gtk_list_store_new ( 2, G_TYPE_STRING, G_TYPE_INT );
|
2008-03-16 15:18:19 +00:00
|
|
|
|
|
|
|
curlevel = pref_int_get( PREF_KEY_MSGLEVEL );
|
2008-09-23 19:11:04 +00:00
|
|
|
for( i = ii = 0; i < G_N_ELEMENTS( trLevels ); ++i )
|
|
|
|
{
|
2008-03-16 15:18:19 +00:00
|
|
|
GtkTreeIter iter;
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_list_store_append ( store, &iter );
|
|
|
|
gtk_list_store_set ( store, &iter, 0, _( trLevels[i].label ),
|
|
|
|
1, trLevels[i].id,
|
|
|
|
-1 );
|
2008-03-16 15:18:19 +00:00
|
|
|
if( trLevels[i].id == curlevel )
|
|
|
|
ii = i;
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
levels = gtk_combo_box_new_with_model ( GTK_TREE_MODEL( store ) );
|
2008-03-16 15:18:19 +00:00
|
|
|
g_object_unref( G_OBJECT( store ) );
|
|
|
|
store = NULL;
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
renderer = gtk_cell_renderer_text_new ( );
|
|
|
|
gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( levels ), renderer, TRUE );
|
|
|
|
gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( levels ), renderer,
|
2008-03-16 15:18:19 +00:00
|
|
|
"text", 0,
|
|
|
|
NULL );
|
|
|
|
gtk_combo_box_set_active( GTK_COMBO_BOX( levels ), ii );
|
|
|
|
|
2008-03-19 15:30:21 +00:00
|
|
|
return levels;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** Public Functions
|
|
|
|
**/
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
msgwin_new( TrCore * core )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * win;
|
|
|
|
GtkWidget * vbox;
|
|
|
|
GtkWidget * toolbar;
|
|
|
|
GtkWidget * w;
|
|
|
|
GtkWidget * view;
|
|
|
|
GtkToolItem * item;
|
2008-03-19 15:30:21 +00:00
|
|
|
struct MsgData * data;
|
|
|
|
|
|
|
|
data = g_new0( struct MsgData, 1 );
|
|
|
|
data->core = core;
|
|
|
|
|
|
|
|
win = gtk_window_new( GTK_WINDOW_TOPLEVEL );
|
|
|
|
gtk_window_set_title( GTK_WINDOW( win ), _( "Message Log" ) );
|
2008-03-19 19:30:03 +00:00
|
|
|
gtk_window_set_default_size( GTK_WINDOW( win ), 560, 350 );
|
2008-03-19 15:30:21 +00:00
|
|
|
gtk_window_set_role( GTK_WINDOW( win ), "message-log" );
|
|
|
|
vbox = gtk_vbox_new( FALSE, 0 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** toolbar
|
|
|
|
**/
|
|
|
|
|
|
|
|
toolbar = gtk_toolbar_new( );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_toolbar_set_orientation( GTK_TOOLBAR(
|
|
|
|
toolbar ), GTK_ORIENTATION_HORIZONTAL );
|
2008-03-19 15:30:21 +00:00
|
|
|
gtk_toolbar_set_style( GTK_TOOLBAR( toolbar ), GTK_TOOLBAR_BOTH_HORIZ );
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
item = gtk_tool_button_new_from_stock( GTK_STOCK_SAVE );
|
|
|
|
g_object_set( G_OBJECT( item ), "is-important", TRUE, NULL );
|
|
|
|
g_signal_connect( item, "clicked", G_CALLBACK( onSaveRequest ), data );
|
|
|
|
gtk_toolbar_insert( GTK_TOOLBAR( toolbar ), item, -1 );
|
2008-03-19 15:30:21 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
item = gtk_tool_button_new_from_stock( GTK_STOCK_CLEAR );
|
|
|
|
g_object_set( G_OBJECT( item ), "is-important", TRUE, NULL );
|
|
|
|
g_signal_connect( item, "clicked", G_CALLBACK( onClearRequest ), data );
|
|
|
|
gtk_toolbar_insert( GTK_TOOLBAR( toolbar ), item, -1 );
|
2008-03-19 15:30:21 +00:00
|
|
|
|
|
|
|
item = gtk_separator_tool_item_new( );
|
|
|
|
gtk_toolbar_insert( GTK_TOOLBAR( toolbar ), item, -1 );
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
item = gtk_toggle_tool_button_new_from_stock( GTK_STOCK_MEDIA_PAUSE );
|
|
|
|
g_object_set( G_OBJECT( item ), "is-important", TRUE, NULL );
|
|
|
|
g_signal_connect( item, "toggled", G_CALLBACK( onPauseToggled ), data );
|
|
|
|
gtk_toolbar_insert( GTK_TOOLBAR( toolbar ), item, -1 );
|
2008-03-19 15:30:21 +00:00
|
|
|
|
|
|
|
item = gtk_separator_tool_item_new( );
|
|
|
|
gtk_toolbar_insert( GTK_TOOLBAR( toolbar ), item, -1 );
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
w = gtk_label_new( _( "Level" ) );
|
|
|
|
gtk_misc_set_padding( GTK_MISC( w ), GUI_PAD, 0 );
|
|
|
|
item = gtk_tool_item_new( );
|
|
|
|
gtk_container_add( GTK_CONTAINER( item ), w );
|
|
|
|
gtk_toolbar_insert( GTK_TOOLBAR( toolbar ), item, -1 );
|
2008-03-19 15:30:21 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
w = debug_level_combo_new( );
|
|
|
|
g_signal_connect( w, "changed", G_CALLBACK(
|
|
|
|
level_combo_changed_cb ), data );
|
|
|
|
item = gtk_tool_item_new( );
|
|
|
|
gtk_container_add( GTK_CONTAINER( item ), w );
|
|
|
|
gtk_toolbar_insert( GTK_TOOLBAR( toolbar ), item, -1 );
|
2008-03-16 15:18:19 +00:00
|
|
|
|
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), toolbar, FALSE, FALSE, 0 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** messages
|
|
|
|
**/
|
2008-03-13 19:34:08 +00:00
|
|
|
|
|
|
|
data->store = gtk_list_store_new( N_COLUMNS,
|
2008-03-19 15:30:21 +00:00
|
|
|
G_TYPE_UINT, /* sequence */
|
2008-03-16 21:26:05 +00:00
|
|
|
G_TYPE_POINTER, /* category */
|
|
|
|
G_TYPE_POINTER, /* message */
|
2008-09-23 19:11:04 +00:00
|
|
|
G_TYPE_POINTER ); /* struct tr_msg_list
|
|
|
|
*/
|
2008-03-16 21:26:05 +00:00
|
|
|
|
2008-03-16 15:18:19 +00:00
|
|
|
addMessages( data->store, myHead );
|
|
|
|
onRefresh( data ); /* much faster to populate *before* it has listeners */
|
2008-03-13 19:34:08 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
data->filter = gtk_tree_model_filter_new( GTK_TREE_MODEL(
|
|
|
|
data->store ), NULL );
|
2008-03-13 19:34:08 +00:00
|
|
|
data->sort = gtk_tree_model_sort_new_with_model( data->filter );
|
2008-03-16 21:41:27 +00:00
|
|
|
gtk_tree_sortable_set_sort_column_id( GTK_TREE_SORTABLE( data->sort ),
|
|
|
|
COL_SEQUENCE,
|
|
|
|
GTK_SORT_ASCENDING );
|
2008-03-13 19:34:08 +00:00
|
|
|
data->maxLevel = pref_int_get( PREF_KEY_MSGLEVEL );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_tree_model_filter_set_visible_func( GTK_TREE_MODEL_FILTER( data->
|
|
|
|
filter ),
|
2008-03-13 19:34:08 +00:00
|
|
|
isRowVisible, data, NULL );
|
|
|
|
|
|
|
|
|
2008-03-16 15:18:19 +00:00
|
|
|
view = gtk_tree_view_new_with_model( data->sort );
|
2008-09-27 18:01:31 +00:00
|
|
|
g_signal_connect( view, "button-release-event",
|
|
|
|
G_CALLBACK( on_tree_view_button_released ), NULL );
|
2008-03-16 15:18:19 +00:00
|
|
|
data->view = GTK_TREE_VIEW( view );
|
|
|
|
gtk_tree_view_set_rules_hint( data->view, TRUE );
|
2008-03-16 21:26:05 +00:00
|
|
|
appendColumn( data->view, COL_SEQUENCE );
|
2008-03-18 19:14:21 +00:00
|
|
|
appendColumn( data->view, COL_NAME );
|
2008-03-16 15:18:19 +00:00
|
|
|
appendColumn( data->view, COL_MESSAGE );
|
|
|
|
w = gtk_scrolled_window_new( NULL, NULL );
|
|
|
|
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( w ),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC );
|
|
|
|
gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( w ),
|
2008-09-23 19:11:04 +00:00
|
|
|
GTK_SHADOW_IN );
|
2008-03-16 15:18:19 +00:00
|
|
|
gtk_container_add( GTK_CONTAINER( w ), view );
|
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), w, TRUE, TRUE, 0 );
|
|
|
|
gtk_container_add( GTK_CONTAINER( win ), vbox );
|
|
|
|
|
2008-03-17 19:33:09 +00:00
|
|
|
data->refresh_tag = g_timeout_add( 1666, onRefresh, data );
|
2008-03-16 15:18:19 +00:00
|
|
|
g_object_weak_ref( G_OBJECT( win ), onWindowDestroyed, data );
|
|
|
|
|
|
|
|
gtk_widget_show_all( win );
|
|
|
|
return win;
|
2006-08-20 22:45:29 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|