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
118 if (appearancePage.getShowSplashScreen())
\r
119 Global.saveWindowVisible("SplashScreen", true);
\r
121 Global.saveWindowVisible("SplashScreen", false);
\r
124 if (appearancePage.getPdfPreview())
\r
125 Global.setPdfPreview(true);
\r
127 Global.setPdfPreview(false);
\r
129 if (appearancePage.getNewNoteWithTags())
\r
130 Global.setNewNoteWithSelectedTags(true);
\r
132 Global.setNewNoteWithSelectedTags(false);
\r
134 Global.setAutoSaveInterval(appearancePage.getAutoSaveInterval());
\r
136 Global.setAutomaticLogin(connectionPage.getAutomaticLogin());
\r
137 Global.setRememberPassword(connectionPage.getRememberPassword());
\r
138 if (connectionPage.getRememberPassword()) {
\r
139 aes.setPassword(connectionPage.getPassword());
\r
141 Global.setProxyValue("url", connectionPage.getProxyUrl());
\r
142 Global.setProxyValue("port", connectionPage.getProxyPort());
\r
143 Global.setProxyValue("userid", connectionPage.getProxyUserid());
\r
144 Global.setProxyValue("password", connectionPage.getProxyPassword());
\r
146 Global.setShowTrayIcon(appearancePage.getShowTrayIcon());
\r
147 Global.setVerifyDelete(appearancePage.getVerifyDelete());
\r
148 Global.setStartMinimized(appearancePage.getStartMinimized());
\r
149 Global.setSynchronizeOnClose(connectionPage.getSynchronizeOnClose());
\r
150 Global.setSynchronizeDeletedContent(connectionPage.getSynchronizeDeletedContent());
\r
151 Global.setTagBehavior(appearancePage.getTagBehavior());
\r
152 FileOutputStream out = null;
\r
154 out = new FileOutputStream(Global.getFileManager().getHomeDirFile("secure.txt"));
\r
155 } catch (FileNotFoundException e) {
\r
156 // if it isn't found we'll write it.
\r
160 Global.userStoreUrl = "https://"+debugPage.getServer()+"/edam/user";
\r
161 Global.setWordRegex(indexPage.getRegex());
\r
162 Global.setRecognitionWeight(indexPage.getRecognitionWeight());
\r
163 Global.setMinimumWordLength(indexPage.getWordLength());
\r
164 Global.minimumWordCount = indexPage.getWordLength();
\r
165 Global.setIndexThreads(indexPage.getIndexThreads());
\r
166 Global.setIndexThreadSleepInterval(indexPage.getSleepInterval());
\r
167 Global.setMessageLevel( debugPage.getDebugLevel());
\r
168 Global.saveCarriageReturnFix(debugPage.getCarriageReturnFix());
\r
169 Global.enableCarriageReturnFix = debugPage.getCarriageReturnFix();
\r
171 Global.setSpellSetting(Configuration.SPELL_IGNOREDIGITWORDS, spellPage.getIgnoreDigitWords());
\r
172 Global.setSpellSetting(Configuration.SPELL_IGNOREINTERNETADDRESSES, spellPage.getIgnoreInternetAddresses());
\r
173 Global.setSpellSetting(Configuration.SPELL_IGNOREMIXEDCASE, spellPage.getIgnoreMixedCase());
\r
174 Global.setSpellSetting(Configuration.SPELL_IGNOREUPPERCASE, spellPage.getIgnoreUpperCase());
\r
175 Global.setSpellSetting(Configuration.SPELL_IGNORESENTENCECAPITALIZATION, spellPage.getIgnoreSentenceCapitalization());
\r
177 String guiFormat = appearancePage.getStyle();
\r
178 QApplication.setStyle(guiFormat);
\r
179 QApplication.style().standardPalette();
\r
180 Global.setStyle(guiFormat);
\r
181 Global.setStandardPalette(appearancePage.getStandardPalette());
\r
182 if (Global.useStandardPalette())
\r
183 QApplication.setPalette(QApplication.style().standardPalette());
\r
185 QApplication.setPalette(Global.originalPalette);
\r
187 String dateFmt = appearancePage.getDateFormat();
\r
188 String timeFmt = appearancePage.getTimeFormat();
\r
189 int dash = dateFmt.indexOf("-");
\r
190 dateFmt = dateFmt.substring(0,dash-1);
\r
191 dash = timeFmt.indexOf("-");
\r
192 timeFmt = timeFmt.substring(0,dash-1);
\r
194 Global.setDateFormat(dateFmt);
\r
195 Global.setTimeFormat(timeFmt);
\r
197 Global.setSyncInterval(connectionPage.getSyncInterval());
\r
199 Global.setOverrideDefaultFont(fontPage.overrideFont());
\r
200 Global.setDefaultFont(fontPage.getFont());
\r
201 Global.setDefaultFontSize(fontPage.getFontSize());
\r
206 public void reject() {
\r
207 QApplication.setStyle(Global.getStyle());
\r
211 public ConfigDebugPage getDebugPage() {
\r
216 public ConfigConnectionPage getConfigPage() {
\r
217 return connectionPage;
\r
220 public void createIcons() {
\r
221 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
224 QListWidgetItem formatsButton = new QListWidgetItem(contentsWidget);
\r
225 formatsButton.setText(tr("Appearance"));
\r
226 formatsButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
227 formatsButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
228 formatsButton.setIcon(new QIcon(iconPath+"appearance.jpg"));
\r
230 QListWidgetItem fontButton = new QListWidgetItem(contentsWidget);
\r
231 fontButton.setText(tr("Fonts"));
\r
232 fontButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
233 fontButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
234 fontButton.setIcon(new QIcon(iconPath+"fontConfig.png"));
\r
236 QListWidgetItem indexButton = new QListWidgetItem(contentsWidget);
\r
237 indexButton.setText(tr("Indexing"));
\r
238 indexButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
239 indexButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
240 indexButton.setIcon(new QIcon(iconPath+"search_config.jpg"));
\r
242 QListWidgetItem spellButton = new QListWidgetItem(contentsWidget);
\r
243 spellButton.setText(tr("Spell Check"));
\r
244 spellButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
245 spellButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
246 spellButton.setIcon(new QIcon(iconPath+"dictionary.png"));
\r
248 QListWidgetItem configButton = new QListWidgetItem(contentsWidget);
\r
249 configButton.setText(tr("Connection"));
\r
250 configButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
251 configButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
252 configButton.setIcon(new QIcon(iconPath+"synchronize.png"));
\r
254 QListWidgetItem debugButton = new QListWidgetItem(contentsWidget);
\r
255 debugButton.setText(tr("Debugging"));
\r
256 debugButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
257 debugButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
258 debugButton.setIcon(new QIcon(iconPath+"debug.jpg"));
\r
260 contentsWidget.currentItemChanged.connect(this, "changePage(QListWidgetItem, QListWidgetItem)");
\r
263 protected void changePage(QListWidgetItem current, QListWidgetItem previous) {
\r
264 pagesWidget.setCurrentIndex(contentsWidget.row(current));
\r
267 private void loadSettings() {
\r
268 Global.originalPalette = QApplication.palette();
\r
270 debugPage.setServer(Global.getServer());
\r
271 debugPage.setDisableUploads(Global.disableUploads);
\r
272 debugPage.setEnableThumbnails(Global.enableThumbnails());
\r
273 // if (Global.getUpdateSequenceNumber() > 0)
\r
274 debugPage.serverCombo.setEnabled(false);
\r
276 if (Global.username.equalsIgnoreCase("") || Global.password.equalsIgnoreCase("")) {
\r
277 AESEncrypter aes = new AESEncrypter();
\r
279 aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("secure.txt")));
\r
280 } catch (FileNotFoundException e) {
\r
281 // File not found, so we'll just get empty strings anyway.
\r
283 String userid = aes.getUserid();
\r
284 String password = aes.getPassword();
\r
285 if (!userid.equals("") && !password.equals("")) {
\r
286 Global.username = userid;
\r
287 Global.password = password;
\r
290 appearancePage.setAutoSaveInterval(Global.getAutoSaveInterval());
\r
291 connectionPage.setUserid(Global.username);
\r
292 connectionPage.setPassword(Global.password);
\r
293 connectionPage.setAutomaticLogin(Global.automaticLogin());
\r
294 connectionPage.setRememberPassword(Global.rememberPassword());
\r
295 appearancePage.setMimicEvernote(Global.getMimicEvernoteInterface());
\r
296 appearancePage.setShowTrayIcon(Global.showTrayIcon());
\r
297 connectionPage.setSynchronizeOnClose(Global.synchronizeOnClose());
\r
298 connectionPage.setSyncronizeDeletedContent(Global.synchronizeDeletedContent());
\r
299 appearancePage.setVerifyDelete(Global.verifyDelete());
\r
300 appearancePage.setStartMinimized(Global.startMinimized());
\r
301 appearancePage.setPdfPreview(Global.pdfPreview());
\r
302 appearancePage.setNewNoteWithTags(Global.newNoteWithSelectedTags());
\r
303 appearancePage.setShowSplashScreen(Global.isWindowVisible("SplashScreen"));
\r
304 appearancePage.setTagBehavior(Global.tagBehavior());
\r
306 indexPage.setRegex(Global.getWordRegex());
\r
307 indexPage.setWordLength(Global.getMinimumWordLength());
\r
308 indexPage.setIndexThreads(Global.getIndexThreads());
\r
309 indexPage.setSleepInterval(Global.getIndexThreadSleepInterval());
\r
310 connectionPage.setSyncInterval(Global.getSyncInterval());
\r
312 appearancePage.setDateFormat(Global.getDateFormat());
\r
313 appearancePage.setTimeFormat(Global.getTimeFormat());
\r
314 appearancePage.setStyle(Global.getStyle());
\r
315 appearancePage.setStandardPalette(Global.useStandardPalette());
\r
317 debugPage.setDebugLevel(Global.getMessageLevel());
\r
318 debugPage.setCarriageReturnFix(Global.enableCarriageReturnFix());
\r