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 ConfigIndexPage indexPage;
\r
51 public ConfigDialog(QWidget parent) {
\r
53 contentsWidget = new QListWidget(this);
\r
54 contentsWidget.setViewMode(QListView.ViewMode.IconMode);
\r
55 contentsWidget.setIconSize(new QSize(96, 84));
\r
56 contentsWidget.setMovement(QListView.Movement.Static);
\r
57 contentsWidget.setMaximumWidth(128);
\r
58 contentsWidget.setSpacing(12);
\r
60 pagesWidget = new QStackedWidget(this);
\r
61 connectionPage = new ConfigConnectionPage(this);
\r
62 appearancePage = new ConfigAppearancePage(this);
\r
63 indexPage = new ConfigIndexPage(this);
\r
64 debugPage = new ConfigDebugPage(this);
\r
65 pagesWidget.addWidget(appearancePage);
\r
66 pagesWidget.addWidget(indexPage);
\r
67 pagesWidget.addWidget(connectionPage);
\r
68 pagesWidget.addWidget(debugPage);
\r
70 QPushButton cancelButton = new QPushButton(tr("Cancel"));
\r
71 QPushButton okButton = new QPushButton(tr("OK"));
\r
72 okButton.clicked.connect(this, "okPushed()");
\r
73 cancelButton.clicked.connect(this, "close()");
\r
76 contentsWidget.setCurrentRow(0);
\r
78 QHBoxLayout horizontalLayout = new QHBoxLayout();
\r
79 horizontalLayout.addWidget(contentsWidget);
\r
80 horizontalLayout.addWidget(pagesWidget,1);
\r
82 QHBoxLayout buttonLayout = new QHBoxLayout();
\r
83 buttonLayout.addStretch(1);
\r
84 buttonLayout.addWidget(okButton);
\r
85 buttonLayout.addWidget(cancelButton);
\r
86 setWindowTitle(tr("Settings"));
\r
88 QVBoxLayout mainLayout = new QVBoxLayout();
\r
89 mainLayout.addLayout(horizontalLayout);
\r
90 mainLayout.addSpacing(1);
\r
91 mainLayout.addLayout(buttonLayout);
\r
92 setLayout(mainLayout);
\r
96 public void okPushed() {
\r
97 Global.setServer(debugPage.getServer());
\r
98 AESEncrypter aes = new AESEncrypter();
\r
99 aes.setUserid(connectionPage.getUserid().trim());
\r
101 if (debugPage.getDisableUploads())
\r
102 Global.disableUploads = true;
\r
104 Global.disableUploads = false;
\r
105 Global.setDisableUploads(Global.disableUploads);
\r
106 Global.setMimicEvernoteInterface(appearancePage.getMimicEvernote());
\r
108 if (appearancePage.getShowSplashScreen())
\r
109 Global.saveWindowVisible("SplashScreen", true);
\r
111 Global.saveWindowVisible("SplashScreen", false);
\r
114 if (appearancePage.getPdfPreview())
\r
115 Global.setPdfPreview(true);
\r
117 Global.setPdfPreview(false);
\r
119 if (appearancePage.getNewNoteWithTags())
\r
120 Global.setNewNoteWithSelectedTags(true);
\r
122 Global.setNewNoteWithSelectedTags(false);
\r
124 Global.setAutoSaveInterval(appearancePage.getAutoSaveInterval());
\r
126 Global.setAutomaticLogin(connectionPage.getAutomaticLogin());
\r
127 Global.setRememberPassword(connectionPage.getRememberPassword());
\r
128 if (connectionPage.getRememberPassword()) {
\r
129 aes.setPassword(connectionPage.getPassword());
\r
131 Global.setShowTrayIcon(appearancePage.getShowTrayIcon());
\r
132 Global.setVerifyDelete(appearancePage.getVerifyDelete());
\r
133 Global.setSynchronizeOnClose(connectionPage.getSynchronizeOnClose());
\r
134 Global.setSynchronizeDeletedContent(connectionPage.getSynchronizeDeletedContent());
\r
135 Global.setTagBehavior(appearancePage.getTagBehavior());
\r
136 FileOutputStream out = null;
\r
138 out = new FileOutputStream(Global.getFileManager().getHomeDirFile("secure.txt"));
\r
139 } catch (FileNotFoundException e) {
\r
140 // if it isn't found we'll write it.
\r
144 Global.userStoreUrl = "https://"+debugPage.getServer()+"/edam/user";
\r
145 Global.setWordRegex(indexPage.getRegex());
\r
146 Global.setRecognitionWeight(indexPage.getRecognitionWeight());
\r
147 Global.setMinimumWordLength(indexPage.getWordLength());
\r
148 Global.minimumWordCount = indexPage.getWordLength();
\r
149 Global.setIndexThreads(indexPage.getIndexThreads());
\r
150 Global.setMessageLevel( debugPage.getDebugLevel());
\r
151 Global.saveCarriageReturnFix(debugPage.getCarriageReturnFix());
\r
152 Global.enableCarriageReturnFix = debugPage.getCarriageReturnFix();
\r
154 String guiFormat = appearancePage.getStyle();
\r
155 QApplication.setStyle(guiFormat);
\r
156 QApplication.style().standardPalette();
\r
157 Global.setStyle(guiFormat);
\r
158 Global.setStandardPalette(appearancePage.getStandardPalette());
\r
159 if (Global.useStandardPalette())
\r
160 QApplication.setPalette(QApplication.style().standardPalette());
\r
162 QApplication.setPalette(Global.originalPalette);
\r
164 String dateFmt = appearancePage.getDateFormat();
\r
165 String timeFmt = appearancePage.getTimeFormat();
\r
166 int dash = dateFmt.indexOf("-");
\r
167 dateFmt = dateFmt.substring(0,dash-1);
\r
168 dash = timeFmt.indexOf("-");
\r
169 timeFmt = timeFmt.substring(0,dash-1);
\r
171 Global.setDateFormat(dateFmt);
\r
172 Global.setTimeFormat(timeFmt);
\r
174 Global.setSyncInterval(connectionPage.getSyncInterval());
\r
179 public void reject() {
\r
180 QApplication.setStyle(Global.getStyle());
\r
184 public ConfigDebugPage getDebugPage() {
\r
189 public ConfigConnectionPage getConfigPage() {
\r
190 return connectionPage;
\r
193 public void createIcons() {
\r
194 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
197 QListWidgetItem formatsButton = new QListWidgetItem(contentsWidget);
\r
198 formatsButton.setText(tr("Appearance"));
\r
199 formatsButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
200 formatsButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
201 formatsButton.setIcon(new QIcon(iconPath+"appearance.jpg"));
\r
203 QListWidgetItem indexButton = new QListWidgetItem(contentsWidget);
\r
204 indexButton.setText(tr("Indexing"));
\r
205 indexButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
206 indexButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
207 indexButton.setIcon(new QIcon(iconPath+"search_config.jpg"));
\r
209 QListWidgetItem configButton = new QListWidgetItem(contentsWidget);
\r
210 configButton.setText(tr("Connection"));
\r
211 configButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
212 configButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
213 configButton.setIcon(new QIcon(iconPath+"synchronize.png"));
\r
215 QListWidgetItem debugButton = new QListWidgetItem(contentsWidget);
\r
216 debugButton.setText(tr("Debugging"));
\r
217 debugButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());
\r
218 debugButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);
\r
219 debugButton.setIcon(new QIcon(iconPath+"debug.jpg"));
\r
221 contentsWidget.currentItemChanged.connect(this, "changePage(QListWidgetItem, QListWidgetItem)");
\r
224 protected void changePage(QListWidgetItem current, QListWidgetItem previous) {
\r
225 pagesWidget.setCurrentIndex(contentsWidget.row(current));
\r
228 private void loadSettings() {
\r
229 Global.originalPalette = QApplication.palette();
\r
231 debugPage.setServer(Global.getServer());
\r
232 debugPage.setDisableUploads(Global.disableUploads);
\r
233 // if (Global.getUpdateSequenceNumber() > 0)
\r
234 debugPage.serverCombo.setEnabled(false);
\r
236 if (Global.username.equalsIgnoreCase("") || Global.password.equalsIgnoreCase("")) {
\r
237 AESEncrypter aes = new AESEncrypter();
\r
239 aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("secure.txt")));
\r
240 } catch (FileNotFoundException e) {
\r
241 // File not found, so we'll just get empty strings anyway.
\r
243 String userid = aes.getUserid();
\r
244 String password = aes.getPassword();
\r
245 if (!userid.equals("") && !password.equals("")) {
\r
246 Global.username = userid;
\r
247 Global.password = password;
\r
250 appearancePage.setAutoSaveInterval(Global.getAutoSaveInterval());
\r
251 connectionPage.setUserid(Global.username);
\r
252 connectionPage.setPassword(Global.password);
\r
253 connectionPage.setAutomaticLogin(Global.automaticLogin());
\r
254 connectionPage.setRememberPassword(Global.rememberPassword());
\r
255 appearancePage.setMimicEvernote(Global.getMimicEvernoteInterface());
\r
256 appearancePage.setShowTrayIcon(Global.showTrayIcon());
\r
257 connectionPage.setSynchronizeOnClose(Global.synchronizeOnClose());
\r
258 connectionPage.setSyncronizeDeletedContent(Global.synchronizeDeletedContent());
\r
259 appearancePage.setVerifyDelete(Global.verifyDelete());
\r
260 appearancePage.setPdfPreview(Global.pdfPreview());
\r
261 appearancePage.setNewNoteWithTags(Global.newNoteWithSelectedTags());
\r
262 appearancePage.setShowSplashScreen(Global.isWindowVisible("SplashScreen"));
\r
263 appearancePage.setTagBehavior(Global.tagBehavior());
\r
265 indexPage.setRegex(Global.getWordRegex());
\r
266 indexPage.setWordLength(Global.getMinimumWordLength());
\r
267 indexPage.setIndexThreads(Global.getIndexThreads());
\r
268 connectionPage.setSyncInterval(Global.getSyncInterval());
\r
270 appearancePage.setDateFormat(Global.getDateFormat());
\r
271 appearancePage.setTimeFormat(Global.getTimeFormat());
\r
272 appearancePage.setStyle(Global.getStyle());
\r
273 appearancePage.setStandardPalette(Global.useStandardPalette());
\r
275 debugPage.setDebugLevel(Global.getMessageLevel());
\r
276 debugPage.setCarriageReturnFix(Global.enableCarriageReturnFix());
\r