]> granicus.if.org Git - transmission/commitdiff
(gtk) #745: sort transfers by ratio
authorCharles Kerr <charles@transmissionbt.com>
Sun, 6 Apr 2008 14:07:41 +0000 (14:07 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Sun, 6 Apr 2008 14:07:41 +0000 (14:07 +0000)
gtk/actions.c
gtk/makemeta-ui.c
gtk/tr-core.c
gtk/tr-prefs.c
gtk/ui.h

index 6b881e225b9cc259bfb9f939c77398c12642afc8..49ff409120021830073e39931926039b2ae08de2 100644 (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
index d1a2be6501bbba36d43b0d0e594fd9952a63ce90..2d724f038ec07dcb68378b701e6bd09ab2584bc7 100644 (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;
index 6800a14443f14c9d247cd1055db4115dd1ee5a3b..8e5aa2eae717808128fcd13da46f52b1e4fe591f 100644 (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 );
 }
 
index c9e981711393d1b538c4d3b894bdbd28d4b68c7e..e7eb4f4aa438c04d3fde491f44f1d99be732a3a2 100644 (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 );
 
index b76c61b75cbaeb3a475a2a4eef6ac9464e46266a..dffedf11b473fe7242f27d995d5d74bd355aed3f 100644 (file)
--- a/gtk/ui.h
+++ b/gtk/ui.h
@@ -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"