Browse Source

Support alternative speed mode (aka turtle mode) in qBittorrent; fixes #335.

pull/406/head
Eric Kok 7 years ago
parent
commit
a7e02e8216
  1. 4
      app/src/main/java/org/transdroid/daemon/Bitflu/BitfluAdapter.java
  2. 4
      app/src/main/java/org/transdroid/daemon/Daemon.java
  3. 20
      app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java

4
app/src/main/java/org/transdroid/daemon/Bitflu/BitfluAdapter.java

@ -41,8 +41,6 @@ import org.transdroid.daemon.task.DaemonTaskResult; @@ -41,8 +41,6 @@ import org.transdroid.daemon.task.DaemonTaskResult;
import org.transdroid.daemon.task.DaemonTaskSuccessResult;
import org.transdroid.daemon.task.GetFileListTask;
import org.transdroid.daemon.task.GetFileListTaskSuccessResult;
import org.transdroid.daemon.task.GetStatsTask;
import org.transdroid.daemon.task.GetStatsTaskSuccessResult;
import org.transdroid.daemon.task.RemoveTask;
import org.transdroid.daemon.task.RetrieveTask;
import org.transdroid.daemon.task.RetrieveTaskSuccessResult;
@ -93,8 +91,6 @@ public class BitfluAdapter implements IDaemonAdapter { @@ -93,8 +91,6 @@ public class BitfluAdapter implements IDaemonAdapter {
JSONObject result = makeBitfluRequest(log, RPC_TORRENT_LIST);
return new RetrieveTaskSuccessResult((RetrieveTask) task,
parseJsonRetrieveTorrents(result.getJSONArray(JSON_ROOT)), null);
case GetStats:
return new GetStatsTaskSuccessResult((GetStatsTask) task, false, -1);
case Pause:
makeBitfluRequest(log, RPC_PAUSE_TORRENT + task.getTargetTorrent().getUniqueID());
return new DaemonTaskSuccessResult(task);

4
app/src/main/java/org/transdroid/daemon/Daemon.java

@ -283,7 +283,7 @@ public enum Daemon { @@ -283,7 +283,7 @@ public enum Daemon {
}
public static boolean supportsStats(Daemon type) {
return type == Transmission || type == Bitflu || type == Dummy;
return type == Transmission || type == qBittorrent || type == Dummy;
}
public static boolean supportsAvailability(Daemon type) {
@ -356,7 +356,7 @@ public enum Daemon { @@ -356,7 +356,7 @@ public enum Daemon {
}
public static boolean supportsSetAlternativeMode(Daemon type) {
return type == Transmission || type == Dummy;
return type == Transmission || type == qBittorrent || type == Dummy;
}
public static boolean supportsSetTrackers(Daemon type) {

20
app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java

@ -53,6 +53,8 @@ import org.transdroid.daemon.task.DaemonTaskResult; @@ -53,6 +53,8 @@ import org.transdroid.daemon.task.DaemonTaskResult;
import org.transdroid.daemon.task.DaemonTaskSuccessResult;
import org.transdroid.daemon.task.GetFileListTask;
import org.transdroid.daemon.task.GetFileListTaskSuccessResult;
import org.transdroid.daemon.task.GetStatsTask;
import org.transdroid.daemon.task.GetStatsTaskSuccessResult;
import org.transdroid.daemon.task.GetTorrentDetailsTask;
import org.transdroid.daemon.task.GetTorrentDetailsTaskSuccessResult;
import org.transdroid.daemon.task.RemoveTask;
@ -300,6 +302,7 @@ public class QbittorrentAdapter implements IDaemonAdapter { @@ -300,6 +302,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
return new DaemonTaskSuccessResult(task);
case ForceRecheck:
// Force recheck a torrent
makeRequest(log, "/command/recheck", new BasicNameValuePair("hash", task.getTargetTorrent().getUniqueID()));
return new DaemonTaskSuccessResult(task);
@ -319,6 +322,23 @@ public class QbittorrentAdapter implements IDaemonAdapter { @@ -319,6 +322,23 @@ public class QbittorrentAdapter implements IDaemonAdapter {
makeRequest(log, "/command/setPreferences", new BasicNameValuePair("json", URLEncoder.encode(prefs.toString(), HTTP.UTF_8)));
return new DaemonTaskSuccessResult(task);
case GetStats:
// Refresh alternative download speeds setting
JSONObject stats = new JSONObject(makeRequest(log, "/sync/maindata?rid=0"));
JSONObject serverStats = stats.optJSONObject("server_state");
boolean alternativeSpeeds = false;
if (serverStats != null) {
alternativeSpeeds = serverStats.optBoolean("use_alt_speed_limits");
}
return new GetStatsTaskSuccessResult((GetStatsTask) task, !alternativeSpeeds, -1);
case SetAlternativeMode:
// Flip alternative speed mode
makeRequest(log, "/command/toggleAlternativeSpeedLimits");
return new DaemonTaskSuccessResult(task);
default:
return new DaemonTaskFailureResult(task,
new DaemonException(ExceptionType.MethodUnsupported, task.getMethod() + " is not supported by " + getType()));

Loading…
Cancel
Save