Changeset 6513


Ignore:
Timestamp:
Aug 14, 2008, 4:43:22 AM (13 years ago)
Author:
charles
Message:

(gtk 1.3x) #826: Transmission doesn't open torrents via web browser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.3x/gtk/add-dialog.c

    r6370 r6513  
    140140}
    141141
     142/**
     143 * When the source .torrent file is deleted
     144 * (such as, if it was a temp file that a web browser passed to us),
     145 * gtk invokes this callback and `filename' will be NULL.
     146 * The `filename' tests here are to prevent us from losing the current
     147 * metadata when that happens.
     148 */
    142149static void
    143150sourceChanged( GtkFileChooserButton * b, gpointer gdata )
    144151{
    145152    struct AddData * data = gdata;
    146 
    147     removeOldTorrent( data );
    148 
    149     g_free( data->filename );
    150     data->filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( b ) );
     153    char * filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( b ) );
    151154
    152155    /* maybe instantiate a torrent */
    153     if( data->filename ) {
     156    if( data->filename || !data->gtor )
     157    {
    154158        int err = 0;
     159        int new_file = 0;
    155160        tr_torrent * torrent;
    156161        tr_handle * handle = tr_core_handle( data->core );
    157         tr_ctorSetMetainfoFromFile( data->ctor, data->filename );
     162
     163        if( filename && ( !data->filename || strcmp( filename, data->filename ) ) )
     164        {
     165            g_free( data->filename );
     166            data->filename = g_strdup( filename );
     167            tr_ctorSetMetainfoFromFile( data->ctor, data->filename );
     168            new_file = 1;
     169        }
     170
    158171        tr_ctorSetDownloadDir( data->ctor, TR_FORCE, data->downloadDir );
    159172        tr_ctorSetPaused( data->ctor, TR_FORCE, TRUE );
    160173        tr_ctorSetDeleteSource( data->ctor, FALSE );
    161         if(( torrent = tr_torrentNew( handle, data->ctor, &err )))
     174
     175        if(( torrent = tr_torrentNew( handle, data->ctor, &err ))) {
     176            removeOldTorrent( data );
    162177            data->gtor = tr_torrent_new_preexisting( torrent );
    163         else
     178        } else if( new_file ) {
    164179            addTorrentErrorDialog( GTK_WIDGET(b), err, data->filename );
    165     }
    166 
    167     updateTorrent( data );
     180        }
     181
     182        updateTorrent( data );
     183    }
     184
     185    g_free( filename );
    168186}
    169187
     
    180198{
    181199    char * fname = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( b ) );
    182     if( fname )
    183     {
    184         struct AddData * data = gdata;
     200    struct AddData * data = gdata;
     201
     202    if( fname && ( !data->downloadDir || strcmp( fname, data->downloadDir ) ) )
     203    {
    185204        g_free( data->downloadDir );
    186         data->downloadDir = fname;
     205        data->downloadDir = g_strdup( fname );
    187206
    188207        updateTorrent( data );
    189208        verifyRequested( NULL, data );
    190209    }
     210
     211    g_free( fname );
    191212}
    192213
Note: See TracChangeset for help on using the changeset viewer.