2 * This file is part of NixNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\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
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
20 //**********************************************
\r
21 //**********************************************
\r
22 //* This dialog is the debugging information
\r
23 //* page used in the Edit/Preferences dialog
\r
24 //**********************************************
\r
25 //**********************************************
\r
27 package cx.fbn.nevernote.dialog;
\r
29 import java.io.FileInputStream;
\r
30 import java.io.FileNotFoundException;
\r
31 import java.io.FileOutputStream;
\r
33 import com.swabunga.spell.engine.Configuration;
\r
34 import com.trolltech.qt.core.QSize;
\r
35 import com.trolltech.qt.core.Qt.AlignmentFlag;
\r
36 import com.trolltech.qt.core.Qt.ItemFlag;
\r
37 import com.trolltech.qt.gui.QApplication;
\r
38 import com.trolltech.qt.gui.QDialog;
\r
39 import com.trolltech.qt.gui.QHBoxLayout;
\r
40 import com.trolltech.qt.gui.QIcon;
\r
41 import com.trolltech.qt.gui.QListView;
\r
42 import com.trolltech.qt.gui.QListWidget;
\r
43 import com.trolltech.qt.gui.QListWidgetItem;
\r
44 import com.trolltech.qt.gui.QPushButton;
\r
45 import com.trolltech.qt.gui.QStackedWidget;
\r
46 import com.trolltech.qt.gui.QVBoxLayout;
\r
47 import com.trolltech.qt.gui.QWidget;
\r
49 import cx.fbn.nevernote.Global;
\r
50 import cx.fbn.nevernote.utilities.AESEncrypter;
\r
51 public class ConfigDialog extends QDialog {
\r
52 private final QListWidget contentsWidget;
\r
53 private final ConfigFontPage fontPage;
\r
54 private final QStackedWidget pagesWidget;
\r
55 private final ConfigConnectionPage connectionPage;
\r
56 private final ConfigDebugPage debugPage;
\r
57 private final ConfigAppearancePage appearancePage;
\r
58 private final ConfigSpellPage spellPage;
\r
59 private final ConfigIndexPage indexPage;
\r
60 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
62 public ConfigDialog(QWidget parent) {
\r
64 contentsWidget = new QListWidget(this);
\r
65 setWindowIcon(new QIcon(iconPath+"config.png"));
\r
66 contentsWidget.setViewMode(QListView.ViewMode.IconMode);
\r
67 contentsWidget.setIconSize(new QSize(96, 84));
\r
68 contentsWidget.setMovement(QListView.Movement.Static);
\r
69 contentsWidget.setMaximumWidth(128);
\r
70 contentsWidget.setSpacing(12);
\r
72 pagesWidget = new QStackedWidget(this);
\r
73 fontPage = new ConfigFontPage(this);
\r
74 connectionPage = new ConfigConnectionPage(this);
\r
75 appearancePage = new ConfigAppearancePage(this);
\r
76 indexPage = new ConfigIndexPage(this);
\r
77 debugPage = new ConfigDebugPage(this);
\r
78 spellPage = new ConfigSpellPage(this);
\r
79 pagesWidget.addWidget(appearancePage);
\r
80 pagesWidget.addWidget(fontPage);
\r
81 pagesWidget.addWidget(indexPage);
\r
82 pagesWidget.addWidget(spellPage);
\r
83 pagesWidget.addWidget(connectionPage);
\r
84 pagesWidget.addWidget(debugPage);
\r
86 QPushButton cancelButton = new QPushButton(tr("Cancel"));
\r
87 QPushButton okButton = new QPushButton(tr("OK"));
\r
88 okButton.clicked.connect(this, "okPushed()");
\r
89 cancelButton.clicked.connect(this, "close()");
\r
92 contentsWidget.setCurrentRow(0);
\r
94 QHBoxLayout horizontalLayout = new QHBoxLayout();
\r
95 horizontalLayout.addWidget(contentsWidget);
\r
96 horizontalLayout.addWidget(pagesWidget,1);
\r
98 QHBoxLayout buttonLayout = new QHBoxLayout();
\r
99 buttonLayout.addStretch(1);
\r
100 buttonLayout.addWidget(okButton);
\r
101 buttonLayout.addWidget(cancelButton);
\r
102 setWindowTitle(tr("Settings"));
\r
104 QVBoxLayout mainLayout = new QVBoxLayout();
\r
105 mainLayout.addLayout(horizontalLayout);
\r
106 mainLayout.addSpacing(1);
\r
107 mainLayout.addLayout(buttonLayout);
\r
108 setLayout(mainLayout);
\r
113 //******************************************
\r
114 //* Ok button is pushed. Save values
\r
115 //******************************************
\r
116 public void okPushed() {
\r
117 Global.setServer(debugPage.getServer());
\r
118 Global.setEnableThumbnails(debugPage.getEnableThumbnails());
\r
119 AESEncrypter aes = new AESEncrypter();
\r
120 aes.setUserid(connectionPage.getUserid().trim());
\r
122 if (debugPage.getDisableUploads())
\r
123 Global.disableUploads = true;
\r
125 Global.disableUploads = false;
\r
126 Global.setDisableUploads(Global.disableUploads);
\r
127 Global.setMimicEvernoteInterface(appearancePage.getMimicEvernote());
\r
128 Global.setMinimizeOnClose(appearancePage.getMinimizeOnClose());
\r
130 if (appearancePage.getShowSplashScreen())
\r
131 Global.saveWindowVisible("SplashScreen", true);
\r
133 Global.saveWindowVisible("SplashScreen", false);
\r
136 if (appearancePage.getPdfPreview())
\r
137 Global.setPdfPreview(true);
\r
139 Global.setPdfPreview(false);
\r
141 if (appearancePage.getCheckForUpdates())
\r
142 Global.setCheckVersionUpgrade(true);
\r
144 Global.setCheckVersionUpgrade(false);
\r
147 if (appearancePage.getNewNoteWithTags())
\r
148 Global.setNewNoteWithSelectedTags(true);
\r
150 Global.setNewNoteWithSelectedTags(false);
\r
152 if (appearancePage.getAnyTagSelection())
\r
153 Global.setAnyTagSelectionMatch(true);
\r
155 Global.setAnyTagSelectionMatch(false);
\r
157 Global.setAutoSaveInterval(appearancePage.getAutoSaveInterval());
\r
159 Global.setAutomaticLogin(connectionPage.getAutomaticLogin());
\r
160 Global.setRememberPassword(connectionPage.getRememberPassword());
\r
161 if (connectionPage.getRememberPassword()) {
\r
162 aes.setPassword(connectionPage.getPassword());
\r
164 Global.setProxyValue("url", connectionPage.getProxyUrl());
\r
165 Global.setProxyValue("port", connectionPage.getProxyPort());
\r
166 Global.setProxyValue("userid", connectionPage.getProxyUserid());
\r
167 Global.setProxyValue("password", connectionPage.getProxyPassword());
\r
169 Global.setShowTrayIcon(appearancePage.getShowTrayIcon());
\r
170 Global.setVerifyDelete(appearancePage.getVerifyDelete());
\r
171 Global.setStartMinimized(appearancePage.getStartMinimized());
\r
172 Global.setSynchronizeOnClose(connectionPage.getSynchronizeOnClose());
\r
173 Global.setSynchronizeDeletedContent(connectionPage.getSynchronizeDeletedContent());
\r
174 Global.setTagBehavior(appearancePage.getTagBehavior());
\r
175 Global.setIndexAttachmentsLocally(indexPage.getIndexAttachmentsLocally());
\r
176 Global.setIndexNoteBody(indexPage.getIndexNoteBody());
\r
177 Global.setIndexNoteTitle(indexPage.getIndexNoteTitle());
\r
178 Global.setIndexImageRecognition(indexPage.getIndexImageRecognition());
\r
179 Global.setAutomaticWildcardSearches(indexPage.getAutomaticWildcardSearches());
\r
180 Global.setSpecialIndexCharacters(indexPage.getSpecialCharacters());
\r
181 Global.setIncludeTagChildren(appearancePage.getIncludeTagChildren());
\r
182 Global.setDisplayRightToLeft(appearancePage.getDisplayRightToLeft());
\r
184 FileOutputStream out = null;
\r
186 out = new FileOutputStream(Global.getFileManager().getHomeDirFile("secure.txt"));
\r
187 } catch (FileNotFoundException e) {
\r
188 // if it isn't found we'll write it.
\r
192 Global.userStoreUrl = "https://"+debugPage.getServer()+"/edam/user";
\r
193 Global.setWordRegex(indexPage.getRegex());
\r
194 Global.setRecognitionWeight(indexPage.getRecognitionWeight());
\r
195 Global.setIndexThreadSleepInterval(indexPage.getSleepInterval());
\r
196 Global.setMessageLevel( debugPage.getDebugLevel());
\r
197 Global.saveCarriageReturnFix(debugPage.getCarriageReturnFix());
\r
198 Global.enableCarriageReturnFix = debugPage.getCarriageReturnFix();
\r
199 Global.saveHtmlEntitiesFix(debugPage.getHtmlEntitiesFix());
\r
200 Global.enableHTMLEntitiesFix = debugPage.getHtmlEntitiesFix();
\r
202 Global.setSpellSetting(Configuration.SPELL_IGNOREDIGITWORDS, spellPage.getIgnoreDigitWords());
\r
203 Global.setSpellSetting(Configuration.SPELL_IGNOREINTERNETADDRESSES, spellPage.getIgnoreInternetAddresses());
\r
204 Global.setSpellSetting(Configuration.SPELL_IGNOREMIXEDCASE, spellPage.getIgnoreMixedCase());
\r
205 Global.setSpellSetting(Configuration.SPELL_IGNOREUPPERCASE, spellPage.getIgnoreUpperCase());
\r
206 Global.setSpellSetting(Configuration.SPELL_IGNORESENTENCECAPITALIZATION, spellPage.getIgnoreSentenceCapitalization());
\r
208 String guiFormat = appearancePage.getStyle();
\r
209 QApplication.setStyle(guiFormat);
\r
210 QApplication.style().standardPalette();
\r
211 Global.setStyle(guiFormat);
\r
212 Global.setStandardPalette(appearancePage.getStandardPalette());
\r
213 if (Global.useStandardPalette())
\r
214 QApplication.setPalette(QApplication.style().standardPalette());
\r
216 QApplication.setPalette(Global.originalPalette);
\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
225 Global.setDateFormat(dateFmt);
\r
226 Global.setTimeFormat(timeFmt);
\r
228 Global.setSyncInterval(connectionPage.getSyncInterval());
\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
239 // Reject the current style
\r
241 public void reject() {
\r
242 QApplication.setStyle(Global.getStyle());
\r
246 //* return the debugging information page
\r
247 public ConfigDebugPage getDebugPage() {
\r
251 // Get the Evernote connection page
\r
252 public ConfigConnectionPage getConfigPage() {
\r
253 return connectionPage;
\r
256 // Create icons used for navigating the page
\r
257 public void createIcons() {
\r
258 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
261 QListWidgetItem formatsButton = new QListWidgetItem(contentsWidget);
\r
262 formatsButton.setText(tr("Appearance"));
\r
263 formatsButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
264 formatsButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
265 formatsButton.setIcon(new QIcon(iconPath+"appearance.jpg"));
\r
267 QListWidgetItem fontButton = new QListWidgetItem(contentsWidget);
\r
268 fontButton.setText(tr("Fonts"));
\r
269 fontButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
270 fontButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
271 fontButton.setIcon(new QIcon(iconPath+"fontConfig.png"));
\r
273 QListWidgetItem indexButton = new QListWidgetItem(contentsWidget);
\r
274 indexButton.setText(tr("Indexing"));
\r
275 indexButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
276 indexButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
277 indexButton.setIcon(new QIcon(iconPath+"search_config.jpg"));
\r
279 QListWidgetItem spellButton = new QListWidgetItem(contentsWidget);
\r
280 spellButton.setText(tr("Spell Check"));
\r
281 spellButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
282 spellButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
283 spellButton.setIcon(new QIcon(iconPath+"dictionary.png"));
\r
285 QListWidgetItem configButton = new QListWidgetItem(contentsWidget);
\r
286 configButton.setText(tr("Connection"));
\r
287 configButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
288 configButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
289 configButton.setIcon(new QIcon(iconPath+"synchronize.png"));
\r
291 QListWidgetItem debugButton = new QListWidgetItem(contentsWidget);
\r
292 debugButton.setText(tr("Debugging"));
\r
293 debugButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
294 debugButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
295 debugButton.setIcon(new QIcon(iconPath+"debug.jpg"));
\r
297 contentsWidget.currentItemChanged.connect(this, "changePage(QListWidgetItem, QListWidgetItem)");
\r
300 // this is called when the user switches config pages
\r
301 protected void changePage(QListWidgetItem current, QListWidgetItem previous) {
\r
302 pagesWidget.setCurrentIndex(contentsWidget.row(current));
\r
305 // Load initial settings
\r
306 private void loadSettings() {
\r
307 Global.originalPalette = QApplication.palette();
\r
309 debugPage.setServer(Global.getServer());
\r
310 debugPage.setDisableUploads(Global.disableUploads);
\r
311 debugPage.setEnableThumbnails(Global.enableThumbnails());
\r
312 // if (Global.getUpdateSequenceNumber() > 0)
\r
313 debugPage.serverCombo.setEnabled(false);
\r
315 if (Global.username.equalsIgnoreCase("") || Global.password.equalsIgnoreCase("")) {
\r
316 AESEncrypter aes = new AESEncrypter();
\r
318 aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("secure.txt")));
\r
319 } catch (FileNotFoundException e) {
\r
320 // File not found, so we'll just get empty strings anyway.
\r
322 String userid = aes.getUserid();
\r
323 String password = aes.getPassword();
\r
324 if (!userid.equals("") && !password.equals("")) {
\r
325 Global.username = userid;
\r
326 Global.password = password;
\r
329 appearancePage.setAutoSaveInterval(Global.getAutoSaveInterval());
\r
330 connectionPage.setUserid(Global.username);
\r
331 connectionPage.setPassword(Global.password);
\r
332 connectionPage.setAutomaticLogin(Global.automaticLogin());
\r
333 connectionPage.setRememberPassword(Global.rememberPassword());
\r
334 appearancePage.setMimicEvernote(Global.getMimicEvernoteInterface());
\r
335 appearancePage.setShowTrayIcon(Global.showTrayIcon());
\r
336 connectionPage.setSynchronizeOnClose(Global.synchronizeOnClose());
\r
337 connectionPage.setSyncronizeDeletedContent(Global.synchronizeDeletedContent());
\r
338 appearancePage.setVerifyDelete(Global.verifyDelete());
\r
339 appearancePage.setStartMinimized(Global.startMinimized());
\r
340 appearancePage.setPdfPreview(Global.pdfPreview());
\r
341 appearancePage.setCheckForUpdates(Global.checkVersionUpgrade());
\r
342 appearancePage.setNewNoteWithTags(Global.newNoteWithSelectedTags());
\r
343 appearancePage.setAnyTagSelection(Global.anyTagSelectionMatch());
\r
344 appearancePage.setShowSplashScreen(Global.isWindowVisible("SplashScreen"));
\r
345 appearancePage.setTagBehavior(Global.tagBehavior());
\r
346 appearancePage.setMinimizeOnClose(Global.minimizeOnClose());
\r
347 appearancePage.setIncludeTagChildren(Global.includeTagChildren());
\r
348 appearancePage.setDisplayRightToLeft(Global.displayRightToLeft());
\r
350 indexPage.setRegex(Global.getWordRegex());
\r
351 indexPage.setSleepInterval(Global.getIndexThreadSleepInterval());
\r
352 connectionPage.setSyncInterval(Global.getSyncInterval());
\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
359 debugPage.setDebugLevel(Global.getMessageLevel());
\r
360 debugPage.setCarriageReturnFix(Global.enableCarriageReturnFix());
\r
361 debugPage.setHtmlEntitiesFix(Global.enableHTMLEntitiesFix);
\r