From 25cdb85efdfe292210087ddb89d58b98a1222449 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Fri, 17 Nov 2017 21:53:26 +0100 Subject: [PATCH] Added support for qBittorrent settings of transfer speeds. --- .../java/org/transdroid/daemon/Daemon.java | 2 +- .../Qbittorrent/QbittorrentAdapter.java | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/transdroid/daemon/Daemon.java b/app/src/main/java/org/transdroid/daemon/Daemon.java index 37d9e318..e36cff35 100644 --- a/app/src/main/java/org/transdroid/daemon/Daemon.java +++ b/app/src/main/java/org/transdroid/daemon/Daemon.java @@ -319,7 +319,7 @@ public enum Daemon { } public static boolean supportsSetTransferRates(Daemon type) { - return type == Deluge || type == Transmission || type == uTorrent || type == BitTorrent || type == rTorrent || type == Vuze || type == BuffaloNas || type == BitComet || type == Aria2 || type == Dummy; + return type == Deluge || type == Transmission || type == uTorrent || type == BitTorrent || type == rTorrent || type == Vuze || type == BuffaloNas || type == BitComet || type == Aria2 || type == qBittorrent || type == Dummy; } public static boolean supportsAddByFile(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 8e77ad6a..b370a956 100644 --- a/app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java @@ -70,7 +70,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.UnsupportedEncodingException; import java.net.URI; -import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -321,17 +320,13 @@ public class QbittorrentAdapter implements IDaemonAdapter { case SetTransferRates: - // TODO: This doesn't seem to work yet // Request to set the maximum transfer rates SetTransferRatesTask ratesTask = (SetTransferRatesTask) task; - int dl = (ratesTask.getDownloadRate() == null ? -1 : ratesTask.getDownloadRate()); - int ul = (ratesTask.getUploadRate() == null ? -1 : ratesTask.getUploadRate()); - - // First get the preferences - JSONObject prefs = new JSONObject(makeRequest(log, "/json/preferences")); - prefs.put("dl_limit", dl); - prefs.put("up_limit", ul); - makeRequest(log, "/command/setPreferences", new BasicNameValuePair("json", URLEncoder.encode(prefs.toString(), HTTP.UTF_8))); + String dl = (ratesTask.getDownloadRate() == null ? "NaN" : Long.toString(ratesTask.getDownloadRate() * 1024)); + String ul = (ratesTask.getUploadRate() == null ? "NaN" : Long.toString(ratesTask.getUploadRate() * 1024)); + + makeRequest(log, "/command/setGlobalDlLimit", new BasicNameValuePair("limit", dl)); + makeRequest(log, "/command/setGlobalUpLimit", new BasicNameValuePair("limit", ul)); return new DaemonTaskSuccessResult(task); case GetStats: @@ -359,8 +354,6 @@ public class QbittorrentAdapter implements IDaemonAdapter { return new DaemonTaskFailureResult(task, new DaemonException(ExceptionType.ParsingFailed, e.toString())); } catch (DaemonException e) { return new DaemonTaskFailureResult(task, e); - } catch (UnsupportedEncodingException e) { - return new DaemonTaskFailureResult(task, new DaemonException(ExceptionType.ParsingFailed, e.toString())); } } @@ -684,7 +677,7 @@ public class QbittorrentAdapter implements IDaemonAdapter { private ArrayList parseJsonFiles(JSONArray response) throws JSONException { // Parse response - ArrayList torrentfiles = new ArrayList(); + ArrayList torrentfiles = new ArrayList<>(); for (int i = 0; i < response.length(); i++) { JSONObject file = response.getJSONObject(i);