(trunk, gtk/qt) use Monsoon's strings for encryption preferences and Deluge's system tray tooltip.

This commit is contained in:
Charles Kerr 2009-06-30 18:08:50 +00:00
parent 07046a26b2
commit 58ba65f55b
10 changed files with 66 additions and 81 deletions

View File

@ -718,45 +718,6 @@ tr_core_session( TrCore * core )
return isDisposed( core ) ? NULL : core->priv->session;
}
static gboolean
statsForeach( GtkTreeModel * model,
GtkTreePath * path UNUSED,
GtkTreeIter * iter,
gpointer gstats )
{
tr_torrent * tor;
struct core_stats * stats = gstats;
int activity;
gtk_tree_model_get( model, iter, MC_TORRENT_RAW, &tor, -1 );
activity = tr_torrentGetActivity( tor );
if( activity == TR_STATUS_DOWNLOAD )
++stats->downloadCount;
else if( activity == TR_STATUS_SEED )
++stats->seedingCount;
return FALSE;
}
void
tr_core_get_stats( const TrCore * core,
struct core_stats * setme )
{
memset( setme, 0, sizeof( struct core_stats ) );
if( !isDisposed( core ) )
{
tr_session * session = core->priv->session;
setme->clientDownloadSpeed = tr_sessionGetPieceSpeed( session, TR_DOWN );
setme->clientUploadSpeed = tr_sessionGetPieceSpeed( session, TR_UP );
gtk_tree_model_foreach( core->priv->model, statsForeach, setme );
}
}
static char*
doCollate( const char * in )
{

View File

@ -45,14 +45,6 @@
TR_CORE_TYPE, \
TrCoreClass )
struct core_stats
{
int downloadCount;
int seedingCount;
float clientDownloadSpeed;
float clientUploadSpeed;
};
typedef struct TrCore
{
GObject parent;
@ -110,9 +102,6 @@ GtkTreeModel * tr_core_model( TrCore * self );
tr_session * tr_core_session( TrCore * self );
void tr_core_get_stats( const TrCore * core,
struct core_stats * setme );
/******
*******
******/

View File

@ -51,25 +51,53 @@ popup( GtkStatusIcon * self,
static gboolean
refresh_tooltip_cb( gpointer data )
{
GtkStatusIcon * icon = GTK_STATUS_ICON( data );
TrCore * core = g_object_get_data( G_OBJECT( icon ), "tr-core" );
struct core_stats stats;
char downStr[32], upStr[32];
char tip[256];
double d;
int limit;
char up[64];
char upLimit[64];
char down[64];
char downLimit[64];
char tip[1024];
const char * idle = _( "Idle" );
GtkStatusIcon * icon = GTK_STATUS_ICON( data );
tr_session * session = tr_core_session( g_object_get_data( G_OBJECT( icon ), "tr-core" ) );
tr_core_get_stats( core, &stats );
/* up */
if(((d = tr_sessionGetRawSpeed( session, TR_UP ))) < 0.1 )
g_strlcpy( up, idle, sizeof( up ) );
else
tr_strlspeed( up, d, sizeof( up ) );
/* up limit */
if( !tr_sessionGetActiveSpeedLimit( session, TR_UP, &limit ) )
*upLimit = '\0';
else {
char buf[64];
tr_strlspeed( buf, limit, sizeof( buf ) );
g_snprintf( upLimit, sizeof( upLimit ), _( "(Limit: %s)" ), buf );
}
/* down */
if(((d = tr_sessionGetRawSpeed( session, TR_DOWN ))) < 0.1 )
g_strlcpy( down, idle, sizeof( down ) );
else
tr_strlspeed( down, d, sizeof( down ) );
/* down limit */
if( !tr_sessionGetActiveSpeedLimit( session, TR_DOWN, &limit ) )
*downLimit = '\0';
else {
char buf[64];
tr_strlspeed( buf, limit, sizeof( buf ) );
g_snprintf( downLimit, sizeof( downLimit ), _( "(Limit: %s)" ), buf );
}
/* %1$s: current upload speed
* %2$s: current upload limit, if any
* %3$s: current download speed
* %4$s: current download limit, if any */
g_snprintf( tip, sizeof( tip ), _( "Transmission\nUp: %1$s %2$s\nDown: %3$s %4$s" ), up, upLimit, down, downLimit );
tr_strlspeed( downStr, stats.clientDownloadSpeed, sizeof( downStr ) );
tr_strlspeed( upStr, stats.clientUploadSpeed, sizeof( upStr ) );
g_snprintf( tip, sizeof( tip ),
/* %1$'d is the number of torrents we're seeding,
%2$'d is the number of torrents we're downloading,
%3$s is our download speed,
%4$s is our upload speed */
_( "%1$'d Seeding, %2$'d Downloading\nDown: %3$s, Up: %4$s" ),
stats.seedingCount,
stats.downloadCount,
downStr, upStr );
#if GTK_CHECK_VERSION( 2,16,0 )
gtk_status_icon_set_tooltip_text( GTK_STATUS_ICON( icon ), tip );
#else

View File

@ -455,9 +455,9 @@ new_encryption_combo( GObject * core, const char * key )
int value;
const char * text;
} items[] = {
{ TR_CLEAR_PREFERRED, N_( "Plaintext preferred" ) },
{ TR_ENCRYPTION_PREFERRED, N_( "Encryption preferred" ) },
{ TR_ENCRYPTION_REQUIRED, N_( "Encryption required" ) }
{ TR_CLEAR_PREFERRED, N_( "Allow encryption" ) },
{ TR_ENCRYPTION_PREFERRED, N_( "Prefer encryption" ) },
{ TR_ENCRYPTION_REQUIRED, N_( "Require encryption" ) }
};
/* build a store for encryption */
@ -1398,7 +1398,7 @@ tr_prefs_dialog_new( GObject * core,
gtk_label_new ( _( "Privacy" ) ) );
gtk_notebook_append_page( GTK_NOTEBOOK( n ),
peerPage( core ),
gtk_label_new ( _( "Peers" ) ) );
gtk_label_new ( _( "Network" ) ) );
gtk_notebook_append_page( GTK_NOTEBOOK( n ),
desktopPage( core ),
gtk_label_new ( _( "Desktop" ) ) );

View File

@ -284,6 +284,8 @@ privateFree( gpointer vprivate )
PrivateData * p = vprivate;
g_signal_handler_disconnect( p->core, p->pref_handler_id );
g_object_unref( G_OBJECT( p->alt_speed_image[1] ) );
g_object_unref( G_OBJECT( p->alt_speed_image[0] ) );
g_free( p->filter_text );
g_free( p );
}

