From e87534773d01e8d825d892f5f14d90f641ba1115 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Tue, 14 Nov 2017 22:39:43 +0100 Subject: [PATCH] Fixed #344 by adding support to qBittorrent for Date Added and Date Done, plus proper Error state. --- .../main/java/org/transdroid/daemon/Daemon.java | 2 +- .../daemon/Qbittorrent/QbittorrentAdapter.java | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/transdroid/daemon/Daemon.java b/app/src/main/java/org/transdroid/daemon/Daemon.java index f93b08d4..6b853a4d 100644 --- a/app/src/main/java/org/transdroid/daemon/Daemon.java +++ b/app/src/main/java/org/transdroid/daemon/Daemon.java @@ -340,7 +340,7 @@ public enum Daemon { } public static boolean supportsDateAdded(Daemon type) { - return type == Vuze || type == Transmission || type == rTorrent || type == Bitflu || type == BitComet || type == uTorrent || type == BitTorrent || type == Deluge || type == Dummy; + return type == Vuze || type == Transmission || type == rTorrent || type == Bitflu || type == BitComet || type == uTorrent || type == BitTorrent || type == Deluge || type == qBittorrent || type == Dummy; } public static boolean supportsLabels(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 342d1c62..b97be3fa 100644 --- a/app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java @@ -69,6 +69,7 @@ import java.net.URI; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; /** @@ -457,6 +458,8 @@ public class QbittorrentAdapter implements IDaemonAdapter { long size; int dlspeed; int upspeed; + Date addedOn = null; + Date completionOn = null; if (apiVersion >= 2) { leechers = new int[2]; @@ -469,6 +472,8 @@ public class QbittorrentAdapter implements IDaemonAdapter { ratio = tor.getDouble("ratio"); dlspeed = tor.getInt("dlspeed"); upspeed = tor.getInt("upspeed"); + addedOn = new Date(tor.getLong("added_on") * 1000L); + completionOn = new Date(tor.getLong("completion_on") * 1000L); } else { leechers = parsePeers(tor.getString("num_leechs")); seeders = parsePeers(tor.getString("num_seeds")); @@ -481,7 +486,6 @@ public class QbittorrentAdapter implements IDaemonAdapter { long eta = -1L; if (dlspeed > 0) eta = (long) (size - (size * progress)) / dlspeed; - // Date added is only available in /json/propertiesGeneral on a per-torrent basis, unfortunately // Add the parsed torrent to the list // @formatter:off torrents.add(new Torrent( @@ -503,8 +507,8 @@ public class QbittorrentAdapter implements IDaemonAdapter { (float) progress, 0f, null, - null, - null, + addedOn, + completionOn, null, settings.getType())); // @formatter:on @@ -594,7 +598,9 @@ public class QbittorrentAdapter implements IDaemonAdapter { private TorrentStatus parseStatus(String state) { // Status is given as a descriptive string - if (state.equals("downloading")) { + if (state.equals("error")) { + return TorrentStatus.Error; + } else if (state.equals("downloading")) { return TorrentStatus.Downloading; } else if (state.equals("uploading")) { return TorrentStatus.Seeding;