Browse Source

Adding proper altenative (turtle)mode support.

Adding basic server stats (not displayed yet; issue 131).
pull/11/head
Eric Kok 13 years ago
parent
commit
e63caf8efd
  1. BIN
      android/res/drawable-hdpi/icon_turtle_title_off.png
  2. 33
      android/src/org/transdroid/gui/TorrentsFragment.java
  3. 4
      lib/src/org/transdroid/daemon/Bitflu/BitfluAdapter.java
  4. 4
      lib/src/org/transdroid/daemon/Daemon.java
  5. 3
      lib/src/org/transdroid/daemon/DaemonMethod.java
  6. 9
      lib/src/org/transdroid/daemon/Transmission/TransmissionAdapter.java
  7. 30
      lib/src/org/transdroid/daemon/task/GetStatsTask.java
  8. 46
      lib/src/org/transdroid/daemon/task/GetStatsTaskSuccessResult.java

BIN
android/res/drawable-hdpi/icon_turtle_title_off.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

33
android/src/org/transdroid/gui/TorrentsFragment.java

@ -39,6 +39,8 @@ import org.transdroid.daemon.task.AddByUrlTask;
import org.transdroid.daemon.task.DaemonTask; import org.transdroid.daemon.task.DaemonTask;
import org.transdroid.daemon.task.DaemonTaskFailureResult; import org.transdroid.daemon.task.DaemonTaskFailureResult;
import org.transdroid.daemon.task.DaemonTaskSuccessResult; import org.transdroid.daemon.task.DaemonTaskSuccessResult;
import org.transdroid.daemon.task.GetStatsTask;
import org.transdroid.daemon.task.GetStatsTaskSuccessResult;
import org.transdroid.daemon.task.PauseAllTask; import org.transdroid.daemon.task.PauseAllTask;
import org.transdroid.daemon.task.PauseTask; import org.transdroid.daemon.task.PauseTask;
import org.transdroid.daemon.task.RemoveTask; import org.transdroid.daemon.task.RemoveTask;
@ -554,7 +556,7 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
miSearch.setIcon(R.drawable.icon_search_title); miSearch.setIcon(R.drawable.icon_search_title);
miSearch.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS|MenuItem.SHOW_AS_ACTION_WITH_TEXT); miSearch.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS|MenuItem.SHOW_AS_ACTION_WITH_TEXT);
MenuItem miAltMode = menu.add(0, MENU_ALTMODE_ID, 0, R.string.menu_altmode); MenuItem miAltMode = menu.add(0, MENU_ALTMODE_ID, 0, R.string.menu_altmode);
miAltMode.setIcon(R.drawable.icon_turtle_title); miAltMode.setIcon(inAlternativeMode? R.drawable.icon_turtle_title: R.drawable.icon_turtle_title_off);
miAltMode.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); miAltMode.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
miAltMode.setVisible(daemon != null && Daemon.supportsSetAlternativeMode(daemon.getType())); miAltMode.setVisible(daemon != null && Daemon.supportsSetAlternativeMode(daemon.getType()));
@ -1381,6 +1383,9 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
public void updateTorrentList() { public void updateTorrentList() {
if (daemon != null) { if (daemon != null) {
queue.enqueue(RetrieveTask.create(daemon)); queue.enqueue(RetrieveTask.create(daemon));
if (Daemon.supportsStats(daemon.getType())) {
queue.enqueue(GetStatsTask.create(daemon));
}
} }
} }
@ -1519,6 +1524,7 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
} }
inAlternativeMode = !inAlternativeMode; inAlternativeMode = !inAlternativeMode;
updateAlternativeModeIcon();
queue.enqueue(SetAlternativeModeTask.create(daemon, inAlternativeMode)); queue.enqueue(SetAlternativeModeTask.create(daemon, inAlternativeMode));
} }
@ -1665,6 +1671,21 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
} }
break; break;
case GetStats:
// Only bother if we still are still looking at the same daemon since the task was queued
if (result.getTask().getAdapterType() == daemon.getType()) {
GetStatsTaskSuccessResult stats = (GetStatsTaskSuccessResult) result;
if (Daemon.supportsSetAlternativeMode(daemon.getType())) {
// Update the alternative/tutle mode indicator
inAlternativeMode = stats.isAlternativeModeEnabled();
updateAlternativeModeIcon();
}
}
break;
case Remove: case Remove:
// Show 'removed' message // Show 'removed' message
@ -1730,8 +1751,18 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
Toast.makeText(getActivity(), getString(R.string.torrent_locationset, ((SetDownloadLocationTask)result.getTask()).getNewLocation()), Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), getString(R.string.torrent_locationset, ((SetDownloadLocationTask)result.getTask()).getNewLocation()), Toast.LENGTH_SHORT).show();
break; break;
case SetAlternativeMode:
// Updated the mode: now update the server stats to reflect the real new status (since the action might have been unsuccessful for some reason)
queue.enqueue(GetStatsTask.create(daemon));
break;
}
} }
private void updateAlternativeModeIcon() {
// By invalidation the options menu it gets redrawn and the turtle icon gets updated
getSupportActivity().invalidateOptionsMenu();
} }
/** /**

4
lib/src/org/transdroid/daemon/Bitflu/BitfluAdapter.java

@ -45,6 +45,8 @@ import org.transdroid.daemon.task.DaemonTaskResult;
import org.transdroid.daemon.task.DaemonTaskSuccessResult; import org.transdroid.daemon.task.DaemonTaskSuccessResult;
import org.transdroid.daemon.task.GetFileListTask; import org.transdroid.daemon.task.GetFileListTask;
import org.transdroid.daemon.task.GetFileListTaskSuccessResult; 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.RemoveTask;
import org.transdroid.daemon.task.RetrieveTask; import org.transdroid.daemon.task.RetrieveTask;
import org.transdroid.daemon.task.RetrieveTaskSuccessResult; import org.transdroid.daemon.task.RetrieveTaskSuccessResult;
@ -94,6 +96,8 @@ public class BitfluAdapter implements IDaemonAdapter {
// Request all torrents from server // Request all torrents from server
JSONObject result = makeBitfluRequest(RPC_TORRENT_LIST); JSONObject result = makeBitfluRequest(RPC_TORRENT_LIST);
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONArray(JSON_ROOT))); return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONArray(JSON_ROOT)));
case GetStats:
return new GetStatsTaskSuccessResult((GetStatsTask) task, false, -1);
case Pause: case Pause:
makeBitfluRequest(RPC_PAUSE_TORRENT + task.getTargetTorrent().getUniqueID()); makeBitfluRequest(RPC_PAUSE_TORRENT + task.getTargetTorrent().getUniqueID());
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);

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

@ -179,6 +179,10 @@ public enum Daemon {
return 8080; return 8080;
} }
public static boolean supportsStats(Daemon type) {
return type == Transmission || type == Bitflu;
}
public static boolean supportsAvailability(Daemon type) { public static boolean supportsAvailability(Daemon type) {
return type == uTorrent || type == BitTorrent || type == DLinkRouterBT || type == Transmission || type == Vuze || type == BuffaloNas; return type == uTorrent || type == BitTorrent || type == DLinkRouterBT || type == Transmission || type == Vuze || type == BuffaloNas;
} }

3
lib/src/org/transdroid/daemon/DaemonMethod.java

@ -42,7 +42,8 @@ public enum DaemonMethod {
SetDownloadLocation (17), SetDownloadLocation (17),
GetTorrentDetails (18), GetTorrentDetails (18),
SetTrackers (19), SetTrackers (19),
SetAlternativeMode (20); SetAlternativeMode (20),
GetStats (21);
private int code; private int code;
private static final Map<Integer,DaemonMethod> lookup = new HashMap<Integer,DaemonMethod>(); private static final Map<Integer,DaemonMethod> lookup = new HashMap<Integer,DaemonMethod>();

9
lib/src/org/transdroid/daemon/Transmission/TransmissionAdapter.java

@ -56,6 +56,8 @@ import org.transdroid.daemon.task.DaemonTaskResult;
import org.transdroid.daemon.task.DaemonTaskSuccessResult; import org.transdroid.daemon.task.DaemonTaskSuccessResult;
import org.transdroid.daemon.task.GetFileListTask; import org.transdroid.daemon.task.GetFileListTask;
import org.transdroid.daemon.task.GetFileListTaskSuccessResult; 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.GetTorrentDetailsTask;
import org.transdroid.daemon.task.GetTorrentDetailsTaskSuccessResult; import org.transdroid.daemon.task.GetTorrentDetailsTaskSuccessResult;
import org.transdroid.daemon.task.PauseTask; import org.transdroid.daemon.task.PauseTask;
@ -149,6 +151,13 @@ public class TransmissionAdapter implements IDaemonAdapter {
JSONObject result = makeRequest(buildRequestObject("torrent-get", request)); JSONObject result = makeRequest(buildRequestObject("torrent-get", request));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONObject("arguments"))); return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONObject("arguments")));
case GetStats:
// Request the current server statistics
JSONObject stats = makeRequest(buildRequestObject("session-get", new JSONObject())).getJSONObject("arguments");
return new GetStatsTaskSuccessResult((GetStatsTask) task, stats.getBoolean("alt-speed-enabled"),
stats.getLong("download-dir-free-space"));
case GetTorrentDetails: case GetTorrentDetails:
// Request fine details of a specific torrent // Request fine details of a specific torrent

30
lib/src/org/transdroid/daemon/task/GetStatsTask.java

@ -0,0 +1,30 @@
/*
* This file is part of Transdroid <http://www.transdroid.org>
*
* Transdroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Transdroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.transdroid.daemon.task;
import org.transdroid.daemon.DaemonMethod;
import org.transdroid.daemon.IDaemonAdapter;
public class GetStatsTask extends DaemonTask {
protected GetStatsTask(IDaemonAdapter adapter) {
super(adapter, DaemonMethod.GetStats, null, null);
}
public static GetStatsTask create(IDaemonAdapter adapter) {
return new GetStatsTask(adapter);
}
}

46
lib/src/org/transdroid/daemon/task/GetStatsTaskSuccessResult.java

@ -0,0 +1,46 @@
/*
* This file is part of Transdroid <http://www.transdroid.org>
*
* Transdroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Transdroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.transdroid.daemon.task;
/**
* The result of a successfully executed RetrieveTask on the daemon.
*
* @author erickok
*
*/
public class GetStatsTaskSuccessResult extends DaemonTaskSuccessResult {
private final boolean alternativeModeEnabled;
private final long downloadDirFreeSpaceBytes;
public GetStatsTaskSuccessResult(GetStatsTask executedTask, boolean alternativeModeEnabled, long downloadDirFreeSpaceBytes) {
super(executedTask);
this.alternativeModeEnabled = alternativeModeEnabled;
this.downloadDirFreeSpaceBytes = downloadDirFreeSpaceBytes;
}
public boolean isAlternativeModeEnabled() {
return alternativeModeEnabled;
}
public long getDownloadDirFreeSpaceBytes() {
return downloadDirFreeSpaceBytes;
}
}
Loading…
Cancel
Save