mirror of
https://github.com/transmission/transmission
synced 2024-12-23 08:13:27 +00:00
(gtk) #1472: More detailed warning on removing active torrents
This commit is contained in:
parent
10714dc224
commit
79e546fe9c
1 changed files with 59 additions and 24 deletions
|
@ -182,14 +182,20 @@ removeResponse( GtkDialog * dialog,
|
||||||
g_free( data );
|
g_free( data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct count_data
|
||||||
|
{
|
||||||
|
int incomplete;
|
||||||
|
int connected;
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
countBusyTorrents( gpointer gtor,
|
countBusyTorrents( gpointer gtor, gpointer gdata )
|
||||||
gpointer busyCount )
|
|
||||||
{
|
{
|
||||||
const tr_stat * stat = tr_torrent_stat( gtor );
|
const tr_stat * stat = tr_torrent_stat( gtor );
|
||||||
|
struct count_data * data = gdata;
|
||||||
|
|
||||||
if( stat->leftUntilDone || stat->peersConnected )
|
if( stat->leftUntilDone ) ++data->incomplete;
|
||||||
++( *(int*)busyCount );
|
if( stat->peersConnected ) ++data->connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -199,11 +205,11 @@ confirmRemove( GtkWindow * parent,
|
||||||
gboolean delete_files )
|
gboolean delete_files )
|
||||||
{
|
{
|
||||||
GtkWidget * d;
|
GtkWidget * d;
|
||||||
struct DeleteData * dd;
|
|
||||||
int busyCount;
|
|
||||||
const int count = g_slist_length( torrents );
|
const int count = g_slist_length( torrents );
|
||||||
|
struct count_data counts;
|
||||||
const char * primary_text;
|
const char * primary_text;
|
||||||
const char * secondary_text;
|
GString * secondary_text;
|
||||||
|
struct DeleteData * dd;
|
||||||
|
|
||||||
if( !count )
|
if( !count )
|
||||||
return;
|
return;
|
||||||
|
@ -213,10 +219,11 @@ confirmRemove( GtkWindow * parent,
|
||||||
dd->torrents = torrents;
|
dd->torrents = torrents;
|
||||||
dd->delete_files = delete_files;
|
dd->delete_files = delete_files;
|
||||||
|
|
||||||
busyCount = 0;
|
counts.incomplete = 0;
|
||||||
g_slist_foreach( torrents, countBusyTorrents, &busyCount );
|
counts.connected = 0;
|
||||||
|
g_slist_foreach( torrents, countBusyTorrents, &counts );
|
||||||
|
|
||||||
if( !busyCount && !delete_files ) /* don't prompt boring torrents */
|
if( !counts.incomplete && !counts.connected && !delete_files ) /* don't prompt boring torrents */
|
||||||
{
|
{
|
||||||
removeTorrents( dd );
|
removeTorrents( dd );
|
||||||
g_free( dd );
|
g_free( dd );
|
||||||
|
@ -224,23 +231,50 @@ confirmRemove( GtkWindow * parent,
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !delete_files )
|
if( !delete_files )
|
||||||
primary_text = ngettext( "Remove torrent?", "Remove torrents?",
|
{
|
||||||
|
primary_text = ngettext( "Remove torrent?",
|
||||||
|
"Remove torrents?",
|
||||||
count );
|
count );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
primary_text = ngettext( "Delete this torrent's downloaded files?",
|
primary_text = ngettext( "Delete this torrent's downloaded files?",
|
||||||
"Delete these torrents' downloaded files?",
|
"Delete these torrents' downloaded files?",
|
||||||
count );
|
count );
|
||||||
|
}
|
||||||
|
|
||||||
if( busyCount > 1 )
|
secondary_text = g_string_new( NULL );
|
||||||
secondary_text = _(
|
|
||||||
"Some of these torrents are incomplete or connected to peers." );
|
if( !counts.incomplete && !counts.connected )
|
||||||
else if( busyCount == 0 )
|
{
|
||||||
secondary_text = NULL;
|
/* boring -- no secondary text needed */
|
||||||
|
}
|
||||||
|
else if( count == counts.incomplete )
|
||||||
|
{
|
||||||
|
g_string_assign( secondary_text, ngettext( "This torrent has not finished downloading.",
|
||||||
|
"These torrents have not finished downloading.",
|
||||||
|
count ) );
|
||||||
|
}
|
||||||
|
else if( count == counts.connected )
|
||||||
|
{
|
||||||
|
g_string_assign( secondary_text, ngettext( "This torrent is connected to peers.",
|
||||||
|
"These torrents are connected to peers.",
|
||||||
|
count ) );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
secondary_text = ngettext(
|
{
|
||||||
"This torrent is incomplete or connected to peers.",
|
if( counts.connected )
|
||||||
"One of these torrents is incomplete or connected to peers.",
|
g_string_append( secondary_text, ngettext( "One of these torrents is connected to peers.",
|
||||||
count );
|
"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, 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,
|
d = gtk_message_dialog_new_with_markup( parent,
|
||||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||||
|
@ -248,9 +282,9 @@ confirmRemove( GtkWindow * parent,
|
||||||
GTK_BUTTONS_NONE,
|
GTK_BUTTONS_NONE,
|
||||||
"<big><b>%s</b></big>",
|
"<big><b>%s</b></big>",
|
||||||
primary_text );
|
primary_text );
|
||||||
if( secondary_text )
|
if( secondary_text->len )
|
||||||
gtk_message_dialog_format_secondary_markup( GTK_MESSAGE_DIALOG( d ),
|
gtk_message_dialog_format_secondary_markup( GTK_MESSAGE_DIALOG( d ),
|
||||||
"%s", secondary_text );
|
"%s", secondary_text->str );
|
||||||
gtk_dialog_add_buttons( GTK_DIALOG( d ),
|
gtk_dialog_add_buttons( GTK_DIALOG( d ),
|
||||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||||
( delete_files ? GTK_STOCK_DELETE :
|
( delete_files ? GTK_STOCK_DELETE :
|
||||||
|
@ -264,5 +298,6 @@ confirmRemove( GtkWindow * parent,
|
||||||
-1 );
|
-1 );
|
||||||
g_signal_connect( d, "response", G_CALLBACK( removeResponse ), dd );
|
g_signal_connect( d, "response", G_CALLBACK( removeResponse ), dd );
|
||||||
gtk_widget_show_all( d );
|
gtk_widget_show_all( d );
|
||||||
}
|
|
||||||
|
|
||||||
|
g_string_free( secondary_text, TRUE );
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue