OSDN Git Service

12ae530e633b32bff7f39dced253b51e87e3b1e8
[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                 proxyPort.setValue(new Integer(Global.getProxyValue("port")));\r
90                 proxyPort.setMinimum(1);\r
91                 proxyPort.setMaximum(65565);\r
92                 proxyUserid.setText(Global.getProxyValue("userid"));\r
93                 proxyPassword.setText(Global.getProxyValue("password"));\r
94                 \r
95                 if (!proxyHost.text().trim().equals("") && proxyPort.text().trim().equals(""))\r
96                         proxyPort.setValue(80);\r
97                 \r
98                 \r
99                 QFormLayout useridLayout = new QFormLayout();\r
100                 useridLayout.addWidget(useridLabel);\r
101                 useridLayout.addWidget(useridEdit);             \r
102                 useridLayout.addWidget(passwordLabel);\r
103                 useridLayout.addWidget(passwordEdit);\r
104                 useridLayout.addWidget(new QLabel(tr("Syncronization Interval")));\r
105                 useridLayout.addWidget(syncInterval);\r
106                 useridLayout.addWidget(rememberPassword);\r
107                 useridLayout.addWidget(autoLogin);\r
108                 useridLayout.addWidget(synchronizeOnClose);\r
109                 useridLayout.addWidget(synchronizeDeletedContents);\r
110                 \r
111                 QGridLayout proxyLayout = new QGridLayout();\r
112                 proxyLayout.addWidget(proxyHostLabel,1,1);\r
113                 proxyLayout.addWidget(proxyHost,1,2);\r
114                 proxyLayout.addWidget(proxyPortLabel,2,1);\r
115                 proxyLayout.addWidget(proxyPort,2,2);\r
116                 proxyLayout.addWidget(proxyUseridLabel,3,1);\r
117                 proxyLayout.addWidget(proxyUserid,3,2);\r
118                 proxyLayout.addWidget(proxyPasswordLabel,4,1);\r
119                 proxyLayout.addWidget(proxyPassword,4,2);\r
120                                 \r
121                 useridGroup.setLayout(useridLayout);\r
122                 proxyGroup.setLayout(proxyLayout);\r
123                 \r
124                 // Add everything together\r
125                 QVBoxLayout mainLayout = new QVBoxLayout();\r
126                 mainLayout.addWidget(useridGroup);\r
127                 mainLayout.addWidget(proxyGroup);\r
128                 mainLayout.addStretch(1);\r
129                 setLayout(mainLayout);\r
130                 \r
131         }\r
132 \r
133         \r
134         //*****************************************\r
135         //* Userid get/set methods \r
136         //*****************************************\r
137         public void setUserid(String id) {\r
138                 useridEdit.setText(id);\r
139         }\r
140         public String getUserid() {\r
141                 return useridEdit.text();\r
142         }\r
143         \r
144 \r
145         //*****************************************\r
146         //* Password get/set methods \r
147         //*****************************************\r
148         public void setPassword(String id) {\r
149                 passwordEdit.setText(id);\r
150         }\r
151         public String getPassword() {\r
152                 return passwordEdit.text();\r
153         }\r
154         \r
155 \r
156         //*******************************************\r
157         //* Remember Password get/set\r
158         //*******************************************\r
159         public void setRememberPassword(boolean val) {\r
160                 rememberPassword.setChecked(val);\r
161         }\r
162         public boolean getRememberPassword() {\r
163                 return rememberPassword.isChecked();\r
164         }\r
165         \r
166         \r
167         \r
168         \r
169         //*******************************************\r
170         //* Automatic login get/set\r
171         //*******************************************\r
172         public void setAutomaticLogin(boolean val) {\r
173                 autoLogin.setChecked(val);\r
174         }\r
175         public boolean getAutomaticLogin() {\r
176                 return autoLogin.isChecked();\r
177         }\r
178 \r
179         \r
180 \r
181         //*****************************************\r
182         //* Synchronize Deleted Note Content\r
183         //*****************************************\r
184         public void setSyncronizeDeletedContent(boolean val) {\r
185                 synchronizeDeletedContents.setChecked(val);\r
186         }\r
187         public boolean getSynchronizeDeletedContent() {\r
188                 return synchronizeDeletedContents.isChecked();\r
189         }\r
190         \r
191 \r
192         \r
193         //******************************************\r
194         //* Get Proxy settings\r
195         //******************************************\r
196         public String getProxyUrl() {\r
197                 return proxyHost.text().trim();\r
198         }\r
199         public String getProxyPort() {\r
200                 if (!proxyHost.text().trim().equalsIgnoreCase("") && proxyPort.text().trim().equals(""))\r
201                         return "80";\r
202                 if (proxyHost.text().trim().equals(""))\r
203                         return "";\r
204                 return proxyPort.text().trim();\r
205         }\r
206         public String getProxyUserid() {\r
207                 if (proxyHost.text().trim().equals(""))\r
208                         return "";\r
209                 return proxyUserid.text().trim();\r
210         }\r
211         public String getProxyPassword() {\r
212                 if (proxyHost.text().trim().equals(""))\r
213                         return "";\r
214                 return proxyPassword.text().trim();\r
215         }\r
216 \r
217         \r
218         \r
219         \r
220         //*****************************************\r
221         //* Get/set synchronize on close\r
222         //*****************************************\r
223         public boolean getSynchronizeOnClose() {\r
224                 return synchronizeOnClose.isChecked();\r
225         }\r
226         public void setSynchronizeOnClose(boolean val) {\r
227                 synchronizeOnClose.setChecked(val);\r
228         }\r
229         \r
230         \r
231         //*****************************************\r
232         //* Get/set sync intervals\r
233         //*****************************************\r
234         public String getSyncInterval() {\r
235                 int i = syncInterval.currentIndex();\r
236                 return syncInterval.itemText(i);        \r
237         }\r
238         public void setSyncInterval(String s) {\r
239                 List<String> vals = syncTimes.stringValues();\r
240                 for (int i=0; i<vals.size(); i++) {\r
241                         if (vals.get(i).equalsIgnoreCase(s))\r
242                                 syncInterval.setCurrentIndex(i);\r
243                 }\r
244         }\r
245 }\r