Changeset 12611


Ignore:
Timestamp:
Aug 2, 2011, 3:59:54 AM (10 years ago)
Author:
jordan
Message:

#671 "torrent queuing" -- modify the queue implementation s.t. every torrent has a queuePosition, even if it's not currently in the queue.

Location:
trunk
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/actions.c

    r12607 r12611  
    5050    { "sort-by-name",      NULL, N_( "Sort by _Name" ),      NULL, NULL, 1 },
    5151    { "sort-by-progress",  NULL, N_( "Sort by _Progress" ),  NULL, NULL, 2 },
    52     { "sort-by-ratio",     NULL, N_( "Sort by Rati_o" ),     NULL, NULL, 3 },
    53     { "sort-by-state",     NULL, N_( "Sort by Stat_e" ),     NULL, NULL, 4 },
    54     { "sort-by-age",       NULL, N_( "Sort by A_ge" ),       NULL, NULL, 5 },
    55     { "sort-by-time-left", NULL, N_( "Sort by Time _Left" ), NULL, NULL, 6 },
    56     { "sort-by-size",      NULL, N_( "Sort by Si_ze" ),      NULL, NULL, 7 }
     52    { "sort-by-queue",     NULL, N_( "Sort by _Queue" ),     NULL, NULL, 3 },
     53    { "sort-by-ratio",     NULL, N_( "Sort by Rati_o" ),     NULL, NULL, 4 },
     54    { "sort-by-state",     NULL, N_( "Sort by Stat_e" ),     NULL, NULL, 5 },
     55    { "sort-by-age",       NULL, N_( "Sort by A_ge" ),       NULL, NULL, 6 },
     56    { "sort-by-time-left", NULL, N_( "Sort by Time _Left" ), NULL, NULL, 7 },
     57    { "sort-by-size",      NULL, N_( "Sort by Si_ze" ),      NULL, NULL, 8 }
    5758};
    5859
  • trunk/gtk/main.c

    r12607 r12611  
    248248{
    249249    int total_count;
    250     int active_count;
    251250    int queued_count;
    252251    int stopped_count;
     
    258257{
    259258    int activity = 0;
    260     int queuePosition = -1;
    261259    struct counts_data * counts = user_data;
    262260
     
    265263    gtk_tree_model_get( model, iter, MC_ACTIVITY, &activity, -1 );
    266264
    267     if( activity == TR_STATUS_DOWNLOAD_WAIT )
     265    if( ( activity == TR_STATUS_DOWNLOAD_WAIT ) || ( activity == TR_STATUS_SEED_WAIT ) )
    268266        ++counts->queued_count;
    269267
    270     if( ( activity == TR_STATUS_STOPPED ) && ( queuePosition < 0 ) )
     268    if( activity == TR_STATUS_STOPPED )
    271269        ++counts->stopped_count;
    272     else
    273         ++counts->active_count;
    274270}
    275271
     
    278274{
    279275    counts->total_count = 0;
    280     counts->active_count = 0;
    281276    counts->queued_count = 0;
    282277    counts->stopped_count = 0;
     
    303298    const size_t active = gtr_core_get_active_torrent_count( data->core );
    304299    const int torrent_count = gtk_tree_model_iter_n_children( gtr_core_model( data->core ), NULL );
    305     const tr_session * session = gtr_core_session( data->core );
    306     const bool queue_enabled = tr_sessionGetQueueEnabled( session, TR_DOWN )
    307                             || tr_sessionGetQueueEnabled( session, TR_UP );
     300    bool has_selection;
     301
     302    get_selected_torrent_counts( data, &sel_counts );
     303    has_selection = sel_counts.total_count > 0;
    308304
    309305    gtr_action_set_sensitive( "select-all", torrent_count != 0 );
     
    312308    gtr_action_set_sensitive( "start-all-torrents", active != total );
    313309
    314     get_selected_torrent_counts( data, &sel_counts );
    315     gtr_action_set_sensitive( "torrent-stop", ( sel_counts.active_count + sel_counts.queued_count ) > 0 );
     310    gtr_action_set_sensitive( "torrent-stop", ( sel_counts.stopped_count < sel_counts.total_count ) );
    316311    gtr_action_set_sensitive( "torrent-start", ( sel_counts.stopped_count ) > 0 );
    317312    gtr_action_set_sensitive( "torrent-start-now", ( sel_counts.stopped_count + sel_counts.queued_count ) > 0 );
    318     gtr_action_set_sensitive( "torrent-verify", sel_counts.total_count != 0 );
    319     gtr_action_set_sensitive( "remove-torrent", sel_counts.total_count != 0 );
    320     gtr_action_set_sensitive( "delete-torrent", sel_counts.total_count != 0 );
    321     gtr_action_set_sensitive( "relocate-torrent", sel_counts.total_count != 0 );
    322     gtr_action_set_sensitive( "show-torrent-properties", sel_counts.total_count != 0 );
     313    gtr_action_set_sensitive( "torrent-verify",          has_selection );
     314    gtr_action_set_sensitive( "remove-torrent",          has_selection );
     315    gtr_action_set_sensitive( "delete-torrent",          has_selection );
     316    gtr_action_set_sensitive( "relocate-torrent",        has_selection );
     317    gtr_action_set_sensitive( "queue-move-top",          has_selection );
     318    gtr_action_set_sensitive( "queue-move-up",           has_selection );
     319    gtr_action_set_sensitive( "queue-move-down",         has_selection );
     320    gtr_action_set_sensitive( "queue-move-bottom",       has_selection );
     321    gtr_action_set_sensitive( "show-torrent-properties", has_selection );
    323322    gtr_action_set_sensitive( "open-torrent-folder", sel_counts.total_count == 1 );
    324323    gtr_action_set_sensitive( "copy-magnet-link-to-clipboard", sel_counts.total_count == 1 );
    325     gtr_action_set_sensitive( "queue-move-top",    queue_enabled && ( sel_counts.queued_count > 0 ) );
    326     gtr_action_set_sensitive( "queue-move-up",     queue_enabled && ( sel_counts.queued_count > 0 ) );
    327     gtr_action_set_sensitive( "queue-move-down",   queue_enabled && ( sel_counts.queued_count > 0 ) );
    328     gtr_action_set_sensitive( "queue-move-bottom", queue_enabled && ( sel_counts.queued_count > 0 ) );
    329324
    330325    canUpdate = 0;
  • trunk/gtk/torrent-cell-renderer.c

    r12609 r12611  
    229229
    230230        case TR_STATUS_DOWNLOAD_WAIT:
    231             g_string_append_printf( gstr, _( "Download queue #%d" ), st->queuePosition + 1 );
     231            g_string_append( gstr, _( "Waiting to download" ) );
    232232            break;
    233 
    234233        case TR_STATUS_SEED_WAIT:
    235             g_string_append_printf( gstr, _( "Seed queue #%d" ), st->queuePosition + 1 );
     234            g_string_append( gstr, _( "Waiting to seed" ) );
    236235            break;
    237236
     
    686685    gtr_cell_renderer_render( p->icon_renderer, window, widget, &icon_area, flags );
    687686    g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", NULL,
    688         "sensitive", sensitive || ( st->queuePosition >= 0 ),
     687        "sensitive", sensitive,
    689688#if GTK_CHECK_VERSION( 3,0,0 )
    690689        "inverted", seed,
     
    806805    g_object_set( p->text_renderer, "text", gstr_prog->str, "scale", SMALL_SCALE, "weight", PANGO_WEIGHT_NORMAL, NULL );
    807806    gtr_cell_renderer_render( p->text_renderer, window, widget, &prog_area, flags );
    808     g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", "", "sensitive", ( sensitive || st->queuePosition >= 0 ),
     807    g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", "", "sensitive", sensitive,
    809808#if GTK_CHECK_VERSION( 3,0,0 )
    810809        "inverted", seed,
  • trunk/gtk/tr-core.c

    r12607 r12611  
    460460
    461461static int
    462 compare_by_queue( const tr_stat * a, const tr_stat * b )
    463 {
    464     const bool a_is_queued = a->queuePosition >= 0;
    465     const bool b_is_queued = b->queuePosition >= 0;
    466     if( a_is_queued != b_is_queued ) return a_is_queued ? -1 : 1;
    467     return b->queuePosition - a->queuePosition;
    468 }
    469 
    470 static int
    471 compare_by_ratio( GtkTreeModel* m, GtkTreeIter * a, GtkTreeIter * b, gpointer user_data )
    472 {
    473     int ret = 0;
     462compare_by_queue( GtkTreeModel * m, GtkTreeIter * a, GtkTreeIter * b, gpointer user_data UNUSED )
     463{
    474464    tr_torrent *ta, *tb;
    475465    const tr_stat *sa, *sb;
     
    480470    sb = tr_torrentStatCached( tb );
    481471
     472    return sb->queuePosition - sa->queuePosition;
     473}
     474
     475static int
     476compare_by_ratio( GtkTreeModel* m, GtkTreeIter * a, GtkTreeIter * b, gpointer user_data )
     477{
     478    int ret = 0;
     479    tr_torrent *ta, *tb;
     480    const tr_stat *sa, *sb;
     481
     482    gtk_tree_model_get( m, a, MC_TORRENT, &ta, -1 );
     483    sa = tr_torrentStatCached( ta );
     484    gtk_tree_model_get( m, b, MC_TORRENT, &tb, -1 );
     485    sb = tr_torrentStatCached( tb );
     486
    482487    if( !ret ) ret = compare_ratio( sa->ratio, sb->ratio );
    483     if( !ret ) ret = compare_by_queue( sa, sb );
    484     if( !ret ) ret = compare_by_name( m, a, b, user_data );
     488    if( !ret ) ret = compare_by_queue( m, a, b, user_data );
    485489    return ret;
    486490}
     
    507511    if( !ret ) ret = compare_double( aUp+aDown, bUp+bDown );
    508512    if( !ret ) ret = compare_uint64( sa->uploadedEver, sb->uploadedEver );
    509     if( !ret ) ret = compare_by_queue( sa, sb );
    510     if( !ret ) ret = compare_by_name( m, a, b, user_data );
     513    if( !ret ) ret = compare_by_queue( m, a, b, user_data );
    511514    return ret;
    512515}
     
    588591
    589592    if( !ret ) ret = compare_int( sa, sb );
    590     if( !ret ) ret = compare_by_queue( tr_torrentStatCached( ta ), tr_torrentStatCached( tb ) );
    591     if( !ret ) ret = compare_by_progress( m, a, b, u );
     593    if( !ret ) ret = compare_by_queue( m, a, b, u );
    592594    return ret;
    593595}
     
    607609    else if( !strcmp( mode, "sort-by-progress" ) )
    608610        sort_func = compare_by_progress;
     611    else if( !strcmp( mode, "sort-by-queue" ) )
     612        sort_func = compare_by_queue;
    609613    else if( !strcmp( mode, "sort-by-time-left" ) )
    610614        sort_func = compare_by_eta;
  • trunk/gtk/ui.h

    r12607 r12611  
    5151    "      <menuitem action='sort-by-name'/>\n"
    5252    "      <menuitem action='sort-by-progress'/>\n"
     53    "      <menuitem action='sort-by-queue'/>\n"
    5354    "      <menuitem action='sort-by-ratio'/>\n"
    5455    "      <menuitem action='sort-by-size'/>\n"
  • trunk/libtransmission/rpcimpl.c

    r12609 r12611  
    314314        tr_torrent * tor = torrents[i];
    315315
    316         if( tor->isRunning || ( tor->queuePosition >= 0 ) )
     316        if( tor->isRunning || tr_torrentIsQueued( tor ) )
    317317        {
    318318            tor->isStopping = true;
  • trunk/libtransmission/session.c

    r12607 r12611  
    26932693    assert( tr_isDirection( direction ) );
    26942694
    2695     while(( tor = tr_torrentNext( session, tor ))) {
    2696         if( !tor->isRunning && ( direction == tr_torrentGetQueueDirection( tor ) ) ) {
    2697             const int position = tr_torrentGetQueuePosition( tor );
    2698             if( ( position >= 0 ) && ( best_position > position ) ) {
    2699                 best_position = position;
    2700                 best_tor = tor;
    2701             }
     2695    while(( tor = tr_torrentNext( session, tor )))
     2696    {
     2697        int position;
     2698
     2699        if( !tr_torrentIsQueued( tor ) )
     2700            continue;
     2701        if( direction != tr_torrentGetQueueDirection( tor ) )
     2702            continue;
     2703
     2704        position = tr_torrentGetQueuePosition( tor );
     2705        if( best_position > position ) {
     2706            best_position = position;
     2707            best_tor = tor;
    27022708        }
    27032709    }
     
    27122718    int active_count;
    27132719    const int max = tr_sessionGetQueueSize( session, dir );
    2714     const tr_torrent_activity activity = TR_UP ? TR_STATUS_SEED : TR_STATUS_DOWNLOAD;
     2720    const tr_torrent_activity activity = dir == TR_UP ? TR_STATUS_SEED : TR_STATUS_DOWNLOAD;
    27152721
    27162722    if( !tr_sessionGetQueueEnabled( session, dir ) )
  • trunk/libtransmission/torrent.c

    r12609 r12611  
    803803    tor->uniqueId = nextUniqueId++;
    804804    tor->magicNumber = TORRENT_MAGIC_NUMBER;
    805     tor->queuePosition = -1;
     805    tor->queuePosition = session->torrentCount;
    806806
    807807    tr_peerIdInit( tor->peer_id );
     
    871871
    872872    /* add the torrent to tr_session.torrentList */
    873     ++session->torrentCount;
     873    session->torrentCount++;
    874874    if( session->torrentList == NULL )
    875875        session->torrentList = tor;
     
    11061106        return is_seed ? TR_STATUS_SEED : TR_STATUS_DOWNLOAD;
    11071107
    1108     if( tor->queuePosition >= 0 ) {
     1108    if( tr_torrentIsQueued( tor ) ) {
    11091109        if( is_seed && tr_sessionGetQueueEnabled( tor->session, TR_UP ) )
    11101110            return TR_STATUS_SEED_WAIT;
     
    14971497***/
    14981498
     1499static bool queueIsSequenced( tr_session * );
     1500
    14991501static void
    15001502freeTorrent( tr_torrent * tor )
     
    15031505    tr_session *  session = tor->session;
    15041506    tr_info *    inf = &tor->info;
     1507    const time_t now = tr_time( );
    15051508
    15061509    assert( !tor->isRunning );
     
    15261529    }
    15271530
     1531    /* decrement the torrent count */
    15281532    assert( session->torrentCount >= 1 );
    15291533    session->torrentCount--;
     1534
     1535    /* resequence the queue positions */
     1536    t = NULL;
     1537    while(( t = tr_torrentNext( session, tor ))) {
     1538        if( t->queuePosition > tor->queuePosition ) {
     1539            t->queuePosition--;
     1540            t->anyDate = now;
     1541        }
     1542    }
     1543    assert( queueIsSequenced( session ) );
    15301544
    15311545    tr_bandwidthDestruct( &tor->bandwidth );
     
    15411555**/
    15421556
    1543 static void queueRemove( tr_torrent * tor );
     1557static void torrentSetQueued( tr_torrent * tor, bool queued );
    15441558
    15451559static void
     
    15541568
    15551569    tr_torrentRecheckCompleteness( tor );
    1556     queueRemove( tor );
     1570    torrentSetQueued( tor, false );
    15571571
    15581572    now = tr_time( );
     
    16021616    return tr_sessionCountQueueFreeSlots( tor->session, dir ) == 0;
    16031617}
    1604 
    1605 static void queueAppend( tr_torrent * tor );
    16061618
    16071619static void
     
    16311643        case TR_STATUS_STOPPED:
    16321644            if( !bypass_queue && torrentShouldQueue( tor ) ) {
    1633                 queueAppend( tor );
     1645                torrentSetQueued( tor, true );
    16341646                return;
    16351647            }
     
    17551767
    17561768    tr_verifyRemove( tor );
    1757     queueRemove( tor );
     1769    torrentSetQueued( tor, false );
    17581770    tr_peerMgrStopTorrent( tor );
    17591771    tr_announcerTorrentStopped( tor );
     
    31753187
    31763188static bool
    3177 queueIsSequenced( tr_torrent * tor )
     3189queueIsSequenced( tr_session * session )
    31783190{
    31793191    int i ;
    31803192    int n ;
    31813193    bool is_sequenced = true;
    3182     tr_session * session = tor->session;
    3183     tr_direction direction = tr_torrentGetQueueDirection( tor );
     3194    tr_torrent * tor;
    31843195    tr_torrent ** tmp = tr_new( tr_torrent *, session->torrentCount );
    31853196
    3186     /* get all the torrents in that queue */
     3197    /* get all the torrents */
    31873198    n = 0;
    31883199    tor = NULL;
    31893200    while(( tor = tr_torrentNext( session, tor )))
    3190         if( tr_torrentIsQueued( tor ) && ( direction == tr_torrentGetQueueDirection( tor ) ) )
    3191             tmp[n++] = tor;
     3201        tmp[n++] = tor;
    31923202
    31933203    /* sort them by position */
     
    31953205
    31963206#if 0
    3197     /* print them */
    3198     fprintf( stderr, "sequence: " );
     3207    fprintf( stderr, "%s", "queue: " );
    31993208    for( i=0; i<n; ++i )
    32003209        fprintf( stderr, "%d ", tmp[i]->queuePosition );
    3201     fprintf( stderr, "\n" );
     3210    fputc( '\n', stderr );
    32023211#endif
    32033212
     
    32203229tr_torrentSetQueuePosition( tr_torrent * tor, int pos )
    32213230{
    3222     if( tr_torrentIsQueued( tor ) )
    3223     {
    3224         int back = -1;
    3225         tr_torrent * walk;
    3226         const tr_direction direction = tr_torrentGetQueueDirection( tor );
    3227         const int old_pos = tor->queuePosition;
    3228         const time_t now = tr_time( );
    3229 
    3230         if( pos < 0 )
    3231             pos = 0;
    3232 
    3233         tor->queuePosition = -1;
    3234 
    3235         walk = NULL;
    3236         while(( walk = tr_torrentNext( tor->session, walk )))
    3237         {
    3238             if( tr_torrentIsQueued( walk ) && ( tr_torrentGetQueueDirection( walk ) == direction ) )
    3239             {
    3240                 if( old_pos < pos ) {
    3241                     if( ( old_pos <= walk->queuePosition ) && ( walk->queuePosition <= pos ) ) {
    3242                         walk->queuePosition--;
    3243                         walk->anyDate = now;
    3244                     }
    3245                 }
    3246 
    3247                 if( old_pos > pos ) {
    3248                     if( ( pos <= walk->queuePosition ) && ( walk->queuePosition < old_pos ) ) {
    3249                         walk->queuePosition++;
    3250                         walk->anyDate = now;
    3251                     }
    3252                 }
    3253 
    3254                 if( back < walk->queuePosition )
    3255                     back = walk->queuePosition;
     3231    int back = -1;
     3232    tr_torrent * walk;
     3233    const int old_pos = tor->queuePosition;
     3234    const time_t now = tr_time( );
     3235
     3236    if( pos < 0 )
     3237        pos = 0;
     3238
     3239    tor->queuePosition = -1;
     3240
     3241    walk = NULL;
     3242    while(( walk = tr_torrentNext( tor->session, walk )))
     3243    {
     3244        if( old_pos < pos ) {
     3245            if( ( old_pos <= walk->queuePosition ) && ( walk->queuePosition <= pos ) ) {
     3246                walk->queuePosition--;
     3247                walk->anyDate = now;
    32563248            }
    32573249        }
    32583250
    3259         tor->queuePosition = MIN( pos, (back+1) );
    3260         tor->anyDate = now;
    3261     }
    3262 
    3263     assert( queueIsSequenced( tor ) );
     3251        if( old_pos > pos ) {
     3252            if( ( pos <= walk->queuePosition ) && ( walk->queuePosition < old_pos ) ) {
     3253                walk->queuePosition++;
     3254                walk->anyDate = now;
     3255            }
     3256        }
     3257
     3258        if( back < walk->queuePosition )
     3259            back = walk->queuePosition;
     3260    }
     3261
     3262    tor->queuePosition = MIN( pos, (back+1) );
     3263    tor->anyDate = now;
     3264
     3265    assert( queueIsSequenced( tor->session ) );
    32643266}
    32653267
     
    33083310}
    33093311
    3310 /* Ensure that the torrents queued for downloads have queuePositions contiguous from [0...n] */
    33113312static void
    3312 queueResequence( tr_session * session, tr_direction direction )
    3313 {
    3314     int i;
    3315     int n;
    3316     tr_torrent * tor = NULL;
    3317     tr_torrent ** tmp = tr_new( tr_torrent *, session->torrentCount );
    3318     const time_t now = tr_time( );
    3319 
    3320     assert( tr_isSession( session ) );
    3321     assert( tr_isDirection( direction ) );
    3322 
    3323     /* get all the torrents in that queue */
    3324     n = 0;
    3325     while(( tor = tr_torrentNext( session, tor ))) {
    3326         if( direction == tr_torrentGetQueueDirection( tor )) {
    3327             const int position = tr_torrentGetQueuePosition( tor );
    3328             if( position >= 0 )
    3329                 tmp[n++] = tor;
    3330         }
    3331     }
    3332 
    3333     /* sort them by position */
    3334     qsort( tmp, n, sizeof( tr_torrent * ), compareTorrentByQueuePosition );
    3335 
    3336     /* sequence them... */
    3337     for( i=0; i<n; ++i ) {
    3338         tr_torrent * tor = tmp[i];
    3339         if( tor->queuePosition != i ) {
    3340             tor->queuePosition = i;
    3341             tor->anyDate = now;
    3342         }
    3343     }
    3344 
    3345     tr_free( tmp );
    3346 }
    3347 
    3348 static void
    3349 queueRemove( tr_torrent * tor )
    3350 {
    3351     if( tr_torrentIsQueued( tor ) )
    3352     {
    3353         tor->queuePosition = -1;
    3354         queueResequence( tor->session, tr_torrentGetQueueDirection( tor ) );
    3355     }
    3356 }
    3357 
    3358 static void
    3359 queueAppend( tr_torrent * tor )
    3360 {
    3361     if( !tr_torrentIsQueued( tor ) )
    3362     {
    3363         /* tr_torrentSetQueuePosition() requres the torrent to be queued,
    3364            so init tor->queuePosition to the back... */
    3365         tor->queuePosition = INT_MAX;
    3366 
    3367         tr_torrentSetQueuePosition( tor, INT_MAX );
    3368     }
    3369 }
     3313torrentSetQueued( tr_torrent * tor, bool queued )
     3314{
     3315    assert( tr_isTorrent( tor ) );
     3316    assert( tr_isBool( queued ) );
     3317
     3318    if( tr_torrentIsQueued( tor ) != queued )
     3319    {
     3320        tor->isQueued = queued;
     3321        tor->anyDate = tr_time( );
     3322    }
     3323}
  • trunk/libtransmission/torrent.h

    r12607 r12611  
    242242    bool                       startAfterVerify;
    243243    bool                       isDirty;
     244    bool                       isQueued;
    244245
    245246    bool                       infoDictOffsetIsCached;
     
    434435tr_torrentIsQueued( const tr_torrent * tor )
    435436{
    436     return tor->queuePosition >= 0;
     437    return tor->isQueued;
    437438}
    438439
  • trunk/libtransmission/transmission.h

    r12609 r12611  
    19981998    bool   finished;
    19991999
    2000     /** The position of this torrent in the download queue.
    2001         This will be >= 0 if the torrent is queued; -1 otherwise. */
     2000    /** This torrent's queue position.
     2001        All torrents have a queue position, even if it's not queued. */
    20022002    int queuePosition;
    20032003
  • trunk/qt/filters.cc

    r12607 r12611  
    4040    "sort-by-name",
    4141    "sort-by-progress",
     42    "sort-by-queue"
    4243    "sort-by-ratio",
    4344    "sort-by-size",
  • trunk/qt/filters.h

    r12607 r12611  
    4343        static const QString names[];
    4444        enum { SORT_BY_ACTIVITY, SORT_BY_AGE, SORT_BY_ETA, SORT_BY_NAME,
    45                SORT_BY_PROGRESS, SORT_BY_RATIO, SORT_BY_SIZE,
     45               SORT_BY_PROGRESS, SORT_BY_QUEUE, SORT_BY_RATIO, SORT_BY_SIZE,
    4646               SORT_BY_STATE, SORT_BY_ID, NUM_MODES };
    4747        static int modeFromName( const QString& name );
  • trunk/qt/mainwin.cc

    r12607 r12611  
    141141    connect( ui.action_SortByName,     SIGNAL(toggled(bool)), this, SLOT(onSortByNameToggled(bool)));
    142142    connect( ui.action_SortByProgress, SIGNAL(toggled(bool)), this, SLOT(onSortByProgressToggled(bool)));
     143    connect( ui.action_SortByQueue,    SIGNAL(toggled(bool)), this, SLOT(onSortByQueueToggled(bool)));
    143144    connect( ui.action_SortByRatio,    SIGNAL(toggled(bool)), this, SLOT(onSortByRatioToggled(bool)));
    144145    connect( ui.action_SortBySize,     SIGNAL(toggled(bool)), this, SLOT(onSortBySizeToggled(bool)));
     
    521522void TrMainWindow :: onSortByNameToggled     ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_NAME );     }
    522523void TrMainWindow :: onSortByProgressToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_PROGRESS ); }
     524void TrMainWindow :: onSortByQueueToggled    ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_QUEUE );    }
    523525void TrMainWindow :: onSortByRatioToggled    ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_RATIO );    }
    524526void TrMainWindow :: onSortBySizeToggled     ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_SIZE );     }
     
    759761    ui.action_Announce->setEnabled( selected > 0 && ( canAnnounce == selected ) );
    760762
    761     ui.action_QueueMoveTop->setEnabled( selectedAndQueued > 0 );
    762     ui.action_QueueMoveUp->setEnabled( selectedAndQueued > 0 );
    763     ui.action_QueueMoveDown->setEnabled( selectedAndQueued > 0 );
    764     ui.action_QueueMoveBottom->setEnabled( selectedAndQueued > 0 );
     763    ui.action_QueueMoveTop->setEnabled( haveSelection );
     764    ui.action_QueueMoveUp->setEnabled( haveSelection );
     765    ui.action_QueueMoveDown->setEnabled( haveSelection );
     766    ui.action_QueueMoveBottom->setEnabled( haveSelection );
    765767
    766768    if( myDetailsDialog )
     
    960962            ui.action_SortByName->setChecked     ( i == SortMode::SORT_BY_NAME );
    961963            ui.action_SortByProgress->setChecked ( i == SortMode::SORT_BY_PROGRESS );
     964            ui.action_SortByQueue->setChecked    ( i == SortMode::SORT_BY_QUEUE );
    962965            ui.action_SortByRatio->setChecked    ( i == SortMode::SORT_BY_RATIO );
    963966            ui.action_SortBySize->setChecked     ( i == SortMode::SORT_BY_SIZE );
  • trunk/qt/mainwin.h

    r12607 r12611  
    139139        void onSortByNameToggled     ( bool );
    140140        void onSortByProgressToggled ( bool );
     141        void onSortByQueueToggled    ( bool );
    141142        void onSortByRatioToggled    ( bool );
    142143        void onSortBySizeToggled     ( bool );
  • trunk/qt/mainwin.ui

    r12607 r12611  
    127127    <addaction name="action_SortByName"/>
    128128    <addaction name="action_SortByProgress"/>
     129    <addaction name="action_SortByQueue"/>
    129130    <addaction name="action_SortByRatio"/>
    130131    <addaction name="action_SortBySize"/>
     
    633634   </property>
    634635  </action>
     636  <action name="action_SortByQueue">
     637   <property name="checkable">
     638    <bool>true</bool>
     639   </property>
     640   <property name="text">
     641    <string>Sort by &amp;Queue</string>
     642   </property>
     643  </action>
    635644 </widget>
    636645 <resources>
  • trunk/qt/torrent-filter.cc

    r12610 r12611  
    8686    switch( myPrefs.get<SortMode>(Prefs::SORT_MODE).mode() )
    8787    {
     88        case SortMode :: SORT_BY_QUEUE:
     89            if( !val ) val = -compare( a->queuePosition(), b->queuePosition() );
     90            break;
    8891        case SortMode :: SORT_BY_SIZE:
    8992            if( !val ) val = compare( a->sizeWhenDone(), b->sizeWhenDone() );
     
    102105            if( !val ) val = compare( a->hasError(), b->hasError() );
    103106            if( !val ) val = compare( a->getActivity(), b->getActivity() );
    104             if( !val ) val = a->compareQueue( *b );
     107            if( !val ) val = -compare( a->queuePosition(), b->queuePosition() );
    105108            // fall through
    106109        case SortMode :: SORT_BY_PROGRESS:
    107110            if( !val ) val = compare( a->percentComplete(), b->percentComplete() );
    108111            if( !val ) val = a->compareSeedRatio( *b );
    109             if( !val ) val = a->compareQueue( *b );
     112            if( !val ) val = -compare( a->queuePosition(), b->queuePosition() );
    110113        case SortMode :: SORT_BY_RATIO:
    111114            if( !val ) val = a->compareRatio( *b );
  • trunk/qt/torrent.cc

    r12609 r12611  
    369369            return true;
    370370    return false;
    371 }
    372 
    373 int
    374 Torrent :: compareQueue( const Torrent& that ) const
    375 {
    376     const bool a_is_queued = isQueued( );
    377     const bool b_is_queued = that.isQueued( );
    378 
    379     if( a_is_queued != b_is_queued )
    380         return a_is_queued ? -1 : 1;
    381 
    382     return that.queuePosition() - queuePosition();
    383371}
    384372
     
    719707        case TR_STATUS_CHECK_WAIT:    str = tr( "Waiting to verify local data" ); break;
    720708        case TR_STATUS_CHECK:         str = tr( "Verifying local data" ); break;
    721         case TR_STATUS_DOWNLOAD_WAIT: str = tr( "Download queue #%1" ).arg( queuePosition() + 1 ); break;
    722         case TR_STATUS_DOWNLOAD:      str = tr( "Downloading" );
    723         case TR_STATUS_SEED_WAIT:     str = tr( "Seed queue #%1" ).arg( queuePosition() + 1 ); break;
    724         case TR_STATUS_SEED:          str = tr( "Seeding" ); break;
     709        case TR_STATUS_DOWNLOAD_WAIT: str = tr( "Waiting to download" ); break;
     710        case TR_STATUS_DOWNLOAD:      str = tr( "Downloading" ); break;
     711        case TR_STATUS_SEED_WAIT:     str = tr( "Queued" ); break;
     712        case TR_STATUS_SEED:          str = tr( "Waiting to seed" ); break;
    725713    }
    726714
  • trunk/qt/torrent.h

    r12609 r12611  
    274274        int compareSeedRatio( const Torrent& ) const;
    275275        int compareRatio( const Torrent& ) const;
    276         int compareQueue( const Torrent& ) const;
    277276        int compareETA( const Torrent& ) const;
    278277        bool hasETA( ) const { return getETA( ) >= 0; }
     
    309308        const FileList& files( ) const { return myFiles; }
    310309        int queuePosition( ) const { return getInt( QUEUE_POSITION ); }
    311         bool isQueued( ) const { return queuePosition( ) >= 0; }
    312310        bool isStalled( ) const { return getBool( IS_STALLED ); }
    313311
     
    324322        bool isWaitingToSeed( ) const { return getActivity( ) == TR_STATUS_SEED_WAIT; }
    325323        bool isReadyToTransfer( ) const { return getActivity()==TR_STATUS_DOWNLOAD || getActivity()==TR_STATUS_SEED; }
     324        bool isQueued( ) const { return isWaitingToDownload() || isWaitingToSeed(); }
    326325        void notifyComplete( ) const;
    327326
  • trunk/web/index.html

    r12607 r12611  
    527527                                                                <li id="sort_by_percent_completed">Progress</li>
    528528                                                                <li id="sort_by_ratio">Ratio</li>
     529                                                                <li id="sort_by_queue_order">Queue Order</li>
    529530                                                                <li id="sort_by_state">State</li>
    530531                                                                <li class="separator"></li>
  • trunk/web/javascript/common.js

    r12607 r12611  
    234234Prefs._SortByActivity     = 'activity';
    235235Prefs._SortByName         = 'name';
     236Prefs._SortByQueue        = 'queue_order';
    236237Prefs._SortByProgress     = 'percent_completed';
    237238Prefs._SortByRatio        = 'ratio';
  • trunk/web/javascript/torrent.js

    r12607 r12611  
    253253        name: function() { return this._name; },
    254254        queuePosition: function() { return this._queue_position; },
    255         isQueued: function() { return this.queuePosition() >= 0; },
     255        isQueued: function() { return ( this.state() == Torrent._StatusSeedWait )
     256                                   || ( this.state() == Torrent._StatusDownloadWait ); },
    256257        webseedsSendingToUs: function() { return this._webseeds_sending_to_us; },
    257258        peersSendingToUs: function() { return this._peers_sending_to_us; },
     
    273274                        case Torrent._StatusCheckWait:      return 'Waiting to verify local data';
    274275                        case Torrent._StatusCheck:          return 'Verifying local data';
    275                         case Torrent._StatusDownloadWait:   return 'Waiting to download #' + (this.queuePosition()+1);
     276                        case Torrent._StatusDownloadWait:   return 'Waiting to download';
    276277                        case Torrent._StatusDownload:       return 'Downloading';
    277                         case Torrent._StatusSeedWait:       return 'Waiting to seed #' + (this.queuePosition()+1);
     278                        case Torrent._StatusSeedWait:       return 'Waiting to seed';
    278279                        case Torrent._StatusSeed:           return 'Seeding';
    279280                        default:                            return 'error';
     
    771772Torrent.compareByQueue = function( a, b )
    772773{
    773         var a_is_queued = a.isQueued( );
    774         var b_is_queued = b.isQueued( );
    775         if( a_is_queued != b_is_queued )
    776                 return a_is_queued ? -1 : 1;
    777 
    778         var a_pos = a.queuePosition( );
    779         var b_pos = b.queuePosition( );
    780         if( a_pos != b_pos )
    781                 return a_pos - b_pos;
    782 
    783         return Torrent.compareByName( a, b );
     774        return a.queuePosition( ) - b.queuePosition();
    784775};
    785776
     
    846837                case Prefs._SortByAge:
    847838                        torrents.sort( this.compareByAge );
     839                        break;
     840                case Prefs._SortByQueue:
     841                        torrents.sort( this.compareByQueue );
    848842                        break;
    849843                case Prefs._SortByProgress:
Note: See TracChangeset for help on using the changeset viewer.