Browse Source

Fixed #40 by adding a new local port option.

pull/82/head
Eric Kok 11 years ago
parent
commit
8a0e638698
  1. 1
      core/res/values/strings.xml
  2. 13
      core/res/xml/pref_server.xml
  3. 53
      core/src/org/transdroid/core/app/settings/ApplicationSettings.java
  4. 26
      core/src/org/transdroid/core/app/settings/ServerSetting.java
  5. 3
      core/src/org/transdroid/core/gui/settings/ServerSettingsActivity.java

1
core/res/values/strings.xml

@ -233,6 +233,7 @@
<string name="pref_advanced">Advanced settings</string> <string name="pref_advanced">Advanced settings</string>
<string name="pref_localaddress">Local IP or host</string> <string name="pref_localaddress">Local IP or host</string>
<string name="pref_localaddress_info">When connected to the specified local network</string> <string name="pref_localaddress_info">When connected to the specified local network</string>
<string name="pref_localport">Local port number</string>
<string name="pref_localnetwork">Local network</string> <string name="pref_localnetwork">Local network</string>
<string name="pref_localnetwork_info">The server\'s local network SSID</string> <string name="pref_localnetwork_info">The server\'s local network SSID</string>
<string name="pref_folder">Folder</string> <string name="pref_folder">Folder</string>

13
core/res/xml/pref_server.xml

@ -49,16 +49,21 @@
android:key="server_port" android:key="server_port"
android:title="@string/pref_port" android:title="@string/pref_port"
android:inputType="numberSigned" /> android:inputType="numberSigned" />
<EditTextPreference
android:key="server_localnetwork"
android:title="@string/pref_localnetwork"
android:summary="@string/pref_localnetwork_info"
android:inputType="textNoSuggestions" />
<EditTextPreference <EditTextPreference
android:key="server_localaddress" android:key="server_localaddress"
android:title="@string/pref_localaddress" android:title="@string/pref_localaddress"
android:summary="@string/pref_localaddress_info" android:summary="@string/pref_localaddress_info"
android:inputType="textUri" /> android:inputType="textUri" />
<EditTextPreference <EditTextPreference
android:key="server_localnetwork" android:key="server_localport"
android:title="@string/pref_localnetwork" android:title="@string/pref_localport"
android:summary="@string/pref_localnetwork_info" android:summary="@string/pref_localaddress_info"
android:inputType="textNoSuggestions" /> android:inputType="numberSigned" />
<CheckBoxPreference <CheckBoxPreference
android:key="server_disableauth" android:key="server_disableauth"
android:title="@string/pref_disableauth" android:title="@string/pref_disableauth"

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

