@ -17,6 +17,59 @@
@@ -17,6 +17,59 @@
* /
package org.transdroid.daemon.Deluge ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DETAILS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DOWNLOADEDEVER ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_ETA ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FIELDS_ARRAY ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILEPRIORITIES ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILEPROGRESS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILE_FIELDS_ARRAY ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_HASH ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_INDEX ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_LABEL ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MAXDOWNLOAD ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MAXUPLOAD ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MESSAGE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD_FILE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD_MAGNET ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_FORCERECHECK ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_GET_LABELS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_GET_METHOD_LIST ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_GET_TORRENTS_STATUS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_INFO ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_MOVESTORAGE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_PAUSE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_PAUSE_ALL ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_REMOVE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_RESUME ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_RESUME_ALL ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SETCONFIG ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SETLABEL ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SETTRACKERS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SET_TORRENT_OPTIONS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_STATUS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_NAME ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_NUMPEERS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_NUMSEEDS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_PARTDONE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_PATH ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_RATEDOWNLOAD ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_RATEUPLOAD ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SAVEPATH ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SIZE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS_FIELDS_ARRAY ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TIMEADDED ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALPEERS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSEEDS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSIZE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKERS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_STATUS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_TIER ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_URL ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_UPLOADEDEVER ;
import android.support.annotation.NonNull ;
import java.io.BufferedInputStream ;
import java.io.ByteArrayOutputStream ;
@ -68,58 +121,6 @@ import org.transdroid.daemon.task.SetLabelTask;
@@ -68,58 +121,6 @@ import org.transdroid.daemon.task.SetLabelTask;
import org.transdroid.daemon.task.SetTrackersTask ;
import org.transdroid.daemon.task.SetTransferRatesTask ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DOWNLOADEDEVER ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_ETA ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DETAILS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILEPRIORITIES ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILEPROGRESS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_HASH ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_INDEX ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_LABEL ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MAXDOWNLOAD ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MAXUPLOAD ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MESSAGE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD_FILE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD_MAGNET ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_FORCERECHECK ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_GET_LABELS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_GET_TORRENTS_STATUS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_INFO ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_MOVESTORAGE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_PAUSE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_PAUSE_ALL ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_REMOVE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_RESUME ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_RESUME_ALL ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SETCONFIG ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SETLABEL ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SETTRACKERS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SET_TORRENT_OPTIONS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_STATUS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_NAME ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_NUMPEERS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_NUMSEEDS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_PARTDONE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_PATH ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_RATEDOWNLOAD ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_RATEUPLOAD ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SAVEPATH ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SIZE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TIMEADDED ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALPEERS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSEEDS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSIZE ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKERS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_STATUS ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_TIER ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_URL ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_UPLOADEDEVER ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FIELDS_ARRAY ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILE_FIELDS_ARRAY ;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS_FIELDS_ARRAY ;
/ * *
* The daemon adapter from the Deluge torrent client using deluged API directly .
*
@ -130,53 +131,53 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -130,53 +131,53 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
public static final int DEFAULT_PORT = 58846 ;
private final DaemonSettings settings ;
private final DelugeRpcClient client ;
private int version = - 1 ;
public DelugeRpcAdapter ( DaemonSettings settings ) {
this . settings = settings ;
client = new DelugeRpcClient ( settings ) ;
}
@Override
public DaemonTaskResult executeTask ( Log log , DaemonTask task ) {
final DelugeRpcClient client = new DelugeRpcClient ( ) ;
try {
client . connect ( settings . getAddress ( ) , settings . getPort ( ) , settings . getUsername ( ) , settings . getPassword ( ) ) ;
switch ( task . getMethod ( ) ) {
case Retrieve :
return doRetrieve ( ( RetrieveTask ) task ) ;
return doRetrieve ( client , ( RetrieveTask ) task ) ;
case AddByUrl :
return doAddByUrl ( ( AddByUrlTask ) task ) ;
return doAddByUrl ( client , ( AddByUrlTask ) task ) ;
case AddByMagnetUrl :
return doAddByMagnetUrl ( ( AddByMagnetUrlTask ) task ) ;
return doAddByMagnetUrl ( client , ( AddByMagnetUrlTask ) task ) ;
case AddByFile :
return doAddByFile ( ( AddByFileTask ) task ) ;
return doAddByFile ( client , ( AddByFileTask ) task ) ;
case Remove :
return doRemove ( ( RemoveTask ) task ) ;
return doRemove ( client , ( RemoveTask ) task ) ;
case Pause :
return doControl ( task , RPC_METHOD_PAUSE ) ;
return doControl ( client , task , RPC_METHOD_PAUSE ) ;
case PauseAll :
return doControlAll ( task , RPC_METHOD_PAUSE_ALL ) ;
return doControlAll ( client , task , RPC_METHOD_PAUSE_ALL ) ;
case Resume :
return doControl ( task , RPC_METHOD_RESUME ) ;
return doControl ( client , task , RPC_METHOD_RESUME ) ;
case ResumeAll :
return doControlAll ( task , RPC_METHOD_RESUME_ALL ) ;
return doControlAll ( client , task , RPC_METHOD_RESUME_ALL ) ;
case GetFileList :
return doGetFileList ( ( GetFileListTask ) task ) ;
return doGetFileList ( client , ( GetFileListTask ) task ) ;
case SetFilePriorities :
return doSetFilePriorities ( ( SetFilePriorityTask ) task ) ;
return doSetFilePriorities ( client , ( SetFilePriorityTask ) task ) ;
case SetTransferRates :
return doSetTransferRates ( ( SetTransferRatesTask ) task ) ;
return doSetTransferRates ( client , ( SetTransferRatesTask ) task ) ;
case SetLabel :
return doSetLabel ( ( SetLabelTask ) task ) ;
return doSetLabel ( client , ( SetLabelTask ) task ) ;
case SetDownloadLocation :
return doSetDownloadLocation ( ( SetDownloadLocationTask ) task ) ;
return doSetDownloadLocation ( client , ( SetDownloadLocationTask ) task ) ;
case GetTorrentDetails :
return doGetTorrentDetails ( ( GetTorrentDetailsTask ) task ) ;
return doGetTorrentDetails ( client , ( GetTorrentDetailsTask ) task ) ;
case SetTrackers :
return doSetTrackers ( ( SetTrackersTask ) task ) ;
return doSetTrackers ( client , ( SetTrackersTask ) task ) ;
case ForceRecheck :
return doForceRecheck ( ( ForceRecheckTask ) task ) ;
return doForceRecheck ( client , ( ForceRecheckTask ) task ) ;
default :
return new DaemonTaskFailureResult ( task ,
new DaemonException ( ExceptionType . MethodUnsupported ,
@ -184,6 +185,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -184,6 +185,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
}
} catch ( DaemonException e ) {
return new DaemonTaskFailureResult ( task , e ) ;
} finally {
client . close ( ) ;
}
}
@ -198,24 +201,32 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -198,24 +201,32 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
}
@NonNull
private RetrieveTaskSuccessResult doRetrieve ( RetrieveTask task ) throws DaemonException {
final List < Object > results = client . sendRequests (
new Request ( RPC_METHOD_INFO ) ,
new Request ( RPC_METHOD_GET_TORRENTS_STATUS , new HashMap < > ( ) , RPC_FIELDS_ARRAY ) ,
new Request ( RPC_METHOD_GET_LABELS ) ) ;
version = DelugeCommon . getVersionString ( ( String ) results . get ( 0 ) ) ;
private RetrieveTaskSuccessResult doRetrieve ( DelugeRpcClient client , RetrieveTask task ) throws DaemonException {
// Get torrents
//noinspection unchecked
final Map < String , Map < String , Object > > torrentsStatus = ( Map < String , Map < String , Object > > ) results
. get ( 1 ) ;
final Map < String , Map < String , Object > > torrentsStatus = ( Map < String , Map < String , Object > > ) client
. sendRequest ( RPC_METHOD_GET_TORRENTS_STATUS , new HashMap < > ( ) , RPC_FIELDS_ARRAY ) ;
final List < Torrent > torrents = getTorrents ( torrentsStatus . values ( ) ) ;
// Check if Label plugin is enabled
//noinspection unchecked
final List < String > methods = ( List < String > ) client . sendRequest ( RPC_METHOD_GET_METHOD_LIST ) ;
final boolean hasLabelPlugin = methods . contains ( RPC_METHOD_GET_LABELS ) ;
// Get label list from server
//noinspection unchecked
final List < Label > labels = getLabels ( ( List < String > ) results . get ( 2 ) , torrents ) ;
final List < String > labelNames = hasLabelPlugin
? ( List < String > ) client . sendRequest ( RPC_METHOD_GET_LABELS )
: new ArrayList < String > ( ) ;
// Extract labels & counts from torrents.
final List < Label > labels = getLabels ( labelNames , torrents ) ;
return new RetrieveTaskSuccessResult ( task , torrents , labels ) ;
}
private GetTorrentDetailsTaskSuccessResult doGetTorrentDetails ( GetTorrentDetailsTask task )
private GetTorrentDetailsTaskSuccessResult doGetTorrentDetails ( DelugeRpcClient client ,
GetTorrentDetailsTask task )
throws DaemonException {
//noinspection unchecked
final Map < String , Object > response = ( Map < String , Object > ) client . sendRequest (
@ -236,30 +247,33 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -236,30 +247,33 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
Collections . singletonList ( ( String ) response . get ( RPC_TRACKER_STATUS ) ) ) ) ;
}
private GetFileListTaskSuccessResult doGetFileList ( GetFileListTask task ) throws DaemonException {
final ArrayList < TorrentFile > files = getTorrentFiles ( task . getTargetTorrent ( ) ) ;
private GetFileListTaskSuccessResult doGetFileList ( DelugeRpcClient client ,
GetFileListTask task ) throws DaemonException {
final ArrayList < TorrentFile > files = getTorrentFiles ( client , task . getTargetTorrent ( ) ) ;
return new GetFileListTaskSuccessResult ( task , files ) ;
}
private DaemonTaskResult doControl ( DaemonTask task , String method ) throws DaemonException {
private DaemonTaskResult doControl ( DelugeRpcClient client , DaemonTask task ,
String method ) throws DaemonException {
client . sendRequest ( method , ( Object ) getTorrentIdsArg ( task ) ) ;
return new DaemonTaskSuccessResult ( task ) ;
}
private DaemonTaskResult doRemove ( RemoveTask task ) throws DaemonException {
private DaemonTaskResult doRemove ( DelugeRpcClient client , RemoveTask task ) throws DaemonException {
client . sendRequest ( RPC_METHOD_REMOVE , task . getTargetTorrent ( ) . getUniqueID ( ) ,
task . includingData ( ) ) ;
return new DaemonTaskSuccessResult ( task ) ;
}
@NonNull
private DaemonTaskResult doControlAll ( DaemonTask task , String method ) throws DaemonException {
private DaemonTaskResult doControlAll ( DelugeRpcClient client , DaemonTask task ,
String method ) throws DaemonException {
client . sendRequest ( method ) ;
return new DaemonTaskSuccessResult ( task ) ;
}
@NonNull
private DaemonTaskResult doAddByFile ( AddByFileTask task ) throws DaemonException {
private DaemonTaskResult doAddByFile ( DelugeRpcClient client , AddByFileTask task ) throws DaemonException {
final String file = task . getFile ( ) ;
final String fileContent = Base64 . encodeBytes ( loadFile ( file ) ) ;
client . sendRequest ( RPC_METHOD_ADD_FILE , file , fileContent , new HashMap < > ( ) ) ;
@ -267,19 +281,20 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -267,19 +281,20 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
}
@NonNull
private DaemonTaskResult doAddByUrl ( AddByUrlTask task ) throws DaemonException {
private DaemonTaskResult doAddByUrl ( DelugeRpcClient client , AddByUrlTask task ) throws DaemonException {
client . sendRequest ( RPC_METHOD_ADD , task . getUrl ( ) , new HashMap < > ( ) ) ;
return new DaemonTaskSuccessResult ( task ) ;
}
@NonNull
private DaemonTaskResult doAddByMagnetUrl ( AddByMagnetUrlTask task ) throws DaemonException {
private DaemonTaskResult doAddByMagnetUrl ( DelugeRpcClient client ,
AddByMagnetUrlTask task ) throws DaemonException {
client . sendRequest ( RPC_METHOD_ADD_MAGNET , task . getUrl ( ) , new HashMap < > ( ) ) ;
return new DaemonTaskSuccessResult ( task ) ;
}
@NonNull
private DaemonTaskResult doSetLabel ( SetLabelTask task ) throws DaemonException {
private DaemonTaskResult doSetLabel ( DelugeRpcClient client , SetLabelTask task ) throws DaemonException {
final String torrentId = task . getTargetTorrent ( ) . getUniqueID ( ) ;
final String label = task . getNewLabel ( ) = = null ? "" : task . getNewLabel ( ) ;
client . sendRequest ( RPC_METHOD_SETLABEL , torrentId , label ) ;
@ -287,9 +302,10 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -287,9 +302,10 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
}
@NonNull
private DaemonTaskResult doSetFilePriorities ( SetFilePriorityTask task ) throws DaemonException {
private DaemonTaskResult doSetFilePriorities ( DelugeRpcClient client ,
SetFilePriorityTask task ) throws DaemonException {
// We first need a listing of all the files (because we can only set the priorities all at once)
final ArrayList < TorrentFile > files = getTorrentFiles ( task . getTargetTorrent ( ) ) ;
final ArrayList < TorrentFile > files = getTorrentFiles ( client , task . getTargetTorrent ( ) ) ;
// prepare options arg
final Map < String , Object > optionsArgs = new HashMap < > ( ) ;
@ -304,8 +320,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -304,8 +320,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
final ArrayList < Integer > priorities = new ArrayList < > ( ) ;
final Priority newPriority = task . getNewPriority ( ) ;
for ( TorrentFile file : files ) {
priorities . add (
convertPriority ( changedFiles . contains ( file . getKey ( ) ) ? newPriority : file . getPriority ( ) ) ) ;
final Priority priority = changedF il es . contains ( file . getKey ( ) ) ? newPriority : file . getPriority ( ) ;
priorities . add ( convertPriority ( client , priority ) ) ;
}
optionsArgs . put ( RPC_FILEPRIORITIES , priorities ) ;
@ -314,7 +330,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -314,7 +330,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
}
@NonNull
private DaemonTaskResult doSetTransferRates ( SetTransferRatesTask task ) throws DaemonException {
private DaemonTaskResult doSetTransferRates ( DelugeRpcClient client ,
SetTransferRatesTask task ) throws DaemonException {
final Map < String , Object > config = new HashMap < > ( ) ;
config . put ( RPC_MAXDOWNLOAD , task . getDownloadRate ( ) = = null ? - 1 : task . getDownloadRate ( ) ) ;
config . put ( RPC_MAXUPLOAD , task . getUploadRate ( ) = = null ? - 1 : task . getUploadRate ( ) ) ;
@ -323,7 +340,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -323,7 +340,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
}
@NonNull
private DaemonTaskResult doSetTrackers ( SetTrackersTask task ) throws DaemonException {
private DaemonTaskResult doSetTrackers ( DelugeRpcClient client , SetTrackersTask task ) throws DaemonException {
final List < Map < String , Object > > trackers = new ArrayList < > ( ) ;
final ArrayList < String > newTrackers = task . getNewTrackers ( ) ;
for ( int i = 0 , n = newTrackers . size ( ) ; i < n ; i + + ) {
@ -337,13 +354,14 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -337,13 +354,14 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
}
@NonNull
private DaemonTaskResult doForceRecheck ( ForceRecheckTask task ) throws DaemonException {
private DaemonTaskResult doForceRecheck ( DelugeRpcClient client , ForceRecheckTask task ) throws DaemonException {
client . sendRequest ( RPC_METHOD_FORCERECHECK , getTorrentIdsArg ( task ) ) ;
return new DaemonTaskSuccessResult ( task ) ;
}
@NonNull
private DaemonTaskResult doSetDownloadLocation ( SetDownloadLocationTask task ) throws DaemonException {
private DaemonTaskResult doSetDownloadLocation ( DelugeRpcClient client ,
SetDownloadLocationTask task ) throws DaemonException {
client . sendRequest ( RPC_METHOD_MOVESTORAGE , getTorrentIdsArg ( task ) , task . getNewLocation ( ) ) ;
return new DaemonTaskSuccessResult ( task ) ;
}
@ -428,7 +446,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -428,7 +446,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
}
@NonNull
private ArrayList < TorrentFile > getTorrentFiles ( Torrent torrent ) throws DaemonException {
private ArrayList < TorrentFile > getTorrentFiles ( DelugeRpcClient client , Torrent torrent ) throws DaemonException {
final ArrayList < TorrentFile > files = new ArrayList < > ( ) ;
//noinspection unchecked
final Map < String , Object > response = ( Map < String , Object > ) client . sendRequest (
@ -458,7 +476,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -458,7 +476,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
torrent . getLocationDir ( ) + path ,
size ,
( long ) ( size * progress ) ,
convertDelugePriority ( priority ) ) ) ;
convertDelugePriority ( client , priority ) ) ) ;
}
return files ;
}
@ -497,18 +515,18 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -497,18 +515,18 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
}
@NonNull
private Priority convertDelugePriority ( int priority )
private Priority convertDelugePriority ( DelugeRpcClient client , int priority )
throws DaemonException {
ensureVersion ( ) ;
ensureVersion ( client ) ;
return DelugeCommon . convertDelugePriority ( priority , version ) ;
}
private int convertPriority ( Priority priority ) throws DaemonException {
ensureVersion ( ) ;
private int convertPriority ( DelugeRpcClient client , Priority priority ) throws DaemonException {
ensureVersion ( client ) ;
return DelugeCommon . convertPriority ( priority , version ) ;
}
private void ensureVersion ( ) throws DaemonException {
private void ensureVersion ( DelugeRpcClient client ) throws DaemonException {
if ( version > 0 ) {
return ;
}
@ -520,4 +538,24 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@@ -520,4 +538,24 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
private Object getTorrentIdsArg ( DaemonTask task ) {
return new String [ ] { task . getTargetTorrent ( ) . getUniqueID ( ) } ;
}
/ * *
* Used to count torrents in labels .
* /
private static class MutableInt {
int value = 1 ;
MutableInt ( int value ) {
this . value = value ;
}
void increment ( ) {
+ + value ;
}
int get ( ) {
return value ;
}
}
}