Changeset 5216


Ignore:
Timestamp:
Mar 7, 2008, 5:47:42 PM (14 years ago)
Author:
charles
Message:

(gtk) #769: when removing a torrent, prompt for confirmation if (a) the torrent is incomplete, (b) the torrent is connected to peers, (c) the user is also deleting the downloaded files.

Location:
trunk/gtk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/actions.c

    r5209 r5216  
    111111  { "pause-torrent", GTK_STOCK_MEDIA_PAUSE,
    112112    N_("_Pause"), "<control>P", NULL, G_CALLBACK(action_cb) },
    113   { "close-torrent", GTK_STOCK_CLOSE, NULL, "Delete", NULL, G_CALLBACK(action_cb) },
    114   { "delete-torrent", GTK_STOCK_DELETE, N_("_Delete Files and Close"), "<control>Delete", NULL, G_CALLBACK(action_cb) },
     113  { "remove-torrent", GTK_STOCK_REMOVE, NULL, "Delete", NULL, G_CALLBACK(action_cb) },
     114  { "delete-torrent", GTK_STOCK_DELETE, N_("_Delete Files and Remove"), "<control>Delete", NULL, G_CALLBACK(action_cb) },
    115115  { "new-torrent", GTK_STOCK_NEW, N_("_New..."), NULL,
    116116    N_("Create a new torrent"),
  • trunk/gtk/dialogs.c

    r5209 r5216  
    293293    GList * torrents;
    294294    TrCore * core;
     295    int busyCount;
    295296};
    296297
    297298static void
     299removeTorrents( struct DeleteData * data )
     300{
     301    GList * l;
     302    for( l=data->torrents; l!=NULL; l=l->next )
     303        tr_core_remove_torrent( data->core, l->data, data->delete_files );
     304    g_list_free( data->torrents );
     305}
     306
     307
     308static void
    298309removeResponse( GtkDialog * dialog, gint response, gpointer gdata )
    299310{
    300311    struct DeleteData * data = gdata;
    301     const int doRemove = response == GTK_RESPONSE_ACCEPT;
    302     const int doDelete = data->delete_files;
    303     GList * l;
    304 
    305     for( l=data->torrents; l!=NULL; l=l->next )
    306     {
    307         TrTorrent * gtor = TR_TORRENT( l->data );
    308 
    309         if( doRemove )
    310             tr_core_remove_torrent( data->core, gtor, doDelete );
    311         else
    312             g_object_unref( G_OBJECT( gtor ) );
    313     }
     312
     313    if( response == GTK_RESPONSE_ACCEPT )
     314        removeTorrents( data );
     315    else
     316        g_list_foreach( data->torrents, (GFunc)g_object_unref, NULL );
    314317
    315318    gtk_widget_destroy( GTK_WIDGET( dialog ) );
    316     g_list_free( data->torrents );
    317319    g_free( data );
    318320}
    319321
     322static void
     323tabulateTorrents( gpointer gtor, gpointer gdata )
     324{
     325    struct DeleteData * data = gdata;
     326    const tr_stat * stat = tr_torrent_stat( gtor );
     327
     328    if( stat->leftUntilDone || stat->peersConnected )
     329        ++data->busyCount;
     330}
     331
    320332void
    321 confirmDelete( GtkWindow * parent,
     333confirmRemove( GtkWindow * parent,
    322334               TrCore    * core,
    323                GList     * torrents )
     335               GList     * torrents,
     336               gboolean    delete_files )
    324337{
    325338    GtkWidget * d;
    326     char text[128];
    327     struct DeleteData * dd = g_new0( struct DeleteData, 1 );
    328 
     339    struct DeleteData * dd;
     340    const int count = g_list_length( torrents );
     341    const char * primary_text;
     342    const char * secondary_text;
     343
     344    if( !count )
     345        return;
     346
     347    dd = g_new0( struct DeleteData, 1 );
    329348    dd->core = core;
    330349    dd->torrents = torrents;
    331     dd->delete_files = TRUE;
    332 
    333     g_snprintf( text, sizeof( text ),
    334                 ngettext( "Delete torrent?",
    335                           "Delete torrents?",
    336                           g_list_length( torrents ) ) );
     350    dd->delete_files = delete_files;
     351
     352    g_list_foreach( torrents, tabulateTorrents, dd );
     353
     354    if( !dd->busyCount && !delete_files ) /* don't prompt boring torrents */
     355    {
     356        removeTorrents( dd );
     357        g_free( dd );
     358        return;
     359    }
     360
     361    if( !delete_files )
     362        primary_text = ngettext( "Remove torrent?", "Remove torrents?", count );
     363    else
     364        primary_text = ngettext( "Delete this torrent's downloaded files?",
     365                                 "Delete these torrents' downloaded files?",
     366                                 count );
     367
     368    if( dd->busyCount > 1 )
     369        secondary_text = _( "Some of these torrents are incomplete or connected to peers." );
     370    else if( dd->busyCount == 0 )
     371        secondary_text = NULL;
     372    else
     373        secondary_text = ngettext( "This torrent is incomplete or connected to peers.",
     374                                   "One of these torrents is incomplete or connected to peers.",
     375                                   count );
     376
    337377    d = gtk_message_dialog_new_with_markup( parent,
    338378                                            GTK_DIALOG_DESTROY_WITH_PARENT,
    339                                             GTK_MESSAGE_WARNING,
     379                                            ( delete_files ? GTK_MESSAGE_WARNING : GTK_MESSAGE_QUESTION ),
    340380                                            GTK_BUTTONS_NONE,
    341                                             "<b>%s</b>", text );
    342     gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( d ),
    343             _( "This removes the torrent and deletes the downloaded files!" ) );
     381                                            "<b>%s</b>", primary_text );
     382    if( secondary_text )
     383        gtk_message_dialog_format_secondary_markup( GTK_MESSAGE_DIALOG( d ), secondary_text );
    344384    gtk_dialog_add_buttons( GTK_DIALOG( d ),
    345385                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    346                             GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT,
     386                            (delete_files ? GTK_STOCK_DELETE : GTK_STOCK_REMOVE), GTK_RESPONSE_ACCEPT,
    347387                            NULL );
    348388    gtk_dialog_set_default_response( GTK_DIALOG ( d ),
  • trunk/gtk/dialogs.h

    r5209 r5216  
    3939void askquit( TrCore*, GtkWindow* parent, callbackfunc_t func, void* cbdata );
    4040
    41 void confirmDelete( GtkWindow * parent, TrCore * core, GList * torrents );
     41void confirmRemove( GtkWindow * parent,
     42                    TrCore    * core,
     43                    GList     * gtorrents,
     44                    gboolean    doDelete );
    4245
    4346#endif /* TG_PREFS_H */
  • trunk/gtk/main.c

    r5215 r5216  
    200200    action_sensitize( "pause-torrent", counts.activeCount!=0 );
    201201    action_sensitize( "start-torrent", counts.inactiveCount!=0 );
    202     action_sensitize( "close-torrent", counts.totalCount!=0 );
     202    action_sensitize( "remove-torrent", counts.totalCount!=0 );
    203203    action_sensitize( "delete-torrent", counts.totalCount!=0 );
    204204    action_sensitize( "verify-torrent", counts.totalCount!=0 );
     
    10381038
    10391039static void
    1040 closeSelectedForeach( gpointer gtor, gpointer gdata )
    1041 {
    1042     struct cbdata * data = gdata;
    1043     tr_core_remove_torrent( data->core, gtor, FALSE );
    1044 }
    1045 
    1046 static void
    1047 closeSelected( struct cbdata * data, gboolean doDelete )
     1040removeSelected( struct cbdata * data, gboolean delete_files )
    10481041{
    10491042    GList * l = NULL;
     
    10511044    gtk_tree_selection_selected_foreach( s, accumulateSelectedTorrents, &l );
    10521045    gtk_tree_selection_unselect_all( s );
    1053     if( l ) {
    1054         if( doDelete )
    1055             confirmDelete( data->wind, data->core, l );
    1056         else {
    1057             g_list_foreach( l, closeSelectedForeach, data );
    1058             g_list_free( l );
    1059         }
    1060     }
     1046    if( l )
     1047        confirmRemove( data->wind, data->core, l, delete_files );
    10611048}
    10621049
     
    11121099        gtk_widget_show_all( w );
    11131100    }
    1114     else if( !strcmp( action_name, "close-torrent" ) )
    1115     {
    1116         closeSelected( data, FALSE );
     1101    else if( !strcmp( action_name, "remove-torrent" ) )
     1102    {
     1103        removeSelected( data, FALSE );
    11171104    }
    11181105    else if( !strcmp( action_name, "delete-torrent" ) )
    11191106    {
    1120         closeSelected( data, TRUE );
     1107        removeSelected( data, TRUE );
    11211108    }
    11221109    else if (!strcmp (action_name, "close"))
  • trunk/gtk/ui.h

    r5209 r5216  
    1111"      <menuitem action='verify-torrent'/>\n"
    1212"      <menuitem action='show-torrent-details'/>\n"
    13 "      <menuitem action='close-torrent'/>\n"
     13"      <menuitem action='remove-torrent'/>\n"
    1414"      <menuitem action='delete-torrent'/>\n"
    1515"      <separator/>\n"
     
    5050"    <toolitem action='start-torrent'/>\n"
    5151"    <toolitem action='pause-torrent'/>\n"
    52 "    <toolitem action='close-torrent'/>\n"
     52"    <toolitem action='remove-torrent'/>\n"
    5353"    <separator/>\n"
    5454"    <toolitem action='show-torrent-details'/>\n"
     
    6363"    <menuitem action='update-tracker'/>\n"
    6464"    <separator/>\n"
    65 "    <menuitem action='close-torrent'/>\n"
     65"    <menuitem action='remove-torrent'/>\n"
    6666"    <menuitem action='delete-torrent'/>\n"
    6767"  </popup>\n"
Note: See TracChangeset for help on using the changeset viewer.