Changeset 2109


Ignore:
Timestamp:
Jun 17, 2007, 2:59:57 AM (15 years ago)
Author:
charles
Message:

Get progress updates working in makemeta.c. More polishing on the gtk+ client's "create torrent" dialog

Location:
branches/file_selection
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/file_selection/gtk/hig.c

    r2097 r2109  
    167167  gtk_table_attach_defaults (GTK_TABLE(table), w, 0, 4, *row, *row+1);
    168168}
     169
     170void
     171hig_message_dialog_set_text (GtkMessageDialog * dialog,
     172                             const char       * primary,
     173                             const char       * secondary)
     174{
     175#if GTK_CHECK_VERSION(2,6,0)
     176  gtk_message_dialog_set_markup (dialog, primary);
     177  gtk_message_dialog_format_secondary_text (dialog, "%s", secondary);
     178#else
     179  char * pch = g_strdup_printf ("<b>%s</b>\n \n%s", primary, secondary);
     180  gtk_message_dialog_set_markup (dialog, pch);
     181  g_free (pch);
     182#endif
     183}
     184
  • branches/file_selection/gtk/hig.h

    r1998 r2109  
    9393                     int         * row);
    9494
     95void
     96hig_message_dialog_set_text (GtkMessageDialog * dialog,
     97                             const char       * primary,
     98                             const char       * secondary);
     99
     100
    95101/**
    96102***
  • branches/file_selection/gtk/make-meta-ui.c

    r2107 r2109  
    4040    GtkWidget * announce_entry;
    4141    GtkWidget * comment_entry;
     42    GtkWidget * progressbar;
    4243    GtkWidget * private_check;
     44    GtkWidget * dialog;
     45    GtkWidget * progress_dialog;
    4346    tr_metainfo_builder_t * builder;
    4447    tr_handle_t * handle;
     
    5659refresh_cb ( gpointer user_data )
    5760{
     61    double fraction;
    5862    MakeMetaUI * ui = (MakeMetaUI *) user_data;
    5963
    60     g_message ("refresh");
     64    fraction = (double)ui->builder->pieceIndex / ui->builder->pieceCount;
     65    gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( ui->progressbar ), fraction );
     66
     67    if( ui->builder->isDone )
     68    {
     69        GtkWidget * w;
     70
     71        if( ui->builder->failed )
     72        {
     73            w = gtk_message_dialog_new (GTK_WINDOW(ui->progress_dialog),
     74                                        GTK_DIALOG_DESTROY_WITH_PARENT,
     75                                        GTK_MESSAGE_ERROR,
     76                                        GTK_BUTTONS_CLOSE,
     77                                        _("Torrent creation failed.")); /* FIXME: tell why */
     78            gtk_dialog_run( GTK_DIALOG( w ) );
     79            gtk_widget_destroy( ui->progress_dialog );
     80        }
     81        else
     82        {
     83            w = gtk_message_dialog_new_with_markup (
     84                GTK_WINDOW(ui->progress_dialog),
     85                GTK_DIALOG_DESTROY_WITH_PARENT,
     86                GTK_MESSAGE_INFO,
     87                GTK_BUTTONS_CLOSE,
     88                NULL);
     89            hig_message_dialog_set_text (GTK_MESSAGE_DIALOG(w),
     90                _("<b>Torrent Created!</b>"),
     91                ui->builder->outputFile);
     92            gtk_dialog_run( GTK_DIALOG( w ) );
     93            gtk_widget_destroy( ui->dialog );
     94        }
     95    }
    6196
    6297    return !ui->builder->isDone;
     
    67102{
    68103    MakeMetaUI * ui = (MakeMetaUI*) user_data;
    69     GtkWidget *w, *l, *p;
     104    GtkWidget *w, *p, *fr;
    70105    char *tmp, *name;
    71106
     
    78113    w = gtk_dialog_new_with_buttons( _("Making Torrent..."),
    79114                                     GTK_WINDOW(d),
    80                                      GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
     115                                     GTK_DIALOG_DESTROY_WITH_PARENT,
    81116                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    82117                                     NULL );
    83118    g_signal_connect( w, "response", G_CALLBACK(cancel_cb), ui );
     119    ui->progress_dialog = w;
     120
    84121
    85122    tmp = g_path_get_basename (ui->builder->top);
    86     name = g_strdup_printf ( "%s.torrent", tmp );
    87     l = gtk_label_new( name );
    88     gtk_box_pack_start_defaults ( GTK_BOX(GTK_DIALOG(w)->vbox), l );
    89     p = gtk_progress_bar_new ();
    90     gtk_box_pack_start_defaults ( GTK_BOX(GTK_DIALOG(w)->vbox), p );
     123    name = g_strdup_printf( "%s.torrent", tmp );
     124    p = ui->progressbar = gtk_progress_bar_new ();
     125    gtk_progress_bar_set_text( GTK_PROGRESS_BAR(p), name );
     126    fr = gtk_frame_new (NULL);
     127    gtk_frame_set_shadow_type (GTK_FRAME(fr), GTK_SHADOW_NONE);
     128    gtk_container_set_border_width( GTK_CONTAINER(fr), 20 );
     129    gtk_container_add (GTK_CONTAINER(fr), p);
     130    gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(w)->vbox), fr );
    91131    gtk_widget_show_all ( w );
    92132    g_free( name );
     
    99139                     gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ui->private_check ) ) );
    100140
    101     g_timeout_add ( 1000, refresh_cb, ui );
     141    g_timeout_add ( 200, refresh_cb, ui );
    102142}
    103143
     
    168208    g_signal_connect( d, "response", G_CALLBACK(response_cb), ui );
    169209    g_object_set_data_full( G_OBJECT(d), "ui", ui, g_free );
     210    ui->dialog = d;
    170211
    171212    t = hig_workarea_create ();
  • branches/file_selection/libtransmission/inout.c

    r2046 r2109  
    191191****/
    192192
    193 int
     193static int
    194194tr_ioRecalculateHash ( tr_torrent_t  * tor,
    195195                       int             pieceIndex,
  • branches/file_selection/libtransmission/inout.h

    r2046 r2109  
    6161void      tr_ioClose       ( tr_io_t * );
    6262
    63 /**
    64  * Recalculate the hash value straight from disk.
    65  * If your piece is incomplete, you'll get a meaningless hash back.
    66  */
    67 int tr_ioRecalculateHash( tr_torrent_t  * tor,
    68                           int             pieceIndex,
    69                           uint8_t       * setme_buf );
    70 
    71 
    7263#endif
  • branches/file_selection/libtransmission/makemeta.c

    r2107 r2109  
    181181   
    182182    ret->pieceSize = bestPieceSize( ret->totalSize );
    183     ret->pieceCount = MAX( 1, ret->totalSize / ret->pieceSize );
     183    ret->pieceCount = ret->totalSize / ret->pieceSize;
    184184    if( ret->totalSize % ret->pieceSize )
    185185        ++ret->pieceCount;
     
    207207
    208208static uint8_t*
    209 getHashInfo ( const tr_metainfo_builder_t  * builder,
    210               int                        * setmeCount )
    211 {
    212     size_t i;
    213     tr_torrent_t t;
    214     uint8_t *ret, *walk;
    215     const size_t topLen = strlen(builder->top) + 1; /* +1 for '/' */
    216 
    217     /* build a mock tr_torrent_t that we can feed to tr_ioRecalculateHash() */ 
    218     memset( &t, 0, sizeof( tr_torrent_t ) );
    219     tr_lockInit ( &t.lock );
    220     t.destination = (char*) builder->top;
    221     t.info.fileCount = builder->fileCount;
    222     t.info.files = calloc( t.info.fileCount, sizeof( tr_file_t ) );
    223     t.info.totalSize = builder->totalSize;
    224     t.info.pieceSize = builder->pieceSize;
    225     t.info.pieceCount = builder->pieceCount;
    226     for( i=0; i<builder->fileCount; ++i ) {
    227         tr_file_t * file = &t.info.files[i];
    228         file->length = builder->fileLengths[i];
    229         strlcpy( file->name, builder->files[i]+topLen, sizeof(file->name) );
    230     }
    231     t.info.pieces = calloc( t.info.pieceCount, sizeof( tr_piece_t ) );
    232     tr_torrentInitFilePieces( &t );
    233     ret = (uint8_t*) malloc ( SHA_DIGEST_LENGTH * t.info.pieceCount );
    234     walk = ret;
    235 
    236     /* FIXME: check the abort flag */
    237     for( i=0; i<(size_t)t.info.pieceCount; ++i ) {
    238         tr_ioRecalculateHash( &t, i, walk );
     209getHashInfo ( tr_metainfo_builder_t * b )
     210{
     211    size_t off = 0;
     212    size_t fileIndex = 0;
     213    uint8_t *ret = (uint8_t*) malloc ( SHA_DIGEST_LENGTH * b->pieceCount );
     214    uint8_t *walk = ret;
     215    uint8_t *buf = malloc( b->pieceSize );
     216    size_t totalRemain;
     217
     218    b->pieceIndex = 0;
     219    totalRemain = b->totalSize;
     220    while ( totalRemain )
     221    {
     222        uint8_t *bufptr = buf;
     223        const size_t thisPieceSize = MIN( b->pieceSize, totalRemain );
     224        size_t pieceRemain = thisPieceSize;
     225
     226        assert( b->pieceIndex < b->pieceCount );
     227
     228        while( pieceRemain )
     229        {
     230            FILE * fp = fopen( b->files[fileIndex], "rb" );
     231            const size_t n_this_pass = MIN( (b->fileLengths[fileIndex] - off), pieceRemain );
     232            if( off )
     233                fseek( fp, off, SEEK_SET );
     234            fread( bufptr, 1, n_this_pass, fp );
     235            bufptr += n_this_pass;
     236            off += n_this_pass;
     237            pieceRemain -= n_this_pass;
     238            fclose( fp );
     239
     240            if( off == b->fileLengths[fileIndex] ) {
     241                off = 0;
     242                ++fileIndex;
     243            }
     244        }
     245
     246        assert( bufptr-buf == (int)thisPieceSize );
     247        assert( pieceRemain == 0 );
     248        SHA1( buf, thisPieceSize, walk );
    239249        walk += SHA_DIGEST_LENGTH;
    240     }
    241     assert( walk-ret == SHA_DIGEST_LENGTH*t.info.pieceCount );
    242 
    243     *setmeCount = t.info.pieceCount;
    244     tr_lockClose ( &t.lock );
    245     free( t.info.pieces );
    246     free( t.info.files );
     250
     251        if( b->abortFlag ) {
     252            b->failed = 1;
     253            break;
     254        }
     255
     256        totalRemain -= thisPieceSize;
     257        ++b->pieceIndex;
     258    }
     259    assert( walk-ret == (int)(SHA_DIGEST_LENGTH*b->pieceCount) );
     260    assert( totalRemain == 0 );
     261
     262    free( buf );
    247263    return ret;
    248264}
     
    278294        memcpy( buf, prev, pch-prev );
    279295        buf[pch-prev] = '\0';
    280         fprintf ( stderr, "adding [%s] to the list of paths\n", buf );
     296        /*fprintf ( stderr, "adding [%s] to the list of paths\n", buf );*/
    281297
    282298        sub = tr_bencListAdd( uninitialized_path );
     
    311327
    312328static void
    313 makeInfoDict ( benc_val_t                 * dict,
    314                const tr_metainfo_builder_t  * builder )
     329makeInfoDict ( benc_val_t             * dict,
     330               tr_metainfo_builder_t  * builder )
    315331{
    316332    uint8_t * pch;
    317     int pieceCount = 0;
    318333    benc_val_t * val;
    319334    char base[MAX_PATH_LENGTH];
     
    328343    tr_bencInitInt( val, builder->pieceSize );
    329344
    330     pch = getHashInfo( builder, &pieceCount );
     345    pch = getHashInfo( builder );
    331346    val = tr_bencDictAdd( dict, "pieces" );
    332     tr_bencInitStr( val, pch, SHA_DIGEST_LENGTH * pieceCount, 0 );
     347    tr_bencInitStr( val, pch, SHA_DIGEST_LENGTH * builder->pieceCount, 0 );
    333348
    334349    if ( builder->isSingleFile )
     
    352367    int n = 5;
    353368    benc_val_t top, *val;
     369fprintf( stderr, "builder %p in realMakeMetaInfo\n", builder );
    354370
    355371    tr_bencInit ( &top, TYPE_DICT );
     
    378394        tr_bencDictReserve( val, 666 );
    379395        makeInfoDict( val, builder );
    380 
    381     /* debugging... */
    382     tr_bencPrint( &top );
    383396
    384397    /* save the file */
     
    445458          break;
    446459
     460fprintf( stderr, "worker thread got builder %p\n", builder);
    447461        tr_realMakeMetaInfo ( builder );
    448462    }
    449463
     464fprintf( stderr, "worker thread exiting\n" );
    450465    workerIsRunning = 0;
    451466}
     
    470485    }
    471486
     487fprintf( stderr, "enqueuing a builder %p\n", builder);
    472488    /* enqueue the builder */
    473489    lock = getQueueLock ( builder->handle );
     
    477493    if( !workerIsRunning ) {
    478494        workerIsRunning = 1;
     495fprintf( stderr, "making new worker thread\n" );
    479496        tr_threadCreate( &workerThread, workerFunc, builder->handle, "makeMeta" );
    480497    }
Note: See TracChangeset for help on using the changeset viewer.