diff --git a/gtk/actions.c b/gtk/actions.c index 21468f0ec..dbbac6079 100644 --- a/gtk/actions.c +++ b/gtk/actions.c @@ -115,6 +115,8 @@ static GtkActionEntry entries[] = N_("_Pause"), "P", NULL, G_CALLBACK(action_cb) }, { "remove-torrent", GTK_STOCK_REMOVE, N_("_Remove"), "Delete", NULL, G_CALLBACK(action_cb) }, + { "delete-torrent", GTK_STOCK_DELETE, + N_("_Delete Files"), "Delete", NULL, G_CALLBACK(action_cb) }, { "new-torrent", GTK_STOCK_NEW, N_("_New..."), NULL, N_("Create a new torrent"), G_CALLBACK(action_cb) }, diff --git a/gtk/dialogs.c b/gtk/dialogs.c index 08839a61b..c4a66339f 100644 --- a/gtk/dialogs.c +++ b/gtk/dialogs.c @@ -289,36 +289,25 @@ askquit( TrCore * core, struct DeleteData { - GtkWidget * delete_files_tb; + gboolean delete_files; GList * torrents; TrCore * core; }; static void -deleteDownloadedToggled( GtkToggleButton * tb, gpointer warn ) -{ - GtkWidget * w = GTK_WIDGET( warn ); - - if( gtk_toggle_button_get_active( tb ) ) - gtk_widget_show( w ); - else - gtk_widget_hide( w ); -} - -static void -deleteResponse( GtkDialog * dialog, gint response, gpointer gdata ) +removeResponse( GtkDialog * dialog, gint response, gpointer gdata ) { struct DeleteData * data = gdata; - const int del = response == GTK_RESPONSE_ACCEPT; - const int deleteFiles = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->delete_files_tb ) ); + const int doRemove = response == GTK_RESPONSE_ACCEPT; + const int doDelete = data->delete_files; GList * l; for( l=data->torrents; l!=NULL; l=l->next ) { TrTorrent * gtor = TR_TORRENT( l->data ); - if( del ) - tr_core_remove_torrent( data->core, gtor, deleteFiles ); + if( doRemove ) + tr_core_remove_torrent( data->core, gtor, doDelete ); else g_object_unref( G_OBJECT( gtor ) ); } @@ -329,62 +318,77 @@ deleteResponse( GtkDialog * dialog, gint response, gpointer gdata ) } void -confirmDelete( GtkWindow * parent, +confirmRemove( GtkWindow * parent, TrCore * core, GList * torrents ) { - char buf[1024]; - GtkWidget * t; GtkWidget * d; - GtkWidget * w; - GtkWidget * warn; + char text[128]; struct DeleteData * dd = g_new0( struct DeleteData, 1 ); dd->core = core; dd->torrents = torrents; + dd->delete_files = FALSE; - d = gtk_dialog_new_with_buttons( _( "Remove Torrent" ), - parent, - GTK_DIALOG_DESTROY_WITH_PARENT|GTK_DIALOG_NO_SEPARATOR, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_REMOVE, GTK_RESPONSE_ACCEPT, - NULL ); + g_snprintf( text, sizeof( text ), + ngettext( "Remove torrent?", + "Remove torrents?", + g_list_length( torrents ) ) ); + d = gtk_message_dialog_new_with_markup( parent, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + "%s", text ); + gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( d ), + _( "This removes the torrent, not its downloads." ) ); + gtk_dialog_add_buttons( GTK_DIALOG( d ), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_REMOVE, GTK_RESPONSE_ACCEPT, + NULL ); + gtk_dialog_set_default_response( GTK_DIALOG ( d ), + GTK_RESPONSE_ACCEPT ); gtk_dialog_set_alternative_button_order( GTK_DIALOG( d ), GTK_RESPONSE_ACCEPT, GTK_RESPONSE_CANCEL, -1 ); - g_signal_connect( d, "response", G_CALLBACK( deleteResponse ), dd ); - - t = gtk_table_new( 3, 2, FALSE ); - gtk_container_set_border_width( GTK_CONTAINER( t ), GUI_PAD_BIG ); - gtk_table_set_col_spacing( GTK_TABLE( t ), 0, GUI_PAD_BIG ); - gtk_table_set_row_spacings( GTK_TABLE( t ), GUI_PAD_BIG ); - - w = gtk_image_new_from_stock( GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG ); - gtk_table_attach( GTK_TABLE( t ), w, 0, 1, 0, 3, GTK_FILL, GTK_FILL, 0, 0 ); - gtk_widget_show( w ); - - g_snprintf( buf, sizeof(buf), "%s", _( "Remove the selected torrent(s)?" ) ); - w = gtk_label_new( buf ); - gtk_misc_set_alignment( GTK_MISC( w ), 0.0, 0.5 ); - gtk_label_set_use_markup( GTK_LABEL( w ), TRUE ); - gtk_table_attach( GTK_TABLE( t ), w, 1, 2, 0, 1, GTK_FILL, 0, 0, 0 ); - gtk_widget_show( w ); - - g_snprintf( buf, sizeof( buf ), "%s", - _( "All downloaded files for this torrent will be deleted!" ) ); - warn = gtk_label_new( buf ); - gtk_label_set_use_markup( GTK_LABEL( warn ), TRUE ); - gtk_table_attach( GTK_TABLE( t ), warn, 1, 2, 2, 3, GTK_FILL, 0, 0, 0 ); - - w = gtk_check_button_new_with_mnemonic( _( "Delete _downloaded files" ) ); - dd->delete_files_tb = w; - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), FALSE ); - gtk_table_attach( GTK_TABLE( t ), w, 1, 2, 1, 2, GTK_FILL, 0, 0, 0 ); - g_signal_connect( w, "toggled", G_CALLBACK(deleteDownloadedToggled), warn ); - gtk_widget_show( w ); - - gtk_widget_show( t ); - gtk_container_add( GTK_CONTAINER( GTK_DIALOG( d )->vbox ), t ); - gtk_widget_show( d ); + g_signal_connect( d, "response", G_CALLBACK( removeResponse ), dd ); + gtk_widget_show_all( d ); +} + +void +confirmDelete( GtkWindow * parent, + TrCore * core, + GList * torrents ) +{ + GtkWidget * d; + char text[128]; + struct DeleteData * dd = g_new0( struct DeleteData, 1 ); + + dd->core = core; + dd->torrents = torrents; + dd->delete_files = TRUE; + + g_snprintf( text, sizeof( text ), + ngettext( "Delete torrent?", + "Delete torrents?", + g_list_length( torrents ) ) ); + d = gtk_message_dialog_new_with_markup( parent, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_NONE, + "%s", text ); + gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( d ), + _( "This removes the torrent and deletes its downloads!" ) ); + gtk_dialog_add_buttons( GTK_DIALOG( d ), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_DELETE, 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 ); } diff --git a/gtk/dialogs.h b/gtk/dialogs.h index ecde8da29..7285a424b 100644 --- a/gtk/dialogs.h +++ b/gtk/dialogs.h @@ -39,5 +39,6 @@ GtkWidget* promptfordir( GtkWindow * parent, void askquit( TrCore*, GtkWindow* parent, callbackfunc_t func, void* cbdata ); void confirmDelete( GtkWindow * parent, TrCore * core, GList * torrents ); +void confirmRemove( GtkWindow * parent, TrCore * core, GList * torrents ); #endif /* TG_PREFS_H */ diff --git a/gtk/main.c b/gtk/main.c index 8f3558931..47009580f 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -200,6 +200,7 @@ refreshTorrentActions( GtkTreeSelection * s ) action_sensitize( "pause-torrent", counts.activeCount!=0 ); action_sensitize( "start-torrent", counts.inactiveCount!=0 ); action_sensitize( "remove-torrent", counts.totalCount!=0 ); + action_sensitize( "delete-torrent", counts.totalCount!=0 ); action_sensitize( "verify-torrent", counts.totalCount!=0 ); action_sensitize( "show-torrent-details", counts.totalCount==1 ); @@ -806,7 +807,8 @@ coreprompt( TrCore * core, } #if GTK_CHECK_VERSION(2,8,0) - gtk_window_set_urgency_hint( GTK_WINDOW( cbdata->wind ), TRUE ); + if( cbdata->wind ) + gtk_window_set_urgency_hint( GTK_WINDOW( cbdata->wind ), TRUE ); g_signal_connect( w, "focus-in-event", G_CALLBACK(on_main_window_focus_in), cbdata ); #endif @@ -955,18 +957,6 @@ stopTorrentForeach (GtkTreeModel * model, g_object_unref( G_OBJECT( tor ) ); } -static void -accumulateSelectedTorrents( GtkTreeModel * model, - GtkTreePath * path UNUSED, - GtkTreeIter * iter, - gpointer gdata ) -{ - GList ** data = ( GList** ) gdata; - TrTorrent * tor = NULL; - gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 ); - *data = g_list_append( *data, tor ); -} - static void updateTrackerForeach (GtkTreeModel * model, GtkTreePath * path UNUSED, @@ -1028,12 +1018,39 @@ recheckTorrentForeach (GtkTreeModel * model, } static gboolean -msgwinclosed() +msgwinclosed( void ) { action_toggle( "toggle-message-log", FALSE ); return FALSE; } +static void +accumulateSelectedTorrents( GtkTreeModel * model, + GtkTreePath * path UNUSED, + GtkTreeIter * iter, + gpointer gdata ) +{ + GList ** data = ( GList** ) gdata; + TrTorrent * tor = NULL; + gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 ); + *data = g_list_append( *data, tor ); +} + +static void +removeSelected( struct cbdata * data, gboolean doDelete ) +{ + GList * l = NULL; + GtkTreeSelection * s = tr_window_get_selection( data->wind ); + gtk_tree_selection_selected_foreach( s, accumulateSelectedTorrents, &l ); + gtk_tree_selection_unselect_all( s ); + if( l ) { + if( doDelete ) + confirmDelete( data->wind, data->core, l ); + else + confirmRemove( data->wind, data->core, l ); + } +} + void doAction ( const char * action_name, gpointer user_data ) { @@ -1085,14 +1102,13 @@ doAction ( const char * action_name, gpointer user_data ) tr_core_handle( data->core ) ); gtk_widget_show_all( w ); } - else if (!strcmp (action_name, "remove-torrent")) + else if( !strcmp( action_name, "remove-torrent" ) ) { - GList * l = NULL; - GtkTreeSelection * s = tr_window_get_selection(data->wind); - gtk_tree_selection_selected_foreach( s, accumulateSelectedTorrents, &l ); - gtk_tree_selection_unselect_all( s ); - if( l != NULL ) - confirmDelete( data->wind, data->core, l ); + removeSelected( data, FALSE ); + } + else if( !strcmp( action_name, "delete-torrent" ) ) + { + removeSelected( data, TRUE ); } else if (!strcmp (action_name, "close")) { diff --git a/gtk/ui.h b/gtk/ui.h index 1abb53c5f..4a816b5b6 100644 --- a/gtk/ui.h +++ b/gtk/ui.h @@ -9,8 +9,9 @@ const char * fallback_ui_file = " \n" " \n" " \n" -" \n" " \n" +" \n" +" \n" " \n" " \n" " \n" @@ -62,6 +63,7 @@ const char * fallback_ui_file = " \n" " \n" " \n" +" \n" " \n" "\n" " \n"