Changeset 4215


Ignore:
Timestamp:
Dec 19, 2007, 7:03:28 AM (15 years ago)
Author:
charles
Message:

(gtk) add sort-by-ratio

Location:
trunk/gtk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/actions.c

    r4210 r4215  
    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-state",      NULL, N_("Sort by _State"),      NULL, NULL, 4 },
    65   { "sort-by-tracker",    NULL, N_("Sort by _Tracker"),    NULL, NULL, 5 }
     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 }
    6667};
    6768
  • trunk/gtk/main.c

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

    r4210 r4215  
    230230                   gpointer         user_data UNUSED )
    231231{
    232     TrTorrent *ta, *tb;
     232    tr_torrent *ta, *tb;
    233233    const tr_stat *sa, *sb;
    234234    int ret;
    235     gtk_tree_model_get( model, a, MC_TORRENT, &ta, -1 );
    236     gtk_tree_model_get( model, b, MC_TORRENT, &tb, -1 );
    237     sa = tr_torrent_stat( ta );
    238     sb = tr_torrent_stat( tb );
     235    gtk_tree_model_get( model, a, MC_TORRENT_RAW, &ta, -1 );
     236    gtk_tree_model_get( model, b, MC_TORRENT_RAW, &tb, -1 );
     237    sa = tr_torrentStat( ta );
     238    sb = tr_torrentStat( tb );
    239239         if( sa->percentDone < sb->percentDone ) ret = -1;
    240240    else if( sa->percentDone > sb->percentDone ) ret =  1;
    241241    else                                         ret =  0;
    242     g_object_unref( G_OBJECT( tb ) );
    243     g_object_unref( G_OBJECT( ta ) );
     242    return ret;
     243}
     244
     245static int
     246compareByRatio( 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;
    244261    return ret;
    245262}
     
    251268                gpointer         user_data UNUSED )
    252269{
    253     TrTorrent *ta, *tb;
    254     const tr_stat *sa, *sb;
    255     int ret;
    256     gtk_tree_model_get( model, a, MC_TORRENT, &ta, -1 );
    257     gtk_tree_model_get( model, b, MC_TORRENT, &tb, -1 );
    258     sa = tr_torrent_stat( ta );
    259     sb = tr_torrent_stat( tb );
    260     ret = sa->status - sb->status;
    261     g_object_unref( G_OBJECT( ta ) );
    262     g_object_unref( G_OBJECT( tb ) );
    263     return ret;
     270    tr_torrent *ta, *tb;
     271    gtk_tree_model_get( model, a, MC_TORRENT_RAW, &ta, -1 );
     272    gtk_tree_model_get( model, b, MC_TORRENT_RAW, &tb, -1 );
     273    return tr_torrentStat(ta)->status - tr_torrentStat(tb)->status;
    264274}
    265275
     
    270280                  gpointer         user_data UNUSED )
    271281{
    272     TrTorrent *ta, *tb;
    273     const tr_info *ia, *ib;
    274     int ret;
    275     gtk_tree_model_get( model, a, MC_TORRENT, &ta, -1 );
    276     gtk_tree_model_get( model, b, MC_TORRENT, &tb, -1 );
    277     ia = tr_torrent_info( ta );
    278     ib = tr_torrent_info( tb );
    279     ret = strcmp( ia->primaryAddress, ib->primaryAddress );
    280     g_object_unref( G_OBJECT( ta ) );
    281     g_object_unref( G_OBJECT( tb ) );
    282     return ret;
     282    const tr_torrent *ta, *tb;
     283    gtk_tree_model_get( model, a, MC_TORRENT_RAW, &ta, -1 );
     284    gtk_tree_model_get( model, b, MC_TORRENT_RAW, &tb, -1 );
     285    return strcmp( tr_torrentInfo(ta)->primaryAddress,
     286                   tr_torrentInfo(tb)->primaryAddress );
    283287}
    284288
     
    309313        type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
    310314        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 );
    311320    }
    312321    else if( !strcmp( mode, "sort-by-state" ) )
  • trunk/gtk/ui.h

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