comparison app/src/main/java/com/five_ten_sg/connectbot/bean/HostBean.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/com/five_ten_sg/connectbot/bean/HostBean.java@e0f5e706a655
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
1 /*
2 * ConnectBot: simple, powerful, open-source SSH client for Android
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package com.five_ten_sg.connectbot.bean;
19
20 import com.five_ten_sg.connectbot.util.HostDatabase;
21 import android.content.ContentValues;
22 import android.net.Uri;
23
24 /**
25 * @author Kenny Root
26 *
27 */
28 public class HostBean extends AbstractBean {
29 public static final String BEAN_NAME = "host";
30
31 /* Database fields */
32 private long id = -1;
33 private String nickname = null;
34 private String username = null;
35 private String hostname = null;
36 private int port = 22;
37 private String protocol = "ssh";
38 private String hostKeyAlgo = null;
39 private byte[] hostKey = null;
40 private long lastConnect = -1;
41 private String color;
42 private boolean useKeys = true;
43 private String useAuthAgent = HostDatabase.AUTHAGENT_NO;
44 private String postLogin = null;
45 private long pubkeyId = -1;
46 private String delKey = HostDatabase.DELKEY_DEL;
47 private float fontSize = -1;
48 private boolean fixedSize = false;
49 private int fixedWidth = 80;
50 private int fixedHeight = 25;
51 private boolean wantSession = true;
52 private boolean compression = false;
53 private String httpproxy = null;
54 private String encoding = HostDatabase.ENCODING_DEFAULT;
55 private boolean stayConnected = false;
56 private boolean wantX11Forward = false;
57 private String x11Host = "localhost";
58 private int x11Port = 6000;
59 private String monitor = null;
60 private String hostemulation = null;
61 private String encryption5250 = null;
62 private String library = null;
63 private String initialMenu = null;
64 private String program = null;
65
66 public HostBean() {
67 }
68
69 @Override
70 public String getBeanName() {
71 return BEAN_NAME;
72 }
73
74 public HostBean(String nickname, String protocol, String username, String hostname, int port) {
75 this.nickname = nickname;
76 this.protocol = protocol;
77 this.username = username;
78 this.hostname = hostname;
79 this.port = port;
80 }
81
82 public boolean isSSH() {
83 return protocol.equals("ssh");
84 }
85
86 public boolean is5250() {
87 return protocol.equals("tn5250");
88 }
89
90 public boolean isTelnet() {
91 return protocol.equals("telnet");
92 }
93
94 public boolean isAsync() {
95 return isSSH() || isTelnet();
96 }
97
98 public void setId(long id) {
99 this.id = id;
100 }
101 public long getId() {
102 return id;
103 }
104 public void setNickname(String nickname) {
105 this.nickname = nickname;
106 }
107 public String getNickname() {
108 return nickname;
109 }
110 public void setUsername(String username) {
111 this.username = username;
112 }
113 public String getUsername() {
114 return username;
115 }
116 public void setHostname(String hostname) {
117 this.hostname = hostname;
118 }
119 public String getHostname() {
120 return hostname;
121 }
122 public void setPort(int port) {
123 this.port = port;
124 }
125 public int getPort() {
126 return port;
127 }
128
129 public void setProtocol(String protocol) {
130 this.protocol = protocol;
131 }
132
133 public String getProtocol() {
134 return protocol;
135 }
136
137 public void setHostKeyAlgo(String hostKeyAlgo) {
138 this.hostKeyAlgo = hostKeyAlgo;
139 }
140 public String getHostKeyAlgo() {
141 return hostKeyAlgo;
142 }
143 public void setHostKey(byte[] hostKey) {
144 if (hostKey == null)
145 this.hostKey = null;
146 else
147 this.hostKey = hostKey.clone();
148 }
149 public byte[] getHostKey() {
150 if (hostKey == null)
151 return null;
152 else
153 return hostKey.clone();
154 }
155 public void setLastConnect(long lastConnect) {
156 this.lastConnect = lastConnect;
157 }
158 public long getLastConnect() {
159 return lastConnect;
160 }
161 public void setColor(String color) {
162 this.color = color;
163 }
164 public String getColor() {
165 return color;
166 }
167 public void setUseKeys(boolean useKeys) {
168 this.useKeys = useKeys;
169 }
170 public boolean getUseKeys() {
171 return useKeys;
172 }
173 public void setUseAuthAgent(String useAuthAgent) {
174 this.useAuthAgent = useAuthAgent;
175 }
176 public String getUseAuthAgent() {
177 return useAuthAgent;
178 }
179 public void setPostLogin(String postLogin) {
180 this.postLogin = postLogin;
181 }
182 public String getPostLogin() {
183 return postLogin;
184 }
185 public void setPubkeyId(long pubkeyId) {
186 this.pubkeyId = pubkeyId;
187 }
188 public long getPubkeyId() {
189 return pubkeyId;
190 }
191 public void setWantSession(boolean wantSession) {
192 this.wantSession = wantSession;
193 }
194 public boolean getWantSession() {
195 return wantSession;
196 }
197 public void setDelKey(String delKey) {
198 this.delKey = delKey;
199 }
200 public String getDelKey() {
201 return delKey;
202 }
203 public void setFontSize(float fontSize) {
204 this.fontSize = fontSize;
205 }
206 public float getFontSize() {
207 return fontSize;
208 }
209 public void setFixedSize(boolean fixedSize) {
210 this.fixedSize = fixedSize;
211 }
212 public boolean getFixedSize() {
213 return fixedSize;
214 }
215 public void setFixedWidth(int fixedWidth) {
216 this.fixedWidth = fixedWidth;
217 }
218 public int getFixedWidth() {
219 return fixedWidth;
220 }
221 public void setFixedHeight(int fixedHeight) {
222 this.fixedHeight = fixedHeight;
223 }
224 public int getFixedHeight() {
225 return fixedHeight;
226 }
227 public void setCompression(boolean compression) {
228 this.compression = compression;
229 }
230 public boolean getCompression() {
231 return compression;
232 }
233 public void setHttpproxy(String httpproxy) {
234 this.httpproxy = httpproxy;
235 }
236 public String getHttpproxy() {
237 return httpproxy;
238 }
239
240 public void setEncoding(String encoding) {
241 this.encoding = encoding;
242 }
243
244 public String getEncoding() {
245 return this.encoding;
246 }
247
248 public void setStayConnected(boolean stayConnected) {
249 this.stayConnected = stayConnected;
250 }
251
252 public boolean getStayConnected() {
253 return stayConnected;
254 }
255
256 public String getDescription() {
257 String description = String.format("%s@%s", username, hostname);
258
259 if (port != 22)
260 description += String.format(":%d", port);
261
262 return description;
263 }
264
265 public boolean getWantX11Forward() {
266 return this.wantX11Forward;
267 }
268
269 public void setWantX11Forward(boolean wantX11Forward) {
270 this.wantX11Forward = wantX11Forward;
271 }
272
273 public String getX11Host() {
274 return this.x11Host;
275 }
276
277 public void setX11Host(String x11Host) {
278 this.x11Host = x11Host;
279 }
280
281 public int getX11Port() {
282 return this.x11Port;
283 }
284
285 public void setX11Port(int x11Port) {
286 this.x11Port = x11Port;
287 }
288
289 public String getMonitor() {
290 return this.monitor;
291 }
292
293 public void setMonitor(String monitor) {
294 this.monitor = monitor;
295 }
296
297 public String getHostEmulation() {
298 return this.hostemulation;
299 }
300
301 public void setHostEmulation(String hostemulation) {
302 this.hostemulation = hostemulation;
303 }
304
305 public String getEncryption5250() {
306 return this.encryption5250;
307 }
308
309 public void setEncryption5250(String encryption5250) {
310 this.encryption5250 = encryption5250;
311 }
312
313 public String getLibrary() {
314 return this.library;
315 }
316
317 public void setLibrary(String library) {
318 this.library = library;
319 }
320
321 public String getInitialMenu() {
322 return this.initialMenu;
323 }
324
325 public void setInitialMenu(String initialMenu) {
326 this.initialMenu = initialMenu;
327 }
328
329 public String getProgram() {
330 return this.program;
331 }
332
333 public void setProgram(String program) {
334 this.program = program;
335 }
336
337 @Override
338 public ContentValues getValues() {
339 ContentValues values = new ContentValues();
340 values.put(HostDatabase.FIELD_HOST_NICKNAME, nickname);
341 values.put(HostDatabase.FIELD_HOST_PROTOCOL, protocol);
342 values.put(HostDatabase.FIELD_HOST_USERNAME, username);
343 values.put(HostDatabase.FIELD_HOST_HOSTNAME, hostname);
344 values.put(HostDatabase.FIELD_HOST_PORT, port);
345 values.put(HostDatabase.FIELD_HOST_HOSTKEYALGO, hostKeyAlgo);
346 values.put(HostDatabase.FIELD_HOST_HOSTKEY, hostKey);
347 values.put(HostDatabase.FIELD_HOST_LASTCONNECT, lastConnect);
348 values.put(HostDatabase.FIELD_HOST_COLOR, color);
349 values.put(HostDatabase.FIELD_HOST_USEKEYS, Boolean.toString(useKeys));
350 values.put(HostDatabase.FIELD_HOST_USEAUTHAGENT, useAuthAgent);
351 values.put(HostDatabase.FIELD_HOST_POSTLOGIN, postLogin);
352 values.put(HostDatabase.FIELD_HOST_PUBKEYID, pubkeyId);
353 values.put(HostDatabase.FIELD_HOST_WANTSESSION, Boolean.toString(wantSession));
354 values.put(HostDatabase.FIELD_HOST_DELKEY, delKey);
355 values.put(HostDatabase.FIELD_HOST_FONTSIZE, fontSize);
356 values.put(HostDatabase.FIELD_HOST_FIXEDSIZE, Boolean.toString(fixedSize));
357 values.put(HostDatabase.FIELD_HOST_FIXEDWIDTH, fixedWidth);
358 values.put(HostDatabase.FIELD_HOST_FIXEDHEIGHT, fixedHeight);
359 values.put(HostDatabase.FIELD_HOST_COMPRESSION, Boolean.toString(compression));
360 values.put(HostDatabase.FIELD_HOST_HTTPPROXY, httpproxy);
361 values.put(HostDatabase.FIELD_HOST_ENCODING, encoding);
362 values.put(HostDatabase.FIELD_HOST_STAYCONNECTED, stayConnected);
363 values.put(HostDatabase.FIELD_HOST_WANTX11FORWARD, wantX11Forward);
364 values.put(HostDatabase.FIELD_HOST_X11HOST, x11Host);
365 values.put(HostDatabase.FIELD_HOST_X11PORT, x11Port);
366 values.put(HostDatabase.FIELD_HOST_MONITOR, monitor);
367 values.put(HostDatabase.FIELD_HOST_EMULATION, hostemulation);
368 values.put(HostDatabase.FIELD_HOST_ENCRYPTION5250, encryption5250);
369 values.put(HostDatabase.FIELD_HOST_LIBRARY5250, library);
370 values.put(HostDatabase.FIELD_HOST_MENU5250, initialMenu);
371 values.put(HostDatabase.FIELD_HOST_PROGRAM5250, program);
372 return values;
373 }
374
375 @Override
376 public boolean equals(Object o) {
377 if (o == null || !(o instanceof HostBean))
378 return false;
379
380 HostBean host = (HostBean)o;
381
382 if (id != -1 && host.getId() != -1)
383 return host.getId() == id;
384
385 if (nickname == null) {
386 if (host.getNickname() != null)
387 return false;
388 }
389 else if (!nickname.equals(host.getNickname()))
390 return false;
391
392 if (protocol == null) {
393 if (host.getProtocol() != null)
394 return false;
395 }
396 else if (!protocol.equals(host.getProtocol()))
397 return false;
398
399 if (username == null) {
400 if (host.getUsername() != null)
401 return false;
402 }
403 else if (!username.equals(host.getUsername()))
404 return false;
405
406 if (hostname == null) {
407 if (host.getHostname() != null)
408 return false;
409 }
410 else if (!hostname.equals(host.getHostname()))
411 return false;
412
413 if (port != host.getPort())
414 return false;
415
416 return true;
417 }
418
419 @Override
420 public int hashCode() {
421 int hash = 7;
422
423 if (id != -1)
424 return (int)id;
425
426 hash = 31 * hash + (null == nickname ? 0 : nickname.hashCode());
427 hash = 31 * hash + (null == protocol ? 0 : protocol.hashCode());
428 hash = 31 * hash + (null == username ? 0 : username.hashCode());
429 hash = 31 * hash + (null == hostname ? 0 : hostname.hashCode());
430 hash = 31 * hash + port;
431 return hash;
432 }
433
434 /**
435 * @return URI identifying this HostBean
436 */
437 public Uri getUri() {
438 StringBuilder sb = new StringBuilder();
439 sb.append(protocol)
440 .append("://");
441
442 if (username != null)
443 sb.append(Uri.encode(username))
444 .append('@');
445
446 sb.append(Uri.encode(hostname))
447 .append(':')
448 .append(port)
449 .append("/#")
450 .append(nickname);
451 return Uri.parse(sb.toString());
452 }
453
454 }