Changeset 7902


Ignore:
Timestamp:
Feb 18, 2009, 6:03:45 AM (13 years ago)
Author:
charles
Message:

(trunk gtk) #1834: Add the ability to sort by ETA

Location:
trunk/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/actions.c

    r7658 r7902  
    5858      NULL, 5 },
    5959    { "sort-by-age",      NULL,        N_( "Sort by A_ge" ),      NULL,
    60       NULL, 6 }
     60      NULL, 6 },
     61    { "sort-by-eta",      NULL,        N_( "Sort by _ETA" ),      NULL,
     62      NULL, 7 }
    6163};
    6264
  • trunk/gtk/tr-core.c

    r7888 r7902  
    246246***/
    247247
     248static gboolean
     249isValidETA( int t )
     250{
     251    return ( t != TR_ETA_NOT_AVAIL ) && ( t != TR_ETA_UNKNOWN );
     252}
     253
    248254static int
    249 compareDouble( double a,
    250                double b )
     255compareETA( int a, int b )
     256{
     257    const gboolean a_valid = isValidETA( a );
     258    const gboolean b_valid = isValidETA( b );
     259
     260    if( !a_valid && !b_valid ) return 0;
     261    if( !a_valid ) return -1;
     262    if( !b_valid ) return 1;
     263    return a < b ? 1 : -1;
     264}
     265
     266static int
     267compareDouble( double a, double b )
    251268{
    252269    if( a < b ) return -1;
     
    256273
    257274static int
    258 compareRatio( double a,
    259               double b )
     275compareRatio( double a, double b )
    260276{
    261277    if( (int)a == TR_RATIO_INF && (int)b == TR_RATIO_INF ) return 0;
     
    266282
    267283static int
    268 compareTime( time_t a,
    269              time_t b )
     284compareTime( time_t a, time_t b )
    270285{
    271286    if( a < b ) return -1;
     
    275290
    276291static int
    277 compareByRatio( GtkTreeModel *          model,
    278                 GtkTreeIter *            a,
    279                 GtkTreeIter *            b,
    280                 gpointer       user_data UNUSED )
    281 {
    282     tr_torrent *   ta, *tb;
     292compareByRatio( GtkTreeModel  * model,
     293                GtkTreeIter   * a,
     294                GtkTreeIter   * b,
     295                gpointer        user_data UNUSED )
     296{
     297    tr_torrent *ta, *tb;
    283298    const tr_stat *sa, *sb;
    284299
     
    370385
    371386static int
     387compareByETA( GtkTreeModel * model,
     388              GtkTreeIter  * a,
     389              GtkTreeIter  * b,
     390              gpointer       user_data UNUSED )
     391{
     392    tr_torrent *ta, *tb;
     393
     394    gtk_tree_model_get( model, a, MC_TORRENT_RAW, &ta, -1 );
     395    gtk_tree_model_get( model, b, MC_TORRENT_RAW, &tb, -1 );
     396
     397    return compareETA( tr_torrentStatCached( ta )->eta,
     398                       tr_torrentStatCached( tb )->eta );
     399}
     400
     401static int
    372402compareByState( GtkTreeModel * model,
    373403                GtkTreeIter *  a,
     
    421451    else if( !strcmp( mode, "sort-by-progress" ) )
    422452        sort_func = compareByProgress;
     453    else if( !strcmp( mode, "sort-by-eta" ) )
     454        sort_func = compareByETA;
    423455    else if( !strcmp( mode, "sort-by-ratio" ) )
    424456        sort_func = compareByRatio;
  • trunk/gtk/ui.h

    r7252 r7902  
    3535    "      <menuitem action='sort-by-name'/>\n"
    3636    "      <menuitem action='sort-by-progress'/>\n"
     37    "      <menuitem action='sort-by-eta'/>\n"
    3738    "      <menuitem action='sort-by-ratio'/>\n"
    3839    "      <menuitem action='sort-by-state'/>\n"
Note: See TracChangeset for help on using the changeset viewer.