(trunk qt) #2072: Delete .torrent with or without error

This commit is contained in:
Charles Kerr 2009-05-15 02:05:07 +00:00
parent e4ffc54b6f
commit 3827d80cd8
4 changed files with 53 additions and 12 deletions

View File

@ -251,10 +251,11 @@ Options :: onAccepted( )
{
// rpc spec section 3.4 "adding a torrent"
const int64_t tag = mySession.getUniqueTag( );
tr_benc top;
tr_bencInitDict( &top, 3 );
tr_bencDictAddStr( &top, "method", "torrent-add" );
tr_bencDictAddInt( &top, "tag", Session::ADD_TORRENT_TAG );
tr_bencDictAddInt( &top, "tag", tag );
tr_benc * args( tr_bencDictAddDict( &top, "arguments", 10 ) );
// "download-dir"
@ -301,14 +302,17 @@ Options :: onAccepted( )
tr_bencListAddInt( l, i );
}
// 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*)));
}
mySession.exec( &top );
tr_bencFree( &top );
deleteLater( );
// maybe the source .torrent
if( myTrashCheck->isChecked( ) )
QFile(myFile).remove( );
}
void

View File

@ -32,6 +32,29 @@ class Prefs;
class QCheckBox;
class Session;
extern "C" { struct tr_benc; };
class FileAdded: public QObject
{
Q_OBJECT
const int64_t myTag;
QString myDelFile;
public:
FileAdded( int tag, const QString file ): myTag(tag), myDelFile(file) { }
~FileAdded( ) { }
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();
}
}
};
class Options: public QDialog
{
Q_OBJECT

View File

@ -47,7 +47,9 @@ namespace
TAG_SESSION_INFO,
TAG_BLOCKLIST_UPDATE,
TAG_ADD_TORRENT,
TAG_PORT_TEST
TAG_PORT_TEST,
FIRST_UNIQUE_TAG
};
}
@ -178,6 +180,7 @@ Session :: updatePref( int key )
***/
Session :: Session( const char * configDir, Prefs& prefs ):
nextUniqueTag( FIRST_UNIQUE_TAG ),
myBlocklistSize( -1 ),
myPrefs( prefs ),
mySession( 0 ),
@ -322,8 +325,6 @@ namespace
}
}
const int Session :: ADD_TORRENT_TAG = TAG_ADD_TORRENT;
void
Session :: torrentSet( const QSet<int>& ids, const QString& key, double value )
{
@ -624,9 +625,19 @@ Session :: parseResponse( const char * json, size_t jsonLength )
const int err( tr_jsonParse( json, jsonLength, &top, &end ) );
if( !err )
{
int64_t tag;
int64_t tag = -1;
const char * result = NULL;
tr_benc * args = NULL;
tr_bencDictFindInt ( &top, "tag", &tag );
tr_bencDictFindStr ( &top, "result", &result );
tr_bencDictFindDict( &top, "arguments", &args );
emit executed( tag, result, args );
tr_benc * torrents;
const char * str;
tr_benc *args, *torrents;
if( tr_bencDictFindInt( &top, "tag", &tag ) )
{
switch( tag )

View File

@ -40,8 +40,6 @@ class Session: public QObject
Session( const char * configDir, Prefs& prefs );
~Session( );
static const int ADD_TORRENT_TAG;
public:
void stop( );
void restart( );
@ -79,6 +77,9 @@ class Session: public QObject
void exec( const char * request );
void exec( const struct tr_benc * request );
public:
int64_t getUniqueTag( ) { return nextUniqueTag++; }
private:
void sessionSet( const char * key, const QVariant& variant );
void pumpRequests( );
@ -117,6 +118,7 @@ class Session: public QObject
void onRequestFinished( int id, bool error );
signals:
void executed( int64_t tag, const QString& result, struct tr_benc * arguments );
void sourceChanged( );
void portTested( bool isOpen );
void statsUpdated( );
@ -129,6 +131,7 @@ class Session: public QObject
void httpAuthenticationRequired( );
private:
int64_t nextUniqueTag;
int64_t myBlocklistSize;
Prefs& myPrefs;
tr_session * mySession;