diff --git a/gtk/tr-core-dbus.xml b/gtk/tr-core-dbus.xml
index ecdb85748..ddec6b4b1 100644
--- a/gtk/tr-core-dbus.xml
+++ b/gtk/tr-core-dbus.xml
@@ -4,7 +4,6 @@
-
diff --git a/gtk/tr-core.c b/gtk/tr-core.c
index bc66285c9..c43cfd618 100644
--- a/gtk/tr-core.c
+++ b/gtk/tr-core.c
@@ -1026,7 +1026,6 @@ tr_core_add_ctor( TrCore * core, tr_ctor * ctor )
gboolean
tr_core_add_metainfo( TrCore * core,
const char * payload,
- const char * filename,
gboolean * setme_handled,
GError ** gerr UNUSED )
{
@@ -1041,38 +1040,23 @@ tr_core_add_metainfo( TrCore * core,
tr_core_add_from_url( core, payload );
*setme_handled = TRUE;
}
- else
+ else /* base64-encoded metainfo */
{
+ int file_length;
tr_ctor * ctor;
- gboolean has_metainfo = FALSE;
- const gboolean do_prompt = pref_flag_get( PREF_KEY_OPTIONS_PROMPT );
+ char * file_contents;
+ gboolean do_prompt = pref_flag_get( PREF_KEY_OPTIONS_PROMPT );
- /* create the constructor */
ctor = tr_ctorNew( session );
tr_core_apply_defaults( ctor );
- if( !has_metainfo && g_file_test( filename, G_FILE_TEST_IS_REGULAR ) )
- {
- /* set the metainfo from a local file */
- has_metainfo = !tr_ctorSetMetainfoFromFile( ctor, filename );
- }
+ file_contents = tr_base64_decode( payload, -1, &file_length );
+ tr_ctorSetMetainfo( ctor, (const uint8_t*)file_contents, file_length );
+ add_ctor( core, ctor, do_prompt, TRUE );
- if( !has_metainfo )
- {
- /* base64-encoded metainfo */
- int file_length;
- char * file_contents = tr_base64_decode( payload, -1, &file_length );
- has_metainfo = !tr_ctorSetMetainfo( ctor, (const uint8_t*)file_contents, file_length );
- tr_free( file_contents );
- }
-
- if( has_metainfo )
- {
- add_ctor( core, ctor, do_prompt, TRUE );
- tr_core_torrents_added( core );
- }
-
- *setme_handled = has_metainfo;
+ tr_free( file_contents );
+ tr_core_torrents_added( core );
+ *setme_handled = TRUE;
}
return TRUE;
diff --git a/gtk/tr-core.h b/gtk/tr-core.h
index 56cbd8739..fe9874313 100644
--- a/gtk/tr-core.h
+++ b/gtk/tr-core.h
@@ -117,8 +117,7 @@ void tr_core_add_list( TrCore * self,
/** @brief Add a torrent. */
gboolean tr_core_add_metainfo( TrCore * core,
- const char * payload,
- const char * optional_filename,
+ const char * base64_metainfo,
gboolean * setme_success,
GError ** err );
diff --git a/gtk/util.c b/gtk/util.c
index 569a66ea6..4d72aeea7 100644
--- a/gtk/util.c
+++ b/gtk/util.c
@@ -586,7 +586,6 @@ gtr_dbus_add_torrent( const char * filename )
if( proxy )
dbus_g_proxy_call( proxy, "AddMetainfo", &err,
G_TYPE_STRING, payload,
- G_TYPE_STRING, filename,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &handled,
G_TYPE_INVALID );
diff --git a/qt/add-data.cc b/qt/add-data.cc
new file mode 100644
index 000000000..1a02cfa08
--- /dev/null
+++ b/qt/add-data.cc
@@ -0,0 +1,101 @@
+/*
+ * This file Copyright (C) 2010 Mnemosyne LLC
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * $Id$
+ */
+
+#include
+#include // tr_base64_encode()
+#include // tr_base64_encode()
+
+#include "add-data.h"
+#include "utils.h"
+
+int
+AddData :: set( const QString& key )
+{
+ if( Utils::isMagnetLink( key ) )
+ {
+ magnet = key;
+ type = MAGNET;
+ }
+ else if ( Utils::isURL( key ) )
+ {
+ url = key;
+ type = URL;
+ }
+ else if( QFile(key).exists( ) )
+ {
+ filename = key;
+ type = FILENAME;
+
+ QFile file( key );
+ file.open( QIODevice::ReadOnly );
+ metainfo = file.readAll( );
+ file.close( );
+ }
+ else
+ {
+ int len;
+ char * raw = tr_base64_decode( key.toUtf8().constData(), key.toUtf8().size(), &len );
+ if( raw ) {
+ metainfo.append( raw, len );
+ tr_free( raw );
+ type = METAINFO;
+ }
+ else type = NONE;
+ }
+
+ return type;
+}
+
+QByteArray
+AddData :: toBase64( ) const
+{
+ QByteArray ret;
+
+ if( !metainfo.isEmpty( ) )
+ {
+ int len = 0;
+ char * b64 = tr_base64_encode( metainfo.constData(), metainfo.size(), &len );
+ ret = QByteArray( b64, len );
+ tr_free( b64 );
+ }
+
+ return ret;
+}
+
+QString
+AddData :: readableName( ) const
+{
+ QString ret;
+
+ switch( type )
+ {
+ case FILENAME: ret = filename; break;
+
+ case MAGNET: ret = magnet; break;
+
+ case URL: ret = url.toString(); break;
+
+ case METAINFO: {
+ tr_info inf;
+ tr_ctor * ctor = tr_ctorNew( NULL );
+ tr_ctorSetMetainfo( ctor, (const uint8_t*)metainfo.constData(), metainfo.size() );
+ if( tr_torrentParse( ctor, &inf ) == TR_PARSE_OK ) {
+ ret = inf.name;
+ tr_metainfoFree( &inf );
+ }
+ tr_ctorFree( ctor );
+ break;
+ }
+ }
+
+ return ret;
+}
diff --git a/qt/add-data.h b/qt/add-data.h
new file mode 100644
index 000000000..5ef43a812
--- /dev/null
+++ b/qt/add-data.h
@@ -0,0 +1,45 @@
+/*
+ * This file Copyright (C) 2010 Mnemosyne LLC
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * $Id$
+ */
+
+#ifndef ADD_DATA_H
+#define ADD_DATA_H
+
+#include
+#include
+#include
+#include
+#include
+
+class AddData
+{
+ public:
+
+ enum { NONE, MAGNET, URL, FILENAME, METAINFO };
+ int type;
+
+ QByteArray metainfo;
+ QString filename;
+ QString magnet;
+ QUrl url;
+
+ public:
+
+ int set( const QString& );
+ AddData( const QString& str ) { set(str); }
+ AddData( ): type(NONE) { }
+
+ QByteArray toBase64( ) const;
+
+ QString readableName( ) const;
+};
+
+#endif
diff --git a/qt/app.cc b/qt/app.cc
index b257ae670..80ce0da5c 100644
--- a/qt/app.cc
+++ b/qt/app.cc
@@ -30,6 +30,7 @@
#include
#include
+#include "add-data.h"
#include "app.h"
#include "dbus-adaptor.h"
#include "formatter.h"
@@ -238,12 +239,10 @@ MyApp :: MyApp( int& argc, char ** argv ):
// register as the dbus handler for Transmission
new TrDBusAdaptor( this );
QDBusConnection bus = QDBusConnection::sessionBus();
- if (!bus.registerService("com.transmissionbt.Transmission"))
- if(bus.lastError().isValid())
- std::cerr << qPrintable(bus.lastError().message()) << std::endl;
- if( !bus.registerObject( "/com/transmissionbt/Transmission", this ))
- if(bus.lastError().isValid())
- std::cerr << qPrintable(bus.lastError().message()) << std::endl;
+ if( !bus.registerService( DBUS_SERVICE ) )
+ std::cerr << "couldn't register " << DBUS_SERVICE << std::endl;
+ if( !bus.registerObject( DBUS_OBJECT_PATH, this ) )
+ std::cerr << "couldn't register " << DBUS_OBJECT_PATH << std::endl;
}
void
@@ -366,20 +365,29 @@ MyApp :: refreshTorrents( )
void
MyApp :: addTorrent( const QString& key )
+{
+ const AddData addme( key );
+
+ if( addme.type != addme.NONE )
+ addTorrent( addme );
+}
+
+void
+MyApp :: addTorrent( const AddData& addme )
{
if( !myPrefs->getBool( Prefs :: OPTIONS_PROMPT ) )
{
- mySession->addTorrent( key );
+ mySession->addTorrent( addme );
}
- else if( Utils::isMagnetLink( key ) || QFile( key ).exists( ) )
+ else if( addme.type == addme.URL )
{
- Options * o = new Options( *mySession, *myPrefs, key, myWindow );
+ myWindow->openURL( addme.url.toString( ) );
+ }
+ else
+ {
+ Options * o = new Options( *mySession, *myPrefs, addme, myWindow );
o->show( );
}
- else if( Utils::isURL( key ) )
- {
- myWindow->openURL( key );
- }
raise( );
}
@@ -440,17 +448,17 @@ main( int argc, char * argv[] )
QDBusConnection bus = QDBusConnection::sessionBus();
for( int i=0, n=addme.size(); i arguments;
- arguments.push_back( QVariant( key ) );
+ arguments.push_back( AddData(addme[i]).toBase64().constData() );
request.setArguments( arguments );
QDBusMessage response = bus.call( request );
+ //std::cerr << qPrintable(response.errorName()) << std::endl;
+ //std::cerr << qPrintable(response.errorMessage()) << std::endl;
arguments = response.arguments( );
delegated |= (arguments.size()==1) && arguments[0].toBool();
}
diff --git a/qt/app.h b/qt/app.h
index 31da7769c..dee0c5f75 100644
--- a/qt/app.h
+++ b/qt/app.h
@@ -16,8 +16,10 @@
#include
#include
#include
+
#include "favicon.h"
+class AddData;
class Prefs;
class Session;
class TorrentModel;
@@ -60,6 +62,7 @@ class MyApp: public QApplication
public slots:
void addTorrent( const QString& );
+ void addTorrent( const AddData& );
private:
void maybeUpdateBlocklist( );
diff --git a/qt/dbus-adaptor.cc b/qt/dbus-adaptor.cc
index 8e01b2499..f4bdfa5c4 100644
--- a/qt/dbus-adaptor.cc
+++ b/qt/dbus-adaptor.cc
@@ -10,7 +10,7 @@
* $Id:$
*/
-#include
+#include "add-data.h"
#include "app.h"
#include "dbus-adaptor.h"
@@ -28,8 +28,12 @@ TrDBusAdaptor :: PresentWindow( )
}
bool
-TrDBusAdaptor :: AddMetainfo( const QString& payload, const QString& filename )
+TrDBusAdaptor :: AddMetainfo( const QString& key )
{
- myApp->addTorrent( QFile(filename).exists() ? filename : payload );
+ AddData addme( key );
+
+ if( addme.type != addme.NONE )
+ myApp->addTorrent( addme );
+
return true;
}
diff --git a/qt/dbus-adaptor.h b/qt/dbus-adaptor.h
index 5e0d2be16..da94e9fef 100644
--- a/qt/dbus-adaptor.h
+++ b/qt/dbus-adaptor.h
@@ -31,7 +31,7 @@ class TrDBusAdaptor: public QDBusAbstractAdaptor
public slots:
bool PresentWindow();
- bool AddMetainfo( const QString& payload, const QString& filename );
+ bool AddMetainfo( const QString& );
};
#endif
diff --git a/qt/make-dialog.cc b/qt/make-dialog.cc
index 5863cbc4c..ba5252d95 100644
--- a/qt/make-dialog.cc
+++ b/qt/make-dialog.cc
@@ -58,7 +58,7 @@ MakeDialog :: onNewButtonBoxClicked( QAbstractButton * button )
{
case QDialogButtonBox::Open:
std::cerr << "calling mySession.addTorrent( " << qPrintable(myTarget) << ", " << qPrintable(QFileInfo(myBuilder->top).dir().path()) << ')' << std::endl;
- mySession.addTorrent( myTarget, QFileInfo(myBuilder->top).dir().path() );
+ mySession.addNewlyCreatedTorrent( myTarget, QFileInfo(myBuilder->top).dir().path() );
break;
case QDialogButtonBox::Abort:
myBuilder->abortFlag = true;
diff --git a/qt/options.cc b/qt/options.cc
index 1ece6f923..2f25ba440 100644
--- a/qt/options.cc
+++ b/qt/options.cc
@@ -13,6 +13,7 @@
#include
#include
+#include
#include
#include
#include
@@ -22,6 +23,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -32,6 +34,7 @@
#include
#include /* mime64 */
+#include "add-data.h"
#include "file-tree.h"
#include "hig.h"
#include "options.h"
@@ -44,10 +47,39 @@
****
***/
-Options :: Options( Session& session, const Prefs& prefs, const QString& filename, QWidget * parent ):
+void
+FileAdded :: executed( int64_t tag, const QString& result, struct tr_benc * arguments )
+{
+ Q_UNUSED( arguments );
+
+ if( tag != myTag )
+ return;
+
+ if( result == "success" )
+ if( !myDelFile.isEmpty( ) )
+ QFile( myDelFile ).remove( );
+
+ if( result != "success" ) {
+ QString text = result;
+ for( int i=0, n=text.size(); i%1
%2
").arg(text).arg(myName) );
+ }
+
+ deleteLater();
+}
+
+/***
+****
+***/
+
+Options :: Options( Session& session, const Prefs& prefs, const AddData& addme, QWidget * parent ):
QDialog( parent, Qt::Dialog ),
mySession( session ),
- myFile( filename ),
+ myAdd( addme ),
myHaveInfo( false ),
myDestinationButton( 0 ),
myVerifyButton( 0 ),
@@ -168,7 +200,17 @@ Options :: refreshButton( QPushButton * p, const QString& text, int width )
void
Options :: refreshFileButton( int width )
{
- refreshButton( myFileButton, QFileInfo(myFile).baseName(), width );
+ QString text;
+
+ switch( myAdd.type )
+ {
+ case AddData::FILENAME: text = QFileInfo(myAdd.filename).baseName(); break;
+ case AddData::URL: text = myAdd.url.toString(); break;
+ case AddData::MAGNET: text = myAdd.magnet; break;
+ default: break;
+ }
+
+ refreshButton( myFileButton, text, width );
}
void
@@ -215,10 +257,13 @@ Options :: reload( )
clearVerify( );
tr_ctor * ctor = tr_ctorNew( 0 );
- if( Utils::isMagnetLink( myFile ) )
- tr_ctorSetMetainfoFromMagnetLink( ctor, myFile.toUtf8().constData() );
- else
- tr_ctorSetMetainfoFromFile( ctor, myFile.toUtf8().constData() );
+
+ switch( myAdd.type ) {
+ case AddData::MAGNET: tr_ctorSetMetainfoFromMagnetLink( ctor, myAdd.magnet.toUtf8().constData() ); break;
+ case AddData::FILENAME: tr_ctorSetMetainfoFromFile( ctor, myAdd.filename.toUtf8().constData() ); break;
+ case AddData::METAINFO: tr_ctorSetMetainfo( ctor, (const uint8_t*)myAdd.metainfo.constData(), myAdd.metainfo.size() ); break;
+ default: break;
+ }
const int err = tr_torrentParse( ctor, &myInfo );
myHaveInfo = !err;
@@ -280,17 +325,25 @@ Options :: onAccepted( )
tr_bencDictAddStr( args, "download-dir", myDestination.absolutePath().toUtf8().constData() );
// "metainfo"
- 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 );
+ switch( myAdd.type )
+ {
+ case AddData::MAGNET:
+ tr_bencDictAddStr( args, "filename", myAdd.magnet.toUtf8().constData() );
+ break;
+
+ case AddData::URL:
+ tr_bencDictAddStr( args, "filename", myAdd.url.toString().toUtf8().constData() );
+ break;
+
+ case AddData::FILENAME:
+ case AddData::METAINFO: {
+ const QByteArray b64 = myAdd.toBase64( );
+ tr_bencDictAddRaw( args, "metainfo", b64.constData(), b64.size() );
+ break;
+ }
+
+ default:
+ std::cerr << "unhandled AddData.type: " << myAdd.type << std::endl;
}
// paused
@@ -329,11 +382,11 @@ Options :: onAccepted( )
}
// maybe delete the source .torrent
- if( myTrashCheck->isChecked( ) ) {
- FileAdded * fileAdded = new FileAdded( tag, myFile );
- connect( &mySession, SIGNAL(executed(int64_t,const QString&, struct tr_benc*)),
- fileAdded, SLOT(executed(int64_t,const QString&, struct tr_benc*)));
- }
+ FileAdded * fileAdded = new FileAdded( tag, myAdd.readableName() );
+ if( myTrashCheck->isChecked( ) && ( myAdd.type==AddData::FILENAME ) )
+ fileAdded->setFileToDelete( myAdd.filename );
+ connect( &mySession, SIGNAL(executed(int64_t,const QString&, struct tr_benc*)),
+ fileAdded, SLOT(executed(int64_t,const QString&, struct tr_benc*)));
//std::cerr << tr_bencToStr(&top,TR_FMT_JSON,NULL) << std::endl;
mySession.exec( &top );
@@ -345,13 +398,16 @@ Options :: onAccepted( )
void
Options :: onFilenameClicked( )
{
- QFileDialog * d = new QFileDialog( this,
- tr( "Add Torrent" ),
- QFileInfo(myFile).absolutePath(),
- tr( "Torrent Files (*.torrent);;All Files (*.*)" ) );
- d->setFileMode( QFileDialog::ExistingFile );
- connect( d, SIGNAL(filesSelected(const QStringList&)), this, SLOT(onFilesSelected(const QStringList&)) );
- d->show( );
+ if( myAdd.type == AddData::FILENAME )
+ {
+ QFileDialog * d = new QFileDialog( this,
+ tr( "Add Torrent" ),
+ QFileInfo(myAdd.filename).absolutePath(),
+ tr( "Torrent Files (*.torrent);;All Files (*.*)" ) );
+ d->setFileMode( QFileDialog::ExistingFile );
+ connect( d, SIGNAL(filesSelected(const QStringList&)), this, SLOT(onFilesSelected(const QStringList&)) );
+ d->show( );
+ }
}
void
@@ -359,7 +415,7 @@ Options :: onFilesSelected( const QStringList& files )
{
if( files.size() == 1 )
{
- myFile = files.at( 0 );
+ myAdd.set( files.at(0) );
refreshFileButton( );
reload( );
}
diff --git a/qt/options.h b/qt/options.h
index 51c4a1056..e7bd12143 100644
--- a/qt/options.h
+++ b/qt/options.h
@@ -13,6 +13,8 @@
#ifndef OPTIONS_DIALOG_H
#define OPTIONS_DIALOG_H
+#include
+
#include
#include
#include
@@ -20,12 +22,14 @@
#include
#include
#include
+#include
#include
#include
#include
#include
-#include "file-tree.h"
+#include "add-data.h" // AddData
+#include "file-tree.h" // FileList
class FileTreeView;
class Prefs;
@@ -39,21 +43,16 @@ class FileAdded: public QObject
{
Q_OBJECT
const int64_t myTag;
+ QString myName;
QString myDelFile;
public:
- FileAdded( int tag, const QString file ): myTag(tag), myDelFile(file) { }
+ FileAdded( int tag, const QString& name ): myTag(tag), myName(name) { }
~FileAdded( ) { }
+ void setFileToDelete( const QString& file ) { myDelFile = file; }
public slots:
- void executed( int64_t tag, const QString& result, struct tr_benc * arguments ) {
- Q_UNUSED( arguments );
- if( tag == myTag ) {
- if( result == "success" )
- QFile( myDelFile ).remove( );
- deleteLater();
- }
- }
+ void executed( int64_t tag, const QString& result, struct tr_benc * arguments );
};
class Options: public QDialog
@@ -61,7 +60,7 @@ class Options: public QDialog
Q_OBJECT
public:
- Options( Session& session, const Prefs& prefs, const QString& filename, QWidget * parent = 0 );
+ Options( Session& session, const Prefs& prefs, const AddData& addme, QWidget * parent = 0 );
~Options( );
private:
@@ -73,7 +72,7 @@ class Options: public QDialog
private:
Session& mySession;
- QString myFile;
+ AddData myAdd;
QDir myDestination;
bool myHaveInfo;
tr_info myInfo;
diff --git a/qt/qtr.pro b/qt/qtr.pro
index 1574e83e1..03026e830 100644
--- a/qt/qtr.pro
+++ b/qt/qtr.pro
@@ -30,14 +30,39 @@ TRANSLATIONS += transmission_en.ts transmission_ru.ts
FORMS += mainwin.ui
RESOURCES += application.qrc
-SOURCES += about.cc app.cc dbus-adaptor.cc details.cc favicon.cc file-tree.cc \
- filterbar.cc filters.cc formatter.cc hig.cc license.cc mainwin.cc \
- make-dialog.cc options.cc prefs.cc prefs-dialog.cc qticonloader.cc \
- relocate.cc session.cc session-dialog.cc squeezelabel.cc \
- stats-dialog.cc torrent.cc torrent-delegate.cc \
- torrent-delegate-min.cc torrent-filter.cc torrent-model.cc \
- tracker-delegate.cc tracker-model.cc tracker-model-filter.cc \
- triconpushbutton.cc utils.cc watchdir.cc
+SOURCES += about.cc \
+ add-data.cc \
+ app.cc \
+ dbus-adaptor.cc \
+ details.cc \
+ favicon.cc \
+ file-tree.cc \
+ filterbar.cc \
+ filters.cc \
+ formatter.cc \
+ hig.cc \
+ license.cc \
+ mainwin.cc \
+ make-dialog.cc \
+ options.cc \
+ prefs.cc \
+ prefs-dialog.cc \
+ qticonloader.cc \
+ relocate.cc \
+ session.cc \
+ session-dialog.cc \
+ squeezelabel.cc \
+ stats-dialog.cc \
+ torrent.cc torrent-delegate.cc \
+ torrent-delegate-min.cc \
+ torrent-filter.cc \
+ torrent-model.cc \
+ tracker-delegate.cc \
+ tracker-model.cc \
+ tracker-model-filter.cc \
+ triconpushbutton.cc \
+ utils.cc \
+ watchdir.cc
HEADERS += $$replace(SOURCES, .cc, .h)
HEADERS += speed.h types.h
diff --git a/qt/session.cc b/qt/session.cc
index 9aac79bb9..a4525310b 100644
--- a/qt/session.cc
+++ b/qt/session.cc
@@ -33,6 +33,7 @@
#include /* tr_free */
#include /* LONG_VERSION */
+#include "add-data.h"
#include "prefs.h"
#include "qticonloader.h"
#include "session.h"
@@ -925,54 +926,38 @@ Session :: setBlocklistSize( int64_t i )
}
void
-Session :: addTorrent( QString filename )
+Session :: addTorrent( const AddData& addMe )
{
- addTorrent( filename, myPrefs.getString( Prefs::DOWNLOAD_DIR ) );
-}
+ const QByteArray b64 = addMe.toBase64();
-namespace
-{
- bool isLink( const QString& str )
- {
- return Utils::isMagnetLink(str) || Utils::isURL(str);
+ tr_benc top, *args;
+ tr_bencInitDict( &top, 2 );
+ tr_bencDictAddStr( &top, "method", "torrent-add" );
+ args = tr_bencDictAddDict( &top, "arguments", 2 );
+ tr_bencDictAddBool( args, "paused", !myPrefs.getBool( Prefs::START ) );
+ switch( addMe.type ) {
+ case AddData::MAGNET: tr_bencDictAddStr( args, "filename", addMe.magnet.toUtf8().constData() ); break;
+ case AddData::URL: tr_bencDictAddStr( args, "filename", addMe.url.toString().toUtf8().constData() ); break;
+ case AddData::FILENAME: /* fall-through */
+ case AddData::METAINFO: tr_bencDictAddRaw( args, "metainfo", b64.constData(), b64.size() ); break;
+ default: std::cerr << "Unhandled AddData type: " << addMe.type << std::endl;
}
+ exec( &top );
+ tr_bencFree( &top );
}
void
-Session :: addTorrent( QString key, QString localPath )
+Session :: addNewlyCreatedTorrent( const QString& filename, const QString& localPath )
{
+ const QByteArray b64 = AddData(filename).toBase64();
+
tr_benc top, *args;
tr_bencInitDict( &top, 2 );
tr_bencDictAddStr( &top, "method", "torrent-add" );
args = tr_bencDictAddDict( &top, "arguments", 3 );
tr_bencDictAddStr( args, "download-dir", qPrintable(localPath) );
tr_bencDictAddBool( args, "paused", !myPrefs.getBool( Prefs::START ) );
-
- // figure out what to do with "key"....
- bool keyHandled = false;
- if( !keyHandled && isLink( key )) {
- tr_bencDictAddStr( args, "filename", key.toUtf8().constData() );
- keyHandled = true; // it's a URL or magnet link...
- }
- if( !keyHandled ) {
- QFile file( key );
- file.open( QIODevice::ReadOnly );
- const QByteArray raw( file.readAll( ) );
- file.close( );
- if( !raw.isEmpty( ) ) {
- int b64len = 0;
- char * b64 = tr_base64_encode( raw.constData(), raw.size(), &b64len );
- tr_bencDictAddRaw( args, "metainfo", b64, b64len );
- tr_free( b64 );
- keyHandled = true; // it's a local file...
- }
- }
- if( !keyHandled ) {
- const QByteArray tmp = key.toUtf8();
- tr_bencDictAddRaw( args, "metainfo", tmp.constData(), tmp.length() );
- keyHandled = true; // treat it as base64
- }
-
+ tr_bencDictAddRaw( args, "metainfo", b64.constData(), b64.size() );
exec( &top );
tr_bencFree( &top );
}
diff --git a/qt/session.h b/qt/session.h
index 532f11052..153b4957f 100644
--- a/qt/session.h
+++ b/qt/session.h
@@ -23,6 +23,8 @@
class QStringList;
+class AddData;
+
#include
extern "C"
@@ -112,8 +114,8 @@ class Session: public QObject
void refreshActiveTorrents( );
void refreshAllTorrents( );
void initTorrents( const QSet& ids = QSet() );
- void addTorrent( QString filename );
- void addTorrent( QString filename, QString localPath );
+ void addNewlyCreatedTorrent( const QString& filename, const QString& localPath );
+ void addTorrent( const AddData& addme );
void removeTorrents( const QSet& torrentIds, bool deleteFiles=false );
void verifyTorrents( const QSet& torrentIds );
void reannounceTorrents( const QSet& torrentIds );