OSDN Git Service

Fix non-latin character search problem & remove minimum word length options.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / ConfigDialog.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.io.FileInputStream;\r
23 import java.io.FileNotFoundException;\r
24 import java.io.FileOutputStream;\r
25 \r
26 import com.swabunga.spell.engine.Configuration;\r
27 import com.trolltech.qt.core.QSize;\r
28 import com.trolltech.qt.core.Qt.AlignmentFlag;\r
29 import com.trolltech.qt.core.Qt.ItemFlag;\r
30 import com.trolltech.qt.gui.QApplication;\r
31 import com.trolltech.qt.gui.QDialog;\r
32 import com.trolltech.qt.gui.QHBoxLayout;\r
33 import com.trolltech.qt.gui.QIcon;\r
34 import com.trolltech.qt.gui.QListView;\r
35 import com.trolltech.qt.gui.QListWidget;\r
36 import com.trolltech.qt.gui.QListWidgetItem;\r
37 import com.trolltech.qt.gui.QPushButton;\r
38 import com.trolltech.qt.gui.QStackedWidget;\r
39 import com.trolltech.qt.gui.QVBoxLayout;\r
40 import com.trolltech.qt.gui.QWidget;\r
41 \r
42 import cx.fbn.nevernote.Global;\r
43 import cx.fbn.nevernote.utilities.AESEncrypter;\r
44 public class ConfigDialog extends QDialog {\r
45         private final QListWidget                               contentsWidget;\r
46         private final ConfigFontPage                    fontPage;\r
47         private final QStackedWidget                    pagesWidget;\r
48         private final ConfigConnectionPage              connectionPage;\r
49         private final ConfigDebugPage                   debugPage;\r
50         private final ConfigAppearancePage              appearancePage;\r
51         private final ConfigSpellPage                   spellPage;\r
52         private final ConfigIndexPage                   indexPage;\r
53     private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
54         \r
55         public ConfigDialog(QWidget parent) {\r
56                 \r
57                 contentsWidget = new QListWidget(this);\r
58                 setWindowIcon(new QIcon(iconPath+"config.png"));\r
59                 contentsWidget.setViewMode(QListView.ViewMode.IconMode);\r
60                 contentsWidget.setIconSize(new QSize(96, 84));\r
61                 contentsWidget.setMovement(QListView.Movement.Static);\r
62                 contentsWidget.setMaximumWidth(128);\r
63                 contentsWidget.setSpacing(12);\r
64                 \r
65                 pagesWidget = new QStackedWidget(this);\r
66                 fontPage = new ConfigFontPage(this);\r
67                 connectionPage = new ConfigConnectionPage(this);\r
68                 appearancePage = new ConfigAppearancePage(this);\r
69                 indexPage = new ConfigIndexPage(this);\r
70                 debugPage = new ConfigDebugPage(this);\r
71                 spellPage = new ConfigSpellPage(this);\r
72                 pagesWidget.addWidget(appearancePage);\r
73                 pagesWidget.addWidget(fontPage);\r
74                 pagesWidget.addWidget(indexPage);\r
75                 pagesWidget.addWidget(spellPage);\r
76                 pagesWidget.addWidget(connectionPage);\r
77                 pagesWidget.addWidget(debugPage);\r
78                 \r
79                 QPushButton cancelButton = new QPushButton(tr("Cancel"));\r
80                 QPushButton okButton = new QPushButton(tr("OK"));\r
81                 okButton.clicked.connect(this, "okPushed()");\r
82                 cancelButton.clicked.connect(this, "close()");\r
83                 \r
84                 createIcons();\r
85                 contentsWidget.setCurrentRow(0);\r
86                 \r
87                 QHBoxLayout horizontalLayout = new QHBoxLayout();\r
88                 horizontalLayout.addWidget(contentsWidget);\r
89                 horizontalLayout.addWidget(pagesWidget,1);\r
90                 \r
91                 QHBoxLayout buttonLayout = new QHBoxLayout();\r
92                 buttonLayout.addStretch(1);\r
93                 buttonLayout.addWidget(okButton);\r
94                 buttonLayout.addWidget(cancelButton);\r
95                 setWindowTitle(tr("Settings")); \r
96                 \r
97                 QVBoxLayout mainLayout = new QVBoxLayout();\r
98                 mainLayout.addLayout(horizontalLayout);\r
99                 mainLayout.addSpacing(1);\r
100                 mainLayout.addLayout(buttonLayout);\r
101                 setLayout(mainLayout);\r
102                 \r
103                 loadSettings();\r
104         }\r
105         public void okPushed() {\r
106                 Global.setServer(debugPage.getServer());\r
107                 Global.setEnableThumbnails(debugPage.getEnableThumbnails());\r
108                 AESEncrypter aes = new AESEncrypter();\r
109                 aes.setUserid(connectionPage.getUserid().trim());\r
110                 \r
111                 if (debugPage.getDisableUploads())\r
112                         Global.disableUploads = true;\r
113                 else\r
114                         Global.disableUploads = false;\r
115                 Global.setDisableUploads(Global.disableUploads);\r
116                 Global.setMimicEvernoteInterface(appearancePage.getMimicEvernote());\r
117                 Global.setMinimizeOnClose(appearancePage.getMinimizeOnClose());\r
118                 \r
119                 if (appearancePage.getShowSplashScreen())\r
120                         Global.saveWindowVisible("SplashScreen", true);\r
121                 else\r
122                         Global.saveWindowVisible("SplashScreen", false);\r
123                         \r
124                 \r
125                 if (appearancePage.getPdfPreview())\r
126                         Global.setPdfPreview(true);\r
127                 else\r
128                         Global.setPdfPreview(false);\r
129                 \r
130                 if (appearancePage.getNewNoteWithTags())\r
131                         Global.setNewNoteWithSelectedTags(true);\r
132                 else\r
133                         Global.setNewNoteWithSelectedTags(false);\r
134                 \r
135                 Global.setAutoSaveInterval(appearancePage.getAutoSaveInterval());\r
136                                                 \r
137                 Global.setAutomaticLogin(connectionPage.getAutomaticLogin());\r
138                 Global.setRememberPassword(connectionPage.getRememberPassword());\r
139                 if (connectionPage.getRememberPassword()) {     \r
140                         aes.setPassword(connectionPage.getPassword());\r
141                 }\r
142                 Global.setProxyValue("url", connectionPage.getProxyUrl());\r
143                 Global.setProxyValue("port", connectionPage.getProxyPort());\r
144                 Global.setProxyValue("userid", connectionPage.getProxyUserid());\r
145                 Global.setProxyValue("password", connectionPage.getProxyPassword());\r
146                 \r
147                 Global.setShowTrayIcon(appearancePage.getShowTrayIcon());\r
148                 Global.setVerifyDelete(appearancePage.getVerifyDelete());\r
149                 Global.setStartMinimized(appearancePage.getStartMinimized());\r
150                 Global.setSynchronizeOnClose(connectionPage.getSynchronizeOnClose());\r
151                 Global.setSynchronizeDeletedContent(connectionPage.getSynchronizeDeletedContent());\r
152                 Global.setTagBehavior(appearancePage.getTagBehavior());\r
153                 Global.setIndexAttachmentsLocally(indexPage.getIndexAttachmentsLocally());\r
154         FileOutputStream out = null;\r
155                 try {\r
156                         out = new FileOutputStream(Global.getFileManager().getHomeDirFile("secure.txt"));\r
157                 } catch (FileNotFoundException e) {\r
158                         // if it isn't found we'll write it.\r
159                 }\r
160                 if (out != null)\r
161                         aes.encrypt(out);\r
162                 Global.userStoreUrl = "https://"+debugPage.getServer()+"/edam/user";\r
163                 Global.setWordRegex(indexPage.getRegex());\r
164                 Global.setRecognitionWeight(indexPage.getRecognitionWeight());\r
165                 Global.setIndexThreadSleepInterval(indexPage.getSleepInterval());\r
166                 Global.setMessageLevel( debugPage.getDebugLevel());\r
167                 Global.saveCarriageReturnFix(debugPage.getCarriageReturnFix());\r
168                 Global.enableCarriageReturnFix = debugPage.getCarriageReturnFix();\r
169                 \r
170                 Global.setSpellSetting(Configuration.SPELL_IGNOREDIGITWORDS, spellPage.getIgnoreDigitWords());\r
171                 Global.setSpellSetting(Configuration.SPELL_IGNOREINTERNETADDRESSES, spellPage.getIgnoreInternetAddresses());\r
172                 Global.setSpellSetting(Configuration.SPELL_IGNOREMIXEDCASE, spellPage.getIgnoreMixedCase());\r
173                 Global.setSpellSetting(Configuration.SPELL_IGNOREUPPERCASE, spellPage.getIgnoreUpperCase());\r
174                 Global.setSpellSetting(Configuration.SPELL_IGNORESENTENCECAPITALIZATION, spellPage.getIgnoreSentenceCapitalization());\r
175                 \r
176                 String guiFormat = appearancePage.getStyle();\r
177                 QApplication.setStyle(guiFormat);\r
178                 QApplication.style().standardPalette();\r
179                 Global.setStyle(guiFormat);\r
180                 Global.setStandardPalette(appearancePage.getStandardPalette());\r
181                 if (Global.useStandardPalette())\r
182                         QApplication.setPalette(QApplication.style().standardPalette());\r
183                 else\r
184                         QApplication.setPalette(Global.originalPalette);\r
185                 \r
186                 String dateFmt = appearancePage.getDateFormat();\r
187                 String timeFmt = appearancePage.getTimeFormat();\r
188                 int dash = dateFmt.indexOf("-");\r
189                 dateFmt = dateFmt.substring(0,dash-1);\r
190                 dash = timeFmt.indexOf("-");\r
191                 timeFmt = timeFmt.substring(0,dash-1);\r
192                 \r
193                 Global.setDateFormat(dateFmt);\r
194                 Global.setTimeFormat(timeFmt);\r
195                 \r
196                 Global.setSyncInterval(connectionPage.getSyncInterval());\r
197                 \r
198                 Global.setOverrideDefaultFont(fontPage.overrideFont());\r
199                 Global.setDefaultFont(fontPage.getFont());\r
200                 Global.setDefaultFontSize(fontPage.getFontSize());\r
201                                 \r
202                 close();\r
203         }\r
204         @Override\r
205         public void reject() {\r
206                 QApplication.setStyle(Global.getStyle());\r
207                 super.reject();\r
208         }\r
209         \r
210         public ConfigDebugPage getDebugPage() {\r
211                 return debugPage;\r
212         }\r
213         \r
214         \r
215         public ConfigConnectionPage getConfigPage() {\r
216                 return connectionPage;\r
217         }\r
218         \r
219         public void createIcons() {\r
220                 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
221 \r
222                 \r
223                 QListWidgetItem formatsButton = new QListWidgetItem(contentsWidget);\r
224                 formatsButton.setText(tr("Appearance"));\r
225                 formatsButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
226                 formatsButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
227                 formatsButton.setIcon(new QIcon(iconPath+"appearance.jpg"));\r
228                 \r
229                 QListWidgetItem fontButton = new QListWidgetItem(contentsWidget);\r
230                 fontButton.setText(tr("Fonts"));\r
231                 fontButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
232                 fontButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
233                 fontButton.setIcon(new QIcon(iconPath+"fontConfig.png"));\r
234                 \r
235                 QListWidgetItem indexButton = new QListWidgetItem(contentsWidget);\r
236                 indexButton.setText(tr("Indexing"));\r
237                 indexButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
238                 indexButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
239                 indexButton.setIcon(new QIcon(iconPath+"search_config.jpg"));\r
240 \r
241                 QListWidgetItem spellButton = new QListWidgetItem(contentsWidget);\r
242                 spellButton.setText(tr("Spell Check"));\r
243                 spellButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
244                 spellButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
245                 spellButton.setIcon(new QIcon(iconPath+"dictionary.png"));\r
246 \r
247                 QListWidgetItem configButton = new QListWidgetItem(contentsWidget);\r
248                 configButton.setText(tr("Connection"));\r
249                 configButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
250                 configButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
251                 configButton.setIcon(new QIcon(iconPath+"synchronize.png"));\r
252 \r
253                 QListWidgetItem debugButton = new QListWidgetItem(contentsWidget);\r
254                 debugButton.setText(tr("Debugging"));\r
255                 debugButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
256                 debugButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
257                 debugButton.setIcon(new QIcon(iconPath+"debug.jpg"));\r
258                 \r
259                 contentsWidget.currentItemChanged.connect(this, "changePage(QListWidgetItem, QListWidgetItem)");\r
260         }\r
261         \r
262         protected void changePage(QListWidgetItem current, QListWidgetItem previous) {\r
263                 pagesWidget.setCurrentIndex(contentsWidget.row(current));\r
264         }\r
265         \r
266         private void loadSettings() {\r
267                 Global.originalPalette = QApplication.palette();\r
268                 \r
269                 debugPage.setServer(Global.getServer());\r
270                 debugPage.setDisableUploads(Global.disableUploads);\r
271                 debugPage.setEnableThumbnails(Global.enableThumbnails());\r
272 //              if (Global.getUpdateSequenceNumber() > 0)\r
273                         debugPage.serverCombo.setEnabled(false);\r
274                 \r
275                 if (Global.username.equalsIgnoreCase("") || Global.password.equalsIgnoreCase("")) {\r
276                 AESEncrypter aes = new AESEncrypter();\r
277                 try {\r
278                                 aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("secure.txt")));\r
279                         } catch (FileNotFoundException e) {\r
280                                 // File not found, so we'll just get empty strings anyway. \r
281                         }\r
282                         String userid = aes.getUserid();\r
283                         String password = aes.getPassword();\r
284                         if (!userid.equals("") && !password.equals("")) {\r
285                         Global.username = userid;\r
286                         Global.password = password;\r
287                         }                                       \r
288                 }\r
289                 appearancePage.setAutoSaveInterval(Global.getAutoSaveInterval());\r
290                 connectionPage.setUserid(Global.username);\r
291                 connectionPage.setPassword(Global.password);\r
292                 connectionPage.setAutomaticLogin(Global.automaticLogin());\r
293                 connectionPage.setRememberPassword(Global.rememberPassword());\r
294                 appearancePage.setMimicEvernote(Global.getMimicEvernoteInterface());\r
295                 appearancePage.setShowTrayIcon(Global.showTrayIcon());\r
296                 connectionPage.setSynchronizeOnClose(Global.synchronizeOnClose());\r
297                 connectionPage.setSyncronizeDeletedContent(Global.synchronizeDeletedContent());\r
298                 appearancePage.setVerifyDelete(Global.verifyDelete());\r
299                 appearancePage.setStartMinimized(Global.startMinimized());\r
300                 appearancePage.setPdfPreview(Global.pdfPreview());\r
301                 appearancePage.setNewNoteWithTags(Global.newNoteWithSelectedTags());\r
302                 appearancePage.setShowSplashScreen(Global.isWindowVisible("SplashScreen"));\r
303                 appearancePage.setTagBehavior(Global.tagBehavior());\r
304                 appearancePage.setMinimizeOnClose(Global.minimizeOnClose());\r
305                 \r
306                 indexPage.setRegex(Global.getWordRegex());\r
307                 indexPage.setSleepInterval(Global.getIndexThreadSleepInterval());\r
308                 connectionPage.setSyncInterval(Global.getSyncInterval());\r
309                 \r
310                 appearancePage.setDateFormat(Global.getDateFormat());\r
311                 appearancePage.setTimeFormat(Global.getTimeFormat());\r
312                 appearancePage.setStyle(Global.getStyle());\r
313                 appearancePage.setStandardPalette(Global.useStandardPalette());\r
314                                                 \r
315                 debugPage.setDebugLevel(Global.getMessageLevel());\r
316                 debugPage.setCarriageReturnFix(Global.enableCarriageReturnFix());\r
317                 \r
318         }\r
319         \r
320 }\r