FreeRDP
ManualBookmark.java
1 /*
2  Manual Bookmark implementation
3 
4  Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5 
6  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7  If a copy of the MPL was not distributed with this file, You can obtain one at
8  http://mozilla.org/MPL/2.0/.
9 */
10 
11 package com.freerdp.freerdpcore.domain;
12 
13 import android.content.SharedPreferences;
14 import android.os.Parcel;
15 import android.os.Parcelable;
16 
17 public class ManualBookmark extends BookmarkBase
18 {
19  public static final Parcelable.Creator<ManualBookmark> CREATOR =
20  new Parcelable.Creator<ManualBookmark>() {
21  public ManualBookmark createFromParcel(Parcel in)
22  {
23  return new ManualBookmark(in);
24  }
25 
26  @Override public ManualBookmark[] newArray(int size)
27  {
28  return new ManualBookmark[size];
29  }
30  };
31  private String hostname;
32  private int port;
33  private boolean enableGatewaySettings;
34  private GatewaySettings gatewaySettings;
35 
36  public ManualBookmark(Parcel parcel)
37  {
38  super(parcel);
39  type = TYPE_MANUAL;
40  hostname = parcel.readString();
41  port = parcel.readInt();
42 
43  enableGatewaySettings = (parcel.readInt() == 1 ? true : false);
44  gatewaySettings = parcel.readParcelable(GatewaySettings.class.getClassLoader());
45  }
46 
47  public ManualBookmark()
48  {
49  super();
50  init();
51  }
52 
53  private void init()
54  {
55  type = TYPE_MANUAL;
56  hostname = "";
57  port = 3389;
58  enableGatewaySettings = false;
59  gatewaySettings = new GatewaySettings();
60  }
61 
62  public String getHostname()
63  {
64  return hostname;
65  }
66 
67  public void setHostname(String hostname)
68  {
69  this.hostname = hostname;
70  }
71 
72  public int getPort()
73  {
74  return port;
75  }
76 
77  public void setPort(int port)
78  {
79  this.port = port;
80  }
81 
82  public boolean getEnableGatewaySettings()
83  {
84  return enableGatewaySettings;
85  }
86 
87  public void setEnableGatewaySettings(boolean enableGatewaySettings)
88  {
89  this.enableGatewaySettings = enableGatewaySettings;
90  }
91 
92  public GatewaySettings getGatewaySettings()
93  {
94  return gatewaySettings;
95  }
96 
97  public void setGatewaySettings(GatewaySettings gatewaySettings)
98  {
99  this.gatewaySettings = gatewaySettings;
100  }
101 
102  @Override public int describeContents()
103  {
104  return 0;
105  }
106 
107  @Override public void writeToParcel(Parcel out, int flags)
108  {
109  super.writeToParcel(out, flags);
110  out.writeString(hostname);
111  out.writeInt(port);
112  out.writeInt(enableGatewaySettings ? 1 : 0);
113  out.writeParcelable(gatewaySettings, flags);
114  }
115 
116  @Override public void writeToSharedPreferences(SharedPreferences sharedPrefs)
117  {
118  super.writeToSharedPreferences(sharedPrefs);
119 
120  SharedPreferences.Editor editor = sharedPrefs.edit();
121  editor.putString("bookmark.hostname", hostname);
122  editor.putInt("bookmark.port", port);
123  editor.putBoolean("bookmark.enable_gateway_settings", enableGatewaySettings);
124  editor.putString("bookmark.gateway_hostname", gatewaySettings.getHostname());
125  editor.putInt("bookmark.gateway_port", gatewaySettings.getPort());
126  editor.putString("bookmark.gateway_username", gatewaySettings.getUsername());
127  editor.putString("bookmark.gateway_password", gatewaySettings.getPassword());
128  editor.putString("bookmark.gateway_domain", gatewaySettings.getDomain());
129  editor.commit();
130  }
131 
132  @Override public void readFromSharedPreferences(SharedPreferences sharedPrefs)
133  {
134  super.readFromSharedPreferences(sharedPrefs);
135 
136  hostname = sharedPrefs.getString("bookmark.hostname", "");
137  port = sharedPrefs.getInt("bookmark.port", 3389);
138  enableGatewaySettings = sharedPrefs.getBoolean("bookmark.enable_gateway_settings", false);
139  gatewaySettings.setHostname(sharedPrefs.getString("bookmark.gateway_hostname", ""));
140  gatewaySettings.setPort(sharedPrefs.getInt("bookmark.gateway_port", 443));
141  gatewaySettings.setUsername(sharedPrefs.getString("bookmark.gateway_username", ""));
142  gatewaySettings.setPassword(sharedPrefs.getString("bookmark.gateway_password", ""));
143  gatewaySettings.setDomain(sharedPrefs.getString("bookmark.gateway_domain", ""));
144  }
145 
146  // Cloneable
147  public Object clone()
148  {
149  return super.clone();
150  }
151 
152  // Gateway Settings class
153  public static class GatewaySettings implements Parcelable
154  {
155  public static final Parcelable.Creator<GatewaySettings> CREATOR =
156  new Parcelable.Creator<GatewaySettings>() {
157  public GatewaySettings createFromParcel(Parcel in)
158  {
159  return new GatewaySettings(in);
160  }
161 
162  @Override public GatewaySettings[] newArray(int size)
163  {
164  return new GatewaySettings[size];
165  }
166  };
167  private String hostname;
168  private int port;
169  private String username;
170  private String password;
171  private String domain;
172 
173  public GatewaySettings()
174  {
175  hostname = "";
176  port = 443;
177  username = "";
178  password = "";
179  domain = "";
180  }
181 
182  public GatewaySettings(Parcel parcel)
183  {
184  hostname = parcel.readString();
185  port = parcel.readInt();
186  username = parcel.readString();
187  password = parcel.readString();
188  domain = parcel.readString();
189  }
190 
191  public String getHostname()
192  {
193  return hostname;
194  }
195 
196  public void setHostname(String hostname)
197  {
198  this.hostname = hostname;
199  }
200 
201  public int getPort()
202  {
203  return port;
204  }
205 
206  public void setPort(int port)
207  {
208  this.port = port;
209  }
210 
211  public String getUsername()
212  {
213  return username;
214  }
215 
216  public void setUsername(String username)
217  {
218  this.username = username;
219  }
220 
221  public String getPassword()
222  {
223  return password;
224  }
225 
226  public void setPassword(String password)
227  {
228  this.password = password;
229  }
230 
231  public String getDomain()
232  {
233  return domain;
234  }
235 
236  public void setDomain(String domain)
237  {
238  this.domain = domain;
239  }
240 
241  @Override public int describeContents()
242  {
243  return 0;
244  }
245 
246  @Override public void writeToParcel(Parcel out, int flags)
247  {
248  out.writeString(hostname);
249  out.writeInt(port);
250  out.writeString(username);
251  out.writeString(password);
252  out.writeString(domain);
253  }
254  }
255 }