(gtk) #745: sort transfers by ratio

This commit is contained in:
Charles Kerr 2008-04-06 14:07:41 +00:00
parent aca7155f19
commit e51b2e8267
5 changed files with 46 additions and 14 deletions

View File

@ -47,8 +47,9 @@ static GtkRadioActionEntry sort_radio_entries[] =
{ "sort-by-activity", NULL, N_("Sort by _Activity"), NULL, NULL, 0 },
{ "sort-by-name", NULL, N_("Sort by _Name"), NULL, NULL, 1 },
{ "sort-by-progress", NULL, N_("Sort by _Progress"), NULL, NULL, 2 },
{ "sort-by-state", NULL, N_("Sort by _State"), NULL, NULL, 3 },
{ "sort-by-tracker", NULL, N_("Sort by _Tracker"), NULL, NULL, 4 }
{ "sort-by-ratio", NULL, N_("Sort by _Ratio"), NULL, NULL, 3 },
{ "sort-by-state", NULL, N_("Sort by _State"), NULL, NULL, 4 },
{ "sort-by-tracker", NULL, N_("Sort by _Tracker"), NULL, NULL, 5 }
};
static void

View File

@ -114,7 +114,7 @@ refresh_cb ( gpointer user_data )
}
case TR_MAKEMETA_IO_WRITE: {
char * tmp = g_strdup_printf( _( "Couldn't write \"%s\": %s" ), ui->builder->errfile, g_strerror( ui->builder->my_errno ) );
char * tmp = g_strdup_printf( _( "Couldn't create \"%1$s\": %2$s" ), ui->builder->errfile, g_strerror( ui->builder->my_errno ) );
txt = g_strdup_printf( _( "Torrent creation failed: %s" ), tmp );
g_free( tmp );
break;

View File

@ -166,6 +166,33 @@ compareDouble( double a, double b )
return 0;
}
static int
compareRatio( double a, double b )
{
if( (int)a == TR_RATIO_INF && (int)b == TR_RATIO_INF ) return 0;
if( (int)a == TR_RATIO_INF ) return 1;
if( (int)b == TR_RATIO_INF ) return -1;
return compareDouble( a, b );
}
static int
compareByRatio( GtkTreeModel * model,
GtkTreeIter * a,
GtkTreeIter * b,
gpointer user_data UNUSED )
{
tr_torrent *ta, *tb;
const tr_stat *sa, *sb;
gtk_tree_model_get( model, a, MC_TORRENT_RAW, &ta, -1 );
gtk_tree_model_get( model, b, MC_TORRENT_RAW, &tb, -1 );
sa = tr_torrentStatCached( ta );
sb = tr_torrentStatCached( tb );
return compareRatio( sa->ratio, sb->ratio );
}
static int
compareByActivity( GtkTreeModel * model,
GtkTreeIter * a,
@ -223,7 +250,7 @@ compareByProgress( GtkTreeModel * model,
sb = tr_torrentStatCached( tb );
ret = compareDouble( sa->percentDone, sb->percentDone );
if( !ret )
ret = compareDouble( sa->ratio, sb->ratio );
ret = compareRatio( sa->ratio, sb->ratio );
return ret;
}
@ -263,24 +290,27 @@ compareByTracker( GtkTreeModel * model,
static void
setSort( TrCore * core, const char * mode, gboolean isReversed )
{
int col = MC_TORRENT_RAW;
const int col = MC_TORRENT_RAW;
GtkTreeIterCompareFunc sort_func;
GtkSortType type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
GtkTreeModel * model = tr_core_model( core );
GtkTreeSortable * sortable = GTK_TREE_SORTABLE( model );
GtkTreeSortable * sortable = GTK_TREE_SORTABLE( tr_core_model( core ) );
if( !strcmp( mode, "sort-by-activity" ) )
gtk_tree_sortable_set_sort_func( sortable, col, compareByActivity, NULL, NULL );
sort_func = compareByActivity;
else if( !strcmp( mode, "sort-by-progress" ) )
gtk_tree_sortable_set_sort_func( sortable, col, compareByProgress, NULL, NULL );
sort_func = compareByProgress;
else if( !strcmp( mode, "sort-by-ratio" ) )
sort_func = compareByRatio;
else if( !strcmp( mode, "sort-by-state" ) )
gtk_tree_sortable_set_sort_func( sortable, col, compareByState, NULL, NULL );
sort_func = compareByState;
else if( !strcmp( mode, "sort-by-tracker" ) )
gtk_tree_sortable_set_sort_func( sortable, col, compareByTracker, NULL, NULL );
sort_func = compareByTracker;
else {
sort_func = compareByName;
type = isReversed ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING;
gtk_tree_sortable_set_sort_func( sortable, col, compareByName, NULL, NULL );
}
gtk_tree_sortable_set_sort_func( sortable, col, sort_func, NULL, NULL );
gtk_tree_sortable_set_sort_column_id( sortable, col, type );
}

View File

@ -461,7 +461,7 @@ peerPage( GObject * core )
target_cb( w, b );
hig_workarea_add_wide_control( t, &row, h );
s = _("Ignore _unencrypted peers");
s = _("_Ignore unencrypted peers");
w = new_check_button( s, PREF_KEY_ENCRYPTED_ONLY, core );
hig_workarea_add_wide_control( t, &row, w );

View File

@ -32,6 +32,7 @@ const char * fallback_ui_file =
" <menuitem action='sort-by-activity'/>\n"
" <menuitem action='sort-by-name'/>\n"
" <menuitem action='sort-by-progress'/>\n"
" <menuitem action='sort-by-ratio'/>\n"
" <menuitem action='sort-by-state'/>\n"
" <menuitem action='sort-by-tracker'/>\n"
" <separator/>\n"