2 * This file is part of NeverNote
3 * Copyright 2009 Randy Baumgarte
5 * This file may be licensed under the terms of of the
6 * GNU General Public License Version 2 (the ``GPL'').
8 * Software distributed under the License is distributed
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
10 * express or implied. See the GPL for the specific language
11 * governing rights and limitations.
13 * You should have received a copy of the GPL along with this
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
15 * or write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 package cx.fbn.nevernote;
20 import java.awt.Desktop;
22 import java.io.FileInputStream;
23 import java.io.FileNotFoundException;
24 import java.security.MessageDigest;
25 import java.security.NoSuchAlgorithmException;
26 import java.sql.Connection;
27 import java.sql.DriverManager;
28 import java.sql.SQLException;
29 import java.text.SimpleDateFormat;
30 import java.util.ArrayList;
31 import java.util.Calendar;
32 import java.util.Collections;
33 import java.util.Comparator;
34 import java.util.Date;
35 import java.util.GregorianCalendar;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.SortedMap;
39 import java.util.Vector;
41 import org.apache.thrift.TException;
43 import com.evernote.edam.error.EDAMNotFoundException;
44 import com.evernote.edam.error.EDAMSystemException;
45 import com.evernote.edam.error.EDAMUserException;
46 import com.evernote.edam.notestore.NoteFilter;
47 import com.evernote.edam.notestore.NoteVersionId;
48 import com.evernote.edam.type.Data;
49 import com.evernote.edam.type.Note;
50 import com.evernote.edam.type.NoteAttributes;
51 import com.evernote.edam.type.Notebook;
52 import com.evernote.edam.type.QueryFormat;
53 import com.evernote.edam.type.Resource;
54 import com.evernote.edam.type.SavedSearch;
55 import com.evernote.edam.type.Tag;
56 import com.evernote.edam.type.User;
57 import com.trolltech.qt.QThread;
58 import com.trolltech.qt.core.QByteArray;
59 import com.trolltech.qt.core.QDataStream;
60 import com.trolltech.qt.core.QDateTime;
61 import com.trolltech.qt.core.QDir;
62 import com.trolltech.qt.core.QFile;
63 import com.trolltech.qt.core.QFileInfo;
64 import com.trolltech.qt.core.QFileSystemWatcher;
65 import com.trolltech.qt.core.QIODevice;
66 import com.trolltech.qt.core.QIODevice.OpenModeFlag;
67 import com.trolltech.qt.core.QLocale;
68 import com.trolltech.qt.core.QModelIndex;
69 import com.trolltech.qt.core.QSize;
70 import com.trolltech.qt.core.QTemporaryFile;
71 import com.trolltech.qt.core.QTextCodec;
72 import com.trolltech.qt.core.QThreadPool;
73 import com.trolltech.qt.core.QTimer;
74 import com.trolltech.qt.core.QTranslator;
75 import com.trolltech.qt.core.QUrl;
76 import com.trolltech.qt.core.Qt;
77 import com.trolltech.qt.core.Qt.SortOrder;
78 import com.trolltech.qt.core.Qt.WidgetAttribute;
79 import com.trolltech.qt.gui.QAbstractItemView;
80 import com.trolltech.qt.gui.QAbstractItemView.ScrollHint;
81 import com.trolltech.qt.gui.QAction;
82 import com.trolltech.qt.gui.QApplication;
83 import com.trolltech.qt.gui.QCloseEvent;
84 import com.trolltech.qt.gui.QColor;
85 import com.trolltech.qt.gui.QComboBox;
86 import com.trolltech.qt.gui.QComboBox.InsertPolicy;
87 import com.trolltech.qt.gui.QCursor;
88 import com.trolltech.qt.gui.QDesktopServices;
89 import com.trolltech.qt.gui.QDialog;
90 import com.trolltech.qt.gui.QFileDialog;
91 import com.trolltech.qt.gui.QFileDialog.AcceptMode;
92 import com.trolltech.qt.gui.QFileDialog.FileMode;
93 import com.trolltech.qt.gui.QGridLayout;
94 import com.trolltech.qt.gui.QHBoxLayout;
95 import com.trolltech.qt.gui.QIcon;
96 import com.trolltech.qt.gui.QImage;
97 import com.trolltech.qt.gui.QLabel;
98 import com.trolltech.qt.gui.QListWidget;
99 import com.trolltech.qt.gui.QMainWindow;
100 import com.trolltech.qt.gui.QMenu;
101 import com.trolltech.qt.gui.QMessageBox;
102 import com.trolltech.qt.gui.QMessageBox.StandardButton;
103 import com.trolltech.qt.gui.QPixmap;
104 import com.trolltech.qt.gui.QPrintDialog;
105 import com.trolltech.qt.gui.QPrinter;
106 import com.trolltech.qt.gui.QProgressBar;
107 import com.trolltech.qt.gui.QSizePolicy;
108 import com.trolltech.qt.gui.QSizePolicy.Policy;
109 import com.trolltech.qt.gui.QSpinBox;
110 import com.trolltech.qt.gui.QSplashScreen;
111 import com.trolltech.qt.gui.QSplitter;
112 import com.trolltech.qt.gui.QStatusBar;
113 import com.trolltech.qt.gui.QSystemTrayIcon;
114 import com.trolltech.qt.gui.QTableWidgetItem;
115 import com.trolltech.qt.gui.QTextEdit;
116 import com.trolltech.qt.gui.QToolBar;
117 import com.trolltech.qt.gui.QTreeWidgetItem;
118 import com.trolltech.qt.webkit.QWebPage.WebAction;
119 import com.trolltech.qt.webkit.QWebSettings;
120 import com.trolltech.qt.xml.QDomAttr;
121 import com.trolltech.qt.xml.QDomDocument;
122 import com.trolltech.qt.xml.QDomElement;
123 import com.trolltech.qt.xml.QDomNodeList;
125 import cx.fbn.nevernote.config.FileManager;
126 import cx.fbn.nevernote.config.InitializationException;
127 import cx.fbn.nevernote.config.StartupConfig;
128 import cx.fbn.nevernote.dialog.AccountDialog;
129 import cx.fbn.nevernote.dialog.ConfigDialog;
130 import cx.fbn.nevernote.dialog.DatabaseLoginDialog;
131 import cx.fbn.nevernote.dialog.DatabaseStatus;
132 import cx.fbn.nevernote.dialog.FindDialog;
133 import cx.fbn.nevernote.dialog.LoginDialog;
134 import cx.fbn.nevernote.dialog.NotebookArchive;
135 import cx.fbn.nevernote.dialog.NotebookEdit;
136 import cx.fbn.nevernote.dialog.OnlineNoteHistory;
137 import cx.fbn.nevernote.dialog.SavedSearchEdit;
138 import cx.fbn.nevernote.dialog.TagEdit;
139 import cx.fbn.nevernote.dialog.ThumbnailViewer;
140 import cx.fbn.nevernote.dialog.WatchFolder;
141 import cx.fbn.nevernote.filters.EnSearch;
142 import cx.fbn.nevernote.gui.AttributeTreeWidget;
143 import cx.fbn.nevernote.gui.BrowserWindow;
144 import cx.fbn.nevernote.gui.DateAttributeFilterTable;
145 import cx.fbn.nevernote.gui.MainMenuBar;
146 import cx.fbn.nevernote.gui.NotebookTreeWidget;
147 import cx.fbn.nevernote.gui.PDFPreview;
148 import cx.fbn.nevernote.gui.SavedSearchTreeWidget;
149 import cx.fbn.nevernote.gui.TableView;
150 import cx.fbn.nevernote.gui.TagTreeWidget;
151 import cx.fbn.nevernote.gui.Thumbnailer;
152 import cx.fbn.nevernote.gui.TrashTreeWidget;
153 import cx.fbn.nevernote.sql.DatabaseConnection;
154 import cx.fbn.nevernote.sql.WatchFolderRecord;
155 import cx.fbn.nevernote.threads.IndexRunner;
156 import cx.fbn.nevernote.threads.SyncRunner;
157 import cx.fbn.nevernote.utilities.AESEncrypter;
158 import cx.fbn.nevernote.utilities.ApplicationLogger;
159 import cx.fbn.nevernote.utilities.FileImporter;
160 import cx.fbn.nevernote.utilities.FileUtils;
161 import cx.fbn.nevernote.utilities.ListManager;
162 import cx.fbn.nevernote.utilities.SyncTimes;
163 import cx.fbn.nevernote.xml.ExportData;
164 import cx.fbn.nevernote.xml.ImportData;
165 import cx.fbn.nevernote.xml.XMLInsertHilight;
168 public class NeverNote extends QMainWindow{
170 QStatusBar statusBar; // Application status bar
172 DatabaseConnection conn;
174 MainMenuBar menuBar; // Main menu bar
175 FindDialog find; // Text search in note dialog
176 List<String> emitLog; // Messages displayed in the status bar;
177 QSystemTrayIcon trayIcon; // little tray icon
178 QMenu trayMenu; // System tray menu
179 QAction trayExitAction; // Exit the application
180 QAction trayShowAction; // toggle the show/hide action
181 QAction trayAddNoteAction; // Add a note from the system tray
183 NotebookTreeWidget notebookTree; // List of notebooks
184 AttributeTreeWidget attributeTree; // List of note attributes
185 TagTreeWidget tagTree; // list of user created tags
186 SavedSearchTreeWidget savedSearchTree; // list of saved searches
187 TrashTreeWidget trashTree; // Trashcan
188 TableView noteTableView; // List of notes (the widget).
190 public BrowserWindow browserWindow; // Window containing browser & labels
191 QToolBar toolBar; // The tool bar under the menu
192 // QLineEdit searchField; // The search filter bar on the toolbar
193 QComboBox searchField; // search filter bar on the toolbar;
194 boolean searchPerformed = false; // Search was done?
195 QProgressBar quotaBar; // The current quota usage
197 ApplicationLogger logger;
198 List<String> selectedNotebookGUIDs; // List of notebook GUIDs
199 List<String> selectedTagGUIDs; // List of selected tag GUIDs
200 List<String> selectedNoteGUIDs; // List of selected notes
201 String selectedSavedSearchGUID; // Currently selected saved searches
203 NoteFilter filter; // Note filter
204 String currentNoteGuid; // GUID of the current note
205 Note currentNote; // The currently viewed note
206 boolean noteDirty; // Has the note been changed?
207 boolean inkNote; // if this is an ink note, it is read only
209 ListManager listManager; // DB runnable task
211 List<QTemporaryFile> tempFiles; // Array of temporary files;
213 QTimer indexTimer; // timer to start the index thread
214 IndexRunner indexRunner; // thread to index notes
217 QTimer syncTimer; // Sync on an interval
218 QTimer syncDelayTimer; // Sync delay to free up database
219 SyncRunner syncRunner; // thread to do a sync.
221 QTimer saveTimer; // Timer to save note contents
223 QTimer authTimer; // Refresh authentication
224 QTimer externalFileSaveTimer; // Save files altered externally
225 List<String> externalFiles; // External files to save later
226 List<String> importFilesKeep; // Auto-import files to save later
227 List<String> importFilesDelete; // Auto-import files to save later
229 int indexTime; // how often to try and index
230 boolean indexRunning; // Is indexing running?
231 boolean indexDisabled; // Is indexing disabled?
233 int syncThreadsReady; // number of sync threads that are free
234 int syncTime; // Sync interval
235 boolean syncRunning; // Is sync running?
236 boolean automaticSync; // do sync automatically?
237 QTreeWidgetItem attributeTreeSelected;
239 QAction prevButton; // Go to the previous item viewed
240 QAction nextButton; // Go to the next item in the history
241 QAction downButton; // Go to the next item in the list
242 QAction upButton; // Go to the prev. item in the list;
243 QAction synchronizeButton; // Synchronize with Evernote
244 List<QIcon> synchronizeAnimation; // Synchronize movie
245 QTimer synchronizeAnimationTimer; // Timer to change animation button
246 int synchronizeFrame; // Current frame being viewed
247 QAction printButton; // Print Button
248 QAction tagButton; // Tag edit button
249 QAction attributeButton; // Attribute information button
250 QAction emailButton; // Email button
251 QAction deleteButton; // Delete button
252 QAction newButton; // new Note Button;
253 QSpinBox zoomSpinner; // Zoom zoom
254 QAction searchClearButton; // Clear the search field
256 QSplitter mainLeftRightSplitter; // main splitter for left/right side
257 QSplitter leftSplitter1; // first left hand splitter
258 QSplitter browserIndexSplitter; // splitter between note index & note text
260 QFileSystemWatcher importKeepWatcher; // Watch & keep auto-import
261 QFileSystemWatcher importDeleteWatcher; // Watch & Delete auto-import
262 List<String> importedFiles; // History of imported files (so we don't import twice)
264 OnlineNoteHistory historyWindow; // online history window
265 List<NoteVersionId> versions; // history versions
267 QTimer threadMonitorTimer; // Timer to watch threads.
268 int dbThreadDeadCount=0; // number of consecutive dead times for the db thread
269 int syncThreadDeadCount=0; // number of consecutive dead times for the sync thread
270 int indexThreadDeadCount=0; // number of consecutive dead times for the index thread
271 int notebookThreadDeadCount=0; // number of consecutive dead times for the notebook thread
272 int tagDeadCount=0; // number of consecutive dead times for the tag thread
273 int trashDeadCount=0; // number of consecutive dead times for the trash thread
274 int saveThreadDeadCount=0; // number of consecutive dead times for the save thread
276 HashMap<String, String> noteCache; // Cash of note content
277 List<String> historyGuids; // GUIDs of previously viewed items
278 int historyPosition; // Position within the viewed items
279 boolean fromHistory; // Is this from the history queue?
280 String trashNoteGuid; // Guid to restore / set into or out of trash to save position
281 Thumbnailer preview; // generate preview image
282 ThumbnailViewer thumbnailViewer; // View preview thumbnail;
284 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
287 //***************************************************************
288 //***************************************************************
289 //** Constructor & main entry point
290 //***************************************************************
291 //***************************************************************
292 // Application Constructor
293 public NeverNote(DatabaseConnection dbConn) {
296 thread().setPriority(Thread.MAX_PRIORITY);
298 logger = new ApplicationLogger("nevernote.log");
299 logger.log(logger.HIGH, tr("Starting Application"));
301 conn.checkDatabaseVersion();
303 // Start building the invalid XML tables
304 Global.invalidElements = conn.getInvalidXMLTable().getInvalidElements();
305 List<String> elements = conn.getInvalidXMLTable().getInvalidAttributeElements();
307 for (int i=0; i<elements.size(); i++) {
308 Global.invalidAttributes.put(elements.get(i), conn.getInvalidXMLTable().getInvalidAttributes(elements.get(i)));
311 logger.log(logger.EXTREME, "Starting GUI build");
313 QTranslator qtTranslator = new QTranslator();
314 qtTranslator.load("classpath:/translations/qt_" + QLocale.system().name() + ".qm");
315 QApplication.instance().installTranslator(qtTranslator);
317 QTranslator nevernoteTranslator = new QTranslator();
318 nevernoteTranslator.load("classpath:/translations/nevernote_"+QLocale.system().name()+ ".qm");
319 QApplication.instance().installTranslator(nevernoteTranslator);
321 Global.originalPalette = QApplication.palette();
322 QApplication.setStyle(Global.getStyle());
323 if (Global.useStandardPalette())
324 QApplication.setPalette(QApplication.style().standardPalette());
325 setWindowTitle("NeverNote");
327 mainLeftRightSplitter = new QSplitter();
328 setCentralWidget(mainLeftRightSplitter);
329 leftSplitter1 = new QSplitter();
330 leftSplitter1.setOrientation(Qt.Orientation.Vertical);
332 browserIndexSplitter = new QSplitter();
333 browserIndexSplitter.setOrientation(Qt.Orientation.Vertical);
335 //* Setup threads & thread timers
336 int indexRunnerCount = Global.getIndexThreads();
337 indexRunnerCount = 1;
338 QThreadPool.globalInstance().setMaxThreadCount(indexRunnerCount+5); // increase max thread count
340 logger.log(logger.EXTREME, tr("Building list manager"));
341 listManager = new ListManager(conn, logger, Global.mainThreadId);
343 logger.log(logger.EXTREME, tr("Building index runners & timers"));
344 indexRunner = new IndexRunner("indexRunner.log", Global.getDatabaseUrl(), Global.getDatabaseUserid(), Global.getDatabaseUserPassword(), Global.cipherPassword);
345 indexThread = new QThread(indexRunner, "Index Thread");
348 synchronizeAnimationTimer = new QTimer();
349 synchronizeAnimationTimer.timeout.connect(this, "updateSyncButton()");
351 indexTimer = new QTimer();
352 indexTime = 1000*60*5; // look for unindexed every 5 minutes
353 // indexTime = 1000*5;
354 indexTimer.start(indexTime); // Start indexing timer
355 indexTimer.timeout.connect(this, "indexTimer()");
356 indexDisabled = false;
357 indexRunning = false;
359 logger.log(logger.EXTREME, tr("Setting sync thread & timers"));
361 syncRunner = new SyncRunner("syncRunner.log", Global.getDatabaseUrl(), Global.getDatabaseUserid(), Global.getDatabaseUserPassword(), Global.cipherPassword);
362 syncTime = new SyncTimes().timeValue(Global.getSyncInterval());
363 syncTimer = new QTimer();
364 syncTimer.timeout.connect(this, "syncTimer()");
365 syncRunner.status.message.connect(this, "setMessage(String)");
366 syncRunner.syncSignal.finished.connect(this, "syncThreadComplete(Boolean)");
367 syncRunner.syncSignal.errorDisconnect.connect(this, "remoteErrorDisconnect()");
370 automaticSync = true;
371 syncTimer.start(syncTime*60*1000);
373 automaticSync = false;
376 syncRunner.setEvernoteUpdateCount(Global.getEvernoteUpdateCount());
377 syncThread = new QThread(syncRunner, "Synchronization Thread");
381 logger.log(logger.EXTREME, tr("Starting authentication timer"));
382 authTimer = new QTimer();
383 authTimer.timeout.connect(this, "authTimer()");
384 authTimer.start(1000*60*15);
385 syncRunner.syncSignal.authRefreshComplete.connect(this, "authRefreshComplete(boolean)");
387 logger.log(logger.EXTREME, tr("Setting save note timer"));
388 saveTimer = new QTimer();
389 saveTimer.timeout.connect(this, "saveNote()");
390 if (Global.getAutoSaveInterval() > 0) {
391 saveTimer.setInterval(1000*60*Global.getAutoSaveInterval());
392 // saveTimer.setInterval(1000*10); // auto save every 20 seconds;
397 logger.log(logger.EXTREME, tr("Starting external file monitor timer"));
398 externalFileSaveTimer = new QTimer();
399 externalFileSaveTimer.timeout.connect(this, "externalFileEditedSaver()");
400 externalFileSaveTimer.setInterval(1000*5); // save every 5 seconds;
401 externalFiles = new ArrayList<String>();
402 importFilesDelete = new ArrayList<String>();
403 importFilesKeep = new ArrayList<String>();
404 externalFileSaveTimer.start();
406 notebookTree = new NotebookTreeWidget();
407 attributeTree = new AttributeTreeWidget();
408 tagTree = new TagTreeWidget(conn);
409 savedSearchTree = new SavedSearchTreeWidget();
410 trashTree = new TrashTreeWidget();
411 noteTableView = new TableView(logger);
413 QGridLayout leftGrid = new QGridLayout();
414 leftSplitter1.setLayout(leftGrid);
415 leftGrid.addWidget(notebookTree, 1, 1);
416 leftGrid.addWidget(tagTree,2,1);
417 leftGrid.addWidget(attributeTree,3,1);
418 leftGrid.addWidget(savedSearchTree,4,1);
419 leftGrid.addWidget(trashTree, 5, 1);
421 // Setup the browser window
422 noteCache = new HashMap<String,String>();
423 browserWindow = new BrowserWindow(conn);
425 browserIndexSplitter.addWidget(noteTableView);
426 browserIndexSplitter.addWidget(browserWindow);
428 mainLeftRightSplitter.addWidget(leftSplitter1);
429 mainLeftRightSplitter.addWidget(browserIndexSplitter);
431 searchField = new QComboBox();
432 searchField.setEditable(true);
433 searchField.activatedIndex.connect(this, "searchFieldChanged()");
434 searchField.setDuplicatesEnabled(false);
435 searchField.editTextChanged.connect(this,"searchFieldTextChanged(String)");
437 quotaBar = new QProgressBar();
439 // Setup the thumbnail viewer
440 thumbnailViewer = new ThumbnailViewer();
441 thumbnailViewer.upArrow.connect(this, "upAction()");
442 thumbnailViewer.downArrow.connect(this, "downAction()");
443 thumbnailViewer.leftArrow.connect(this, "nextViewedAction()");
444 thumbnailViewer.rightArrow.connect(this, "previousViewedAction()");
446 listManager.loadNotesIndex();
447 initializeNotebookTree();
449 initializeSavedSearchTree();
450 attributeTree.itemClicked.connect(this, "attributeTreeClicked(QTreeWidgetItem, Integer)");
451 attributeTreeSelected = null;
452 initializeNoteTable();
454 selectedNoteGUIDs = new ArrayList<String>();
455 statusBar = new QStatusBar();
456 setStatusBar(statusBar);
457 menuBar = new MainMenuBar(this);
458 emitLog = new ArrayList<String>();
460 tagTree.setDeleteAction(menuBar.tagDeleteAction);
461 tagTree.setEditAction(menuBar.tagEditAction);
462 tagTree.setAddAction(menuBar.tagAddAction);
463 tagTree.setVisible(Global.isWindowVisible("tagTree"));
464 tagTree.noteSignal.tagsAdded.connect(this, "tagsAdded(String, String)");
465 menuBar.hideTags.setChecked(Global.isWindowVisible("tagTree"));
466 listManager.tagSignal.listChanged.connect(this, "reloadTagTree()");
468 notebookTree.setDeleteAction(menuBar.notebookDeleteAction);
469 notebookTree.setEditAction(menuBar.notebookEditAction);
470 notebookTree.setAddAction(menuBar.notebookAddAction);
471 notebookTree.setVisible(Global.isWindowVisible("notebookTree"));
472 notebookTree.noteSignal.notebookChanged.connect(this, "updateNoteNotebook(String, String)");
473 menuBar.hideNotebooks.setChecked(Global.isWindowVisible("notebookTree"));
475 savedSearchTree.setAddAction(menuBar.savedSearchAddAction);
476 savedSearchTree.setEditAction(menuBar.savedSearchEditAction);
477 savedSearchTree.setDeleteAction(menuBar.savedSearchDeleteAction);
478 savedSearchTree.itemSelectionChanged.connect(this, "updateSavedSearchSelection()");
479 savedSearchTree.setVisible(Global.isWindowVisible("savedSearchTree"));
480 menuBar.hideSavedSearches.setChecked(Global.isWindowVisible("savedSearchTree"));
482 noteTableView.setAddAction(menuBar.noteAdd);
483 noteTableView.setDeleteAction(menuBar.noteDelete);
484 noteTableView.setRestoreAction(menuBar.noteRestoreAction);
485 noteTableView.setNoteDuplicateAction(menuBar.noteDuplicateAction);
486 noteTableView.setNoteHistoryAction(menuBar.noteOnlineHistoryAction);
487 noteTableView.noteSignal.titleColorChanged.connect(this, "titleColorChanged(Integer)");
488 noteTableView.setMergeNotesAction(menuBar.noteMergeAction);
489 noteTableView.rowChanged.connect(this, "scrollToGuid(String)");
490 noteTableView.resetViewport.connect(this, "scrollToCurrentGuid()");
491 noteTableView.doubleClicked.connect(this, "listDoubleClick()");
492 listManager.trashSignal.countChanged.connect(trashTree, "updateCounts(Integer)");
494 trashTree.itemSelectionChanged.connect(this, "trashTreeSelection()");
495 trashTree.setEmptyAction(menuBar.emptyTrashAction);
496 trashTree.setVisible(Global.isWindowVisible("trashTree"));
497 menuBar.hideTrash.setChecked(Global.isWindowVisible("trashTree"));
498 trashTree.updateCounts(listManager.getTrashCount());
500 attributeTree.setVisible(Global.isWindowVisible("attributeTree"));
501 menuBar.hideAttributes.setChecked(Global.isWindowVisible("attributeTree"));
503 noteTableView.setVisible(Global.isWindowVisible("noteList"));
504 menuBar.hideNoteList.setChecked(Global.isWindowVisible("noteList"));
506 if (!Global.isWindowVisible("editorButtonBar"))
507 toggleEditorButtonBar();
508 if (!Global.isWindowVisible("leftPanel"))
509 menuBar.hideLeftSide.setChecked(true);
513 find = new FindDialog();
514 find.getOkButton().clicked.connect(this, "doFindText()");
516 // Setup the tray icon menu bar
517 trayShowAction = new QAction("Show/Hide", this);
518 trayExitAction = new QAction("Exit", this);
519 trayAddNoteAction = new QAction("Add Note", this);
521 trayExitAction.triggered.connect(this, "close()");
522 trayAddNoteAction.triggered.connect(this, "addNote()");
523 trayShowAction.triggered.connect(this, "trayToggleVisible()");
525 trayMenu = new QMenu(this);
526 trayMenu.addAction(trayAddNoteAction);
527 trayMenu.addAction(trayShowAction);
528 trayMenu.addAction(trayExitAction);
531 trayIcon = new QSystemTrayIcon(this);
532 trayIcon.setToolTip("NeverNote");
533 trayIcon.setContextMenu(trayMenu);
534 trayIcon.activated.connect(this, "trayActivated(com.trolltech.qt.gui.QSystemTrayIcon$ActivationReason)");
537 currentNoteGuid = Global.getLastViewedNoteGuid();
538 historyGuids = new ArrayList<String>();
542 if (!currentNoteGuid.trim().equals("")) {
543 currentNote = conn.getNoteTable().getNote(currentNoteGuid, true,true,false,false,true);
546 noteIndexUpdated(true);
548 menuBar.showEditorBar.setChecked(Global.isWindowVisible("editorButtonBar"));
549 if (menuBar.showEditorBar.isChecked())
551 tagIndexUpdated(true);
552 savedSearchIndexUpdated();
553 notebookIndexUpdated();
555 setupSyncSignalListeners();
556 setupBrowserSignalListeners();
557 setupIndexListeners();
560 tagTree.tagSignal.listChanged.connect(this, "tagIndexUpdated()");
561 tagTree.showAllTags(true);
563 QIcon appIcon = new QIcon(iconPath+"nevernote.png");
564 setWindowIcon(appIcon);
565 trayIcon.setIcon(appIcon);
566 if (Global.showTrayIcon())
571 scrollToGuid(currentNoteGuid);
572 if (Global.automaticLogin()) {
574 if (Global.isConnected)
577 setupFolderImports();
580 restoreWindowState();
582 if (Global.mimicEvernoteInterface) {
583 notebookTree.selectGuid("");
586 threadMonitorTimer = new QTimer();
587 threadMonitorTimer.timeout.connect(this, "threadMonitorCheck()");
588 threadMonitorTimer.start(1000*10); // Check for threads every 10 seconds;
590 historyGuids.add(currentNoteGuid);
593 int sortCol = Global.getSortColumn();
594 int sortOrder = Global.getSortOrder();
595 noteTableView.sortByColumn(sortCol, SortOrder.resolve(sortOrder));
600 public static void main(String[] args) {
601 QApplication.initialize(args);
602 QPixmap pixmap = new QPixmap("classpath:cx/fbn/nevernote/icons/splash_logo.png");
603 QSplashScreen splash = new QSplashScreen(pixmap);
606 DatabaseConnection dbConn;
609 initializeGlobalSettings(args);
611 showSplash = Global.isWindowVisible("SplashScreen");
615 dbConn = setupDatabaseConnection();
617 // Must be last stage of setup - only safe once DB is open hence we know we are the only instance running
618 Global.getFileManager().purgeResDirectory();
620 } catch (InitializationException e) {
623 QMessageBox.critical(null, "Startup error", "Aborting: " + e.getMessage());
627 NeverNote application = new NeverNote(dbConn);
629 application.setAttribute(WidgetAttribute.WA_DeleteOnClose, true);
630 if (Global.wasWindowMaximized())
631 application.showMaximized();
635 splash.finish(application);
637 System.out.println("Goodbye.");
642 * Open the internal database, or create if not present
644 * @throws InitializationException when opening the database fails, e.g. because another process has it locked
646 private static DatabaseConnection setupDatabaseConnection() throws InitializationException {
647 ApplicationLogger logger = new ApplicationLogger("nevernote-database.log");
648 DatabaseConnection dbConn = new DatabaseConnection(logger,Global.getDatabaseUrl(), Global.getDatabaseUserid(), Global.getDatabaseUserPassword(), Global.cipherPassword);
650 if (Global.getDatabaseUrl().toUpperCase().indexOf("CIPHER=") > -1) {
651 boolean goodCheck = false;
653 DatabaseLoginDialog dialog = new DatabaseLoginDialog();
655 if (!dialog.okPressed())
657 Global.cipherPassword = dialog.getPassword();
658 goodCheck = databaseCheck(Global.getDatabaseUrl(), Global.getDatabaseUserid(),
659 Global.getDatabaseUserPassword(), Global.cipherPassword);
665 private static void initializeGlobalSettings(String[] args) throws InitializationException {
666 StartupConfig startupConfig = new StartupConfig();
668 for (String arg : args) {
669 String lower = arg.toLowerCase();
670 if (lower.startsWith("--name="))
671 startupConfig.setName(arg.substring(arg.indexOf('=') + 1));
672 if (lower.startsWith("--home="))
673 startupConfig.setHomeDirPath(arg.substring(arg.indexOf('=') + 1));
674 if (lower.startsWith("--disable-viewing"))
675 startupConfig.setDisableViewing(true);
678 Global.setup(startupConfig);
683 public void closeEvent(QCloseEvent event) {
684 logger.log(logger.HIGH, "Entering NeverNote.closeEvent");
687 if (currentNote!= null & browserWindow!=null) {
688 if (!currentNote.getTitle().equals(browserWindow.getTitle()))
689 conn.getNoteTable().updateNoteTitle(currentNote.getGuid(), browserWindow.getTitle());
692 setMessage("Beginning shutdown.");
694 externalFileEditedSaver();
695 if (Global.isConnected && Global.synchronizeOnClose()) {
696 setMessage("Performing synchronization before closing.");
697 syncRunner.addWork("SYNC");
699 setMessage("Closing Program.");
700 threadMonitorTimer.stop();
702 syncRunner.addWork("STOP");
703 indexRunner.addWork("STOP");
708 if (tempFiles != null)
711 browserWindow.noteSignal.tagsChanged.disconnect();
712 browserWindow.noteSignal.titleChanged.disconnect();
713 browserWindow.noteSignal.noteChanged.disconnect();
714 browserWindow.noteSignal.notebookChanged.disconnect();
715 browserWindow.noteSignal.createdDateChanged.disconnect();
716 browserWindow.noteSignal.alteredDateChanged.disconnect();
717 syncRunner.searchSignal.listChanged.disconnect();
718 syncRunner.tagSignal.listChanged.disconnect();
719 syncRunner.notebookSignal.listChanged.disconnect();
720 syncRunner.noteIndexSignal.listChanged.disconnect();
723 int position = noteTableView.header.visualIndex(Global.noteTableCreationPosition);
724 Global.setColumnPosition("noteTableCreationPosition", position);
725 position = noteTableView.header.visualIndex(Global.noteTableTagPosition);
726 Global.setColumnPosition("noteTableTagPosition", position);
727 position = noteTableView.header.visualIndex(Global.noteTableNotebookPosition);
728 Global.setColumnPosition("noteTableNotebookPosition", position);
729 position = noteTableView.header.visualIndex(Global.noteTableChangedPosition);
730 Global.setColumnPosition("noteTableChangedPosition", position);
731 position = noteTableView.header.visualIndex(Global.noteTableAuthorPosition);
732 Global.setColumnPosition("noteTableAuthorPosition", position);
733 position = noteTableView.header.visualIndex(Global.noteTableSourceUrlPosition);
734 Global.setColumnPosition("noteTableSourceUrlPosition", position);
735 position = noteTableView.header.visualIndex(Global.noteTableSubjectDatePosition);
736 Global.setColumnPosition("noteTableSubjectDatePosition", position);
737 position = noteTableView.header.visualIndex(Global.noteTableTitlePosition);
738 Global.setColumnPosition("noteTableTitlePosition", position);
739 position = noteTableView.header.visualIndex(Global.noteTableSynchronizedPosition);
740 Global.setColumnPosition("noteTableSynchronizedPosition", position);
742 saveNoteIndexWidth();
744 int width = notebookTree.columnWidth(0);
745 Global.setColumnWidth("notebookTreeName", width);
746 width = tagTree.columnWidth(0);
747 Global.setColumnWidth("tagTreeName", width);
749 Global.saveWindowMaximized(isMaximized());
750 Global.saveCurrentNoteGuid(currentNoteGuid);
752 int sortCol = noteTableView.proxyModel.sortColumn();
753 int sortOrder = noteTableView.proxyModel.sortOrder().value();
754 Global.setSortColumn(sortCol);
755 Global.setSortOrder(sortOrder);
759 Global.keepRunning = false;
761 logger.log(logger.MEDIUM, "Waiting for indexThread to stop");
762 indexRunner.thread().join(50);
763 logger.log(logger.MEDIUM, "Index thread has stopped");
764 } catch (InterruptedException e1) {
765 e1.printStackTrace();
767 if (!syncRunner.isIdle()) {
769 logger.log(logger.MEDIUM, "Waiting for syncThread to stop");
771 logger.log(logger.MEDIUM, "Sync thread has stopped");
772 } catch (InterruptedException e1) {
773 e1.printStackTrace();
777 logger.log(logger.HIGH, "Leaving NeverNote.closeEvent");
780 public void setMessage(String s) {
781 logger.log(logger.HIGH, "Entering NeverNote.setMessage");
782 logger.log(logger.HIGH, "Message: " +s);
783 statusBar.showMessage(s);
785 logger.log(logger.HIGH, "Leaving NeverNote.setMessage");
788 private void waitCursor(boolean wait) {
790 QApplication.setOverrideCursor(new QCursor(Qt.CursorShape.WaitCursor));
792 QApplication.restoreOverrideCursor();
795 private void setupIndexListeners() {
796 indexRunner.noteSignal.noteIndexed.connect(this, "indexThreadComplete(String)");
797 indexRunner.resourceSignal.resourceIndexed.connect(this, "indexThreadComplete(String)");
798 // indexRunner.threadSignal.indexNeeded.connect(listManager, "setIndexNeeded(String, String, Boolean)");
800 private void setupSyncSignalListeners() {
801 syncRunner.tagSignal.listChanged.connect(this, "tagIndexUpdated()");
802 syncRunner.searchSignal.listChanged.connect(this, "savedSearchIndexUpdated()");
803 syncRunner.notebookSignal.listChanged.connect(this, "notebookIndexUpdated()");
804 syncRunner.noteIndexSignal.listChanged.connect(this, "noteIndexUpdated(boolean)");
805 syncRunner.noteSignal.quotaChanged.connect(this, "updateQuotaBar()");
807 // syncRunner.syncSignal.setSequenceDate.connect(this,"setSequenceDate(long)");
808 syncRunner.syncSignal.saveUploadAmount.connect(this,"saveUploadAmount(long)");
809 // syncRunner.syncSignal.setUpdateSequenceNumber.connect(this,"setUpdateSequenceNumber(int)");
810 syncRunner.syncSignal.saveUserInformation.connect(this,"saveUserInformation(User)");
811 syncRunner.syncSignal.saveEvernoteUpdateCount.connect(this,"saveEvernoteUpdateCount(int)");
813 syncRunner.noteSignal.guidChanged.connect(this, "noteGuidChanged(String, String)");
814 syncRunner.noteSignal.noteChanged.connect(this, "invalidateNoteCache(String, String)");
815 syncRunner.resourceSignal.resourceGuidChanged.connect(this, "noteResourceGuidChanged(String,String,String)");
817 syncRunner.syncSignal.refreshLists.connect(this, "refreshLists()");
820 private void setupBrowserSignalListeners() {
822 browserWindow.fileWatcher.fileChanged.connect(this, "externalFileEdited(String)");
823 browserWindow.noteSignal.tagsChanged.connect(this, "updateNoteTags(String, List)");
824 browserWindow.noteSignal.tagsChanged.connect(this, "updateListTags(String, List)");
825 browserWindow.noteSignal.noteChanged.connect(this, "invalidateNoteCache(String, String)");
826 browserWindow.noteSignal.noteChanged.connect(this, "setNoteDirty()");
827 browserWindow.noteSignal.titleChanged.connect(listManager, "updateNoteTitle(String, String)");
828 browserWindow.noteSignal.titleChanged.connect(this, "updateListTitle(String, String)");
829 browserWindow.noteSignal.notebookChanged.connect(this, "updateNoteNotebook(String, String)");
830 browserWindow.noteSignal.createdDateChanged.connect(listManager, "updateNoteCreatedDate(String, QDateTime)");
831 browserWindow.noteSignal.createdDateChanged.connect(this, "updateListDateCreated(String, QDateTime)");
832 browserWindow.noteSignal.alteredDateChanged.connect(listManager, "updateNoteAlteredDate(String, QDateTime)");
833 browserWindow.noteSignal.alteredDateChanged.connect(this, "updateListDateChanged(String, QDateTime)");
834 browserWindow.noteSignal.subjectDateChanged.connect(listManager, "updateNoteSubjectDate(String, QDateTime)");
835 browserWindow.noteSignal.subjectDateChanged.connect(this, "updateListDateSubject(String, QDateTime)");
836 browserWindow.noteSignal.authorChanged.connect(listManager, "updateNoteAuthor(String, String)");
837 browserWindow.noteSignal.geoChanged.connect(listManager, "updateNoteGeoTag(String, Double,Double,Double)");
838 browserWindow.noteSignal.authorChanged.connect(this, "updateListAuthor(String, String)");
839 browserWindow.noteSignal.geoChanged.connect(this, "setNoteDirty()");
840 browserWindow.noteSignal.sourceUrlChanged.connect(listManager, "updateNoteSourceUrl(String, String)");
841 browserWindow.noteSignal.sourceUrlChanged.connect(this, "updateListSourceUrl(String, String)");
842 browserWindow.focusLost.connect(this, "saveNote()");
843 browserWindow.resourceSignal.contentChanged.connect(this, "externalFileEdited(String)");
844 // browserWindow.resourceSignal.externalFileEdit.connect(this, "saveResourceLater(String, String)");
849 //***************************************************************
850 //***************************************************************
851 //* Settings and look & feel
852 //***************************************************************
853 //***************************************************************
854 @SuppressWarnings("unused")
855 private void settings() {
856 logger.log(logger.HIGH, "Entering NeverNote.settings");
857 ConfigDialog settings = new ConfigDialog(this);
858 String dateFormat = Global.getDateFormat();
859 String timeFormat = Global.getTimeFormat();
862 if (Global.showTrayIcon())
867 if (menuBar.showEditorBar.isChecked())
870 // Reset the save timer
871 if (Global.getAutoSaveInterval() > 0)
872 saveTimer.setInterval(1000*60*Global.getAutoSaveInterval());
876 // This is a hack to force a reload of the index in case the date or time changed.
877 // if (!dateFormat.equals(Global.getDateFormat()) ||
878 // !timeFormat.equals(Global.getTimeFormat())) {
880 noteIndexUpdated(true);
883 logger.log(logger.HIGH, "Leaving NeverNote.settings");
885 // Restore things to the way they were
886 private void restoreWindowState() {
887 // We need to name things or this doesn't work.
888 setObjectName("NeverNote");
889 mainLeftRightSplitter.setObjectName("mainLeftRightSplitter");
890 browserIndexSplitter.setObjectName("browserIndexSplitter");
891 leftSplitter1.setObjectName("leftSplitter1");
893 // Restore the actual positions.
894 restoreGeometry(Global.restoreGeometry(objectName()));
895 mainLeftRightSplitter.restoreState(Global.restoreState(mainLeftRightSplitter.objectName()));
896 browserIndexSplitter.restoreState(Global.restoreState(browserIndexSplitter.objectName()));
897 leftSplitter1.restoreState(Global.restoreState(leftSplitter1.objectName()));
900 // Save window positions for the next start
901 private void saveWindowState() {
902 Global.saveGeometry(objectName(), saveGeometry());
903 Global.saveState(mainLeftRightSplitter.objectName(), mainLeftRightSplitter.saveState());
904 Global.saveState(browserIndexSplitter.objectName(), browserIndexSplitter.saveState());
905 Global.saveState(leftSplitter1.objectName(), leftSplitter1.saveState());
907 // Load the style sheet
908 private void loadStyleSheet() {
909 String fileName = Global.getFileManager().getQssDirPath("default.qss");
910 QFile file = new QFile(fileName);
911 file.open(OpenModeFlag.ReadOnly);
912 String styleSheet = file.readAll().toString();
914 setStyleSheet(styleSheet);
916 // Save column widths for the next time
917 private void saveNoteIndexWidth() {
919 width = noteTableView.getColumnWidth(Global.noteTableCreationPosition);
920 Global.setColumnWidth("noteTableCreationPosition", width);
921 width = noteTableView.getColumnWidth(Global.noteTableChangedPosition);
922 Global.setColumnWidth("noteTableChangedPosition", width);
923 width = noteTableView.getColumnWidth(Global.noteTableGuidPosition);
924 Global.setColumnWidth("noteTableGuidPosition", width);
925 width = noteTableView.getColumnWidth(Global.noteTableNotebookPosition);
926 Global.setColumnWidth("noteTableNotebookPosition", width);
927 width = noteTableView.getColumnWidth(Global.noteTableTagPosition);
928 Global.setColumnWidth("noteTableTagPosition", width);
929 width = noteTableView.getColumnWidth(Global.noteTableTitlePosition);
930 Global.setColumnWidth("noteTableTitlePosition", width);
931 width = noteTableView.getColumnWidth(Global.noteTableSourceUrlPosition);
932 Global.setColumnWidth("noteTableSourceUrlPosition", width);
933 width = noteTableView.getColumnWidth(Global.noteTableAuthorPosition);
934 Global.setColumnWidth("noteTableAuthorPosition", width);
935 width = noteTableView.getColumnWidth(Global.noteTableSubjectDatePosition);
936 Global.setColumnWidth("noteTableSubjectDatePosition", width);
937 width = noteTableView.getColumnWidth(Global.noteTableSynchronizedPosition);
938 Global.setColumnWidth("noteTableSynchronizedPosition", width);
942 //***************************************************************
943 //***************************************************************
944 //** These functions deal with Notebook menu items
945 //***************************************************************
946 //***************************************************************
947 // Setup the tree containing the user's notebooks.
948 private void initializeNotebookTree() {
949 logger.log(logger.HIGH, "Entering NeverNote.initializeNotebookTree");
950 notebookTree.itemSelectionChanged.connect(this, "notebookTreeSelection()");
951 listManager.notebookSignal.refreshNotebookTreeCounts.connect(notebookTree, "updateCounts(List, List)");
952 // notebookTree.resize(Global.getSize("notebookTree"));
953 logger.log(logger.HIGH, "Leaving NeverNote.initializeNotebookTree");
955 // Listener when a notebook is selected
956 @SuppressWarnings("unused")
957 private void notebookTreeSelection() {
958 logger.log(logger.HIGH, "Entering NeverNote.notebookTreeSelection");
961 clearAttributeFilter();
962 clearSavedSearchFilter();
963 if (Global.mimicEvernoteInterface) {
968 menuBar.noteRestoreAction.setVisible(false);
969 menuBar.notebookEditAction.setEnabled(true);
970 menuBar.notebookDeleteAction.setEnabled(true);
971 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
972 QTreeWidgetItem currentSelection;
973 selectedNotebookGUIDs.clear();
974 if (!Global.mimicEvernoteInterface) {
975 for (int i=0; i<selections.size(); i++) {
976 currentSelection = selections.get(i);
977 selectedNotebookGUIDs.add(currentSelection.text(2));
981 // There is the potential for no notebooks to be selected if this
982 // happens then we make it look like all notebooks were selecetd.
983 // If that happens, just select the "all notebooks"
984 selections = notebookTree.selectedItems();
985 if (selections.size()==0) {
986 selectedNotebookGUIDs.clear();
987 menuBar.notebookEditAction.setEnabled(false);
988 menuBar.notebookDeleteAction.setEnabled(false);
992 if (selections.size() > 0)
993 guid = (selections.get(0).text(2));
994 if (!guid.equals(""))
995 selectedNotebookGUIDs.add(guid);
997 listManager.setSelectedNotebooks(selectedNotebookGUIDs);
998 listManager.loadNotesIndex();
999 noteIndexUpdated(false);
1000 logger.log(logger.HIGH, "Leaving NeverNote.notebookTreeSelection");
1003 private void clearNotebookFilter() {
1004 notebookTree.blockSignals(true);
1005 notebookTree.clearSelection();
1006 menuBar.noteRestoreAction.setVisible(false);
1007 menuBar.notebookEditAction.setEnabled(false);
1008 menuBar.notebookDeleteAction.setEnabled(false);
1009 selectedNotebookGUIDs.clear();
1010 listManager.setSelectedNotebooks(selectedNotebookGUIDs);
1011 notebookTree.blockSignals(false);
1013 // Triggered when the notebook DB has been updated
1014 private void notebookIndexUpdated() {
1015 logger.log(logger.HIGH, "Entering NeverNote.notebookIndexUpdated");
1016 if (selectedNotebookGUIDs == null)
1017 selectedNotebookGUIDs = new ArrayList<String>();
1018 List<Notebook> books = conn.getNotebookTable().getAll();
1019 for (int i=books.size()-1; i>=0; i--) {
1020 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1021 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(books.get(i).getGuid())) {
1023 j=listManager.getArchiveNotebookIndex().size();
1029 listManager.countNotebookResults(listManager.getNoteIndex());
1030 notebookTree.blockSignals(true);
1031 notebookTree.load(books, listManager.getLocalNotebooks());
1032 for (int i=selectedNotebookGUIDs.size()-1; i>=0; i--) {
1033 boolean found = notebookTree.selectGuid(selectedNotebookGUIDs.get(i));
1035 selectedNotebookGUIDs.remove(i);
1037 notebookTree.blockSignals(false);
1039 logger.log(logger.HIGH, "Leaving NeverNote.notebookIndexUpdated");
1041 // Show/Hide note information
1042 private void toggleNotebookWindow() {
1043 logger.log(logger.HIGH, "Entering NeverNote.toggleNotebookWindow");
1044 if (notebookTree.isVisible())
1045 notebookTree.hide();
1047 notebookTree.show();
1048 menuBar.hideNotebooks.setChecked(notebookTree.isVisible());
1049 Global.saveWindowVisible("notebookTree", notebookTree.isVisible());
1050 logger.log(logger.HIGH, "Leaving NeverNote.toggleNotebookWindow");
1052 // Add a new notebook
1053 @SuppressWarnings("unused")
1054 private void addNotebook() {
1055 logger.log(logger.HIGH, "Inside NeverNote.addNotebook");
1056 NotebookEdit edit = new NotebookEdit();
1057 edit.setNotebooks(listManager.getNotebookIndex());
1060 if (!edit.okPressed())
1063 Calendar currentTime = new GregorianCalendar();
1064 Long l = new Long(currentTime.getTimeInMillis());
1065 String randint = new String(Long.toString(l));
1067 Notebook newBook = new Notebook();
1068 newBook.setUpdateSequenceNum(0);
1069 newBook.setGuid(randint);
1070 newBook.setName(edit.getNotebook());
1071 newBook.setServiceCreated(new Date().getTime());
1072 newBook.setServiceUpdated(new Date().getTime());
1073 newBook.setDefaultNotebook(false);
1074 newBook.setPublished(false);
1076 listManager.getNotebookIndex().add(newBook);
1078 listManager.getLocalNotebooks().add(newBook.getGuid());
1079 conn.getNotebookTable().addNotebook(newBook, true, edit.isLocal());
1080 notebookIndexUpdated();
1081 listManager.countNotebookResults(listManager.getNoteIndex());
1082 // notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
1083 logger.log(logger.HIGH, "Leaving NeverNote.addNotebook");
1085 // Edit an existing notebook
1086 @SuppressWarnings("unused")
1087 private void editNotebook() {
1088 logger.log(logger.HIGH, "Entering NeverNote.editNotebook");
1089 NotebookEdit edit = new NotebookEdit();
1090 edit.setTitle("Edit Notebook");
1091 edit.setLocalCheckboxEnabled(false);
1092 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1093 QTreeWidgetItem currentSelection;
1094 currentSelection = selections.get(0);
1095 edit.setNotebook(currentSelection.text(0));
1096 edit.setNotebooks(listManager.getNotebookIndex());
1099 if (!edit.okPressed())
1102 String guid = currentSelection.text(2);
1103 updateListNotebookName(currentSelection.text(0), edit.getNotebook());
1104 currentSelection.setText(0, edit.getNotebook());
1106 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1107 if (listManager.getNotebookIndex().get(i).getGuid().equals(guid)) {
1108 listManager.getNotebookIndex().get(i).setName(edit.getNotebook());
1109 conn.getNotebookTable().updateNotebook(listManager.getNotebookIndex().get(i), true);
1110 i=listManager.getNotebookIndex().size();
1114 // Build a list of non-closed notebooks
1115 List<Notebook> nbooks = new ArrayList<Notebook>();
1116 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1117 boolean found=false;
1118 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1119 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
1123 nbooks.add(listManager.getNotebookIndex().get(i));
1126 browserWindow.setNotebookList(nbooks);
1127 logger.log(logger.HIGH, "Leaving NeverNote.editNotebook");
1129 // Delete an existing notebook
1130 @SuppressWarnings("unused")
1131 private void deleteNotebook() {
1132 logger.log(logger.HIGH, "Entering NeverNote.deleteNotebook");
1133 boolean assigned = false;
1134 // Check if any notes have this notebook
1135 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1136 for (int i=0; i<selections.size(); i++) {
1137 QTreeWidgetItem currentSelection;
1138 currentSelection = selections.get(i);
1139 String guid = currentSelection.text(2);
1140 for (int j=0; j<listManager.getNoteIndex().size(); j++) {
1141 String noteGuid = listManager.getNoteIndex().get(j).getNotebookGuid();
1142 if (noteGuid.equals(guid)) {
1144 j=listManager.getNoteIndex().size();
1145 i=selections.size();
1150 QMessageBox.information(this, "Unable to Delete", "Some of the selected notebook(s) contain notes.\n"+
1151 "Please delete the notes or move them to another notebook before deleting any notebooks.");
1155 if (conn.getNotebookTable().getAll().size() == 1) {
1156 QMessageBox.information(this, "Unable to Delete", "You must have at least one notebook.");
1160 // If all notebooks are clear, verify the delete
1161 if (QMessageBox.question(this, "Confirmation", "Delete the selected notebooks?",
1162 QMessageBox.StandardButton.Yes,
1163 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
1167 // If confirmed, delete the notebook
1168 for (int i=selections.size()-1; i>=0; i--) {
1169 QTreeWidgetItem currentSelection;
1170 currentSelection = selections.get(i);
1171 String guid = currentSelection.text(2);
1172 conn.getNotebookTable().expungeNotebook(guid, true);
1173 listManager.deleteNotebook(guid);
1175 // for (int i=<dbRunner.getLocalNotebooks().size()-1; i>=0; i--) {
1176 // if (dbRunner.getLocalNotebooks().get(i).equals(arg0))
1178 notebookTree.load(listManager.getNotebookIndex(), listManager.getLocalNotebooks());
1179 listManager.countNotebookResults(listManager.getNoteIndex());
1180 // notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
1181 logger.log(logger.HIGH, "Entering NeverNote.deleteNotebook");
1183 // A note's notebook has been updated
1184 @SuppressWarnings("unused")
1185 private void updateNoteNotebook(String guid, String notebookGuid) {
1187 // Update the list manager
1188 listManager.updateNoteNotebook(guid, notebookGuid);
1189 listManager.countNotebookResults(listManager.getNoteIndex());
1190 // notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
1192 // Find the name of the notebook
1193 String notebookName = null;
1194 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1195 if (listManager.getNotebookIndex().get(i).getGuid().equals(notebookGuid)) {
1196 notebookName = listManager.getNotebookIndex().get(i).getName();
1197 i=listManager.getNotebookIndex().size();
1201 // If we found the name, update the browser window
1202 if (notebookName != null) {
1203 updateListNoteNotebook(guid, notebookName);
1204 if (guid.equals(currentNoteGuid)) {
1205 int pos = browserWindow.notebookBox.findText(notebookName);
1207 browserWindow.notebookBox.setCurrentIndex(pos);
1211 // If we're dealing with the current note, then we need to be sure and update the notebook there
1212 if (guid.equals(currentNoteGuid)) {
1213 if (currentNote != null) {
1214 currentNote.setNotebookGuid(notebookGuid);
1218 // Open/close notebooks
1219 @SuppressWarnings("unused")
1220 private void closeNotebooks() {
1221 NotebookArchive na = new NotebookArchive(listManager.getNotebookIndex(), listManager.getArchiveNotebookIndex());
1223 if (!na.okClicked())
1227 listManager.getArchiveNotebookIndex().clear();
1229 for (int i=na.getClosedBookList().count()-1; i>=0; i--) {
1230 String text = na.getClosedBookList().takeItem(i).text();
1231 for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
1232 if (listManager.getNotebookIndex().get(j).getName().equalsIgnoreCase(text)) {
1233 Notebook n = listManager.getNotebookIndex().get(j);
1234 conn.getNotebookTable().setArchived(n.getGuid(),true);
1235 listManager.getArchiveNotebookIndex().add(n);
1236 j=listManager.getNotebookIndex().size();
1241 for (int i=na.getOpenBookList().count()-1; i>=0; i--) {
1242 String text = na.getOpenBookList().takeItem(i).text();
1243 for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
1244 if (listManager.getNotebookIndex().get(j).getName().equalsIgnoreCase(text)) {
1245 Notebook n = listManager.getNotebookIndex().get(j);
1246 conn.getNotebookTable().setArchived(n.getGuid(),false);
1247 j=listManager.getNotebookIndex().size();
1252 listManager.loadNotesIndex();
1253 notebookIndexUpdated();
1254 noteIndexUpdated(true);
1255 // noteIndexUpdated(false);
1257 // Build a list of non-closed notebooks
1258 List<Notebook> nbooks = new ArrayList<Notebook>();
1259 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1260 boolean found=false;
1261 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1262 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
1266 nbooks.add(listManager.getNotebookIndex().get(i));
1269 browserWindow.setNotebookList(nbooks);
1276 //***************************************************************
1277 //***************************************************************
1278 //** These functions deal with Tag menu items
1279 //***************************************************************
1280 //***************************************************************
1281 // Add a new notebook
1282 @SuppressWarnings("unused")
1283 private void addTag() {
1284 logger.log(logger.HIGH, "Inside NeverNote.addTag");
1285 TagEdit edit = new TagEdit();
1286 edit.setTagList(listManager.getTagIndex());
1289 if (!edit.okPressed())
1292 Calendar currentTime = new GregorianCalendar();
1293 Long l = new Long(currentTime.getTimeInMillis());
1294 String randint = new String(Long.toString(l));
1296 Tag newTag = new Tag();
1297 newTag.setUpdateSequenceNum(0);
1298 newTag.setGuid(randint);
1299 newTag.setName(edit.getTag());
1300 conn.getTagTable().addTag(newTag, true);
1301 listManager.getTagIndex().add(newTag);
1304 logger.log(logger.HIGH, "Leaving NeverNote.addTag");
1306 private void reloadTagTree() {
1307 logger.log(logger.HIGH, "Entering NeverNote.reloadTagTree");
1308 tagIndexUpdated(false);
1309 boolean filter = false;
1310 listManager.countTagResults(listManager.getNoteIndex());
1311 if (notebookTree.selectedItems().size() > 0
1312 && !notebookTree.selectedItems().get(0).text(0).equalsIgnoreCase("All Notebooks"))
1314 if (tagTree.selectedItems().size() > 0)
1316 tagTree.showAllTags(!filter);
1317 logger.log(logger.HIGH, "Leaving NeverNote.reloadTagTree");
1319 // Edit an existing tag
1320 @SuppressWarnings("unused")
1321 private void editTag() {
1322 logger.log(logger.HIGH, "Entering NeverNote.editTag");
1323 TagEdit edit = new TagEdit();
1324 edit.setTitle("Edit Tag");
1325 List<QTreeWidgetItem> selections = tagTree.selectedItems();
1326 QTreeWidgetItem currentSelection;
1327 currentSelection = selections.get(0);
1328 edit.setTag(currentSelection.text(0));
1329 edit.setTagList(listManager.getTagIndex());
1332 if (!edit.okPressed())
1335 String guid = currentSelection.text(2);
1336 currentSelection.setText(0,edit.getTag());
1338 for (int i=0; i<listManager.getTagIndex().size(); i++) {
1339 if (listManager.getTagIndex().get(i).getGuid().equals(guid)) {
1340 listManager.getTagIndex().get(i).setName(edit.getTag());
1341 conn.getTagTable().updateTag(listManager.getTagIndex().get(i), true);
1342 updateListTagName(guid);
1343 if (currentNote != null && currentNote.getTagGuids().contains(guid))
1344 browserWindow.setTag(getTagNamesForNote(currentNote));
1345 logger.log(logger.HIGH, "Leaving NeverNote.editTag");
1349 browserWindow.setTag(getTagNamesForNote(currentNote));
1350 logger.log(logger.HIGH, "Leaving NeverNote.editTag...");
1352 // Delete an existing tag
1353 @SuppressWarnings("unused")
1354 private void deleteTag() {
1355 logger.log(logger.HIGH, "Entering NeverNote.deleteTag");
1357 if (QMessageBox.question(this, "Confirmation", "Delete the selected tags?",
1358 QMessageBox.StandardButton.Yes,
1359 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
1363 List<QTreeWidgetItem> selections = tagTree.selectedItems();
1364 for (int i=selections.size()-1; i>=0; i--) {
1365 QTreeWidgetItem currentSelection;
1366 currentSelection = selections.get(i);
1367 removeTagItem(currentSelection.text(2));
1369 tagIndexUpdated(true);
1370 listManager.countTagResults(listManager.getNoteIndex());
1371 // tagTree.updateCounts(listManager.getTagCounter());
1372 logger.log(logger.HIGH, "Leaving NeverNote.deleteTag");
1374 // Remove a tag tree item. Go recursively down & remove the children too
1375 private void removeTagItem(String guid) {
1376 for (int j=listManager.getTagIndex().size()-1; j>=0; j--) {
1377 String parent = listManager.getTagIndex().get(j).getParentGuid();
1378 if (parent != null && parent.equals(guid)) {
1379 //Remove this tag's children
1380 removeTagItem(listManager.getTagIndex().get(j).getGuid());
1383 //Now, remove this tag
1384 removeListTagName(guid);
1385 conn.getTagTable().expungeTag(guid, true);
1386 for (int a=0; a<listManager.getTagIndex().size(); a++) {
1387 if (listManager.getTagIndex().get(a).getGuid().equals(guid)) {
1388 listManager.getTagIndex().remove(a);
1393 // Setup the tree containing the user's tags
1394 private void initializeTagTree() {
1395 logger.log(logger.HIGH, "Entering NeverNote.initializeTagTree");
1396 tagTree.itemSelectionChanged.connect(this, "tagTreeSelection()");
1397 listManager.tagSignal.refreshTagTreeCounts.connect(tagTree, "updateCounts(List)");
1398 logger.log(logger.HIGH, "Leaving NeverNote.initializeTagTree");
1400 // Listener when a tag is selected
1401 @SuppressWarnings("unused")
1402 private void tagTreeSelection() {
1403 logger.log(logger.HIGH, "Entering NeverNote.tagTreeSelection");
1405 List<QTreeWidgetItem> x = tagTree.selectedItems();
1406 for (int i=0; i<x.size(); i++) {
1410 clearAttributeFilter();
1411 clearSavedSearchFilter();
1413 menuBar.noteRestoreAction.setVisible(false);
1415 List<QTreeWidgetItem> selections = tagTree.selectedItems();
1416 QTreeWidgetItem currentSelection;
1417 selectedTagGUIDs.clear();
1418 for (int i=0; i<selections.size(); i++) {
1419 currentSelection = selections.get(i);
1420 selectedTagGUIDs.add(currentSelection.text(2));
1422 if (selections.size() > 0) {
1423 menuBar.tagEditAction.setEnabled(true);
1424 menuBar.tagDeleteAction.setEnabled(true);
1427 menuBar.tagEditAction.setEnabled(false);
1428 menuBar.tagDeleteAction.setEnabled(false);
1430 listManager.setSelectedTags(selectedTagGUIDs);
1431 listManager.loadNotesIndex();
1432 noteIndexUpdated(false);
1433 logger.log(logger.HIGH, "Leaving NeverNote.tagTreeSelection");
1435 // trigger the tag index to be refreshed
1436 @SuppressWarnings("unused")
1437 private void tagIndexUpdated() {
1438 tagIndexUpdated(true);
1440 private void tagIndexUpdated(boolean reload) {
1441 logger.log(logger.HIGH, "Entering NeverNote.tagIndexUpdated");
1442 if (selectedTagGUIDs == null)
1443 selectedTagGUIDs = new ArrayList<String>();
1444 // selectedTagGUIDs.clear(); // clear out old entries
1446 tagTree.blockSignals(true);
1448 tagTree.load(listManager.getTagIndex());
1449 for (int i=selectedTagGUIDs.size()-1; i>=0; i--) {
1450 boolean found = tagTree.selectGuid(selectedTagGUIDs.get(i));
1452 selectedTagGUIDs.remove(i);
1454 tagTree.blockSignals(false);
1456 browserWindow.setTag(getTagNamesForNote(currentNote));
1457 logger.log(logger.HIGH, "Leaving NeverNote.tagIndexUpdated");
1459 // Show/Hide note information
1460 private void toggleTagWindow() {
1461 logger.log(logger.HIGH, "Entering NeverNote.toggleTagWindow");
1462 if (tagTree.isVisible())
1466 menuBar.hideTags.setChecked(tagTree.isVisible());
1467 Global.saveWindowVisible("tagTree", tagTree.isVisible());
1468 logger.log(logger.HIGH, "Leaving NeverNote.toggleTagWindow");
1470 // A note's tags have been updated
1471 @SuppressWarnings("unused")
1472 private void updateNoteTags(String guid, List<String> tags) {
1473 // Save any new tags. We'll need them later.
1474 List<String> newTags = new ArrayList<String>();
1475 for (int i=0; i<tags.size(); i++) {
1476 if (conn.getTagTable().findTagByName(tags.get(i))==null)
1477 newTags.add(tags.get(i));
1480 listManager.saveNoteTags(guid, tags);
1481 listManager.countTagResults(listManager.getNoteIndex());
1482 StringBuffer names = new StringBuffer("");
1483 for (int i=0; i<tags.size(); i++) {
1484 names = names.append(tags.get(i));
1485 if (i<tags.size()-1) {
1486 names.append(Global.tagDelimeter + " ");
1489 browserWindow.setTag(names.toString());
1492 // Now, we need to add any new tags to the tag tree
1493 for (int i=0; i<newTags.size(); i++)
1494 tagTree.insertTag(newTags.get(i), conn.getTagTable().findTagByName(newTags.get(i)));
1496 // Get a string containing all tag names for a note
1497 private String getTagNamesForNote(Note n) {
1498 logger.log(logger.HIGH, "Entering NeverNote.getTagNamesForNote");
1499 if (n==null || n.getGuid() == null || n.getGuid().equals(""))
1501 StringBuffer buffer = new StringBuffer(100);
1502 Vector<String> v = new Vector<String>();
1503 List<String> guids = n.getTagGuids();
1508 for (int i=0; i<guids.size(); i++) {
1509 v.add(listManager.getTagNameByGuid(guids.get(i)));
1511 Comparator<String> comparator = Collections.reverseOrder();
1512 Collections.sort(v,comparator);
1513 Collections.reverse(v);
1515 for (int i = 0; i<v.size(); i++) {
1517 buffer.append(", ");
1518 buffer.append(v.get(i));
1521 logger.log(logger.HIGH, "Leaving NeverNote.getTagNamesForNote");
1522 return buffer.toString();
1524 // Tags were added via dropping notes from the note list
1525 @SuppressWarnings("unused")
1526 private void tagsAdded(String noteGuid, String tagGuid) {
1527 String tagName = null;
1528 for (int i=0; i<listManager.getTagIndex().size(); i++) {
1529 if (listManager.getTagIndex().get(i).getGuid().equals(tagGuid)) {
1530 tagName = listManager.getTagIndex().get(i).getName();
1531 i=listManager.getTagIndex().size();
1534 if (tagName == null)
1537 for (int i=0; i<noteTableView.model.rowCount(); i++) {
1538 QModelIndex modelIndex = noteTableView.model.index(i, Global.noteTableGuidPosition);
1539 if (modelIndex != null) {
1540 SortedMap<Integer, Object> ix = noteTableView.model.itemData(modelIndex);
1541 String titleGuid = (String)ix.values().toArray()[0];
1542 if (titleGuid.equals(noteGuid)) {
1543 String text = (String)noteTableView.model.data(i, Global.noteTableTagPosition);
1544 if (!text.trim().equals(""))
1545 text = text + Global.tagDelimeter + " " +tagName;
1548 noteTableView.model.setData(i, Global.noteTableTagPosition, text);
1549 noteTableView.model.setData(i, Global.noteTableSynchronizedPosition, "false");
1550 if (noteGuid.equals(currentNoteGuid))
1551 browserWindow.setTag(text);
1552 i=noteTableView.model.rowCount();
1557 private void clearTagFilter() {
1558 tagTree.blockSignals(true);
1559 tagTree.clearSelection();
1560 menuBar.noteRestoreAction.setVisible(false);
1561 menuBar.tagEditAction.setEnabled(false);
1562 menuBar.tagDeleteAction.setEnabled(false);
1563 selectedTagGUIDs.clear();
1564 listManager.setSelectedTags(selectedTagGUIDs);
1565 tagTree.blockSignals(false);
1569 //***************************************************************
1570 //***************************************************************
1571 //** These functions deal with Saved Search menu items
1572 //***************************************************************
1573 //***************************************************************
1574 // Add a new notebook
1575 @SuppressWarnings("unused")
1576 private void addSavedSearch() {
1577 logger.log(logger.HIGH, "Inside NeverNote.addSavedSearch");
1578 SavedSearchEdit edit = new SavedSearchEdit();
1579 edit.setSearchList(listManager.getSavedSearchIndex());
1582 if (!edit.okPressed())
1585 Calendar currentTime = new GregorianCalendar();
1586 Long l = new Long(currentTime.getTimeInMillis());
1587 String randint = new String(Long.toString(l));
1589 SavedSearch search = new SavedSearch();
1590 search.setUpdateSequenceNum(0);
1591 search.setGuid(randint);
1592 search.setName(edit.getName());
1593 search.setQuery(edit.getQuery());
1594 search.setFormat(QueryFormat.USER);
1595 listManager.getSavedSearchIndex().add(search);
1596 conn.getSavedSearchTable().addSavedSearch(search, true);
1597 savedSearchIndexUpdated();
1598 logger.log(logger.HIGH, "Leaving NeverNote.addSavedSearch");
1600 // Edit an existing tag
1601 @SuppressWarnings("unused")
1602 private void editSavedSearch() {
1603 logger.log(logger.HIGH, "Entering NeverNote.editSavedSearch");
1604 SavedSearchEdit edit = new SavedSearchEdit();
1605 edit.setTitle("Edit Search");
1606 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
1607 QTreeWidgetItem currentSelection;
1608 currentSelection = selections.get(0);
1609 String guid = currentSelection.text(1);
1610 SavedSearch s = conn.getSavedSearchTable().getSavedSearch(guid);
1611 edit.setName(currentSelection.text(0));
1612 edit.setQuery(s.getQuery());
1613 edit.setSearchList(listManager.getSavedSearchIndex());
1616 if (!edit.okPressed())
1619 List<SavedSearch> list = listManager.getSavedSearchIndex();
1620 SavedSearch search = null;
1621 boolean found = false;
1622 for (int i=0; i<list.size(); i++) {
1623 search = list.get(i);
1624 if (search.getGuid().equals(guid)) {
1631 search.setName(edit.getName());
1632 search.setQuery(edit.getQuery());
1633 conn.getSavedSearchTable().updateSavedSearch(search, true);
1634 savedSearchIndexUpdated();
1635 logger.log(logger.HIGH, "Leaving NeverNote.editSavedSearch");
1637 // Delete an existing tag
1638 @SuppressWarnings("unused")
1639 private void deleteSavedSearch() {
1640 logger.log(logger.HIGH, "Entering NeverNote.deleteSavedSearch");
1642 if (QMessageBox.question(this, "Confirmation", "Delete the selected search?",
1643 QMessageBox.StandardButton.Yes,
1644 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
1648 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
1649 for (int i=selections.size()-1; i>=0; i--) {
1650 QTreeWidgetItem currentSelection;
1651 currentSelection = selections.get(i);
1652 for (int j=0; j<listManager.getSavedSearchIndex().size(); j++) {
1653 if (listManager.getSavedSearchIndex().get(j).getGuid().equals(currentSelection.text(1))) {
1654 conn.getSavedSearchTable().expungeSavedSearch(listManager.getSavedSearchIndex().get(j).getGuid(), true);
1655 listManager.getSavedSearchIndex().remove(j);
1656 j=listManager.getSavedSearchIndex().size()+1;
1659 selections.remove(i);
1661 savedSearchIndexUpdated();
1662 logger.log(logger.HIGH, "Leaving NeverNote.deleteSavedSearch");
1664 // Setup the tree containing the user's tags
1665 private void initializeSavedSearchTree() {
1666 logger.log(logger.HIGH, "Entering NeverNote.initializeSavedSearchTree");
1667 savedSearchTree.itemSelectionChanged.connect(this, "savedSearchTreeSelection()");
1668 logger.log(logger.HIGH, "Leaving NeverNote.initializeSavedSearchTree");
1670 // Listener when a tag is selected
1671 @SuppressWarnings("unused")
1672 private void savedSearchTreeSelection() {
1673 logger.log(logger.HIGH, "Entering NeverNote.savedSearchTreeSelection");
1675 clearNotebookFilter();
1678 clearAttributeFilter();
1680 String currentGuid = selectedSavedSearchGUID;
1681 menuBar.savedSearchEditAction.setEnabled(true);
1682 menuBar.savedSearchDeleteAction.setEnabled(true);
1683 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
1684 QTreeWidgetItem currentSelection;
1685 selectedSavedSearchGUID = "";
1686 for (int i=0; i<selections.size(); i++) {
1687 currentSelection = selections.get(i);
1688 if (currentSelection.text(1).equals(currentGuid)) {
1689 currentSelection.setSelected(false);
1691 selectedSavedSearchGUID = currentSelection.text(1);
1693 // i = selections.size() +1;
1696 // There is the potential for no notebooks to be selected if this
1697 // happens then we make it look like all notebooks were selecetd.
1698 // If that happens, just select the "all notebooks"
1699 if (selections.size()==0) {
1700 clearSavedSearchFilter();
1702 listManager.setSelectedSavedSearch(selectedSavedSearchGUID);
1704 logger.log(logger.HIGH, "Leaving NeverNote.savedSearchTreeSelection");
1706 private void clearSavedSearchFilter() {
1707 menuBar.savedSearchEditAction.setEnabled(false);
1708 menuBar.savedSearchDeleteAction.setEnabled(false);
1709 savedSearchTree.blockSignals(true);
1710 savedSearchTree.clearSelection();
1711 savedSearchTree.blockSignals(false);
1712 selectedSavedSearchGUID = "";
1713 searchField.setEditText("");
1714 searchPerformed = false;
1715 listManager.setSelectedSavedSearch(selectedSavedSearchGUID);
1717 // trigger the tag index to be refreshed
1718 private void savedSearchIndexUpdated() {
1719 if (selectedSavedSearchGUID == null)
1720 selectedSavedSearchGUID = new String();
1721 savedSearchTree.blockSignals(true);
1722 savedSearchTree.load(listManager.getSavedSearchIndex());
1723 savedSearchTree.selectGuid(selectedSavedSearchGUID);
1724 savedSearchTree.blockSignals(false);
1726 // trigger when the saved search selection changes
1727 @SuppressWarnings("unused")
1728 private void updateSavedSearchSelection() {
1729 logger.log(logger.HIGH, "Entering NeverNote.updateSavedSearchSelection()");
1731 menuBar.savedSearchEditAction.setEnabled(true);
1732 menuBar.savedSearchDeleteAction.setEnabled(true);
1733 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
1735 if (selections.size() > 0) {
1736 menuBar.savedSearchEditAction.setEnabled(true);
1737 menuBar.savedSearchDeleteAction.setEnabled(true);
1738 selectedSavedSearchGUID = selections.get(0).text(1);
1739 SavedSearch s = conn.getSavedSearchTable().getSavedSearch(selectedSavedSearchGUID);
1740 searchField.setEditText(s.getQuery());
1742 menuBar.savedSearchEditAction.setEnabled(false);
1743 menuBar.savedSearchDeleteAction.setEnabled(false);
1744 selectedSavedSearchGUID = "";
1745 searchField.setEditText("");
1747 searchFieldChanged();
1749 logger.log(logger.HIGH, "Leaving NeverNote.updateSavedSearchSelection()");
1753 // Show/Hide note information
1754 private void toggleSavedSearchWindow() {
1755 logger.log(logger.HIGH, "Entering NeverNote.toggleSavedSearchWindow");
1756 if (savedSearchTree.isVisible())
1757 savedSearchTree.hide();
1759 savedSearchTree.show();
1760 menuBar.hideSavedSearches.setChecked(savedSearchTree.isVisible());
1762 Global.saveWindowVisible("savedSearchTree", savedSearchTree.isVisible());
1763 logger.log(logger.HIGH, "Leaving NeverNote.toggleSavedSearchWindow");
1769 //***************************************************************
1770 //***************************************************************
1771 //** These functions deal with Help menu & tool menu items
1772 //***************************************************************
1773 //***************************************************************
1774 // Show database status
1775 @SuppressWarnings("unused")
1776 private void databaseStatus() {
1778 int dirty = conn.getNoteTable().getDirtyCount();
1779 int unindexed = conn.getNoteTable().getUnindexedCount();
1780 DatabaseStatus status = new DatabaseStatus();
1781 status.setUnsynchronized(dirty);
1782 status.setUnindexed(unindexed);
1783 status.setNoteCount(conn.getNoteTable().getNoteCount());
1784 status.setNotebookCount(listManager.getNotebookIndex().size());
1785 status.setSavedSearchCount(listManager.getSavedSearchIndex().size());
1786 status.setTagCount(listManager.getTagIndex().size());
1787 status.setResourceCount(conn.getNoteTable().noteResourceTable.getResourceCount());
1788 status.setWordCount(conn.getWordsTable().getWordCount());
1792 // Compact the database
1793 @SuppressWarnings("unused")
1794 private void compactDatabase() {
1795 logger.log(logger.HIGH, "Entering NeverNote.compactDatabase");
1796 if (QMessageBox.question(this, "Confirmation", "This will free unused space in the database, "+
1797 "but please be aware that depending upon the size of your database this can be time consuming " +
1798 "and NeverNote will be unresponsive until it is complete. Do you wish to continue?",
1799 QMessageBox.StandardButton.Yes,
1800 QMessageBox.StandardButton.No)==StandardButton.No.value() && Global.verifyDelete() == true) {
1803 setMessage("Compacting database.");
1805 listManager.compactDatabase();
1807 setMessage("Database compact is complete.");
1808 logger.log(logger.HIGH, "Leaving NeverNote.compactDatabase");
1810 @SuppressWarnings("unused")
1811 private void accountInformation() {
1812 logger.log(logger.HIGH, "Entering NeverNote.accountInformation");
1813 AccountDialog dialog = new AccountDialog();
1815 logger.log(logger.HIGH, "Leaving NeverNote.accountInformation");
1817 @SuppressWarnings("unused")
1818 private void releaseNotes() {
1819 logger.log(logger.HIGH, "Entering NeverNote.releaseNotes");
1820 QDialog dialog = new QDialog(this);
1821 QHBoxLayout layout = new QHBoxLayout();
1822 QTextEdit textBox = new QTextEdit();
1823 layout.addWidget(textBox);
1824 textBox.setReadOnly(true);
1825 QFile file = new QFile(Global.getFileManager().getHomeDirPath("release.txt"));
1826 if (!file.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly,
1827 QIODevice.OpenModeFlag.Text)))
1829 textBox.setText(file.readAll().toString());
1831 dialog.setWindowTitle("Release Notes");
1832 dialog.setLayout(layout);
1834 logger.log(logger.HIGH, "Leaving NeverNote.releaseNotes");
1836 // Called when user picks Log from the help menu
1837 @SuppressWarnings("unused")
1838 private void logger() {
1839 logger.log(logger.HIGH, "Entering NeverNote.logger");
1840 QDialog dialog = new QDialog(this);
1841 QHBoxLayout layout = new QHBoxLayout();
1842 QListWidget textBox = new QListWidget();
1843 layout.addWidget(textBox);
1844 textBox.addItems(emitLog);
1846 dialog.setLayout(layout);
1847 dialog.setWindowTitle("Mesasge Log");
1849 logger.log(logger.HIGH, "Leaving NeverNote.logger");
1851 // Menu option "help/about" was selected
1852 @SuppressWarnings("unused")
1853 private void about() {
1854 logger.log(logger.HIGH, "Entering NeverNote.about");
1855 QMessageBox.about(this,
1856 tr("About NeverNote"),
1857 tr("<h4><center><b>NeverNote</b></center></h4><hr><center>Version "+Global.version+"<hr></center>Evernote"
1858 +" Generic client.<br><br>"
1859 +"Licensed under GPL v2. <br><hr><br>"
1860 +"Evernote is copyright 2001-2010 by Evernote Corporation<br>"
1861 +"Jambi and QT are the licensed trademark of Nokia Corporation<br>"
1862 +"PDFRenderer is licened under the LGPL<br>"
1863 +"Jazzy is licened under the LGPL<br>"
1864 +"Java is a registered trademark of Sun Microsystems.<br><hr>"));
1865 logger.log(logger.HIGH, "Leaving NeverNote.about");
1867 // Hide the entire left hand side
1868 @SuppressWarnings("unused")
1869 private void toggleLeftSide() {
1872 hidden = !menuBar.hideLeftSide.isChecked();
1873 menuBar.hideLeftSide.setChecked(!hidden);
1875 if (notebookTree.isVisible() != hidden)
1876 toggleNotebookWindow();
1877 if (savedSearchTree.isVisible() != hidden)
1878 toggleSavedSearchWindow();
1879 if (tagTree.isVisible() != hidden)
1881 if (attributeTree.isVisible() != hidden)
1882 toggleAttributesWindow();
1883 if (trashTree.isVisible() != hidden)
1884 toggleTrashWindow();
1886 Global.saveWindowVisible("leftPanel", hidden);
1891 //***************************************************************
1892 //***************************************************************
1893 //** These functions deal with the Toolbar
1894 //***************************************************************
1895 //***************************************************************
1896 // Text in the search bar has been cleared
1897 private void searchFieldCleared() {
1898 searchField.setEditText("");
1899 saveNoteIndexWidth();
1901 // text in the search bar changed. We only use this to tell if it was cleared,
1902 // otherwise we trigger off searchFieldChanged.
1903 @SuppressWarnings("unused")
1904 private void searchFieldTextChanged(String text) {
1905 if (text.trim().equals("")) {
1906 searchFieldCleared();
1907 if (searchPerformed) {
1909 listManager.setEnSearch("");
1910 ///// listManager.clearNoteIndexSearch();
1911 //noteIndexUpdated(true);
1912 listManager.loadNotesIndex();
1913 refreshEvernoteNote(true);
1914 noteIndexUpdated(false);
1916 searchPerformed = false;
1919 // Text in the toolbar has changed
1920 private void searchFieldChanged() {
1921 logger.log(logger.HIGH, "Entering NeverNote.searchFieldChanged");
1923 saveNoteIndexWidth();
1924 String text = searchField.currentText();
1925 listManager.setEnSearch(text.trim());
1926 listManager.loadNotesIndex();
1927 //--->>> noteIndexUpdated(true);
1928 noteIndexUpdated(false);
1929 refreshEvernoteNote(true);
1930 searchPerformed = true;
1931 logger.log(logger.HIGH, "Leaving NeverNote.searchFieldChanged");
1933 // Build the window tool bar
1934 private void setupToolBar() {
1935 logger.log(logger.HIGH, "Entering NeverNote.setupToolBar");
1936 toolBar = addToolBar(tr("toolBar"));
1938 prevButton = toolBar.addAction("Previous");
1939 QIcon prevIcon = new QIcon(iconPath+"back.png");
1940 prevButton.setIcon(prevIcon);
1941 prevButton.triggered.connect(this, "previousViewedAction()");
1943 nextButton = toolBar.addAction("Next");
1944 QIcon nextIcon = new QIcon(iconPath+"forward.png");
1945 nextButton.setIcon(nextIcon);
1946 nextButton.triggered.connect(this, "nextViewedAction()");
1948 upButton = toolBar.addAction("Up");
1949 QIcon upIcon = new QIcon(iconPath+"up.png");
1950 upButton.setIcon(upIcon);
1951 upButton.triggered.connect(this, "upAction()");
1953 downButton = toolBar.addAction("Down");
1954 QIcon downIcon = new QIcon(iconPath+"down.png");
1955 downButton.setIcon(downIcon);
1956 downButton.triggered.connect(this, "downAction()");
1958 synchronizeButton = toolBar.addAction("Synchronize");
1959 synchronizeAnimation = new ArrayList<QIcon>();
1960 synchronizeAnimation.add(new QIcon(iconPath+"synchronize-0.png"));
1961 synchronizeAnimation.add(new QIcon(iconPath+"synchronize-1.png"));
1962 synchronizeAnimation.add(new QIcon(iconPath+"synchronize-2.png"));
1963 synchronizeAnimation.add(new QIcon(iconPath+"synchronize-3.png"));
1964 synchronizeButton.setIcon(synchronizeAnimation.get(0));
1965 synchronizeFrame = 0;
1966 synchronizeButton.triggered.connect(this, "evernoteSync()");
1968 printButton = toolBar.addAction("Print");
1969 QIcon printIcon = new QIcon(iconPath+"print.png");
1970 printButton.setIcon(printIcon);
1971 printButton.triggered.connect(this, "printNote()");
1973 tagButton = toolBar.addAction("Tag");
1974 QIcon tagIcon = new QIcon(iconPath+"tag.png");
1975 tagButton.setIcon(tagIcon);
1976 tagButton.triggered.connect(browserWindow, "modifyTags()");
1978 attributeButton = toolBar.addAction("Attributes");
1979 QIcon attributeIcon = new QIcon(iconPath+"attribute.png");
1980 attributeButton.setIcon(attributeIcon);
1981 attributeButton.triggered.connect(this, "toggleNoteInformation()");
1983 emailButton = toolBar.addAction("Email");
1984 QIcon emailIcon = new QIcon(iconPath+"email.png");
1985 emailButton.setIcon(emailIcon);
1986 emailButton.triggered.connect(this, "emailNote()");
1988 deleteButton = toolBar.addAction("Delete");
1989 QIcon deleteIcon = new QIcon(iconPath+"delete.png");
1990 deleteButton.setIcon(deleteIcon);
1991 deleteButton.triggered.connect(this, "deleteNote()");
1993 newButton = toolBar.addAction("New");
1994 QIcon newIcon = new QIcon(iconPath+"new.png");
1995 newButton.triggered.connect(this, "addNote()");
1996 newButton.setIcon(newIcon);
1997 toolBar.addSeparator();
1998 toolBar.addWidget(new QLabel("Quota:"));
1999 toolBar.addWidget(quotaBar);
2000 //quotaBar.setSizePolicy(Policy.Minimum, Policy.Minimum);
2004 zoomSpinner = new QSpinBox();
2005 zoomSpinner.setMinimum(10);
2006 zoomSpinner.setMaximum(1000);
2007 zoomSpinner.setAccelerated(true);
2008 zoomSpinner.setSingleStep(10);
2009 zoomSpinner.setValue(100);
2010 zoomSpinner.valueChanged.connect(this, "zoomChanged()");
2011 toolBar.addWidget(new QLabel("Zoom"));
2012 toolBar.addWidget(zoomSpinner);
2014 //toolBar.addWidget(new QLabel(" "));
2015 toolBar.addSeparator();
2016 toolBar.addWidget(new QLabel(" Search:"));
2017 toolBar.addWidget(searchField);
2018 QSizePolicy sizePolicy = new QSizePolicy();
2019 sizePolicy.setHorizontalPolicy(Policy.MinimumExpanding);
2020 searchField.setSizePolicy(sizePolicy);
2021 searchField.setInsertPolicy(InsertPolicy.InsertAtTop);
2023 searchClearButton = toolBar.addAction("Search Clear");
2024 QIcon searchClearIcon = new QIcon(iconPath+"searchclear.png");
2025 searchClearButton.setIcon(searchClearIcon);
2026 searchClearButton.triggered.connect(this, "searchFieldCleared()");
2028 logger.log(logger.HIGH, "Leaving NeverNote.setupToolBar");
2030 // Update the sychronize button picture
2031 @SuppressWarnings("unused")
2032 private void updateSyncButton() {
2034 if (synchronizeFrame == 4)
2035 synchronizeFrame = 0;
2036 synchronizeButton.setIcon(synchronizeAnimation.get(synchronizeFrame));
2038 // Synchronize with Evernote
2039 @SuppressWarnings("unused")
2040 private void evernoteSync() {
2041 logger.log(logger.HIGH, "Entering NeverNote.evernoteSync");
2042 if (!Global.isConnected)
2044 if (Global.isConnected)
2045 synchronizeAnimationTimer.start(200);
2047 logger.log(logger.HIGH, "Leaving NeverNote.evernoteSync");
2049 private void updateQuotaBar() {
2050 long limit = Global.getUploadLimit();
2051 long amount = Global.getUploadAmount();
2052 if (amount>0 && limit>0) {
2053 int percent =(int)(amount*100/limit);
2054 quotaBar.setValue(percent);
2056 quotaBar.setValue(0);
2059 @SuppressWarnings("unused")
2060 private void zoomChanged() {
2061 browserWindow.getBrowser().setZoomFactor(new Double(zoomSpinner.value())/100);
2064 //****************************************************************
2065 //****************************************************************
2066 //* System Tray functions
2067 //****************************************************************
2068 //****************************************************************
2069 private void trayToggleVisible() {
2077 @SuppressWarnings("unused")
2078 private void trayActivated(QSystemTrayIcon.ActivationReason reason) {
2079 if (reason == QSystemTrayIcon.ActivationReason.DoubleClick) {
2080 String name = QSystemTrayIcon.MessageIcon.resolve(reason.value()).name();
2081 trayToggleVisible();
2086 //***************************************************************
2087 //***************************************************************
2088 //** These functions deal with the trash tree
2089 //***************************************************************
2090 //***************************************************************
2091 // Setup the tree containing the trash.
2092 @SuppressWarnings("unused")
2093 private void trashTreeSelection() {
2094 logger.log(logger.HIGH, "Entering NeverNote.trashTreeSelection");
2096 clearNotebookFilter();
2098 clearAttributeFilter();
2099 clearSavedSearchFilter();
2101 String tempGuid = currentNoteGuid;
2103 // currentNoteGuid = "";
2104 currentNote = new Note();
2105 selectedNoteGUIDs.clear();
2106 listManager.getSelectedNotebooks().clear();
2107 listManager.getSelectedTags().clear();
2108 listManager.setSelectedSavedSearch("");
2109 browserWindow.clear();
2111 // toggle the add buttons
2112 newButton.setEnabled(!newButton.isEnabled());
2113 menuBar.noteAdd.setEnabled(newButton.isEnabled());
2114 menuBar.noteAdd.setVisible(true);
2116 List<QTreeWidgetItem> selections = trashTree.selectedItems();
2117 if (selections.size() == 0) {
2118 currentNoteGuid = trashNoteGuid;
2119 trashNoteGuid = tempGuid;
2120 Global.showDeleted = false;
2121 menuBar.noteRestoreAction.setEnabled(false);
2122 menuBar.noteRestoreAction.setVisible(false);
2125 currentNoteGuid = trashNoteGuid;
2126 trashNoteGuid = tempGuid;
2127 menuBar.noteRestoreAction.setEnabled(true);
2128 menuBar.noteRestoreAction.setVisible(true);
2129 Global.showDeleted = true;
2131 listManager.loadNotesIndex();
2132 noteIndexUpdated(false);
2133 //// browserWindow.setEnabled(newButton.isEnabled());
2134 browserWindow.setReadOnly(!newButton.isEnabled());
2135 logger.log(logger.HIGH, "Leaving NeverNote.trashTreeSelection");
2137 // Empty the trash file
2138 @SuppressWarnings("unused")
2139 private void emptyTrash() {
2140 // browserWindow.clear();
2141 listManager.emptyTrash();
2142 if (trashTree.selectedItems().size() > 0) {
2143 listManager.getSelectedNotebooks().clear();
2144 listManager.getSelectedTags().clear();
2145 listManager.setSelectedSavedSearch("");
2146 newButton.setEnabled(!newButton.isEnabled());
2147 menuBar.noteAdd.setEnabled(newButton.isEnabled());
2148 menuBar.noteAdd.setVisible(true);
2149 browserWindow.clear();
2152 clearNotebookFilter();
2153 clearSavedSearchFilter();
2154 clearAttributeFilter();
2156 Global.showDeleted = false;
2157 menuBar.noteRestoreAction.setEnabled(false);
2158 menuBar.noteRestoreAction.setVisible(false);
2160 listManager.loadNotesIndex();
2161 //--->>> noteIndexUpdated(true);
2162 noteIndexUpdated(false);
2165 // Show/Hide trash window
2166 private void toggleTrashWindow() {
2167 logger.log(logger.HIGH, "Entering NeverNote.toggleTrashWindow");
2168 if (trashTree.isVisible())
2172 menuBar.hideTrash.setChecked(trashTree.isVisible());
2174 Global.saveWindowVisible("trashTree", trashTree.isVisible());
2175 logger.log(logger.HIGH, "Leaving NeverNote.trashWindow");
2177 private void clearTrashFilter() {
2178 Global.showDeleted = false;
2179 newButton.setEnabled(true);
2180 menuBar.noteAdd.setEnabled(true);
2181 menuBar.noteAdd.setVisible(true);
2182 trashTree.blockSignals(true);
2183 trashTree.clearSelection();
2184 trashTree.blockSignals(false);
2189 //***************************************************************
2190 //***************************************************************
2191 //** These functions deal with connection settings
2192 //***************************************************************
2193 //***************************************************************
2194 // SyncRunner had a problem and things are disconnected
2195 @SuppressWarnings("unused")
2196 private void remoteErrorDisconnect() {
2197 menuBar.connectAction.setText("Connect");
2198 menuBar.connectAction.setToolTip("Connect to Evernote");
2199 menuBar.synchronizeAction.setEnabled(false);
2200 synchronizeAnimationTimer.stop();
2203 // Do a manual connect/disconnect
2204 private void remoteConnect() {
2205 logger.log(logger.HIGH, "Entering NeverNote.remoteConnect");
2207 if (Global.isConnected) {
2208 Global.isConnected = false;
2209 syncRunner.enDisconnect();
2210 setupConnectMenuOptions();
2215 AESEncrypter aes = new AESEncrypter();
2217 aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("secure.txt")));
2218 } catch (FileNotFoundException e) {
2219 // File not found, so we'll just get empty strings anyway.
2221 String userid = aes.getUserid();
2222 String password = aes.getPassword();
2223 if (!userid.equals("") && !password.equals("")) {
2224 Global.username = userid;
2225 Global.password = password;
2228 // Show the login dialog box
2229 if (!Global.automaticLogin() || userid.equals("")|| password.equals("")) {
2230 LoginDialog login = new LoginDialog();
2233 if (!login.okPressed()) {
2237 Global.username = login.getUserid();
2238 Global.password = login.getPassword();
2240 syncRunner.username = Global.username;
2241 syncRunner.password = Global.password;
2242 syncRunner.userStoreUrl = Global.userStoreUrl;
2243 syncRunner.noteStoreUrl = Global.noteStoreUrl;
2244 syncRunner.noteStoreUrlBase = Global.noteStoreUrlBase;
2245 syncRunner.enConnect();
2246 Global.isConnected = syncRunner.isConnected;
2248 setupConnectMenuOptions();
2249 logger.log(logger.HIGH, "Leaving NeverNote.remoteConnect");
2251 private void setupConnectMenuOptions() {
2252 logger.log(logger.HIGH, "entering NeverNote.setupConnectMenuOptions");
2253 if (!Global.isConnected) {
2254 menuBar.connectAction.setText("Connect");
2255 menuBar.connectAction.setToolTip("Connect to Evernote");
2256 menuBar.synchronizeAction.setEnabled(false);
2258 menuBar.connectAction.setText("Disconnect");
2259 menuBar.connectAction.setToolTip("Disconnect from Evernote");
2260 menuBar.synchronizeAction.setEnabled(true);
2262 logger.log(logger.HIGH, "Leaving NeverNote.setupConnectionMenuOptions");
2267 //***************************************************************
2268 //***************************************************************
2269 //** These functions deal with the GUI Attribute tree
2270 //***************************************************************
2271 //***************************************************************
2272 @SuppressWarnings("unused")
2273 private void attributeTreeClicked(QTreeWidgetItem item, Integer integer) {
2276 clearNotebookFilter();
2278 clearSavedSearchFilter();
2280 if (attributeTreeSelected == null || item.nativeId() != attributeTreeSelected.nativeId()) {
2281 if (item.childCount() > 0) {
2282 item.setSelected(false);
2284 Global.createdBeforeFilter.reset();
2285 Global.createdSinceFilter.reset();
2286 Global.changedBeforeFilter.reset();
2287 Global.changedSinceFilter.reset();
2288 Global.containsFilter.reset();
2289 attributeTreeSelected = item;
2290 DateAttributeFilterTable f = null;
2291 f = findDateAttributeFilterTable(item.parent());
2293 f.select(item.text(0));
2295 String text = item.text(0);
2296 Global.containsFilter.select(text);
2299 listManager.loadNotesIndex();
2300 noteIndexUpdated(false);
2303 attributeTreeSelected = null;
2304 item.setSelected(false);
2305 Global.createdBeforeFilter.reset();
2306 Global.createdSinceFilter.reset();
2307 Global.changedBeforeFilter.reset();
2308 Global.changedSinceFilter.reset();
2309 Global.containsFilter.reset();
2310 listManager.loadNotesIndex();
2311 noteIndexUpdated(false);
2313 // This determines what attribute filter we need, depending upon the selection
2314 private DateAttributeFilterTable findDateAttributeFilterTable(QTreeWidgetItem w) {
2315 if (w.parent() != null && w.childCount() > 0) {
2316 QTreeWidgetItem parent = w.parent();
2317 if (parent.text(0).equalsIgnoreCase("created") &&
2318 w.text(0).equalsIgnoreCase("since"))
2319 return Global.createdSinceFilter;
2320 if (parent.text(0).equalsIgnoreCase("created") &&
2321 w.text(0).equalsIgnoreCase("before"))
2322 return Global.createdBeforeFilter;
2323 if (parent.text(0).equalsIgnoreCase("last modified") &&
2324 w.text(0).equalsIgnoreCase("since"))
2325 return Global.changedSinceFilter;
2326 if (parent.text(0).equalsIgnoreCase("last modified") &&
2327 w.text(0).equalsIgnoreCase("before"))
2328 return Global.changedBeforeFilter;
2332 // Show/Hide attribute search window
2333 private void toggleAttributesWindow() {
2334 logger.log(logger.HIGH, "Entering NeverNote.toggleAttributesWindow");
2335 if (attributeTree.isVisible())
2336 attributeTree.hide();
2338 attributeTree.show();
2339 menuBar.hideAttributes.setChecked(attributeTree.isVisible());
2341 Global.saveWindowVisible("attributeTree", attributeTree.isVisible());
2342 logger.log(logger.HIGH, "Leaving NeverNote.toggleAttributeWindow");
2344 private void clearAttributeFilter() {
2345 Global.createdBeforeFilter.reset();
2346 Global.createdSinceFilter.reset();
2347 Global.changedBeforeFilter.reset();
2348 Global.changedSinceFilter.reset();
2349 Global.containsFilter.reset();
2350 attributeTreeSelected = null;
2351 attributeTree.blockSignals(true);
2352 attributeTree.clearSelection();
2353 attributeTree.blockSignals(false);
2357 //***************************************************************
2358 //***************************************************************
2359 //** These functions deal with the GUI Note index table
2360 //***************************************************************
2361 //***************************************************************
2362 // Initialize the note list table
2363 private void initializeNoteTable() {
2364 logger.log(logger.HIGH, "Entering NeverNote.initializeNoteTable");
2365 noteTableView.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection);
2366 noteTableView.selectionModel().selectionChanged.connect(this, "noteTableSelection()");
2367 logger.log(logger.HIGH, "Leaving NeverNote.initializeNoteTable");
2369 // Show/Hide trash window
2370 @SuppressWarnings("unused")
2371 private void toggleNoteListWindow() {
2372 logger.log(logger.HIGH, "Entering NeverNote.toggleNoteListWindow");
2373 if (noteTableView.isVisible())
2374 noteTableView.hide();
2376 noteTableView.show();
2377 menuBar.hideNoteList.setChecked(noteTableView.isVisible());
2379 Global.saveWindowVisible("noteList", noteTableView.isVisible());
2380 logger.log(logger.HIGH, "Leaving NeverNote.toggleNoteListWindow");
2382 // Handle the event that a user selects a note from the table
2383 @SuppressWarnings("unused")
2384 private void noteTableSelection() {
2385 logger.log(logger.HIGH, "Entering NeverNote.noteTableSelection");
2387 if (historyGuids.size() == 0) {
2388 historyGuids.add(currentNoteGuid);
2389 historyPosition = 1;
2391 noteTableView.showColumn(Global.noteTableGuidPosition);
2393 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
2394 noteTableView.hideColumn(Global.noteTableGuidPosition);
2396 if (selections.size() > 0) {
2398 menuBar.noteDuplicateAction.setEnabled(true);
2399 menuBar.noteOnlineHistoryAction.setEnabled(true);
2400 menuBar.noteMergeAction.setEnabled(true);
2401 selectedNoteGUIDs.clear();
2402 if (selections.size() != 1 || Global.showDeleted) {
2403 menuBar.noteDuplicateAction.setEnabled(false);
2405 if (selections.size() != 1 || !Global.isConnected) {
2406 menuBar.noteOnlineHistoryAction.setEnabled(false);
2408 if (selections.size() == 1) {
2409 menuBar.noteMergeAction.setEnabled(false);
2411 for (int i=0; i<selections.size(); i++) {
2412 int row = selections.get(i).row();
2414 upButton.setEnabled(false);
2416 upButton.setEnabled(true);
2417 if (row < noteTableView.model.rowCount()-1)
2418 downButton.setEnabled(true);
2420 downButton.setEnabled(false);
2421 index = noteTableView.proxyModel.index(row, Global.noteTableGuidPosition);
2422 SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(index);
2423 currentNoteGuid = (String)ix.values().toArray()[0];
2424 selectedNoteGUIDs.add(currentNoteGuid);
2428 nextButton.setEnabled(true);
2429 prevButton.setEnabled(true);
2431 int endPosition = historyGuids.size()-1;
2432 for (int j=historyPosition; j<=endPosition; j++) {
2433 historyGuids.remove(historyGuids.size()-1);
2435 historyGuids.add(currentNoteGuid);
2436 historyPosition = historyGuids.size();
2438 if (historyPosition <= 1)
2439 prevButton.setEnabled(false);
2440 if (historyPosition == historyGuids.size())
2441 nextButton.setEnabled(false);
2443 fromHistory = false;
2444 scrollToGuid(currentNoteGuid);
2445 refreshEvernoteNote(true);
2446 logger.log(logger.HIGH, "Leaving NeverNote.noteTableSelection");
2448 // Trigger a refresh when the note db has been updated
2449 private void noteIndexUpdated(boolean reload) {
2450 logger.log(logger.HIGH, "Entering NeverNote.noteIndexUpdated");
2451 Global.traceReset();
2453 refreshEvernoteNoteList();
2454 logger.log(logger.HIGH, "Calling note table reload in NeverNote.noteIndexUpdated() - "+reload);
2455 noteTableView.load(listManager, reload);
2456 scrollToGuid(currentNoteGuid);
2457 logger.log(logger.HIGH, "Leaving NeverNote.noteIndexUpdated");
2459 // Called when the list of notes is updated
2460 private void refreshEvernoteNoteList() {
2461 logger.log(logger.HIGH, "Entering NeverNote.refreshEvernoteNoteList");
2462 browserWindow.setDisabled(false);
2463 if (selectedNoteGUIDs == null)
2464 selectedNoteGUIDs = new ArrayList<String>();
2465 selectedNoteGUIDs.clear(); // clear out old entries
2467 String saveCurrentNoteGuid = new String();
2468 String tempNoteGuid = new String();
2470 historyGuids.clear();
2471 historyPosition = 0;
2472 prevButton.setEnabled(false);
2473 nextButton.setEnabled(false);
2475 if (currentNoteGuid == null)
2476 currentNoteGuid = new String();
2478 for (Note note : listManager.getNoteIndex()) {
2479 tempNoteGuid = note.getGuid();
2480 if (currentNoteGuid.equals(tempNoteGuid)) {
2481 saveCurrentNoteGuid = new String(tempNoteGuid);
2485 if (listManager.getNoteIndex().size() == 0) {
2486 currentNoteGuid = "";
2488 browserWindow.clear();
2489 browserWindow.setDisabled(true);
2492 if (saveCurrentNoteGuid.equals("") && listManager.getNoteIndex().size() >0) {
2493 currentNoteGuid = listManager.getNoteIndex().get(listManager.getNoteIndex().size()-1).getGuid();
2494 currentNote = listManager.getNoteIndex().get(listManager.getNoteIndex().size()-1);
2495 refreshEvernoteNote(true);
2497 refreshEvernoteNote(false);
2501 logger.log(logger.HIGH, "Leaving NeverNote.refreshEvernoteNoteList");
2503 // Called when the previous arrow button is clicked
2504 @SuppressWarnings("unused")
2505 private void previousViewedAction() {
2506 if (!prevButton.isEnabled())
2508 if (historyPosition == 0)
2511 if (historyPosition <= 0)
2513 String historyGuid = historyGuids.get(historyPosition-1);
2515 for (int i=0; i<noteTableView.model().rowCount(); i++) {
2516 QModelIndex modelIndex = noteTableView.model().index(i, Global.noteTableGuidPosition);
2517 if (modelIndex != null) {
2518 SortedMap<Integer, Object> ix = noteTableView.model().itemData(modelIndex);
2519 String tableGuid = (String)ix.values().toArray()[0];
2520 if (tableGuid.equals(historyGuid)) {
2521 noteTableView.selectRow(i);
2527 @SuppressWarnings("unused")
2528 private void nextViewedAction() {
2529 if (!nextButton.isEnabled())
2531 String historyGuid = historyGuids.get(historyPosition);
2534 for (int i=0; i<noteTableView.model().rowCount(); i++) {
2535 QModelIndex modelIndex = noteTableView.model().index(i, Global.noteTableGuidPosition);
2536 if (modelIndex != null) {
2537 SortedMap<Integer, Object> ix = noteTableView.model().itemData(modelIndex);
2538 String tableGuid = (String)ix.values().toArray()[0];
2539 if (tableGuid.equals(historyGuid)) {
2540 noteTableView.selectRow(i);
2546 // Called when the up arrow is clicked
2547 @SuppressWarnings("unused")
2548 private void upAction() {
2549 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
2550 int row = selections.get(0).row();
2552 noteTableView.selectRow(row-1);
2555 // Called when the down arrow is clicked
2556 @SuppressWarnings("unused")
2557 private void downAction() {
2558 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
2559 int row = selections.get(0).row();
2560 int max = noteTableView.model.rowCount();
2562 noteTableView.selectRow(row+1);
2565 // Update a tag string for a specific note in the list
2566 @SuppressWarnings("unused")
2567 private void updateListTags(String guid, List<String> tags) {
2568 logger.log(logger.HIGH, "Entering NeverNote.updateListTags");
2569 StringBuffer tagBuffer = new StringBuffer();
2570 for (int i=0; i<tags.size(); i++) {
2571 tagBuffer.append(tags.get(i));
2572 if (i<tags.size()-1)
2573 tagBuffer.append(", ");
2576 for (int i=0; i<noteTableView.model.rowCount(); i++) {
2577 QModelIndex modelIndex = noteTableView.model.index(i, Global.noteTableGuidPosition);
2578 if (modelIndex != null) {
2579 SortedMap<Integer, Object> ix = noteTableView.model.itemData(modelIndex);
2580 String tableGuid = (String)ix.values().toArray()[0];
2581 if (tableGuid.equals(guid)) {
2582 noteTableView.model.setData(i, Global.noteTableTagPosition,tagBuffer.toString());
2583 noteTableView.model.setData(i, Global.noteTableSynchronizedPosition, "false");
2588 logger.log(logger.HIGH, "Leaving NeverNote.updateListTags");
2590 // Update a title for a specific note in the list
2591 @SuppressWarnings("unused")
2592 private void updateListTitle(String guid, String title) {
2593 logger.log(logger.HIGH, "Entering NeverNote.updateListTitle");
2595 for (int i=0; i<noteTableView.model.rowCount(); i++) {
2596 //QModelIndex modelIndex = noteTableView.proxyModel.index(i, Global.noteTableGuidPosition);
2597 QModelIndex modelIndex = noteTableView.model.index(i, Global.noteTableGuidPosition);
2598 if (modelIndex != null) {
2599 // SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(modelIndex);
2600 SortedMap<Integer, Object> ix = noteTableView.model.itemData(modelIndex);
2601 String tableGuid = (String)ix.values().toArray()[0];
2602 if (tableGuid.equals(guid)) {
2603 noteTableView.model.setData(i, Global.noteTableTitlePosition,title);
2604 noteTableView.model.setData(i, Global.noteTableSynchronizedPosition, "false");
2609 logger.log(logger.HIGH, "Leaving NeverNote.updateListTitle");
2611 // Update a title for a specific note in the list
2612 @SuppressWarnings("unused")
2613 private void updateListAuthor(String guid, String author) {
2614 logger.log(logger.HIGH, "Entering NeverNote.updateListAuthor");
2616 for (int i=0; i<noteTableView.model.rowCount(); i++) {
2617 //QModelIndex modelIndex = noteTableView.proxyModel.index(i, Global.noteTableGuidPosition);
2618 QModelIndex modelIndex = noteTableView.model.index(i, Global.noteTableGuidPosition);
2619 if (modelIndex != null) {
2620 // SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(modelIndex);
2621 SortedMap<Integer, Object> ix = noteTableView.model.itemData(modelIndex);
2622 String tableGuid = (String)ix.values().toArray()[0];
2623 if (tableGuid.equals(guid)) {
2624 noteTableView.model.setData(i, Global.noteTableAuthorPosition,author);
2625 noteTableView.model.setData(i, Global.noteTableSynchronizedPosition, "false");
2630 logger.log(logger.HIGH, "Leaving NeverNote.updateListAuthor");
2632 private void updateListNoteNotebook(String guid, String notebook) {
2633 logger.log(logger.HIGH, "Entering NeverNote.updateListNoteNotebook");
2635 for (int i=0; i<noteTableView.model.rowCount(); i++) {
2636 //QModelIndex modelIndex = noteTableView.proxyModel.index(i, Global.noteTableGuidPosition);
2637 QModelIndex modelIndex = noteTableView.model.index(i, Global.noteTableGuidPosition);
2638 if (modelIndex != null) {
2639 // SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(modelIndex);
2640 SortedMap<Integer, Object> ix = noteTableView.model.itemData(modelIndex);
2641 String tableGuid = (String)ix.values().toArray()[0];
2642 if (tableGuid.equals(guid)) {
2643 noteTableView.model.setData(i, Global.noteTableNotebookPosition,notebook);
2644 noteTableView.model.setData(i, Global.noteTableSynchronizedPosition, "false");
2649 logger.log(logger.HIGH, "Leaving NeverNote.updateListNoteNotebook");
2651 // Update a title for a specific note in the list
2652 @SuppressWarnings("unused")
2653 private void updateListSourceUrl(String guid, String url) {
2654 logger.log(logger.HIGH, "Entering NeverNote.updateListAuthor");
2656 for (int i=0; i<noteTableView.model.rowCount(); i++) {
2657 //QModelIndex modelIndex = noteTableView.proxyModel.index(i, Global.noteTableGuidPosition);
2658 QModelIndex modelIndex = noteTableView.model.index(i, Global.noteTableGuidPosition);
2659 if (modelIndex != null) {
2660 // SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(modelIndex);
2661 SortedMap<Integer, Object> ix = noteTableView.model.itemData(modelIndex);
2662 String tableGuid = (String)ix.values().toArray()[0];
2663 if (tableGuid.equals(guid)) {
2664 noteTableView.model.setData(i, Global.noteTableSynchronizedPosition, "false");
2665 noteTableView.model.setData(i, Global.noteTableSourceUrlPosition,url);
2670 logger.log(logger.HIGH, "Leaving NeverNote.updateListAuthor");
2672 private void updateListGuid(String oldGuid, String newGuid) {
2673 logger.log(logger.HIGH, "Entering NeverNote.updateListTitle");
2675 for (int i=0; i<noteTableView.model.rowCount(); i++) {
2676 QModelIndex modelIndex = noteTableView.model.index(i, Global.noteTableGuidPosition);
2677 if (modelIndex != null) {
2678 SortedMap<Integer, Object> ix = noteTableView.model.itemData(modelIndex);
2679 String tableGuid = (String)ix.values().toArray()[0];
2680 if (tableGuid.equals(oldGuid)) {
2681 noteTableView.model.setData(i, Global.noteTableGuidPosition,newGuid);
2682 //noteTableView.model.setData(i, Global.noteTableSynchronizedPosition, "false");
2687 logger.log(logger.HIGH, "Leaving NeverNote.updateListTitle");
2689 private void updateListTagName(String guid) {
2690 logger.log(logger.HIGH, "Entering NeverNote.updateTagName");
2692 for (int j=0; j<listManager.getNoteIndex().size(); j++) {
2693 if (listManager.getNoteIndex().get(j).getTagGuids().contains(guid)) {
2694 String newName = listManager.getTagNamesForNote(listManager.getNoteIndex().get(j));
2696 for (int i=0; i<noteTableView.model.rowCount(); i++) {
2697 QModelIndex modelIndex = noteTableView.model.index(i, Global.noteTableGuidPosition);
2698 if (modelIndex != null) {
2699 SortedMap<Integer, Object> ix = noteTableView.model.itemData(modelIndex);
2700 String noteGuid = (String)ix.values().toArray()[0];
2701 if (noteGuid.equalsIgnoreCase(listManager.getNoteIndex().get(j).getGuid())) {
2702 noteTableView.model.setData(i, Global.noteTableTagPosition, newName);
2703 //noteTableView.model.setData(i, Global.noteTableSynchronizedPosition, "false");
2704 i=noteTableView.model.rowCount();
2710 logger.log(logger.HIGH, "Leaving NeverNote.updateListNotebook");
2712 private void removeListTagName(String guid) {
2713 logger.log(logger.HIGH, "Entering NeverNote.updateTagName");
2715 for (int j=0; j<listManager.getNoteIndex().size(); j++) {
2716 if (listManager.getNoteIndex().get(j).getTagGuids().contains(guid)) {
2717 for (int i=listManager.getNoteIndex().get(j).getTagGuids().size()-1; i>=0; i--) {
2718 if (listManager.getNoteIndex().get(j).getTagGuids().get(i).equals(guid))
2719 listManager.getNoteIndex().get(j).getTagGuids().remove(i);
2722 String newName = listManager.getTagNamesForNote(listManager.getNoteIndex().get(j));
2723 for (int i=0; i<noteTableView.model.rowCount(); i++) {
2724 QModelIndex modelIndex = noteTableView.model.index(i, Global.noteTableGuidPosition);
2725 if (modelIndex != null) {
2726 SortedMap<Integer, Object> ix = noteTableView.model.itemData(modelIndex);
2727 String noteGuid = (String)ix.values().toArray()[0];
2728 if (noteGuid.equalsIgnoreCase(listManager.getNoteIndex().get(j).getGuid())) {
2729 noteTableView.model.setData(i, Global.noteTableTagPosition, newName);
2730 // noteTableView.model.setData(i, Global.noteTableSynchronizedPosition, "false");
2731 i=noteTableView.model.rowCount();
2737 logger.log(logger.HIGH, "Leaving NeverNote.updateListNotebook");
2739 private void updateListNotebookName(String oldName, String newName) {
2740 logger.log(logger.HIGH, "Entering NeverNote.updateListNotebookName");
2742 for (int i=0; i<noteTableView.model.rowCount(); i++) {
2743 QModelIndex modelIndex = noteTableView.model.index(i, Global.noteTableNotebookPosition);
2744 if (modelIndex != null) {
2745 SortedMap<Integer, Object> ix = noteTableView.model.itemData(modelIndex);
2746 String tableName = (String)ix.values().toArray()[0];
2747 if (tableName.equalsIgnoreCase(oldName)) {
2748 // noteTableView.model.setData(i, Global.noteTableSynchronizedPosition, "false");
2749 noteTableView.model.setData(i, Global.noteTableNotebookPosition, newName);