Changeset 5009


Ignore:
Timestamp:
Feb 12, 2008, 6:53:31 PM (14 years ago)
Author:
charles
Message:

(gtk) update FileList? to allow it to switch which torrent's files are being shown.

Location:
trunk/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/file-list.c

    r5003 r5009  
    3131#include <libtransmission/transmission.h>
    3232
    33 #include "actions.h"
    34 #include "tr_torrent.h"
     33#include "file-list.h"
    3534#include "hig.h"
    36 #include "torrent-inspector.h"
    37 #include "util.h"
    38 
    39 #define UPDATE_INTERVAL_MSEC 2000
    40 
    41 #define STRIPROOT( path ) \
    42     ( g_path_is_absolute( (path) ) ? g_path_skip_root( (path) ) : (path) )
    4335
    4436enum
     
    5850{
    5951  TrTorrent * gtor;
     52  GtkWidget * top;
     53  GtkWidget * view;
    6054  GtkTreeModel * model; /* same object as store, but recast */
    6155  GtkTreeStore * store; /* same object as model, but recast */
     56  guint timeout_tag;
    6257}
    6358FileData;
     
    363358}
    364359
    365 GtkWidget *
    366 file_list_new( TrTorrent * gtor )
    367 {
    368     GtkWidget           * ret;
     360static void
     361freeData( gpointer gdata )
     362{
     363    FileData * data = gdata;
     364
     365    if( data->timeout_tag ) {
     366        g_source_remove( data->timeout_tag );
     367        data->timeout_tag = 0;
     368    }
     369
     370    g_free( data );
     371}
     372
     373static void
     374torrentDestroyed( gpointer gdata, GObject * deadTorrent UNUSED )
     375{
     376    FileData * data = gdata;
     377    file_list_set_torrent( data->top, NULL );
     378}
     379
     380static gboolean
     381refreshModel( gpointer gdata )
     382{
     383    FileData * data  = gdata;
     384
     385    g_assert( data != NULL );
     386
     387    if( data->gtor )
     388    {
     389        guint64 foo, bar;
     390        int fileCount;
     391        tr_torrent * tor;
     392        tr_file_stat * fileStats;
     393
     394        tor = tr_torrent_handle( data->gtor );
     395        fileCount = 0;
     396        fileStats = tr_torrentFiles( tor, &fileCount );
     397        updateprogress (data->model, data->store, NULL, fileStats, &foo, &bar);
     398        tr_torrentFilesFree( fileStats, fileCount );
     399    }
     400
     401    return TRUE;
     402}
     403
     404void
     405file_list_set_torrent( GtkWidget * w, TrTorrent * gtor )
     406{
     407    GtkTreeStore        * store;
    369408    FileData            * data;
    370     const tr_info       * inf;
    371     tr_torrent          * tor;
    372     GtkTreeStore        * store;
    373     int                   ii;
    374     GtkWidget           * view, * scroll;
    375     GtkCellRenderer     * rend;
    376     GtkCellRenderer     * priority_rend;
    377     GtkCellRenderer     * enabled_rend;
    378     GtkTreeViewColumn   * col;
    379     GtkTreeSelection    * sel;
    380     GtkTreeModel        * model;
    381 
     409
     410    data = g_object_get_data( G_OBJECT( w ), "file-data" );
     411
     412    /* instantiate the model */
    382413    store = gtk_tree_store_new ( N_FILE_COLS,
    383414                                 G_TYPE_STRING,    /* stock */
     
    389420                                 G_TYPE_STRING,    /* priority */
    390421                                 G_TYPE_BOOLEAN ); /* dl enabled */
    391 
    392     /* set up the model */
    393     tor = tr_torrent_handle( gtor );
    394     inf = tr_torrent_info( gtor );
    395     for( ii = 0; ii < inf->fileCount; ii++ )
    396     {
    397         parsepath( tor, store, NULL, STRIPROOT( inf->files[ii].name ),
    398                    ii, inf->files[ii].length );
    399     }
    400     getdirtotals( store, NULL );
     422    data->store = store;
     423    data->model = GTK_TREE_MODEL( store );
     424    data->gtor = gtor;
     425
     426    if( data->timeout_tag ) {
     427        g_source_remove( data->timeout_tag );
     428        data->timeout_tag = 0;
     429    }
     430
     431    /* populate the model */
     432    if( gtor )
     433    {
     434        int i;
     435        const tr_info * inf = tr_torrent_info( gtor );
     436        tr_torrent * tor = tr_torrent_handle( gtor );
     437        g_object_weak_ref( G_OBJECT( gtor ), torrentDestroyed, data );
     438
     439        for( i=0; inf && i<inf->fileCount; ++i )
     440        {
     441            const char * path = inf->files[i].name;
     442            const char * base = g_path_is_absolute( path ) ? g_path_skip_root( path ) : path;
     443            parsepath( tor, store, NULL, base, i, inf->files[i].length );
     444        }
     445
     446        getdirtotals( store, NULL );
     447
     448        data->timeout_tag = g_timeout_add( 1000, refreshModel, data );
     449    }
     450
     451    gtk_tree_view_set_model( GTK_TREE_VIEW( data->view ), GTK_TREE_MODEL( store ) );
     452    gtk_tree_view_expand_all( GTK_TREE_VIEW( data->view ) );
     453}
     454
     455GtkWidget *
     456file_list_new( TrTorrent * gtor )
     457{
     458    GtkWidget           * ret;
     459    FileData            * data;
     460    GtkWidget           * view, * scroll;
     461    GtkCellRenderer     * rend;
     462    GtkCellRenderer     * priority_rend;
     463    GtkCellRenderer     * enabled_rend;
     464    GtkTreeViewColumn   * col;
     465    GtkTreeSelection    * sel;
     466    GtkTreeModel        * model;
    401467
    402468    /* create the view */
    403     view = gtk_tree_view_new_with_model( GTK_TREE_MODEL( store ) );
     469    view = gtk_tree_view_new( );
    404470    gtk_container_set_border_width( GTK_CONTAINER( view ), GUI_PAD_BIG );
    405     g_object_set_data (G_OBJECT(view), "torrent-handle", tor );
    406471
    407472    /* add file column */
     
    476541    gtk_container_add( GTK_CONTAINER( scroll ), view );
    477542    gtk_widget_set_size_request (scroll, 0u, 200u);
    478     gtk_container_set_border_width (GTK_CONTAINER(scroll), GUI_PAD);
    479543
    480544    ret = scroll;
    481     data = g_new (FileData, 1);
    482     data->gtor = gtor;
    483     data->model = GTK_TREE_MODEL(store);
    484     data->store = store;
    485     g_object_set_data_full (G_OBJECT(ret), "file-data", data, g_free);
     545    data = g_new0( FileData, 1 );
     546    data->view = view;
     547    data->top = scroll;
    486548    g_signal_connect (G_OBJECT(priority_rend), "edited", G_CALLBACK(priority_changed_cb), data);
    487549    g_signal_connect(enabled_rend, "toggled", G_CALLBACK(enabled_toggled), data );
     550    g_object_set_data_full( G_OBJECT( ret ), "file-data", data, freeData );
     551    file_list_set_torrent( ret, gtor );
     552
    488553    return ret;
    489554}
    490 
    491 void
    492 file_list_refresh( GtkWidget * top )
    493 {
    494     guint64 foo, bar;
    495     int fileCount = 0;
    496     FileData * data = g_object_get_data (G_OBJECT(top), "file-data");
    497     tr_torrent * tor = tr_torrent_handle( data->gtor );
    498     tr_file_stat * fileStats = tr_torrentFiles( tor, &fileCount );
    499     updateprogress (data->model, data->store, NULL, fileStats, &foo, &bar);
    500     tr_torrentFilesFree( fileStats, fileCount );
    501 }
  • trunk/gtk/file-list.h

    r5003 r5009  
    3030
    3131/* create a new file list */
    32 GtkWidget * file_list_new( TrTorrent * gtor );
     32GtkWidget * file_list_new( TrTorrent * );
    3333
    34 /* updates the 'percent complete' column */
    35 void file_list_refresh( GtkWidget* );
     34void file_list_set_torrent( GtkWidget *, TrTorrent * );
    3635
    3736#endif
  • trunk/gtk/torrent-inspector.c

    r5007 r5009  
    10761076  refresh_activity  (g_object_get_data (G_OBJECT(data), "activity-top"));
    10771077  refresh_options   (g_object_get_data (G_OBJECT(data), "options-top"));
    1078   file_list_refresh (g_object_get_data (G_OBJECT(data), "files-top"));
    1079 
    10801078  return TRUE;
    10811079}
     
    11241122
    11251123  w = file_list_new( gtor );
     1124  gtk_container_set_border_width( GTK_CONTAINER( w ), GUI_PAD_BIG );
    11261125  g_object_set_data (G_OBJECT(d), "files-top", w);
    11271126  gtk_notebook_append_page (GTK_NOTEBOOK(n), w,
Note: See TracChangeset for help on using the changeset viewer.