Browse Source

Added support for Deluge viewing and setting of labels on torrents. Fixes #54.

pull/82/head
Eric Kok 11 years ago
parent
commit
093835cf86
  1. 14
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  2. 2
      lib/src/org/transdroid/daemon/Daemon.java
  3. 37
      lib/src/org/transdroid/daemon/Deluge/DelugeAdapter.java

14
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -51,20 +51,12 @@ import org.transdroid.core.gui.lists.LocalTorrent; @@ -51,20 +51,12 @@ import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.lists.NoProgressHeaderTransformer;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.log.*;
import org.transdroid.core.gui.navigation.FilterListAdapter;
import org.transdroid.core.gui.navigation.FilterListAdapter_;
import org.transdroid.core.gui.navigation.FilterListDropDownAdapter;
import org.transdroid.core.gui.navigation.FilterListDropDownAdapter_;
import org.transdroid.core.gui.navigation.Label;
import org.transdroid.core.gui.navigation.NavigationFilter;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.gui.navigation.RefreshableActivity;
import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.rss.RssfeedsActivity_;
import org.transdroid.core.gui.navigation.*;
import org.transdroid.core.gui.rss.*;
import org.transdroid.core.gui.search.BarcodeHelper;
import org.transdroid.core.gui.search.FilePickerHelper;
import org.transdroid.core.gui.search.UrlEntryDialog;
import org.transdroid.core.gui.settings.MainSettingsActivity_;
import org.transdroid.core.gui.settings.*;
import org.transdroid.core.service.BootReceiver;
import org.transdroid.core.service.ConnectivityHelper;
import org.transdroid.core.widget.ListWidgetProvider;

2
lib/src/org/transdroid/daemon/Daemon.java

@ -318,7 +318,7 @@ public enum Daemon { @@ -318,7 +318,7 @@ public enum Daemon {
}
public static boolean supportsSetLabel(Daemon type) {
return type == uTorrent || type == BitTorrent || type == rTorrent || type == Dummy;
return type == uTorrent || type == BitTorrent || type == rTorrent || type == Deluge || type == Dummy;
}
public static boolean supportsSetDownloadLocation(Daemon type) {

37
lib/src/org/transdroid/daemon/Deluge/DelugeAdapter.java

@ -38,14 +38,15 @@ import org.json.JSONException; @@ -38,14 +38,15 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.DaemonException;
import org.transdroid.daemon.DaemonException.ExceptionType;
import org.transdroid.daemon.DaemonSettings;
import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Label;
import org.transdroid.daemon.Priority;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentDetails;
import org.transdroid.daemon.TorrentFile;
import org.transdroid.daemon.TorrentStatus;
import org.transdroid.daemon.DaemonException.ExceptionType;
import org.transdroid.daemon.task.AddByFileTask;
import org.transdroid.daemon.task.AddByMagnetUrlTask;
import org.transdroid.daemon.task.AddByUrlTask;
@ -113,6 +114,7 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -113,6 +114,7 @@ public class DelugeAdapter implements IDaemonAdapter {
private static final String RPC_METHOD_MOVESTORAGE = "core.move_storage";
private static final String RPC_METHOD_SETTRACKERS = "core.set_torrent_trackers";
private static final String RPC_METHOD_FORCERECHECK = "core.force_recheck";
private static final String RPC_METHOD_SETLABEL = "label.set_torrent";
private static final String RPC_NAME = "name";
private static final String RPC_STATUS = "state";
@ -137,7 +139,6 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -137,7 +139,6 @@ public class DelugeAdapter implements IDaemonAdapter {
private static final String RPC_LABEL = "label";
private static final String RPC_TRACKERS = "trackers";
private static final String RPC_TRACKER_STATUS = "tracker_status";
private static final String NO_LABEL = "No Label";
private static final String RPC_DETAILS = "files";
private static final String RPC_INDEX = "index";
@ -226,7 +227,7 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -226,7 +227,7 @@ public class DelugeAdapter implements IDaemonAdapter {
// params.put(-1); // cache_id
JSONObject result = makeRequest(buildRequest(RPC_METHOD_GET, params));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONObject(RPC_RESULT)),null);
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONObject(RPC_RESULT)), parseJsonRetrieveLabels(result.getJSONObject(RPC_RESULT)));
case GetTorrentDetails:
@ -373,13 +374,11 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -373,13 +374,11 @@ public class DelugeAdapter implements IDaemonAdapter {
case SetLabel:
// TODO: This doesn't seem to work; totally undocumented and also broken in the web UI so won't fix for now
// Request to set the label
SetLabelTask labelTask = (SetLabelTask) task;
JSONObject labelMap = new JSONObject();
labelMap.put(RPC_LABEL, (labelTask.getNewLabel() == null? NO_LABEL: labelTask.getNewLabel()));
makeRequest(buildRequest(RPC_METHOD_SETCONFIG, (new JSONArray()).put(labelMap)));
params.put(task.getTargetTorrent().getUniqueID());
params.put(labelTask.getNewLabel() == null ? "" : labelTask.getNewLabel());
makeRequest(buildRequest(RPC_METHOD_SETLABEL, params));
return new DaemonTaskSuccessResult(task);
case SetTrackers:
@ -612,6 +611,28 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -612,6 +611,28 @@ public class DelugeAdapter implements IDaemonAdapter {
}
private ArrayList<Label> parseJsonRetrieveLabels(JSONObject response) throws JSONException {
// Get the labels, of they exist (which is dependent on the plugin)
if (!response.has("filters"))
return null;
JSONObject filters = response.getJSONObject("filters");
if (!filters.has("label"))
return null;
JSONArray labels = filters.getJSONArray("label");
// Parse response
ArrayList<Label> allLabels = new ArrayList<Label>();
for (int i = 0; i < labels.length(); i++) {
JSONArray labelAndCount = labels.getJSONArray(i);
if (labelAndCount.getString(0).equals("All"))
continue; // Ignore the 'All' filter, which is not an actual label
allLabels.add(new Label(labelAndCount.getString(0), labelAndCount.getInt(1)));
}
return allLabels;
}
private ArrayList<TorrentFile> parseJsonFileListing(JSONObject response, Torrent torrent) throws JSONException {
// Parse response

Loading…
Cancel
Save