Browse Source

Added import and export of settings (Transdroid 1.x settings can be imported too).

pull/11/head
Eric Kok 11 years ago
parent
commit
4ff57b7010
  1. 1
      core/res/values/changelog.xml
  2. 7
      core/res/values/strings.xml
  3. 5
      core/src/org/transdroid/core/app/settings/ApplicationSettings.java
  4. 5
      core/src/org/transdroid/core/app/settings/RssfeedSetting.java
  5. 264
      core/src/org/transdroid/core/app/settings/SettingsPersistence.java
  6. 13
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  7. 89
      core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java
  8. 45
      lib/src/org/transdroid/daemon/Daemon.java
  9. 15
      lib/src/org/transdroid/daemon/OS.java

1
core/res/values/changelog.xml

@ -4,7 +4,6 @@ @@ -4,7 +4,6 @@
Transdroid 2.0.0-alpha1\n
- Totally reworked Holo-style interface\n
- Provide tablet interface on smaller tablets\n
- Automatically switch between local and remote IP configurations\n
\n
Older changes: http://www.transdroid.org/about/changelog/
</string>

7
core/res/values/strings.xml

@ -175,7 +175,11 @@ @@ -175,7 +175,11 @@
<string name="pref_usedarktheme">Use dark UI theme</string>
<string name="pref_usedarktheme_info">Requires a restart to take effect</string>
<string name="pref_import">Import settings</string>
<string name="pref_import_dialog">Transdroid will try to import server, web search, RSS and system settings from: %1$s</string>
<string name="pref_import_success">Settings successfully imported</string>
<string name="pref_export">Export settings</string>
<string name="pref_export_dialog">Transdroid will export server (including passwords), web search, RSS and system settings to the following plain text JSON file: %1$s</string>
<string name="pref_export_success">Settings successfully exported</string>
<string name="pref_sendlog">Send error log</string>
<string name="pref_sendlog_info">Get support or report a bug</string>
<string name="pref_installhelp">View install guides</string>
@ -259,7 +263,8 @@ @@ -259,7 +263,8 @@
<string name="error_norssfeed">URL is not a (valid) RSS feed</string>
<string name="error_media_not_available">SD card not available to read/write</string>
<string name="error_no_valid_settings_file">File does not seem to contain Transdroid settings</string>
<string name="error_file_not_found">There is no settings file found</string>
<string name="error_file_not_found">The settings file could not be found</string>
<string name="error_cant_write_settings_file">Can\'t write to the settings file</string>
<string name="system_name" translatable="false">Transdroid</string>
<string name="system_developer" translatable="false">\u00A9 Eric Kok, 2312 development</string>

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

@ -291,7 +291,8 @@ public class ApplicationSettings { @@ -291,7 +291,8 @@ public class ApplicationSettings {
return new RssfeedSetting(order,
prefs.getString("rssfeed_name_" + order, null),
prefs.getString("rssfeed_url_" + order, null),
prefs.getBoolean("rssfeed_reqauth_" + order, false));
prefs.getBoolean("rssfeed_reqauth_" + order, false),
prefs.getString("rssfeed_lastnew_" + order, null));
// @formatter:on
}
@ -311,12 +312,14 @@ public class ApplicationSettings { @@ -311,12 +312,14 @@ public class ApplicationSettings {
edit.putString("rssfeed_name_" + i, prefs.getString("rssfeed_name_" + (i + 1), null));
edit.putString("rssfeed_url_" + i, prefs.getString("rssfeed_url_" + (i + 1), null));
edit.putBoolean("rssfeed_reqauth_" + i, prefs.getBoolean("rssfeed_reqauth_" + (i + 1), false));
edit.putString("rssfeed_lastnew_" + i, prefs.getString("rssfeed_lastnew_" + (i + 1), null));
}
// Remove the last settings, of which we are now sure are no longer required
edit.remove("rssfeed_name_" + max);
edit.remove("rssfeed_url_" + max);
edit.remove("rssfeed_reqauth_" + max);
edit.remove("rssfeed_lastnew_" + max);
edit.commit();
}

