mirror of
https://github.com/transmission/transmission
synced 2024-12-31 20:16:57 +00:00
(trunk) #3450 "regression: Qt client dbus support broken" -- fixed
This commit is contained in:
parent
ff23406f38
commit
3fa4865863
16 changed files with 348 additions and 139 deletions
|
@ -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"/>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
101
qt/add-data.cc
Normal file
101
qt/add-data.cc
Normal file
|
@ -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;
|
||||
}
|
45
qt/add-data.h
Normal file
45
qt/add-data.h
Normal file
|
@ -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
|
40
qt/app.cc
40
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,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<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();
|
||||
}
|
||||
|
|
3
qt/app.h
3
qt/app.h
|
@ -16,8 +16,10 @@
|
|||
#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( );
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
118
qt/options.cc
118
qt/options.cc
|
@ -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"
|
||||
|
@ -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<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( );
|
||||
}
|
||||
|
|
23
qt/options.h
23
qt/options.h
|
@ -13,6 +13,8 @@
|
|||
#ifndef OPTIONS_DIALOG_H
|
||||
#define OPTIONS_DIALOG_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QDialog>
|
||||
#include <QEvent>
|
||||
#include <QString>
|
||||
|
@ -20,12 +22,14 @@
|
|||
#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;
|
||||
|
|
41
qt/qtr.pro
41
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
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue