Changeset 10645


Ignore:
Timestamp:
May 13, 2010, 11:54:32 PM (11 years ago)
Author:
charles
Message:

(trunk qt) #2612 "display new transfer window when adding magnet transfer" -- implemented for Qt client

Location:
trunk/qt
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/app.cc

    r10560 r10645  
    226226
    227227    for( QStringList::const_iterator it=filenames.begin(), end=filenames.end(); it!=end; ++it )
    228         mySession->addTorrent( *it );
     228        addTorrent( *it );
    229229
    230230    // register as the dbus handler for Transmission
     
    323323{
    324324    if( !myPrefs->getBool( Prefs :: OPTIONS_PROMPT ) )
     325    {
    325326        mySession->addTorrent( key );
    326     else if( !QFile( key ).exists( ) )
    327         myWindow->openURL( key );
    328     else {
     327    }
     328    else if( Utils::isMagnetLink( key ) || QFile( key ).exists( ) )
     329    {
    329330        Options * o = new Options( *mySession, *myPrefs, key, myWindow );
    330331        o->show( );
    331332    }
     333    else if( Utils::isURL( key ) )
     334    {
     335        myWindow->openURL( key );
     336    }
     337
    332338    raise( );
    333339}
  • trunk/qt/options.cc

    r10080 r10645  
    3939#include "session.h"
    4040#include "torrent.h"
     41#include "utils.h"
    4142
    4243/***
     
    215216
    216217    tr_ctor * ctor = tr_ctorNew( 0 );
    217     tr_ctorSetMetainfoFromFile( ctor, myFile.toUtf8().constData() );
     218    if( Utils::isMagnetLink( myFile ) )
     219        tr_ctorSetMetainfoFromMagnetLink( ctor, myFile.toUtf8().constData() );
     220    else
     221        tr_ctorSetMetainfoFromFile( ctor, myFile.toUtf8().constData() );
     222
    218223    const int err = tr_torrentParse( ctor, &myInfo );
    219224    myHaveInfo = !err;
     
    276281
    277282    // "metainfo"
    278     QFile file( myFile );
    279     file.open( QIODevice::ReadOnly );
    280     const QByteArray metainfo( file.readAll( ) );
    281     file.close( );
    282     int base64Size = 0;
    283     char * base64 = tr_base64_encode( metainfo.constData(), metainfo.size(), &base64Size );
    284     tr_bencDictAddRaw( args, "metainfo", base64, base64Size );
    285     tr_free( base64 );
     283    if( Utils::isMagnetLink( myFile ) || Utils::isURL( myFile ) )
     284        tr_bencDictAddStr( args, "filename", myFile.toUtf8().constData() );
     285    else {
     286        QFile file( myFile );
     287        file.open( QIODevice::ReadOnly );
     288        const QByteArray metainfo( file.readAll( ) );
     289        file.close( );
     290        int base64Size = 0;
     291        char * base64 = tr_base64_encode( metainfo.constData(), metainfo.size(), &base64Size );
     292        tr_bencDictAddRaw( args, "metainfo", base64, base64Size );
     293        tr_free( base64 );
     294    }
    286295
    287296    // paused
     
    327336    }
    328337
     338std::cerr << tr_bencToStr(&top,TR_FMT_JSON,NULL) << std::endl;
    329339    mySession.exec( &top );
    330340
  • trunk/qt/session.cc

    r10638 r10645  
    3636#include "session-dialog.h"
    3737#include "torrent.h"
     38#include "utils.h"
    3839
    3940// #define DEBUG_HTTP
     
    866867    bool isLink( const QString& str )
    867868    {
    868         return str.startsWith( "magnet:?" )
    869             || str.startsWith( "http://" )
    870             || str.startsWith( "https://" )
    871             || str.startsWith( "ftp://" );
     869        return Utils::isMagnetLink(str) || Utils::isURL(str);
    872870    }
    873871}
  • trunk/qt/utils.h

    r9868 r10645  
    3838        static void toStderr( const QString& qstr );
    3939
     40        ///
     41        /// URLs
     42        ///
     43
     44        static bool isMagnetLink( const QString& s ) { return s.startsWith( "magnet:?" ); }
     45
     46        static bool isURL( const QString& s ) { return s.startsWith( "http://" )
     47                                                    || s.startsWith( "https://" )
     48                                                    || s.startsWith( "ftp://" ); }
     49
    4050};
    4151
Note: See TracChangeset for help on using the changeset viewer.