Changeset 4216


Ignore:
Timestamp:
Dec 19, 2007, 7:10:47 AM (14 years ago)
Author:
charles
Message:

that last commit was kind of silly... "sort by ratio" can be merged into "sort by progress"

Location:
trunk/gtk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/actions.c

    r4215 r4216  
    6262  { "sort-by-name",       NULL, N_("Sort by _Name"),       NULL, NULL, 2 },
    6363  { "sort-by-progress",   NULL, N_("Sort by _Progress"),   NULL, NULL, 3 },
    64   { "sort-by-ratio",      NULL, N_("Sort by _Ratio"),      NULL, NULL, 4 },
    65   { "sort-by-state",      NULL, N_("Sort by _State"),      NULL, NULL, 5 },
    66   { "sort-by-tracker",    NULL, N_("Sort by _Tracker"),    NULL, NULL, 6 }
     64  { "sort-by-state",      NULL, N_("Sort by _State"),      NULL, NULL, 4 },
     65  { "sort-by-tracker",    NULL, N_("Sort by _Tracker"),    NULL, NULL, 5 }
    6766};
    6867
  • trunk/gtk/main.c

    r4215 r4216  
    10291029         ||  !strcmp( action_name, "sort-by-name" )
    10301030         ||  !strcmp( action_name, "sort-by-progress" )
    1031          ||  !strcmp( action_name, "sort-by-ratio" )
    10321031         ||  !strcmp( action_name, "sort-by-state" )
    10331032         ||  !strcmp( action_name, "sort-by-tracker" ) )
  • trunk/gtk/tr_core.c

    r4215 r4216  
    172172
    173173static int
     174compareDouble( double a, double b )
     175{
     176    if( a < b ) return -1;
     177    if( b > a ) return 1;
     178    return 0;
     179}
     180
     181static int
    174182compareByActivity( GtkTreeModel * model,
    175183                   GtkTreeIter  * a,
     
    177185                   gpointer       user_data UNUSED )
    178186{
    179     int ia, ib;
     187    int i;
    180188    tr_torrent *ta, *tb;
    181189    const tr_stat *sa, *sb;
     
    187195    sb = tr_torrentStat( tb );
    188196
    189     ia = (int)( 1024 * ( sa->rateUpload + sa->rateDownload ) );
    190     ib = (int)( 1024 * ( sb->rateUpload + sb->rateDownload ) );
    191     if( ia != ib )
    192         return ia - ib;
     197    if(( i = compareDouble( sa->rateUpload + sa->rateDownload,
     198                            sb->rateUpload + sb->rateDownload ) ))
     199        return i;
    193200
    194201    if( sa->uploadedEver != sb->uploadedEver )
     
    204211                    gpointer         user_data UNUSED )
    205212{
    206     /* FIXME */
    207     return 0;
     213    return 0; /* FIXME */
    208214}
    209215
     
    230236                   gpointer         user_data UNUSED )
    231237{
     238    int ret;
    232239    tr_torrent *ta, *tb;
    233240    const tr_stat *sa, *sb;
    234     int ret;
    235241    gtk_tree_model_get( model, a, MC_TORRENT_RAW, &ta, -1 );
    236242    gtk_tree_model_get( model, b, MC_TORRENT_RAW, &tb, -1 );
    237243    sa = tr_torrentStat( ta );
    238244    sb = tr_torrentStat( tb );
    239          if( sa->percentDone < sb->percentDone ) ret = -1;
    240     else if( sa->percentDone > sb->percentDone ) ret =  1;
    241     else                                         ret =  0;
    242     return ret;
    243 }
    244 
    245 static int
    246 compareByRatio( GtkTreeModel   * model,
    247                 GtkTreeIter    * a,
    248                 GtkTreeIter    * b,
    249                 gpointer         user_data UNUSED )
    250 {
    251     tr_torrent *ta, *tb;
    252     const tr_stat *sa, *sb;
    253     int ret;
    254     gtk_tree_model_get( model, a, MC_TORRENT_RAW, &ta, -1 );
    255     gtk_tree_model_get( model, b, MC_TORRENT_RAW, &tb, -1 );
    256     sa = tr_torrentStat( ta );
    257     sb = tr_torrentStat( tb );
    258          if( sa->ratio < sb->ratio ) ret = -1;
    259     else if( sa->ratio > sb->ratio ) ret =  1;
    260     else                             ret =  0;
     245    ret = compareDouble( sa->percentDone, sb->percentDone );
     246    if( !ret )
     247        ret = compareDouble( sa->ratio, sa->ratio );
    261248    return ret;
    262249}
     
    313300        type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
    314301        gtk_tree_sortable_set_sort_func( sortable, col, compareByProgress, NULL, NULL );
    315     }
    316     else if( !strcmp( mode, "sort-by-ratio" ) )
    317     {
    318         type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
    319         gtk_tree_sortable_set_sort_func( sortable, col, compareByRatio, NULL, NULL );
    320302    }
    321303    else if( !strcmp( mode, "sort-by-state" ) )
  • trunk/gtk/ui.h

    r4215 r4216  
    2323"      <menuitem action='sort-by-name'/>\n"
    2424"      <menuitem action='sort-by-progress'/>\n"
    25 "      <menuitem action='sort-by-ratio'/>\n"
    2625"      <menuitem action='sort-by-state'/>\n"
    2726"      <menuitem action='sort-by-tracker'/>\n"
Note: See TracChangeset for help on using the changeset viewer.