OSDN Git Service

uni-gramで日本語全文検索できるように変更。ノートコンテンツとタイトルが対象。日本語全文検索時に日本語がハイライトされない問題を修正。
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / ConfigDialog.java
1 /*\r
2  * This file is part of NixNote/NeighborNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * Copyright 2013 Yuki Takahashi\r
5  * \r
6  * This file may be licensed under the terms of of the\r
7  * GNU General Public License Version 2 (the ``GPL'').\r
8  *\r
9  * Software distributed under the License is distributed\r
10  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
11  * express or implied. See the GPL for the specific language\r
12  * governing rights and limitations.\r
13  *\r
14  * You should have received a copy of the GPL along with this\r
15  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
16  * or write to the Free Software Foundation, Inc.,\r
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
18  *\r
19 */\r
20 \r
21 //**********************************************\r
22 //**********************************************\r
23 //* This dialog is the debugging information \r
24 //* page used in the Edit/Preferences dialog\r
25 //**********************************************\r
26 //**********************************************\r
27 \r
28 package cx.fbn.nevernote.dialog;\r
29 \r
30 import com.swabunga.spell.engine.Configuration;\r
31 import com.trolltech.qt.core.QSize;\r
32 import com.trolltech.qt.core.Qt.AlignmentFlag;\r
33 import com.trolltech.qt.core.Qt.ItemFlag;\r
34 import com.trolltech.qt.gui.QApplication;\r
35 import com.trolltech.qt.gui.QDialog;\r
36 import com.trolltech.qt.gui.QHBoxLayout;\r
37 import com.trolltech.qt.gui.QIcon;\r
38 import com.trolltech.qt.gui.QListView;\r
39 import com.trolltech.qt.gui.QListWidget;\r
40 import com.trolltech.qt.gui.QListWidgetItem;\r
41 import com.trolltech.qt.gui.QPushButton;\r
42 import com.trolltech.qt.gui.QStackedWidget;\r
43 import com.trolltech.qt.gui.QVBoxLayout;\r
44 import com.trolltech.qt.gui.QWidget;\r
45 \r
46 import cx.fbn.nevernote.Global;\r
47 import cx.fbn.nevernote.sql.DatabaseConnection;\r
48 import cx.fbn.nevernote.sql.driver.NSqlQuery;\r
49 public class ConfigDialog extends QDialog {\r
50         private final QListWidget                               contentsWidget;\r
51         private final ConfigFontPage                    fontPage;\r
52         private final QStackedWidget                    pagesWidget;\r
53         private final ConfigConnectionPage              connectionPage;\r
54         private final ConfigDebugPage                   debugPage;\r
55         private final ConfigAppearancePage              appearancePage;\r
56         private final ConfigSpellPage                   spellPage;\r
57         private final ConfigIndexPage                   indexPage;\r
58         // ICHANGED\r
59         private final ConfigRensoNoteListPage           rensoNoteListPage;\r
60         private final DatabaseConnection conn;\r
61         \r
62     private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
63         \r
64         public ConfigDialog(QWidget parent, DatabaseConnection conn) {\r
65                 this.conn = conn;\r
66                 \r
67                 contentsWidget = new QListWidget(this);\r
68                 setWindowIcon(new QIcon(iconPath+"config.png"));\r
69                 contentsWidget.setViewMode(QListView.ViewMode.IconMode);\r
70                 contentsWidget.setIconSize(new QSize(96, 84));\r
71                 contentsWidget.setMovement(QListView.Movement.Static);\r
72                 contentsWidget.setMaximumWidth(128);\r
73                 contentsWidget.setSpacing(12);\r
74                 \r
75                 pagesWidget = new QStackedWidget(this);\r
76                 fontPage = new ConfigFontPage(this);\r
77                 connectionPage = new ConfigConnectionPage(this);\r
78                 appearancePage = new ConfigAppearancePage(this);\r
79                 indexPage = new ConfigIndexPage(this);\r
80                 debugPage = new ConfigDebugPage(this);\r
81                 spellPage = new ConfigSpellPage(this);\r
82                 // ICHANGED\r
83                 rensoNoteListPage = new ConfigRensoNoteListPage(this);\r
84                 \r
85                 pagesWidget.addWidget(appearancePage);\r
86                 pagesWidget.addWidget(fontPage);\r
87                 pagesWidget.addWidget(indexPage);\r
88                 pagesWidget.addWidget(spellPage);\r
89                 pagesWidget.addWidget(connectionPage);\r
90                 pagesWidget.addWidget(debugPage);\r
91                 // ICHANGED\r
92                 pagesWidget.addWidget(rensoNoteListPage);\r
93                 \r
94                 QPushButton cancelButton = new QPushButton(tr("Cancel"));\r
95                 QPushButton okButton = new QPushButton(tr("OK"));\r
96                 okButton.clicked.connect(this, "okPushed()");\r
97                 cancelButton.clicked.connect(this, "close()");\r
98                 \r
99                 createIcons();\r
100                 contentsWidget.setCurrentRow(0);\r
101                 \r
102                 QHBoxLayout horizontalLayout = new QHBoxLayout();\r
103                 horizontalLayout.addWidget(contentsWidget);\r
104                 horizontalLayout.addWidget(pagesWidget,1);\r
105                 \r
106                 QHBoxLayout buttonLayout = new QHBoxLayout();\r
107                 buttonLayout.addStretch(1);\r
108                 buttonLayout.addWidget(okButton);\r
109                 buttonLayout.addWidget(cancelButton);\r
110                 setWindowTitle(tr("Settings")); \r
111                 \r
112                 QVBoxLayout mainLayout = new QVBoxLayout();\r
113                 mainLayout.addLayout(horizontalLayout);\r
114                 mainLayout.addSpacing(1);\r
115                 mainLayout.addLayout(buttonLayout);\r
116                 setLayout(mainLayout);\r
117                 \r
118                 loadSettings();\r
119         }\r
120 \r
121         //******************************************\r
122         //* Ok button is pushed.  Save values\r
123         //******************************************\r
124         public void okPushed() {\r
125                 Global.setServer(debugPage.getServer());\r
126                 Global.setEnableThumbnails(debugPage.getEnableThumbnails());\r
127 \r
128                 \r
129                 if (debugPage.getDisableUploads())\r
130                         Global.disableUploads = true;\r
131                 else\r
132                         Global.disableUploads = false;\r
133                 Global.setDisableUploads(Global.disableUploads);\r
134                 Global.setMimicEvernoteInterface(appearancePage.getMimicEvernote());\r
135                 Global.setMinimizeOnClose(appearancePage.getMinimizeOnClose());\r
136                 \r
137                 if (appearancePage.getShowSplashScreen())\r
138                         Global.saveWindowVisible("SplashScreen", true);\r
139                 else\r
140                         Global.saveWindowVisible("SplashScreen", false);\r
141                         \r
142                 \r
143                 if (appearancePage.getPdfPreview())\r
144                         Global.setPdfPreview(true);\r
145                 else\r
146                         Global.setPdfPreview(false);\r
147 \r
148                 if (appearancePage.getCheckForUpdates())\r
149                         Global.setCheckVersionUpgrade(true);\r
150                 else\r
151                         Global.setCheckVersionUpgrade(false);\r
152 \r
153                 \r
154                 if (appearancePage.getNewNoteWithTags())\r
155                         Global.setNewNoteWithSelectedTags(true);\r
156                 else\r
157                         Global.setNewNoteWithSelectedTags(false);\r
158                 \r
159                 if (appearancePage.getAnyTagSelection())\r
160                         Global.setAnyTagSelectionMatch(true);\r
161                 else\r
162                         Global.setAnyTagSelectionMatch(false);\r
163                 \r
164                 Global.setAutoSaveInterval(appearancePage.getAutoSaveInterval());\r
165                                                 \r
166                 Global.setAutomaticLogin(connectionPage.getAutomaticLogin());\r
167                 Global.setProxyValue("url", connectionPage.getProxyUrl());\r
168                 Global.setProxyValue("port", connectionPage.getProxyPort());\r
169                 Global.setProxyValue("userid", connectionPage.getProxyUserid());\r
170                 Global.setProxyValue("password", connectionPage.getProxyPassword());\r
171                 \r
172                 Global.setShowTrayIcon(appearancePage.getShowTrayIcon());\r
173                 Global.setVerifyDelete(appearancePage.getVerifyDelete());\r
174                 Global.setStartMinimized(appearancePage.getStartMinimized());\r
175                 Global.setSynchronizeOnClose(connectionPage.getSynchronizeOnClose());\r
176                 Global.setSynchronizeDeletedContent(connectionPage.getSynchronizeDeletedContent());\r
177                 Global.setTagBehavior(appearancePage.getTagBehavior());\r
178                 Global.setIndexAttachmentsLocally(indexPage.getIndexAttachmentsLocally());\r
179                 Global.setIndexNoteBody(indexPage.getIndexNoteBody());\r
180                 Global.setIndexNoteTitle(indexPage.getIndexNoteTitle());\r
181                 Global.setIndexImageRecognition(indexPage.getIndexImageRecognition());\r
182                 Global.setAutomaticWildcardSearches(indexPage.getAutomaticWildcardSearches());\r
183                 Global.setSpecialIndexCharacters(indexPage.getSpecialCharacters());\r
184                 Global.setIncludeTagChildren(appearancePage.getIncludeTagChildren());\r
185                 Global.setDisplayRightToLeft(appearancePage.getDisplayRightToLeft());\r
186                 \r
187                 Global.userStoreUrl = "https://"+debugPage.getServer()+"/edam/user";\r
188                 Global.setWordRegex(indexPage.getRegex());\r
189                 Global.setRecognitionWeight(indexPage.getRecognitionWeight());\r
190                 Global.setIndexThreadSleepInterval(indexPage.getSleepInterval());\r
191                 Global.setMessageLevel( debugPage.getDebugLevel());\r
192                 Global.saveCarriageReturnFix(debugPage.getCarriageReturnFix());\r
193                 Global.enableCarriageReturnFix = debugPage.getCarriageReturnFix();\r
194                 Global.saveHtmlEntitiesFix(debugPage.getHtmlEntitiesFix());\r
195                 Global.enableHTMLEntitiesFix = debugPage.getHtmlEntitiesFix();\r
196                 \r
197                 Global.setSpellSetting(Configuration.SPELL_IGNOREDIGITWORDS, spellPage.getIgnoreDigitWords());\r
198                 Global.setSpellSetting(Configuration.SPELL_IGNOREINTERNETADDRESSES, spellPage.getIgnoreInternetAddresses());\r
199                 Global.setSpellSetting(Configuration.SPELL_IGNOREMIXEDCASE, spellPage.getIgnoreMixedCase());\r
200                 Global.setSpellSetting(Configuration.SPELL_IGNOREUPPERCASE, spellPage.getIgnoreUpperCase());\r
201                 Global.setSpellSetting(Configuration.SPELL_IGNORESENTENCECAPITALIZATION, spellPage.getIgnoreSentenceCapitalization());\r
202                 \r
203                 String guiFormat = appearancePage.getStyle();\r
204                 QApplication.setStyle(guiFormat);\r
205                 QApplication.style().standardPalette();\r
206                 Global.setStyle(guiFormat);\r
207                 Global.setStandardPalette(appearancePage.getStandardPalette());\r
208                 if (Global.useStandardPalette())\r
209                         QApplication.setPalette(QApplication.style().standardPalette());\r
210                 else\r
211                         QApplication.setPalette(Global.originalPalette);\r
212                 Global.setStartupNotebook(appearancePage.getStartupNotebook());\r
213                 \r
214                 String dateFmt = appearancePage.getDateFormat();\r
215                 String timeFmt = appearancePage.getTimeFormat();\r
216                 int dash = dateFmt.indexOf("-");\r
217                 dateFmt = dateFmt.substring(0,dash-1);\r
218                 dash = timeFmt.indexOf("-");\r
219                 timeFmt = timeFmt.substring(0,dash-1);\r
220                 \r
221                 Global.setDateFormat(dateFmt);\r
222                 Global.setTimeFormat(timeFmt);\r
223                 \r
224                 Global.setSyncInterval(connectionPage.getSyncInterval());\r
225                 \r
226                 Global.setOverrideDefaultFont(fontPage.overrideFont());\r
227                 Global.setDefaultFont(fontPage.getFont());\r
228                 Global.setDefaultFontSize(fontPage.getFontSize());\r
229                 Global.setDatabaseCache(debugPage.getDatabaseCacheSize());\r
230                 \r
231                 // ICHANGED\r
232                 Global.setBrowseWeight(rensoNoteListPage.getBrowseWeight());\r
233                 Global.setCopyPasteWeight(rensoNoteListPage.getCopyPasteWeight());\r
234                 Global.setAddNewNoteWeight(rensoNoteListPage.getAddNewNoteWeight());\r
235                 Global.setRensoItemClickWeight(rensoNoteListPage.getRensoItemClickWeight());
236                 Global.setSameTagWeight(rensoNoteListPage.getSameTagWeight());
237                 Global.setSameNotebookWeight(rensoNoteListPage.getSameNotebookWeight());\r
238                 \r
239                 // ICHANGED\r
240                 Global.setMergeRensoNote(rensoNoteListPage.getMergeChecked());\r
241                 Global.setDuplicateRensoNote(rensoNoteListPage.getDuplicateChecked());\r
242                 Global.setVerifyExclude(rensoNoteListPage.getVerifyExcludeChecked());\r
243                 Global.setRensoListItemMaximum(rensoNoteListPage.getRensoListItemMaximum());\r
244                 \r
245                 // 全文検索の対象項目を再設定\r
246                 NSqlQuery query = new NSqlQuery(conn.getConnection());\r
247                 query.exec("CALL FTL_DROP_ALL();");     // カラム単位で削除できないので一度全部消して、再構築\r
248                 \r
249                 StringBuilder noteTableTarget = new StringBuilder();\r
250                 if (Global.indexNoteBody()) {\r
251                         noteTableTarget.append("CONTENTTEXT");\r
252                 }\r
253                 if (Global.indexNoteTitle()) {\r
254                         if (noteTableTarget.length() > 0) {\r
255                                 noteTableTarget.append(", ");\r
256                         }\r
257                         noteTableTarget.append("TITLE");\r
258                 }\r
259                 \r
260                 // TODO 他の項目もあとで追加\r
261                 \r
262                 if (noteTableTarget.length() > 0) {\r
263                         query.prepare("CALL FTL_CREATE_INDEX('PUBLIC', 'NOTE', :column);");\r
264                         query.bindValue(":column", noteTableTarget.toString());\r
265                         query.exec();\r
266                 }\r
267                 \r
268                 close();\r
269         }\r
270         \r
271         \r
272         // Reject the current style\r
273         @Override\r
274         public void reject() {\r
275                 QApplication.setStyle(Global.getStyle());\r
276                 super.reject();\r
277         }\r
278         \r
279         //* return the debugging information page\r
280         public ConfigDebugPage getDebugPage() {\r
281                 return debugPage;\r
282         }\r
283         \r
284         // Get the Evernote connection page\r
285         public ConfigConnectionPage getConfigPage() {\r
286                 return connectionPage;\r
287         }\r
288         \r
289         // Create icons used for navigating the page\r
290         public void createIcons() {\r
291                 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
292 \r
293                 \r
294                 QListWidgetItem formatsButton = new QListWidgetItem(contentsWidget);\r
295                 formatsButton.setText(tr("Appearance"));\r
296                 formatsButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
297                 formatsButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
298                 formatsButton.setIcon(new QIcon(iconPath+"appearance.png"));\r
299                 \r
300                 QListWidgetItem fontButton = new QListWidgetItem(contentsWidget);\r
301                 fontButton.setText(tr("Fonts"));\r
302                 fontButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
303                 fontButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
304                 fontButton.setIcon(new QIcon(iconPath+"fontConfig.png"));\r
305                 \r
306                 QListWidgetItem indexButton = new QListWidgetItem(contentsWidget);\r
307                 indexButton.setText(tr("Indexing"));\r
308                 indexButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
309                 indexButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
310                 indexButton.setIcon(new QIcon(iconPath+"search_config.jpg"));\r
311 \r
312                 QListWidgetItem spellButton = new QListWidgetItem(contentsWidget);\r
313                 spellButton.setText(tr("Spell Check"));\r
314                 spellButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
315                 spellButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
316                 spellButton.setIcon(new QIcon(iconPath+"dictionary.png"));\r
317 \r
318                 QListWidgetItem configButton = new QListWidgetItem(contentsWidget);\r
319                 configButton.setText(tr("Connection"));\r
320                 configButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
321                 configButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
322                 configButton.setIcon(new QIcon(iconPath+"synchronize.png"));\r
323 \r
324                 QListWidgetItem debugButton = new QListWidgetItem(contentsWidget);\r
325                 debugButton.setText(tr("Debugging"));\r
326                 debugButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
327                 debugButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
328                 debugButton.setIcon(new QIcon(iconPath+"debug.jpg"));\r
329                 \r
330                 // ICHANGED\r
331                 QListWidgetItem rensoListButton = new QListWidgetItem(contentsWidget);\r
332                 rensoListButton.setText(tr("Renso Note List"));\r
333                 rensoListButton.setTextAlignment(AlignmentFlag.AlignCenter.value());\r
334                 rensoListButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
335                 rensoListButton.setIcon(new QIcon(iconPath+"rensoNoteList.png"));\r
336                 \r
337                 contentsWidget.currentItemChanged.connect(this, "changePage(QListWidgetItem, QListWidgetItem)");\r
338         }\r
339         \r
340         // this is called when the user switches config pages\r
341         protected void changePage(QListWidgetItem current, QListWidgetItem previous) {\r
342                 pagesWidget.setCurrentIndex(contentsWidget.row(current));\r
343         }\r
344         \r
345         // Load initial settings\r
346         private void loadSettings() {\r
347                 Global.originalPalette = QApplication.palette();\r
348                 \r
349                 debugPage.setServer(Global.getServer());\r
350                 debugPage.setDisableUploads(Global.disableUploads);\r
351                 debugPage.setEnableThumbnails(Global.enableThumbnails());\r
352 //              if (Global.getUpdateSequenceNumber() > 0)\r
353                 \r
354                 // ICHANGED\r
355                 // TODO ↓のコメントアウトは最終的に外す(設定のデバッグページのサーバー選択を使用不可にする)\r
356                 //      debugPage.serverCombo.setEnabled(false);\r
357 \r
358                 appearancePage.setAutoSaveInterval(Global.getAutoSaveInterval());\r
359                 connectionPage.setAutomaticLogin(Global.automaticLogin());\r
360                 appearancePage.setMimicEvernote(Global.getMimicEvernoteInterface());\r
361                 appearancePage.setShowTrayIcon(Global.showTrayIcon());\r
362                 connectionPage.setSynchronizeOnClose(Global.synchronizeOnClose());\r
363                 connectionPage.setSyncronizeDeletedContent(Global.synchronizeDeletedContent());\r
364                 appearancePage.setVerifyDelete(Global.verifyDelete());\r
365                 appearancePage.setStartMinimized(Global.startMinimized());\r
366                 appearancePage.setPdfPreview(Global.pdfPreview());\r
367                 appearancePage.setCheckForUpdates(Global.checkVersionUpgrade());\r
368                 appearancePage.setNewNoteWithTags(Global.newNoteWithSelectedTags());\r
369                 appearancePage.setAnyTagSelection(Global.anyTagSelectionMatch());\r
370                 appearancePage.setShowSplashScreen(Global.isWindowVisible("SplashScreen"));\r
371                 appearancePage.setTagBehavior(Global.tagBehavior());\r
372                 appearancePage.setMinimizeOnClose(Global.minimizeOnClose());\r
373                 appearancePage.setIncludeTagChildren(Global.includeTagChildren());\r
374                 appearancePage.setDisplayRightToLeft(Global.displayRightToLeft());\r
375                 appearancePage.setStartupNotebook(Global.getStartupNotebook());\r
376                 \r
377                 indexPage.setRegex(Global.getWordRegex());\r
378                 indexPage.setSleepInterval(Global.getIndexThreadSleepInterval());\r
379                 connectionPage.setSyncInterval(Global.getSyncInterval());\r
380                 \r
381                 appearancePage.setDateFormat(Global.getDateFormat());\r
382                 appearancePage.setTimeFormat(Global.getTimeFormat());\r
383                 appearancePage.setStyle(Global.getStyle());\r
384                 appearancePage.setStandardPalette(Global.useStandardPalette());\r
385                                                 \r
386                 debugPage.setDebugLevel(Global.getMessageLevel());\r
387                 debugPage.setCarriageReturnFix(Global.enableCarriageReturnFix());\r
388                 debugPage.setHtmlEntitiesFix(Global.enableHTMLEntitiesFix);\r
389                 \r
390         }\r
391         \r
392 }\r