Changeset 5536


Ignore:
Timestamp:
Apr 6, 2008, 2:07:41 PM (14 years ago)
Author:
charles
Message:

(gtk) #745: sort transfers by ratio

Location:
trunk/gtk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/actions.c

    r5496 r5536  
    4848  { "sort-by-name",       NULL, N_("Sort by _Name"),       NULL, NULL, 1 },
    4949  { "sort-by-progress",   NULL, N_("Sort by _Progress"),   NULL, NULL, 2 },
    50   { "sort-by-state",      NULL, N_("Sort by _State"),      NULL, NULL, 3 },
    51   { "sort-by-tracker",    NULL, N_("Sort by _Tracker"),    NULL, NULL, 4 }
     50  { "sort-by-ratio",      NULL, N_("Sort by _Ratio"),      NULL, NULL, 3 },
     51  { "sort-by-state",      NULL, N_("Sort by _State"),      NULL, NULL, 4 },
     52  { "sort-by-tracker",    NULL, N_("Sort by _Tracker"),    NULL, NULL, 5 }
    5253};
    5354
  • trunk/gtk/makemeta-ui.c

    r5455 r5536  
    115115
    116116            case TR_MAKEMETA_IO_WRITE: {
    117                 char * tmp = g_strdup_printf( _( "Couldn't write \"%s\": %s" ), ui->builder->errfile, g_strerror( ui->builder->my_errno ) );
     117                char * tmp = g_strdup_printf( _( "Couldn't create \"%1$s\": %2$s" ), ui->builder->errfile, g_strerror( ui->builder->my_errno ) );
    118118                txt = g_strdup_printf( _( "Torrent creation failed: %s" ), tmp );
    119119                g_free( tmp  );
  • trunk/gtk/tr-core.c

    r5517 r5536  
    168168
    169169static int
     170compareRatio( double a, double b )
     171{
     172    if( (int)a == TR_RATIO_INF && (int)b == TR_RATIO_INF ) return 0;
     173    if( (int)a == TR_RATIO_INF ) return 1;
     174    if( (int)b == TR_RATIO_INF ) return -1;
     175    return compareDouble( a, b );
     176}
     177
     178static int
     179compareByRatio( GtkTreeModel * model,
     180                GtkTreeIter  * a,
     181                GtkTreeIter  * b,
     182                gpointer       user_data UNUSED )
     183{
     184    tr_torrent *ta, *tb;
     185    const tr_stat *sa, *sb;
     186
     187    gtk_tree_model_get( model, a, MC_TORRENT_RAW, &ta, -1 );
     188    gtk_tree_model_get( model, b, MC_TORRENT_RAW, &tb, -1 );
     189
     190    sa = tr_torrentStatCached( ta );
     191    sb = tr_torrentStatCached( tb );
     192
     193    return compareRatio( sa->ratio, sb->ratio );
     194}
     195
     196static int
    170197compareByActivity( GtkTreeModel * model,
    171198                   GtkTreeIter  * a,
     
    224251    ret = compareDouble( sa->percentDone, sb->percentDone );
    225252    if( !ret )
    226         ret = compareDouble( sa->ratio, sb->ratio );
     253        ret = compareRatio( sa->ratio, sb->ratio );
    227254    return ret;
    228255}
     
    264291setSort( TrCore * core, const char * mode, gboolean isReversed  )
    265292{
    266     int col = MC_TORRENT_RAW;
     293    const int col = MC_TORRENT_RAW;
     294    GtkTreeIterCompareFunc sort_func;
    267295    GtkSortType type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
    268     GtkTreeModel * model = tr_core_model( core );
    269     GtkTreeSortable * sortable = GTK_TREE_SORTABLE( model );
     296    GtkTreeSortable * sortable = GTK_TREE_SORTABLE( tr_core_model( core )  );
    270297
    271298    if( !strcmp( mode, "sort-by-activity" ) )
    272         gtk_tree_sortable_set_sort_func( sortable, col, compareByActivity, NULL, NULL );
     299        sort_func = compareByActivity;
    273300    else if( !strcmp( mode, "sort-by-progress" ) )
    274         gtk_tree_sortable_set_sort_func( sortable, col, compareByProgress, NULL, NULL );
     301        sort_func = compareByProgress;
     302    else if( !strcmp( mode, "sort-by-ratio" ) )
     303        sort_func = compareByRatio;
    275304    else if( !strcmp( mode, "sort-by-state" ) )
    276         gtk_tree_sortable_set_sort_func( sortable, col, compareByState, NULL, NULL );
     305        sort_func = compareByState;
    277306    else if( !strcmp( mode, "sort-by-tracker" ) )
    278         gtk_tree_sortable_set_sort_func( sortable, col, compareByTracker, NULL, NULL );
     307        sort_func = compareByTracker;
    279308    else {
     309        sort_func = compareByName;
    280310        type = isReversed ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING;
    281         gtk_tree_sortable_set_sort_func( sortable, col, compareByName, NULL, NULL );
    282     }
    283 
     311    }
     312 
     313    gtk_tree_sortable_set_sort_func( sortable, col, sort_func, NULL, NULL );
    284314    gtk_tree_sortable_set_sort_column_id( sortable, col, type );
    285315}
  • trunk/gtk/tr-prefs.c

    r5496 r5536  
    462462        hig_workarea_add_wide_control( t, &row, h );
    463463       
    464         s = _("Ignore _unencrypted peers");
     464        s = _("_Ignore unencrypted peers");
    465465        w = new_check_button( s, PREF_KEY_ENCRYPTED_ONLY, core );
    466466        hig_workarea_add_wide_control( t, &row, w );
  • trunk/gtk/ui.h

    r5496 r5536  
    3333"      <menuitem action='sort-by-name'/>\n"
    3434"      <menuitem action='sort-by-progress'/>\n"
     35"      <menuitem action='sort-by-ratio'/>\n"
    3536"      <menuitem action='sort-by-state'/>\n"
    3637"      <menuitem action='sort-by-tracker'/>\n"
Note: See TracChangeset for help on using the changeset viewer.