@ -96,19 +96,34 @@ public class ApplicationSettings {
String port = prefs.getString("server_port_" + order, ""); String port = prefs.getString("server_port_" + order, "");
if (port.equals("")) if (port.equals(""))
port = Integer.toString(Daemon.getDefaultPortNumber(type, ssl)); port = Integer.toString(Daemon.getDefaultPortNumber(type, ssl));
String localPort = prefs.getString("server_localport_" + order, "");
return new ServerSetting(order, prefs.getString("server_name_" + order, null), type, prefs.getString( if (localPort.equals(""))
"server_address_" + order, null), prefs.getString("server_localaddress_" + order, null), localPort = port; // Default to the normal (non-local) port
prefs.getString("server_localnetwork_" + order, null), Integer.parseInt(port), ssl, prefs.getBoolean(
"server_ssltrustall_" + order, false), prefs.getString("server_ssltrustkey_" + order, null), return new ServerSetting(order,
prefs.getString("server_name_" + order, null),
type,
prefs.getString("server_address_" + order, null),
prefs.getString("server_localaddress_" + order, null),
Integer.parseInt(localPort),
prefs.getString("server_localnetwork_" + order, null),
Integer.parseInt(port),
ssl,
prefs.getBoolean("server_ssltrustall_" + order, false),
prefs.getString("server_ssltrustkey_" + order, null),
prefs.getString("server_folder_" + order, null), prefs.getString("server_folder_" + order, null),
!prefs.getBoolean("server_disableauth_" + order, false), prefs.getString("server_user_" + order, null), !prefs.getBoolean("server_disableauth_" + order, false),
prefs.getString("server_pass_" + order, null), prefs.getString("server_extrapass_" + order, null), prefs.getString("server_user_" + order, null),
OS.fromCode(prefs.getString("server_os_" + order, "type_linux")), prefs.getString("server_downloaddir_" prefs.getString("server_pass_" + order, null),
+ order, null), prefs.getString("server_ftpurl_" + order, null), prefs.getString( prefs.getString("server_extrapass_" + order, null),
"server_ftppass_" + order, null), Integer.parseInt(prefs.getString("server_timeout_" + order, OS.fromCode(prefs.getString("server_os_" + order, "type_linux")),
"8")), prefs.getBoolean("server_alarmfinished_" + order, true), prefs.getBoolean( prefs.getString("server_downloaddir_" + order, null),
"server_alarmnew_" + order, false), false); 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 // @formatter:on
} }
@ -251,8 +266,10 @@ public class ApplicationSettings {
*/ */
public WebsearchSetting getWebsearchSetting(int order) { public WebsearchSetting getWebsearchSetting(int order) {
// @formatter:off // @formatter:off
return new WebsearchSetting(order, prefs.getString("websearch_name_" + order, null), prefs.getString( return new WebsearchSetting(order,
"websearch_baseurl_" + order, null), prefs.getString("websearch_cookies_" + order, null)); prefs.getString("websearch_name_" + order, null),
prefs.getString("websearch_baseurl_" + order, null),
prefs.getString("websearch_cookies_" + order, null));
// @formatter:on // @formatter:on
} }
@ -313,9 +330,11 @@ public class ApplicationSettings {
public RssfeedSetting getRssfeedSetting(int order) { public RssfeedSetting getRssfeedSetting(int order) {
// @formatter:off // @formatter:off
long lastViewed = prefs.getLong("rssfeed_lastviewed_" + order, -1); long lastViewed = prefs.getLong("rssfeed_lastviewed_" + order, -1);
return new RssfeedSetting(order, prefs.getString("rssfeed_name_" + order, null), prefs.getString("rssfeed_url_" return new RssfeedSetting(order,
+ order, null), prefs.getBoolean("rssfeed_reqauth_" + order, false), lastViewed == -1L ? null prefs.getString("rssfeed_name_" + order, null),
: new Date(lastViewed)); prefs.getString("rssfeed_url_" + order, null),
prefs.getBoolean("rssfeed_reqauth_" + order, false),
lastViewed == -1L ? null : new Date(lastViewed));
// @formatter:on // @formatter:on
} }

26
core/src/org/transdroid/core/app/settings/ServerSetting.java

@ -40,6 +40,7 @@ public class ServerSetting implements SimpleListItem {
private final Daemon type; private final Daemon type;
private final String address; private final String address;
private final String localAddress; private final String localAddress;
private final int localPort;
private final String localNetwork; private final String localNetwork;
private final int port; private final int port;
private final String folder; private final String folder;
@ -65,6 +66,7 @@ public class ServerSetting implements SimpleListItem {
* @param type The server daemon type * @param type The server daemon type
* @param address The server domain name or IP address * @param address The server domain name or IP address
* @param localAddress The server domain or IP address when connected to the server's local network * @param localAddress The server domain or IP address when connected to the server's local network
* @param localPort The port on which the server is running in the server's local network
* @param localNetwork The server's local network SSID * @param localNetwork The server's local network SSID
* @param port The port on which the server daemon is running * @param port The port on which the server daemon is running
* @param sslTrustKey The specific key that will be accepted. * @param sslTrustKey The specific key that will be accepted.
@ -78,16 +80,17 @@ public class ServerSetting implements SimpleListItem {
* @param timeout The number of seconds to wait before timing out a connection attempt * @param timeout The number of seconds to wait before timing out a connection attempt
* @param isAutoGenerated Whether this setting was generated rather than manually inputed by the user * @param isAutoGenerated Whether this setting was generated rather than manually inputed by the user
*/ */
public ServerSetting(int key, String name, Daemon type, String address, String localAddress, String localNetwork, public ServerSetting(int key, String name, Daemon type, String address, String localAddress, int localPort,
int port, boolean ssl, boolean sslTrustAll, String sslTrustKey, String folder, boolean useAuthentication, String localNetwork, int port, boolean ssl, boolean sslTrustAll, String sslTrustKey, String folder,
String username, String password, String extraPass, OS os, String downloadDir, String ftpUrl, boolean useAuthentication, String username, String password, String extraPass, OS os, String downloadDir,
String ftpPassword, int timeout, boolean alarmOnFinishedDownload, boolean alarmOnNewTorrent, String ftpUrl, String ftpPassword, int timeout, boolean alarmOnFinishedDownload, boolean alarmOnNewTorrent,
boolean isAutoGenerated) { boolean isAutoGenerated) {
this.key = key; this.key = key;
this.name = name; this.name = name;
this.type = type; this.type = type;
this.address = address; this.address = address;
this.localAddress = localAddress; this.localAddress = localAddress;
this.localPort = localPort;
this.localNetwork = localNetwork; this.localNetwork = localNetwork;
this.port = port; this.port = port;
this.ssl = ssl; this.ssl = ssl;
@ -131,6 +134,10 @@ public class ServerSetting implements SimpleListItem {
return localAddress; return localAddress;
} }
public int getLocalPort() {
return localPort;
}
public String getLocalNetwork() { public String getLocalNetwork() {
return localNetwork; return localNetwork;
} }
@ -254,7 +261,7 @@ public class ServerSetting implements SimpleListItem {
* Returns the appropriate daemon adapter to which tasks can be executed, in accordance with this server's settings * Returns the appropriate daemon adapter to which tasks can be executed, in accordance with this server's settings
* @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not * @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not
* be determined * be determined
* @param context * @param context
* @return An IDaemonAdapter instance of the specific torrent client daemon type * @return An IDaemonAdapter instance of the specific torrent client daemon type
*/ */
public IDaemonAdapter createServerAdapter(String connectedToNetwork, Context context) { public IDaemonAdapter createServerAdapter(String connectedToNetwork, Context context) {
@ -276,9 +283,10 @@ public class ServerSetting implements SimpleListItem {
Log.d(caller, "Creating adapter for " + name + " of type " + type.name() + ": connected to " Log.d(caller, "Creating adapter for " + name + " of type " + type.name() + ": connected to "
+ connectedToNetwork + " and configured local network is " + localNetwork); + connectedToNetwork + " and configured local network is " + localNetwork);
return new DaemonSettings(name, type, return new DaemonSettings(name, type,
connectedToNetwork != null && connectedToNetwork.equals(localNetwork) ? localAddress : address, port, connectedToNetwork != null && connectedToNetwork.equals(localNetwork) ? localAddress : address,
ssl, sslTrustAll, sslTrustKey, folder, useAuthentication, username, password, extraPass, os, connectedToNetwork != null && connectedToNetwork.equals(localNetwork) ? localPort : port, ssl,
downloadDir, ftpUrl, ftpPassword, timeout, alarmOnFinishedDownload, alarmOnNewTorrent, sslTrustAll, sslTrustKey, folder, useAuthentication, username, password, extraPass, os, downloadDir,
Integer.toString(key), isAutoGenerated); ftpUrl, ftpPassword, timeout, alarmOnFinishedDownload, alarmOnNewTorrent, Integer.toString(key),
isAutoGenerated);
} }
} }

3
core/src/org/transdroid/core/gui/settings/ServerSettingsActivity.java

@ -57,8 +57,9 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
initTextPreference("server_user"); initTextPreference("server_user");
initTextPreference("server_pass"); initTextPreference("server_pass");
extraPass = initTextPreference("server_extrapass"); extraPass = initTextPreference("server_extrapass");
initTextPreference("server_localaddress");
initTextPreference("server_localnetwork"); initTextPreference("server_localnetwork");
initTextPreference("server_localaddress");
initTextPreference("server_localport");
folder = initTextPreference("server_folder"); folder = initTextPreference("server_folder");
initTextPreference("server_timeout", "8"); initTextPreference("server_timeout", "8");
initBooleanPreference("server_alarmfinished", true); initBooleanPreference("server_alarmfinished", true);

Loading…
Cancel
Save