View File

@ -1026,6 +1026,9 @@ tr_sessionGetActiveSpeedLimit( const tr_session * session, tr_direction dir, int
{
int isLimited = TRUE;
if( !tr_isSession( session ) )
return FALSE;
if( tr_sessionUsesAltSpeed( session ) )
*setme = tr_sessionGetAltSpeed( session, dir );
else if( tr_sessionIsSpeedLimited( session, dir ) )

View File

@ -140,10 +140,6 @@ struct tr_session
tr_bool tr_sessionAllowsDHT( const tr_session * session );
tr_bool tr_sessionGetActiveSpeedLimit( const tr_session * session,
tr_direction dir,
int * setme );
const char * tr_sessionFindTorrentFile( const tr_session * session,
const char * hashString );

View File

@ -629,6 +629,12 @@ typedef void ( tr_altSpeedFunc ) ( tr_session *, tr_bool active, tr_bool us
void tr_sessionClearAltSpeedFunc ( tr_session * );
void tr_sessionSetAltSpeedFunc ( tr_session *, tr_altSpeedFunc *, void * );
tr_bool tr_sessionGetActiveSpeedLimit( const tr_session * session,
tr_direction dir,
int * setme );
/***
****
***/

View File

@ -360,7 +360,7 @@ PrefsDialog :: onPortTest( )
}
QWidget *
PrefsDialog :: createPeersTab( )
PrefsDialog :: createNetworkTab( )
{
HIG * hig = new HIG( this );
hig->addSectionTitle( tr( "Incoming Peers" ) );
@ -463,9 +463,9 @@ PrefsDialog :: createPrivacyTab( )
hig->addWideControl( l );
QComboBox * box = new QComboBox( );
box->addItem( tr( "Plaintext preferred" ), 0 );
box->addItem( tr( "Encryption preferred" ), 1 );
box->addItem( tr( "Encryption required" ), 2 );
box->addItem( tr( "Allow encryption" ), 0 );
box->addItem( tr( "Prefer encryption" ), 1 );
box->addItem( tr( "Require encryption" ), 2 );
myWidgets.insert( Prefs :: ENCRYPTION, box );
connect( box, SIGNAL(activated(int)), this, SLOT(encryptionEdited(int)));
@ -578,7 +578,7 @@ PrefsDialog :: PrefsDialog( Session& session, Prefs& prefs, QWidget * parent ):
t->addTab( createTorrentsTab( ), tr( "Torrents" ) );
t->addTab( createSpeedTab( ), tr( "Speed" ) );
t->addTab( createPrivacyTab( ), tr( "Privacy" ) );
t->addTab( createPeersTab( ), tr( "Peers" ) );
t->addTab( createNetworkTab( ), tr( "Network" ) );
t->addTab( createWebTab( session ), tr( "Web" ) );
//t->addTab( createTrackerTab( ), tr( "Trackers" ) );
myLayout->addWidget( t );

View File

@ -78,7 +78,7 @@ class PrefsDialog: public QDialog
private:
bool isAllowed( int key ) const;
QWidget * createTorrentsTab( );
QWidget * createPeersTab( );
QWidget * createNetworkTab( );
QWidget * createPrivacyTab( );
QWidget * createSpeedTab( );
QWidget * createWebTab( Session& );