Changeset 5064


Ignore:
Timestamp:
Feb 19, 2008, 3:57:03 AM (14 years ago)
Author:
charles
Message:

(gtk) add ability to delete downloaded files when deleting a torrent

Location:
trunk
Files:
11 edited
4 moved

Legend:

Unmodified
Added
Removed
  • trunk/autogen.sh

    r5008 r5064  
    3535cd $ORIGDIR || exit $?
    3636
    37 if test -z "$AUTOGEN_SUBDIR_MODE"; then
    38   $srcdir/configure --enable-maintainer-mode $AUTOGEN_CONFIGURE_ARGS "$@" || exit $?
    39   echo
    40   echo "Now type 'make' to compile $PROJECT."
    41 fi
  • trunk/gtk/Makefile.am

    r5015 r5064  
    1515    actions.h \
    1616    conf.h \
     17    details.h \
    1718    dialogs.h \
    1819    hig.h \
     
    2425    makemeta-ui.h \
    2526    msgwin.h \
    26     open.h \
     27    open-dialog.h \
    2728    stats.h \
    2829    sexy-icon-entry.h \
    2930    torrent-cell-renderer.h \
    30     torrent-inspector.h \
    3131    tr_core.h \
    3232    tr_icon.h \
     
    4242    actions.c \
    4343    conf.c \
     44    details.c \
    4445    dialogs.c \
    4546    file-list.c \
     
    5051    makemeta-ui.c \
    5152    msgwin.c \
    52     open.c \
     53    open-dialog.c \
    5354    sexy-icon-entry.c \
    5455    stats.c \
    5556    torrent-cell-renderer.c \
    56     torrent-inspector.c \
    5757    tr_core.c \
    5858    tr_icon.c \
  • trunk/gtk/actions.c

    r4970 r5064  
    1616#include <libtransmission/transmission.h>
    1717#include "conf.h"
    18 #include "torrent-inspector.h"
    1918#include "tr_core.h"
    2019#include "tr_prefs.h"
     
    116115    N_("_Pause"), "<control>P", NULL, G_CALLBACK(action_cb) },
    117116  { "remove-torrent", GTK_STOCK_REMOVE,
    118     N_("_Remove"), "<control>Delete", NULL, G_CALLBACK(action_cb) },
     117    N_("_Remove"), "Delete", NULL, G_CALLBACK(action_cb) },
    119118  { "new-torrent", GTK_STOCK_NEW, N_("_New..."), NULL,
    120119    N_("Create a new torrent"),
  • trunk/gtk/details.c

    r5054 r5064  
    2020
    2121#include "actions.h"
     22#include "details.h"
    2223#include "file-list.h"
    2324#include "tr_torrent.h"
    2425#include "hig.h"
    25 #include "torrent-inspector.h"
    2626#include "util.h"
    2727
  • trunk/gtk/dialogs.c

    r5022 r5064  
    275275    gtk_widget_show_all( wind );
    276276}
     277
     278/***
     279****
     280***/
     281
     282struct DeleteData
     283{
     284    GtkWidget * delete_files_tb;
     285    GList * torrents;
     286    TrCore * core;
     287};
     288
     289static void
     290deleteDownloadedToggled( GtkToggleButton * tb, gpointer warn )
     291{
     292    GtkWidget * w = GTK_WIDGET( warn );
     293
     294    if( gtk_toggle_button_get_active( tb ) )
     295        gtk_widget_show( w );
     296    else
     297        gtk_widget_hide( w );
     298}
     299
     300static void
     301deleteResponse( GtkDialog * dialog, gint response, gpointer gdata )
     302{
     303    struct DeleteData * data = gdata;
     304    const int del = response == GTK_RESPONSE_YES;
     305    const int deleteFiles = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->delete_files_tb ) );
     306    GList * l;
     307
     308    for( l=data->torrents; l!=NULL; l=l->next )
     309    {
     310        TrTorrent * gtor = TR_TORRENT( l->data );
     311
     312        if( del )
     313            tr_core_remove_torrent( data->core, gtor, deleteFiles );
     314        else
     315            g_object_unref( G_OBJECT( gtor ) );
     316    }
     317
     318    gtk_widget_destroy( GTK_WIDGET( dialog ) );
     319    g_list_free( data->torrents );
     320    g_free( data );
     321}
     322
     323void
     324confirmDelete( GtkWindow * parent,
     325               TrCore    * core,
     326               GList     * torrents )
     327{
     328    char buf[1024];
     329    GtkWidget * t;
     330    GtkWidget * d;
     331    GtkWidget * w;
     332    GtkWidget * warn;
     333    struct DeleteData * dd = g_new0( struct DeleteData, 1 );
     334
     335    dd->core = core;
     336    dd->torrents = torrents;
     337
     338    d = gtk_dialog_new_with_buttons( _( "Remove Torrent" ),
     339                                     parent,
     340                                     GTK_DIALOG_DESTROY_WITH_PARENT|GTK_DIALOG_NO_SEPARATOR,
     341                                     GTK_STOCK_NO, GTK_RESPONSE_NO,
     342                                     GTK_STOCK_YES, GTK_RESPONSE_YES,
     343                                     NULL );
     344    g_signal_connect( d, "response", G_CALLBACK( deleteResponse ), dd );
     345
     346    t = gtk_table_new( 3, 2, FALSE );
     347    gtk_container_set_border_width( GTK_CONTAINER( t ), GUI_PAD_BIG );
     348    gtk_table_set_col_spacing( GTK_TABLE( t ), 0, GUI_PAD_BIG );
     349    gtk_table_set_row_spacings( GTK_TABLE( t ), GUI_PAD_BIG );
     350
     351    w = gtk_image_new_from_stock( GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG );
     352    gtk_table_attach( GTK_TABLE( t ), w, 0, 1, 0, 3, GTK_FILL, GTK_FILL, 0, 0 );
     353    gtk_widget_show( w );
     354
     355    g_snprintf( buf, sizeof(buf), "<b>%s</b>", _( "Remove the selected torrent(s)?" ) );
     356    w = gtk_label_new( buf );
     357    gtk_misc_set_alignment( GTK_MISC( w ), 0.0, 0.5 );
     358    gtk_label_set_use_markup( GTK_LABEL( w ), TRUE );
     359    gtk_table_attach( GTK_TABLE( t ), w, 1, 2, 0, 1, GTK_FILL, 0, 0, 0 );
     360    gtk_widget_show( w );
     361
     362    g_snprintf( buf, sizeof( buf ), "<i>%s</i>",
     363                _( "All downloaded files for this torrent will be deleted!" ) );
     364    warn = gtk_label_new( buf );
     365    gtk_label_set_use_markup( GTK_LABEL( warn ), TRUE );
     366    gtk_table_attach( GTK_TABLE( t ), warn, 1, 2, 2, 3, GTK_FILL, 0, 0, 0 );
     367   
     368    w = gtk_check_button_new_with_mnemonic( _( "Delete _downloaded files" ) );
     369    dd->delete_files_tb = w;
     370    gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), FALSE );
     371    gtk_table_attach( GTK_TABLE( t ), w, 1, 2, 1, 2, GTK_FILL, 0, 0, 0 );
     372    g_signal_connect( w, "toggled", G_CALLBACK(deleteDownloadedToggled), warn );
     373    gtk_widget_show( w );
     374
     375    gtk_widget_show( t );
     376    gtk_container_add( GTK_CONTAINER( GTK_DIALOG( d )->vbox ), t );
     377    gtk_widget_show( d );
     378}
  • trunk/gtk/dialogs.h

    r5015 r5064  
    3636void askquit( TrCore*, GtkWindow* parent, callbackfunc_t func, void* cbdata );
    3737
     38void confirmDelete( GtkWindow * parent, TrCore * core, GList * torrents );
     39
    3840#endif /* TG_PREFS_H */
  • trunk/gtk/main.c

    r5026 r5064  
    4444#include "actions.h"
    4545#include "conf.h"
     46#include "details.h"
    4647#include "dialogs.h"
    4748#include "ipc.h"
    4849#include "makemeta-ui.h"
    4950#include "msgwin.h"
    50 #include "open.h"
     51#include "open-dialog.h"
    5152#include "stats.h"
    52 #include "torrent-inspector.h"
    5353#include "tr_core.h"
    5454#include "tr_icon.h"
     
    155155static gboolean
    156156updatemodel(gpointer gdata);
    157 static GList *
    158 getselection( struct cbdata * cbdata );
    159157
    160158static void
     
    854852}
    855853
    856 /* returns a GList of GtkTreeRowReferences to each selected row */
    857 static GList *
    858 getselection( struct cbdata * cbdata )
    859 {
    860     GList * rows = NULL;
    861 
    862     if( NULL != cbdata->wind )
    863     {
    864         GList * l;
    865         GtkTreeSelection *s = tr_window_get_selection(cbdata->wind);
    866         GtkTreeModel * filter_model;
    867         GtkTreeModel * store_model;
    868         rows = gtk_tree_selection_get_selected_rows( s, &filter_model );
    869         store_model = gtk_tree_model_filter_get_model(
    870                                                  GTK_TREE_MODEL_FILTER( filter_model ) );
    871         for( l=rows; l!=NULL; l=l->next )
    872         {
    873             GtkTreePath * path = gtk_tree_model_filter_convert_path_to_child_path(
    874                                         GTK_TREE_MODEL_FILTER( filter_model ), l->data );
    875             GtkTreeRowReference * ref = gtk_tree_row_reference_new( store_model, path );
    876             gtk_tree_path_free( path );
    877             gtk_tree_path_free( l->data );
    878             l->data = ref;
    879         }
    880     }
    881 
    882     return rows;
    883 }
    884 
    885854static void
    886855about ( GtkWindow * parent )
     
    937906
    938907static void
     908accumulateSelectedTorrents( GtkTreeModel * model,
     909                            GtkTreePath  * path UNUSED,
     910                            GtkTreeIter  * iter,
     911                            gpointer       gdata )
     912{
     913    GList ** data = ( GList** ) gdata;
     914    TrTorrent * tor = NULL;
     915    gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
     916    *data = g_list_append( *data, tor );
     917}
     918
     919static void
    939920updateTrackerForeach (GtkTreeModel * model,
    940921                      GtkTreePath  * path UNUSED,
     
    10551036    else if (!strcmp (action_name, "remove-torrent"))
    10561037    {
    1057         /* this modifies the model's contents, so can't use foreach */
    1058         GList *l, *sel = getselection( data );
    1059         GtkTreeModel *model = tr_core_model( data->core );
    1060         gtk_tree_selection_unselect_all( tr_window_get_selection( data->wind) );
    1061         for( l=sel; l!=NULL; l=l->next )
    1062         {
    1063             GtkTreeIter iter;
    1064             GtkTreeRowReference * reference = l->data;
    1065             GtkTreePath * path = gtk_tree_row_reference_get_path( reference );
    1066             gtk_tree_model_get_iter( model, &iter, path );
    1067             tr_core_delete_torrent( data->core, &iter );
    1068             gtk_tree_path_free( path );
    1069             gtk_tree_row_reference_free( reference );
    1070             changed = TRUE;
    1071         }
    1072         g_list_free( sel );
     1038        GList * l = NULL;
     1039        GtkTreeSelection * s = tr_window_get_selection(data->wind);
     1040        gtk_tree_selection_selected_foreach( s, accumulateSelectedTorrents, &l );
     1041        if( l != NULL )
     1042            confirmDelete( data->wind, data->core, l );
    10731043    }
    10741044    else if (!strcmp (action_name, "close"))
  • trunk/gtk/open-dialog.c

    r5054 r5064  
    1616#include "file-list.h"
    1717#include "hig.h"
    18 #include "open.h"
     18#include "open-dialog.h"
    1919
    2020struct OpenData
  • trunk/gtk/tr_core.c

    r5036 r5064  
    572572}
    573573
     574static gboolean
     575findTorrentInModel( TrCore * core, const TrTorrent * gtor, GtkTreeIter * setme )
     576{
     577    int match = 0;
     578    GtkTreeIter iter;
     579    GtkTreeModel * model = tr_core_model( core );
     580
     581    if( gtk_tree_model_iter_children( model, &iter, NULL ) ) do
     582    {
     583        TrTorrent * tmp;
     584        gtk_tree_model_get( model, &iter, MC_TORRENT, &tmp, -1 );
     585        match = tmp == gtor;
     586        g_object_unref( G_OBJECT( tmp ) );
     587    }
     588    while( !match && gtk_tree_model_iter_next( model, &iter ) );
     589
     590    if( match )
     591        *setme = iter;
     592
     593    return match;
     594}
     595
     596void
     597tr_core_remove_torrent( TrCore * self, TrTorrent * gtor, int deleteFiles )
     598{
     599    GtkTreeIter iter;
     600    GtkTreeModel * model = tr_core_model( self );
     601
     602    /* remove from the gui */
     603    if( findTorrentInModel( self, gtor, &iter ) )
     604        gtk_list_store_remove( GTK_LIST_STORE( model ), &iter );
     605
     606    /* maybe delete the downloaded files */
     607    if( deleteFiles )
     608        tr_torrent_delete_files( gtor );
     609
     610    /* delete the torrent */
     611    tr_torrentRemoveSaved( tr_torrent_handle( gtor ) );
     612    g_object_unref( G_OBJECT( gtor ) );
     613}
     614
     615
    574616/***
    575617****
  • trunk/gtk/tr_core.h

    r5036 r5064  
    141141void tr_core_delete_torrent( TrCore * self, GtkTreeIter * iter );
    142142
     143void tr_core_remove_torrent( TrCore * self, TrTorrent * gtor, int deleteFiles );
     144
    143145/* update the model with current torrent status */
    144146void tr_core_update( TrCore * self );
  • trunk/gtk/tr_torrent.c

    r5015 r5064  
    2323 *****************************************************************************/
    2424
     25#include <errno.h>
    2526#include <string.h>
    2627#include <unistd.h>
     
    2829#include <gtk/gtk.h>
    2930#include <glib/gi18n.h>
     31#include <glib/gstdio.h>
    3032
    3133#include <libtransmission/transmission.h>
     
    286288    return top;
    287289}
     290
     291void
     292tr_torrent_delete_files( TrTorrent * gtor )
     293{
     294    int i;
     295    const tr_info * info = tr_torrent_info( gtor );
     296    const char * stop = tr_torrentGetFolder( tr_torrent_handle( gtor ) );
     297
     298    for( i=0; info && i<info->fileCount; ++i )
     299    {
     300        char * file = g_build_filename( stop, info->files[i].name, NULL );
     301        while( strcmp( stop, file ) && strlen(stop) < strlen(file) )
     302        {
     303            char * swap = g_path_get_dirname( file );
     304            g_unlink( file );
     305            g_free( file );
     306            file = swap;
     307        }
     308        g_free( file );
     309    }
     310}
  • trunk/gtk/tr_torrent.h

    r5015 r5064  
    7878
    7979void
     80tr_torrent_delete_files( TrTorrent * tor );
     81
     82void
    8083tr_torrent_check_seeding_cap ( TrTorrent* );
    8184void
  • trunk/po/POTFILES.in

    r5015 r5064  
    33gtk/actions.c
    44gtk/conf.c
     5gtk/details.c
    56gtk/dialogs.c
    67gtk/file-list.c
     
    1112gtk/makemeta-ui.c
    1213gtk/msgwin.c
    13 gtk/open.c
     14gtk/open-dialog.c
    1415gtk/stats.c
    1516gtk/torrent-cell-renderer.c
    16 gtk/torrent-inspector.c
    1717gtk/tr_core.c
    1818gtk/tr_icon.c
Note: See TracChangeset for help on using the changeset viewer.