mirror of
https://github.com/transmission/transmission
synced 2025-03-03 10:15:45 +00:00
(trunk qt) #2612 "display new transfer window when adding magnet transfer" -- implemented for Qt client
This commit is contained in:
parent
e7e627c3e7
commit
77ef2c1e0c
4 changed files with 41 additions and 17 deletions
14
qt/app.cc
14
qt/app.cc
|
@ -225,7 +225,7 @@ MyApp :: MyApp( int& argc, char ** argv ):
|
|||
}
|
||||
|
||||
for( QStringList::const_iterator it=filenames.begin(), end=filenames.end(); it!=end; ++it )
|
||||
mySession->addTorrent( *it );
|
||||
addTorrent( *it );
|
||||
|
||||
// register as the dbus handler for Transmission
|
||||
new TrDBusAdaptor( this );
|
||||
|
@ -322,13 +322,19 @@ void
|
|||
MyApp :: addTorrent( const QString& key )
|
||||
{
|
||||
if( !myPrefs->getBool( Prefs :: OPTIONS_PROMPT ) )
|
||||
{
|
||||
mySession->addTorrent( key );
|
||||
else if( !QFile( key ).exists( ) )
|
||||
myWindow->openURL( key );
|
||||
else {
|
||||
}
|
||||
else if( Utils::isMagnetLink( key ) || QFile( key ).exists( ) )
|
||||
{
|
||||
Options * o = new Options( *mySession, *myPrefs, key, myWindow );
|
||||
o->show( );
|
||||
}
|
||||
else if( Utils::isURL( key ) )
|
||||
{
|
||||
myWindow->openURL( key );
|
||||
}
|
||||
|
||||
raise( );
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "prefs.h"
|
||||
#include "session.h"
|
||||
#include "torrent.h"
|
||||
#include "utils.h"
|
||||
|
||||
/***
|
||||
****
|
||||
|
@ -214,7 +215,11 @@ Options :: reload( )
|
|||
clearVerify( );
|
||||
|
||||
tr_ctor * ctor = tr_ctorNew( 0 );
|
||||
tr_ctorSetMetainfoFromFile( ctor, myFile.toUtf8().constData() );
|
||||
if( Utils::isMagnetLink( myFile ) )
|
||||
tr_ctorSetMetainfoFromMagnetLink( ctor, myFile.toUtf8().constData() );
|
||||
else
|
||||
tr_ctorSetMetainfoFromFile( ctor, myFile.toUtf8().constData() );
|
||||
|
||||
const int err = tr_torrentParse( ctor, &myInfo );
|
||||
myHaveInfo = !err;
|
||||
tr_ctorFree( ctor );
|
||||
|
@ -275,14 +280,18 @@ Options :: onAccepted( )
|
|||
tr_bencDictAddStr( args, "download-dir", myDestination.absolutePath().toUtf8().constData() );
|
||||
|
||||
// "metainfo"
|
||||
QFile file( myFile );
|
||||
file.open( QIODevice::ReadOnly );
|
||||
const QByteArray metainfo( file.readAll( ) );
|
||||
file.close( );
|
||||
int base64Size = 0;
|
||||
char * base64 = tr_base64_encode( metainfo.constData(), metainfo.size(), &base64Size );
|
||||
tr_bencDictAddRaw( args, "metainfo", base64, base64Size );
|
||||
tr_free( base64 );
|
||||
if( Utils::isMagnetLink( myFile ) || Utils::isURL( myFile ) )
|
||||
tr_bencDictAddStr( args, "filename", myFile.toUtf8().constData() );
|
||||
else {
|
||||
QFile file( myFile );
|
||||
file.open( QIODevice::ReadOnly );
|
||||
const QByteArray metainfo( file.readAll( ) );
|
||||
file.close( );
|
||||
int base64Size = 0;
|
||||
char * base64 = tr_base64_encode( metainfo.constData(), metainfo.size(), &base64Size );
|
||||
tr_bencDictAddRaw( args, "metainfo", base64, base64Size );
|
||||
tr_free( base64 );
|
||||
}
|
||||
|
||||
// paused
|
||||
tr_bencDictAddBool( args, "paused", !myStartCheck->isChecked( ) );
|
||||
|
@ -326,6 +335,7 @@ Options :: onAccepted( )
|
|||
fileAdded, SLOT(executed(int64_t,const QString&, struct tr_benc*)));
|
||||
}
|
||||
|
||||
std::cerr << tr_bencToStr(&top,TR_FMT_JSON,NULL) << std::endl;
|
||||
mySession.exec( &top );
|
||||
|
||||
tr_bencFree( &top );
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "session.h"
|
||||
#include "session-dialog.h"
|
||||
#include "torrent.h"
|
||||
#include "utils.h"
|
||||
|
||||
// #define DEBUG_HTTP
|
||||
|
||||
|
@ -865,10 +866,7 @@ namespace
|
|||
{
|
||||
bool isLink( const QString& str )
|
||||
{
|
||||
return str.startsWith( "magnet:?" )
|
||||
|| str.startsWith( "http://" )
|
||||
|| str.startsWith( "https://" )
|
||||
|| str.startsWith( "ftp://" );
|
||||
return Utils::isMagnetLink(str) || Utils::isURL(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
10
qt/utils.h
10
qt/utils.h
|
@ -37,6 +37,16 @@ class Utils: public QObject
|
|||
// meh
|
||||
static void toStderr( const QString& qstr );
|
||||
|
||||
///
|
||||
/// URLs
|
||||
///
|
||||
|
||||
static bool isMagnetLink( const QString& s ) { return s.startsWith( "magnet:?" ); }
|
||||
|
||||
static bool isURL( const QString& s ) { return s.startsWith( "http://" )
|
||||
|| s.startsWith( "https://" )
|
||||
|| s.startsWith( "ftp://" ); }
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue