diff --git a/app/src/main/java/org/transdroid/daemon/Bitflu/BitfluAdapter.java b/app/src/main/java/org/transdroid/daemon/Bitflu/BitfluAdapter.java index 867fef0a..34fd1e2a 100644 --- a/app/src/main/java/org/transdroid/daemon/Bitflu/BitfluAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/Bitflu/BitfluAdapter.java @@ -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 { 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); diff --git a/app/src/main/java/org/transdroid/daemon/Daemon.java b/app/src/main/java/org/transdroid/daemon/Daemon.java index 6b853a4d..5b05dcb6 100644 --- a/app/src/main/java/org/transdroid/daemon/Daemon.java +++ b/app/src/main/java/org/transdroid/daemon/Daemon.java @@ -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 { } public static boolean supportsSetAlternativeMode(Daemon type) { - return type == Transmission || type == Dummy; + return type == Transmission || type == qBittorrent || type == Dummy; } public static boolean supportsSetTrackers(Daemon type) { diff --git a/app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java index b97be3fa..56afbd60 100644 --- a/app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java @@ -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 { 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 { 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()));