OSDN Git Service

Correct number format exception on proxy port and update to 0.92.1
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / ConfigConnectionPage.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.dialog;\r
21 \r
22 import java.util.List;\r
23 \r
24 import com.trolltech.qt.gui.QCheckBox;\r
25 import com.trolltech.qt.gui.QComboBox;\r
26 import com.trolltech.qt.gui.QFormLayout;\r
27 import com.trolltech.qt.gui.QGridLayout;\r
28 import com.trolltech.qt.gui.QGroupBox;\r
29 import com.trolltech.qt.gui.QLabel;\r
30 import com.trolltech.qt.gui.QLineEdit;\r
31 import com.trolltech.qt.gui.QSpinBox;\r
32 import com.trolltech.qt.gui.QVBoxLayout;\r
33 import com.trolltech.qt.gui.QWidget;\r
34 \r
35 import cx.fbn.nevernote.Global;\r
36 import cx.fbn.nevernote.utilities.SyncTimes;\r
37 \r
38 public class ConfigConnectionPage extends QWidget {\r
39         private final QLineEdit useridEdit;\r
40         private final QLineEdit passwordEdit;\r
41         private final QCheckBox rememberPassword;\r
42         private final QCheckBox autoLogin;\r
43         private final QComboBox syncInterval;\r
44         private final SyncTimes syncTimes;\r
45         private final QCheckBox synchronizeOnClose;\r
46         private final QCheckBox synchronizeDeletedContents;\r
47         \r
48         private final QLineEdit proxyHost;\r
49         private final QSpinBox proxyPort;\r
50         private final QLineEdit proxyUserid;\r
51         private final QLineEdit proxyPassword;\r
52         \r
53         public ConfigConnectionPage(QWidget parent) {\r
54                 \r
55                 // Userid settings\r
56                 QGroupBox useridGroup = new QGroupBox(tr("Connection"));\r
57                 QLabel useridLabel = new QLabel(tr("Userid"));\r
58                 QLabel passwordLabel = new QLabel(tr("Password"));\r
59 \r
60                 \r
61                 useridEdit = new QLineEdit();\r
62                 useridEdit.setText(Global.username);\r
63                 \r
64                 passwordEdit = new QLineEdit();\r
65                 passwordEdit.setText(Global.password);\r
66                 passwordEdit.setEchoMode(QLineEdit.EchoMode.Password);\r
67                 \r
68                 syncInterval = new QComboBox(this);\r
69                 syncTimes = new SyncTimes();\r
70                 syncInterval.addItems(syncTimes.stringValues());\r
71                 \r
72                 rememberPassword = new QCheckBox("Remember Userid & Password");\r
73                 autoLogin = new QCheckBox("Automatic Connect");\r
74                 synchronizeDeletedContents = new QCheckBox("Synchronze Deleted Note Content");\r
75                 synchronizeOnClose = new QCheckBox("Synchronize On Shutdown (only if connected)");\r
76                 \r
77                 QGroupBox proxyGroup = new QGroupBox("Proxy Settings");\r
78                 QLabel proxyHostLabel = new QLabel(tr("Host"));\r
79                 QLabel proxyPortLabel = new QLabel(tr("Port"));\r
80                 QLabel proxyUseridLabel = new QLabel(tr("Userid"));\r
81                 QLabel proxyPasswordLabel = new QLabel(tr("Password"));\r
82                 proxyHost = new QLineEdit();\r
83                 proxyPort = new QSpinBox();\r
84                 proxyUserid = new QLineEdit();\r
85                 proxyPassword = new QLineEdit();\r
86                 proxyPassword.setEchoMode(QLineEdit.EchoMode.Password);\r
87                 \r
88                 proxyHost.setText(Global.getProxyValue("url"));\r
89                 String portString = Global.getProxyValue("port");\r
90                 Integer port = new Integer(80);\r
91                 try {\r
92                         port = new Integer(portString.trim());\r
93                 } catch (Exception e) {\r
94                 }\r
95 \r
96                 proxyPort.setMinimum(1);\r
97                 proxyPort.setMaximum(65565);\r
98                 proxyPort.setValue(port);\r
99                 proxyUserid.setText(Global.getProxyValue("userid"));\r
100                 proxyPassword.setText(Global.getProxyValue("password"));\r
101                 \r
102                 if (!proxyHost.text().trim().equals("") && proxyPort.text().trim().equals(""))\r
103                         proxyPort.setValue(80);\r
104                 \r
105                 \r
106                 QFormLayout useridLayout = new QFormLayout();\r
107                 useridLayout.addWidget(useridLabel);\r
108                 useridLayout.addWidget(useridEdit);             \r
109                 useridLayout.addWidget(passwordLabel);\r
110                 useridLayout.addWidget(passwordEdit);\r
111                 useridLayout.addWidget(new QLabel(tr("Syncronization Interval")));\r
112                 useridLayout.addWidget(syncInterval);\r
113                 useridLayout.addWidget(rememberPassword);\r
114                 useridLayout.addWidget(autoLogin);\r
115                 useridLayout.addWidget(synchronizeOnClose);\r
116                 useridLayout.addWidget(synchronizeDeletedContents);\r
117                 \r
118                 QGridLayout proxyLayout = new QGridLayout();\r
119                 proxyLayout.addWidget(proxyHostLabel,1,1);\r
120                 proxyLayout.addWidget(proxyHost,1,2);\r
121                 proxyLayout.addWidget(proxyPortLabel,2,1);\r
122                 proxyLayout.addWidget(proxyPort,2,2);\r
123                 proxyLayout.addWidget(proxyUseridLabel,3,1);\r
124                 proxyLayout.addWidget(proxyUserid,3,2);\r
125                 proxyLayout.addWidget(proxyPasswordLabel,4,1);\r
126                 proxyLayout.addWidget(proxyPassword,4,2);\r
127                                 \r
128                 useridGroup.setLayout(useridLayout);\r
129                 proxyGroup.setLayout(proxyLayout);\r
130                 \r
131                 // Add everything together\r
132                 QVBoxLayout mainLayout = new QVBoxLayout();\r
133                 mainLayout.addWidget(useridGroup);\r
134                 mainLayout.addWidget(proxyGroup);\r
135                 mainLayout.addStretch(1);\r
136                 setLayout(mainLayout);\r
137                 \r
138         }\r
139 \r
140         \r
141         //*****************************************\r
142         //* Userid get/set methods \r
143         //*****************************************\r
144         public void setUserid(String id) {\r
145                 useridEdit.setText(id);\r
146         }\r
147         public String getUserid() {\r
148                 return useridEdit.text();\r
149         }\r
150         \r
151 \r
152         //*****************************************\r
153         //* Password get/set methods \r
154         //*****************************************\r
155         public void setPassword(String id) {\r
156                 passwordEdit.setText(id);\r
157         }\r
158         public String getPassword() {\r
159                 return passwordEdit.text();\r
160         }\r
161         \r
162 \r
163         //*******************************************\r
164         //* Remember Password get/set\r
165         //*******************************************\r
166         public void setRememberPassword(boolean val) {\r
167                 rememberPassword.setChecked(val);\r
168         }\r
169         public boolean getRememberPassword() {\r
170                 return rememberPassword.isChecked();\r
171         }\r
172         \r
173         \r
174         \r
175         \r
176         //*******************************************\r
177         //* Automatic login get/set\r
178         //*******************************************\r
179         public void setAutomaticLogin(boolean val) {\r
180                 autoLogin.setChecked(val);\r
181         }\r
182         public boolean getAutomaticLogin() {\r
183                 return autoLogin.isChecked();\r
184         }\r
185 \r
186         \r
187 \r
188         //*****************************************\r
189         //* Synchronize Deleted Note Content\r
190         //*****************************************\r
191         public void setSyncronizeDeletedContent(boolean val) {\r
192                 synchronizeDeletedContents.setChecked(val);\r
193         }\r
194         public boolean getSynchronizeDeletedContent() {\r
195                 return synchronizeDeletedContents.isChecked();\r
196         }\r
197         \r
198 \r
199         \r
200         //******************************************\r
201         //* Get Proxy settings\r
202         //******************************************\r
203         public String getProxyUrl() {\r
204                 return proxyHost.text().trim();\r
205         }\r
206         public String getProxyPort() {\r
207                 if (!proxyHost.text().trim().equalsIgnoreCase("") && proxyPort.text().trim().equals(""))\r
208                         return "80";\r
209                 if (proxyHost.text().trim().equals(""))\r
210                         return "";\r
211                 return proxyPort.text().trim();\r
212         }\r
213         public String getProxyUserid() {\r
214                 if (proxyHost.text().trim().equals(""))\r
215                         return "";\r
216                 return proxyUserid.text().trim();\r
217         }\r
218         public String getProxyPassword() {\r
219                 if (proxyHost.text().trim().equals(""))\r
220                         return "";\r
221                 return proxyPassword.text().trim();\r
222         }\r
223 \r
224         \r
225         \r
226         \r
227         //*****************************************\r
228         //* Get/set synchronize on close\r
229         //*****************************************\r
230         public boolean getSynchronizeOnClose() {\r
231                 return synchronizeOnClose.isChecked();\r
232         }\r
233         public void setSynchronizeOnClose(boolean val) {\r
234                 synchronizeOnClose.setChecked(val);\r
235         }\r
236         \r
237         \r
238         //*****************************************\r
239         //* Get/set sync intervals\r
240         //*****************************************\r
241         public String getSyncInterval() {\r
242                 int i = syncInterval.currentIndex();\r
243                 return syncInterval.itemText(i);        \r
244         }\r
245         public void setSyncInterval(String s) {\r
246                 List<String> vals = syncTimes.stringValues();\r
247                 for (int i=0; i<vals.size(); i++) {\r
248                         if (vals.get(i).equalsIgnoreCase(s))\r
249                                 syncInterval.setCurrentIndex(i);\r
250                 }\r
251         }\r
252 }\r