Changeset 10523


Ignore:
Timestamp:
Apr 23, 2010, 7:37:13 PM (11 years ago)
Author:
charles
Message:

(trunk gtk) #2999 "'Set Location' should support multiple torrents" -- implemented in trunk for 2.00

Location:
trunk/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r10505 r10523  
    322322    action_sensitize( "delete-torrent", counts.totalCount != 0 );
    323323    action_sensitize( "verify-torrent", counts.totalCount != 0 );
     324    action_sensitize( "relocate-torrent", counts.totalCount != 0 );
    324325    action_sensitize( "show-torrent-properties", counts.totalCount != 0 );
    325326    action_sensitize( "open-torrent-folder", counts.totalCount == 1 );
    326     action_sensitize( "relocate-torrent", counts.totalCount == 1 );
    327327    action_sensitize( "copy-magnet-link-to-clipboard", counts.totalCount == 1 );
    328328
     
    16001600    else if( !strcmp( action_name, "relocate-torrent" ) )
    16011601    {
    1602         tr_torrent * tor = getFirstSelectedTorrent( data );
    1603         if( tor != NULL )
     1602        GSList * ids = getSelectedTorrentIds( data );
     1603        if( ids != NULL )
    16041604        {
    16051605            GtkWindow * parent = GTK_WINDOW( data->wind );
    1606             GtkWidget * w = gtr_relocate_dialog_new( parent, tor );
     1606            GtkWidget * w = gtr_relocate_dialog_new( parent, data->core, ids );
    16071607            gtk_widget_show( w );
    16081608        }
  • trunk/gtk/relocate.c

    r10340 r10523  
    2121#include "util.h"
    2222
     23#define DATA_KEY "gtr-relocate-data"
     24
    2325static char * previousLocation = NULL;
    2426
    25 struct UpdateData
     27struct relocate_dialog_data
    2628{
    27     GtkDialog * dialog;
    28     GtkDialog * moving_dialog;
    2929    int done;
     30    tr_bool do_move;
     31    TrCore * core;
     32    GSList * torrent_ids;
     33    GtkWidget * message_dialog;
     34    GtkWidget * chooser_dialog;
    3035};
     36
     37static void
     38data_free( gpointer gdata )
     39{
     40    struct relocate_dialog_data * data = gdata;
     41    g_slist_free( data->torrent_ids );
     42    g_free( data );
     43}
     44
     45/***
     46****
     47***/
     48
     49static void
     50startMovingNextTorrent( struct relocate_dialog_data * data )
     51{
     52    char * str;
     53    const int id = GPOINTER_TO_INT( data->torrent_ids->data );
     54
     55    tr_session * session = tr_core_session( data->core );
     56
     57    tr_torrent * tor = tr_torrentFindFromId( session, id );
     58    if( tor != NULL )
     59        tr_torrentSetLocation( tor, previousLocation, data->do_move, NULL, &data->done );
     60
     61    data->torrent_ids = g_slist_delete_link( data->torrent_ids,
     62                                             data->torrent_ids );
     63
     64    str = g_strdup_printf( _( "Moving \"%s\"" ), tr_torrentInfo(tor)->name );
     65    gtk_message_dialog_set_markup( GTK_MESSAGE_DIALOG( data->message_dialog ), str );
     66    g_free( str );
     67}
    3168
    3269/* every once in awhile, check to see if the move is done.
     
    3572onTimer( gpointer gdata )
    3673{
    37     struct UpdateData * data = gdata;
     74    struct relocate_dialog_data * data = gdata;
    3875    const int done = data->done;
    3976
     
    4279        const int flags = GTK_DIALOG_MODAL
    4380                        | GTK_DIALOG_DESTROY_WITH_PARENT;
    44         GtkWidget * w = gtk_message_dialog_new( GTK_WINDOW( data->moving_dialog ),
     81        GtkWidget * w = gtk_message_dialog_new( GTK_WINDOW( data->message_dialog ),
    4582                                                flags,
    4683                                                GTK_MESSAGE_ERROR,
     
    4986                                                _( "Couldn't move torrent" ) );
    5087        gtk_dialog_run( GTK_DIALOG( w ) );
    51         gtk_widget_destroy( GTK_WIDGET( data->moving_dialog ) );
     88        gtk_widget_destroy( GTK_WIDGET( data->message_dialog ) );
     89        return FALSE;
    5290    }
    53     else if( done != TR_LOC_MOVING )
     91    else if( done == TR_LOC_DONE )
    5492    {
    55         gtk_widget_destroy( GTK_WIDGET( data->dialog ) );
    56         g_free( data );
     93        if( data->torrent_ids != NULL )
     94        {
     95            startMovingNextTorrent( data );
     96        }
     97        else
     98        {
     99            gtk_widget_destroy( GTK_WIDGET( data->chooser_dialog ) );
     100            return FALSE;
     101        }
    57102    }
    58103
    59     return !done;
     104    return TRUE; /* keep looping */
    60105}
    61106
     
    65110    if( response == GTK_RESPONSE_APPLY )
    66111    {
    67         struct UpdateData * updateData;
    68 
    69112        GtkWidget * w;
    70113        GObject * d = G_OBJECT( dialog );
    71         tr_torrent * tor = g_object_get_data( d, "torrent" );
     114        struct relocate_dialog_data * data = g_object_get_data( d, DATA_KEY );
    72115        GtkFileChooser * chooser = g_object_get_data( d, "chooser" );
    73116        GtkToggleButton * move_tb = g_object_get_data( d, "move_rb" );
    74117        char * location = gtk_file_chooser_get_filename( chooser );
    75         const gboolean do_move = gtk_toggle_button_get_active( move_tb );
     118
     119        data->do_move = gtk_toggle_button_get_active( move_tb );
    76120
    77121        /* pop up a dialog saying that the work is in progress */
     
    80124                                    GTK_MESSAGE_INFO,
    81125                                    GTK_BUTTONS_CLOSE,
    82                                     _( "Moving \"%s\"" ),
    83                                     tr_torrentInfo(tor)->name );
     126                                    NULL );
    84127        gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( w ), _( "This may take a moment..." ) );
    85128        gtk_dialog_set_response_sensitive( GTK_DIALOG( w ), GTK_RESPONSE_CLOSE, FALSE );
    86129        gtk_widget_show( w );
    87130
    88         /* start the move and periodically check its status */
    89         updateData = g_new( struct UpdateData, 1 );
    90         updateData->dialog = dialog;
    91         updateData->moving_dialog = GTK_DIALOG( w );
    92         updateData->done = FALSE;
    93         tr_torrentSetLocation( tor, location, do_move, NULL, &updateData->done );
    94         gtr_timeout_add_seconds( 1, onTimer, updateData );
    95 
    96131        /* remember this location so that it can be the default next time */
    97132        g_free( previousLocation );
    98133        previousLocation = location;
     134
     135        /* start the move and periodically check its status */
     136        data->message_dialog = w;
     137        data->done = TR_LOC_DONE;
     138        onTimer( data );
     139        gtr_timeout_add_seconds( 1, onTimer, data );
    99140    }
    100141    else
     
    105146
    106147GtkWidget*
    107 gtr_relocate_dialog_new( GtkWindow * parent, tr_torrent * tor )
     148gtr_relocate_dialog_new( GtkWindow * parent,
     149                         TrCore    * core,
     150                         GSList    * torrent_ids )
    108151{
    109152    int row;
     
    111154    GtkWidget * d;
    112155    GtkWidget * t;
     156    struct relocate_dialog_data * data;
    113157
    114158    d = gtk_dialog_new_with_buttons( _( "Set Torrent Location" ), parent,
     
    119163                                     GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
    120164                                     NULL );
    121     g_object_set_data( G_OBJECT( d ), "torrent", tor );
    122165    gtk_dialog_set_default_response( GTK_DIALOG( d ),
    123166                                     GTK_RESPONSE_CANCEL );
     
    147190    gtk_box_pack_start( GTK_BOX( GTK_DIALOG( d )->vbox ), t, TRUE, TRUE, 0 );
    148191
     192    data = g_new0( struct relocate_dialog_data, 1 );
     193    data->core = core;
     194    data->torrent_ids = torrent_ids;
     195    data->chooser_dialog = d;
     196    g_object_set_data_full( G_OBJECT( d ), DATA_KEY, data, data_free );
     197
    149198    return d;
    150199}
  • trunk/gtk/relocate.h

    r9868 r10523  
    1515
    1616#include <gtk/gtk.h>
    17 #include <libtransmission/transmission.h>
     17#include "tr-core.h"
    1818
    19 GtkWidget * gtr_relocate_dialog_new( GtkWindow * parent, tr_torrent * tor );
     19GtkWidget * gtr_relocate_dialog_new( GtkWindow * parent,
     20                                     TrCore    * core,
     21                                     GSList    * torrentIds );
    2022
    2123#endif
Note: See TracChangeset for help on using the changeset viewer.