Browse Source

Finalized adding of torrents via http, file or magnet; also multiple http links at once via ADD_MULTIPLE.

pull/11/head
Eric Kok 12 years ago
parent
commit
3593ead589
  1. 2
      android/src/com/xirvik/transdroid/preferences/PreferencesXirvikServer.java
  2. 2
      android/src/org/transdroid/preferences/ImportExport.java
  3. 2
      android/src/org/transdroid/search/barcode/GoogleWebSearchBarcodeResolver.java
  4. 2
      android/src/org/transdroid/service/UpdateService.java
  5. 4
      core/res/layout-w900dp/activity_rssfeeds.xml
  6. 2
      core/res/layout/activity_rssitems.xml
  7. 5
      core/res/layout/fragment_rssitems.xml
  8. 6
      core/res/layout/list_item_rssitem.xml
  9. 6
      core/res/menu/fragment_rssfeeds.xml
  10. 5
      core/res/values/strings.xml
  11. 6
      core/res/xml/pref_websearch.xml
  12. 2
      core/src/org/transdroid/core/app/search/GoogleWebSearchBarcodeResolver.java
  13. 50
      core/src/org/transdroid/core/app/settings/ApplicationSettings.java
  14. 2
      core/src/org/transdroid/core/app/settings/SettingsPersistence.java
  15. 8
      core/src/org/transdroid/core/app/settings/WebsearchSetting.java
  16. 124
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  17. 2
      core/src/org/transdroid/core/gui/rss/RssfeedLoader.java
  18. 3
      core/src/org/transdroid/core/gui/rss/RssfeedView.java
  19. 75
      core/src/org/transdroid/core/gui/rss/RssfeedsActivity.java
  20. 7
      core/src/org/transdroid/core/gui/rss/RssfeedsFragment.java
  21. 5
      core/src/org/transdroid/core/gui/rss/RssitemView.java
  22. 4
      core/src/org/transdroid/core/gui/rss/RssitemsActivity.java
  23. 41
      core/src/org/transdroid/core/gui/rss/RssitemsFragment.java
  24. 1
      core/src/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java
  25. 1
      core/src/org/transdroid/core/rssparser/Channel.java
  26. 6
      core/src/org/transdroid/core/rssparser/HttpHelper.java
  27. 3
      core/src/org/transdroid/core/rssparser/Item.java
  28. 104
      full/AndroidManifest.xml
  29. 10
      lib/src/org/transdroid/daemon/BitComet/BitCometAdapter.java
  30. 2
      lib/src/org/transdroid/daemon/Bitflu/BitfluAdapter.java
  31. 2
      lib/src/org/transdroid/daemon/BuffaloNas/BuffaloNasAdapter.java
  32. 2
      lib/src/org/transdroid/daemon/DLinkRouterBT/DLinkRouterBTAdapter.java
  33. 6
      lib/src/org/transdroid/daemon/Deluge/DelugeAdapter.java
  34. 6
      lib/src/org/transdroid/daemon/Ktorrent/KtorrentAdapter.java
  35. 2
      lib/src/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java
  36. 2
      lib/src/org/transdroid/daemon/Synology/SynologyAdapter.java
  37. 4
      lib/src/org/transdroid/daemon/Tfb4rt/Tfb4rtAdapter.java
  38. 12
      lib/src/org/transdroid/daemon/Transmission/TransmissionAdapter.java
  39. 6
      lib/src/org/transdroid/daemon/Utorrent/UtorrentAdapter.java
  40. 77
      lib/src/org/transdroid/daemon/util/HttpHelper.java
  41. 101
      lite/AndroidManifest.xml

2
android/src/com/xirvik/transdroid/preferences/PreferencesXirvikServer.java

