char* tr_strltime( char * buf, int seconds, size_t buflen ) { int days, hours, minutes; char d[128], h[128], m[128], s[128]; if( seconds < 0 ) seconds = 0; days = seconds / 86400; hours = ( seconds % 86400 ) / 3600; minutes = ( seconds % 3600 ) / 60; seconds = ( seconds % 3600 ) % 60; g_snprintf( d, sizeof( d ), gtr_ngettext( "%'d day", "%'d days", days ), days ); g_snprintf( h, sizeof( h ), gtr_ngettext( "%'d hour", "%'d hours", hours ), hours ); g_snprintf( m, sizeof( m ), gtr_ngettext( "%'d minute", "%'d minutes", minutes ), minutes ); g_snprintf( s, sizeof( s ), gtr_ngettext( "%'d second", "%'d seconds", seconds ), seconds ); if( days ) { if( days >= 4 || !hours ) { g_strlcpy( buf, d, buflen ); } else { g_snprintf( buf, buflen, "%s, %s", d, h ); } } else if( hours ) { if( hours >= 4 || !minutes ) { g_strlcpy( buf, h, buflen ); } else { g_snprintf( buf, buflen, "%s, %s", h, m ); } } else if( minutes ) { if( minutes >= 4 || !seconds ) { g_strlcpy( buf, m, buflen ); } else { g_snprintf( buf, buflen, "%s, %s", m, s ); } } else { g_strlcpy( buf, s, buflen ); } return buf; }
static gboolean updateStats( gpointer gdata ) { const char * fmt; char buf[128]; struct stat_ui * ui = gdata; tr_session_stats one, all; tr_sessionGetStats( tr_core_session( ui->core ), &one ); tr_sessionGetCumulativeStats( tr_core_session( ui->core ), &all ); setLabel( ui->one_up_lb, tr_strlsize( buf, one.uploadedBytes, sizeof( buf ) ) ); setLabel( ui->one_down_lb, tr_strlsize( buf, one.downloadedBytes, sizeof( buf ) ) ); setLabel( ui->one_time_lb, tr_strltime( buf, one.secondsActive, sizeof( buf ) ) ); setLabelFromRatio( ui->one_ratio_lb, one.ratio ); fmt = gtr_ngettext( "Started %'d time", "Started %'d times", (int)all.sessionCount ); g_snprintf( buf, sizeof( buf ), fmt, (int)all.sessionCount ); setLabel( ui->all_sessions_lb, buf ); setLabel( ui->all_up_lb, tr_strlsize( buf, all.uploadedBytes, sizeof( buf ) ) ); setLabel( ui->all_down_lb, tr_strlsize( buf, all.downloadedBytes, sizeof( buf ) ) ); setLabel( ui->all_time_lb, tr_strltime( buf, all.secondsActive, sizeof( buf ) ) ); setLabelFromRatio( ui->all_ratio_lb, all.ratio ); return TRUE; }
static char* getStatusString( const tr_torrent * tor, const tr_stat * st, const double uploadSpeed_KBps, const double downloadSpeed_KBps ) { const int isActive = st->activity != TR_STATUS_STOPPED; const int isChecking = st->activity == TR_STATUS_CHECK || st->activity == TR_STATUS_CHECK_WAIT; GString * gstr = g_string_new( NULL ); if( st->error ) { const char * fmt[] = { NULL, N_( "Tracker gave a warning: \"%s\"" ), N_( "Tracker gave an error: \"%s\"" ), N_( "Error: %s" ) }; g_string_append_printf( gstr, _( fmt[st->error] ), st->errorString ); } else switch( st->activity ) { case TR_STATUS_STOPPED: case TR_STATUS_CHECK_WAIT: case TR_STATUS_CHECK: { char * pch = getShortStatusString( tor, st, uploadSpeed_KBps, downloadSpeed_KBps ); g_string_assign( gstr, pch ); g_free( pch ); break; } case TR_STATUS_DOWNLOAD: { if( tr_torrentHasMetadata( tor ) ) { g_string_append_printf( gstr, gtr_ngettext( "Downloading from %1$'d of %2$'d connected peer", "Downloading from %1$'d of %2$'d connected peers", st->webseedsSendingToUs + st->peersSendingToUs ), st->webseedsSendingToUs + st->peersSendingToUs, st->webseedsSendingToUs + st->peersConnected ); } else { g_string_append_printf( gstr, gtr_ngettext( "Downloading metadata from %1$'d peer (%2$d%% done)", "Downloading metadata from %1$'d peers (%2$d%% done)", st->peersConnected + st->peersConnected ), st->peersConnected + st->webseedsSendingToUs, (int)(100.0*st->metadataPercentComplete) ); } break; } case TR_STATUS_SEED: g_string_append_printf( gstr, gtr_ngettext( "Seeding to %1$'d of %2$'d connected peer", "Seeding to %1$'d of %2$'d connected peers", st->peersConnected ), st->peersGettingFromUs, st->peersConnected ); break; } if( isActive && !isChecking ) { char buf[256]; getShortTransferString( tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof( buf ) ); if( *buf ) g_string_append_printf( gstr, " - %s", buf ); } return g_string_free( gstr, FALSE ); }
void gtr_confirm_remove( GtkWindow * parent, TrCore * core, GSList * torrents, gboolean delete_files ) { GtkWidget * d; const int count = g_slist_length( torrents ); struct count_data counts; GString * primary_text; GString * secondary_text; struct DeleteData * dd; if( !count ) return; dd = g_new0( struct DeleteData, 1 ); dd->core = core; dd->torrents = torrents; dd->delete_files = delete_files; counts.incomplete = 0; counts.connected = 0; g_slist_foreach( torrents, countBusyTorrents, &counts ); primary_text = g_string_new( NULL ); if( !delete_files ) { g_string_printf( primary_text, gtr_ngettext( "Remove torrent?", "Remove %d torrents?", count ), count ); } else { g_string_printf( primary_text, gtr_ngettext( "Delete this torrent's downloaded files?", "Delete these %d torrents' downloaded files?", count ), count ); } secondary_text = g_string_new( NULL ); if( !counts.incomplete && !counts.connected ) { g_string_assign( secondary_text, gtr_ngettext( "Once removed, continuing the transfer will require the torrent file or magnet link.", "Once removed, continuing the transfers will require the torrent files or magnet links.", count ) ); } else if( count == counts.incomplete ) { g_string_assign( secondary_text, gtr_ngettext( "This torrent has not finished downloading.", "These torrents have not finished downloading.", count ) ); } else if( count == counts.connected ) { g_string_assign( secondary_text, gtr_ngettext( "This torrent is connected to peers.", "These torrents are connected to peers.", count ) ); } else { if( counts.connected ) g_string_append( secondary_text, gtr_ngettext( "One of these torrents is connected to peers.", "Some of these torrents are connected to peers.", counts.connected ) ); if( counts.connected && counts.incomplete ) g_string_append( secondary_text, "\n" ); if( counts.incomplete ) g_string_assign( secondary_text, gtr_ngettext( "One of these torrents has not finished downloading.", "Some of these torrents have not finished downloading.", counts.incomplete ) ); } d = gtk_message_dialog_new_with_markup( parent, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "<big><b>%s</b></big>", primary_text->str ); if( secondary_text->len ) gtk_message_dialog_format_secondary_markup( GTK_MESSAGE_DIALOG( d ), "%s", secondary_text->str ); gtk_dialog_add_buttons( GTK_DIALOG( d ), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, ( delete_files ? GTK_STOCK_DELETE : GTK_STOCK_REMOVE ), GTK_RESPONSE_ACCEPT, NULL ); gtk_dialog_set_default_response( GTK_DIALOG ( d ), GTK_RESPONSE_CANCEL ); gtk_dialog_set_alternative_button_order( GTK_DIALOG( d ), GTK_RESPONSE_ACCEPT, GTK_RESPONSE_CANCEL, -1 ); g_signal_connect( d, "response", G_CALLBACK( removeResponse ), dd ); gtk_widget_show_all( d ); g_string_free( primary_text, TRUE ); g_string_free( secondary_text, TRUE ); }