Changeset 2316


Ignore:
Timestamp:
Jul 10, 2007, 3:12:46 AM (16 years ago)
Author:
charles
Message:

splitting dnd and priorities apart, and moving the file storage for those fields into fastresume

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/actions.c

    r2304 r2316  
    4040  { "priority-high", NULL, N_("_High"), NULL, NULL, TR_PRI_HIGH },
    4141  { "priority-normal", NULL, N_("_Normal"), NULL, NULL, TR_PRI_NORMAL },
    42   { "priority-low", NULL, N_("_Low"), NULL, NULL, TR_PRI_LOW },
    43   { "priority-dnd", NULL, N_("_Don't Get"), NULL, NULL, TR_PRI_DND  }
     42  { "priority-low", NULL, N_("_Low"), NULL, NULL, TR_PRI_LOW }
    4443};
    4544
  • trunk/gtk/torrent-inspector.c

    r2267 r2316  
    943943  FC_SIZE,
    944944  FC_PRIORITY,
     945  FC_ENABLED,
    945946  N_FILE_COLS
    946947};
     
    962963        case TR_PRI_NORMAL: return _("Normal");
    963964        case TR_PRI_LOW:    return _("Low");
    964         case TR_PRI_DND:    return _("Don't Get");
    965965        default:            return "BUG!";
    966966    }
     
    972972    if( !strcmp( str, _( "High" ) ) ) return TR_PRI_HIGH;
    973973    if( !strcmp( str, _( "Low" ) ) ) return TR_PRI_LOW;
    974     if( !strcmp( str, _( "Don't Get" ) ) ) return TR_PRI_DND;;
    975974    return TR_PRI_NORMAL;
    976975}
     
    989988    const char   * stock;
    990989    int            priority = 0;
     990    gboolean       enabled = TRUE;
    991991
    992992    model  = GTK_TREE_MODEL( store );
     
    10261026    }
    10271027
    1028     if (index != -1)
     1028    if (index != -1) {
    10291029        priority = tr_torrentGetFilePriority( tor, index );
     1030        enabled  = tr_torrentGetFileDL( tor, index );
     1031    }
    10301032
    10311033    escaped = g_markup_escape_text (file, -1);
    1032     gtk_tree_store_set( store, &iter, FC_INDEX, index, FC_LABEL, escaped,
    1033                         FC_KEY, mykey, FC_STOCK, stock,
    1034                         FC_PRIORITY, priorityToString(priority),
    1035                         FC_SIZE, size, -1 );
     1034    gtk_tree_store_set( store, &iter, FC_INDEX, index,
     1035                                      FC_LABEL, escaped,
     1036                                      FC_KEY, mykey,
     1037                                      FC_STOCK, stock,
     1038                                      FC_PRIORITY, priorityToString(priority),
     1039                                      FC_ENABLED, enabled,
     1040                                      FC_SIZE, size, -1 );
    10361041  done:
    10371042    g_free( escaped );
     
    11411146  gtk_list_store_append (store, &iter);
    11421147  gtk_list_store_set (store, &iter, 0, _("Low"), 1, TR_PRI_LOW, -1);
    1143   gtk_list_store_append (store, &iter);
    1144   gtk_list_store_set (store, &iter, 0, _("Don't Get"), 1, TR_PRI_DND, -1);
    11451148  return GTK_TREE_MODEL (store);
    11461149}
     
    11561159    action_sensitize ( "priority-normal", has_selection );
    11571160    action_sensitize ( "priority-low", has_selection );
    1158     action_sensitize ( "priority-dnd", has_selection );
    11591161
    11601162    if( has_selection )
     
    11671169            case TR_PRI_HIGH:   key = "priority-high";   break;
    11681170            case TR_PRI_LOW:    key = "priority-low";    break;
    1169             case TR_PRI_DND:    key = "priority-dnd";    break;
    11701171            default:            key = "priority-normal"; break;
    11711172        }
     
    11731174        g_free( pch );
    11741175    }
     1176}
     1177
     1178static void
     1179set_files_enabled( GtkTreeStore     * store,
     1180                   GtkTreeIter      * iter,
     1181                   tr_torrent_t     * tor,
     1182                   gboolean           enabled )
     1183{
     1184    int index;
     1185    GtkTreeIter child;
     1186
     1187    gtk_tree_model_get( GTK_TREE_MODEL(store), iter, FC_INDEX, &index, -1  );
     1188    if (index >= 0)
     1189      tr_torrentSetFileDL( tor, index, !enabled );
     1190    gtk_tree_store_set( store, iter, FC_ENABLED, enabled, -1 );
     1191
     1192    if( gtk_tree_model_iter_children( GTK_TREE_MODEL(store), &child, iter ) ) do
     1193      set_files_enabled( store, &child, tor, enabled );
     1194    while( gtk_tree_model_iter_next( GTK_TREE_MODEL(store), &child ) );
    11751195}
    11761196
     
    12521272}
    12531273
     1274static void
     1275enabled_toggled (GtkCellRendererToggle  * cell UNUSED,
     1276                 const gchar            * path_str,
     1277                 gpointer                 data_gpointer)
     1278{
     1279  FileData * data = (FileData*) data_gpointer;
     1280  GtkTreePath * path = gtk_tree_path_new_from_string( path_str );
     1281  GtkTreeModel * model = data->model;
     1282  GtkTreeIter iter;
     1283  gboolean enabled;
     1284
     1285  gtk_tree_model_get_iter( model, &iter, path );
     1286  gtk_tree_model_get( model, &iter, FC_ENABLED, &enabled, -1 );
     1287  enabled = !enabled;
     1288  set_files_enabled( GTK_TREE_STORE(model),
     1289                     &iter,
     1290                     tr_torrent_handle( data->gtor ),
     1291                     enabled );
     1292
     1293  gtk_tree_path_free( path );
     1294}
     1295
    12541296GtkWidget *
    12551297file_page_new ( TrTorrent * gtor )
     
    12631305    GtkWidget           * view, * scroll;
    12641306    GtkCellRenderer     * rend;
     1307    GtkCellRenderer     * priority_rend;
    12651308    GtkTreeViewColumn   * col;
    12661309    GtkTreeSelection    * sel;
     
    12681311
    12691312    store = gtk_tree_store_new ( N_FILE_COLS,
    1270                                  G_TYPE_STRING,  /* stock */
    1271                                  G_TYPE_STRING,  /* label */
    1272                                  G_TYPE_INT,     /* prog [0..100] */
    1273                                  G_TYPE_STRING,  /* key */
    1274                                  G_TYPE_INT,     /* index */
    1275                                  G_TYPE_UINT64,  /* size */
    1276                                  G_TYPE_STRING); /* priority */
     1313                                 G_TYPE_STRING,    /* stock */
     1314                                 G_TYPE_STRING,    /* label */
     1315                                 G_TYPE_INT,       /* prog [0..100] */
     1316                                 G_TYPE_STRING,    /* key */
     1317                                 G_TYPE_INT,       /* index */
     1318                                 G_TYPE_UINT64,    /* size */
     1319                                 G_TYPE_STRING,    /* priority */
     1320                                 G_TYPE_BOOLEAN ); /* dl enabled */
    12771321
    12781322    /* set up the model */
     
    13231367    fileSelectionChangedCB( sel, NULL );
    13241368
    1325 
    13261369    /* add priority column */
    13271370    model = priority_model_new ();
     
    13291372    gtk_tree_view_column_set_sort_column_id( col, FC_PRIORITY );
    13301373    gtk_tree_view_column_set_title (col, _("Priority"));
    1331     rend = gtk_cell_renderer_combo_new ();
     1374    rend = priority_rend = gtk_cell_renderer_combo_new ();
    13321375    gtk_tree_view_column_pack_start (col, rend, TRUE);
    13331376    g_object_set (G_OBJECT(rend), "model", model,
     
    13401383    gtk_tree_view_append_column( GTK_TREE_VIEW( view ), col );
    13411384
     1385    /* download enabled column */
     1386    col = gtk_tree_view_column_new ();
     1387    gtk_tree_view_column_set_sort_column_id( col, FC_ENABLED );
     1388    rend = gtk_cell_renderer_toggle_new  ();
     1389    col = gtk_tree_view_column_new_with_attributes (_("Enabled"),
     1390                                                    rend,
     1391                                                    "active", FC_ENABLED,
     1392                                                    NULL);
     1393    gtk_tree_view_append_column( GTK_TREE_VIEW( view ), col );
     1394
    13421395    /* create the scrolled window and stick the view in it */
    13431396    scroll = gtk_scrolled_window_new( NULL, NULL );
     
    13571410    data->selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
    13581411    g_object_set_data_full (G_OBJECT(ret), "file-data", data, g_free);
    1359     g_signal_connect (G_OBJECT(rend), "edited", G_CALLBACK(priority_changed_cb), data);
     1412    g_signal_connect (G_OBJECT(priority_rend), "edited", G_CALLBACK(priority_changed_cb), data);
     1413    g_signal_connect( rend, "toggled", G_CALLBACK(enabled_toggled), data );
    13601414    return ret;
    13611415}
  • trunk/gtk/ui.h

    r2149 r2316  
    5959"      <menuitem action='priority-normal'/>\n"
    6060"      <menuitem action='priority-low'/>\n"
    61 "      <menuitem action='priority-dnd'/>\n"
    6261"    </menu>\n"
    6362"  </popup>\n"
  • trunk/libtransmission/completion.c

    r2308 r2316  
    296296        if( tr_cpPieceIsComplete( cp, i ) )
    297297            continue;
    298         if( info->pieces[i].priority != TR_PRI_DND)
     298        if( !info->pieces[i].dnd )
    299299            return TR_CP_INCOMPLETE;
    300300        ret = TR_CP_DONE;
     
    344344
    345345    for( i=0; i<info->pieceCount; ++i )
    346         if( !tr_cpPieceIsComplete( cp, i ) && info->pieces[i].priority != TR_PRI_DND )
     346        if( !tr_cpPieceIsComplete( cp, i ) && !info->pieces[i].dnd )
    347347            b += ( tr_cpCountBlocks( cp, i ) - cp->completeBlocks[ i ] );
    348348
     
    350350
    351351    i = tor->blockCount - 1;
    352     if( !tr_cpBlockIsComplete( cp, tor->blockCount-1 )
    353                   && info->pieces[info->pieceCount-1].priority != TR_PRI_DND )
     352    if( !tr_cpBlockIsComplete( cp, tor->blockCount-1 ) && !info->pieces[info->pieceCount-1].dnd )
    354353        b -= (tor->blockSize - (tor->info.totalSize % tor->blockSize));
    355354
  • trunk/libtransmission/fastresume.c

    r2315 r2316  
    6161 */
    6262#define FR_ID_PROGRESS          0x05
     63/* dnd and priority
     64 * char * number of files: l,n,h for low, normal, high priority
     65 * uint8_t * number of files: nonzero if dnd flag is set
     66 */
     67#define FR_ID_PRIORITY          0x06
    6368
    6469/* macros for the length of various pieces of the progress data */
     
    168173    }
    169174
     175
     176    /* Write the priorities and DND flags */
     177    if( TRUE )
     178    {
     179        int i;
     180        const int n = tor->info.fileCount;
     181        char * buf = tr_new0( char, n*2 );
     182        char * walk = buf;
     183
     184        /* priorities */
     185        for( i=0; i<n; ++i ) {
     186            char ch;
     187            const int priority = tor->info.files[i].priority;
     188            switch( priority ) {
     189               case TR_PRI_LOW:   ch = 'l'; break; /* low */
     190               case TR_PRI_HIGH:  ch = 'h'; break; /* high */
     191               default:           ch = 'n'; break; /* normal */
     192            };
     193            *walk++ = ch;
     194        }
     195
     196        /* dnd flags */
     197        for( i=0; i<n; ++i )
     198            *walk++ = tor->info.files[i].dnd ? '\1' : '\0';
     199
     200        /* write it */
     201        assert( walk - buf == 2*n );
     202        fastResumeWriteData( FR_ID_PRIORITY, buf, 1, walk-buf, file );
     203
     204        /* cleanup */
     205        tr_free( buf );
     206    }
     207
     208
    170209    /* Write download and upload totals */
    171210    total = tor->downloadedCur + tor->downloadedPrev;
     
    189228
    190229    tr_dbg( "Resume file '%s' written", path );
     230}
     231
     232static int
     233fastResumeLoadPriorities( tr_torrent_t * tor,
     234                          FILE         * file )
     235{
     236    const size_t n = tor->info.fileCount;
     237    const size_t len = 2 * n;
     238    char * buf = tr_new0( char, len );
     239    char * walk = buf;
     240    size_t i;
     241
     242    if( len != fread( buf, 1, len, file ) ) {
     243        tr_inf( "Couldn't read from resume file" );
     244        free( buf );
     245        return TR_ERROR_IO_OTHER;
     246    }
     247
     248    /* set file priorities */
     249    for( i=0; i<n; ++i ) {
     250       tr_priority_t priority;
     251       const char ch = *walk++;
     252       switch( ch ) {
     253           case 'l': priority = TR_PRI_LOW; break;
     254           case 'h': priority = TR_PRI_HIGH; break;
     255           default:  priority = TR_PRI_NORMAL; break;
     256       }
     257       tor->info.files[i].priority = priority;
     258    }
     259
     260    /* set the dnd flags */
     261    for( i=0; i<n; ++i )
     262        tor->info.files[i].dnd = *walk++ != 0;
     263
     264    free( buf );
     265    return TR_OK;
    191266}
    192267
     
    326401                if( (uint32_t)FR_PROGRESS_LEN( tor ) == len )
    327402                {
    328                     if( fastResumeLoadProgress( tor, uncheckedPieces, file ) )
     403                    ret = fastResumeLoadProgress( tor, uncheckedPieces, file );
     404
     405                    if( ret && ( feof(file) || ferror(file) ) )
    329406                    {
    330                         if( feof( file ) || ferror( file ) )
    331                         {
    332                             fclose( file );
    333                             return 1;
    334                         }
     407                        fclose( file );
     408                        return 1;
    335409                    }
    336                     else
     410
     411                    continue;
     412                }
     413                break;
     414
     415            case FR_ID_PRIORITY:
     416
     417                /* read priority data */
     418                if( len == (uint32_t)(2 * tor->info.fileCount) )
     419                {
     420                    ret = fastResumeLoadPriorities( tor, file );
     421
     422                    if( ret && ( feof(file) || ferror(file) ) )
    337423                    {
    338                         ret = 0;
     424                        fclose( file );
     425                        return 1;
    339426                    }
     427
    340428                    continue;
    341429                }
  • trunk/libtransmission/peerutils.h

    r2306 r2316  
    170170        return 0;
    171171
    172     if( tor->info.pieces[piece].priority == TR_PRI_DND ) /* we don't want it */
     172    if( tor->info.pieces[piece].dnd ) /* we don't want it */
    173173        return 0;
    174174
  • trunk/libtransmission/torrent.c

    r2313 r2316  
    2323 *****************************************************************************/
    2424
     25#include "transmission.h"
     26#include "fastresume.h"
    2527#include "trcompat.h" /* for strlcpy */
    26 #include "transmission.h"
    2728#include "metainfo.h"
    2829#include "net.h" /* tr_netNtop */
     
    130131{
    131132    int i;
    132     tr_priority_t priority = TR_PRI_DND;
     133    tr_priority_t priority = TR_PRI_NORMAL;
    133134
    134135    for( i=0; i<tor->info.fileCount; ++i )
     
    11101111***/
    11111112
     1113static void
     1114tr_torrentSetFilePriorityImpl( tr_torrent_t   * tor,
     1115                               int              fileIndex,
     1116                               tr_priority_t    priority,
     1117                               int              doSave )
     1118{
     1119    int i;
     1120    tr_file_t * file;
     1121
     1122    tr_torrentWriterLock( tor );
     1123
     1124    assert( tor != NULL );
     1125    assert( 0<=fileIndex && fileIndex<tor->info.fileCount );
     1126    assert( priority==TR_PRI_LOW || priority==TR_PRI_NORMAL || priority==TR_PRI_HIGH );
     1127
     1128    file = &tor->info.files[fileIndex];
     1129    file->priority = priority;
     1130    for( i=file->firstPiece; i<=file->lastPiece; ++i )
     1131      tor->info.pieces[i].priority = calculatePiecePriority( tor, i );
     1132
     1133    tr_dbg ( "Setting file #%d (pieces %d-%d) priority to %d (%s)",
     1134             fileIndex, file->firstPiece, file->lastPiece,
     1135             priority, tor->info.files[fileIndex].name );
     1136
     1137    if( doSave )
     1138        fastResumeSave( tor );
     1139
     1140    tr_torrentWriterUnlock( tor );
     1141}
     1142
    11121143void
    11131144tr_torrentSetFilePriority( tr_torrent_t   * tor,
     
    11151146                           tr_priority_t    priority )
    11161147{
     1148    tr_torrentSetFilePriorityImpl( tor, fileIndex, priority, TRUE );
     1149}
     1150
     1151void
     1152tr_torrentSetFilePriorities( tr_torrent_t         * tor,
     1153                             const tr_priority_t  * filePriorities )
     1154{
    11171155    int i;
    1118     tr_file_t * file;
    1119 
    1120     tr_torrentWriterLock( tor );
    1121 
    1122     assert( tor != NULL );
    1123     assert( 0<=fileIndex && fileIndex<tor->info.fileCount );
    1124     assert( priority==TR_PRI_LOW || priority==TR_PRI_NORMAL
    1125          || priority==TR_PRI_HIGH || priority==TR_PRI_DND );
    1126 
    1127     file = &tor->info.files[fileIndex];
    1128     file->priority = priority;
    1129     for( i=file->firstPiece; i<=file->lastPiece; ++i )
    1130       tor->info.pieces[i].priority = calculatePiecePriority( tor, i );
    1131 
    1132     tr_dbg ( "Setting file #%d (pieces %d-%d) priority to %d (%s)",
    1133              fileIndex, file->firstPiece, file->lastPiece,
    1134              priority, tor->info.files[fileIndex].name );
    1135 
    1136     tr_torrentWriterUnlock( tor );
     1156    for( i=0; i<tor->info.pieceCount; ++i )
     1157        tr_torrentSetFilePriorityImpl( tor, i, filePriorities[i], FALSE );
     1158    fastResumeSave( tor );
    11371159}
    11381160
     
    11521174
    11531175
    1154 void
    1155 tr_torrentSetFilePriorities( tr_torrent_t         * tor,
    1156                              const tr_priority_t  * filePriorities )
    1157 {
    1158     int i;
    1159     for( i=0; i<tor->info.pieceCount; ++i )
    1160       tr_torrentSetFilePriority( tor, i, filePriorities[i] );
    1161 }
    1162 
    11631176tr_priority_t*
    11641177tr_torrentGetFilePriorities( const tr_torrent_t * tor )
     
    11751188    return p;
    11761189}
     1190
     1191int
     1192tr_torrentGetFileDL( const tr_torrent_t * tor,
     1193                     int                  file )
     1194{
     1195    int do_download;
     1196    tr_torrentReaderLock( tor );
     1197
     1198    assert( 0<=file && file<tor->info.fileCount );
     1199    do_download = !tor->info.files[file].dnd;
     1200
     1201    tr_torrentReaderUnlock( tor );
     1202    return do_download != 0;
     1203}
     1204
     1205void
     1206tr_torrentSetFileDL( tr_torrent_t  * tor,
     1207                     int             file,
     1208                     int             do_download )
     1209{
     1210    tr_torrentWriterLock( tor );
     1211
     1212    assert( 0<=file && file<tor->info.fileCount );
     1213    tor->info.files[file].dnd = !do_download;
     1214    fastResumeSave( tor );
     1215
     1216    tr_torrentWriterUnlock( tor );
     1217}
  • trunk/libtransmission/transmission.h

    r2259 r2316  
    207207enum
    208208{
    209     TR_PRI_DND    = -2, /* Do Not Download */
    210209    TR_PRI_LOW    = -1,
    211210    TR_PRI_NORMAL =  0, /* since NORMAL is 0, memset initializes nicely */
     
    216215
    217216/* priorities should be an array of tor->info.fileCount bytes,
    218  * each holding a value of TR_PRI_NORMAL, _HIGH, _LOW, or _DND. */
     217 * each holding a value of TR_PRI_NORMAL, _HIGH, or _LOW */
    219218void tr_torrentSetFilePriorities ( tr_torrent_t *, const tr_priority_t * priorities );
    220219
    221220/* single-file form of tr_torrentPrioritizeFiles.
    222  * priority must be one of TR_PRI_NORMAL, _HIGH, _LOW, or _DND */
     221 * priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW */
    223222void tr_torrentSetFilePriority( tr_torrent_t *, int file, tr_priority_t priority );
    224223
    225224/* returns a malloc()ed array of tor->info.fileCount items,
    226  * each holding a value of TR_PRI_NORMAL, _HIGH, _LOW, or _DND.
     225 * each holding a value of TR_PRI_NORMAL, _HIGH, or _LOW.
    227226   free the array when done. */
    228227tr_priority_t* tr_torrentGetFilePriorities( const tr_torrent_t * );
    229228
    230229/* single-file form of tr_torrentGetFilePriorities.
    231  * returns one of TR_PRI_NORMAL, _HIGH, _LOW, or _DND */
     230 * returns one of TR_PRI_NORMAL, _HIGH, or _LOW. */
    232231tr_priority_t tr_torrentGetFilePriority( const tr_torrent_t *, int file );
    233232
    234 /* returns the priority for the specified piece,
    235  * as ranked by the number of files of various priorities in that piece.
    236  * a zero priority means DND */
    237 tr_priority_t tr_torrentGetPiecePriority( const tr_torrent_t *, int pieceIndex );
     233/* returns true if the file's `download' flag is set */
     234int tr_torrentGetFileDL( const tr_torrent_t *, int file );
     235
     236/* set the specified file's `download' flag */
     237void tr_torrentSetFileDL( tr_torrent_t *, int file, int do_download );
     238
    238239
    239240/***********************************************************************
     
    468469    uint64_t length;                /* Length of the file, in bytes */
    469470    char     name[MAX_PATH_LENGTH]; /* Path to the file */
    470     int8_t   priority;              /* TR_PRI_HIGH, _NORMAL, _LOW, or _DND */
     471    int8_t   priority;              /* TR_PRI_HIGH, _NORMAL, or _LOW */
     472    int8_t   dnd;                   /* nonzero if the file shouldn't be downloaded */
    471473    int      firstPiece;            /* We need pieces [firstPiece... */
    472474    int      lastPiece;             /* ...lastPiece] to dl this file */
     
    478480{
    479481    uint8_t  hash[SHA_DIGEST_LENGTH];  /* pieces hash */
    480     int8_t   priority;                 /* TR_PRI_HIGH, _NORMAL, _LOW, or _DND */
     482    int8_t   priority;                 /* TR_PRI_HIGH, _NORMAL, or _LOW */
     483    int8_t   dnd;                      /*  nonzero if the piece shouldn't be downloaded */
    481484}
    482485tr_piece_t;
Note: See TracChangeset for help on using the changeset viewer.