@ -230,7 +230,7 @@ public class PreferencesXirvikServer extends PreferenceActivity { @@ -230,7 +230,7 @@ public class PreferencesXirvikServer extends PreferenceActivity {
String url = "https://" + serverValue + ":443/browsers_addons/transdroid_autoconf.txt";
HttpResponse request = httpclient.execute(new HttpGet(url));
InputStream stream = request.getEntity().getContent();
String folderVal = HttpHelper.ConvertStreamToString(stream).trim();
String folderVal = HttpHelper.convertStreamToString(stream).trim();
if (folderVal.startsWith("<?xml")) {
folderVal = null;
}

2
android/src/org/transdroid/preferences/ImportExport.java

@ -33,7 +33,7 @@ public class ImportExport { @@ -33,7 +33,7 @@ public class ImportExport {
Editor editor = prefs.edit();
// Read the settings file
String raw = HttpHelper.ConvertStreamToString(new FileInputStream(settingsFile));
String raw = HttpHelper.convertStreamToString(new FileInputStream(settingsFile));
JSONObject json = new JSONObject(raw);
if (json.has("servers")) {

2
android/src/org/transdroid/search/barcode/GoogleWebSearchBarcodeResolver.java

@ -53,7 +53,7 @@ public abstract class GoogleWebSearchBarcodeResolver extends AsyncTask<String, @@ -53,7 +53,7 @@ public abstract class GoogleWebSearchBarcodeResolver extends AsyncTask<String,
HttpGet httpget = new HttpGet(callUrl);
HttpResponse response = httpclient.execute(httpget);
InputStream instream = response.getEntity().getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
JSONArray results = new JSONObject(result).getJSONObject("responseData").getJSONArray("results");
// We will combine and filter multiple results, if there are any

2
android/src/org/transdroid/service/UpdateService.java

@ -134,7 +134,7 @@ public class UpdateService extends IntentService { @@ -134,7 +134,7 @@ public class UpdateService extends IntentService {
// Retrieve what is the latest released app version
HttpResponse request = httpclient.execute(new HttpGet(url));
InputStream stream = request.getEntity().getContent();
String appVersion[] = HttpHelper.ConvertStreamToString(stream).split("\\|");
String appVersion[] = HttpHelper.convertStreamToString(stream).split("\\|");
stream.close();
return appVersion;

4
core/res/layout-w900dp/activity_rssfeeds.xml

@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
android:id="@+id/rssfeeds_list"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_weight="2"
class="org.transdroid.core.gui.rss.RssfeedsFragment_"
tools:layout="@layout/fragment_rssfeeds" />
@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
android:id="@+id/rssitems_list"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_weight="3"
class="org.transdroid.core.gui.rss.RssitemsFragment_"
tools:layout="@layout/fragment_rssitems" />

2
core/res/layout/activity_rssitems.xml

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
tools:context=".RssItemsActivity" >
<fragment
android:id="@+id/rssfitems_list"
android:id="@+id/rssitems_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="org.transdroid.core.gui.rss.RssitemsFragment_"

5
core/res/layout/fragment_rssitems.xml

@ -21,8 +21,7 @@ @@ -21,8 +21,7 @@
android:gravity="center"
android:maxWidth="400dip"
android:padding="@dimen/margin_default"
android:text="@string/rss_empty"
android:textIsSelectable="false"
android:visibility="gone" />
android:text="@string/rss_noselection"
android:textIsSelectable="false" />
</FrameLayout>

6
core/res/layout/list_item_rssitem.xml

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<org.transdroid.core.gui.lists.RssitemStatusLayout xmlns:android="http://schemas.android.com/apk/res/android"
<org.transdroid.core.gui.rss.RssitemStatusLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/selectable_background_transdroid"
@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:textColor="?attr/text_bright"
android:textIsSelectable="true"
android:textIsSelectable="false"
android:textSize="@dimen/text_enlarged" />
<TextView
@ -26,4 +26,4 @@ @@ -26,4 +26,4 @@
android:textIsSelectable="false"
android:textSize="@dimen/text_small" />
</org.transdroid.core.gui.lists.RssitemStatusLayout>
</org.transdroid.core.gui.rss.RssitemStatusLayout>

6
core/res/menu/fragment_rssfeeds.xml

@ -1,5 +1,11 @@ @@ -1,5 +1,11 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_refresh"
android:icon="?attr/ic_action_refresh"
android:showAsAction="always"
android:title="@string/action_refresh"/>
<item
android:id="@+id/action_settings"
android:title="@string/action_settings"/>

5
core/res/values/strings.xml

@ -121,7 +121,10 @@ @@ -121,7 +121,10 @@
<string name="rss_feeds">RSS feeds</string>
<string name="rss_nosettings">You have not defined any RSS feeds yet to monitor. Torrent-specific RSS feeds keep you up to date with new releases and you are notified of new items.</string>
<string name="rss_noselection">Select an RSS feed to view the new items</string>
<string name="rss_empty">The RSS feed is not available or it contains no items</string>
<string name="rss_notloaded">Sorry, please wait until the RSS feed is loaded</string>
<string name="rss_error">Sorry, this RSS feed could not be loaded at this time</string>
<plurals name="rss_itemsselected">
<item quantity="one">%1$d item selected</item>
<item quantity="other">%1$d items selected</item>
@ -140,6 +143,8 @@ @@ -140,6 +143,8 @@
<string name="pref_name_optional">Optional personal name</string>
<string name="pref_searchurl">Direct search URL</string>
<string name="pref_searchurl_info">%s will be replaced by the search query</string>
<string name="pref_cookies">Cookies</string>
<string name="pref_cookies_info">Optional; use the key1=value1;key2=value2 format</string>
<string name="pref_feedurl">Feed URL</string>
<string name="pref_reqauth">Requires authentication</string>
<string name="pref_reqauth_info">Opens links in the webbrowser for user login</string>

6
core/res/xml/pref_websearch.xml

@ -13,4 +13,10 @@ @@ -13,4 +13,10 @@
android:summary="@string/pref_searchurl_info"
android:inputType="textUri" />
<EditTextPreference
android:key="websearch_cookies"
android:title="@string/pref_cookies"
android:summary="@string/pref_cookies_info"
android:inputType="textUri" />
</PreferenceScreen>

2
core/src/org/transdroid/core/app/search/GoogleWebSearchBarcodeResolver.java

@ -44,7 +44,7 @@ public class GoogleWebSearchBarcodeResolver { @@ -44,7 +44,7 @@ public class GoogleWebSearchBarcodeResolver {
HttpGet httpget = new HttpGet(callUrl);
HttpResponse response = httpclient.execute(httpget);
InputStream instream = response.getEntity().getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
JSONArray results = new JSONObject(result).getJSONObject("responseData").getJSONArray("results");
// We will combine and filter multiple results, if there are any

50
core/src/org/transdroid/core/app/settings/ApplicationSettings.java

@ -65,18 +65,28 @@ public class ApplicationSettings { @@ -65,18 +65,28 @@ public class ApplicationSettings {
Daemon type = Daemon.fromCode(prefs.getString("server_type_" + order, null));
boolean ssl = prefs.getBoolean("server_sslenabled_" + order, false);
String defaultPort = Integer.toString(Daemon.getDefaultPortNumber(type, ssl));
return new ServerSetting(order, prefs.getString("server_name_" + order, null), type, prefs.getString(
"server_address_" + order, null), prefs.getString("server_localaddress_" + order, null),
prefs.getString("server_localnetwork_" + order, null), Integer.parseInt(prefs.getString("server_port_"
+ order, defaultPort)), ssl, prefs.getBoolean("server_ssltrustall_" + order, false),
prefs.getString("server_ssltrustkey_" + order, null), prefs.getString("server_folder_" + order, null),
prefs.getBoolean("server_useauth_" + order, true), prefs.getString("server_user_" + order, null),
prefs.getString("server_pass_" + order, null), prefs.getString("server_extrapass_" + order, null),
OS.fromCode(prefs.getString("server_os_" + order, "type_linux")), prefs.getString("server_downloaddir_"
+ order, null), prefs.getString("server_ftpurl_" + order, null), prefs.getString(
"server_ftppass_" + order, null), Integer.parseInt(prefs.getString("server_timeout_" + order,
"8")), prefs.getBoolean("server_alarmfinished_" + order, true), prefs.getBoolean(
"server_alarmnew_" + order, false), false);
return new ServerSetting(order,
prefs.getString("server_name_" + order, null), type,
prefs.getString("server_address_" + order, null),
prefs.getString("server_localaddress_" + order, null),
prefs.getString("server_localnetwork_" + order, null),
Integer.parseInt(prefs.getString("server_port_" + order, defaultPort)),
ssl,
prefs.getBoolean("server_ssltrustall_" + order, false),
prefs.getString("server_ssltrustkey_" + order, null),
prefs.getString("server_folder_" + order, null),
prefs.getBoolean("server_useauth_" + order, true),
prefs.getString("server_user_" + order, null),
prefs.getString("server_pass_" + order, null),
prefs.getString("server_extrapass_" + order, null),
OS.fromCode(prefs.getString("server_os_" + order, "type_linux")),
prefs.getString("server_downloaddir_" + order, null),
prefs.getString("server_ftpurl_" + order, null),
prefs.getString("server_ftppass_" + order, null),
Integer.parseInt(prefs.getString("server_timeout_" + order, "8")),
prefs.getBoolean("server_alarmfinished_" + order, true),
prefs.getBoolean("server_alarmnew_" + order, false),
false);
// @formatter:on
}
@ -219,8 +229,10 @@ public class ApplicationSettings { @@ -219,8 +229,10 @@ public class ApplicationSettings {
*/
public WebsearchSetting getWebsearchSetting(int order) {
// @formatter:off
return new WebsearchSetting(order, prefs.getString("websearch_name_" + order, null), prefs.getString(
"websearch_baseurl_" + order, null));
return new WebsearchSetting(order,
prefs.getString("websearch_name_" + order, null),
prefs.getString("websearch_baseurl_" + order, null),
prefs.getString("websearch_cookies_" + order, null));
// @formatter:on
}
@ -239,11 +251,13 @@ public class ApplicationSettings { @@ -239,11 +251,13 @@ public class ApplicationSettings {
for (int i = order; i < max; i++) {
edit.putString("websearch_name_" + i, prefs.getString("websearch_name_" + (i + 1), null));
edit.putString("websearch_baseurl_" + i, prefs.getString("websearch_baseurl_" + (i + 1), null));
edit.putString("websearch_cookies_" + i, prefs.getString("websearch_cookies_" + (i + 1), null));
}
// Remove the last settings, of which we are now sure are no longer required
edit.remove("websearch_name_" + max);
edit.remove("websearch_baseurl_" + max);
edit.remove("websearch_cookies_" + max);
edit.commit();
}
@ -279,9 +293,11 @@ public class ApplicationSettings { @@ -279,9 +293,11 @@ public class ApplicationSettings {
public RssfeedSetting getRssfeedSetting(int order) {
// @formatter:off
long lastViewed = prefs.getLong("rssfeed_lastviewed_" + order, -1);
return new RssfeedSetting(order, prefs.getString("rssfeed_name_" + order, null), prefs.getString("rssfeed_url_"
+ order, null), prefs.getBoolean("rssfeed_reqauth_" + order, false), lastViewed == -1L ? null
: new Date(lastViewed));
return new RssfeedSetting(order,
prefs.getString("rssfeed_name_" + order, null),
prefs.getString("rssfeed_url_" + order, null),
prefs.getBoolean("rssfeed_reqauth_" + order, false),
lastViewed == -1L ? null: new Date(lastViewed));
// @formatter:on
}

2
core/src/org/transdroid/core/app/settings/SettingsPersistence.java

@ -49,7 +49,7 @@ public class SettingsPersistence { @@ -49,7 +49,7 @@ public class SettingsPersistence {
Editor editor = prefs.edit();
// Read the settings file
String raw = HttpHelper.ConvertStreamToString(new FileInputStream(settingsFile));
String raw = HttpHelper.convertStreamToString(new FileInputStream(settingsFile));
JSONObject json = new JSONObject(raw);
// Import servers

8
core/src/org/transdroid/core/app/settings/WebsearchSetting.java

@ -17,11 +17,13 @@ public class WebsearchSetting implements SimpleListItem { @@ -17,11 +17,13 @@ public class WebsearchSetting implements SimpleListItem {
private final int order;
private final String name;
private final String baseUrl;
private final String cookies;
public WebsearchSetting(int order, String name, String baseUrl) {
public WebsearchSetting(int order, String name, String baseUrl, String cookies) {
this.order = order;
this.name = name;
this.baseUrl = baseUrl;
this.cookies = cookies;
}
public int getOrder() {
@ -43,6 +45,10 @@ public class WebsearchSetting implements SimpleListItem { @@ -43,6 +45,10 @@ public class WebsearchSetting implements SimpleListItem {
return baseUrl;
}
public String getCookies() {
return cookies;
}
public String getKey() {
return KEY_PREFIX + getOrder();
}

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

@ -1,11 +1,14 @@ @@ -1,11 +1,14 @@
package org.transdroid.core.gui;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
@ -19,17 +22,33 @@ import org.androidannotations.annotations.OptionsMenu; @@ -19,17 +22,33 @@ import org.androidannotations.annotations.OptionsMenu;
import org.androidannotations.annotations.SystemService;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.*;
import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.app.settings.WebsearchSetting;
import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.log.*;
import org.transdroid.core.gui.navigation.*;
import org.transdroid.core.gui.rss.*;
import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.log.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.StatusType;
import org.transdroid.core.gui.rss.RssfeedsActivity_;
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.*;
import org.transdroid.core.gui.settings.MainSettingsActivity_;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Priority;
@ -62,6 +81,7 @@ import org.transdroid.daemon.task.SetTrackersTask; @@ -62,6 +81,7 @@ import org.transdroid.daemon.task.SetTrackersTask;
import org.transdroid.daemon.task.StartTask;
import org.transdroid.daemon.task.StopTask;
import org.transdroid.daemon.util.DLog;
import org.transdroid.daemon.util.HttpHelper;
import android.annotation.TargetApi;
import android.app.SearchManager;
@ -185,6 +205,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -185,6 +205,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Handle any start up intents
if (firstStart && getIntent() != null) {
currentConnection = lastUsed.createServerAdapter();
handleStartIntent();
}
@ -399,11 +420,32 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -399,11 +420,32 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Adding a torrent from http or https URL
if (dataUri.getScheme().equals("http") || dataUri.getScheme().equals("https")) {
String title = data.substring(data.lastIndexOf("/"));
// Check if the target URL is also defined as a web search in the user's settings
List<WebsearchSetting> websearches = applicationSettings.getWebsearchSettings();
WebsearchSetting match = null;
for (WebsearchSetting setting : websearches) {
Uri uri = Uri.parse(setting.getBaseUrl());
if (uri.getHost() != null && uri.getHost().equals(dataUri.getHost())) {
match = setting;
break;
}
}
// If the URL is also a web search and it defines cookies, use the cookies by downloading the targeted
// torrent file (while supplies the cookies to the HTTP request) instead of sending the URL directly to the
// torrent client
if (match != null && match.getCookies() != null) {
addTorrentFromWeb(data, match);
} else {
// Normally send the URL to the torrent client; the title we show is just the 'file name'
// TODO: Make a better effort in determining the title (check query string, clean special chars)
String title = data.substring(data.lastIndexOf("/") + 1);
if (intent.hasExtra("TORRENT_TITLE")) {
title = intent.getStringExtra("TORRENT_TITLE");
}
addTorrentByUrl(data, title);
}
return;
}
@ -413,9 +455,9 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -413,9 +455,9 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
return;
}
// Adding a local .torrent file
// Adding a local .torrent file; the title we show is just the file name
if (dataUri.getScheme().equals("file")) {
String title = data.substring(data.lastIndexOf("/"));
String title = data.substring(data.lastIndexOf("/") + 1);
addTorrentByFile(data, title);
return;
}
@ -638,13 +680,61 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -638,13 +680,61 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
private void addTorrentFromDownloads(Uri contentUri) {
InputStream input = null;
try {
// Open the content uri as input stream
input = getContentResolver().openInputStream(contentUri);
// Open the content uri as input stream and this via a local temporary file
addTorrentFromStream(getContentResolver().openInputStream(contentUri));
} catch (SecurityException e) {
// No longer access to this file
Log.e(this, "No access given to " + contentUri.toString() + ": " + e.toString());
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
} catch (FileNotFoundException e) {
Log.e(this, contentUri.toString() + " does not exist: " + e.toString());
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
}
}
@Background
protected void addTorrentFromWeb(String url, WebsearchSetting websearchSetting) {
try {
// Cookies are taken from the websearchSetting that we already matched against this target URL
DefaultHttpClient httpclient = HttpHelper.createStandardHttpClient(false, null, null, true, null, 10000,
null, -1);
Map<String, String> cookies = HttpHelper.parseCookiePairs(websearchSetting.getCookies());
String domain = Uri.parse(url).getHost();
for (Entry<String, String> pair : cookies.entrySet()) {
BasicClientCookie cookie = new BasicClientCookie(pair.getKey(), pair.getValue());
cookie.setPath("/");
cookie.setDomain(domain);
httpclient.getCookieStore().addCookie(cookie);
}
// Download the torrent at the specified URL (which will first be written to a temporary file)
// If we get an HTTP 401, 403 or 404 response, show an error to the user
HttpResponse response = httpclient.execute(new HttpGet(url));
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED
|| response.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN
|| response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
Log.e(this, "Can't retrieve web torrent " + url + ": Unexpected HTTP response status code "
+ response.getStatusLine().toString());
Crouton.showText(this, R.string.error_401, NavigationHelper.CROUTON_ERROR_STYLE);
return;
}
InputStream input = response.getEntity().getContent();
addTorrentFromStream(input);
} catch (Exception e) {
Log.e(this, "Can't retrieve web torrent " + url + ": " + e.toString());
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
}
}
@Background
protected void addTorrentFromStream(InputStream input) {
File tempFile = new File("/not/yet/set");
try {
// Write a temporary file with the torrent contents
File tempFile = File.createTempFile("transdroid_", ".torrent", getCacheDir());
tempFile = File.createTempFile("transdroid_", ".torrent", getCacheDir());
FileOutputStream output = new FileOutputStream(tempFile);
try {
final byte[] buffer = new byte[1024];
@ -657,17 +747,15 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -657,17 +747,15 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
} finally {
output.close();
}
} catch (SecurityException e) {
// No longer access to this file
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
} catch (IOException e1) {
// Can't write temporary file
} catch (IOException e) {
Log.e(this, "Can't write input stream to " + tempFile.toString() + ": " + e.toString());
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
} finally {
try {
if (input != null)
input.close();
} catch (IOException e) {
Log.e(this, "Error closing the input stream " + tempFile.toString() + ": " + e.toString());
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
}
}
@ -725,7 +813,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -725,7 +813,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
@Override
public void removeTorrent(Torrent torrent, boolean withData) {
DaemonTaskResult result = RemoveTask.create(currentConnection, torrent, withData).execute();
if (result instanceof DaemonTaskResult) {
if (result instanceof DaemonTaskSuccessResult) {
onTaskSucceeded(
(DaemonTaskSuccessResult) result,
getString(withData ? R.string.result_removed_with_data : R.string.result_removed, torrent.getName()));

2
core/src/org/transdroid/core/gui/rss/RssfeedLoader.java

@ -36,7 +36,7 @@ public class RssfeedLoader { @@ -36,7 +36,7 @@ public class RssfeedLoader {
newCount++;
item.setIsNew(true);
} else {
item.setIsNew(true);
item.setIsNew(false);
}
}
}

3
core/src/org/transdroid/core/gui/rss/RssfeedView.java

@ -55,7 +55,8 @@ public class RssfeedView extends LinearLayout { @@ -55,7 +55,8 @@ public class RssfeedView extends LinearLayout {
// Clear and then asynchronously load the RSS feed site' favicon
// Uses the g.etfv.co service to resolve the favicon of any feed URL
faviconImage.setImageDrawable(null);
navigationHelper.getImageCache().displayImage(String.format(GETFVO_URL, rssfeedLoader), faviconImage);
navigationHelper.getImageCache().displayImage(String.format(GETFVO_URL, rssfeedLoader.getSetting().getUrl()),
faviconImage);
}

75
core/src/org/transdroid/core/gui/rss/RssfeedsActivity.java

@ -1,11 +1,9 @@ @@ -1,11 +1,9 @@
package org.transdroid.core.gui.rss;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Bean;
@ -16,10 +14,10 @@ import org.androidannotations.annotations.UiThread; @@ -16,10 +14,10 @@ import org.androidannotations.annotations.UiThread;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.*;
import org.transdroid.core.gui.*;
import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.rssparser.Channel;
import org.transdroid.core.rssparser.RssParser;
import org.xml.sax.SAXException;
import android.annotation.TargetApi;
import android.content.Intent;
@ -28,6 +26,8 @@ import android.os.Bundle; @@ -28,6 +26,8 @@ import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import de.keyboardsurfer.android.widget.crouton.Crouton;
@EActivity(resName = "activity_rssfeeds")
public class RssfeedsActivity extends SherlockFragmentActivity {
@ -59,9 +59,22 @@ public class RssfeedsActivity extends SherlockFragmentActivity { @@ -59,9 +59,22 @@ public class RssfeedsActivity extends SherlockFragmentActivity {
getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.rss_feeds)));
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@OptionsItem(android.R.id.home)
protected void navigateUp() {
TorrentsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start();
}
@Override
protected void onResume() {
super.onResume();
refreshFeeds();
}
/**
* Reload the RSS feed settings and start loading all the feeds. To be called from contained fragments.
*/
public void refreshFeeds() {
loaders = new ArrayList<RssfeedLoader>();
// For each RSS feed setting the user created, start a loader that retrieved the RSS feed (via a background
// thread) and, on success, determines the new items in the feed
@ -73,28 +86,21 @@ public class RssfeedsActivity extends SherlockFragmentActivity { @@ -73,28 +86,21 @@ public class RssfeedsActivity extends SherlockFragmentActivity {
fragmentFeeds.update(loaders);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@OptionsItem(android.R.id.home)
protected void navigateUp() {
TorrentsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start();
}
/**
* Performs the loading of the RSS feed content and parsing of items, in a background thread.
* @param loader The RSS feed loader for which to retrieve the contents
*/
@Background
protected void loadRssfeed(RssfeedLoader loader) {
RssParser parser = new RssParser(loader.getSetting().getUrl());
try {
// Load and parse the feed
RssParser parser = new RssParser(loader.getSetting().getUrl());
parser.parse();
handleRssfeedResult(loader, parser.getChannel(), true);
} catch (ParserConfigurationException e) {
handleRssfeedResult(loader, null, true);
} catch (SAXException e) {
handleRssfeedResult(loader, null, true);
} catch (IOException e) {
handleRssfeedResult(loader, parser.getChannel(), false);
} catch (Exception e) {
// Catch any error that may occurred and register this failure
handleRssfeedResult(loader, null, true);
Log.i(this, "RSS feed " + loader.getSetting().getUrl() + " error: " + e.toString());
}
}
@ -114,14 +120,45 @@ public class RssfeedsActivity extends SherlockFragmentActivity { @@ -114,14 +120,45 @@ public class RssfeedsActivity extends SherlockFragmentActivity {
/**
* Opens an RSS feed in the dedicated fragment (if there was space in the UI) or a new {@link RssitemsActivity}.
* Optionally this also registers in the user preferences that the feed was now viewed, so that in the future the
* new items can be properly marked.
* @param loader The RSS feed loader (with settings and the loaded content channel) to show
* @param markAsViewedNow True if the user settings should be updated to reflect this feed's last viewed date; false otherwise
*/
public void openRssfeed(RssfeedLoader loader) {
public void openRssfeed(RssfeedLoader loader, boolean markAsViewedNow) {
// The RSS feed content was loaded and can now be shown in the dedicated fragment or a new activity
if (fragmentItems != null) {
fragmentItems.update(loader.getChannel());
// If desired, update the lastViewedDate of this feed in the user setting; this won't be loaded until the RSS
// feeds screen in opened again.
if (!loader.hasError() && loader.getChannel() != null && markAsViewedNow) {
applicationSettings.setRssfeedLastViewer(loader.getSetting().getOrder(), new Date());
}
fragmentItems.update(loader.getChannel(), loader.hasError());
} else {
// Error message or not yet loaded? Show a toast message instead of opening the items activity
if (loader.hasError()) {
Crouton.showText(this, R.string.rss_error, NavigationHelper.CROUTON_INFO_STYLE);
return;
}
if (loader.getChannel() == null || loader.getChannel().getItems().size() == 0) {
Crouton.showText(this, R.string.rss_notloaded, NavigationHelper.CROUTON_INFO_STYLE);
return;
}
// If desired, update the lastViewedDate of this feed in the user setting; this won't be loaded until the RSS
// feeds screen in opened again
if (markAsViewedNow) {
applicationSettings.setRssfeedLastViewer(loader.getSetting().getOrder(), new Date());
}
RssitemsActivity_.intent(this).rssfeed(loader.getChannel()).start();
}
}
}

7
core/src/org/transdroid/core/gui/rss/RssfeedsFragment.java

@ -61,9 +61,14 @@ public class RssfeedsFragment extends SherlockFragment { @@ -61,9 +61,14 @@ public class RssfeedsFragment extends SherlockFragment {
MainSettingsActivity_.intent(getActivity()).start();
}
@OptionsItem(resName = "action_refresh")
protected void refreshScreen() {
((RssfeedsActivity)getActivity()).refreshFeeds();
}
@ItemClick(resName = "rssfeeds_list")
protected void onFeedClicked(RssfeedLoader loader) {
((RssfeedsActivity)getActivity()).openRssfeed(loader);
((RssfeedsActivity)getActivity()).openRssfeed(loader, true);
}
/**

5
core/src/org/transdroid/core/gui/rss/RssitemView.java

@ -26,8 +26,9 @@ public class RssitemView extends RssitemStatusLayout { @@ -26,8 +26,9 @@ public class RssitemView extends RssitemStatusLayout {
public void bind(Item rssitem) {
nameText.setText(rssitem.getTitle());
dateText.setText(DateUtils.getRelativeDateTimeString(getContext(), rssitem.getPubdate().getTime(),
DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, DateUtils.FORMAT_ABBREV_MONTH));
dateText.setText(rssitem.getPubdate() == null ? "" : DateUtils.getRelativeDateTimeString(getContext(), rssitem
.getPubdate().getTime(), DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS,
DateUtils.FORMAT_ABBREV_MONTH));
setIsNew(rssitem.isNew());
}

4
core/src/org/transdroid/core/gui/rss/RssitemsActivity.java

@ -18,7 +18,7 @@ import android.os.Bundle; @@ -18,7 +18,7 @@ import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
@EActivity(resName = "activity_rssfeeds")
@EActivity(resName = "activity_rssitems")
public class RssitemsActivity extends SherlockFragmentActivity {
@Extra
@ -51,7 +51,7 @@ public class RssitemsActivity extends SherlockFragmentActivity { @@ -51,7 +51,7 @@ public class RssitemsActivity extends SherlockFragmentActivity {
getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(rssfeed.getTitle()));
// Get the intent extras and show them to the already loaded fragment
fragmentItems.update(rssfeed);
fragmentItems.update(rssfeed, false);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)

41
core/src/org/transdroid/core/gui/rss/RssitemsFragment.java

@ -15,6 +15,7 @@ import org.transdroid.core.rssparser.Channel; @@ -15,6 +15,7 @@ import org.transdroid.core.rssparser.Channel;
import org.transdroid.core.rssparser.Item;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
@ -33,9 +34,11 @@ public class RssitemsFragment extends SherlockFragment { @@ -33,9 +34,11 @@ public class RssitemsFragment extends SherlockFragment {
@InstanceState
protected Channel rssfeed = null;
@InstanceState
protected boolean hasError = false;
// Views
@ViewById(resName = "rssfeeds_list")
@ViewById(resName = "rssitems_list")
protected SherlockListView rssitemsList;
@Bean
protected RssitemsAdapter rssitemsAdapter;
@ -48,17 +51,34 @@ public class RssitemsFragment extends SherlockFragment { @@ -48,17 +51,34 @@ public class RssitemsFragment extends SherlockFragment {
// Set up the list adapter, which allows multi-select
rssitemsList.setAdapter(rssitemsAdapter);
rssitemsList.setMultiChoiceModeListener(onItemsSelected);
update(rssfeed);
update(rssfeed, hasError);
}
/**
* Update the shown RSS items in the list and the known last view date. This is automatically called when the
* fragment is instantiated by its build, but should be manually called if it was instantiated empty.
* @param rssfeed The RSS feed Channel object that was retrieved
* Update the shown RSS items in the list.
* @param channel The loaded RSS content channel object
* @param hasError True if there were errors in loading the channel, in which case an error text is shown; false
* otherwise
*/
public void update(Channel rssfeed) {
rssitemsAdapter.update(rssfeed);
public void update(Channel channel, boolean hasError) {
rssitemsAdapter.update(channel);
rssitemsList.setVisibility(View.GONE);
emptyText.setVisibility(View.VISIBLE);
if (hasError) {
emptyText.setText(R.string.rss_error);
return;
}
if (channel == null) {
emptyText.setText(R.string.rss_noselection);
return;
}
if (channel.getItems().size() == 0) {
emptyText.setText(R.string.rss_empty);
return;
}
rssitemsList.setVisibility(View.VISIBLE);
emptyText.setVisibility(View.INVISIBLE);
}
@ItemClick(resName = "rssitems_list")
@ -90,8 +110,7 @@ public class RssitemsFragment extends SherlockFragment { @@ -90,8 +110,7 @@ public class RssitemsFragment extends SherlockFragment {
List<Item> checked = new ArrayList<Item>();
for (int i = 0; i < rssitemsList.getCheckedItemPositions().size(); i++) {
if (rssitemsList.getCheckedItemPositions().valueAt(i))
checked.add(rssitemsAdapter.getItem(
rssitemsList.getCheckedItemPositions().keyAt(i)));
checked.add(rssitemsAdapter.getItem(rssitemsList.getCheckedItemPositions().keyAt(i)));
}
int itemId = item.getItemId();
@ -102,8 +121,8 @@ public class RssitemsFragment extends SherlockFragment { @@ -102,8 +121,8 @@ public class RssitemsFragment extends SherlockFragment {
String[] urls = new String[checked.size()];
String[] titles = new String[checked.size()];
for (int i = 0; i < checked.size(); i++) {
urls[i] = checked.get(0).getTheLink();
titles[i] = checked.get(0).getTitle();
urls[i] = checked.get(i).getTheLink();
titles[i] = checked.get(i).getTitle();
}
intent.putExtra("TORRENT_URLS", urls);
intent.putExtra("TORRENT_TITLES", titles);

1
core/src/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java

@ -30,6 +30,7 @@ public class WebsearchSettingsActivity extends KeyBoundPreferencesActivity { @@ -30,6 +30,7 @@ public class WebsearchSettingsActivity extends KeyBoundPreferencesActivity {
init(R.xml.pref_websearch, ApplicationSettings_.getInstance_(this).getMaxWebsearch());
initTextPreference("websearch_name");
initTextPreference("websearch_baseurl");
initTextPreference("websearch_cookies");
}

1
core/src/org/transdroid/core/rssparser/Channel.java

@ -137,6 +137,7 @@ public class Channel implements Parcelable { @@ -137,6 +137,7 @@ public class Channel implements Parcelable {
};
private Channel(Parcel in) {
this();
id = in.readInt();
title = in.readString();
link = in.readString();

6
core/src/org/transdroid/core/rssparser/HttpHelper.java

@ -110,7 +110,7 @@ public class HttpHelper { @@ -110,7 +110,7 @@ public class HttpHelper {
*
* Taken from http://senior.ceng.metu.edu.tr/2009/praeda/2009/01/11/a-simple-restful-client-at-android/
*/
public static String ConvertStreamToString(InputStream is, String encoding) throws UnsupportedEncodingException {
public static String convertStreamToString(InputStream is, String encoding) throws UnsupportedEncodingException {
InputStreamReader isr;
if (encoding != null) {
isr = new InputStreamReader(is, encoding);
@ -137,9 +137,9 @@ public class HttpHelper { @@ -137,9 +137,9 @@ public class HttpHelper {
return sb.toString();
}
public static String ConvertStreamToString(InputStream is) {
public static String convertStreamToString(InputStream is) {
try {
return ConvertStreamToString(is, null);
return convertStreamToString(is, null);
} catch (UnsupportedEncodingException e) {
// Since this is going to use the default encoding, it is never going to crash on an UnsupportedEncodingException
e.printStackTrace();

3
core/src/org/transdroid/core/rssparser/Item.java

@ -117,8 +117,7 @@ public class Item implements Parcelable { @@ -117,8 +117,7 @@ public class Item implements Parcelable {
* @return A single link URI to be used
*/
public Uri getTheLinkUri() {
// TODO Auto-generated method stub
return null;
return Uri.parse(getTheLink());
}
@Override

104
full/AndroidManifest.xml

@ -44,19 +44,105 @@ @@ -44,19 +44,105 @@
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<intent-filter>
<action android:name="org.transdroid.ADD_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:mimeType="application/x-bittorrent"
android:host="*"
android:scheme="http" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:pathPattern=".*\\.torrent"
android:host="*"
android:scheme="http" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:mimeType="application/x-bittorrent"
android:host="*"
android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:pathPattern=".*\\.torrent"
android:host="*"
android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:mimeType="application/x-bittorrent"
android:host="*"
android:scheme="file" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:pathPattern=".*\\.torrent"
android:host="*"
android:scheme="file" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/x-bittorrent" />
<data android:scheme="http" android:mimeType="application/x-bittorrent" />
<data android:scheme="http" android:pathPattern=".*\\.torrent" />
<data android:scheme="https" android:mimeType="application/x-bittorrent" />
<data android:scheme="https" android:pathPattern=".*\\.torrent" />
<data android:scheme="file" android:mimeType="application/x-bittorrent" />
<data android:scheme="file" android:pathPattern=".*\\.torrent" />
<data android:scheme="content" android:mimeType="application/x-bittorrent" />
<data android:scheme="content" android:pathPattern=".*\\.torrent" />
<data
android:mimeType="application/x-bittorrent"
android:host="*"
android:scheme="content" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:pathPattern=".*\\.torrent"
android:host="*"
android:scheme="content" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="magnet" />
</intent-filter>

10
lib/src/org/transdroid/daemon/BitComet/BitCometAdapter.java

@ -253,7 +253,7 @@ public class BitCometAdapter implements IDaemonAdapter { @@ -253,7 +253,7 @@ public class BitCometAdapter implements IDaemonAdapter {
// Read HTTP response
java.io.InputStream instream = entity.getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
instream.close();
// Return raw result
@ -288,7 +288,7 @@ public class BitCometAdapter implements IDaemonAdapter { @@ -288,7 +288,7 @@ public class BitCometAdapter implements IDaemonAdapter {
// Read BitComet response
java.io.InputStream instream = entity.getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
instream.close();
int idx = result.indexOf("save_path' value='")+18;
@ -307,7 +307,7 @@ public class BitCometAdapter implements IDaemonAdapter { @@ -307,7 +307,7 @@ public class BitCometAdapter implements IDaemonAdapter {
if (entity != null) {
// Check BitComet response
instream = entity.getContent();
result = HttpHelper.ConvertStreamToString(instream);
result = HttpHelper.convertStreamToString(instream);
instream.close();
if (result.indexOf("failed!") > 0) throw new Exception("Adding torrent file failed");
}
@ -340,7 +340,7 @@ public class BitCometAdapter implements IDaemonAdapter { @@ -340,7 +340,7 @@ public class BitCometAdapter implements IDaemonAdapter {
// Read BitComet response
java.io.InputStream instream = entity.getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
instream.close();
int idx = result.indexOf("save_path' value='")+18;
@ -364,7 +364,7 @@ public class BitCometAdapter implements IDaemonAdapter { @@ -364,7 +364,7 @@ public class BitCometAdapter implements IDaemonAdapter {
if (entity != null) {
// Check BitComet response
instream = entity.getContent();
result = HttpHelper.ConvertStreamToString(instream);
result = HttpHelper.convertStreamToString(instream);
instream.close();
if (result.indexOf("failed!") > 0) {
throw new Exception("Adding URL failed");

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

@ -155,7 +155,7 @@ public class BitfluAdapter implements IDaemonAdapter { @@ -155,7 +155,7 @@ public class BitfluAdapter implements IDaemonAdapter {
// Read JSON response
InputStream instream = response.getEntity().getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
int httpstatus = response.getStatusLine().getStatusCode();
if(httpstatus != 200) {

2
lib/src/org/transdroid/daemon/BuffaloNas/BuffaloNasAdapter.java

@ -178,7 +178,7 @@ public class BuffaloNasAdapter implements IDaemonAdapter { @@ -178,7 +178,7 @@ public class BuffaloNasAdapter implements IDaemonAdapter {
// Read JSON response
java.io.InputStream instream = entity.getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
instream.close();
// Return raw result

2
lib/src/org/transdroid/daemon/DLinkRouterBT/DLinkRouterBTAdapter.java

@ -273,7 +273,7 @@ public class DLinkRouterBTAdapter implements IDaemonAdapter { @@ -273,7 +273,7 @@ public class DLinkRouterBTAdapter implements IDaemonAdapter {
// Read JSON response
java.io.InputStream instream = entity.getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
JSONObject json = new JSONObject(result);
instream.close();

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

@ -182,7 +182,7 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -182,7 +182,7 @@ public class DelugeAdapter implements IDaemonAdapter {
// Read JSON response
InputStream instream = response.getEntity().getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
// If the upload succeeded, add the torrent file on the server
// For this we need the file name, which is now send as a JSON object like:
@ -477,7 +477,7 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -477,7 +477,7 @@ public class DelugeAdapter implements IDaemonAdapter {
// Still no session cookie?
if (sessionCookie == null) {
// Set error message and cancel the action that was requested
throw new DaemonException(ExceptionType.AuthenticationFailure, "Password error? Server time difference? No (valid) cookie in response and JSON was: " + HttpHelper.ConvertStreamToString(instream));
throw new DaemonException(ExceptionType.AuthenticationFailure, "Password error? Server time difference? No (valid) cookie in response and JSON was: " + HttpHelper.convertStreamToString(instream));
}
}
@ -509,7 +509,7 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -509,7 +509,7 @@ public class DelugeAdapter implements IDaemonAdapter {
// Read JSON response
InputStream instream = entity.getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
JSONObject json = new JSONObject(result);
instream.close();

6
lib/src/org/transdroid/daemon/Ktorrent/KtorrentAdapter.java

@ -293,7 +293,7 @@ public class KtorrentAdapter implements IDaemonAdapter { @@ -293,7 +293,7 @@ public class KtorrentAdapter implements IDaemonAdapter {
HttpGet httpget = new HttpGet(buildWebUIUrl() + RPC_URL_CHALLENGE);
HttpResponse response = httpclient.execute(httpget);
InputStream instream = response.getEntity().getContent();
String challengeString = HttpHelper.ConvertStreamToString(instream).replaceAll("\\<.*?>","").trim();
String challengeString = HttpHelper.convertStreamToString(instream).replaceAll("\\<.*?>","").trim();
instream.close();
// Challenge string should be something like TncpX3TB8uZ0h8eqztZ6
if (challengeString == null || challengeString.length() != 20) {
@ -358,7 +358,7 @@ public class KtorrentAdapter implements IDaemonAdapter { @@ -358,7 +358,7 @@ public class KtorrentAdapter implements IDaemonAdapter {
// Read response (a successful action always returned '1')
InputStream instream = response.getEntity().getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
instream.close();
if (result.contains(RPC_SUCCESS)) {
return true;
@ -407,7 +407,7 @@ public class KtorrentAdapter implements IDaemonAdapter { @@ -407,7 +407,7 @@ public class KtorrentAdapter implements IDaemonAdapter {
// Read response (a successful action always returned '1')
InputStream instream = response.getEntity().getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
instream.close();
if (result.equals("")) {
return true;

2
lib/src/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java

@ -306,7 +306,7 @@ public class QbittorrentAdapter implements IDaemonAdapter { @@ -306,7 +306,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
// Read JSON response
java.io.InputStream instream = entity.getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
instream.close();
//TLog.d(LOG_NAME, "Success: " + (result.length() > 300? result.substring(0, 300) + "... (" + result.length() + " chars)": result));

2
lib/src/org/transdroid/daemon/Synology/SynologyAdapter.java

@ -427,7 +427,7 @@ public class SynologyAdapter implements IDaemonAdapter { @@ -427,7 +427,7 @@ public class SynologyAdapter implements IDaemonAdapter {
}
// Read JSON response
java.io.InputStream instream = entity.getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
JSONObject json;
json = new JSONObject(result);
instream.close();

4
lib/src/org/transdroid/daemon/Tfb4rt/Tfb4rtAdapter.java

@ -195,7 +195,7 @@ public class Tfb4rtAdapter implements IDaemonAdapter { @@ -195,7 +195,7 @@ public class Tfb4rtAdapter implements IDaemonAdapter {
// Read response (a successful action always returned '1')
InputStream instream = response.getEntity().getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
instream.close();
if (result.trim().equals("1")) {
return true;
@ -232,7 +232,7 @@ public class Tfb4rtAdapter implements IDaemonAdapter { @@ -232,7 +232,7 @@ public class Tfb4rtAdapter implements IDaemonAdapter {
// Read response (a successful action always returned '1')
InputStream instream = response.getEntity().getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
instream.close();
if (result.equals("1")) {
return true;

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

@ -396,17 +396,20 @@ public class TransmissionAdapter implements IDaemonAdapter { @@ -396,17 +396,20 @@ public class TransmissionAdapter implements IDaemonAdapter {
}
// Execute
DLog.d(LOG_NAME, "Execute " + data.getString("method") + " request to " + httppost.getURI().toString());
HttpResponse response = httpclient.execute(httppost);
// Authentication error?
if (response.getStatusLine().getStatusCode() == 401) {
throw new DaemonException(ExceptionType.AuthenticationFailure, "401 HTTP response (username or password incorrect)");
throw new DaemonException(ExceptionType.AuthenticationFailure,
"401 HTTP response (username or password incorrect)");
}
// 409 error because of a session id?
if (response.getStatusLine().getStatusCode() == 409) {
// Retry post, but this time with the new session token that was encapsulated in the 409 response
DLog.d(LOG_NAME, "Receive HTTP 409 with new session code; now try again for the actual request");
sessionToken = response.getFirstHeader(sessionHeader).getValue();
httppost.addHeader(sessionHeader, sessionToken);
response = httpclient.execute(httppost);
@ -418,12 +421,13 @@ public class TransmissionAdapter implements IDaemonAdapter { @@ -418,12 +421,13 @@ public class TransmissionAdapter implements IDaemonAdapter {
// Read JSON response
java.io.InputStream instream = entity.getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
DLog.d(LOG_NAME,
"Received content response starting with "
+ (result.length() > 100 ? result.substring(0, 100) + "..." : result));
JSONObject json = new JSONObject(result);
instream.close();
//TLog.d(LOG_NAME, "Success: " + (result.length() > 200? result.substring(0, 200) + "... (" + result.length() + " chars)": result));
// Return the JSON object
return json;
}

6
lib/src/org/transdroid/daemon/Utorrent/UtorrentAdapter.java

@ -302,7 +302,7 @@ public class UtorrentAdapter implements IDaemonAdapter { @@ -302,7 +302,7 @@ public class UtorrentAdapter implements IDaemonAdapter {
// Read JSON response
InputStream instream = response.getEntity().getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
if ((result.equals("") || result.trim().equals("invalid request"))) {
authtoken = null;
throw new DaemonException(ExceptionType.AuthenticationFailure, "Response was '" + result.replace("\n", "") + "' instead of a proper JSON object (and we used auth token '" + authtoken + "')");
@ -341,7 +341,7 @@ public class UtorrentAdapter implements IDaemonAdapter { @@ -341,7 +341,7 @@ public class UtorrentAdapter implements IDaemonAdapter {
throw new DaemonException(ExceptionType.ConnectionError, "Not found (404); server doesn't exist or is inaccessible");
}
InputStream instream = response.getEntity().getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
authtoken = result.replaceAll("\\<.*?>","").trim();
}
@ -366,7 +366,7 @@ public class UtorrentAdapter implements IDaemonAdapter { @@ -366,7 +366,7 @@ public class UtorrentAdapter implements IDaemonAdapter {
// Read JSON response
InputStream instream = response.getEntity().getContent();
String result = HttpHelper.ConvertStreamToString(instream);
String result = HttpHelper.convertStreamToString(instream);
JSONObject json = new JSONObject(result);
instream.close();
return json;

77
lib/src/org/transdroid/daemon/util/HttpHelper.java

@ -15,13 +15,16 @@ @@ -15,13 +15,16 @@
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.transdroid.daemon.util;
package org.transdroid.daemon.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import org.apache.http.Header;
@ -51,11 +54,11 @@ import org.transdroid.daemon.DaemonException; @@ -51,11 +54,11 @@ import org.transdroid.daemon.DaemonException;
import org.transdroid.daemon.DaemonException.ExceptionType;
import org.transdroid.daemon.DaemonSettings;
import android.net.Uri;
/**
* Provides a set of general helper methods that can be used in web-based communication.
*
* @author erickok
*
*/
public class HttpHelper {
@ -71,19 +74,22 @@ public class HttpHelper { @@ -71,19 +74,22 @@ public class HttpHelper {
public static String userAgent = null;
/**
* Creates a standard Apache HttpClient that is thread safe, supports different
* SSL auth methods and basic authentication
* Creates a standard Apache HttpClient that is thread safe, supports different SSL auth methods and basic
* authentication
* @param settings The server settings to adhere
* @return An HttpClient that should be stored locally and reused for every new request
* @throws DaemonException Thrown when information (such as username/password) is missing
*/
public static DefaultHttpClient createStandardHttpClient(DaemonSettings settings, boolean userBasicAuth) throws DaemonException {
return createStandardHttpClient(userBasicAuth && settings.shouldUseAuthentication(), settings.getUsername(), settings.getPassword(), settings.getSslTrustAll(), settings.getSslTrustKey(), settings.getTimeoutInMilliseconds(), settings.getAddress(), settings.getPort());
public static DefaultHttpClient createStandardHttpClient(DaemonSettings settings, boolean userBasicAuth)
throws DaemonException {
return createStandardHttpClient(userBasicAuth && settings.shouldUseAuthentication(), settings.getUsername(),
settings.getPassword(), settings.getSslTrustAll(), settings.getSslTrustKey(),
settings.getTimeoutInMilliseconds(), settings.getAddress(), settings.getPort());
}
/**
* Creates a standard Apache HttpClient that is thread safe, supports different
* SSL auth methods and basic authentication
* Creates a standard Apache HttpClient that is thread safe, supports different SSL auth methods and basic
* authentication
* @param sslTrustAll Whether to trust all SSL certificates
* @param sslTrustkey A specific SSL key to accept exclusively
* @param timeout The connection timeout for all requests
@ -92,7 +98,9 @@ public class HttpHelper { @@ -92,7 +98,9 @@ public class HttpHelper {
* @return An HttpClient that should be stored locally and reused for every new request
* @throws DaemonException Thrown when information (such as username/password) is missing
*/
public static DefaultHttpClient createStandardHttpClient(boolean userBasicAuth, String username, String password, boolean sslTrustAll, String sslTrustkey, int timeout, String authAddress, int authPort) throws DaemonException {
public static DefaultHttpClient createStandardHttpClient(boolean userBasicAuth, String username, String password,
boolean sslTrustAll, String sslTrustkey, int timeout, String authAddress, int authPort)
throws DaemonException {
// Register http and https sockets
SchemeRegistry registry = new SchemeRegistry();
@ -109,12 +117,14 @@ public class HttpHelper { @@ -109,12 +117,14 @@ public class HttpHelper {
HttpProtocolParams.setUserAgent(httpparams, userAgent);
}
DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams, registry), httpparams);
DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams, registry),
httpparams);
// Authentication credentials
if (userBasicAuth) {
if (username == null || password == null) {
throw new DaemonException(ExceptionType.AuthenticationFailure, "No username or password was provided while we hadauthentication enabled");
throw new DaemonException(ExceptionType.AuthenticationFailure,
"No username or password was provided while we hadauthentication enabled");
}
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(authAddress, authPort, AuthScope.ANY_REALM),
@ -184,14 +194,13 @@ public class HttpHelper { @@ -184,14 +194,13 @@ public class HttpHelper {
}
/*
* To convert the InputStream to String we use the BufferedReader.readLine()
* method. We iterate until the BufferedReader return null which means
* there's no more data to read. Each line will appended to a StringBuilder
* To convert the InputStream to String we use the BufferedReader.readLine() method. We iterate until the
* BufferedReader return null which means there's no more data to read. Each line will appended to a StringBuilder
* and returned as String.
*
* Taken from http://senior.ceng.metu.edu.tr/2009/praeda/2009/01/11/a-simple-restful-client-at-android/
*/
public static String ConvertStreamToString(InputStream is, String encoding) throws UnsupportedEncodingException {
public static String convertStreamToString(InputStream is, String encoding) throws UnsupportedEncodingException {
InputStreamReader isr;
if (encoding != null) {
isr = new InputStreamReader(is, encoding);
@ -218,14 +227,44 @@ public class HttpHelper { @@ -218,14 +227,44 @@ public class HttpHelper {
return sb.toString();
}
public static String ConvertStreamToString(InputStream is) {
public static String convertStreamToString(InputStream is) {
try {
return ConvertStreamToString(is, null);
return convertStreamToString(is, null);
} catch (UnsupportedEncodingException e) {
// Since this is going to use the default encoding, it is never going to crash on an UnsupportedEncodingException
// Since this is going to use the default encoding, it is never going to crash on an
// UnsupportedEncodingException
e.printStackTrace();
return null;
}
}
/**
* Parses the individual parameters from a textual cookie representation-like string and returns them in an unsorted
* map. Inspired by Android's (API level 11+) getQueryParameterNames(Uri).
* @param raw A string of the form key1=value1;key2=value
* @return An unsorted, unmodifiable map of pairs of string keys and string values
*/
public static Map<String, String> parseCookiePairs(String raw) {
Map<String, String> pairs = new HashMap<String, String>();
int start = 0;
do {
int next = raw.indexOf(';', start);
int end = (next == -1) ? raw.length() : next;
int separator = raw.indexOf('=', start);
if (separator > end || separator == -1) {
separator = end;
}
String name = raw.substring(start, separator);
String value = raw.substring(separator + 1, end);
pairs.put(Uri.decode(name), Uri.decode(value));
start = end + 1;
} while (start < raw.length());
return Collections.unmodifiableMap(pairs);
}
}

101
lite/AndroidManifest.xml

@ -28,7 +28,8 @@ @@ -28,7 +28,8 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/system_name"
android:theme="@style/Theme.Sherlock" >
android:theme="@style/Theme.Sherlock"
android:hardwareAccelerated="true" >
<!-- Main activities -->
<activity
@ -44,11 +45,104 @@ @@ -44,11 +45,104 @@
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<intent-filter>
<action android:name="org.transdroid.ADD_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:mimeType="application/x-bittorrent"
android:scheme="http" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:pathPattern=".*\\.torrent"
android:scheme="http" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:mimeType="application/x-bittorrent"
android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:pathPattern=".*\\.torrent"
android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:mimeType="application/x-bittorrent"
android:scheme="file" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:pathPattern=".*\\.torrent"
android:scheme="file" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:mimeType="application/x-bittorrent"
android:scheme="content" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:pathPattern=".*\\.torrent"
android:scheme="content" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="magnet" />
</intent-filter>
</activity>
<activity
android:name="org.transdroid.core.gui.DetailsActivity_"
android:uiOptions="splitActionBarWhenNarrow"
android:theme="@style/TransdroidTheme" >
android:theme="@style/TransdroidTheme"
android:uiOptions="splitActionBarWhenNarrow" >
</activity>
<!-- Settings screens -->
@ -59,7 +153,6 @@ @@ -59,7 +153,6 @@
<activity android:name="org.transdroid.core.gui.settings.NotificationSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.settings.SystemSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.navigation.DialogHelper_" />
</application>
</manifest>
Loading…
Cancel
Save