OSDN Git Service

1a4cabd3298287787b1f71a0aafea3a97211df1d
[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 public class ConfigDialog extends QDialog {\r
48         private final QListWidget                               contentsWidget;\r
49         private final ConfigFontPage                    fontPage;\r
50         private final QStackedWidget                    pagesWidget;\r
51         private final ConfigConnectionPage              connectionPage;\r
52         private final ConfigDebugPage                   debugPage;\r
53         private final ConfigAppearancePage              appearancePage;\r
54         private final ConfigSpellPage                   spellPage;\r
55         private final ConfigIndexPage                   indexPage;\r
56         // ICHANGED\r
57         private final ConfigRensoNoteListPage           rensoNoteListPage;\r
58         \r
59     private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
60         \r
61         public ConfigDialog(QWidget parent) {\r
62                 \r
63                 contentsWidget = new QListWidget(this);\r
64                 setWindowIcon(new QIcon(iconPath+"config.png"));\r
65                 contentsWidget.setViewMode(QListView.ViewMode.IconMode);\r
66                 contentsWidget.setIconSize(new QSize(96, 84));\r
67                 contentsWidget.setMovement(QListView.Movement.Static);\r
68                 contentsWidget.setMaximumWidth(128);\r
69                 contentsWidget.setSpacing(12);\r
70                 \r
71                 pagesWidget = new QStackedWidget(this);\r
72                 fontPage = new ConfigFontPage(this);\r
73                 connectionPage = new ConfigConnectionPage(this);\r
74                 appearancePage = new ConfigAppearancePage(this);\r
75                 indexPage = new ConfigIndexPage(this);\r
76                 debugPage = new ConfigDebugPage(this);\r
77                 spellPage = new ConfigSpellPage(this);\r
78                 // ICHANGED\r
79                 rensoNoteListPage = new ConfigRensoNoteListPage(this);\r
80                 \r
81                 pagesWidget.addWidget(appearancePage);\r
82                 pagesWidget.addWidget(fontPage);\r
83                 pagesWidget.addWidget(indexPage);\r
84                 pagesWidget.addWidget(spellPage);\r
85                 pagesWidget.addWidget(connectionPage);\r
86                 pagesWidget.addWidget(debugPage);\r
87                 // ICHANGED\r
88                 pagesWidget.addWidget(rensoNoteListPage);\r
89                 \r
90                 QPushButton cancelButton = new QPushButton(tr("Cancel"));\r
91                 QPushButton okButton = new QPushButton(tr("OK"));\r
92                 okButton.clicked.connect(this, "okPushed()");\r
93                 cancelButton.clicked.connect(this, "close()");\r
94                 \r
95                 createIcons();\r
96                 contentsWidget.setCurrentRow(0);\r
97                 \r
98                 QHBoxLayout horizontalLayout = new QHBoxLayout();\r
99                 horizontalLayout.addWidget(contentsWidget);\r
100                 horizontalLayout.addWidget(pagesWidget,1);\r
101                 \r
102                 QHBoxLayout buttonLayout = new QHBoxLayout();\r
103                 buttonLayout.addStretch(1);\r
104                 buttonLayout.addWidget(okButton);\r
105                 buttonLayout.addWidget(cancelButton);\r
106                 setWindowTitle(tr("Settings")); \r
107                 \r
108                 QVBoxLayout mainLayout = new QVBoxLayout();\r
109                 mainLayout.addLayout(horizontalLayout);\r
110                 mainLayout.addSpacing(1);\r
111                 mainLayout.addLayout(buttonLayout);\r
112                 setLayout(mainLayout);\r
113                 \r
114                 loadSettings();\r
115         }\r
116 \r
117         //******************************************\r
118         //* Ok button is pushed.  Save values\r
119         //******************************************\r
120         public void okPushed() {\r
121                 Global.setServer(debugPage.getServer());\r
122                 Global.setEnableThumbnails(debugPage.getEnableThumbnails());\r
123 \r
124                 \r
125                 if (debugPage.getDisableUploads())\r
126                         Global.disableUploads = true;\r
127                 else\r
128                         Global.disableUploads = false;\r
129                 Global.setDisableUploads(Global.disableUploads);\r
130                 Global.setMimicEvernoteInterface(appearancePage.getMimicEvernote());\r
131                 Global.setMinimizeOnClose(appearancePage.getMinimizeOnClose());\r
132                 \r
133                 if (appearancePage.getShowSplashScreen())\r
134                         Global.saveWindowVisible("SplashScreen", true);\r
135                 else\r
136                         Global.saveWindowVisible("SplashScreen", false);\r
137                         \r
138                 \r
139                 if (appearancePage.getPdfPreview())\r
140                         Global.setPdfPreview(true);\r
141                 else\r
142                         Global.setPdfPreview(false);\r
143 \r
144                 if (appearancePage.getCheckForUpdates())\r
145                         Global.setCheckVersionUpgrade(true);\r
146                 else\r
147                         Global.setCheckVersionUpgrade(false);\r
148 \r
149                 \r
150                 if (appearancePage.getNewNoteWithTags())\r
151                         Global.setNewNoteWithSelectedTags(true);\r
152                 else\r
153                         Global.setNewNoteWithSelectedTags(false);\r
154                 \r
155                 if (appearancePage.getAnyTagSelection())\r
156                         Global.setAnyTagSelectionMatch(true);\r
157                 else\r
158                         Global.setAnyTagSelectionMatch(false);\r
159                 \r
160                 Global.setAutoSaveInterval(appearancePage.getAutoSaveInterval());\r
161                                                 \r
162                 Global.setAutomaticLogin(connectionPage.getAutomaticLogin());\r
163                 Global.setProxyValue("url", connectionPage.getProxyUrl());\r
164                 Global.setProxyValue("port", connectionPage.getProxyPort());\r
165                 Global.setProxyValue("userid", connectionPage.getProxyUserid());\r
166                 Global.setProxyValue("password", connectionPage.getProxyPassword());\r
167                 \r
168                 Global.setShowTrayIcon(appearancePage.getShowTrayIcon());\r
169                 Global.setVerifyDelete(appearancePage.getVerifyDelete());\r
170                 Global.setStartMinimized(appearancePage.getStartMinimized());\r
171                 Global.setSynchronizeOnClose(connectionPage.getSynchronizeOnClose());\r
172                 Global.setSynchronizeDeletedContent(connectionPage.getSynchronizeDeletedContent());\r
173                 Global.setTagBehavior(appearancePage.getTagBehavior());\r
174                 Global.setIndexAttachmentsLocally(indexPage.getIndexAttachmentsLocally());\r
175                 Global.setIndexNoteBody(indexPage.getIndexNoteBody());\r
176                 Global.setIndexNoteTitle(indexPage.getIndexNoteTitle());\r
177                 Global.setIndexImageRecognition(indexPage.getIndexImageRecognition());\r
178                 Global.setAutomaticWildcardSearches(indexPage.getAutomaticWildcardSearches());\r
179                 Global.setSpecialIndexCharacters(indexPage.getSpecialCharacters());\r
180                 Global.setIncludeTagChildren(appearancePage.getIncludeTagChildren());\r
181                 Global.setDisplayRightToLeft(appearancePage.getDisplayRightToLeft());\r
182                 \r
183                 Global.userStoreUrl = "https://"+debugPage.getServer()+"/edam/user";\r
184                 Global.setWordRegex(indexPage.getRegex());\r
185                 Global.setRecognitionWeight(indexPage.getRecognitionWeight());\r
186                 Global.setIndexThreadSleepInterval(indexPage.getSleepInterval());\r
187                 Global.setMessageLevel( debugPage.getDebugLevel());\r
188                 Global.saveCarriageReturnFix(debugPage.getCarriageReturnFix());\r
189                 Global.enableCarriageReturnFix = debugPage.getCarriageReturnFix();\r
190                 Global.saveHtmlEntitiesFix(debugPage.getHtmlEntitiesFix());\r
191                 Global.enableHTMLEntitiesFix = debugPage.getHtmlEntitiesFix();\r
192                 \r
193                 Global.setSpellSetting(Configuration.SPELL_IGNOREDIGITWORDS, spellPage.getIgnoreDigitWords());\r
194                 Global.setSpellSetting(Configuration.SPELL_IGNOREINTERNETADDRESSES, spellPage.getIgnoreInternetAddresses());\r
195                 Global.setSpellSetting(Configuration.SPELL_IGNOREMIXEDCASE, spellPage.getIgnoreMixedCase());\r
196                 Global.setSpellSetting(Configuration.SPELL_IGNOREUPPERCASE, spellPage.getIgnoreUpperCase());\r
197                 Global.setSpellSetting(Configuration.SPELL_IGNORESENTENCECAPITALIZATION, spellPage.getIgnoreSentenceCapitalization());\r
198                 \r
199                 String guiFormat = appearancePage.getStyle();\r
200                 QApplication.setStyle(guiFormat);\r
201                 QApplication.style().standardPalette();\r
202                 Global.setStyle(guiFormat);\r
203                 Global.setStandardPalette(appearancePage.getStandardPalette());\r
204                 if (Global.useStandardPalette())\r
205                         QApplication.setPalette(QApplication.style().standardPalette());\r
206                 else\r
207                         QApplication.setPalette(Global.originalPalette);\r
208                 Global.setStartupNotebook(appearancePage.getStartupNotebook());\r
209                 \r
210                 String dateFmt = appearancePage.getDateFormat();\r
211                 String timeFmt = appearancePage.getTimeFormat();\r
212                 int dash = dateFmt.indexOf("-");\r
213                 dateFmt = dateFmt.substring(0,dash-1);\r
214                 dash = timeFmt.indexOf("-");\r
215                 timeFmt = timeFmt.substring(0,dash-1);\r
216                 \r
217                 Global.setDateFormat(dateFmt);\r
218                 Global.setTimeFormat(timeFmt);\r
219                 \r
220                 Global.setSyncInterval(connectionPage.getSyncInterval());\r
221                 \r
222                 Global.setOverrideDefaultFont(fontPage.overrideFont());\r
223                 Global.setDefaultFont(fontPage.getFont());\r
224                 Global.setDefaultFontSize(fontPage.getFontSize());\r
225                 Global.setDatabaseCache(debugPage.getDatabaseCacheSize());\r
226                 \r
227                 // ICHANGED\r
228                 Global.setBrowseWeight(rensoNoteListPage.getBrowseWeight());\r
229                 Global.setCopyPasteWeight(rensoNoteListPage.getCopyPasteWeight());\r
230                 Global.setAddNewNoteWeight(rensoNoteListPage.getAddNewNoteWeight());\r
231                 Global.setRensoItemClickWeight(rensoNoteListPage.getRensoItemClickWeight());
232                 Global.setSameTagWeight(rensoNoteListPage.getSameTagWeight());
233                 Global.setSameNotebookWeight(rensoNoteListPage.getSameNotebookWeight());\r
234                 \r
235                 // ICHANGED\r
236                 Global.setMergeRensoNote(rensoNoteListPage.getMergeChecked());\r
237                 Global.setDuplicateRensoNote(rensoNoteListPage.getDuplicateChecked());\r
238                 Global.setVerifyExclude(rensoNoteListPage.getVerifyExcludeChecked());\r
239                 Global.setRensoListItemMaximum(rensoNoteListPage.getRensoListItemMaximum());\r
240                 \r
241                 close();\r
242         }\r
243         \r
244         \r
245         // Reject the current style\r
246         @Override\r
247         public void reject() {\r
248                 QApplication.setStyle(Global.getStyle());\r
249                 super.reject();\r
250         }\r
251         \r
252         //* return the debugging information page\r
253         public ConfigDebugPage getDebugPage() {\r
254                 return debugPage;\r
255         }\r
256         \r
257         // Get the Evernote connection page\r
258         public ConfigConnectionPage getConfigPage() {\r
259                 return connectionPage;\r
260         }\r
261         \r
262         // Create icons used for navigating the page\r
263         public void createIcons() {\r
264                 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
265 \r
266                 \r
267                 QListWidgetItem formatsButton = new QListWidgetItem(contentsWidget);\r
268                 formatsButton.setText(tr("Appearance"));\r
269                 formatsButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
270                 formatsButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
271                 formatsButton.setIcon(new QIcon(iconPath+"appearance.png"));\r
272                 \r
273                 QListWidgetItem fontButton = new QListWidgetItem(contentsWidget);\r
274                 fontButton.setText(tr("Fonts"));\r
275                 fontButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
276                 fontButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
277                 fontButton.setIcon(new QIcon(iconPath+"fontConfig.png"));\r
278                 \r
279                 QListWidgetItem indexButton = new QListWidgetItem(contentsWidget);\r
280                 indexButton.setText(tr("Indexing"));\r
281                 indexButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
282                 indexButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
283                 indexButton.setIcon(new QIcon(iconPath+"search_config.jpg"));\r
284 \r
285                 QListWidgetItem spellButton = new QListWidgetItem(contentsWidget);\r
286                 spellButton.setText(tr("Spell Check"));\r
287                 spellButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
288                 spellButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
289                 spellButton.setIcon(new QIcon(iconPath+"dictionary.png"));\r
290 \r
291                 QListWidgetItem configButton = new QListWidgetItem(contentsWidget);\r
292                 configButton.setText(tr("Connection"));\r
293                 configButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
294                 configButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
295                 configButton.setIcon(new QIcon(iconPath+"synchronize.png"));\r
296 \r
297                 QListWidgetItem debugButton = new QListWidgetItem(contentsWidget);\r
298                 debugButton.setText(tr("Debugging"));\r
299                 debugButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
300                 debugButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
301                 debugButton.setIcon(new QIcon(iconPath+"debug.jpg"));\r
302                 \r
303                 // ICHANGED\r
304                 QListWidgetItem rensoListButton = new QListWidgetItem(contentsWidget);\r
305                 rensoListButton.setText(tr("Renso Note List"));\r
306                 rensoListButton.setTextAlignment(AlignmentFlag.AlignCenter.value());\r
307                 rensoListButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
308                 rensoListButton.setIcon(new QIcon(iconPath+"rensoNoteList.png"));\r
309                 \r
310                 contentsWidget.currentItemChanged.connect(this, "changePage(QListWidgetItem, QListWidgetItem)");\r
311         }\r
312         \r
313         // this is called when the user switches config pages\r
314         protected void changePage(QListWidgetItem current, QListWidgetItem previous) {\r
315                 pagesWidget.setCurrentIndex(contentsWidget.row(current));\r
316         }\r
317         \r
318         // Load initial settings\r
319         private void loadSettings() {\r
320                 Global.originalPalette = QApplication.palette();\r
321                 \r
322                 debugPage.setServer(Global.getServer());\r
323                 debugPage.setDisableUploads(Global.disableUploads);\r
324                 debugPage.setEnableThumbnails(Global.enableThumbnails());\r
325 //              if (Global.getUpdateSequenceNumber() > 0)\r
326                 \r
327                 // ICHANGED\r
328                 // TODO ↓のコメントアウトは最終的に外す(設定のデバッグページのサーバー選択を使用不可にする)\r
329                 //      debugPage.serverCombo.setEnabled(false);\r
330 \r
331                 appearancePage.setAutoSaveInterval(Global.getAutoSaveInterval());\r
332                 connectionPage.setAutomaticLogin(Global.automaticLogin());\r
333                 appearancePage.setMimicEvernote(Global.getMimicEvernoteInterface());\r
334                 appearancePage.setShowTrayIcon(Global.showTrayIcon());\r
335                 connectionPage.setSynchronizeOnClose(Global.synchronizeOnClose());\r
336                 connectionPage.setSyncronizeDeletedContent(Global.synchronizeDeletedContent());\r
337                 appearancePage.setVerifyDelete(Global.verifyDelete());\r
338                 appearancePage.setStartMinimized(Global.startMinimized());\r
339                 appearancePage.setPdfPreview(Global.pdfPreview());\r
340                 appearancePage.setCheckForUpdates(Global.checkVersionUpgrade());\r
341                 appearancePage.setNewNoteWithTags(Global.newNoteWithSelectedTags());\r
342                 appearancePage.setAnyTagSelection(Global.anyTagSelectionMatch());\r
343                 appearancePage.setShowSplashScreen(Global.isWindowVisible("SplashScreen"));\r
344                 appearancePage.setTagBehavior(Global.tagBehavior());\r
345                 appearancePage.setMinimizeOnClose(Global.minimizeOnClose());\r
346                 appearancePage.setIncludeTagChildren(Global.includeTagChildren());\r
347                 appearancePage.setDisplayRightToLeft(Global.displayRightToLeft());\r
348                 appearancePage.setStartupNotebook(Global.getStartupNotebook());\r
349                 \r
350                 indexPage.setRegex(Global.getWordRegex());\r
351                 indexPage.setSleepInterval(Global.getIndexThreadSleepInterval());\r
352                 connectionPage.setSyncInterval(Global.getSyncInterval());\r
353                 \r
354                 appearancePage.setDateFormat(Global.getDateFormat());\r
355                 appearancePage.setTimeFormat(Global.getTimeFormat());\r
356                 appearancePage.setStyle(Global.getStyle());\r
357                 appearancePage.setStandardPalette(Global.useStandardPalette());\r
358                                                 \r
359                 debugPage.setDebugLevel(Global.getMessageLevel());\r
360                 debugPage.setCarriageReturnFix(Global.enableCarriageReturnFix());\r
361                 debugPage.setHtmlEntitiesFix(Global.enableHTMLEntitiesFix);\r
362                 \r
363         }\r
364         \r
365 }\r