5
core/src/org/transdroid/core/app/settings/RssfeedSetting.java

@ -19,12 +19,12 @@ public class RssfeedSetting implements SimpleListItem { @@ -19,12 +19,12 @@ public class RssfeedSetting implements SimpleListItem {
private final boolean requiresAuth;
private String lastNew;
public RssfeedSetting(int order, String name, String baseUrl, boolean needsAuth) {
public RssfeedSetting(int order, String name, String baseUrl, boolean needsAuth, String lastNew) {
this.order = order;
this.name = name;
this.url = baseUrl;
this.requiresAuth = needsAuth;
this.lastNew = null;
this.lastNew = lastNew;
}
public int getOrder() {
@ -55,6 +55,7 @@ public class RssfeedSetting implements SimpleListItem { @@ -55,6 +55,7 @@ public class RssfeedSetting implements SimpleListItem {
* @return The last new item's URL as URL-encoded string
*/
public String getLastNew() {
// TODO: Persist this into Preferences
return this.lastNew;
}

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

@ -0,0 +1,264 @@ @@ -0,0 +1,264 @@
package org.transdroid.core.app.settings;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.EBean.Scope;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.transdroid.daemon.util.HttpHelper;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Environment;
@EBean(scope = Scope.Singleton)
public class SettingsPersistence {
@Bean
protected ApplicationSettings applicationSettings;
@Bean
protected SystemSettings systemSettings;
public static final String DEFAULT_SETTINGS_DIR = Environment.getExternalStorageDirectory().toString()
+ "/Transdroid";
public static final String DEFAULT_SETTINGS_FILENAME = "/settings.json";
public static final File DEFAULT_SETTINGS_FILE = new File(DEFAULT_SETTINGS_DIR + DEFAULT_SETTINGS_FILENAME);
/**
* Synchronously reads the server, web searches, RSS feed, background service and system settings from a file in
* JSON format.
* @param settingsFile The local file to write the settings to
* @throws FileNotFoundException Thrown when the settings file doesn't exist or couln't be read
* @throws JSONException Thrown when the file did not contain valid JSON content
*/
public void importSettings(SharedPreferences prefs, File settingsFile) throws FileNotFoundException,
JSONException {
Editor editor = prefs.edit();
// Read the settings file
String raw = HttpHelper.ConvertStreamToString(new FileInputStream(settingsFile));
JSONObject json = new JSONObject(raw);
// Import servers
if (json.has("servers")) {
JSONArray servers = json.getJSONArray("servers");
for (int i = 0; i < servers.length(); i++) {
JSONObject server = servers.getJSONObject(i);
String postfix = Integer.toString(applicationSettings.getMaxServer() + 1 + i);
if (server.has("name"))
editor.putString("server_name_" + postfix, server.getString("name"));
if (server.has("type"))
editor.putString("server_type_" + postfix, server.getString("type"));
if (server.has("host"))
editor.putString("server_address_" + postfix, server.getString("host"));
if (server.has("local_network"))
editor.putString("server_localnetwork_" + postfix, server.getString("local_network"));
if (server.has("local_host"))
editor.putString("server_localaddress_" + postfix, server.getString("local_host"));
if (server.has("port"))
editor.putString("server_port_" + postfix, server.getString("port"));
if (server.has("ssl"))
editor.putBoolean("server_sslenabled_" + postfix, server.getBoolean("ssl"));
if (server.has("ssl_accept_all"))
editor.putBoolean("server_ssltrustall_" + postfix, server.getBoolean("ssl_accept_all"));
if (server.has("ssl_trust_key"))
editor.putString("server_ssltrustkey_" + postfix, server.getString("ssl_trust_key"));
if (server.has("folder"))
editor.putString("server_folder_" + postfix, server.getString("folder"));
if (server.has("use_auth"))
editor.putBoolean("server_useauth_" + postfix, server.getBoolean("use_auth"));
if (server.has("username"))
editor.putString("server_user_" + postfix, server.getString("username"));
if (server.has("password"))
editor.putString("server_pass_" + postfix, server.getString("password"));
if (server.has("extra_password"))
editor.putString("server_extrapass_" + postfix, server.getString("extra_password"));
if (server.has("os_type"))
editor.putString("server_os_" + postfix, server.getString("os_type"));
if (server.has("downloads_dir"))
editor.putString("server_downloaddir_" + postfix, server.getString("downloads_dir"));
if (server.has("base_ftp_url"))
editor.putString("server_ftpurl_" + postfix, server.getString("base_ftp_url"));
if (server.has("ftp_password"))
editor.putString("server_ftppass_" + postfix, server.getString("ftp_password"));
if (server.has("server_timeout"))
editor.putString("server_timeout_" + postfix, server.getString("server_timeout"));
if (server.has("download_alarm"))
editor.putBoolean("server_alarmfinished_" + postfix, server.getBoolean("download_alarm"));
if (server.has("new_torrent_alarm"))
editor.putBoolean("server_alarmnew_" + postfix, server.getBoolean("new_torrent_alarm"));
}
}
// Import web search sites
if (json.has("websites")) {
JSONArray sites = json.getJSONArray("websites");
for (int i = 0; i < sites.length(); i++) {
JSONObject site = sites.getJSONObject(i);
String postfix = Integer.toString(applicationSettings.getMaxWebsearch() + 1 + i);
if (site.has("name"))
editor.putString("websearch_name_" + postfix, site.getString("name"));
if (site.has("url"))
editor.putString("websearch_baseurl_" + postfix, site.getString("url"));
}
}
// Import RSS feeds
if (json.has("rssfeeds")) {
JSONArray feeds = json.getJSONArray("rssfeeds");
for (int i = 0; i < feeds.length(); i++) {
JSONObject feed = feeds.getJSONObject(i);
String postfix = Integer.toString(applicationSettings.getMaxRssfeed() + 1 + i);
if (feed.has("name"))
editor.putString("rssfeed_name_" + postfix, feed.getString("name"));
if (feed.has("url"))
editor.putString("rssfeed_url_" + postfix, feed.getString("url"));
if (feed.has("needs_auth"))
editor.putBoolean("rssfeed_reqauth_" + postfix, feed.getBoolean("needs_auth"));
if (feed.has("last_seen"))
editor.putString("rssfeed_lastnew_" + postfix, feed.getString("last_seen"));
}
}
// Import background service and system settings
if (json.has("alarm_enabled"))
editor.putBoolean("notifications_enabled", json.getBoolean("alarm_enabled"));
if (json.has("alarm_interval"))
editor.putString("notifications_interval", json.getString("alarm_interval"));
if (json.has("alarm_sound_uri"))
editor.putString("notifications_sound", json.getString("alarm_sound_uri"));
if (json.has("alarm_vibrate"))
editor.putBoolean("notifications_vibrate", json.getBoolean("alarm_vibrate"));
if (json.has("alarm_ledcolour"))
editor.putInt("notifications_ledcolour", json.getInt("alarm_ledcolour"));
if (json.has("alarm_adwnotifications"))
editor.putBoolean("notifications_adwnotify", json.getBoolean("alarm_adwnotifications"));
if (json.has("system_checkupdates"))
editor.putBoolean("system_checkupdates", json.getBoolean("system_checkupdates"));
if (json.has("system_usedarktheme"))
editor.putBoolean("system_usedarktheme", json.getBoolean("system_usedarktheme"));
editor.commit();
}
/**
* Synchronously writes the server, web searches, RSS feed, background service and system settings to a file in JSON
* format.
* @param prefs The application-global preferences object to write settings to
* @param settingsFile The local file to read the settings from
* @throws JSONException Thrown when the JSON content could not be constructed properly
* @throws IOException Thrown when the settings file could not be created or written to
*/
public void exportSettings(SharedPreferences prefs, File settingsFile) throws JSONException, IOException {
// Create a single JSON object that will contain all settings
JSONObject json = new JSONObject();
// Convert server settings into JSON
JSONArray servers = new JSONArray();
int i = 0;
String postfixi = "0";
while (prefs.contains("server_type_" + postfixi)) {
JSONObject server = new JSONObject();
server.put("name", prefs.getString("server_name_" + postfixi, null));
server.put("type", prefs.getString("server_type_" + postfixi, null));
server.put("host", prefs.getString("server_address_" + postfixi, null));
server.put("local_network", prefs.getString("server_localnetwork_" + postfixi, null));
server.put("local_host", prefs.getString("server_localaddress_" + postfixi, null));
server.put("port", prefs.getString("server_port_" + postfixi, null));
server.put("ssl", prefs.getBoolean("server_sslenabled_" + postfixi, false));
server.put("ssl_accept_all", prefs.getBoolean("server_ssltrustall_" + postfixi, false));
server.put("ssl_trust_key", prefs.getString("server_ssltrustkey_" + postfixi, null));
server.put("folder", prefs.getString("server_folder_" + postfixi, null));
server.put("use_auth", prefs.getBoolean("server_useauth_" + postfixi, true));
server.put("username", prefs.getString("server_user_" + postfixi, null));
server.put("password", prefs.getString("server_pass_" + postfixi, null));
server.put("extra_password", prefs.getString("server_extrapass_" + postfixi, null));
server.put("os_type", prefs.getString("server_os_" + postfixi, null));
server.put("downloads_dir", prefs.getString("server_downloaddir_" + postfixi, null));
server.put("base_ftp_url", prefs.getString("server_ftpurl_" + postfixi, null));
server.put("ftp_password", prefs.getString("server_ftppass_" + postfixi, null));
server.put("server_timeout", prefs.getString("server_ftppass_" + postfixi, null));
server.put("download_alarm", prefs.getBoolean("server_alarmfinished_" + postfixi, false));
server.put("new_torrent_alarm", prefs.getBoolean("server_alarmnew_" + postfixi, false));
servers.put(server);
i++;
postfixi = Integer.toString(i);
}
json.put("servers", servers);
// Convert web search settings into JSON
JSONArray sites = new JSONArray();
int j = 0;
String postfixj = "0";
while (prefs.contains("websearch_baseurl_" + postfixj)) {
JSONObject site = new JSONObject();
site.put("name", prefs.getString("websearch_name_" + postfixj, null));
site.put("url", prefs.getString("websearch_baseurl_" + postfixj, null));
sites.put(site);
j++;
postfixj = Integer.toString(j);
}
json.put("websites", sites);
// Convert RSS feed settings into JSON
JSONArray feeds = new JSONArray();
int k = 0;
String postfixk = "0";
while (prefs.contains("rssfeed_url_" + postfixk)) {
JSONObject feed = new JSONObject();
feed.put("name", prefs.getString("rssfeed_name_" + postfixk, null));
feed.put("url", prefs.getString("rssfeed_url_" + postfixk, null));
feed.put("needs_auth", prefs.getBoolean("rssfeed_reqauth_" + postfixk, false));
feed.put("last_seen", prefs.getString("rssfeed_lastnew_" + postfixk, null));
feeds.put(feed);
k++;
postfixk = Integer.toString(k);
}
json.put("rssfeeds", feeds);
// Convert background service and system settings into JSON
json.put("alarm_enabled", prefs.getBoolean("notifications_enabled", true));
json.put("alarm_interval", prefs.getString("notifications_interval", null));
json.put("alarm_sound_uri", prefs.getString("notifications_sound", null));
json.put("alarm_vibrate", prefs.getBoolean("notifications_vibrate", false));
json.put("alarm_ledcolour", prefs.getInt("notifications_ledcolour", -1));
json.put("alarm_adwnotifications", prefs.getBoolean("notifications_adwnotify", false));
json.put("system_checkupdates", prefs.getBoolean("system_checkupdates", true));
json.put("system_usedarktheme", prefs.getBoolean("system_usedarktheme", false));
// Serialise the JSON object to a file
if (settingsFile.exists()) {
settingsFile.delete();
}
settingsFile.getParentFile().mkdirs();
settingsFile.createNewFile();
FileWriter writer = new FileWriter(settingsFile);
writer.write(json.toString(2));
writer.flush();
writer.close();
}
}

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

@ -21,16 +21,11 @@ import org.androidannotations.annotations.UiThread; @@ -21,16 +21,11 @@ import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R;
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.*;
import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.lists.SimpleListItem;
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.log.*;
import org.transdroid.core.gui.navigation.*;
import org.transdroid.core.gui.navigation.Label;
import org.transdroid.core.gui.navigation.NavigationFilter;
import org.transdroid.core.gui.navigation.NavigationHelper;
@ -38,7 +33,7 @@ import org.transdroid.core.gui.navigation.StatusType; @@ -38,7 +33,7 @@ import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.search.BarcodeHelper;
import org.transdroid.core.gui.search.FilePickerHelper;
import org.transdroid.core.gui.search.UrlEntryDialog;
import org.transdroid.core.gui.settings.MainSettingsActivity_;
import org.transdroid.core.gui.settings.*;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Torrent;

89
core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java

@ -1,46 +1,65 @@ @@ -1,46 +1,65 @@
package org.transdroid.core.gui.settings;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem;
import org.json.JSONException;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.SettingsPersistence;
import org.transdroid.core.gui.log.ErrorLogSender;
import org.transdroid.core.gui.navigation.DialogHelper;
import org.transdroid.core.gui.navigation.NavigationHelper;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceManager;
import com.actionbarsherlock.app.SherlockPreferenceActivity;
import de.keyboardsurfer.android.widget.crouton.Crouton;
@EActivity
public class SystemSettingsActivity extends SherlockPreferenceActivity {
protected static final int DIALOG_CHANGELOG = 0;
protected static final int DIALOG_ABOUT = 1;
protected static final int DIALOG_IMPORTSETTINGS = 2;
protected static final int DIALOG_EXPORTSETTINGS = 3;
protected static final String INSTALLHELP_URI = "http://www.transdroid.org/download/";
@Bean
protected NavigationHelper navigationHelper;
@Bean
protected ApplicationSettings applicationSettings;
@Bean
protected ErrorLogSender errorLogSender;
@Bean
protected SettingsPersistence settingsPersistence;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Just load the system-related preferences from XML
addPreferencesFromResource(R.xml.pref_system);
// Handle outgoing links
findPreference("system_sendlog").setOnPreferenceClickListener(onSendLogClick);
findPreference("system_installhelp").setOnPreferenceClickListener(onInstallHelpClick);
@ -73,21 +92,23 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity { @@ -73,21 +92,23 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity {
};
private OnPreferenceClickListener onImportSettingsClick = new OnPreferenceClickListener() {
@SuppressWarnings("deprecation")
@Override
public boolean onPreferenceClick(Preference preference) {
// TODO: Allow import of settings
showDialog(DIALOG_IMPORTSETTINGS);
return true;
}
};
private OnPreferenceClickListener onExportSettingsClick = new OnPreferenceClickListener() {
@SuppressWarnings("deprecation")
@Override
public boolean onPreferenceClick(Preference preference) {
// TODO: Allow export of settings
showDialog(DIALOG_EXPORTSETTINGS);
return true;
}
};
private OnPreferenceClickListener onChangeLogClick = new OnPreferenceClickListener() {
@SuppressWarnings("deprecation")
@Override
@ -105,15 +126,67 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity { @@ -105,15 +126,67 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity {
return true;
}
};
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_CHANGELOG:
return DialogHelper.showDialog(this, new ChangelogDialog());
case DIALOG_ABOUT:
return DialogHelper.showDialog(this, new AboutDialog());
case DIALOG_IMPORTSETTINGS:
// @formatter:off
return new AlertDialog.Builder(this)
.setMessage(
getString(R.string.pref_import_dialog, SettingsPersistence.DEFAULT_SETTINGS_FILE.toString()))
.setPositiveButton(android.R.string.ok, importSettings)
.setNegativeButton(android.R.string.cancel, null).create();
// @formatter:on
case DIALOG_EXPORTSETTINGS:
// @formatter:off
return new AlertDialog.Builder(this)
.setMessage(
getString(R.string.pref_export_dialog, SettingsPersistence.DEFAULT_SETTINGS_FILE.toString()))
.setPositiveButton(android.R.string.ok, exportSettings)
.setNegativeButton(android.R.string.cancel, null).create();
// @formatter:on
}
return null;
}
private OnClickListener importSettings = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SystemSettingsActivity.this);
try {
settingsPersistence.importSettings(prefs, SettingsPersistence.DEFAULT_SETTINGS_FILE);
Crouton.showText(SystemSettingsActivity.this, R.string.pref_import_success,
navigationHelper.CROUTON_INFO_STYLE);
} catch (FileNotFoundException e) {
Crouton.showText(SystemSettingsActivity.this, R.string.error_file_not_found,
navigationHelper.CROUTON_ERROR_STYLE);
} catch (JSONException e) {
Crouton.showText(SystemSettingsActivity.this, R.string.error_no_valid_settings_file,
navigationHelper.CROUTON_ERROR_STYLE);
}
}
};
private OnClickListener exportSettings = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SystemSettingsActivity.this);
try {
settingsPersistence.exportSettings(prefs, SettingsPersistence.DEFAULT_SETTINGS_FILE);
Crouton.showText(SystemSettingsActivity.this, R.string.pref_export_success,
navigationHelper.CROUTON_INFO_STYLE);
} catch (JSONException e) {
Crouton.showText(SystemSettingsActivity.this, R.string.error_cant_write_settings_file,
navigationHelper.CROUTON_ERROR_STYLE);
} catch (IOException e) {
Crouton.showText(SystemSettingsActivity.this, R.string.error_cant_write_settings_file,
navigationHelper.CROUTON_ERROR_STYLE);
}
}
};
}

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

