Changeset 5262


Ignore:
Timestamp:
Mar 16, 2008, 3:18:19 PM (14 years ago)
Author:
charles
Message:

(gtk) speed up the population of the debug window.

Location:
trunk/gtk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r5251 r5262  
    6464
    6565/* interval in milliseconds to update the torrent list display */
    66 #define UPDATE_INTERVAL         1000
     66#define UPDATE_INTERVAL         1666
    6767
    6868/* interval in milliseconds to check for stopped torrents and update display */
     
    321321        g_signal_connect( mainwind, "window-state-event", G_CALLBACK(windowStateChanged), cbdata );
    322322
    323         /* set message level here before tr_init() */
    324         msgwin_loadpref( );
    325 
    326323        appsetup( mainwind, argfiles, cbdata, startpaused, startminimized );
    327324    }
     
    881878      tr_window_update( data->wind );
    882879
    883   /* update the message window */
    884   msgwin_update();
    885 
    886880  return TRUE;
    887881}
     
    11241118        if( !data->msgwin )
    11251119        {
    1126             GtkWidget * win = msgwin_create( data->core );
     1120            GtkWidget * win = msgwin_new( data->core );
    11271121            g_signal_connect( win, "destroy", G_CALLBACK( msgwinclosed ),
    11281122                             NULL );
  • trunk/gtk/msgwin.c

    r5252 r5262  
    1 /******************************************************************************
    2  * $Id$
     1/*
     2 * This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com>
    33 *
    4  * Copyright (c) 2006-2008 Transmission authors and contributors
    5  *
    6  * Permission is hereby granted, free of charge, to any person obtaining a
    7  * copy of this software and associated documentation files (the "Software"),
    8  * to deal in the Software without restriction, including without limitation
    9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    10  * and/or sell copies of the Software, and to permit persons to whom the
    11  * Software is furnished to do so, subject to the following conditions:
    12  *
    13  * The above copyright notice and this permission notice shall be included in
    14  * all copies or substantial portions of the Software.
    15  *
    16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    22  * DEALINGS IN THE SOFTWARE.
    23  *****************************************************************************/
     4 * This file is licensed by the GPL version 2.  Works owned by the
     5 * Transmission project are granted a special exemption to clause 2(b)
     6 * so that the bulk of its code can remain under the MIT license.
     7 * This exemption does not extend to derived works not owned by
     8 * the Transmission project.
     9 *
     10 * $Id:$
     11 */
    2412
    2513#include <errno.h>
     
    3523#include "hig.h"
    3624#include "msgwin.h"
     25#include "tr-core.h"
    3726#include "tr-prefs.h"
    3827#include "util.h"
     
    5847    GtkTreeModel * sort;
    5948    int maxLevel;
     49    guint refresh_tag;
    6050};
    6151
    62 static struct MsgData myData;
     52static struct tr_msg_list * myTail = NULL;
     53static struct tr_msg_list * myHead = NULL;
    6354
    6455/***
     
    165156
    166157static void
    167 onClearRequest( GtkWidget * w UNUSED, gpointer unused UNUSED )
    168 {
    169     struct MsgData * data = &myData;
     158onClearRequest( GtkWidget * w UNUSED, gpointer gdata )
     159{
     160    struct MsgData * data = gdata;
    170161    gtk_list_store_clear( data->store );
     162    tr_freeMessageList( myHead );
     163    myHead = myTail = NULL;
    171164}
    172165
     
    305298}
    306299
     300static void
     301onWindowDestroyed( gpointer gdata, GObject * deadWindow UNUSED )
     302{
     303    struct MsgData * data = gdata;
     304    g_source_remove( data->refresh_tag );
     305    g_free( data );
     306}
     307
     308static tr_msg_list *
     309addMessages( GtkListStore * store, struct tr_msg_list * head )
     310{
     311    const char * default_category = g_get_application_name( );
     312    static int sequence = 1;
     313    tr_msg_list * i;
     314
     315    for( i=head; i; i=i->next )
     316    {
     317        GtkTreeIter unused;
     318
     319        gtk_list_store_insert_with_values( store, &unused, 0,
     320                                           COL_LEVEL, (int)i->level,
     321                                           COL_LINE, i->line,
     322                                           COL_FILE, i->file,
     323                                           COL_TIME, (uint64_t)i->when,
     324                                           COL_CATEGORY, ( i->name ? i->name : default_category ),
     325                                           COL_MESSAGE, i->message,
     326                                           COL_SEQUENCE, sequence++,
     327                                           -1 );
     328
     329         if( !i->next )
     330             break;
     331    }
     332
     333    return i; /* tail */
     334}
     335
     336static gboolean
     337onRefresh( gpointer gdata )
     338{
     339    tr_msg_list * msgs = tr_getQueuedMessages( );
     340    if( msgs )
     341    {
     342        /* add the new messages and append them to the end of
     343         * our persistent list */
     344        struct MsgData * data = gdata;
     345        tr_msg_list * tail = addMessages( data->store, msgs );
     346        if( myTail )
     347            myTail->next = msgs;
     348        else
     349            myHead = msgs;
     350        myTail = tail;
     351    }
     352    return TRUE;
     353}
     354
    307355/**
    308356***  Public Functions
     
    310358
    311359GtkWidget *
    312 msgwin_create( TrCore * core )
    313 {
    314   unsigned int i;
    315   GtkListStore * store;
    316   GtkWidget * win;
    317   GtkWidget * vbox;
    318   GtkWidget * levels;
    319   GtkWidget * toolbar;
    320   GtkWidget * w;
    321   GtkWidget * view;
    322   GtkWidget * l;
    323   GtkCellRenderer * renderer;
    324   int ii, curlevel;
    325   struct MsgData * data;
    326 
    327   data = &myData;
    328   data->core = core;
    329 
    330   win = gtk_window_new( GTK_WINDOW_TOPLEVEL );
    331   gtk_window_set_title( GTK_WINDOW( win ), _( "Message Log" ) );
    332   gtk_window_set_default_size( GTK_WINDOW( win ), 600, 400 );
    333   gtk_window_set_role( GTK_WINDOW( win ), "message-log" );
    334   vbox = gtk_vbox_new( FALSE, 0 );
    335 
    336   /**
    337   ***  toolbar
    338   **/
    339 
    340   toolbar = gtk_toolbar_new( );
    341   gtk_toolbar_set_style( GTK_TOOLBAR( toolbar), GTK_TOOLBAR_BOTH_HORIZ );
    342 
    343   gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_SAVE,
    344                            NULL, NULL,
    345                            G_CALLBACK(onSaveRequest), data, -1);
    346 
    347   gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_CLEAR,
    348                            NULL, NULL,
    349                            G_CALLBACK(onClearRequest), data, -1);
    350 
    351   gtk_toolbar_insert_space(GTK_TOOLBAR(toolbar), -1);
    352 
    353 
    354   l = gtk_label_new( _( "Level" ) );
    355   gtk_misc_set_padding( GTK_MISC( l ), GUI_PAD, 0 );
    356   gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
    357                              GTK_TOOLBAR_CHILD_WIDGET, l,
    358                              NULL, _("Set the verbosity level"),
    359                              NULL, NULL, NULL, NULL);
    360 
    361   w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
    362   gtk_widget_set_size_request( w, GUI_PAD_SMALL, GUI_PAD_SMALL );
    363   gtk_toolbar_append_element( GTK_TOOLBAR(toolbar),
    364                               GTK_TOOLBAR_CHILD_WIDGET, w,
    365                               NULL, NULL, NULL, NULL, NULL, NULL);
    366 
    367   store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
    368 
    369   curlevel = pref_int_get( PREF_KEY_MSGLEVEL );
    370   for( i=ii=0; i<G_N_ELEMENTS(trLevels); ++i ) {
    371       GtkTreeIter iter;
    372       gtk_list_store_append (store, &iter);
    373       gtk_list_store_set (store, &iter, 0, _(trLevels[i].label),
    374                                         1, trLevels[i].id,
    375                                        -1);
    376       if( trLevels[i].id == curlevel )
    377           ii = i;
    378   }
    379   levels = gtk_combo_box_new_with_model (GTK_TREE_MODEL(store));
    380   g_object_unref( G_OBJECT( store ) );
    381   store = NULL;
    382 
    383   renderer = gtk_cell_renderer_text_new ();
    384   gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(levels), renderer, TRUE );
    385   gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT(levels), renderer,
    386                                   "text", 0,
    387                                   NULL );
    388   gtk_combo_box_set_active( GTK_COMBO_BOX( levels ), ii );
    389   g_signal_connect( levels, "changed",
    390                     G_CALLBACK(level_combo_changed_cb), data );
    391 
    392   gtk_toolbar_append_element( GTK_TOOLBAR( toolbar ),
    393                               GTK_TOOLBAR_CHILD_WIDGET, levels,
    394                               NULL, _("Set the verbosity level"),
    395                               NULL, NULL, NULL, NULL);
    396 
    397   gtk_box_pack_start( GTK_BOX( vbox ), toolbar, FALSE, FALSE, 0 );
    398 
    399   /**
    400   ***  messages
    401   **/
    402 
    403   view = gtk_tree_view_new_with_model( data->sort );
    404   data->view = GTK_TREE_VIEW( view );
    405   gtk_tree_view_set_rules_hint( data->view, TRUE );
    406   appendColumn( data->view, COL_TIME );
    407   appendColumn( data->view, COL_CATEGORY );
    408   appendColumn( data->view, COL_MESSAGE );
    409   w = gtk_scrolled_window_new( NULL, NULL );
    410   gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( w ),
    411                                   GTK_POLICY_AUTOMATIC,
    412                                   GTK_POLICY_AUTOMATIC );
    413   gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( w ),
    414                                        GTK_SHADOW_IN);
    415   gtk_container_add( GTK_CONTAINER( w ), view );
    416   gtk_box_pack_start( GTK_BOX( vbox ), w, TRUE, TRUE, 0 );
    417   gtk_container_add( GTK_CONTAINER( win ), vbox );
    418 
    419 
    420   msgwin_update( );
    421   gtk_widget_show_all( win );
    422   return win;
    423 }
    424 
    425 void
    426 msgwin_loadpref( void )
    427 {
    428     struct MsgData * data = &myData;
     360msgwin_new( TrCore * core )
     361{
     362    unsigned int i;
     363    GtkListStore * store;
     364    GtkWidget * win;
     365    GtkWidget * vbox;
     366    GtkWidget * levels;
     367    GtkWidget * toolbar;
     368    GtkWidget * w;
     369    GtkWidget * view;
     370    GtkWidget * l;
     371    GtkCellRenderer * renderer;
     372    int ii, curlevel;
     373    struct MsgData * data;
     374
     375    data = g_new0( struct MsgData, 1 );
     376    data->core = core;
     377
     378    win = gtk_window_new( GTK_WINDOW_TOPLEVEL );
     379    gtk_window_set_title( GTK_WINDOW( win ), _( "Message Log" ) );
     380    gtk_window_set_default_size( GTK_WINDOW( win ), 600, 400 );
     381    gtk_window_set_role( GTK_WINDOW( win ), "message-log" );
     382    vbox = gtk_vbox_new( FALSE, 0 );
     383
     384    /**
     385    ***  toolbar
     386    **/
     387
     388    toolbar = gtk_toolbar_new( );
     389
     390    gtk_toolbar_insert_stock( GTK_TOOLBAR(toolbar), GTK_STOCK_SAVE,
     391                              NULL, NULL,
     392                              G_CALLBACK(onSaveRequest), data, -1);
     393
     394    gtk_toolbar_insert_stock( GTK_TOOLBAR(toolbar), GTK_STOCK_CLEAR,
     395                              NULL, NULL,
     396                              G_CALLBACK(onClearRequest), data, -1);
     397
     398    gtk_toolbar_insert_space(GTK_TOOLBAR(toolbar), -1);
     399
     400
     401    l = gtk_label_new( _( "Level" ) );
     402    gtk_misc_set_padding( GTK_MISC( l ), GUI_PAD, 0 );
     403    gtk_toolbar_append_element( GTK_TOOLBAR(toolbar),
     404                                GTK_TOOLBAR_CHILD_WIDGET, l,
     405                                NULL, _("Set the verbosity level"),
     406                                NULL, NULL, NULL, NULL);
     407
     408    w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
     409    gtk_widget_set_size_request( w, GUI_PAD_SMALL, GUI_PAD_SMALL );
     410    gtk_toolbar_append_element( GTK_TOOLBAR(toolbar),
     411                                GTK_TOOLBAR_CHILD_WIDGET, w,
     412                                NULL, NULL, NULL, NULL, NULL, NULL);
     413
     414    store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
     415
     416    curlevel = pref_int_get( PREF_KEY_MSGLEVEL );
     417    for( i=ii=0; i<G_N_ELEMENTS(trLevels); ++i ) {
     418        GtkTreeIter iter;
     419        gtk_list_store_append (store, &iter);
     420        gtk_list_store_set (store, &iter, 0, _(trLevels[i].label),
     421                                          1, trLevels[i].id,
     422                                         -1);
     423        if( trLevels[i].id == curlevel )
     424            ii = i;
     425    }
     426    levels = gtk_combo_box_new_with_model (GTK_TREE_MODEL(store));
     427    g_object_unref( G_OBJECT( store ) );
     428    store = NULL;
     429
     430    renderer = gtk_cell_renderer_text_new ();
     431    gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(levels), renderer, TRUE );
     432    gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT(levels), renderer,
     433                                    "text", 0,
     434                                    NULL );
     435    gtk_combo_box_set_active( GTK_COMBO_BOX( levels ), ii );
     436    g_signal_connect( levels, "changed",
     437                      G_CALLBACK(level_combo_changed_cb), data );
     438
     439    gtk_toolbar_append_element( GTK_TOOLBAR( toolbar ),
     440                                GTK_TOOLBAR_CHILD_WIDGET, levels,
     441                                NULL, _("Set the verbosity level"),
     442                                NULL, NULL, NULL, NULL);
     443
     444    gtk_box_pack_start( GTK_BOX( vbox ), toolbar, FALSE, FALSE, 0 );
     445
     446    /**
     447    ***  messages
     448    **/
    429449
    430450    data->store = gtk_list_store_new( N_COLUMNS,
     
    436456                                      G_TYPE_STRING,    /* message */
    437457                                      G_TYPE_INT );     /* sequence */
     458    addMessages( data->store, myHead );
     459    onRefresh( data ); /* much faster to populate *before* it has listeners */
    438460
    439461    data->filter = gtk_tree_model_filter_new( GTK_TREE_MODEL( data->store ), NULL );
     
    442464    gtk_tree_model_filter_set_visible_func( GTK_TREE_MODEL_FILTER( data->filter ),
    443465                                            isRowVisible, data, NULL );
    444 }
    445 
    446 void
    447 msgwin_update( void )
    448 {
    449     tr_msg_list * i;
    450     tr_msg_list * msgs;
    451     struct MsgData * data = &myData;
    452     static int sequence = 1;
    453     const char * default_category = g_get_application_name( );
    454 
    455     msgs = tr_getQueuedMessages();
    456     for( i=msgs; i; i=i->next )
    457     {
    458         GtkTreeIter unused;
    459 
    460         gtk_list_store_insert_with_values( data->store, &unused, -1,
    461                                            COL_LEVEL, (int)i->level,
    462                                            COL_LINE, i->line,
    463                                            COL_FILE, i->file,
    464                                            COL_TIME, (uint64_t)i->when,
    465                                            COL_CATEGORY, ( i->name ? i->name : default_category ),
    466                                            COL_MESSAGE, i->message,
    467                                            COL_SEQUENCE, sequence++,
    468                                            -1 );
    469     }
    470     tr_freeMessageList( msgs );
    471 }
     466
     467
     468    view = gtk_tree_view_new_with_model( data->sort );
     469    data->view = GTK_TREE_VIEW( view );
     470    gtk_tree_view_set_rules_hint( data->view, TRUE );
     471    appendColumn( data->view, COL_TIME );
     472    appendColumn( data->view, COL_CATEGORY );
     473    appendColumn( data->view, COL_MESSAGE );
     474    w = gtk_scrolled_window_new( NULL, NULL );
     475    gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( w ),
     476                                    GTK_POLICY_AUTOMATIC,
     477                                    GTK_POLICY_AUTOMATIC );
     478    gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( w ),
     479                                         GTK_SHADOW_IN);
     480    gtk_container_add( GTK_CONTAINER( w ), view );
     481    gtk_box_pack_start( GTK_BOX( vbox ), w, TRUE, TRUE, 0 );
     482    gtk_container_add( GTK_CONTAINER( win ), vbox );
     483
     484    data->refresh_tag = g_timeout_add( 1000, onRefresh, data );
     485    g_object_weak_ref( G_OBJECT( win ), onWindowDestroyed, data );
     486
     487    gtk_widget_show_all( win );
     488    return win;
     489}
  • trunk/gtk/msgwin.h

    r5122 r5262  
    1 /******************************************************************************
    2  * $Id$
     1/*
     2 * This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com>
    33 *
    4  * Copyright (c) 2005-2008 Transmission authors and contributors
    5  *
    6  * Permission is hereby granted, free of charge, to any person obtaining a
    7  * copy of this software and associated documentation files (the "Software"),
    8  * to deal in the Software without restriction, including without limitation
    9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    10  * and/or sell copies of the Software, and to permit persons to whom the
    11  * Software is furnished to do so, subject to the following conditions:
    12  *
    13  * The above copyright notice and this permission notice shall be included in
    14  * all copies or substantial portions of the Software.
    15  *
    16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    22  * DEALINGS IN THE SOFTWARE.
    23  *****************************************************************************/
     4 * This file is licensed by the GPL version 2.  Works owned by the
     5 * Transmission project are granted a special exemption to clause 2(b)
     6 * so that the bulk of its code can remain under the MIT license.
     7 * This exemption does not extend to derived works not owned by
     8 * the Transmission project.
     9 *
     10 * $Id:$
     11 */
    2412
    2513#ifndef TG_MSGWIN_H
    2614#define TG_MSGWIN_H
    2715
    28 #include "tr-core.h"
     16struct TrCore;
    2917
    30 void
    31 msgwin_init( void );
     18GtkWidget * msgwin_new( struct TrCore * core );
    3219
    33 GtkWidget *
    34 msgwin_create( TrCore* core );
    35 
    36 void
    37 msgwin_update( void );
    38 
    39 void
    40 msgwin_loadpref( void );
    41 
    42 #endif /* TG_MSGWIN_H */
     20#endif
  • trunk/gtk/torrent-cell-renderer.c

    r5226 r5262  
    7878                  tr_strlratio( buf3, torStat->ratio, sizeof( buf3 ) ) );
    7979
    80     // add time when downloading
     80    /* add time when downloading */
    8181    if( torStat->status == TR_STATUS_DOWNLOAD )
    8282    {
  • trunk/gtk/tr-core.c

    r5242 r5262  
    555555    while( in < end ) {
    556556        const gunichar ch = g_utf8_get_char( in );
    557         if (!g_unichar_isalnum (ch)) // eat everything before the first alnum
     557        if (!g_unichar_isalnum (ch)) /* eat everything before the first alnum */
    558558            in += g_unichar_to_utf8( ch, NULL );
    559559        else
Note: See TracChangeset for help on using the changeset viewer.