2 * This file is part of NeverNote
\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 package cx.fbn.nevernote.dialog;
\r
22 import java.io.FileInputStream;
\r
23 import java.io.FileNotFoundException;
\r
24 import java.io.FileOutputStream;
\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
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
55 public ConfigDialog(QWidget parent) {
\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
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
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
85 contentsWidget.setCurrentRow(0);
\r
87 QHBoxLayout horizontalLayout = new QHBoxLayout();
\r
88 horizontalLayout.addWidget(contentsWidget);
\r
89 horizontalLayout.addWidget(pagesWidget,1);
\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
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
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
111 if (debugPage.getDisableUploads())
\r
112 Global.disableUploads = true;
\r
114 Global.disableUploads = false;
\r
115 Global.setDisableUploads(Global.disableUploads);
\r
116 Global.setMimicEvernoteInterface(appearancePage.getMimicEvernote());
\r
117 Global.setMinimizeOnClose(appearancePage.getMinimizeOnClose());
\r
119 if (appearancePage.getShowSplashScreen())
\r
120 Global.saveWindowVisible("SplashScreen", true);
\r
122 Global.saveWindowVisible("SplashScreen", false);
\r
125 if (appearancePage.getPdfPreview())
\r
126 Global.setPdfPreview(true);
\r
128 Global.setPdfPreview(false);
\r
130 if (appearancePage.getCheckForUpdates())
\r
131 Global.setCheckVersionUpgrade(true);
\r
133 Global.setCheckVersionUpgrade(false);
\r
136 if (appearancePage.getNewNoteWithTags())
\r
137 Global.setNewNoteWithSelectedTags(true);
\r
139 Global.setNewNoteWithSelectedTags(false);
\r
141 Global.setAutoSaveInterval(appearancePage.getAutoSaveInterval());
\r
143 Global.setAutomaticLogin(connectionPage.getAutomaticLogin());
\r
144 Global.setRememberPassword(connectionPage.getRememberPassword());
\r
145 if (connectionPage.getRememberPassword()) {
\r
146 aes.setPassword(connectionPage.getPassword());
\r
148 Global.setProxyValue("url", connectionPage.getProxyUrl());
\r
149 Global.setProxyValue("port", connectionPage.getProxyPort());
\r
150 Global.setProxyValue("userid", connectionPage.getProxyUserid());
\r
151 Global.setProxyValue("password", connectionPage.getProxyPassword());
\r
153 Global.setShowTrayIcon(appearancePage.getShowTrayIcon());
\r
154 Global.setVerifyDelete(appearancePage.getVerifyDelete());
\r
155 Global.setStartMinimized(appearancePage.getStartMinimized());
\r
156 Global.setSynchronizeOnClose(connectionPage.getSynchronizeOnClose());
\r
157 Global.setSynchronizeDeletedContent(connectionPage.getSynchronizeDeletedContent());
\r
158 Global.setTagBehavior(appearancePage.getTagBehavior());
\r
159 Global.setIndexAttachmentsLocally(indexPage.getIndexAttachmentsLocally());
\r
160 FileOutputStream out = null;
\r
162 out = new FileOutputStream(Global.getFileManager().getHomeDirFile("secure.txt"));
\r
163 } catch (FileNotFoundException e) {
\r
164 // if it isn't found we'll write it.
\r
168 Global.userStoreUrl = "https://"+debugPage.getServer()+"/edam/user";
\r
169 Global.setWordRegex(indexPage.getRegex());
\r
170 Global.setRecognitionWeight(indexPage.getRecognitionWeight());
\r
171 Global.setIndexThreadSleepInterval(indexPage.getSleepInterval());
\r
172 Global.setMessageLevel( debugPage.getDebugLevel());
\r
173 Global.saveCarriageReturnFix(debugPage.getCarriageReturnFix());
\r
174 Global.enableCarriageReturnFix = debugPage.getCarriageReturnFix();
\r
176 Global.setSpellSetting(Configuration.SPELL_IGNOREDIGITWORDS, spellPage.getIgnoreDigitWords());
\r
177 Global.setSpellSetting(Configuration.SPELL_IGNOREINTERNETADDRESSES, spellPage.getIgnoreInternetAddresses());
\r
178 Global.setSpellSetting(Configuration.SPELL_IGNOREMIXEDCASE, spellPage.getIgnoreMixedCase());
\r
179 Global.setSpellSetting(Configuration.SPELL_IGNOREUPPERCASE, spellPage.getIgnoreUpperCase());
\r
180 Global.setSpellSetting(Configuration.SPELL_IGNORESENTENCECAPITALIZATION, spellPage.getIgnoreSentenceCapitalization());
\r
182 String guiFormat = appearancePage.getStyle();
\r
183 QApplication.setStyle(guiFormat);
\r
184 QApplication.style().standardPalette();
\r
185 Global.setStyle(guiFormat);
\r
186 Global.setStandardPalette(appearancePage.getStandardPalette());
\r
187 if (Global.useStandardPalette())
\r
188 QApplication.setPalette(QApplication.style().standardPalette());
\r
190 QApplication.setPalette(Global.originalPalette);
\r
192 String dateFmt = appearancePage.getDateFormat();
\r
193 String timeFmt = appearancePage.getTimeFormat();
\r
194 int dash = dateFmt.indexOf("-");
\r
195 dateFmt = dateFmt.substring(0,dash-1);
\r
196 dash = timeFmt.indexOf("-");
\r
197 timeFmt = timeFmt.substring(0,dash-1);
\r
199 Global.setDateFormat(dateFmt);
\r
200 Global.setTimeFormat(timeFmt);
\r
202 Global.setSyncInterval(connectionPage.getSyncInterval());
\r
204 Global.setOverrideDefaultFont(fontPage.overrideFont());
\r
205 Global.setDefaultFont(fontPage.getFont());
\r
206 Global.setDefaultFontSize(fontPage.getFontSize());
\r
211 public void reject() {
\r
212 QApplication.setStyle(Global.getStyle());
\r
216 public ConfigDebugPage getDebugPage() {
\r
221 public ConfigConnectionPage getConfigPage() {
\r
222 return connectionPage;
\r
225 public void createIcons() {
\r
226 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
229 QListWidgetItem formatsButton = new QListWidgetItem(contentsWidget);
\r
230 formatsButton.setText(tr("Appearance"));
\r
231 formatsButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
232 formatsButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
233 formatsButton.setIcon(new QIcon(iconPath+"appearance.jpg"));
\r
235 QListWidgetItem fontButton = new QListWidgetItem(contentsWidget);
\r
236 fontButton.setText(tr("Fonts"));
\r
237 fontButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
238 fontButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
239 fontButton.setIcon(new QIcon(iconPath+"fontConfig.png"));
\r
241 QListWidgetItem indexButton = new QListWidgetItem(contentsWidget);
\r
242 indexButton.setText(tr("Indexing"));
\r
243 indexButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
244 indexButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
245 indexButton.setIcon(new QIcon(iconPath+"search_config.jpg"));
\r
247 QListWidgetItem spellButton = new QListWidgetItem(contentsWidget);
\r
248 spellButton.setText(tr("Spell Check"));
\r
249 spellButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
250 spellButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
251 spellButton.setIcon(new QIcon(iconPath+"dictionary.png"));
\r
253 QListWidgetItem configButton = new QListWidgetItem(contentsWidget);
\r
254 configButton.setText(tr("Connection"));
\r
255 configButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
256 configButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
257 configButton.setIcon(new QIcon(iconPath+"synchronize.png"));
\r
259 QListWidgetItem debugButton = new QListWidgetItem(contentsWidget);
\r
260 debugButton.setText(tr("Debugging"));
\r
261 debugButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
262 debugButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
263 debugButton.setIcon(new QIcon(iconPath+"debug.jpg"));
\r
265 contentsWidget.currentItemChanged.connect(this, "changePage(QListWidgetItem, QListWidgetItem)");
\r
268 protected void changePage(QListWidgetItem current, QListWidgetItem previous) {
\r
269 pagesWidget.setCurrentIndex(contentsWidget.row(current));
\r
272 private void loadSettings() {
\r
273 Global.originalPalette = QApplication.palette();
\r
275 debugPage.setServer(Global.getServer());
\r
276 debugPage.setDisableUploads(Global.disableUploads);
\r
277 debugPage.setEnableThumbnails(Global.enableThumbnails());
\r
278 // if (Global.getUpdateSequenceNumber() > 0)
\r
279 debugPage.serverCombo.setEnabled(false);
\r
281 if (Global.username.equalsIgnoreCase("") || Global.password.equalsIgnoreCase("")) {
\r
282 AESEncrypter aes = new AESEncrypter();
\r
284 aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("secure.txt")));
\r
285 } catch (FileNotFoundException e) {
\r
286 // File not found, so we'll just get empty strings anyway.
\r
288 String userid = aes.getUserid();
\r
289 String password = aes.getPassword();
\r
290 if (!userid.equals("") && !password.equals("")) {
\r
291 Global.username = userid;
\r
292 Global.password = password;
\r
295 appearancePage.setAutoSaveInterval(Global.getAutoSaveInterval());
\r
296 connectionPage.setUserid(Global.username);
\r
297 connectionPage.setPassword(Global.password);
\r
298 connectionPage.setAutomaticLogin(Global.automaticLogin());
\r
299 connectionPage.setRememberPassword(Global.rememberPassword());
\r
300 appearancePage.setMimicEvernote(Global.getMimicEvernoteInterface());
\r
301 appearancePage.setShowTrayIcon(Global.showTrayIcon());
\r
302 connectionPage.setSynchronizeOnClose(Global.synchronizeOnClose());
\r
303 connectionPage.setSyncronizeDeletedContent(Global.synchronizeDeletedContent());
\r
304 appearancePage.setVerifyDelete(Global.verifyDelete());
\r
305 appearancePage.setStartMinimized(Global.startMinimized());
\r
306 appearancePage.setPdfPreview(Global.pdfPreview());
\r
307 appearancePage.setCheckForUpdates(Global.checkVersionUpgrade());
\r
308 appearancePage.setNewNoteWithTags(Global.newNoteWithSelectedTags());
\r
309 appearancePage.setShowSplashScreen(Global.isWindowVisible("SplashScreen"));
\r
310 appearancePage.setTagBehavior(Global.tagBehavior());
\r
311 appearancePage.setMinimizeOnClose(Global.minimizeOnClose());
\r
313 indexPage.setRegex(Global.getWordRegex());
\r
314 indexPage.setSleepInterval(Global.getIndexThreadSleepInterval());
\r
315 connectionPage.setSyncInterval(Global.getSyncInterval());
\r
317 appearancePage.setDateFormat(Global.getDateFormat());
\r
318 appearancePage.setTimeFormat(Global.getTimeFormat());
\r
319 appearancePage.setStyle(Global.getStyle());
\r
320 appearancePage.setStandardPalette(Global.useStandardPalette());
\r
322 debugPage.setDebugLevel(Global.getMessageLevel());
\r
323 debugPage.setCarriageReturnFix(Global.enableCarriageReturnFix());
\r