]> granicus.if.org Git - transmission/commitdiff
(trunk) #3450 "regression: Qt client dbus support broken" -- fixed
authorCharles Kerr <charles@transmissionbt.com>
Sun, 1 Aug 2010 18:55:04 +0000 (18:55 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Sun, 1 Aug 2010 18:55:04 +0000 (18:55 +0000)
16 files changed:
gtk/tr-core-dbus.xml
gtk/tr-core.c
gtk/tr-core.h
gtk/util.c
qt/add-data.cc [new file with mode: 0644]
qt/add-data.h [new file with mode: 0644]
qt/app.cc
qt/app.h
qt/dbus-adaptor.cc
qt/dbus-adaptor.h
qt/make-dialog.cc
qt/options.cc
qt/options.h
qt/qtr.pro
qt/session.cc
qt/session.h

index ecdb857480f05bf9bf79b35c04adadeaeaa27540..ddec6b4b1deb92585b182260e737120b3318a064 100644 (file)
@@ -4,7 +4,6 @@
     <method name="AddMetainfo">
       <arg type="b" name="handled" direction="out"/>
       <arg type="s" name="metainfo" direction="in"/>
-      <arg type="s" name="filename" direction="in"/>
     </method>
     <method name="PresentWindow">
       <arg type="b" name="handled" direction="out"/>
index bc66285c9730ad14304201211989d9e03b06b083..c43cfd6184884cbeda9ebcde1577a459f10dae34 100644 (file)
@@ -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 );
-        }
-
-        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 );
-        }
+        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 );
 
-        *setme_handled = has_metainfo;
+        tr_free( file_contents );
+        tr_core_torrents_added( core );
+        *setme_handled = TRUE;
     }
 
     return TRUE;
index 56cbd8739e5a5e646e8d05091b1a8c64b7453515..fe9874313d2e4abe30a1846969a24bea6795083d 100644 (file)
@@ -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 );
 
index 569a66ea6458cefe6e439162b9a9f7862509a4a6..4d72aeea7a68f7b110144025042da5867df40fbf 100644 (file)
@@ -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 (file)
index 0000000..1a02cfa
--- /dev/null
@@ -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 <libtransmission/transmission.h>
+#include <libtransmission/bencode.h> // tr_base64_encode()
+#include <libtransmission/utils.h> // 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 (file)
index 0000000..5ef43a8
--- /dev/null
@@ -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 <QByteArray>
+#include <QFile>
+#include <QObject>
+#include <QString>
+#include <QUrl>
+
+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
index b257ae670eb1b5fd94e123b849a8031a1e8157a5..80ce0da5cfb68e5076be0398fe35348fbdd61f1b 100644 (file)
--- a/qt/app.cc
+++ b/qt/app.cc
@@ -30,6 +30,7 @@
 #include <libtransmission/utils.h>
 #include <libtransmission/version.h>
 
+#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,19 +365,28 @@ 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 );
-        o->show( );
+        myWindow->openURL( addme.url.toString( ) );
     }
-    else if( Utils::isURL( key ) )
+    else
     {
-        myWindow->openURL( key );
+        Options * o = new Options( *mySession, *myPrefs, addme, myWindow );
+        o->show( );
     }
 
     raise( );
@@ -440,17 +448,17 @@ main( int argc, char * argv[] )
     QDBusConnection bus = QDBusConnection::sessionBus();
     for( int i=0, n=addme.size(); i<n; ++i )
     {
-        const QString key = addme[i];
-
         QDBusMessage request = QDBusMessage::createMethodCall( DBUS_SERVICE,
                                                                DBUS_OBJECT_PATH,
                                                                DBUS_INTERFACE,
                                                                "AddMetainfo" );
         QList<QVariant> 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();
     }
index 31da7769cf0e1973205afb5f282fd044c38d5cdd..dee0c5f75f1311b841005447802dc29db12eaf3b 100644 (file)
--- a/qt/app.h
+++ b/qt/app.h
 #include <QApplication>
 #include <QSet>
 #include <QTimer>
+
 #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( );
index 8e01b2499376ff5c0e9b052890778df15537b05d..f4bdfa5c42da3003d27563e9ff35ca660918e1cb 100644 (file)
@@ -10,7 +10,7 @@
  * $Id:$
  */
 
-#include <QFile>
+#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;
 }
index 5e0d2be1659d11bdf0809f8802714b96312ae058..da94e9fefdb7fd6d466232ad1aafa7c20b59aa48 100644 (file)
@@ -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
index 5863cbc4c69bbcac871b49d5538ca66bb55c6613..ba5252d952a256b75d605ef04a158cb517222034 100644 (file)
@@ -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;
index 1ece6f9234c100a9cf2d44d2c6325b147dd22cde..2f25ba4408959f3817a46ef946ebf3b21046d56c 100644 (file)
@@ -13,6 +13,7 @@
 #include <cstdio>
 #include <iostream>
 
+#include <QApplication>
 #include <QCheckBox>
 #include <QComboBox>
 #include <QDialogButtonBox>
@@ -22,6 +23,7 @@
 #include <QFileInfo>
 #include <QGridLayout>
 #include <QLabel>
+#include <QMessageBox>
 #include <QPushButton>
 #include <QResizeEvent>
 #include <QSet>
@@ -32,6 +34,7 @@
 #include <libtransmission/bencode.h>
 #include <libtransmission/utils.h> /* mime64 */
 
+#include "add-data.h"
 #include "file-tree.h"
 #include "hig.h"
 #include "options.h"
 ****
 ***/
 
-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<n; ++i )
+            if( !i || text[i-1].isSpace() )
+                text[i] = text[i].toUpper();
+        QMessageBox::warning( QApplication::activeWindow(),
+                              tr( "Error Adding Torrent" ),
+                              QString("<p><b>%1</b></p><p>%2</p>").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( );
     }
index 51c4a105659ca369b7f90a5749e0509f02c469c3..e7bd1214330912a40362f05486e959ebf1ffb77f 100644 (file)
@@ -13,6 +13,8 @@
 #ifndef OPTIONS_DIALOG_H
 #define OPTIONS_DIALOG_H
 
+#include <iostream>
+
 #include <QDialog>
 #include <QEvent>
 #include <QString>
 #include <QVector>
 #include <QMap>
 #include <QPushButton>
+#include <QString>
 #include <QStringList>
 #include <QCryptographicHash>
 #include <QFile>
 #include <QTimer>
 
-#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;
index 1574e83e181be0794029ece8ac1f9352c1d628df..03026e830d29eb8d1f498745d1b704517d6b8711 100644 (file)
@@ -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
 
index 9aac79bb9a6e192d9e319480024d9bbefcc672c5..a4525310b904f53786cc0bb87b18d216d5424fc4 100644 (file)
@@ -33,6 +33,7 @@
 #include <libtransmission/utils.h> /* tr_free */
 #include <libtransmission/version.h> /* 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 );
 }
index 532f1105232350abd295db12e5f214d560c6ae6e..153b4957f8d0e086d66f44b2bad9d10653866698 100644 (file)
@@ -23,6 +23,8 @@
 
 class QStringList;
 
+class AddData;
+
 #include <libtransmission/transmission.h>
 
 extern "C"
@@ -112,8 +114,8 @@ class Session: public QObject
         void refreshActiveTorrents( );
         void refreshAllTorrents( );
         void initTorrents( const QSet<int>& ids = QSet<int>() );
-        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<int>& torrentIds, bool deleteFiles=false );
         void verifyTorrents( const QSet<int>& torrentIds );
         void reannounceTorrents( const QSet<int>& torrentIds );