1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-03 05:25:52 +00:00

(trunk gtk/qt) #1502: Details' Addresses should "sort -n"

This commit is contained in:
Charles Kerr 2009-04-16 16:35:00 +00:00
parent bee21fb545
commit 3f00d88ed8
2 changed files with 26 additions and 20 deletions

View file

@ -83,6 +83,7 @@ webseed_model_new( const tr_torrent * tor )
enum enum
{ {
PEER_COL_ADDRESS, PEER_COL_ADDRESS,
PEER_COL_ADDRESS_COLLATED,
PEER_COL_DOWNLOAD_RATE, PEER_COL_DOWNLOAD_RATE,
PEER_COL_UPLOAD_RATE, PEER_COL_UPLOAD_RATE,
PEER_COL_CLIENT, PEER_COL_CLIENT,
@ -128,13 +129,21 @@ peer_row_set( GtkListStore * store,
GtkTreeIter * iter, GtkTreeIter * iter,
const tr_peer_stat * peer ) const tr_peer_stat * peer )
{ {
int quads[4];
char buf[128];
const char * client = peer->client; const char * client = peer->client;
if( !client || !strcmp( client, "Unknown Client" ) ) if( !client || !strcmp( client, "Unknown Client" ) )
client = " "; client = " ";
if( sscanf( peer->addr, "%d.%d.%d.%d", quads, quads+1, quads+2, quads+3 ) == 4 )
g_snprintf( buf, sizeof( buf ), "%03d.%03d.%03d.%03d", quads[0], quads[1], quads[2], quads[3] );
else
g_strlcpy( buf, peer->addr, sizeof( buf ) );
gtk_list_store_set( store, iter, gtk_list_store_set( store, iter,
PEER_COL_ADDRESS, peer->addr, PEER_COL_ADDRESS, peer->addr,
PEER_COL_ADDRESS_COLLATED, buf,
PEER_COL_CLIENT, client, PEER_COL_CLIENT, client,
PEER_COL_IS_ENCRYPTED, peer->isEncrypted, PEER_COL_IS_ENCRYPTED, peer->isEncrypted,
PEER_COL_PROGRESS, (int)( 100.0 * peer->progress ), PEER_COL_PROGRESS, (int)( 100.0 * peer->progress ),
@ -163,12 +172,13 @@ static GtkTreeModel*
peer_model_new( tr_torrent * tor ) peer_model_new( tr_torrent * tor )
{ {
GtkListStore * m = gtk_list_store_new( N_PEER_COLS, GtkListStore * m = gtk_list_store_new( N_PEER_COLS,
G_TYPE_STRING, /* addr */ G_TYPE_STRING, /* address */
G_TYPE_FLOAT, /* downloadFromRate */ G_TYPE_STRING, /* collated address */
G_TYPE_FLOAT, /* uploadToRate */ G_TYPE_FLOAT, /* downloadFromRate */
G_TYPE_STRING, /* client */ G_TYPE_FLOAT, /* uploadToRate */
G_TYPE_INT, /* progress [0..100] */ G_TYPE_STRING, /* client */
G_TYPE_BOOLEAN, /* isEncrypted */ G_TYPE_INT, /* progress [0..100] */
G_TYPE_BOOLEAN, /* isEncrypted */
G_TYPE_STRING ); /* flagString */ G_TYPE_STRING ); /* flagString */
int n_peers = 0; int n_peers = 0;
@ -485,6 +495,7 @@ peer_page_new( TrTorrent * gtor )
for( i = 0; i < G_N_ELEMENTS( view_columns ); ++i ) for( i = 0; i < G_N_ELEMENTS( view_columns ); ++i )
{ {
const int col = view_columns[i]; const int col = view_columns[i];
int sort_col = col;
const char * t = _( peer_column_names[col] ); const char * t = _( peer_column_names[col] );
GtkTreeViewColumn * c; GtkTreeViewColumn * c;
GtkCellRenderer * r; GtkCellRenderer * r;
@ -494,6 +505,7 @@ peer_page_new( TrTorrent * gtor )
case PEER_COL_ADDRESS: case PEER_COL_ADDRESS:
r = gtk_cell_renderer_text_new( ); r = gtk_cell_renderer_text_new( );
c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL ); c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
sort_col = PEER_COL_ADDRESS_COLLATED;
break; break;
case PEER_COL_CLIENT: case PEER_COL_CLIENT:
@ -537,7 +549,7 @@ peer_page_new( TrTorrent * gtor )
} }
gtk_tree_view_column_set_resizable( c, FALSE ); gtk_tree_view_column_set_resizable( c, FALSE );
gtk_tree_view_column_set_sort_column_id( c, col ); gtk_tree_view_column_set_sort_column_id( c, sort_col );
gtk_tree_view_append_column( GTK_TREE_VIEW( v ), c ); gtk_tree_view_append_column( GTK_TREE_VIEW( v ), c );
} }

View file

@ -80,17 +80,9 @@ namespace
class PeerItem: public QTreeWidgetItem class PeerItem: public QTreeWidgetItem
{ {
Peer peer; Peer peer;
int quads[4]; QString collatedAddress;
QString status; QString status;
bool quadsLessThan( const PeerItem * that ) const {
for( int i=0; i<4; ++i ) {
if( quads[i] < that->quads[i] ) return true;
if( quads[i] > that->quads[i] ) return false;
}
return false;
}
public: public:
PeerItem( ) { } PeerItem( ) { }
virtual ~PeerItem( ) { } virtual ~PeerItem( ) { }
@ -101,9 +93,11 @@ class PeerItem: public QTreeWidgetItem
} }
void setPeer( const Peer& p ) { void setPeer( const Peer& p ) {
peer = p; peer = p;
const QStringList tokens( p.address.split(".") ); int quads[4];
for( int i=0; i<4; ++i ) if( sscanf( p.address.toUtf8().constData(), "%d.%d.%d.%d", quads+0, quads+1, quads+2, quads+3 ) == 4 )
quads[i] = tokens.at(i).toInt(); collatedAddress.sprintf( "%03d.%03d.%03d.%03d", quads[0], quads[1], quads[2], quads[3] );
else
collatedAddress = p.address;
} }
virtual bool operator< ( const QTreeWidgetItem & other ) const { virtual bool operator< ( const QTreeWidgetItem & other ) const {
const PeerItem * that = dynamic_cast<const PeerItem*>(&other); const PeerItem * that = dynamic_cast<const PeerItem*>(&other);
@ -114,7 +108,7 @@ class PeerItem: public QTreeWidgetItem
case COL_DOWN: return peer.rateToClient < that->peer.rateToClient; case COL_DOWN: return peer.rateToClient < that->peer.rateToClient;
case COL_PERCENT: return peer.progress < that->peer.progress; case COL_PERCENT: return peer.progress < that->peer.progress;
case COL_STATUS: return status < that->status; case COL_STATUS: return status < that->status;
case COL_ADDRESS: return quadsLessThan( that ); case COL_ADDRESS: return collatedAddress < that->collatedAddress;
case COL_CLIENT: return peer.clientName < that->peer.clientName; case COL_CLIENT: return peer.clientName < that->peer.clientName;
default: /*COL_LOCK*/ return peer.isEncrypted && !that->peer.isEncrypted; default: /*COL_LOCK*/ return peer.isEncrypted && !that->peer.isEncrypted;
} }