Browse Source

Merge pull request #368 from Niluge-KiWi/rtorrent_fix_stop_pause

Fix stop/pause for rtorrent
pull/311/merge
Eric Kok 8 years ago committed by GitHub
parent
commit
06b041c2f2
  1. 40
      app/src/main/java/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java

40
app/src/main/java/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java

@ -135,7 +135,8 @@ public class RtorrentAdapter implements IDaemonAdapter {
"d.custom=seedingtime", "d.custom=seedingtime",
"d.custom1=", "d.custom1=",
"d.peers_complete=", "d.peers_complete=",
"d.peers_accounted=" }); "d.peers_accounted=",
"d.is_open=" });
// @formatter:on // @formatter:on
return new RetrieveTaskSuccessResult((RetrieveTask) task, onTorrentsRetrieved(result), return new RetrieveTaskSuccessResult((RetrieveTask) task, onTorrentsRetrieved(result),
lastKnownLabels); lastKnownLabels);
@ -226,49 +227,51 @@ public class RtorrentAdapter implements IDaemonAdapter {
case Pause: case Pause:
// Pause a torrent // Pause a torrent
makeRtorrentCall(log, "d.pause", new String[]{task.getTargetTorrent().getUniqueID()}); makeRtorrentCall(log, "d.stop", new String[]{task.getTargetTorrent().getUniqueID()});
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case PauseAll: case PauseAll:
// Resume all torrents // Resume all torrents
makeRtorrentCall(log, "d.multicall2", new String[]{"","main", "d.pause="}); makeRtorrentCall(log, "d.multicall2", new String[]{"","main", "d.stop="});
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case Resume: case Resume:
// Resume a torrent // Resume a torrent
makeRtorrentCall(log, "d.resume", new String[]{task.getTargetTorrent().getUniqueID()}); makeRtorrentCall(log, "d.start", new String[]{task.getTargetTorrent().getUniqueID()});
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case ResumeAll: case ResumeAll:
// Resume all torrents // Resume all torrents
makeRtorrentCall(log, "d.multicall2", new String[]{"", "main", "d.resume="}); makeRtorrentCall(log, "d.multicall2", new String[]{"", "main", "d.start="});
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case Stop: case Stop:
// Stop a torrent // Stop a torrent
makeRtorrentCall(log, "d.stop", new String[]{task.getTargetTorrent().getUniqueID()}); makeRtorrentCall(log, "d.stop", new String[]{task.getTargetTorrent().getUniqueID()});
makeRtorrentCall(log, "d.close", new String[]{task.getTargetTorrent().getUniqueID()});
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case StopAll: case StopAll:
// Stop all torrents // Stop all torrents
makeRtorrentCall(log, "d.multicall2", new String[]{"", "main", "d.stop="}); makeRtorrentCall(log, "d.multicall2", new String[]{"", "main", "d.stop=", "d.close="});
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case Start: case Start:
// Start a torrent // Start a torrent
makeRtorrentCall(log, "d.open", new String[]{task.getTargetTorrent().getUniqueID()});
makeRtorrentCall(log, "d.start", new String[]{task.getTargetTorrent().getUniqueID()}); makeRtorrentCall(log, "d.start", new String[]{task.getTargetTorrent().getUniqueID()});
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case StartAll: case StartAll:
// Start all torrents // Start all torrents
makeRtorrentCall(log, "d.multicall2", new String[]{"", "main", "d.start="}); makeRtorrentCall(log, "d.multicall2", new String[]{"", "main", "d.open=", "d.start="});
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case SetFilePriorities: case SetFilePriorities:
@ -454,7 +457,7 @@ public class RtorrentAdapter implements IDaemonAdapter {
i, i,
(String)info[0], // hash (String)info[0], // hash
(String)info[1], // name (String)info[1], // name
convertTorrentStatus((Long)info[2], (Long)info[13], (Long)info[14], (Long)info[15]), // status convertTorrentStatus((Long)info[2], (Long)info[24], (Long)info[13], (Long)info[14], (Long)info[15]), // status
basePath.substring(0, basePath.indexOf((String)info[17])), // locationDir basePath.substring(0, basePath.indexOf((String)info[17])), // locationDir
((Long)info[3]).intValue(), // rateDownload ((Long)info[3]).intValue(), // rateDownload
((Long)info[4]).intValue(), // rateUpload ((Long)info[4]).intValue(), // rateUpload
@ -486,7 +489,7 @@ public class RtorrentAdapter implements IDaemonAdapter {
i, i,
(String)info[0], // hash (String)info[0], // hash
(String)info[1], // name (String)info[1], // name
convertTorrentStatus(((Integer)info[2]).longValue(), ((Integer)info[13]).longValue(), ((Integer)info[14]).longValue(), ((Integer)info[15]).longValue()), // status convertTorrentStatus(((Integer)info[2]).longValue(), ((Integer)info[24]).longValue(), ((Integer)info[13]).longValue(), ((Integer)info[14]).longValue(), ((Integer)info[15]).longValue()), // status
basePath.substring(0, basePath.indexOf((String)info[17])), // locationDir basePath.substring(0, basePath.indexOf((String)info[17])), // locationDir
rateDownload, // rateDownload rateDownload, // rateDownload
(Integer)info[4], // rateUpload (Integer)info[4], // rateUpload
@ -607,19 +610,24 @@ public class RtorrentAdapter implements IDaemonAdapter {
} }
} }
private TorrentStatus convertTorrentStatus(Long state, Long complete, Long active, Long checking) { private TorrentStatus convertTorrentStatus(Long state, Long open, Long complete, Long active, Long checking) {
if (state == 0) { if (checking == 1) {
return TorrentStatus.Queued; return TorrentStatus.Checking;
} else if (active == 1) { }
if (open == 1) {
// links with tracker/peers are open: not stopped
if (state == 1 && active == 1) {
if (complete == 1) { if (complete == 1) {
return TorrentStatus.Seeding; return TorrentStatus.Seeding;
} else { } else {
return TorrentStatus.Downloading; return TorrentStatus.Downloading;
} }
} else if (checking == 1) { }
return TorrentStatus.Checking;
} else {
return TorrentStatus.Paused; return TorrentStatus.Paused;
} else {
// maybe could be Stopped or Waiting
return TorrentStatus.Queued;
} }
} }

Loading…
Cancel
Save