mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 10:28:32 +00:00
(trunk) #3450 "regression: Qt client dbus support broken" -- fixed
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
<method name="AddMetainfo">
|
<method name="AddMetainfo">
|
||||||
<arg type="b" name="handled" direction="out"/>
|
<arg type="b" name="handled" direction="out"/>
|
||||||
<arg type="s" name="metainfo" direction="in"/>
|
<arg type="s" name="metainfo" direction="in"/>
|
||||||
<arg type="s" name="filename" direction="in"/>
|
|
||||||
</method>
|
</method>
|
||||||
<method name="PresentWindow">
|
<method name="PresentWindow">
|
||||||
<arg type="b" name="handled" direction="out"/>
|
<arg type="b" name="handled" direction="out"/>
|
||||||
|
|||||||
@@ -1026,7 +1026,6 @@ tr_core_add_ctor( TrCore * core, tr_ctor * ctor )
|
|||||||
gboolean
|
gboolean
|
||||||
tr_core_add_metainfo( TrCore * core,
|
tr_core_add_metainfo( TrCore * core,
|
||||||
const char * payload,
|
const char * payload,
|
||||||
const char * filename,
|
|
||||||
gboolean * setme_handled,
|
gboolean * setme_handled,
|
||||||
GError ** gerr UNUSED )
|
GError ** gerr UNUSED )
|
||||||
{
|
{
|
||||||
@@ -1041,38 +1040,23 @@ tr_core_add_metainfo( TrCore * core,
|
|||||||
tr_core_add_from_url( core, payload );
|
tr_core_add_from_url( core, payload );
|
||||||
*setme_handled = TRUE;
|
*setme_handled = TRUE;
|
||||||
}
|
}
|
||||||
else
|
else /* base64-encoded metainfo */
|
||||||
{
|
{
|
||||||
|
int file_length;
|
||||||
tr_ctor * ctor;
|
tr_ctor * ctor;
|
||||||
gboolean has_metainfo = FALSE;
|
char * file_contents;
|
||||||
const gboolean do_prompt = pref_flag_get( PREF_KEY_OPTIONS_PROMPT );
|
gboolean do_prompt = pref_flag_get( PREF_KEY_OPTIONS_PROMPT );
|
||||||
|
|
||||||
/* create the constructor */
|
|
||||||
ctor = tr_ctorNew( session );
|
ctor = tr_ctorNew( session );
|
||||||
tr_core_apply_defaults( ctor );
|
tr_core_apply_defaults( ctor );
|
||||||
|
|
||||||
if( !has_metainfo && g_file_test( filename, G_FILE_TEST_IS_REGULAR ) )
|
file_contents = tr_base64_decode( payload, -1, &file_length );
|
||||||
{
|
tr_ctorSetMetainfo( ctor, (const uint8_t*)file_contents, file_length );
|
||||||
/* 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 );
|
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;
|
return TRUE;
|
||||||
|
|||||||
@@ -117,8 +117,7 @@ void tr_core_add_list( TrCore * self,
|
|||||||
|
|
||||||
/** @brief Add a torrent. */
|
/** @brief Add a torrent. */
|
||||||
gboolean tr_core_add_metainfo( TrCore * core,
|
gboolean tr_core_add_metainfo( TrCore * core,
|
||||||
const char * payload,
|
const char * base64_metainfo,
|
||||||
const char * optional_filename,
|
|
||||||
gboolean * setme_success,
|
gboolean * setme_success,
|
||||||
GError ** err );
|
GError ** err );
|
||||||
|
|
||||||
|
|||||||
@@ -586,7 +586,6 @@ gtr_dbus_add_torrent( const char * filename )
|
|||||||
if( proxy )
|
if( proxy )
|
||||||
dbus_g_proxy_call( proxy, "AddMetainfo", &err,
|
dbus_g_proxy_call( proxy, "AddMetainfo", &err,
|
||||||
G_TYPE_STRING, payload,
|
G_TYPE_STRING, payload,
|
||||||
G_TYPE_STRING, filename,
|
|
||||||
G_TYPE_INVALID,
|
G_TYPE_INVALID,
|
||||||
G_TYPE_BOOLEAN, &handled,
|
G_TYPE_BOOLEAN, &handled,
|
||||||
G_TYPE_INVALID );
|
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/utils.h>
|
||||||
#include <libtransmission/version.h>
|
#include <libtransmission/version.h>
|
||||||
|
|
||||||
|
#include "add-data.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "dbus-adaptor.h"
|
#include "dbus-adaptor.h"
|
||||||
#include "formatter.h"
|
#include "formatter.h"
|
||||||
@@ -238,12 +239,10 @@ MyApp :: MyApp( int& argc, char ** argv ):
|
|||||||
// register as the dbus handler for Transmission
|
// register as the dbus handler for Transmission
|
||||||
new TrDBusAdaptor( this );
|
new TrDBusAdaptor( this );
|
||||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||||
if (!bus.registerService("com.transmissionbt.Transmission"))
|
if( !bus.registerService( DBUS_SERVICE ) )
|
||||||
if(bus.lastError().isValid())
|
std::cerr << "couldn't register " << DBUS_SERVICE << std::endl;
|
||||||
std::cerr << qPrintable(bus.lastError().message()) << std::endl;
|
if( !bus.registerObject( DBUS_OBJECT_PATH, this ) )
|
||||||
if( !bus.registerObject( "/com/transmissionbt/Transmission", this ))
|
std::cerr << "couldn't register " << DBUS_OBJECT_PATH << std::endl;
|
||||||
if(bus.lastError().isValid())
|
|
||||||
std::cerr << qPrintable(bus.lastError().message()) << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -366,20 +365,29 @@ MyApp :: refreshTorrents( )
|
|||||||
|
|
||||||
void
|
void
|
||||||
MyApp :: addTorrent( const QString& key )
|
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 ) )
|
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( );
|
o->show( );
|
||||||
}
|
}
|
||||||
else if( Utils::isURL( key ) )
|
|
||||||
{
|
|
||||||
myWindow->openURL( key );
|
|
||||||
}
|
|
||||||
|
|
||||||
raise( );
|
raise( );
|
||||||
}
|
}
|
||||||
@@ -440,17 +448,17 @@ main( int argc, char * argv[] )
|
|||||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||||
for( int i=0, n=addme.size(); i<n; ++i )
|
for( int i=0, n=addme.size(); i<n; ++i )
|
||||||
{
|
{
|
||||||
const QString key = addme[i];
|
|
||||||
|
|
||||||
QDBusMessage request = QDBusMessage::createMethodCall( DBUS_SERVICE,
|
QDBusMessage request = QDBusMessage::createMethodCall( DBUS_SERVICE,
|
||||||
DBUS_OBJECT_PATH,
|
DBUS_OBJECT_PATH,
|
||||||
DBUS_INTERFACE,
|
DBUS_INTERFACE,
|
||||||
"AddMetainfo" );
|
"AddMetainfo" );
|
||||||
QList<QVariant> arguments;
|
QList<QVariant> arguments;
|
||||||
arguments.push_back( QVariant( key ) );
|
arguments.push_back( AddData(addme[i]).toBase64().constData() );
|
||||||
request.setArguments( arguments );
|
request.setArguments( arguments );
|
||||||
|
|
||||||
QDBusMessage response = bus.call( request );
|
QDBusMessage response = bus.call( request );
|
||||||
|
//std::cerr << qPrintable(response.errorName()) << std::endl;
|
||||||
|
//std::cerr << qPrintable(response.errorMessage()) << std::endl;
|
||||||
arguments = response.arguments( );
|
arguments = response.arguments( );
|
||||||
delegated |= (arguments.size()==1) && arguments[0].toBool();
|
delegated |= (arguments.size()==1) && arguments[0].toBool();
|
||||||
}
|
}
|
||||||
|
|||||||
3
qt/app.h
3
qt/app.h
@@ -16,8 +16,10 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include "favicon.h"
|
#include "favicon.h"
|
||||||
|
|
||||||
|
class AddData;
|
||||||
class Prefs;
|
class Prefs;
|
||||||
class Session;
|
class Session;
|
||||||
class TorrentModel;
|
class TorrentModel;
|
||||||
@@ -60,6 +62,7 @@ class MyApp: public QApplication
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void addTorrent( const QString& );
|
void addTorrent( const QString& );
|
||||||
|
void addTorrent( const AddData& );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void maybeUpdateBlocklist( );
|
void maybeUpdateBlocklist( );
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
* $Id:$
|
* $Id:$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QFile>
|
#include "add-data.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "dbus-adaptor.h"
|
#include "dbus-adaptor.h"
|
||||||
|
|
||||||
@@ -28,8 +28,12 @@ TrDBusAdaptor :: PresentWindow( )
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class TrDBusAdaptor: public QDBusAbstractAdaptor
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool PresentWindow();
|
bool PresentWindow();
|
||||||
bool AddMetainfo( const QString& payload, const QString& filename );
|
bool AddMetainfo( const QString& );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ MakeDialog :: onNewButtonBoxClicked( QAbstractButton * button )
|
|||||||
{
|
{
|
||||||
case QDialogButtonBox::Open:
|
case QDialogButtonBox::Open:
|
||||||
std::cerr << "calling mySession.addTorrent( " << qPrintable(myTarget) << ", " << qPrintable(QFileInfo(myBuilder->top).dir().path()) << ')' << std::endl;
|
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;
|
break;
|
||||||
case QDialogButtonBox::Abort:
|
case QDialogButtonBox::Abort:
|
||||||
myBuilder->abortFlag = true;
|
myBuilder->abortFlag = true;
|
||||||
|
|||||||
102
qt/options.cc
102
qt/options.cc
@@ -13,6 +13,7 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
@@ -32,6 +34,7 @@
|
|||||||
#include <libtransmission/bencode.h>
|
#include <libtransmission/bencode.h>
|
||||||
#include <libtransmission/utils.h> /* mime64 */
|
#include <libtransmission/utils.h> /* mime64 */
|
||||||
|
|
||||||
|
#include "add-data.h"
|
||||||
#include "file-tree.h"
|
#include "file-tree.h"
|
||||||
#include "hig.h"
|
#include "hig.h"
|
||||||
#include "options.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 ),
|
QDialog( parent, Qt::Dialog ),
|
||||||
mySession( session ),
|
mySession( session ),
|
||||||
myFile( filename ),
|
myAdd( addme ),
|
||||||
myHaveInfo( false ),
|
myHaveInfo( false ),
|
||||||
myDestinationButton( 0 ),
|
myDestinationButton( 0 ),
|
||||||
myVerifyButton( 0 ),
|
myVerifyButton( 0 ),
|
||||||
@@ -168,7 +200,17 @@ Options :: refreshButton( QPushButton * p, const QString& text, int width )
|
|||||||
void
|
void
|
||||||
Options :: refreshFileButton( int width )
|
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
|
void
|
||||||
@@ -215,10 +257,13 @@ Options :: reload( )
|
|||||||
clearVerify( );
|
clearVerify( );
|
||||||
|
|
||||||
tr_ctor * ctor = tr_ctorNew( 0 );
|
tr_ctor * ctor = tr_ctorNew( 0 );
|
||||||
if( Utils::isMagnetLink( myFile ) )
|
|
||||||
tr_ctorSetMetainfoFromMagnetLink( ctor, myFile.toUtf8().constData() );
|
switch( myAdd.type ) {
|
||||||
else
|
case AddData::MAGNET: tr_ctorSetMetainfoFromMagnetLink( ctor, myAdd.magnet.toUtf8().constData() ); break;
|
||||||
tr_ctorSetMetainfoFromFile( ctor, myFile.toUtf8().constData() );
|
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 );
|
const int err = tr_torrentParse( ctor, &myInfo );
|
||||||
myHaveInfo = !err;
|
myHaveInfo = !err;
|
||||||
@@ -280,17 +325,25 @@ Options :: onAccepted( )
|
|||||||
tr_bencDictAddStr( args, "download-dir", myDestination.absolutePath().toUtf8().constData() );
|
tr_bencDictAddStr( args, "download-dir", myDestination.absolutePath().toUtf8().constData() );
|
||||||
|
|
||||||
// "metainfo"
|
// "metainfo"
|
||||||
if( Utils::isMagnetLink( myFile ) || Utils::isURL( myFile ) )
|
switch( myAdd.type )
|
||||||
tr_bencDictAddStr( args, "filename", myFile.toUtf8().constData() );
|
{
|
||||||
else {
|
case AddData::MAGNET:
|
||||||
QFile file( myFile );
|
tr_bencDictAddStr( args, "filename", myAdd.magnet.toUtf8().constData() );
|
||||||
file.open( QIODevice::ReadOnly );
|
break;
|
||||||
const QByteArray metainfo( file.readAll( ) );
|
|
||||||
file.close( );
|
case AddData::URL:
|
||||||
int base64Size = 0;
|
tr_bencDictAddStr( args, "filename", myAdd.url.toString().toUtf8().constData() );
|
||||||
char * base64 = tr_base64_encode( metainfo.constData(), metainfo.size(), &base64Size );
|
break;
|
||||||
tr_bencDictAddRaw( args, "metainfo", base64, base64Size );
|
|
||||||
tr_free( base64 );
|
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
|
// paused
|
||||||
@@ -329,11 +382,11 @@ Options :: onAccepted( )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// maybe delete the source .torrent
|
// maybe delete the source .torrent
|
||||||
if( myTrashCheck->isChecked( ) ) {
|
FileAdded * fileAdded = new FileAdded( tag, myAdd.readableName() );
|
||||||
FileAdded * fileAdded = new FileAdded( tag, myFile );
|
if( myTrashCheck->isChecked( ) && ( myAdd.type==AddData::FILENAME ) )
|
||||||
|
fileAdded->setFileToDelete( myAdd.filename );
|
||||||
connect( &mySession, SIGNAL(executed(int64_t,const QString&, struct tr_benc*)),
|
connect( &mySession, SIGNAL(executed(int64_t,const QString&, struct tr_benc*)),
|
||||||
fileAdded, SLOT(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;
|
//std::cerr << tr_bencToStr(&top,TR_FMT_JSON,NULL) << std::endl;
|
||||||
mySession.exec( &top );
|
mySession.exec( &top );
|
||||||
@@ -345,13 +398,16 @@ Options :: onAccepted( )
|
|||||||
void
|
void
|
||||||
Options :: onFilenameClicked( )
|
Options :: onFilenameClicked( )
|
||||||
{
|
{
|
||||||
|
if( myAdd.type == AddData::FILENAME )
|
||||||
|
{
|
||||||
QFileDialog * d = new QFileDialog( this,
|
QFileDialog * d = new QFileDialog( this,
|
||||||
tr( "Add Torrent" ),
|
tr( "Add Torrent" ),
|
||||||
QFileInfo(myFile).absolutePath(),
|
QFileInfo(myAdd.filename).absolutePath(),
|
||||||
tr( "Torrent Files (*.torrent);;All Files (*.*)" ) );
|
tr( "Torrent Files (*.torrent);;All Files (*.*)" ) );
|
||||||
d->setFileMode( QFileDialog::ExistingFile );
|
d->setFileMode( QFileDialog::ExistingFile );
|
||||||
connect( d, SIGNAL(filesSelected(const QStringList&)), this, SLOT(onFilesSelected(const QStringList&)) );
|
connect( d, SIGNAL(filesSelected(const QStringList&)), this, SLOT(onFilesSelected(const QStringList&)) );
|
||||||
d->show( );
|
d->show( );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -359,7 +415,7 @@ Options :: onFilesSelected( const QStringList& files )
|
|||||||
{
|
{
|
||||||
if( files.size() == 1 )
|
if( files.size() == 1 )
|
||||||
{
|
{
|
||||||
myFile = files.at( 0 );
|
myAdd.set( files.at(0) );
|
||||||
refreshFileButton( );
|
refreshFileButton( );
|
||||||
reload( );
|
reload( );
|
||||||
}
|
}
|
||||||
|
|||||||
23
qt/options.h
23
qt/options.h
@@ -13,6 +13,8 @@
|
|||||||
#ifndef OPTIONS_DIALOG_H
|
#ifndef OPTIONS_DIALOG_H
|
||||||
#define OPTIONS_DIALOG_H
|
#define OPTIONS_DIALOG_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@@ -20,12 +22,14 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include "file-tree.h"
|
#include "add-data.h" // AddData
|
||||||
|
#include "file-tree.h" // FileList
|
||||||
|
|
||||||
class FileTreeView;
|
class FileTreeView;
|
||||||
class Prefs;
|
class Prefs;
|
||||||
@@ -39,21 +43,16 @@ class FileAdded: public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
const int64_t myTag;
|
const int64_t myTag;
|
||||||
|
QString myName;
|
||||||
QString myDelFile;
|
QString myDelFile;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileAdded( int tag, const QString file ): myTag(tag), myDelFile(file) { }
|
FileAdded( int tag, const QString& name ): myTag(tag), myName(name) { }
|
||||||
~FileAdded( ) { }
|
~FileAdded( ) { }
|
||||||
|
void setFileToDelete( const QString& file ) { myDelFile = file; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void executed( int64_t tag, const QString& result, struct tr_benc * arguments ) {
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Options: public QDialog
|
class Options: public QDialog
|
||||||
@@ -61,7 +60,7 @@ class Options: public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
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( );
|
~Options( );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -73,7 +72,7 @@ class Options: public QDialog
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Session& mySession;
|
Session& mySession;
|
||||||
QString myFile;
|
AddData myAdd;
|
||||||
QDir myDestination;
|
QDir myDestination;
|
||||||
bool myHaveInfo;
|
bool myHaveInfo;
|
||||||
tr_info myInfo;
|
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
|
FORMS += mainwin.ui
|
||||||
RESOURCES += application.qrc
|
RESOURCES += application.qrc
|
||||||
SOURCES += about.cc app.cc dbus-adaptor.cc details.cc favicon.cc file-tree.cc \
|
SOURCES += about.cc \
|
||||||
filterbar.cc filters.cc formatter.cc hig.cc license.cc mainwin.cc \
|
add-data.cc \
|
||||||
make-dialog.cc options.cc prefs.cc prefs-dialog.cc qticonloader.cc \
|
app.cc \
|
||||||
relocate.cc session.cc session-dialog.cc squeezelabel.cc \
|
dbus-adaptor.cc \
|
||||||
stats-dialog.cc torrent.cc torrent-delegate.cc \
|
details.cc \
|
||||||
torrent-delegate-min.cc torrent-filter.cc torrent-model.cc \
|
favicon.cc \
|
||||||
tracker-delegate.cc tracker-model.cc tracker-model-filter.cc \
|
file-tree.cc \
|
||||||
triconpushbutton.cc utils.cc watchdir.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 += $$replace(SOURCES, .cc, .h)
|
||||||
HEADERS += speed.h types.h
|
HEADERS += speed.h types.h
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include <libtransmission/utils.h> /* tr_free */
|
#include <libtransmission/utils.h> /* tr_free */
|
||||||
#include <libtransmission/version.h> /* LONG_VERSION */
|
#include <libtransmission/version.h> /* LONG_VERSION */
|
||||||
|
|
||||||
|
#include "add-data.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "qticonloader.h"
|
#include "qticonloader.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
@@ -925,54 +926,38 @@ Session :: setBlocklistSize( int64_t i )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Session :: addTorrent( QString filename )
|
Session :: addTorrent( const AddData& addMe )
|
||||||
{
|
{
|
||||||
addTorrent( filename, myPrefs.getString( Prefs::DOWNLOAD_DIR ) );
|
const QByteArray b64 = addMe.toBase64();
|
||||||
}
|
|
||||||
|
|
||||||
namespace
|
tr_benc top, *args;
|
||||||
{
|
tr_bencInitDict( &top, 2 );
|
||||||
bool isLink( const QString& str )
|
tr_bencDictAddStr( &top, "method", "torrent-add" );
|
||||||
{
|
args = tr_bencDictAddDict( &top, "arguments", 2 );
|
||||||
return Utils::isMagnetLink(str) || Utils::isURL(str);
|
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
|
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_benc top, *args;
|
||||||
tr_bencInitDict( &top, 2 );
|
tr_bencInitDict( &top, 2 );
|
||||||
tr_bencDictAddStr( &top, "method", "torrent-add" );
|
tr_bencDictAddStr( &top, "method", "torrent-add" );
|
||||||
args = tr_bencDictAddDict( &top, "arguments", 3 );
|
args = tr_bencDictAddDict( &top, "arguments", 3 );
|
||||||
tr_bencDictAddStr( args, "download-dir", qPrintable(localPath) );
|
tr_bencDictAddStr( args, "download-dir", qPrintable(localPath) );
|
||||||
tr_bencDictAddBool( args, "paused", !myPrefs.getBool( Prefs::START ) );
|
tr_bencDictAddBool( args, "paused", !myPrefs.getBool( Prefs::START ) );
|
||||||
|
tr_bencDictAddRaw( args, "metainfo", b64.constData(), b64.size() );
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
exec( &top );
|
exec( &top );
|
||||||
tr_bencFree( &top );
|
tr_bencFree( &top );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
class QStringList;
|
class QStringList;
|
||||||
|
|
||||||
|
class AddData;
|
||||||
|
|
||||||
#include <libtransmission/transmission.h>
|
#include <libtransmission/transmission.h>
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
@@ -112,8 +114,8 @@ class Session: public QObject
|
|||||||
void refreshActiveTorrents( );
|
void refreshActiveTorrents( );
|
||||||
void refreshAllTorrents( );
|
void refreshAllTorrents( );
|
||||||
void initTorrents( const QSet<int>& ids = QSet<int>() );
|
void initTorrents( const QSet<int>& ids = QSet<int>() );
|
||||||
void addTorrent( QString filename );
|
void addNewlyCreatedTorrent( const QString& filename, const QString& localPath );
|
||||||
void addTorrent( QString filename, QString localPath );
|
void addTorrent( const AddData& addme );
|
||||||
void removeTorrents( const QSet<int>& torrentIds, bool deleteFiles=false );
|
void removeTorrents( const QSet<int>& torrentIds, bool deleteFiles=false );
|
||||||
void verifyTorrents( const QSet<int>& torrentIds );
|
void verifyTorrents( const QSet<int>& torrentIds );
|
||||||
void reannounceTorrents( const QSet<int>& torrentIds );
|
void reannounceTorrents( const QSet<int>& torrentIds );
|
||||||
|
|||||||
Reference in New Issue
Block a user