diff options
author | Kenny Root <kenny@the-b.org> | 2009-08-14 12:16:32 +0000 |
---|---|---|
committer | Kenny Root <kenny@the-b.org> | 2009-08-14 12:16:32 +0000 |
commit | 9c092118f8ebd2cd3b40f8a689c234b450778b11 (patch) | |
tree | eb003b0764c7f3eac15f262e9a142c509fbbbf2b /src | |
parent | 8be636afaee6decbf7e7465870e2296c343b36c4 (diff) | |
download | connectbot-9c092118f8ebd2cd3b40f8a689c234b450778b11.tar.gz connectbot-9c092118f8ebd2cd3b40f8a689c234b450778b11.tar.bz2 connectbot-9c092118f8ebd2cd3b40f8a689c234b450778b11.zip |
Don't auto-start local connections upon selection
There is apparently a race condition in building the UIs. The local
transport was starting up prematurely and causing the host list to cycle
multiple times at some point.
This change also makes it so that hosts quick-connected using the same
nickname as a previous host simply uses the previous host instead of
creating a new entry that can never be "reached"
git-svn-id: https://connectbot.googlecode.com/svn/trunk/connectbot@396 df292f66-193f-0410-a5fc-6d59da041ff2
Diffstat (limited to 'src')
-rw-r--r-- | src/org/connectbot/HostListActivity.java | 23 | ||||
-rw-r--r-- | src/org/connectbot/service/TerminalManager.java | 24 | ||||
-rw-r--r-- | src/org/connectbot/transport/Local.java | 10 | ||||
-rw-r--r-- | src/org/connectbot/transport/TransportFactory.java | 29 |
4 files changed, 50 insertions, 36 deletions
diff --git a/src/org/connectbot/HostListActivity.java b/src/org/connectbot/HostListActivity.java index 1cdee4f..cc2a1b2 100644 --- a/src/org/connectbot/HostListActivity.java +++ b/src/org/connectbot/HostListActivity.java @@ -247,15 +247,7 @@ public class HostListActivity extends ListActivity { quickconnect.setHint(formatHint); quickconnect.setError(null); - - // Start ConsoleActivity immediately if the hint is empty. - if ("".equals(formatHint)) { - quickconnect.setEnabled(false); - startConsoleActivity(); - } else { - quickconnect.setEnabled(true); - quickconnect.requestFocus(); - } + quickconnect.requestFocus(); } public void onNothingSelected(AdapterView<?> arg0) { } }); @@ -410,14 +402,17 @@ public class HostListActivity extends ListActivity { return false; } - HostBean host = TransportFactory.getTransport(uri.getScheme()).createHost(uri); - host.setColor(HostDatabase.COLOR_GRAY); - host.setPubkeyId(HostDatabase.PUBKEYID_ANY); - hostdb.saveHost(host); + HostBean host = TransportFactory.findHost(hostdb, uri); + if (host == null) { + host = TransportFactory.getTransport(uri.getScheme()).createHost(uri); + host.setColor(HostDatabase.COLOR_GRAY); + host.setPubkeyId(HostDatabase.PUBKEYID_ANY); + hostdb.saveHost(host); + } Intent intent = new Intent(HostListActivity.this, ConsoleActivity.class); intent.setData(uri); - HostListActivity.this.startActivity(intent); + startActivity(intent); return true; } diff --git a/src/org/connectbot/service/TerminalManager.java b/src/org/connectbot/service/TerminalManager.java index b272845..2faac98 100644 --- a/src/org/connectbot/service/TerminalManager.java +++ b/src/org/connectbot/service/TerminalManager.java @@ -34,7 +34,6 @@ import org.connectbot.ConsoleActivity; import org.connectbot.R; import org.connectbot.bean.HostBean; import org.connectbot.bean.PubkeyBean; -import org.connectbot.transport.AbsTransport; import org.connectbot.transport.TransportFactory; import org.connectbot.util.HostDatabase; import org.connectbot.util.PreferenceConstants; @@ -255,27 +254,12 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen * format specified by an individual transport. */ public void openConnection(Uri uri) throws Exception { - AbsTransport transport = TransportFactory.getTransport(uri.getScheme()); + HostBean host = TransportFactory.findHost(hostdb, uri); - Map<String, String> selection = new HashMap<String, String>(); + if (host == null) + host = TransportFactory.getTransport(uri.getScheme()).createHost(uri); - transport.getSelectionArgs(uri, selection); - if (selection.size() == 0) { - Log.e(TAG, String.format("Transport %s failed to do something useful with URI=%s", - uri.getScheme(), uri.toString())); - throw new IllegalStateException("Failed to get needed selection arguments"); - } - - HostBean host = hostdb.findHost(selection); - - if (host == null) { - Log.d(TAG, String.format( - "Didn't find existing host (selection=%s)", - selection.toString())); - host = transport.createHost(uri); - } - - this.openConnection(host); + openConnection(host); } /** diff --git a/src/org/connectbot/transport/Local.java b/src/org/connectbot/transport/Local.java index bbc8be0..23c16b2 100644 --- a/src/org/connectbot/transport/Local.java +++ b/src/org/connectbot/transport/Local.java @@ -200,7 +200,13 @@ public class Local extends AbsTransport { } public static Uri getUri(String input) { - return Uri.parse(DEFAULT_URI); + Uri uri = Uri.parse(DEFAULT_URI); + + if (input != null && input.length() > 0) { + uri = uri.buildUpon().fragment(input).build(); + } + + return uri; } @Override @@ -220,6 +226,6 @@ public class Local extends AbsTransport { } public static String getFormatHint(Context context) { - return ""; + return context.getString(R.string.hostpref_nickname_title); } } diff --git a/src/org/connectbot/transport/TransportFactory.java b/src/org/connectbot/transport/TransportFactory.java index 1239441..991829d 100644 --- a/src/org/connectbot/transport/TransportFactory.java +++ b/src/org/connectbot/transport/TransportFactory.java @@ -18,6 +18,12 @@ package org.connectbot.transport; +import java.util.HashMap; +import java.util.Map; + +import org.connectbot.bean.HostBean; +import org.connectbot.util.HostDatabase; + import android.content.Context; import android.net.Uri; import android.util.Log; @@ -28,6 +34,8 @@ import android.util.Log; * */ public class TransportFactory { + private static final String TAG = "ConnectBot.TransportFactory"; + private static String[] transportNames = { SSH.getProtocolName(), Telnet.getProtocolName(), @@ -101,4 +109,25 @@ public class TransportFactory { return AbsTransport.getFormatHint(context); } } + + /** + * @param hostdb Handle to HostDatabase + * @param uri URI to target server + * @param host HostBean in which to put the results + * @return true when host was found + */ + public static HostBean findHost(HostDatabase hostdb, Uri uri) { + AbsTransport transport = getTransport(uri.getScheme()); + + Map<String, String> selection = new HashMap<String, String>(); + + transport.getSelectionArgs(uri, selection); + if (selection.size() == 0) { + Log.e(TAG, String.format("Transport %s failed to do something useful with URI=%s", + uri.getScheme(), uri.toString())); + throw new IllegalStateException("Failed to get needed selection arguments"); + } + + return hostdb.findHost(selection); + } } |