@ -105,6 +105,45 @@ public enum Daemon { @@ -105,6 +105,45 @@ public enum Daemon {
};
public abstract IDaemonAdapter createAdapter(DaemonSettings settings);
/**
* Returns the code as used in preferences matching the given daemon type
* @return A string of the form 'daemon_<type>' that represents the daemon's enum value
*/
public static String toCode(Daemon type) {
if (type == null)
return null;
switch (type) {
case BitComet:
return "daemon_bitcomet";
case Bitflu:
return "daemon_bitflue";
case BitTorrent:
return "daemon_bittorrent";
case BuffaloNas:
return "daemon_buffalonas";
case Deluge:
return "daemon_deluge";
case DLinkRouterBT:
return "daemon_dlinkrouterbt";
case KTorrent:
return "daemon_ktorrent";
case qBittorrent:
return "daemon_qbittorrent";
case rTorrent:
return "daemon_rtorrent";
case Tfb4rt:
return "daemon_tfb4rt";
case Transmission:
return "daemon_transmission";
case uTorrent:
return "daemon_utorrent";
case Vuze:
return "daemon_vuze";
default:
return null;
}
}
/**
* Returns the daemon enum type based on the code used in the user preferences.
@ -115,6 +154,9 @@ public enum Daemon { @@ -115,6 +154,9 @@ public enum Daemon {
if (daemonCode == null) {
return null;
}
if (daemonCode.equals("daemon_bitcomet")) {
return BitComet;
}
if (daemonCode.equals("daemon_bitflu")) {
return Bitflu;
}
@ -151,9 +193,6 @@ public enum Daemon { @@ -151,9 +193,6 @@ public enum Daemon {
if (daemonCode.equals("daemon_vuze")) {
return Vuze;
}
if (daemonCode.equals("daemon_bitcomet")) {
return BitComet;
}
return null;
}

15
lib/src/org/transdroid/daemon/OS.java

@ -12,6 +12,21 @@ public enum OS { @@ -12,6 +12,21 @@ public enum OS {
@Override public String getPathSeperator() { return "/"; }
};
public static String toCode(OS os) {
if (os == null)
return null;
switch (os) {
case Windows:
return "type_windows";
case Mac:
return "type_mac";
case Linux:
return "type_linux";
default:
return null;
}
}
public static OS fromCode(String osCode) {
if (osCode == null) {
return null;

Loading…
Cancel
Save