Changeset 7117


Ignore:
Timestamp:
Nov 16, 2008, 7:11:34 AM (12 years ago)
Author:
charles
Message:

(gtk) #1472: More detailed warning on removing active torrents

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/dialogs.c

    r6935 r7117  
    183183}
    184184
     185struct count_data
     186{
     187    int incomplete;
     188    int connected;
     189};
     190
    185191static void
    186 countBusyTorrents( gpointer gtor,
    187                    gpointer busyCount )
     192countBusyTorrents( gpointer gtor, gpointer gdata )
    188193{
    189194    const tr_stat * stat = tr_torrent_stat( gtor );
    190 
    191     if( stat->leftUntilDone || stat->peersConnected )
    192         ++( *(int*)busyCount );
     195    struct count_data * data = gdata;
     196
     197    if( stat->leftUntilDone ) ++data->incomplete;
     198    if( stat->peersConnected ) ++data->connected;
    193199}
    194200
     
    200206{
    201207    GtkWidget *         d;
     208    const int           count = g_slist_length( torrents );
     209    struct count_data   counts;
     210    const char        * primary_text;
     211    GString           * secondary_text;
    202212    struct DeleteData * dd;
    203     int                 busyCount;
    204     const int           count = g_slist_length( torrents );
    205     const char *        primary_text;
    206     const char *        secondary_text;
    207213
    208214    if( !count )
     
    214220    dd->delete_files = delete_files;
    215221
    216     busyCount = 0;
    217     g_slist_foreach( torrents, countBusyTorrents, &busyCount );
    218 
    219     if( !busyCount && !delete_files ) /* don't prompt boring torrents */
     222    counts.incomplete = 0;
     223    counts.connected = 0;
     224    g_slist_foreach( torrents, countBusyTorrents, &counts );
     225
     226    if( !counts.incomplete && !counts.connected && !delete_files ) /* don't prompt boring torrents */
    220227    {
    221228        removeTorrents( dd );
     
    225232
    226233    if( !delete_files )
    227         primary_text = ngettext( "Remove torrent?", "Remove torrents?",
     234    {
     235        primary_text = ngettext( "Remove torrent?",
     236                                 "Remove torrents?",
    228237                                 count );
     238    }
    229239    else
     240    {
    230241        primary_text = ngettext( "Delete this torrent's downloaded files?",
    231242                                 "Delete these torrents' downloaded files?",
    232243                                 count );
    233 
    234     if( busyCount > 1 )
    235         secondary_text = _(
    236             "Some of these torrents are incomplete or connected to peers." );
    237     else if( busyCount == 0 )
    238         secondary_text = NULL;
     244    }
     245
     246    secondary_text = g_string_new( NULL );
     247
     248    if( !counts.incomplete && !counts.connected )
     249    {
     250        /* boring -- no secondary text needed */
     251    }
     252    else if( count == counts.incomplete )
     253    {
     254        g_string_assign( secondary_text, ngettext( "This torrent has not finished downloading.",
     255                                                   "These torrents have not finished downloading.",
     256                                                   count ) );
     257    }
     258    else if( count == counts.connected )
     259    {
     260        g_string_assign( secondary_text, ngettext( "This torrent is connected to peers.",
     261                                                   "These torrents are connected to peers.",
     262                                                   count ) );
     263    }
    239264    else
    240         secondary_text = ngettext(
    241             "This torrent is incomplete or connected to peers.",
    242             "One of these torrents is incomplete or connected to peers.",
    243             count );
     265    {
     266        if( counts.connected )
     267            g_string_append( secondary_text, ngettext( "One of these torrents is connected to peers.",
     268                                                       "Some of these torrents are connected to peers.",
     269                                                       counts.connected ) );
     270        if( counts.connected && counts.incomplete )
     271            g_string_append( secondary_text, "\n" );
     272 
     273        if( counts.incomplete )
     274            g_string_assign( secondary_text, ngettext( "One of these torrents has not finished downloading.",
     275                                                       "Some of these torrents have not finished downloading.",
     276                                                       counts.incomplete ) );
     277    }
    244278
    245279    d = gtk_message_dialog_new_with_markup( parent,
     
    249283                                            "<big><b>%s</b></big>",
    250284                                            primary_text );
    251     if( secondary_text )
     285    if( secondary_text->len )
    252286        gtk_message_dialog_format_secondary_markup( GTK_MESSAGE_DIALOG( d ),
    253                                                     "%s", secondary_text );
     287                                                    "%s", secondary_text->str );
    254288    gtk_dialog_add_buttons( GTK_DIALOG( d ),
    255289                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
     
    265299    g_signal_connect( d, "response", G_CALLBACK( removeResponse ), dd );
    266300    gtk_widget_show_all( d );
    267 }
    268 
     301
     302    g_string_free( secondary_text, TRUE );
     303}
Note: See TracChangeset for help on using the changeset viewer.