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.trolltech.qt.core.QSize;
\r
27 import com.trolltech.qt.core.Qt.AlignmentFlag;
\r
28 import com.trolltech.qt.core.Qt.ItemFlag;
\r
29 import com.trolltech.qt.gui.QApplication;
\r
30 import com.trolltech.qt.gui.QDialog;
\r
31 import com.trolltech.qt.gui.QHBoxLayout;
\r
32 import com.trolltech.qt.gui.QIcon;
\r
33 import com.trolltech.qt.gui.QListView;
\r
34 import com.trolltech.qt.gui.QListWidget;
\r
35 import com.trolltech.qt.gui.QListWidgetItem;
\r
36 import com.trolltech.qt.gui.QPushButton;
\r
37 import com.trolltech.qt.gui.QStackedWidget;
\r
38 import com.trolltech.qt.gui.QVBoxLayout;
\r
39 import com.trolltech.qt.gui.QWidget;
\r
41 import cx.fbn.nevernote.Global;
\r
42 import cx.fbn.nevernote.utilities.AESEncrypter;
\r
43 public class ConfigDialog extends QDialog {
\r
44 private final QListWidget contentsWidget;
\r
45 private final QStackedWidget pagesWidget;
\r
46 private final ConfigConnectionPage connectionPage;
\r
47 private final ConfigDebugPage debugPage;
\r
48 private final ConfigAppearancePage appearancePage;
\r
49 private final ConfigShowColumnsPage columnsPage;
\r
50 private final ConfigIndexPage indexPage;
\r
51 private final ConfigShowEditorButtonsPage editorButtonsPage;
\r
53 public ConfigDialog(QWidget parent) {
\r
55 contentsWidget = new QListWidget(this);
\r
56 contentsWidget.setViewMode(QListView.ViewMode.IconMode);
\r
57 contentsWidget.setIconSize(new QSize(96, 84));
\r
58 contentsWidget.setMovement(QListView.Movement.Static);
\r
59 contentsWidget.setMaximumWidth(128);
\r
60 contentsWidget.setSpacing(12);
\r
62 pagesWidget = new QStackedWidget(this);
\r
63 connectionPage = new ConfigConnectionPage(this);
\r
64 appearancePage = new ConfigAppearancePage(this);
\r
65 indexPage = new ConfigIndexPage(this);
\r
66 debugPage = new ConfigDebugPage(this);
\r
67 columnsPage = new ConfigShowColumnsPage(this);
\r
68 editorButtonsPage = new ConfigShowEditorButtonsPage(this);
\r
69 pagesWidget.addWidget(appearancePage);
\r
70 pagesWidget.addWidget(indexPage);
\r
71 pagesWidget.addWidget(connectionPage);
\r
72 pagesWidget.addWidget(columnsPage);
\r
73 pagesWidget.addWidget(editorButtonsPage);
\r
74 pagesWidget.addWidget(debugPage);
\r
76 QPushButton cancelButton = new QPushButton(tr("Cancel"));
\r
77 QPushButton okButton = new QPushButton(tr("OK"));
\r
78 okButton.clicked.connect(this, "okPushed()");
\r
79 cancelButton.clicked.connect(this, "close()");
\r
82 contentsWidget.setCurrentRow(0);
\r
84 QHBoxLayout horizontalLayout = new QHBoxLayout();
\r
85 horizontalLayout.addWidget(contentsWidget);
\r
86 horizontalLayout.addWidget(pagesWidget,1);
\r
88 QHBoxLayout buttonLayout = new QHBoxLayout();
\r
89 buttonLayout.addStretch(1);
\r
90 buttonLayout.addWidget(okButton);
\r
91 buttonLayout.addWidget(cancelButton);
\r
92 setWindowTitle(tr("Settings"));
\r
94 QVBoxLayout mainLayout = new QVBoxLayout();
\r
95 mainLayout.addLayout(horizontalLayout);
\r
96 mainLayout.addSpacing(1);
\r
97 mainLayout.addLayout(buttonLayout);
\r
98 setLayout(mainLayout);
\r
102 public void okPushed() {
\r
103 Global.setServer(debugPage.getServer());
\r
104 AESEncrypter aes = new AESEncrypter();
\r
105 aes.setUserid(connectionPage.getUserid().trim());
\r
107 if (debugPage.getDisableUploads())
\r
108 Global.disableUploads = true;
\r
110 Global.disableUploads = false;
\r
111 Global.setDisableUploads(Global.disableUploads);
\r
112 Global.setMimicEvernoteInterface(appearancePage.getMimicEvernote());
\r
114 if (appearancePage.getShowSplashScreen())
\r
115 Global.saveWindowVisible("SplashScreen", true);
\r
117 Global.saveWindowVisible("SplashScreen", false);
\r
120 if (appearancePage.getPdfPreview())
\r
121 Global.setPdfPreview(true);
\r
123 Global.setPdfPreview(false);
\r
125 Global.setAutoSaveInterval(appearancePage.getAutoSaveInterval());
\r
127 Global.setAutomaticLogin(connectionPage.getAutomaticLogin());
\r
128 Global.setRememberPassword(connectionPage.getRememberPassword());
\r
129 if (connectionPage.getRememberPassword()) {
\r
130 aes.setPassword(connectionPage.getPassword());
\r
132 Global.setShowTrayIcon(appearancePage.getShowTrayIcon());
\r
133 Global.setVerifyDelete(appearancePage.getVerifyDelete());
\r
134 Global.setSynchronizeOnClose(connectionPage.getSynchronizeOnClose());
\r
135 Global.setSynchronizeDeletedContent(connectionPage.getSynchronizeDeletedContent());
\r
136 Global.setTagBehavior(appearancePage.getTagBehavior());
\r
137 FileOutputStream out = null;
\r
139 out = new FileOutputStream(Global.getFileManager().getHomeDirFile("secure.txt"));
\r
140 } catch (FileNotFoundException e) {
\r
141 // if it isn't found we'll write it.
\r
145 Global.userStoreUrl = "https://"+debugPage.getServer()+"/edam/user";
\r
146 Global.setWordRegex(indexPage.getRegex());
\r
147 Global.setRecognitionWeight(indexPage.getRecognitionWeight());
\r
148 Global.setMinimumWordLength(indexPage.getWordLength());
\r
149 Global.minimumWordCount = indexPage.getWordLength();
\r
150 Global.setIndexThreads(indexPage.getIndexThreads());
\r
151 Global.setMessageLevel( debugPage.getDebugLevel());
\r
152 Global.saveCarriageReturnFix(debugPage.getCarriageReturnFix());
\r
153 Global.enableCarriageReturnFix = debugPage.getCarriageReturnFix();
\r
155 String guiFormat = appearancePage.getStyle();
\r
156 QApplication.setStyle(guiFormat);
\r
157 QApplication.style().standardPalette();
\r
158 Global.setStyle(guiFormat);
\r
159 Global.setStandardPalette(appearancePage.getStandardPalette());
\r
160 if (Global.useStandardPalette())
\r
161 QApplication.setPalette(QApplication.style().standardPalette());
\r
163 QApplication.setPalette(Global.originalPalette);
\r
165 String dateFmt = appearancePage.getDateFormat();
\r
166 String timeFmt = appearancePage.getTimeFormat();
\r
167 int dash = dateFmt.indexOf("-");
\r
168 dateFmt = dateFmt.substring(0,dash-1);
\r
169 dash = timeFmt.indexOf("-");
\r
170 timeFmt = timeFmt.substring(0,dash-1);
\r
172 Global.setDateFormat(dateFmt);
\r
173 Global.setTimeFormat(timeFmt);
\r
175 Global.setSyncInterval(connectionPage.getSyncInterval());
\r
177 Global.saveColumnVisible("dateCreated", columnsPage.showDateCreated());
\r
178 Global.saveColumnVisible("dateChanged", columnsPage.showDateChanged());
\r
179 Global.saveColumnVisible("dateSubject", columnsPage.showDateSubject());
\r
180 Global.saveColumnVisible("author", columnsPage.showAuthor());
\r
181 Global.saveColumnVisible("sourceUrl", columnsPage.showSourceUrl());
\r
182 Global.saveColumnVisible("synchronized", columnsPage.showSynchronized());
\r
183 Global.saveColumnVisible("notebook", columnsPage.showNotebook());
\r
184 Global.saveColumnVisible("tags", columnsPage.showTags());
\r
186 Global.saveEditorButtonsVisible("undo", editorButtonsPage.showUndo());
\r
187 Global.saveEditorButtonsVisible("redo", editorButtonsPage.showRedo());
\r
188 Global.saveEditorButtonsVisible("cut", editorButtonsPage.showCut());
\r
189 Global.saveEditorButtonsVisible("copy", editorButtonsPage.showCopy());
\r
190 Global.saveEditorButtonsVisible("paste", editorButtonsPage.showPaste());
\r
191 Global.saveEditorButtonsVisible("underline", editorButtonsPage.showUnderline());
\r
192 Global.saveEditorButtonsVisible("strikethrough", editorButtonsPage.showStrikethrough());
\r
193 Global.saveEditorButtonsVisible("italic", editorButtonsPage.showItalic());
\r
194 Global.saveEditorButtonsVisible("bold", editorButtonsPage.showBold());
\r
195 Global.saveEditorButtonsVisible("font", editorButtonsPage.showFont());
\r
196 Global.saveEditorButtonsVisible("fontSize", editorButtonsPage.showFontSize());
\r
197 Global.saveEditorButtonsVisible("fontColor", editorButtonsPage.showFontColor());
\r
198 Global.saveEditorButtonsVisible("fontHilight", editorButtonsPage.showFontHilight());
\r
199 Global.saveEditorButtonsVisible("indent", editorButtonsPage.showIndent());
\r
200 Global.saveEditorButtonsVisible("outdent", editorButtonsPage.showOutdent());
\r
201 Global.saveEditorButtonsVisible("numberList", editorButtonsPage.showNumberList());
\r
202 Global.saveEditorButtonsVisible("bulletList", editorButtonsPage.showBulletList());
\r
203 Global.saveEditorButtonsVisible("alignCenter", editorButtonsPage.showAlignCenter());
\r
204 Global.saveEditorButtonsVisible("alignLeft", editorButtonsPage.showAlignLeft());
\r
205 Global.saveEditorButtonsVisible("alignRight", editorButtonsPage.showAlignRight());
\r
209 public void reject() {
\r
210 QApplication.setStyle(Global.getStyle());
\r
214 public ConfigDebugPage getDebugPage() {
\r
219 public ConfigConnectionPage getConfigPage() {
\r
220 return connectionPage;
\r
223 public void createIcons() {
\r
224 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
227 QListWidgetItem formatsButton = new QListWidgetItem(contentsWidget);
\r
228 formatsButton.setText(tr("Appearance"));
\r
229 formatsButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
230 formatsButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
231 formatsButton.setIcon(new QIcon(iconPath+"appearance.jpg"));
\r
233 QListWidgetItem indexButton = new QListWidgetItem(contentsWidget);
\r
234 indexButton.setText(tr("Indexing"));
\r
235 indexButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
236 indexButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
237 indexButton.setIcon(new QIcon(iconPath+"search_config.jpg"));
\r
239 QListWidgetItem configButton = new QListWidgetItem(contentsWidget);
\r
240 configButton.setText(tr("Connection"));
\r
241 configButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
242 configButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
243 configButton.setIcon(new QIcon(iconPath+"synchronize.png"));
\r
245 QListWidgetItem columnsButton = new QListWidgetItem(contentsWidget);
\r
246 columnsButton.setText(tr("Hide Columns"));
\r
247 columnsButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
248 columnsButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
249 columnsButton.setIcon(new QIcon(iconPath+"show-columns.png"));
\r
251 QListWidgetItem editorButton = new QListWidgetItem(contentsWidget);
\r
252 editorButton.setText(tr("Hide Edit Buttons"));
\r
253 editorButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
254 editorButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
255 editorButton.setIcon(new QIcon(iconPath+"scissors.jpg"));
\r
257 QListWidgetItem debugButton = new QListWidgetItem(contentsWidget);
\r
258 debugButton.setText(tr("Debugging"));
\r
259 debugButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
260 debugButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
261 debugButton.setIcon(new QIcon(iconPath+"debug.jpg"));
\r
263 contentsWidget.currentItemChanged.connect(this, "changePage(QListWidgetItem, QListWidgetItem)");
\r
266 protected void changePage(QListWidgetItem current, QListWidgetItem previous) {
\r
267 pagesWidget.setCurrentIndex(contentsWidget.row(current));
\r
270 private void loadSettings() {
\r
271 Global.originalPalette = QApplication.palette();
\r
273 debugPage.setServer(Global.getServer());
\r
274 debugPage.setDisableUploads(Global.disableUploads);
\r
275 // if (Global.getUpdateSequenceNumber() > 0)
\r
276 debugPage.serverCombo.setEnabled(false);
\r
278 if (Global.username.equalsIgnoreCase("") || Global.password.equalsIgnoreCase("")) {
\r
279 AESEncrypter aes = new AESEncrypter();
\r
281 aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("secure.txt")));
\r
282 } catch (FileNotFoundException e) {
\r
283 // File not found, so we'll just get empty strings anyway.
\r
285 String userid = aes.getUserid();
\r
286 String password = aes.getPassword();
\r
287 if (!userid.equals("") && !password.equals("")) {
\r
288 Global.username = userid;
\r
289 Global.password = password;
\r
292 appearancePage.setAutoSaveInterval(Global.getAutoSaveInterval());
\r
293 connectionPage.setUserid(Global.username);
\r
294 connectionPage.setPassword(Global.password);
\r
295 connectionPage.setAutomaticLogin(Global.automaticLogin());
\r
296 connectionPage.setRememberPassword(Global.rememberPassword());
\r
297 appearancePage.setMimicEvernote(Global.getMimicEvernoteInterface());
\r
298 appearancePage.setShowTrayIcon(Global.showTrayIcon());
\r
299 connectionPage.setSynchronizeOnClose(Global.synchronizeOnClose());
\r
300 connectionPage.setSyncronizeDeletedContent(Global.synchronizeDeletedContent());
\r
301 appearancePage.setVerifyDelete(Global.verifyDelete());
\r
302 appearancePage.setPdfPreview(Global.pdfPreview());
\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 connectionPage.setSyncInterval(Global.getSyncInterval());
\r
311 appearancePage.setDateFormat(Global.getDateFormat());
\r
312 appearancePage.setTimeFormat(Global.getTimeFormat());
\r
313 appearancePage.setStyle(Global.getStyle());
\r
314 appearancePage.setStandardPalette(Global.useStandardPalette());
\r
316 columnsPage.setDateCreated(Global.isColumnVisible("dateCreated"));
\r
317 columnsPage.setDateSubject(Global.isColumnVisible("dateSubject"));
\r
318 columnsPage.setDateChanged(Global.isColumnVisible("dateChanged"));
\r
319 columnsPage.setAuthor(Global.isColumnVisible("author"));
\r
320 columnsPage.setSourceUrl(Global.isColumnVisible("sourceUrl"));
\r
321 columnsPage.setTags(Global.isColumnVisible("tags"));
\r
322 columnsPage.setSynchronized(Global.isColumnVisible("synchronized"));
\r
323 columnsPage.setNotebook(Global.isColumnVisible("notebook"));
\r
325 editorButtonsPage.setUndo(Global.isEditorButtonVisible("undo"));
\r
326 editorButtonsPage.setRedo(Global.isEditorButtonVisible("redo"));
\r
327 editorButtonsPage.setCut(Global.isEditorButtonVisible("cut"));
\r
328 editorButtonsPage.setCopy(Global.isEditorButtonVisible("copy"));
\r
329 editorButtonsPage.setPaste(Global.isEditorButtonVisible("paste"));
\r
330 editorButtonsPage.setBold(Global.isEditorButtonVisible("bold"));
\r
331 editorButtonsPage.setItalic(Global.isEditorButtonVisible("italic"));
\r
332 editorButtonsPage.setUnderline(Global.isEditorButtonVisible("underline"));
\r
333 editorButtonsPage.setStrikethrough(Global.isEditorButtonVisible("strikethrough"));
\r
334 editorButtonsPage.setIndent(Global.isEditorButtonVisible("indent"));
\r
335 editorButtonsPage.setHline(Global.isEditorButtonVisible("hline"));
\r
336 editorButtonsPage.setOutdent(Global.isEditorButtonVisible("outdent"));
\r
337 editorButtonsPage.setBulletList(Global.isEditorButtonVisible("bulletList"));
\r
338 editorButtonsPage.setNumberList(Global.isEditorButtonVisible("numberList"));
\r
339 editorButtonsPage.setFont(Global.isEditorButtonVisible("font"));
\r
340 editorButtonsPage.setFontSize(Global.isEditorButtonVisible("fontSize"));
\r
341 editorButtonsPage.setFontColor(Global.isEditorButtonVisible("fontColor"));
\r
342 editorButtonsPage.setFontHighlight(Global.isEditorButtonVisible("fontHilight"));
\r
343 editorButtonsPage.setAlignLeft(Global.isEditorButtonVisible("alignLeft"));
\r
344 editorButtonsPage.setAlignCenter(Global.isEditorButtonVisible("alignCenter"));
\r
345 editorButtonsPage.setAlignRight(Global.isEditorButtonVisible("alignRight"));
\r
347 debugPage.setDebugLevel(Global.getMessageLevel());
\r
348 debugPage.setCarriageReturnFix(Global.enableCarriageReturnFix());
\r