(trunk gtk) add "sort by size" to the main window's list of torrents

This commit is contained in:
Charles Kerr 2009-03-01 00:11:53 +00:00
parent fb02e9d437
commit 89eff88dec
3 changed files with 47 additions and 33 deletions

View File

@ -44,22 +44,15 @@ action_cb( GtkAction * a,
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-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 },
{ "sort-by-age", NULL, N_( "Sort by A_ge" ), NULL,
NULL, 6 },
{ "sort-by-eta", NULL, N_( "Sort by _ETA" ), NULL,
NULL, 7 }
{ "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-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 },
{ "sort-by-age", NULL, N_( "Sort by A_ge" ), NULL, NULL, 6 },
{ "sort-by-eta", NULL, N_( "Sort by _ETA" ), NULL, NULL, 7 },
{ "sort-by-size", NULL, N_( "Sort by Si_ze" ), NULL, NULL, 8 }
};
static void

View File

@ -350,10 +350,10 @@ compareByName( GtkTreeModel * model,
}
static int
compareByAge( GtkTreeModel * model,
GtkTreeIter * a,
GtkTreeIter * b,
gpointer user_data UNUSED )
compareByAge( GtkTreeModel * model,
GtkTreeIter * a,
GtkTreeIter * b,
gpointer user_data UNUSED )
{
tr_torrent *ta, *tb;
@ -363,20 +363,39 @@ compareByAge( GtkTreeModel * model,
tr_torrentStatCached( tb )->addedDate );
}
static int
compareBySize( GtkTreeModel * model,
GtkTreeIter * a,
GtkTreeIter * b,
gpointer user_data UNUSED )
{
tr_torrent *t;
const tr_info *ia, *ib;
gtk_tree_model_get( model, a, MC_TORRENT_RAW, &t, -1 );
ia = tr_torrentInfo( t );
gtk_tree_model_get( model, b, MC_TORRENT_RAW, &t, -1 );
ib = tr_torrentInfo( t );
if( ia->totalSize < ib->totalSize ) return 1;
if( ia->totalSize > ib->totalSize ) return -1;
return 0;
}
static int
compareByProgress( GtkTreeModel * model,
GtkTreeIter * a,
GtkTreeIter * b,
gpointer user_data UNUSED )
{
int ret;
tr_torrent * ta, *tb;
int ret;
tr_torrent * t;
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 );
gtk_tree_model_get( model, a, MC_TORRENT_RAW, &t, -1 );
sa = tr_torrentStatCached( t );
gtk_tree_model_get( model, b, MC_TORRENT_RAW, &t, -1 );
sb = tr_torrentStatCached( t );
ret = compareDouble( sa->percentDone, sb->percentDone );
if( !ret )
ret = compareRatio( sa->ratio, sb->ratio );
@ -419,10 +438,10 @@ compareByState( GtkTreeModel * model,
}
static int
compareByTracker( GtkTreeModel * model,
GtkTreeIter * a,
GtkTreeIter * b,
gpointer user_data UNUSED )
compareByTracker( GtkTreeModel * model,
GtkTreeIter * a,
GtkTreeIter * b,
gpointer user_data UNUSED )
{
const tr_torrent *ta, *tb;
@ -458,8 +477,9 @@ setSort( TrCore * core,
sort_func = compareByState;
else if( !strcmp( mode, "sort-by-tracker" ) )
sort_func = compareByTracker;
else
{
else if( !strcmp( mode, "sort-by-size" ) )
sort_func = compareBySize;
else {
sort_func = compareByName;
type = isReversed ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING;
}

View File

@ -35,10 +35,11 @@ static const char * fallback_ui_file =
" <separator/>\n"
" <menuitem action='sort-by-activity'/>\n"
" <menuitem action='sort-by-age'/>\n"
" <menuitem action='sort-by-eta'/>\n"
" <menuitem action='sort-by-name'/>\n"
" <menuitem action='sort-by-progress'/>\n"
" <menuitem action='sort-by-eta'/>\n"
" <menuitem action='sort-by-ratio'/>\n"
" <menuitem action='sort-by-size'/>\n"
" <menuitem action='sort-by-state'/>\n"
" <menuitem action='sort-by-tracker'/>\n"
" <separator/>\n"