OSDN Git Service

ツールバーの「新規」ボタンを押した時にノートを新しいタブで開けるように変更した
[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 \r
45 import cx.fbn.nevernote.Global;\r
46 import cx.fbn.nevernote.NeverNote;\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         private final ConfigRensoNoteListPage   rensoNoteListPage;\r
59         private final NeverNote                                 parent;\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(NeverNote parent, DatabaseConnection conn) {\r
65                 this.parent = parent;\r
66                 this.conn = conn;\r
67                 \r
68                 contentsWidget = new QListWidget(this);\r
69                 setWindowIcon(new QIcon(iconPath+"config.png"));\r
70                 contentsWidget.setViewMode(QListView.ViewMode.IconMode);\r
71                 contentsWidget.setIconSize(new QSize(96, 84));\r
72                 contentsWidget.setMovement(QListView.Movement.Static);\r
73                 contentsWidget.setMaximumWidth(128);\r
74                 contentsWidget.setSpacing(12);\r
75                 \r
76                 pagesWidget = new QStackedWidget(this);\r
77                 fontPage = new ConfigFontPage(this);\r
78                 connectionPage = new ConfigConnectionPage(this);\r
79                 appearancePage = new ConfigAppearancePage(this);\r
80                 indexPage = new ConfigIndexPage(this);\r
81                 debugPage = new ConfigDebugPage(this);\r
82                 spellPage = new ConfigSpellPage(this);\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                 pagesWidget.addWidget(rensoNoteListPage);\r
92                 \r
93                 QPushButton cancelButton = new QPushButton(tr("Cancel"));\r
94                 QPushButton okButton = new QPushButton(tr("OK"));\r
95                 okButton.clicked.connect(this, "okPushed()");\r
96                 cancelButton.clicked.connect(this, "close()");\r
97                 \r
98                 createIcons();\r
99                 contentsWidget.setCurrentRow(0);\r
100                 \r
101                 QHBoxLayout horizontalLayout = new QHBoxLayout();\r
102                 horizontalLayout.addWidget(contentsWidget);\r
103                 horizontalLayout.addWidget(pagesWidget,1);\r
104                 \r
105                 QHBoxLayout buttonLayout = new QHBoxLayout();\r
106                 buttonLayout.addStretch(1);\r
107                 buttonLayout.addWidget(okButton);\r
108                 buttonLayout.addWidget(cancelButton);\r
109                 setWindowTitle(tr("Settings")); \r
110                 \r
111                 QVBoxLayout mainLayout = new QVBoxLayout();\r
112                 mainLayout.addLayout(horizontalLayout);\r
113                 mainLayout.addSpacing(1);\r
114                 mainLayout.addLayout(buttonLayout);\r
115                 setLayout(mainLayout);\r
116                 \r
117                 loadSettings();\r
118         }\r
119 \r
120         //******************************************\r
121         //* Ok button is pushed.  Save values\r
122         //******************************************\r
123         public void okPushed() {\r
124                 Global.setServer(debugPage.getServer());\r
125                 Global.setEnableThumbnails(debugPage.getEnableThumbnails());\r
126 \r
127                 \r
128                 if (debugPage.getDisableUploads())\r
129                         Global.disableUploads = true;\r
130                 else\r
131                         Global.disableUploads = false;\r
132                 Global.setDisableUploads(Global.disableUploads);\r
133                 Global.setMimicEvernoteInterface(appearancePage.getMimicEvernote());\r
134                 Global.setMinimizeOnClose(appearancePage.getMinimizeOnClose());\r
135                 \r
136                 if (appearancePage.getShowSplashScreen())\r
137                         Global.saveWindowVisible("SplashScreen", true);\r
138                 else\r
139                         Global.saveWindowVisible("SplashScreen", false);\r
140                         \r
141                 \r
142                 if (appearancePage.getPdfPreview())\r
143                         Global.setPdfPreview(true);\r
144                 else\r
145                         Global.setPdfPreview(false);\r
146 \r
147                 if (appearancePage.getCheckForUpdates())\r
148                         Global.setCheckVersionUpgrade(true);\r
149                 else\r
150                         Global.setCheckVersionUpgrade(false);\r
151                 \r
152                 if (appearancePage.getNewAction())\r
153                         Global.setToolBarNewAction(true);\r
154                 else\r
155                         Global.setToolBarNewAction(false);\r
156 \r
157                 \r
158                 if (appearancePage.getNewNoteWithTags())\r
159                         Global.setNewNoteWithSelectedTags(true);\r
160                 else\r
161                         Global.setNewNoteWithSelectedTags(false);\r
162                 \r
163                 if (appearancePage.getAnyTagSelection())\r
164                         Global.setAnyTagSelectionMatch(true);\r
165                 else\r
166                         Global.setAnyTagSelectionMatch(false);\r
167                 \r
168                 Global.setAutoSaveInterval(appearancePage.getAutoSaveInterval());\r
169                                                 \r
170                 Global.setAutomaticLogin(connectionPage.getAutomaticLogin());\r
171                 Global.setProxyValue("url", connectionPage.getProxyUrl());\r
172                 Global.setProxyValue("port", connectionPage.getProxyPort());\r
173                 Global.setProxyValue("userid", connectionPage.getProxyUserid());\r
174                 Global.setProxyValue("password", connectionPage.getProxyPassword());\r
175                 \r
176                 Global.setShowTrayIcon(appearancePage.getShowTrayIcon());\r
177                 Global.setVerifyDelete(appearancePage.getVerifyDelete());\r
178                 Global.setStartMinimized(appearancePage.getStartMinimized());\r
179                 Global.setSynchronizeOnClose(connectionPage.getSynchronizeOnClose());\r
180                 Global.setSynchronizeDeletedContent(connectionPage.getSynchronizeDeletedContent());\r
181                 Global.setTagBehavior(appearancePage.getTagBehavior());\r
182                 Global.setIndexAttachmentsLocally(indexPage.getIndexAttachmentsLocally());\r
183                 Global.setIndexNoteBody(indexPage.getIndexNoteBody());\r
184                 Global.setIndexNoteTitle(indexPage.getIndexNoteTitle());\r
185                 Global.setIndexImageRecognition(indexPage.getIndexImageRecognition());\r
186 //              Global.setAutomaticWildcardSearches(indexPage.getAutomaticWildcardSearches());\r
187 //              Global.setSpecialIndexCharacters(indexPage.getSpecialCharacters());\r
188                 Global.setIncludeTagChildren(appearancePage.getIncludeTagChildren());\r
189                 Global.setDisplayRightToLeft(appearancePage.getDisplayRightToLeft());\r
190                 \r
191                 Global.userStoreUrl = "https://"+debugPage.getServer()+"/edam/user";\r
192 //              Global.setWordRegex(indexPage.getRegex());\r
193                 Global.setRecognitionWeight(indexPage.getRecognitionWeight());\r
194                 Global.setIndexThreadSleepInterval(indexPage.getSleepInterval());\r
195                 Global.setMessageLevel( debugPage.getDebugLevel());\r
196                 Global.saveCarriageReturnFix(debugPage.getCarriageReturnFix());\r
197                 Global.enableCarriageReturnFix = debugPage.getCarriageReturnFix();\r
198                 Global.saveHtmlEntitiesFix(debugPage.getHtmlEntitiesFix());\r
199                 Global.enableHTMLEntitiesFix = debugPage.getHtmlEntitiesFix();\r
200                 \r
201                 Global.setSpellSetting(Configuration.SPELL_IGNOREDIGITWORDS, spellPage.getIgnoreDigitWords());\r
202                 Global.setSpellSetting(Configuration.SPELL_IGNOREINTERNETADDRESSES, spellPage.getIgnoreInternetAddresses());\r
203                 Global.setSpellSetting(Configuration.SPELL_IGNOREMIXEDCASE, spellPage.getIgnoreMixedCase());\r
204                 Global.setSpellSetting(Configuration.SPELL_IGNOREUPPERCASE, spellPage.getIgnoreUpperCase());\r
205                 Global.setSpellSetting(Configuration.SPELL_IGNORESENTENCECAPITALIZATION, spellPage.getIgnoreSentenceCapitalization());\r
206                 \r
207                 String guiFormat = appearancePage.getStyle();\r
208                 QApplication.setStyle(guiFormat);\r
209                 QApplication.style().standardPalette();\r
210                 Global.setStyle(guiFormat);\r
211                 Global.setStandardPalette(appearancePage.getStandardPalette());\r
212                 if (Global.useStandardPalette())\r
213                         QApplication.setPalette(QApplication.style().standardPalette());\r
214                 else\r
215                         QApplication.setPalette(Global.originalPalette);\r
216                 Global.setStartupNotebook(appearancePage.getStartupNotebook());\r
217                 \r
218                 String dateFmt = appearancePage.getDateFormat();\r
219                 String timeFmt = appearancePage.getTimeFormat();\r
220                 int dash = dateFmt.indexOf("-");\r
221                 dateFmt = dateFmt.substring(0,dash-1);\r
222                 dash = timeFmt.indexOf("-");\r
223                 timeFmt = timeFmt.substring(0,dash-1);\r
224                 \r
225                 Global.setDateFormat(dateFmt);\r
226                 Global.setTimeFormat(timeFmt);\r
227                 \r
228                 Global.setSyncInterval(connectionPage.getSyncInterval());\r
229                 \r
230                 Global.setOverrideDefaultFont(fontPage.overrideFont());\r
231                 Global.setDefaultFont(fontPage.getFont());\r
232                 Global.setDefaultFontSize(fontPage.getFontSize());\r
233                 Global.setDatabaseCache(debugPage.getDatabaseCacheSize());\r
234                 \r
235                 Global.setBrowseWeight(rensoNoteListPage.getBrowseWeight());\r
236                 Global.setCopyPasteWeight(rensoNoteListPage.getCopyPasteWeight());\r
237                 Global.setAddNewNoteWeight(rensoNoteListPage.getAddNewNoteWeight());\r
238                 Global.setRensoItemClickWeight(rensoNoteListPage.getRensoItemClickWeight());\r
239                 Global.setSameTagWeight(rensoNoteListPage.getSameTagWeight());\r
240                 Global.setSameNotebookWeight(rensoNoteListPage.getSameNotebookWeight());\r
241                 Global.setENRelatedNotesWeight(rensoNoteListPage.getENRelatedNotesWeight());\r
242                 \r
243                 // 現在カスタムモードなら、カスタムモードの設定値として保存\r
244                 String mode = new String(Global.rensoWeightingSelect());\r
245                 if (mode.equals("Custom")) {\r
246                         Global.saveCustomBrowseWeight(rensoNoteListPage.getBrowseWeight());\r
247                         Global.saveCustomCopyPasteWeight(rensoNoteListPage.getCopyPasteWeight());\r
248                         Global.saveCustomAddNewNoteWeight(rensoNoteListPage.getAddNewNoteWeight());\r
249                         Global.saveCustomRensoItemClickWeight(rensoNoteListPage.getRensoItemClickWeight());\r
250                         Global.saveCustomSameTagWeight(rensoNoteListPage.getSameTagWeight());\r
251                         Global.saveCustomSameNotebookWeight(rensoNoteListPage.getSameNotebookWeight());\r
252                         Global.saveCustomENRelatedNotesWeight(rensoNoteListPage.getENRelatedNotesWeight());\r
253                 }\r
254                 \r
255                 Global.setMergeRensoNote(rensoNoteListPage.getMergeChecked());\r
256                 Global.setDuplicateRensoNote(rensoNoteListPage.getDuplicateChecked());\r
257                 Global.setVerifyExclude(rensoNoteListPage.getVerifyExcludeChecked());\r
258                 Global.setRensoListItemMaximum(rensoNoteListPage.getRensoListItemMaximum());\r
259                 \r
260                 // 連想ノートリストをリフレッシュ\r
261                 parent.getRensoNoteList().refreshRensoNoteList(parent.getCurrentNoteGuid());\r
262                 \r
263                 // 全文検索の対象項目を再設定\r
264                 NSqlQuery nQuery = new NSqlQuery(conn.getConnection());\r
265                 NSqlQuery rQuery = new NSqlQuery(conn.getResourceConnection()); \r
266                 // カラム単位で削除できないので一度全部消す\r
267                 nQuery.exec("CALL FTL_DROP_ALL();");\r
268                 rQuery.exec("CALL FTL_DROP_ALL();");\r
269                 // 再構築\r
270                 Global.rebuildFullTextNoteTarget(conn);\r
271                 Global.rebuildFullTextResourceTarget(conn);\r
272                 \r
273                 // ツールバーの「新規」ボタンを押した時の動作を再設定\r
274         if (Global.toolBarNewAction()) {\r
275                 parent.connectNewButtonSlot("noteAddNewTab()");\r
276         } else {\r
277                 parent.connectNewButtonSlot("addNote()");\r
278         }\r
279                 \r
280                 close();\r
281         }\r
282         \r
283         \r
284         // Reject the current style\r
285         @Override\r
286         public void reject() {\r
287                 QApplication.setStyle(Global.getStyle());\r
288                 super.reject();\r
289         }\r
290         \r
291         //* return the debugging information page\r
292         public ConfigDebugPage getDebugPage() {\r
293                 return debugPage;\r
294         }\r
295         \r
296         // Get the Evernote connection page\r
297         public ConfigConnectionPage getConfigPage() {\r
298                 return connectionPage;\r
299         }\r
300         \r
301         // Create icons used for navigating the page\r
302         public void createIcons() {\r
303                 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
304                 \r
305                 QListWidgetItem formatsButton = new QListWidgetItem(contentsWidget);\r
306                 formatsButton.setText(tr("Appearance"));\r
307                 formatsButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
308                 formatsButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
309                 formatsButton.setIcon(new QIcon(iconPath+"appearance.png"));\r
310                 \r
311                 QListWidgetItem fontButton = new QListWidgetItem(contentsWidget);\r
312                 fontButton.setText(tr("Fonts"));\r
313                 fontButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
314                 fontButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
315                 fontButton.setIcon(new QIcon(iconPath+"fontConfig.png"));\r
316                 \r
317                 QListWidgetItem indexButton = new QListWidgetItem(contentsWidget);\r
318                 indexButton.setText(tr("Indexing"));\r
319                 indexButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
320                 indexButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
321                 indexButton.setIcon(new QIcon(iconPath+"search_config.jpg"));\r
322 \r
323                 QListWidgetItem spellButton = new QListWidgetItem(contentsWidget);\r
324                 spellButton.setText(tr("Spell Check"));\r
325                 spellButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
326                 spellButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
327                 spellButton.setIcon(new QIcon(iconPath+"dictionary.png"));\r
328 \r
329                 QListWidgetItem configButton = new QListWidgetItem(contentsWidget);\r
330                 configButton.setText(tr("Connection"));\r
331                 configButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
332                 configButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
333                 configButton.setIcon(new QIcon(iconPath+"synchronize.png"));\r
334 \r
335                 QListWidgetItem debugButton = new QListWidgetItem(contentsWidget);\r
336                 debugButton.setText(tr("Debugging"));\r
337                 debugButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
338                 debugButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
339                 debugButton.setIcon(new QIcon(iconPath+"debug.jpg"));\r
340                 \r
341                 QListWidgetItem rensoListButton = new QListWidgetItem(contentsWidget);\r
342                 rensoListButton.setText(tr("Renso Note List"));\r
343                 rensoListButton.setTextAlignment(AlignmentFlag.AlignCenter.value());\r
344                 rensoListButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
345                 rensoListButton.setIcon(new QIcon(iconPath+"rensoNoteList.png"));\r
346                 \r
347                 contentsWidget.currentItemChanged.connect(this, "changePage(QListWidgetItem, QListWidgetItem)");\r
348         }\r
349         \r
350         // this is called when the user switches config pages\r
351         protected void changePage(QListWidgetItem current, QListWidgetItem previous) {\r
352                 pagesWidget.setCurrentIndex(contentsWidget.row(current));\r
353         }\r
354         \r
355         // Load initial settings\r
356         private void loadSettings() {\r
357                 Global.originalPalette = QApplication.palette();\r
358                 \r
359                 debugPage.setServer(Global.getServer());\r
360                 debugPage.setDisableUploads(Global.disableUploads);\r
361                 debugPage.setEnableThumbnails(Global.enableThumbnails());\r
362 //              if (Global.getUpdateSequenceNumber() > 0)\r
363                 \r
364                 // TODO ↓のコメントアウトは最終的に外す(設定のデバッグページのサーバー選択を使用不可にする)\r
365                 //      debugPage.serverCombo.setEnabled(false);\r
366 \r
367                 appearancePage.setAutoSaveInterval(Global.getAutoSaveInterval());\r
368                 connectionPage.setAutomaticLogin(Global.automaticLogin());\r
369                 appearancePage.setMimicEvernote(Global.getMimicEvernoteInterface());\r
370                 appearancePage.setShowTrayIcon(Global.showTrayIcon());\r
371                 connectionPage.setSynchronizeOnClose(Global.synchronizeOnClose());\r
372                 connectionPage.setSyncronizeDeletedContent(Global.synchronizeDeletedContent());\r
373                 appearancePage.setVerifyDelete(Global.verifyDelete());\r
374                 appearancePage.setStartMinimized(Global.startMinimized());\r
375                 appearancePage.setPdfPreview(Global.pdfPreview());\r
376                 appearancePage.setCheckForUpdates(Global.checkVersionUpgrade());\r
377                 appearancePage.setNewNoteWithTags(Global.newNoteWithSelectedTags());\r
378                 appearancePage.setAnyTagSelection(Global.anyTagSelectionMatch());\r
379                 appearancePage.setShowSplashScreen(Global.isWindowVisible("SplashScreen"));\r
380                 appearancePage.setTagBehavior(Global.tagBehavior());\r
381                 appearancePage.setMinimizeOnClose(Global.minimizeOnClose());\r
382                 appearancePage.setIncludeTagChildren(Global.includeTagChildren());\r
383                 appearancePage.setDisplayRightToLeft(Global.displayRightToLeft());\r
384                 appearancePage.setStartupNotebook(Global.getStartupNotebook());\r
385                 appearancePage.setNewAction(Global.toolBarNewAction());\r
386                 \r
387 //              indexPage.setRegex(Global.getWordRegex());\r
388                 indexPage.setSleepInterval(Global.getIndexThreadSleepInterval());\r
389                 connectionPage.setSyncInterval(Global.getSyncInterval());\r
390                 \r
391                 appearancePage.setDateFormat(Global.getDateFormat());\r
392                 appearancePage.setTimeFormat(Global.getTimeFormat());\r
393                 appearancePage.setStyle(Global.getStyle());\r
394                 appearancePage.setStandardPalette(Global.useStandardPalette());\r
395                                                 \r
396                 debugPage.setDebugLevel(Global.getMessageLevel());\r
397                 debugPage.setCarriageReturnFix(Global.enableCarriageReturnFix());\r
398                 debugPage.setHtmlEntitiesFix(Global.enableHTMLEntitiesFix);\r
399                 \r
400         }\r
401         \r
402 }\r