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.ItemDataRole;
78 import com.trolltech.qt.core.Qt.SortOrder;
79 import com.trolltech.qt.core.Qt.WidgetAttribute;
80 import com.trolltech.qt.gui.QAbstractItemView;
81 import com.trolltech.qt.gui.QAbstractItemView.ScrollHint;
82 import com.trolltech.qt.gui.QAction;
83 import com.trolltech.qt.gui.QApplication;
84 import com.trolltech.qt.gui.QCloseEvent;
85 import com.trolltech.qt.gui.QColor;
86 import com.trolltech.qt.gui.QComboBox;
87 import com.trolltech.qt.gui.QComboBox.InsertPolicy;
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 public 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, "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, "Building list manager");
341 listManager = new ListManager(conn, logger);
343 logger.log(logger.EXTREME, "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, "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, "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, "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;
395 listManager.saveRunner.noteSignals.noteSaveRunnerError.connect(this, "saveRunnerError(String, String)");
397 logger.log(logger.EXTREME, "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, listManager);
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(tr("Beginning shutdown."));
694 externalFileEditedSaver();
695 if (Global.isConnected && Global.synchronizeOnClose()) {
696 setMessage(tr("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 Global.saveWindowVisible("toolBar", toolBar.isVisible());
743 saveNoteIndexWidth();
745 int width = notebookTree.columnWidth(0);
746 Global.setColumnWidth("notebookTreeName", width);
747 width = tagTree.columnWidth(0);
748 Global.setColumnWidth("tagTreeName", width);
750 Global.saveWindowMaximized(isMaximized());
751 Global.saveCurrentNoteGuid(currentNoteGuid);
753 int sortCol = noteTableView.proxyModel.sortColumn();
754 int sortOrder = noteTableView.proxyModel.sortOrder().value();
755 Global.setSortColumn(sortCol);
756 Global.setSortOrder(sortOrder);
760 Global.keepRunning = false;
762 logger.log(logger.MEDIUM, "Waiting for indexThread to stop");
763 indexRunner.thread().join(50);
764 logger.log(logger.MEDIUM, "Index thread has stopped");
765 } catch (InterruptedException e1) {
766 e1.printStackTrace();
768 if (!syncRunner.isIdle()) {
770 logger.log(logger.MEDIUM, "Waiting for syncThread to stop");
772 logger.log(logger.MEDIUM, "Sync thread has stopped");
773 } catch (InterruptedException e1) {
774 e1.printStackTrace();
778 logger.log(logger.HIGH, "Leaving NeverNote.closeEvent");
781 public void setMessage(String s) {
782 logger.log(logger.HIGH, "Entering NeverNote.setMessage");
783 logger.log(logger.HIGH, "Message: " +s);
784 statusBar.showMessage(s);
786 logger.log(logger.HIGH, "Leaving NeverNote.setMessage");
789 private void waitCursor(boolean wait) {
791 // QApplication.setOverrideCursor(new QCursor(Qt.CursorShape.WaitCursor));
793 // QApplication.restoreOverrideCursor();
796 private void setupIndexListeners() {
797 indexRunner.noteSignal.noteIndexed.connect(this, "indexThreadComplete(String)");
798 indexRunner.resourceSignal.resourceIndexed.connect(this, "indexThreadComplete(String)");
799 // indexRunner.threadSignal.indexNeeded.connect(listManager, "setIndexNeeded(String, String, Boolean)");
801 private void setupSyncSignalListeners() {
802 syncRunner.tagSignal.listChanged.connect(this, "tagIndexUpdated()");
803 syncRunner.searchSignal.listChanged.connect(this, "savedSearchIndexUpdated()");
804 syncRunner.notebookSignal.listChanged.connect(this, "notebookIndexUpdated()");
805 syncRunner.noteIndexSignal.listChanged.connect(this, "noteIndexUpdated(boolean)");
806 syncRunner.noteSignal.quotaChanged.connect(this, "updateQuotaBar()");
808 syncRunner.syncSignal.saveUploadAmount.connect(this,"saveUploadAmount(long)");
809 syncRunner.syncSignal.saveUserInformation.connect(this,"saveUserInformation(User)");
810 syncRunner.syncSignal.saveEvernoteUpdateCount.connect(this,"saveEvernoteUpdateCount(int)");
812 syncRunner.noteSignal.guidChanged.connect(this, "noteGuidChanged(String, String)");
813 syncRunner.noteSignal.noteChanged.connect(this, "invalidateNoteCache(String, String)");
814 syncRunner.resourceSignal.resourceGuidChanged.connect(this, "noteResourceGuidChanged(String,String,String)");
815 syncRunner.noteSignal.noteDownloaded.connect(listManager, "noteDownloaded(Note)");
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.notebookChanged.connect(this, "updateNoteNotebook(String, String)");
829 browserWindow.noteSignal.createdDateChanged.connect(listManager, "updateNoteCreatedDate(String, QDateTime)");
830 browserWindow.noteSignal.alteredDateChanged.connect(listManager, "updateNoteAlteredDate(String, QDateTime)");
831 browserWindow.noteSignal.subjectDateChanged.connect(listManager, "updateNoteSubjectDate(String, QDateTime)");
832 browserWindow.noteSignal.authorChanged.connect(listManager, "updateNoteAuthor(String, String)");
833 browserWindow.noteSignal.geoChanged.connect(listManager, "updateNoteGeoTag(String, Double,Double,Double)");
834 browserWindow.noteSignal.geoChanged.connect(this, "setNoteDirty()");
835 browserWindow.noteSignal.sourceUrlChanged.connect(listManager, "updateNoteSourceUrl(String, String)");
836 browserWindow.focusLost.connect(this, "saveNote()");
837 browserWindow.resourceSignal.contentChanged.connect(this, "externalFileEdited(String)");
842 //***************************************************************
843 //***************************************************************
844 //* Settings and look & feel
845 //***************************************************************
846 //***************************************************************
847 @SuppressWarnings("unused")
848 private void settings() {
849 logger.log(logger.HIGH, "Entering NeverNote.settings");
850 ConfigDialog settings = new ConfigDialog(this);
851 String dateFormat = Global.getDateFormat();
852 String timeFormat = Global.getTimeFormat();
855 if (Global.showTrayIcon())
860 if (menuBar.showEditorBar.isChecked())
863 // Reset the save timer
864 if (Global.getAutoSaveInterval() > 0)
865 saveTimer.setInterval(1000*60*Global.getAutoSaveInterval());
869 // This is a hack to force a reload of the index in case the date or time changed.
870 // if (!dateFormat.equals(Global.getDateFormat()) ||
871 // !timeFormat.equals(Global.getTimeFormat())) {
873 noteIndexUpdated(true);
876 logger.log(logger.HIGH, "Leaving NeverNote.settings");
878 // Restore things to the way they were
879 private void restoreWindowState() {
880 // We need to name things or this doesn't work.
881 setObjectName("NeverNote");
882 mainLeftRightSplitter.setObjectName("mainLeftRightSplitter");
883 browserIndexSplitter.setObjectName("browserIndexSplitter");
884 leftSplitter1.setObjectName("leftSplitter1");
886 // Restore the actual positions.
887 restoreGeometry(Global.restoreGeometry(objectName()));
888 mainLeftRightSplitter.restoreState(Global.restoreState(mainLeftRightSplitter.objectName()));
889 browserIndexSplitter.restoreState(Global.restoreState(browserIndexSplitter.objectName()));
890 leftSplitter1.restoreState(Global.restoreState(leftSplitter1.objectName()));
893 // Save window positions for the next start
894 private void saveWindowState() {
895 Global.saveGeometry(objectName(), saveGeometry());
896 Global.saveState(mainLeftRightSplitter.objectName(), mainLeftRightSplitter.saveState());
897 Global.saveState(browserIndexSplitter.objectName(), browserIndexSplitter.saveState());
898 Global.saveState(leftSplitter1.objectName(), leftSplitter1.saveState());
900 // Load the style sheet
901 private void loadStyleSheet() {
902 String fileName = Global.getFileManager().getQssDirPath("default.qss");
903 QFile file = new QFile(fileName);
904 file.open(OpenModeFlag.ReadOnly);
905 String styleSheet = file.readAll().toString();
907 setStyleSheet(styleSheet);
909 // Save column widths for the next time
910 private void saveNoteIndexWidth() {
912 width = noteTableView.getColumnWidth(Global.noteTableCreationPosition);
913 Global.setColumnWidth("noteTableCreationPosition", width);
914 width = noteTableView.getColumnWidth(Global.noteTableChangedPosition);
915 Global.setColumnWidth("noteTableChangedPosition", width);
916 width = noteTableView.getColumnWidth(Global.noteTableGuidPosition);
917 Global.setColumnWidth("noteTableGuidPosition", width);
918 width = noteTableView.getColumnWidth(Global.noteTableNotebookPosition);
919 Global.setColumnWidth("noteTableNotebookPosition", width);
920 width = noteTableView.getColumnWidth(Global.noteTableTagPosition);
921 Global.setColumnWidth("noteTableTagPosition", width);
922 width = noteTableView.getColumnWidth(Global.noteTableTitlePosition);
923 Global.setColumnWidth("noteTableTitlePosition", width);
924 width = noteTableView.getColumnWidth(Global.noteTableSourceUrlPosition);
925 Global.setColumnWidth("noteTableSourceUrlPosition", width);
926 width = noteTableView.getColumnWidth(Global.noteTableAuthorPosition);
927 Global.setColumnWidth("noteTableAuthorPosition", width);
928 width = noteTableView.getColumnWidth(Global.noteTableSubjectDatePosition);
929 Global.setColumnWidth("noteTableSubjectDatePosition", width);
930 width = noteTableView.getColumnWidth(Global.noteTableSynchronizedPosition);
931 Global.setColumnWidth("noteTableSynchronizedPosition", width);
935 //***************************************************************
936 //***************************************************************
937 //** These functions deal with Notebook menu items
938 //***************************************************************
939 //***************************************************************
940 // Setup the tree containing the user's notebooks.
941 private void initializeNotebookTree() {
942 logger.log(logger.HIGH, "Entering NeverNote.initializeNotebookTree");
943 notebookTree.itemSelectionChanged.connect(this, "notebookTreeSelection()");
944 listManager.notebookSignal.refreshNotebookTreeCounts.connect(notebookTree, "updateCounts(List, List)");
945 // notebookTree.resize(Global.getSize("notebookTree"));
946 logger.log(logger.HIGH, "Leaving NeverNote.initializeNotebookTree");
948 // Listener when a notebook is selected
949 private void notebookTreeSelection() {
950 logger.log(logger.HIGH, "Entering NeverNote.notebookTreeSelection");
953 clearAttributeFilter();
954 clearSavedSearchFilter();
955 if (Global.mimicEvernoteInterface) {
959 menuBar.noteRestoreAction.setVisible(false);
960 menuBar.notebookEditAction.setEnabled(true);
961 menuBar.notebookDeleteAction.setEnabled(true);
962 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
963 QTreeWidgetItem currentSelection;
964 selectedNotebookGUIDs.clear();
965 if (!Global.mimicEvernoteInterface) {
966 for (int i=0; i<selections.size(); i++) {
967 currentSelection = selections.get(i);
968 selectedNotebookGUIDs.add(currentSelection.text(2));
972 // There is the potential for no notebooks to be selected if this
973 // happens then we make it look like all notebooks were selecetd.
974 // If that happens, just select the "all notebooks"
975 selections = notebookTree.selectedItems();
976 if (selections.size()==0) {
977 selectedNotebookGUIDs.clear();
978 menuBar.notebookEditAction.setEnabled(false);
979 menuBar.notebookDeleteAction.setEnabled(false);
983 if (selections.size() > 0)
984 guid = (selections.get(0).text(2));
985 if (!guid.equals(""))
986 selectedNotebookGUIDs.add(guid);
988 listManager.setSelectedNotebooks(selectedNotebookGUIDs);
989 listManager.loadNotesIndex();
990 noteIndexUpdated(false);
991 logger.log(logger.HIGH, "Leaving NeverNote.notebookTreeSelection");
994 private void clearNotebookFilter() {
995 notebookTree.blockSignals(true);
996 notebookTree.clearSelection();
997 menuBar.noteRestoreAction.setVisible(false);
998 menuBar.notebookEditAction.setEnabled(false);
999 menuBar.notebookDeleteAction.setEnabled(false);
1000 selectedNotebookGUIDs.clear();
1001 listManager.setSelectedNotebooks(selectedNotebookGUIDs);
1002 notebookTree.blockSignals(false);
1004 // Triggered when the notebook DB has been updated
1005 private void notebookIndexUpdated() {
1006 logger.log(logger.HIGH, "Entering NeverNote.notebookIndexUpdated");
1007 if (selectedNotebookGUIDs == null)
1008 selectedNotebookGUIDs = new ArrayList<String>();
1009 List<Notebook> books = conn.getNotebookTable().getAll();
1010 for (int i=books.size()-1; i>=0; i--) {
1011 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1012 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(books.get(i).getGuid())) {
1014 j=listManager.getArchiveNotebookIndex().size();
1020 listManager.countNotebookResults(listManager.getNoteIndex());
1021 notebookTree.blockSignals(true);
1022 notebookTree.load(books, listManager.getLocalNotebooks());
1023 for (int i=selectedNotebookGUIDs.size()-1; i>=0; i--) {
1024 boolean found = notebookTree.selectGuid(selectedNotebookGUIDs.get(i));
1026 selectedNotebookGUIDs.remove(i);
1028 notebookTree.blockSignals(false);
1030 logger.log(logger.HIGH, "Leaving NeverNote.notebookIndexUpdated");
1032 // Show/Hide note information
1033 private void toggleNotebookWindow() {
1034 logger.log(logger.HIGH, "Entering NeverNote.toggleNotebookWindow");
1035 if (notebookTree.isVisible())
1036 notebookTree.hide();
1038 notebookTree.show();
1039 menuBar.hideNotebooks.setChecked(notebookTree.isVisible());
1040 Global.saveWindowVisible("notebookTree", notebookTree.isVisible());
1041 logger.log(logger.HIGH, "Leaving NeverNote.toggleNotebookWindow");
1043 // Add a new notebook
1044 @SuppressWarnings("unused")
1045 private void addNotebook() {
1046 logger.log(logger.HIGH, "Inside NeverNote.addNotebook");
1047 NotebookEdit edit = new NotebookEdit();
1048 edit.setNotebooks(listManager.getNotebookIndex());
1051 if (!edit.okPressed())
1054 Calendar currentTime = new GregorianCalendar();
1055 Long l = new Long(currentTime.getTimeInMillis());
1056 String randint = new String(Long.toString(l));
1058 Notebook newBook = new Notebook();
1059 newBook.setUpdateSequenceNum(0);
1060 newBook.setGuid(randint);
1061 newBook.setName(edit.getNotebook());
1062 newBook.setServiceCreated(new Date().getTime());
1063 newBook.setServiceUpdated(new Date().getTime());
1064 newBook.setDefaultNotebook(false);
1065 newBook.setPublished(false);
1067 listManager.getNotebookIndex().add(newBook);
1069 listManager.getLocalNotebooks().add(newBook.getGuid());
1070 conn.getNotebookTable().addNotebook(newBook, true, edit.isLocal());
1071 notebookIndexUpdated();
1072 listManager.countNotebookResults(listManager.getNoteIndex());
1073 // notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
1074 logger.log(logger.HIGH, "Leaving NeverNote.addNotebook");
1076 // Edit an existing notebook
1077 @SuppressWarnings("unused")
1078 private void editNotebook() {
1079 logger.log(logger.HIGH, "Entering NeverNote.editNotebook");
1080 NotebookEdit edit = new NotebookEdit();
1081 edit.setTitle(tr("Edit Notebook"));
1082 edit.setLocalCheckboxEnabled(false);
1083 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1084 QTreeWidgetItem currentSelection;
1085 currentSelection = selections.get(0);
1086 edit.setNotebook(currentSelection.text(0));
1087 edit.setNotebooks(listManager.getNotebookIndex());
1090 if (!edit.okPressed())
1093 String guid = currentSelection.text(2);
1094 updateListNotebookName(currentSelection.text(0), edit.getNotebook());
1095 currentSelection.setText(0, edit.getNotebook());
1097 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1098 if (listManager.getNotebookIndex().get(i).getGuid().equals(guid)) {
1099 listManager.getNotebookIndex().get(i).setName(edit.getNotebook());
1100 conn.getNotebookTable().updateNotebook(listManager.getNotebookIndex().get(i), true);
1101 i=listManager.getNotebookIndex().size();
1105 // Build a list of non-closed notebooks
1106 List<Notebook> nbooks = new ArrayList<Notebook>();
1107 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1108 boolean found=false;
1109 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1110 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
1114 nbooks.add(listManager.getNotebookIndex().get(i));
1117 browserWindow.setNotebookList(nbooks);
1118 logger.log(logger.HIGH, "Leaving NeverNote.editNotebook");
1120 // Delete an existing notebook
1121 @SuppressWarnings("unused")
1122 private void deleteNotebook() {
1123 logger.log(logger.HIGH, "Entering NeverNote.deleteNotebook");
1124 boolean assigned = false;
1125 // Check if any notes have this notebook
1126 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1127 for (int i=0; i<selections.size(); i++) {
1128 QTreeWidgetItem currentSelection;
1129 currentSelection = selections.get(i);
1130 String guid = currentSelection.text(2);
1131 for (int j=0; j<listManager.getNoteIndex().size(); j++) {
1132 String noteGuid = listManager.getNoteIndex().get(j).getNotebookGuid();
1133 if (noteGuid.equals(guid)) {
1135 j=listManager.getNoteIndex().size();
1136 i=selections.size();
1141 QMessageBox.information(this, tr("Unable to Delete"), tr("Some of the selected notebook(s) contain notes.\n"+
1142 "Please delete the notes or move them to another notebook before deleting any notebooks."));
1146 if (conn.getNotebookTable().getAll().size() == 1) {
1147 QMessageBox.information(this, tr("Unable to Delete"), tr("You must have at least one notebook."));
1151 // If all notebooks are clear, verify the delete
1152 if (QMessageBox.question(this, tr("Confirmation"), tr("Delete the selected notebooks?"),
1153 QMessageBox.StandardButton.Yes,
1154 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
1158 // If confirmed, delete the notebook
1159 for (int i=selections.size()-1; i>=0; i--) {
1160 QTreeWidgetItem currentSelection;
1161 currentSelection = selections.get(i);
1162 String guid = currentSelection.text(2);
1163 conn.getNotebookTable().expungeNotebook(guid, true);
1164 listManager.deleteNotebook(guid);
1166 // for (int i=<dbRunner.getLocalNotebooks().size()-1; i>=0; i--) {
1167 // if (dbRunner.getLocalNotebooks().get(i).equals(arg0))
1169 notebookTreeSelection();
1170 notebookTree.load(listManager.getNotebookIndex(), listManager.getLocalNotebooks());
1171 listManager.countNotebookResults(listManager.getNoteIndex());
1172 // notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
1173 logger.log(logger.HIGH, "Entering NeverNote.deleteNotebook");
1175 // A note's notebook has been updated
1176 @SuppressWarnings("unused")
1177 private void updateNoteNotebook(String guid, String notebookGuid) {
1179 // Update the list manager
1180 listManager.updateNoteNotebook(guid, notebookGuid);
1181 listManager.countNotebookResults(listManager.getNoteIndex());
1182 // notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
1184 // Find the name of the notebook
1185 String notebookName = null;
1186 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1187 if (listManager.getNotebookIndex().get(i).getGuid().equals(notebookGuid)) {
1188 notebookName = listManager.getNotebookIndex().get(i).getName();
1193 // If we found the name, update the browser window
1194 if (notebookName != null) {
1195 updateListNoteNotebook(guid, notebookName);
1196 if (guid.equals(currentNoteGuid)) {
1197 int pos = browserWindow.notebookBox.findText(notebookName);
1199 browserWindow.notebookBox.setCurrentIndex(pos);
1203 // If we're dealing with the current note, then we need to be sure and update the notebook there
1204 if (guid.equals(currentNoteGuid)) {
1205 if (currentNote != null) {
1206 currentNote.setNotebookGuid(notebookGuid);
1210 // Open/close notebooks
1211 @SuppressWarnings("unused")
1212 private void closeNotebooks() {
1213 NotebookArchive na = new NotebookArchive(listManager.getNotebookIndex(), listManager.getArchiveNotebookIndex());
1215 if (!na.okClicked())
1219 listManager.getArchiveNotebookIndex().clear();
1221 for (int i=na.getClosedBookList().count()-1; i>=0; i--) {
1222 String text = na.getClosedBookList().takeItem(i).text();
1223 for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
1224 if (listManager.getNotebookIndex().get(j).getName().equalsIgnoreCase(text)) {
1225 Notebook n = listManager.getNotebookIndex().get(j);
1226 conn.getNotebookTable().setArchived(n.getGuid(),true);
1227 listManager.getArchiveNotebookIndex().add(n);
1228 j=listManager.getNotebookIndex().size();
1233 for (int i=na.getOpenBookList().count()-1; i>=0; i--) {
1234 String text = na.getOpenBookList().takeItem(i).text();
1235 for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
1236 if (listManager.getNotebookIndex().get(j).getName().equalsIgnoreCase(text)) {
1237 Notebook n = listManager.getNotebookIndex().get(j);
1238 conn.getNotebookTable().setArchived(n.getGuid(),false);
1239 j=listManager.getNotebookIndex().size();
1243 notebookTreeSelection();
1244 listManager.loadNotesIndex();
1245 notebookIndexUpdated();
1246 noteIndexUpdated(false);
1247 // noteIndexUpdated(false);
1249 // Build a list of non-closed notebooks
1250 List<Notebook> nbooks = new ArrayList<Notebook>();
1251 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1252 boolean found=false;
1253 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1254 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
1258 nbooks.add(listManager.getNotebookIndex().get(i));
1261 browserWindow.setNotebookList(nbooks);
1268 //***************************************************************
1269 //***************************************************************
1270 //** These functions deal with Tag menu items
1271 //***************************************************************
1272 //***************************************************************
1273 // Add a new notebook
1274 @SuppressWarnings("unused")
1275 private void addTag() {
1276 logger.log(logger.HIGH, "Inside NeverNote.addTag");
1277 TagEdit edit = new TagEdit();
1278 edit.setTagList(listManager.getTagIndex());
1281 if (!edit.okPressed())
1284 Calendar currentTime = new GregorianCalendar();
1285 Long l = new Long(currentTime.getTimeInMillis());
1286 String randint = new String(Long.toString(l));
1288 Tag newTag = new Tag();
1289 newTag.setUpdateSequenceNum(0);
1290 newTag.setGuid(randint);
1291 newTag.setName(edit.getTag());
1292 conn.getTagTable().addTag(newTag, true);
1293 listManager.getTagIndex().add(newTag);
1296 logger.log(logger.HIGH, "Leaving NeverNote.addTag");
1298 private void reloadTagTree() {
1299 logger.log(logger.HIGH, "Entering NeverNote.reloadTagTree");
1300 tagIndexUpdated(false);
1301 boolean filter = false;
1302 listManager.countTagResults(listManager.getNoteIndex());
1303 if (notebookTree.selectedItems().size() > 0
1304 && !notebookTree.selectedItems().get(0).text(0).equalsIgnoreCase("All Notebooks"))
1306 if (tagTree.selectedItems().size() > 0)
1308 tagTree.showAllTags(!filter);
1309 logger.log(logger.HIGH, "Leaving NeverNote.reloadTagTree");
1311 // Edit an existing tag
1312 @SuppressWarnings("unused")
1313 private void editTag() {
1314 logger.log(logger.HIGH, "Entering NeverNote.editTag");
1315 TagEdit edit = new TagEdit();
1316 edit.setTitle("Edit Tag");
1317 List<QTreeWidgetItem> selections = tagTree.selectedItems();
1318 QTreeWidgetItem currentSelection;
1319 currentSelection = selections.get(0);
1320 edit.setTag(currentSelection.text(0));
1321 edit.setTagList(listManager.getTagIndex());
1324 if (!edit.okPressed())
1327 String guid = currentSelection.text(2);
1328 currentSelection.setText(0,edit.getTag());
1330 for (int i=0; i<listManager.getTagIndex().size(); i++) {
1331 if (listManager.getTagIndex().get(i).getGuid().equals(guid)) {
1332 listManager.getTagIndex().get(i).setName(edit.getTag());
1333 conn.getTagTable().updateTag(listManager.getTagIndex().get(i), true);
1334 updateListTagName(guid);
1335 if (currentNote != null && currentNote.getTagGuids().contains(guid))
1336 browserWindow.setTag(getTagNamesForNote(currentNote));
1337 logger.log(logger.HIGH, "Leaving NeverNote.editTag");
1341 browserWindow.setTag(getTagNamesForNote(currentNote));
1342 logger.log(logger.HIGH, "Leaving NeverNote.editTag...");
1344 // Delete an existing tag
1345 @SuppressWarnings("unused")
1346 private void deleteTag() {
1347 logger.log(logger.HIGH, "Entering NeverNote.deleteTag");
1349 if (QMessageBox.question(this, tr("Confirmation"), tr("Delete the selected tags?"),
1350 QMessageBox.StandardButton.Yes,
1351 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
1355 List<QTreeWidgetItem> selections = tagTree.selectedItems();
1356 for (int i=selections.size()-1; i>=0; i--) {
1357 QTreeWidgetItem currentSelection;
1358 currentSelection = selections.get(i);
1359 removeTagItem(currentSelection.text(2));
1361 tagIndexUpdated(true);
1363 listManager.countTagResults(listManager.getNoteIndex());
1364 // tagTree.updateCounts(listManager.getTagCounter());
1365 logger.log(logger.HIGH, "Leaving NeverNote.deleteTag");
1367 // Remove a tag tree item. Go recursively down & remove the children too
1368 private void removeTagItem(String guid) {
1369 for (int j=listManager.getTagIndex().size()-1; j>=0; j--) {
1370 String parent = listManager.getTagIndex().get(j).getParentGuid();
1371 if (parent != null && parent.equals(guid)) {
1372 //Remove this tag's children
1373 removeTagItem(listManager.getTagIndex().get(j).getGuid());
1376 //Now, remove this tag
1377 removeListTagName(guid);
1378 conn.getTagTable().expungeTag(guid, true);
1379 for (int a=0; a<listManager.getTagIndex().size(); a++) {
1380 if (listManager.getTagIndex().get(a).getGuid().equals(guid)) {
1381 listManager.getTagIndex().remove(a);
1386 // Setup the tree containing the user's tags
1387 private void initializeTagTree() {
1388 logger.log(logger.HIGH, "Entering NeverNote.initializeTagTree");
1389 tagTree.itemSelectionChanged.connect(this, "tagTreeSelection()");
1390 listManager.tagSignal.refreshTagTreeCounts.connect(tagTree, "updateCounts(List)");
1391 logger.log(logger.HIGH, "Leaving NeverNote.initializeTagTree");
1393 // Listener when a tag is selected
1394 private void tagTreeSelection() {
1395 logger.log(logger.HIGH, "Entering NeverNote.tagTreeSelection");
1398 clearAttributeFilter();
1399 clearSavedSearchFilter();
1401 menuBar.noteRestoreAction.setVisible(false);
1403 List<QTreeWidgetItem> selections = tagTree.selectedItems();
1404 QTreeWidgetItem currentSelection;
1405 selectedTagGUIDs.clear();
1406 for (int i=0; i<selections.size(); i++) {
1407 currentSelection = selections.get(i);
1408 selectedTagGUIDs.add(currentSelection.text(2));
1410 if (selections.size() > 0) {
1411 menuBar.tagEditAction.setEnabled(true);
1412 menuBar.tagDeleteAction.setEnabled(true);
1415 menuBar.tagEditAction.setEnabled(false);
1416 menuBar.tagDeleteAction.setEnabled(false);
1418 listManager.setSelectedTags(selectedTagGUIDs);
1419 listManager.loadNotesIndex();
1420 noteIndexUpdated(false);
1421 logger.log(logger.HIGH, "Leaving NeverNote.tagTreeSelection");
1423 // trigger the tag index to be refreshed
1424 @SuppressWarnings("unused")
1425 private void tagIndexUpdated() {
1426 tagIndexUpdated(true);
1428 private void tagIndexUpdated(boolean reload) {
1429 logger.log(logger.HIGH, "Entering NeverNote.tagIndexUpdated");
1430 if (selectedTagGUIDs == null)
1431 selectedTagGUIDs = new ArrayList<String>();
1432 // selectedTagGUIDs.clear(); // clear out old entries
1434 tagTree.blockSignals(true);
1436 tagTree.load(listManager.getTagIndex());
1437 for (int i=selectedTagGUIDs.size()-1; i>=0; i--) {
1438 boolean found = tagTree.selectGuid(selectedTagGUIDs.get(i));
1440 selectedTagGUIDs.remove(i);
1442 tagTree.blockSignals(false);
1444 browserWindow.setTag(getTagNamesForNote(currentNote));
1445 logger.log(logger.HIGH, "Leaving NeverNote.tagIndexUpdated");
1447 // Show/Hide note information
1448 private void toggleTagWindow() {
1449 logger.log(logger.HIGH, "Entering NeverNote.toggleTagWindow");
1450 if (tagTree.isVisible())
1454 menuBar.hideTags.setChecked(tagTree.isVisible());
1455 Global.saveWindowVisible("tagTree", tagTree.isVisible());
1456 logger.log(logger.HIGH, "Leaving NeverNote.toggleTagWindow");
1458 // A note's tags have been updated
1459 @SuppressWarnings("unused")
1460 private void updateNoteTags(String guid, List<String> tags) {
1461 // Save any new tags. We'll need them later.
1462 List<String> newTags = new ArrayList<String>();
1463 for (int i=0; i<tags.size(); i++) {
1464 if (conn.getTagTable().findTagByName(tags.get(i))==null)
1465 newTags.add(tags.get(i));
1468 listManager.saveNoteTags(guid, tags);
1469 listManager.countTagResults(listManager.getNoteIndex());
1470 StringBuffer names = new StringBuffer("");
1471 for (int i=0; i<tags.size(); i++) {
1472 names = names.append(tags.get(i));
1473 if (i<tags.size()-1) {
1474 names.append(Global.tagDelimeter + " ");
1477 browserWindow.setTag(names.toString());
1480 // Now, we need to add any new tags to the tag tree
1481 for (int i=0; i<newTags.size(); i++)
1482 tagTree.insertTag(newTags.get(i), conn.getTagTable().findTagByName(newTags.get(i)));
1484 // Get a string containing all tag names for a note
1485 private String getTagNamesForNote(Note n) {
1486 logger.log(logger.HIGH, "Entering NeverNote.getTagNamesForNote");
1487 if (n==null || n.getGuid() == null || n.getGuid().equals(""))
1489 StringBuffer buffer = new StringBuffer(100);
1490 Vector<String> v = new Vector<String>();
1491 List<String> guids = n.getTagGuids();
1496 for (int i=0; i<guids.size(); i++) {
1497 v.add(listManager.getTagNameByGuid(guids.get(i)));
1499 Comparator<String> comparator = Collections.reverseOrder();
1500 Collections.sort(v,comparator);
1501 Collections.reverse(v);
1503 for (int i = 0; i<v.size(); i++) {
1505 buffer.append(", ");
1506 buffer.append(v.get(i));
1509 logger.log(logger.HIGH, "Leaving NeverNote.getTagNamesForNote");
1510 return buffer.toString();
1512 // Tags were added via dropping notes from the note list
1513 @SuppressWarnings("unused")
1514 private void tagsAdded(String noteGuid, String tagGuid) {
1515 String tagName = null;
1516 for (int i=0; i<listManager.getTagIndex().size(); i++) {
1517 if (listManager.getTagIndex().get(i).getGuid().equals(tagGuid)) {
1518 tagName = listManager.getTagIndex().get(i).getName();
1519 i=listManager.getTagIndex().size();
1522 if (tagName == null)
1525 for (int i=0; i<listManager.getMasterNoteIndex().size(); i++) {
1526 if (listManager.getMasterNoteIndex().get(i).getGuid().equals(noteGuid)) {
1527 List<String> tagNames = new ArrayList<String>();
1528 tagNames.add(new String(tagName));
1529 Note n = listManager.getMasterNoteIndex().get(i);
1530 for (int j=0; j<n.getTagNames().size(); j++) {
1531 tagNames.add(new String(n.getTagNames().get(j)));
1533 listManager.getNoteTableModel().updateNoteTags(noteGuid, n.getTagGuids(), tagNames);
1534 if (n.getGuid().equals(currentNoteGuid)) {
1535 Collections.sort(tagNames);
1536 String display = "";
1537 for (int j=0; j<tagNames.size(); j++) {
1538 display = display+tagNames.get(j);
1539 if (j+2<tagNames.size())
1540 display = display+Global.tagDelimeter+" ";
1542 browserWindow.setTag(display);
1544 i=listManager.getMasterNoteIndex().size();
1549 listManager.getNoteTableModel().updateNoteSyncStatus(noteGuid, false);
1551 private void clearTagFilter() {
1552 tagTree.blockSignals(true);
1553 tagTree.clearSelection();
1554 menuBar.noteRestoreAction.setVisible(false);
1555 menuBar.tagEditAction.setEnabled(false);
1556 menuBar.tagDeleteAction.setEnabled(false);
1557 selectedTagGUIDs.clear();
1558 listManager.setSelectedTags(selectedTagGUIDs);
1559 tagTree.blockSignals(false);
1563 //***************************************************************
1564 //***************************************************************
1565 //** These functions deal with Saved Search menu items
1566 //***************************************************************
1567 //***************************************************************
1568 // Add a new notebook
1569 @SuppressWarnings("unused")
1570 private void addSavedSearch() {
1571 logger.log(logger.HIGH, "Inside NeverNote.addSavedSearch");
1572 SavedSearchEdit edit = new SavedSearchEdit();
1573 edit.setSearchList(listManager.getSavedSearchIndex());
1576 if (!edit.okPressed())
1579 Calendar currentTime = new GregorianCalendar();
1580 Long l = new Long(currentTime.getTimeInMillis());
1581 String randint = new String(Long.toString(l));
1583 SavedSearch search = new SavedSearch();
1584 search.setUpdateSequenceNum(0);
1585 search.setGuid(randint);
1586 search.setName(edit.getName());
1587 search.setQuery(edit.getQuery());
1588 search.setFormat(QueryFormat.USER);
1589 listManager.getSavedSearchIndex().add(search);
1590 conn.getSavedSearchTable().addSavedSearch(search, true);
1591 savedSearchIndexUpdated();
1592 logger.log(logger.HIGH, "Leaving NeverNote.addSavedSearch");
1594 // Edit an existing tag
1595 @SuppressWarnings("unused")
1596 private void editSavedSearch() {
1597 logger.log(logger.HIGH, "Entering NeverNote.editSavedSearch");
1598 SavedSearchEdit edit = new SavedSearchEdit();
1599 edit.setTitle(tr("Edit Search"));
1600 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
1601 QTreeWidgetItem currentSelection;
1602 currentSelection = selections.get(0);
1603 String guid = currentSelection.text(1);
1604 SavedSearch s = conn.getSavedSearchTable().getSavedSearch(guid);
1605 edit.setName(currentSelection.text(0));
1606 edit.setQuery(s.getQuery());
1607 edit.setSearchList(listManager.getSavedSearchIndex());
1610 if (!edit.okPressed())
1613 List<SavedSearch> list = listManager.getSavedSearchIndex();
1614 SavedSearch search = null;
1615 boolean found = false;
1616 for (int i=0; i<list.size(); i++) {
1617 search = list.get(i);
1618 if (search.getGuid().equals(guid)) {
1625 search.setName(edit.getName());
1626 search.setQuery(edit.getQuery());
1627 conn.getSavedSearchTable().updateSavedSearch(search, true);
1628 savedSearchIndexUpdated();
1629 logger.log(logger.HIGH, "Leaving NeverNote.editSavedSearch");
1631 // Delete an existing tag
1632 @SuppressWarnings("unused")
1633 private void deleteSavedSearch() {
1634 logger.log(logger.HIGH, "Entering NeverNote.deleteSavedSearch");
1636 if (QMessageBox.question(this, "Confirmation", "Delete the selected search?",
1637 QMessageBox.StandardButton.Yes,
1638 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
1642 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
1643 for (int i=selections.size()-1; i>=0; i--) {
1644 QTreeWidgetItem currentSelection;
1645 currentSelection = selections.get(i);
1646 for (int j=0; j<listManager.getSavedSearchIndex().size(); j++) {
1647 if (listManager.getSavedSearchIndex().get(j).getGuid().equals(currentSelection.text(1))) {
1648 conn.getSavedSearchTable().expungeSavedSearch(listManager.getSavedSearchIndex().get(j).getGuid(), true);
1649 listManager.getSavedSearchIndex().remove(j);
1650 j=listManager.getSavedSearchIndex().size()+1;
1653 selections.remove(i);
1655 savedSearchIndexUpdated();
1656 logger.log(logger.HIGH, "Leaving NeverNote.deleteSavedSearch");
1658 // Setup the tree containing the user's tags
1659 private void initializeSavedSearchTree() {
1660 logger.log(logger.HIGH, "Entering NeverNote.initializeSavedSearchTree");
1661 savedSearchTree.itemSelectionChanged.connect(this, "savedSearchTreeSelection()");
1662 logger.log(logger.HIGH, "Leaving NeverNote.initializeSavedSearchTree");
1664 // Listener when a tag is selected
1665 @SuppressWarnings("unused")
1666 private void savedSearchTreeSelection() {
1667 logger.log(logger.HIGH, "Entering NeverNote.savedSearchTreeSelection");
1669 clearNotebookFilter();
1672 clearAttributeFilter();
1674 String currentGuid = selectedSavedSearchGUID;
1675 menuBar.savedSearchEditAction.setEnabled(true);
1676 menuBar.savedSearchDeleteAction.setEnabled(true);
1677 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
1678 QTreeWidgetItem currentSelection;
1679 selectedSavedSearchGUID = "";
1680 for (int i=0; i<selections.size(); i++) {
1681 currentSelection = selections.get(i);
1682 if (currentSelection.text(1).equals(currentGuid)) {
1683 currentSelection.setSelected(false);
1685 selectedSavedSearchGUID = currentSelection.text(1);
1687 // i = selections.size() +1;
1690 // There is the potential for no notebooks to be selected if this
1691 // happens then we make it look like all notebooks were selecetd.
1692 // If that happens, just select the "all notebooks"
1693 if (selections.size()==0) {
1694 clearSavedSearchFilter();
1696 listManager.setSelectedSavedSearch(selectedSavedSearchGUID);
1698 logger.log(logger.HIGH, "Leaving NeverNote.savedSearchTreeSelection");
1700 private void clearSavedSearchFilter() {
1701 menuBar.savedSearchEditAction.setEnabled(false);
1702 menuBar.savedSearchDeleteAction.setEnabled(false);
1703 savedSearchTree.blockSignals(true);
1704 savedSearchTree.clearSelection();
1705 savedSearchTree.blockSignals(false);
1706 selectedSavedSearchGUID = "";
1707 searchField.setEditText("");
1708 searchPerformed = false;
1709 listManager.setSelectedSavedSearch(selectedSavedSearchGUID);
1711 // trigger the tag index to be refreshed
1712 private void savedSearchIndexUpdated() {
1713 if (selectedSavedSearchGUID == null)
1714 selectedSavedSearchGUID = new String();
1715 savedSearchTree.blockSignals(true);
1716 savedSearchTree.load(listManager.getSavedSearchIndex());
1717 savedSearchTree.selectGuid(selectedSavedSearchGUID);
1718 savedSearchTree.blockSignals(false);
1720 // trigger when the saved search selection changes
1721 @SuppressWarnings("unused")
1722 private void updateSavedSearchSelection() {
1723 logger.log(logger.HIGH, "Entering NeverNote.updateSavedSearchSelection()");
1725 menuBar.savedSearchEditAction.setEnabled(true);
1726 menuBar.savedSearchDeleteAction.setEnabled(true);
1727 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
1729 if (selections.size() > 0) {
1730 menuBar.savedSearchEditAction.setEnabled(true);
1731 menuBar.savedSearchDeleteAction.setEnabled(true);
1732 selectedSavedSearchGUID = selections.get(0).text(1);
1733 SavedSearch s = conn.getSavedSearchTable().getSavedSearch(selectedSavedSearchGUID);
1734 searchField.setEditText(s.getQuery());
1736 menuBar.savedSearchEditAction.setEnabled(false);
1737 menuBar.savedSearchDeleteAction.setEnabled(false);
1738 selectedSavedSearchGUID = "";
1739 searchField.setEditText("");
1741 searchFieldChanged();
1743 logger.log(logger.HIGH, "Leaving NeverNote.updateSavedSearchSelection()");
1747 // Show/Hide note information
1748 private void toggleSavedSearchWindow() {
1749 logger.log(logger.HIGH, "Entering NeverNote.toggleSavedSearchWindow");
1750 if (savedSearchTree.isVisible())
1751 savedSearchTree.hide();
1753 savedSearchTree.show();
1754 menuBar.hideSavedSearches.setChecked(savedSearchTree.isVisible());
1756 Global.saveWindowVisible("savedSearchTree", savedSearchTree.isVisible());
1757 logger.log(logger.HIGH, "Leaving NeverNote.toggleSavedSearchWindow");
1763 //***************************************************************
1764 //***************************************************************
1765 //** These functions deal with Help menu & tool menu items
1766 //***************************************************************
1767 //***************************************************************
1768 // Show database status
1769 @SuppressWarnings("unused")
1770 private void databaseStatus() {
1772 int dirty = conn.getNoteTable().getDirtyCount();
1773 int unindexed = conn.getNoteTable().getUnindexedCount();
1774 DatabaseStatus status = new DatabaseStatus();
1775 status.setUnsynchronized(dirty);
1776 status.setUnindexed(unindexed);
1777 status.setNoteCount(conn.getNoteTable().getNoteCount());
1778 status.setNotebookCount(listManager.getNotebookIndex().size());
1779 status.setSavedSearchCount(listManager.getSavedSearchIndex().size());
1780 status.setTagCount(listManager.getTagIndex().size());
1781 status.setResourceCount(conn.getNoteTable().noteResourceTable.getResourceCount());
1782 status.setWordCount(conn.getWordsTable().getWordCount());
1786 // Compact the database
1787 @SuppressWarnings("unused")
1788 private void compactDatabase() {
1789 logger.log(logger.HIGH, "Entering NeverNote.compactDatabase");
1790 if (QMessageBox.question(this, tr("Confirmation"), tr("This will free unused space in the database, "+
1791 "but please be aware that depending upon the size of your database this can be time consuming " +
1792 "and NeverNote will be unresponsive until it is complete. Do you wish to continue?"),
1793 QMessageBox.StandardButton.Yes,
1794 QMessageBox.StandardButton.No)==StandardButton.No.value() && Global.verifyDelete() == true) {
1797 setMessage("Compacting database.");
1799 listManager.compactDatabase();
1801 setMessage("Database compact is complete.");
1802 logger.log(logger.HIGH, "Leaving NeverNote.compactDatabase");
1804 @SuppressWarnings("unused")
1805 private void accountInformation() {
1806 logger.log(logger.HIGH, "Entering NeverNote.accountInformation");
1807 AccountDialog dialog = new AccountDialog();
1809 logger.log(logger.HIGH, "Leaving NeverNote.accountInformation");
1811 @SuppressWarnings("unused")
1812 private void releaseNotes() {
1813 logger.log(logger.HIGH, "Entering NeverNote.releaseNotes");
1814 QDialog dialog = new QDialog(this);
1815 QHBoxLayout layout = new QHBoxLayout();
1816 QTextEdit textBox = new QTextEdit();
1817 layout.addWidget(textBox);
1818 textBox.setReadOnly(true);
1819 QFile file = new QFile(Global.getFileManager().getHomeDirPath("release.txt"));
1820 if (!file.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly,
1821 QIODevice.OpenModeFlag.Text)))
1823 textBox.setText(file.readAll().toString());
1825 dialog.setWindowTitle(tr("Release Notes"));
1826 dialog.setLayout(layout);
1828 logger.log(logger.HIGH, "Leaving NeverNote.releaseNotes");
1830 // Called when user picks Log from the help menu
1831 @SuppressWarnings("unused")
1832 private void logger() {
1833 logger.log(logger.HIGH, "Entering NeverNote.logger");
1834 QDialog dialog = new QDialog(this);
1835 QHBoxLayout layout = new QHBoxLayout();
1836 QListWidget textBox = new QListWidget();
1837 layout.addWidget(textBox);
1838 textBox.addItems(emitLog);
1840 dialog.setLayout(layout);
1841 dialog.setWindowTitle(tr("Mesasge Log"));
1843 logger.log(logger.HIGH, "Leaving NeverNote.logger");
1845 // Menu option "help/about" was selected
1846 @SuppressWarnings("unused")
1847 private void about() {
1848 logger.log(logger.HIGH, "Entering NeverNote.about");
1849 QMessageBox.about(this,
1850 tr("About NeverNote"),
1851 tr("<h4><center><b>NeverNote</b></center></h4><hr><center>Version ")
1853 +tr("<hr></center>Evernote"
1854 +"An Open Source Evernote Client.<br><br>"
1855 +"Licensed under GPL v2. <br><hr><br>"
1856 +"Evernote is copyright 2001-2010 by Evernote Corporation<br>"
1857 +"Jambi and QT are the licensed trademark of Nokia Corporation<br>"
1858 +"PDFRenderer is licened under the LGPL<br>"
1859 +"JTidy is copyrighted under the World Wide Web Consortium<br>"
1860 +"Apache Common Utilities licensed under the Apache License Version 2.0<br>"
1861 +"Jazzy is licened under the LGPL<br>"
1862 +"Java is a registered trademark of Oracle Corporation.<br><hr>"));
1863 logger.log(logger.HIGH, "Leaving NeverNote.about");
1865 // Hide the entire left hand side
1866 @SuppressWarnings("unused")
1867 private void toggleLeftSide() {
1870 hidden = !menuBar.hideLeftSide.isChecked();
1871 menuBar.hideLeftSide.setChecked(!hidden);
1873 if (notebookTree.isVisible() != hidden)
1874 toggleNotebookWindow();
1875 if (savedSearchTree.isVisible() != hidden)
1876 toggleSavedSearchWindow();
1877 if (tagTree.isVisible() != hidden)
1879 if (attributeTree.isVisible() != hidden)
1880 toggleAttributesWindow();
1881 if (trashTree.isVisible() != hidden)
1882 toggleTrashWindow();
1884 Global.saveWindowVisible("leftPanel", hidden);
1889 //***************************************************************
1890 //***************************************************************
1891 //** These functions deal with the Toolbar
1892 //***************************************************************
1893 //***************************************************************
1894 // Text in the search bar has been cleared
1895 private void searchFieldCleared() {
1896 searchField.setEditText("");
1897 saveNoteIndexWidth();
1899 // text in the search bar changed. We only use this to tell if it was cleared,
1900 // otherwise we trigger off searchFieldChanged.
1901 @SuppressWarnings("unused")
1902 private void searchFieldTextChanged(String text) {
1903 if (text.trim().equals("")) {
1904 searchFieldCleared();
1905 if (searchPerformed) {
1907 listManager.setEnSearch("");
1908 ///// listManager.clearNoteIndexSearch();
1909 //noteIndexUpdated(true);
1910 listManager.loadNotesIndex();
1911 refreshEvernoteNote(true);
1912 noteIndexUpdated(false);
1914 searchPerformed = false;
1917 // Text in the toolbar has changed
1918 private void searchFieldChanged() {
1919 logger.log(logger.HIGH, "Entering NeverNote.searchFieldChanged");
1921 saveNoteIndexWidth();
1922 String text = searchField.currentText();
1923 listManager.setEnSearch(text.trim());
1924 listManager.loadNotesIndex();
1925 //--->>> noteIndexUpdated(true);
1926 noteIndexUpdated(false);
1927 refreshEvernoteNote(true);
1928 searchPerformed = true;
1929 logger.log(logger.HIGH, "Leaving NeverNote.searchFieldChanged");
1932 // Build the window tool bar
1933 private void setupToolBar() {
1934 logger.log(logger.HIGH, "Entering NeverNote.setupToolBar");
1935 toolBar = addToolBar(tr("Tool Bar"));
1936 menuBar.setupToolBarVisible();
1937 if (!Global.isWindowVisible("toolBar"))
1938 toolBar.setVisible(false);
1940 toolBar.setVisible(true);
1942 prevButton = toolBar.addAction("Previous");
1943 QIcon prevIcon = new QIcon(iconPath+"back.png");
1944 prevButton.setIcon(prevIcon);
1945 prevButton.triggered.connect(this, "previousViewedAction()");
1947 nextButton = toolBar.addAction("Next");
1948 QIcon nextIcon = new QIcon(iconPath+"forward.png");
1949 nextButton.setIcon(nextIcon);
1950 nextButton.triggered.connect(this, "nextViewedAction()");
1952 upButton = toolBar.addAction("Up");
1953 QIcon upIcon = new QIcon(iconPath+"up.png");
1954 upButton.setIcon(upIcon);
1955 upButton.triggered.connect(this, "upAction()");
1957 downButton = toolBar.addAction("Down");
1958 QIcon downIcon = new QIcon(iconPath+"down.png");
1959 downButton.setIcon(downIcon);
1960 downButton.triggered.connect(this, "downAction()");
1962 synchronizeButton = toolBar.addAction("Synchronize");
1963 synchronizeAnimation = new ArrayList<QIcon>();
1964 synchronizeAnimation.add(new QIcon(iconPath+"synchronize-0.png"));
1965 synchronizeAnimation.add(new QIcon(iconPath+"synchronize-1.png"));
1966 synchronizeAnimation.add(new QIcon(iconPath+"synchronize-2.png"));
1967 synchronizeAnimation.add(new QIcon(iconPath+"synchronize-3.png"));
1968 synchronizeButton.setIcon(synchronizeAnimation.get(0));
1969 synchronizeFrame = 0;
1970 synchronizeButton.triggered.connect(this, "evernoteSync()");
1972 printButton = toolBar.addAction("Print");
1973 QIcon printIcon = new QIcon(iconPath+"print.png");
1974 printButton.setIcon(printIcon);
1975 printButton.triggered.connect(this, "printNote()");
1977 tagButton = toolBar.addAction("Tag");
1978 QIcon tagIcon = new QIcon(iconPath+"tag.png");
1979 tagButton.setIcon(tagIcon);
1980 tagButton.triggered.connect(browserWindow, "modifyTags()");
1982 attributeButton = toolBar.addAction("Attributes");
1983 QIcon attributeIcon = new QIcon(iconPath+"attribute.png");
1984 attributeButton.setIcon(attributeIcon);
1985 attributeButton.triggered.connect(this, "toggleNoteInformation()");
1987 emailButton = toolBar.addAction("Email");
1988 QIcon emailIcon = new QIcon(iconPath+"email.png");
1989 emailButton.setIcon(emailIcon);
1990 emailButton.triggered.connect(this, "emailNote()");
1992 deleteButton = toolBar.addAction("Delete");
1993 QIcon deleteIcon = new QIcon(iconPath+"delete.png");
1994 deleteButton.setIcon(deleteIcon);
1995 deleteButton.triggered.connect(this, "deleteNote()");
1997 newButton = toolBar.addAction("New");
1998 QIcon newIcon = new QIcon(iconPath+"new.png");
1999 newButton.triggered.connect(this, "addNote()");
2000 newButton.setIcon(newIcon);
2001 toolBar.addSeparator();
2002 toolBar.addWidget(new QLabel(tr("Quota:")));
2003 toolBar.addWidget(quotaBar);
2004 //quotaBar.setSizePolicy(Policy.Minimum, Policy.Minimum);
2008 zoomSpinner = new QSpinBox();
2009 zoomSpinner.setMinimum(10);
2010 zoomSpinner.setMaximum(1000);
2011 zoomSpinner.setAccelerated(true);
2012 zoomSpinner.setSingleStep(10);
2013 zoomSpinner.setValue(100);
2014 zoomSpinner.valueChanged.connect(this, "zoomChanged()");
2015 toolBar.addWidget(new QLabel(tr("Zoom")));
2016 toolBar.addWidget(zoomSpinner);
2018 //toolBar.addWidget(new QLabel(" "));
2019 toolBar.addSeparator();
2020 toolBar.addWidget(new QLabel(tr(" Search:")));
2021 toolBar.addWidget(searchField);
2022 QSizePolicy sizePolicy = new QSizePolicy();
2023 sizePolicy.setHorizontalPolicy(Policy.MinimumExpanding);
2024 searchField.setSizePolicy(sizePolicy);
2025 searchField.setInsertPolicy(InsertPolicy.InsertAtTop);
2027 searchClearButton = toolBar.addAction("Search Clear");
2028 QIcon searchClearIcon = new QIcon(iconPath+"searchclear.png");
2029 searchClearButton.setIcon(searchClearIcon);
2030 searchClearButton.triggered.connect(this, "searchFieldCleared()");
2032 logger.log(logger.HIGH, "Leaving NeverNote.setupToolBar");
2034 // Update the sychronize button picture
2035 @SuppressWarnings("unused")
2036 private void updateSyncButton() {
2038 if (synchronizeFrame == 4)
2039 synchronizeFrame = 0;
2040 synchronizeButton.setIcon(synchronizeAnimation.get(synchronizeFrame));
2042 // Synchronize with Evernote
2043 @SuppressWarnings("unused")
2044 private void evernoteSync() {
2045 logger.log(logger.HIGH, "Entering NeverNote.evernoteSync");
2046 if (!Global.isConnected)
2048 if (Global.isConnected)
2049 synchronizeAnimationTimer.start(200);
2051 logger.log(logger.HIGH, "Leaving NeverNote.evernoteSync");
2053 private void updateQuotaBar() {
2054 long limit = Global.getUploadLimit();
2055 long amount = Global.getUploadAmount();
2056 if (amount>0 && limit>0) {
2057 int percent =(int)(amount*100/limit);
2058 quotaBar.setValue(percent);
2060 quotaBar.setValue(0);
2063 @SuppressWarnings("unused")
2064 private void zoomChanged() {
2065 browserWindow.getBrowser().setZoomFactor(new Double(zoomSpinner.value())/100);
2068 //****************************************************************
2069 //****************************************************************
2070 //* System Tray functions
2071 //****************************************************************
2072 //****************************************************************
2073 private void trayToggleVisible() {
2081 @SuppressWarnings("unused")
2082 private void trayActivated(QSystemTrayIcon.ActivationReason reason) {
2083 if (reason == QSystemTrayIcon.ActivationReason.DoubleClick) {
2084 String name = QSystemTrayIcon.MessageIcon.resolve(reason.value()).name();
2085 trayToggleVisible();
2090 //***************************************************************
2091 //***************************************************************
2092 //** These functions deal with the trash tree
2093 //***************************************************************
2094 //***************************************************************
2095 // Setup the tree containing the trash.
2096 @SuppressWarnings("unused")
2097 private void trashTreeSelection() {
2098 logger.log(logger.HIGH, "Entering NeverNote.trashTreeSelection");
2100 clearNotebookFilter();
2102 clearAttributeFilter();
2103 clearSavedSearchFilter();
2105 String tempGuid = currentNoteGuid;
2107 // currentNoteGuid = "";
2108 currentNote = new Note();
2109 selectedNoteGUIDs.clear();
2110 listManager.getSelectedNotebooks().clear();
2111 listManager.getSelectedTags().clear();
2112 listManager.setSelectedSavedSearch("");
2113 browserWindow.clear();
2115 // toggle the add buttons
2116 newButton.setEnabled(!newButton.isEnabled());
2117 menuBar.noteAdd.setEnabled(newButton.isEnabled());
2118 menuBar.noteAdd.setVisible(true);
2120 List<QTreeWidgetItem> selections = trashTree.selectedItems();
2121 if (selections.size() == 0) {
2122 currentNoteGuid = trashNoteGuid;
2123 trashNoteGuid = tempGuid;
2124 Global.showDeleted = false;
2125 menuBar.noteRestoreAction.setEnabled(false);
2126 menuBar.noteRestoreAction.setVisible(false);
2129 currentNoteGuid = trashNoteGuid;
2130 trashNoteGuid = tempGuid;
2131 menuBar.noteRestoreAction.setEnabled(true);
2132 menuBar.noteRestoreAction.setVisible(true);
2133 Global.showDeleted = true;
2135 listManager.loadNotesIndex();
2136 noteIndexUpdated(false);
2137 //// browserWindow.setEnabled(newButton.isEnabled());
2138 browserWindow.setReadOnly(!newButton.isEnabled());
2139 logger.log(logger.HIGH, "Leaving NeverNote.trashTreeSelection");
2141 // Empty the trash file
2142 @SuppressWarnings("unused")
2143 private void emptyTrash() {
2144 // browserWindow.clear();
2145 listManager.emptyTrash();
2146 if (trashTree.selectedItems().size() > 0) {
2147 listManager.getSelectedNotebooks().clear();
2148 listManager.getSelectedTags().clear();
2149 listManager.setSelectedSavedSearch("");
2150 newButton.setEnabled(!newButton.isEnabled());
2151 menuBar.noteAdd.setEnabled(newButton.isEnabled());
2152 menuBar.noteAdd.setVisible(true);
2153 browserWindow.clear();
2156 clearNotebookFilter();
2157 clearSavedSearchFilter();
2158 clearAttributeFilter();
2160 Global.showDeleted = false;
2161 menuBar.noteRestoreAction.setEnabled(false);
2162 menuBar.noteRestoreAction.setVisible(false);
2164 listManager.loadNotesIndex();
2165 //--->>> noteIndexUpdated(true);
2166 noteIndexUpdated(false);
2169 // Show/Hide trash window
2170 private void toggleTrashWindow() {
2171 logger.log(logger.HIGH, "Entering NeverNote.toggleTrashWindow");
2172 if (trashTree.isVisible())
2176 menuBar.hideTrash.setChecked(trashTree.isVisible());
2178 Global.saveWindowVisible("trashTree", trashTree.isVisible());
2179 logger.log(logger.HIGH, "Leaving NeverNote.trashWindow");
2181 private void clearTrashFilter() {
2182 Global.showDeleted = false;
2183 newButton.setEnabled(true);
2184 menuBar.noteAdd.setEnabled(true);
2185 menuBar.noteAdd.setVisible(true);
2186 trashTree.blockSignals(true);
2187 trashTree.clearSelection();
2188 trashTree.blockSignals(false);
2193 //***************************************************************
2194 //***************************************************************
2195 //** These functions deal with connection settings
2196 //***************************************************************
2197 //***************************************************************
2198 // SyncRunner had a problem and things are disconnected
2199 @SuppressWarnings("unused")
2200 private void remoteErrorDisconnect() {
2201 menuBar.connectAction.setText(tr("Connect"));
2202 menuBar.connectAction.setToolTip(tr("Connect to Evernote"));
2203 menuBar.synchronizeAction.setEnabled(false);
2204 synchronizeAnimationTimer.stop();
2207 // Do a manual connect/disconnect
2208 private void remoteConnect() {
2209 logger.log(logger.HIGH, "Entering NeverNote.remoteConnect");
2211 if (Global.isConnected) {
2212 Global.isConnected = false;
2213 syncRunner.enDisconnect();
2214 setupConnectMenuOptions();
2219 AESEncrypter aes = new AESEncrypter();
2221 aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("secure.txt")));
2222 } catch (FileNotFoundException e) {
2223 // File not found, so we'll just get empty strings anyway.
2225 String userid = aes.getUserid();
2226 String password = aes.getPassword();
2227 if (!userid.equals("") && !password.equals("")) {
2228 Global.username = userid;
2229 Global.password = password;
2232 // Show the login dialog box
2233 if (!Global.automaticLogin() || userid.equals("")|| password.equals("")) {
2234 LoginDialog login = new LoginDialog();
2237 if (!login.okPressed()) {
2241 Global.username = login.getUserid();
2242 Global.password = login.getPassword();
2244 syncRunner.username = Global.username;
2245 syncRunner.password = Global.password;
2246 syncRunner.userStoreUrl = Global.userStoreUrl;
2247 syncRunner.noteStoreUrl = Global.noteStoreUrl;
2248 syncRunner.noteStoreUrlBase = Global.noteStoreUrlBase;
2249 syncRunner.enConnect();
2250 Global.isConnected = syncRunner.isConnected;
2252 setupConnectMenuOptions();
2253 logger.log(logger.HIGH, "Leaving NeverNote.remoteConnect");
2255 private void setupConnectMenuOptions() {
2256 logger.log(logger.HIGH, "entering NeverNote.setupConnectMenuOptions");
2257 if (!Global.isConnected) {
2258 menuBar.connectAction.setText(tr("Connect"));
2259 menuBar.connectAction.setToolTip(tr("Connect to Evernote"));
2260 menuBar.synchronizeAction.setEnabled(false);
2262 menuBar.connectAction.setText(tr("Disconnect"));
2263 menuBar.connectAction.setToolTip(tr("Disconnect from Evernote"));
2264 menuBar.synchronizeAction.setEnabled(true);
2266 logger.log(logger.HIGH, "Leaving NeverNote.setupConnectionMenuOptions");
2271 //***************************************************************
2272 //***************************************************************
2273 //** These functions deal with the GUI Attribute tree
2274 //***************************************************************
2275 //***************************************************************
2276 @SuppressWarnings("unused")
2277 private void attributeTreeClicked(QTreeWidgetItem item, Integer integer) {
2280 clearNotebookFilter();
2282 clearSavedSearchFilter();
2284 if (attributeTreeSelected == null || item.nativeId() != attributeTreeSelected.nativeId()) {
2285 if (item.childCount() > 0) {
2286 item.setSelected(false);
2288 Global.createdBeforeFilter.reset();
2289 Global.createdSinceFilter.reset();
2290 Global.changedBeforeFilter.reset();
2291 Global.changedSinceFilter.reset();
2292 Global.containsFilter.reset();
2293 attributeTreeSelected = item;
2294 DateAttributeFilterTable f = null;
2295 f = findDateAttributeFilterTable(item.parent());
2297 f.select(item.parent().indexOfChild(item));
2299 Global.containsFilter.select(item.parent().indexOfChild(item));
2302 listManager.loadNotesIndex();
2303 noteIndexUpdated(false);
2306 attributeTreeSelected = null;
2307 item.setSelected(false);
2308 Global.createdBeforeFilter.reset();
2309 Global.createdSinceFilter.reset();
2310 Global.changedBeforeFilter.reset();
2311 Global.changedSinceFilter.reset();
2312 Global.containsFilter.reset();
2313 listManager.loadNotesIndex();
2314 noteIndexUpdated(false);
2316 // This determines what attribute filter we need, depending upon the selection
2317 private DateAttributeFilterTable findDateAttributeFilterTable(QTreeWidgetItem w) {
2318 if (w.parent() != null && w.childCount() > 0) {
2319 QTreeWidgetItem parent = w.parent();
2320 if (parent.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Created &&
2321 w.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Since)
2322 return Global.createdSinceFilter;
2323 if (parent.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Created &&
2324 w.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Before)
2325 return Global.createdBeforeFilter;
2326 if (parent.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.LastModified &&
2327 w.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Since)
2328 return Global.changedSinceFilter;
2329 if (parent.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.LastModified &&
2330 w.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Before)
2331 return Global.changedBeforeFilter;
2336 // Show/Hide attribute search window
2337 private void toggleAttributesWindow() {
2338 logger.log(logger.HIGH, "Entering NeverNote.toggleAttributesWindow");
2339 if (attributeTree.isVisible())
2340 attributeTree.hide();
2342 attributeTree.show();
2343 menuBar.hideAttributes.setChecked(attributeTree.isVisible());
2345 Global.saveWindowVisible("attributeTree", attributeTree.isVisible());
2346 logger.log(logger.HIGH, "Leaving NeverNote.toggleAttributeWindow");
2348 private void clearAttributeFilter() {
2349 Global.createdBeforeFilter.reset();
2350 Global.createdSinceFilter.reset();
2351 Global.changedBeforeFilter.reset();
2352 Global.changedSinceFilter.reset();
2353 Global.containsFilter.reset();
2354 attributeTreeSelected = null;
2355 attributeTree.blockSignals(true);
2356 attributeTree.clearSelection();
2357 attributeTree.blockSignals(false);
2361 //***************************************************************
2362 //***************************************************************
2363 //** These functions deal with the GUI Note index table
2364 //***************************************************************
2365 //***************************************************************
2366 // Initialize the note list table
2367 private void initializeNoteTable() {
2368 logger.log(logger.HIGH, "Entering NeverNote.initializeNoteTable");
2369 noteTableView.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection);
2370 noteTableView.selectionModel().selectionChanged.connect(this, "noteTableSelection()");
2371 logger.log(logger.HIGH, "Leaving NeverNote.initializeNoteTable");
2373 // Show/Hide trash window
2374 @SuppressWarnings("unused")
2375 private void toggleNoteListWindow() {
2376 logger.log(logger.HIGH, "Entering NeverNote.toggleNoteListWindow");
2377 if (noteTableView.isVisible())
2378 noteTableView.hide();
2380 noteTableView.show();
2381 menuBar.hideNoteList.setChecked(noteTableView.isVisible());
2383 Global.saveWindowVisible("noteList", noteTableView.isVisible());
2384 logger.log(logger.HIGH, "Leaving NeverNote.toggleNoteListWindow");
2386 // Handle the event that a user selects a note from the table
2387 @SuppressWarnings("unused")
2388 private void noteTableSelection() {
2389 logger.log(logger.HIGH, "Entering NeverNote.noteTableSelection");
2391 if (historyGuids.size() == 0) {
2392 historyGuids.add(currentNoteGuid);
2393 historyPosition = 1;
2395 noteTableView.showColumn(Global.noteTableGuidPosition);
2397 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
2398 noteTableView.hideColumn(Global.noteTableGuidPosition);
2400 if (selections.size() > 0) {
2402 menuBar.noteDuplicateAction.setEnabled(true);
2403 menuBar.noteOnlineHistoryAction.setEnabled(true);
2404 menuBar.noteMergeAction.setEnabled(true);
2405 selectedNoteGUIDs.clear();
2406 if (selections.size() != 1 || Global.showDeleted) {
2407 menuBar.noteDuplicateAction.setEnabled(false);
2409 if (selections.size() != 1 || !Global.isConnected) {
2410 menuBar.noteOnlineHistoryAction.setEnabled(false);
2412 if (selections.size() == 1) {
2413 menuBar.noteMergeAction.setEnabled(false);
2415 for (int i=0; i<selections.size(); i++) {
2416 int row = selections.get(i).row();
2418 upButton.setEnabled(false);
2420 upButton.setEnabled(true);
2421 if (row < listManager.getNoteTableModel().rowCount()-1)
2422 downButton.setEnabled(true);
2424 downButton.setEnabled(false);
2425 index = noteTableView.proxyModel.index(row, Global.noteTableGuidPosition);
2426 SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(index);
2427 currentNoteGuid = (String)ix.values().toArray()[0];
2428 selectedNoteGUIDs.add(currentNoteGuid);
2432 nextButton.setEnabled(true);
2433 prevButton.setEnabled(true);
2435 int endPosition = historyGuids.size()-1;
2436 for (int j=historyPosition; j<=endPosition; j++) {
2437 historyGuids.remove(historyGuids.size()-1);
2439 historyGuids.add(currentNoteGuid);
2440 historyPosition = historyGuids.size();
2442 if (historyPosition <= 1)
2443 prevButton.setEnabled(false);
2444 if (historyPosition == historyGuids.size())
2445 nextButton.setEnabled(false);
2447 fromHistory = false;
2448 scrollToGuid(currentNoteGuid);
2449 refreshEvernoteNote(true);
2450 logger.log(logger.HIGH, "Leaving NeverNote.noteTableSelection");
2452 // Trigger a refresh when the note db has been updated
2453 private void noteIndexUpdated(boolean reload) {
2454 logger.log(logger.HIGH, "Entering NeverNote.noteIndexUpdated");
2456 refreshEvernoteNoteList();
2457 logger.log(logger.HIGH, "Calling note table reload in NeverNote.noteIndexUpdated() - "+reload);
2458 noteTableView.load(reload);
2459 scrollToGuid(currentNoteGuid);
2460 logger.log(logger.HIGH, "Leaving NeverNote.noteIndexUpdated");
2462 // Called when the list of notes is updated
2463 private void refreshEvernoteNoteList() {
2464 logger.log(logger.HIGH, "Entering NeverNote.refreshEvernoteNoteList");
2465 browserWindow.setDisabled(false);
2466 if (selectedNoteGUIDs == null)
2467 selectedNoteGUIDs = new ArrayList<String>();
2468 selectedNoteGUIDs.clear(); // clear out old entries
2470 String saveCurrentNoteGuid = new String();
2471 String tempNoteGuid = new String();
2473 historyGuids.clear();
2474 historyPosition = 0;
2475 prevButton.setEnabled(false);
2476 nextButton.setEnabled(false);
2478 if (currentNoteGuid == null)
2479 currentNoteGuid = new String();
2481 for (Note note : listManager.getNoteIndex()) {
2482 tempNoteGuid = note.getGuid();
2483 if (currentNoteGuid.equals(tempNoteGuid)) {
2484 saveCurrentNoteGuid = new String(tempNoteGuid);
2488 if (listManager.getNoteIndex().size() == 0) {
2489 currentNoteGuid = "";
2491 browserWindow.clear();
2492 browserWindow.setDisabled(true);
2495 if (saveCurrentNoteGuid.equals("") && listManager.getNoteIndex().size() >0) {
2496 currentNoteGuid = listManager.getNoteIndex().get(listManager.getNoteIndex().size()-1).getGuid();
2497 currentNote = listManager.getNoteIndex().get(listManager.getNoteIndex().size()-1);
2498 refreshEvernoteNote(true);
2500 refreshEvernoteNote(false);
2504 logger.log(logger.HIGH, "Leaving NeverNote.refreshEvernoteNoteList");
2506 // Called when the previous arrow button is clicked
2507 @SuppressWarnings("unused")
2508 private void previousViewedAction() {
2509 if (!prevButton.isEnabled())
2511 if (historyPosition == 0)
2514 if (historyPosition <= 0)
2516 String historyGuid = historyGuids.get(historyPosition-1);
2518 for (int i=0; i<noteTableView.model().rowCount(); i++) {
2519 QModelIndex modelIndex = noteTableView.model().index(i, Global.noteTableGuidPosition);
2520 if (modelIndex != null) {
2521 SortedMap<Integer, Object> ix = noteTableView.model().itemData(modelIndex);
2522 String tableGuid = (String)ix.values().toArray()[0];
2523 if (tableGuid.equals(historyGuid)) {
2524 noteTableView.selectRow(i);
2530 @SuppressWarnings("unused")
2531 private void nextViewedAction() {
2532 if (!nextButton.isEnabled())
2534 String historyGuid = historyGuids.get(historyPosition);
2537 for (int i=0; i<noteTableView.model().rowCount(); i++) {
2538 QModelIndex modelIndex = noteTableView.model().index(i, Global.noteTableGuidPosition);
2539 if (modelIndex != null) {
2540 SortedMap<Integer, Object> ix = noteTableView.model().itemData(modelIndex);
2541 String tableGuid = (String)ix.values().toArray()[0];
2542 if (tableGuid.equals(historyGuid)) {
2543 noteTableView.selectRow(i);
2549 // Called when the up arrow is clicked
2550 @SuppressWarnings("unused")
2551 private void upAction() {
2552 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
2553 int row = selections.get(0).row();
2555 noteTableView.selectRow(row-1);
2558 // Called when the down arrow is clicked
2559 @SuppressWarnings("unused")
2560 private void downAction() {
2561 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
2562 int row = selections.get(0).row();
2563 int max = listManager.getNoteTableModel().rowCount();
2565 noteTableView.selectRow(row+1);
2568 // Update a tag string for a specific note in the list
2569 @SuppressWarnings("unused")
2570 private void updateListTags(String guid, List<String> tags) {
2571 logger.log(logger.HIGH, "Entering NeverNote.updateListTags");
2572 StringBuffer tagBuffer = new StringBuffer();
2573 for (int i=0; i<tags.size(); i++) {
2574 tagBuffer.append(tags.get(i));
2575 if (i<tags.size()-1)
2576 tagBuffer.append(", ");
2579 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2580 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2581 if (modelIndex != null) {
2582 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2583 String tableGuid = (String)ix.values().toArray()[0];
2584 if (tableGuid.equals(guid)) {
2585 listManager.getNoteTableModel().setData(i, Global.noteTableTagPosition,tagBuffer.toString());
2586 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2591 logger.log(logger.HIGH, "Leaving NeverNote.updateListTags");
2593 // Update a title for a specific note in the list
2594 @SuppressWarnings("unused")
2595 private void updateListAuthor(String guid, String author) {
2596 logger.log(logger.HIGH, "Entering NeverNote.updateListAuthor");
2598 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2599 //QModelIndex modelIndex = noteTableView.proxyModel.index(i, Global.noteTableGuidPosition);
2600 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2601 if (modelIndex != null) {
2602 // SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(modelIndex);
2603 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2604 String tableGuid = (String)ix.values().toArray()[0];
2605 if (tableGuid.equals(guid)) {
2606 listManager.getNoteTableModel().setData(i, Global.noteTableAuthorPosition,author);
2607 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2612 logger.log(logger.HIGH, "Leaving NeverNote.updateListAuthor");
2614 private void updateListNoteNotebook(String guid, String notebook) {
2615 logger.log(logger.HIGH, "Entering NeverNote.updateListNoteNotebook");
2616 listManager.getNoteTableModel().updateNoteSyncStatus(guid, false);
2617 logger.log(logger.HIGH, "Leaving NeverNote.updateListNoteNotebook");
2619 // Update a title for a specific note in the list
2620 @SuppressWarnings("unused")
2621 private void updateListSourceUrl(String guid, String url) {
2622 logger.log(logger.HIGH, "Entering NeverNote.updateListAuthor");
2624 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2625 //QModelIndex modelIndex = noteTableView.proxyModel.index(i, Global.noteTableGuidPosition);
2626 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2627 if (modelIndex != null) {
2628 // SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(modelIndex);
2629 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2630 String tableGuid = (String)ix.values().toArray()[0];
2631 if (tableGuid.equals(guid)) {
2632 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2633 listManager.getNoteTableModel().setData(i, Global.noteTableSourceUrlPosition,url);
2638 logger.log(logger.HIGH, "Leaving NeverNote.updateListAuthor");
2640 private void updateListGuid(String oldGuid, String newGuid) {
2641 logger.log(logger.HIGH, "Entering NeverNote.updateListTitle");
2643 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2644 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2645 if (modelIndex != null) {
2646 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2647 String tableGuid = (String)ix.values().toArray()[0];
2648 if (tableGuid.equals(oldGuid)) {
2649 listManager.getNoteTableModel().setData(i, Global.noteTableGuidPosition,newGuid);
2650 //listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2655 logger.log(logger.HIGH, "Leaving NeverNote.updateListTitle");
2657 private void updateListTagName(String guid) {
2658 logger.log(logger.HIGH, "Entering NeverNote.updateTagName");
2660 for (int j=0; j<listManager.getNoteIndex().size(); j++) {
2661 if (listManager.getNoteIndex().get(j).getTagGuids().contains(guid)) {
2662 String newName = listManager.getTagNamesForNote(listManager.getNoteIndex().get(j));
2664 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2665 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2666 if (modelIndex != null) {
2667 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2668 String noteGuid = (String)ix.values().toArray()[0];
2669 if (noteGuid.equalsIgnoreCase(listManager.getNoteIndex().get(j).getGuid())) {
2670 listManager.getNoteTableModel().setData(i, Global.noteTableTagPosition, newName);
2671 //listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2672 i=listManager.getNoteTableModel().rowCount();
2678 logger.log(logger.HIGH, "Leaving NeverNote.updateListNotebook");
2680 private void removeListTagName(String guid) {
2681 logger.log(logger.HIGH, "Entering NeverNote.updateTagName");
2683 for (int j=0; j<listManager.getNoteIndex().size(); j++) {
2684 if (listManager.getNoteIndex().get(j).getTagGuids().contains(guid)) {
2685 for (int i=listManager.getNoteIndex().get(j).getTagGuids().size()-1; i>=0; i--) {
2686 if (listManager.getNoteIndex().get(j).getTagGuids().get(i).equals(guid))
2687 listManager.getNoteIndex().get(j).getTagGuids().remove(i);
2690 String newName = listManager.getTagNamesForNote(listManager.getNoteIndex().get(j));
2691 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2692 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2693 if (modelIndex != null) {
2694 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2695 String noteGuid = (String)ix.values().toArray()[0];
2696 if (noteGuid.equalsIgnoreCase(listManager.getNoteIndex().get(j).getGuid())) {
2697 listManager.getNoteTableModel().setData(i, Global.noteTableTagPosition, newName);
2698 // listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2699 i=listManager.getNoteTableModel().rowCount();
2705 logger.log(logger.HIGH, "Leaving NeverNote.updateListNotebook");
2707 private void updateListNotebookName(String oldName, String newName) {
2708 logger.log(logger.HIGH, "Entering NeverNote.updateListNotebookName");
2710 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2711 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableNotebookPosition);
2712 if (modelIndex != null) {
2713 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2714 String tableName = (String)ix.values().toArray()[0];
2715 if (tableName.equalsIgnoreCase(oldName)) {
2716 // listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2717 listManager.getNoteTableModel().setData(i, Global.noteTableNotebookPosition, newName);
2721 logger.log(logger.HIGH, "Leaving NeverNote.updateListNotebookName");
2723 @SuppressWarnings("unused")
2724 private void updateListDateCreated(String guid, QDateTime date) {
2725 logger.log(logger.HIGH, "Entering NeverNote.updateListDateCreated");
2727 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2728 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2729 if (modelIndex != null) {
2730 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2731 String tableGuid = (String)ix.values().toArray()[0];
2732 if (tableGuid.equals(guid)) {
2733 listManager.getNoteTableModel().setData(i, Global.noteTableCreationPosition, date.toString(Global.getDateFormat()+" " +Global.getTimeFormat()));
2738 logger.log(logger.HIGH, "Leaving NeverNote.updateListDateCreated");
2740 @SuppressWarnings("unused")
2741 private void updateListDateSubject(String guid, QDateTime date) {
2742 logger.log(logger.HIGH, "Entering NeverNote.updateListDateSubject");
2744 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2745 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2746 if (modelIndex != null) {
2747 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2748 String tableGuid = (String)ix.values().toArray()[0];
2749 if (tableGuid.equals(guid)) {
2750 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2751 listManager.getNoteTableModel().setData(i, Global.noteTableSubjectDatePosition, date.toString(Global.getDateFormat()+" " +Global.getTimeFormat()));
2756 logger.log(logger.HIGH, "Leaving NeverNote.updateListDateCreated");
2758 @SuppressWarnings("unused")
2759 private void updateListDateChanged(String guid, QDateTime date) {
2760 logger.log(logger.HIGH, "Entering NeverNote.updateListDateChanged");
2762 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2763 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2764 if (modelIndex != null) {
2765 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2766 String tableGuid = (String)ix.values().toArray()[0];
2767 if (tableGuid.equals(guid)) {
2768 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2769 listManager.getNoteTableModel().setData(i, Global.noteTableChangedPosition, date.toString(Global.getDateFormat()+" " +Global.getTimeFormat()));
2774 logger.log(logger.HIGH, "Leaving NeverNote.updateListDateChanged");
2776 private void updateListDateChanged() {
2777 logger.log(logger.HIGH, "Entering NeverNote.updateListDateChanged");
2778 QDateTime date = new QDateTime(QDateTime.currentDateTime());
2779 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2780 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2781 if (modelIndex != null) {
2782 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2783 String tableGuid = (String)ix.values().toArray()[0];
2784 if (tableGuid.equals(currentNoteGuid)) {
2785 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2786 listManager.getNoteTableModel().setData(i, Global.noteTableChangedPosition, date.toString(Global.getDateFormat()+" " +Global.getTimeFormat()));
2791 logger.log(logger.HIGH, "Leaving NeverNote.updateListDateChanged");
2794 @SuppressWarnings("unused")
2795 private void scrollToCurrentGuid() {
2796 //scrollToGuid(currentNoteGuid);
2797 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
2798 if (selections.size() == 0)
2800 QModelIndex index = selections.get(0);
2801 int row = selections.get(0).row();
2802 String guid = (String)index.model().index(row, Global.noteTableGuidPosition).data();
2805 // Scroll to a particular index item
2806 private void scrollToGuid(String guid) {
2807 if (currentNote == null || guid == null)
2809 if (currentNote.isActive() && Global.showDeleted) {
2810 for (int i=0; i<listManager.getNoteIndex().size(); i++) {
2811 if (!listManager.getNoteIndex().get(i).isActive()) {
2812 currentNote = listManager.getNoteIndex().get(i);
2813 currentNoteGuid = currentNote.getGuid();
2814 i = listManager.getNoteIndex().size();
2819 if (!currentNote.isActive() && !Global.showDeleted) {
2820 for (int i=0; i<listManager.getNoteIndex().size(); i++) {
2821 if (listManager.getNoteIndex().get(i).isActive()) {
2822 currentNote = listManager.getNoteIndex().get(i);
2823 currentNoteGuid = currentNote.getGuid();
2824 i = listManager.getNoteIndex().size();
2830 for (int i=0; i<noteTableView.model().rowCount(); i++) {
2831 index = noteTableView.model().index(i, Global.noteTableGuidPosition);
2832 if (currentNoteGuid.equals(index.data())) {
2833 // noteTableView.setCurrentIndex(index);
2834 noteTableView.selectRow(i);
2835 noteTableView.scrollTo(index, ScrollHint.EnsureVisible); // This should work, but it doesn't
2836 i=listManager.getNoteTableModel().rowCount();
2840 // Show/Hide columns
2841 private void showColumns() {
2842 noteTableView.setColumnHidden(Global.noteTableCreationPosition, !Global.isColumnVisible("dateCreated"));
2843 noteTableView.setColumnHidden(Global.noteTableChangedPosition, !Global.isColumnVisible("dateChanged"));
2844 noteTableView.setColumnHidden(Global.noteTableSubjectDatePosition, !Global.isColumnVisible("dateSubject"));
2845 noteTableView.setColumnHidden(Global.noteTableAuthorPosition, !Global.isColumnVisible("author"));
2846 noteTableView.setColumnHidden(Global.noteTableSourceUrlPosition, !Global.isColumnVisible("sourceUrl"));
2847 noteTableView.setColumnHidden(Global.noteTableTagPosition, !Global.isColumnVisible("tags"));
2848 noteTableView.setColumnHidden(Global.noteTableNotebookPosition, !Global.isColumnVisible("notebook"));
2849 noteTableView.setColumnHidden(Global.noteTableSynchronizedPosition, !Global.isColumnVisible("synchronized"));
2851 // Open a separate window
2852 @SuppressWarnings("unused")
2853 private void listDoubleClick() {
2856 // Title color has changed
2857 @SuppressWarnings("unused")
2858 private void titleColorChanged(Integer color) {
2859 logger.log(logger.HIGH, "Entering NeverNote.updateListAuthor");
2861 QColor backgroundColor = new QColor();
2862 QColor foregroundColor = new QColor(QColor.black);
2863 backgroundColor.setRgb(color);
2865 if (backgroundColor.rgb() == QColor.black.rgb() || backgroundColor.rgb() == QColor.blue.rgb())
2866 foregroundColor.setRgb(QColor.white.rgb());
2868 if (selectedNoteGUIDs.size() == 0)
2869 selectedNoteGUIDs.add(currentNoteGuid);
2871 for (int j=0; j<selectedNoteGUIDs.size(); j++) {
2872 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2873 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2874 if (modelIndex != null) {
2875 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2876 String tableGuid = (String)ix.values().toArray()[0];
2877 if (tableGuid.equals(selectedNoteGUIDs.get(j))) {
2878 for (int k=0; k<Global.noteTableColumnCount; k++) {
2879 listManager.getNoteTableModel().setData(i, k, backgroundColor, Qt.ItemDataRole.BackgroundRole);
2880 listManager.getNoteTableModel().setData(i, k, foregroundColor, Qt.ItemDataRole.ForegroundRole);
2881 listManager.updateNoteTitleColor(selectedNoteGUIDs.get(j), backgroundColor.rgb());
2883 i=listManager.getNoteTableModel().rowCount();
2888 logger.log(logger.HIGH, "Leaving NeverNote.updateListAuthor");
2892 //***************************************************************
2893 //***************************************************************
2894 //** These functions deal with Note specific things
2895 //***************************************************************
2896 //***************************************************************
2897 @SuppressWarnings("unused")
2898 private void setNoteDirty() {
2899 logger.log(logger.EXTREME, "Entering NeverNote.setNoteDirty()");
2901 // If the note is dirty, then it is unsynchronized by default.
2905 // Set the note as dirty and check if its status is synchronized in the display table
2907 for (int i=0; i<listManager.getUnsynchronizedNotes().size(); i++) {
2908 if (listManager.getUnsynchronizedNotes().get(i).equals(currentNoteGuid))
2912 // If this wasn't already marked as unsynchronized, then we need to update the table
2913 listManager.getNoteTableModel().updateNoteSyncStatus(currentNoteGuid, false);
2914 /* listManager.getUnsynchronizedNotes().add(currentNoteGuid);
2915 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2916 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2917 if (modelIndex != null) {
2918 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2919 String tableGuid = (String)ix.values().toArray()[0];
2920 if (tableGuid.equals(currentNoteGuid)) {
2921 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2927 logger.log(logger.EXTREME, "Leaving NeverNote.setNoteDirty()");
2929 private void saveNote() {
2930 logger.log(logger.EXTREME, "Inside NeverNote.saveNote()");
2932 logger.log(logger.EXTREME, "Note is dirty.");
2935 preview = new Thumbnailer(currentNoteGuid, new QSize(1024,768));
2936 preview.finished.connect(this, "saveThumbnail(String)");
2937 preview.setContent(browserWindow.getContent());
2939 logger.log(logger.EXTREME, "Saving to cache");
2940 QTextCodec codec = QTextCodec.codecForLocale();
2941 // QTextDecoder decoder = codec.makeDecoder();
2942 codec = QTextCodec.codecForName("UTF-8");
2943 QByteArray unicode = codec.fromUnicode(browserWindow.getContent());
2944 noteCache.put(currentNoteGuid, unicode.toString());
2946 logger.log(logger.EXTREME, "updating list manager");
2947 listManager.updateNoteContent(currentNoteGuid, browserWindow.getContent());
2948 // noteCache.put(currentNoteGuid, browserWindow.getContent());
2949 logger.log(logger.EXTREME, "Updating title");
2950 listManager.updateNoteTitle(currentNoteGuid, browserWindow.getTitle());
2951 updateListDateChanged();
2953 logger.log(logger.EXTREME, "Looking through note index for refreshed note");
2954 for (int i=0; i<listManager.getNoteIndex().size(); i++) {
2955 if (listManager.getNoteIndex().get(i).getGuid().equals(currentNoteGuid)) {
2956 currentNote = listManager.getNoteIndex().get(i);
2957 i = listManager.getNoteIndex().size();
2964 // Get a note from Evernote (and put it in the browser)
2965 private void refreshEvernoteNote(boolean reload) {
2966 logger.log(logger.HIGH, "Entering NeverNote.refreshEvernoteNote");
2967 if (Global.disableViewing) {
2968 browserWindow.setEnabled(false);
2972 if (!Global.showDeleted)
2973 browserWindow.setReadOnly(false);
2974 Global.cryptCounter =0;
2975 if (currentNoteGuid.equals("")) {
2976 browserWindow.setReadOnly(true);
2983 browserWindow.loadingData(true);
2985 currentNote = conn.getNoteTable().getNote(currentNoteGuid, true,true,false,false,true);
2986 if (currentNote == null)
2989 if (!noteCache.containsKey(currentNoteGuid) || conn.getNoteTable().isThumbnailNeeded(currentNoteGuid)) {
2990 QByteArray js = new QByteArray();
2991 // We need to prepend the note with <HEAD></HEAD> or encoded characters are ugly
2992 js.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
2993 js.append("<style type=\"text/css\">en-crypt-temp { border-style:solid; border-color:blue; padding:0.5mm 0.5mm 0.5mm 0.5mm; }</style>");
2994 js.append("<style type=\"text/css\">en-hilight { background-color: rgb(255,255,0) }</style>");
2995 js.append("<style type=\"text/css\">en-spell { text-decoration: none; border-bottom: dotted 1px #cc0000; }</style>");
2996 js.append("</head>");
2997 js.append(rebuildNoteHTML(currentNoteGuid, currentNote.getContent()));
2998 js.append("</HTML>");
2999 js.replace("<!DOCTYPE en-note SYSTEM 'http://xml.evernote.com/pub/enml.dtd'>", "");
3000 js.replace("<!DOCTYPE en-note SYSTEM 'http://xml.evernote.com/pub/enml2.dtd'>", "");
3001 js.replace("<?xml version='1.0' encoding='UTF-8'?>", "");
3002 browserWindow.getBrowser().setContent(js);
3003 noteCache.put(currentNoteGuid, js.toString());
3004 if (conn.getNoteTable().isThumbnailNeeded(currentNoteGuid)) {
3005 preview = new Thumbnailer(currentNoteGuid, new QSize(1024,768));
3006 preview.finished.connect(this, "saveThumbnail(String)");
3007 preview.setContent(js.toString());
3010 logger.log(logger.HIGH, "Note content is being pulled from the cache");
3011 String cachedContent = modifyCachedTodoTags(noteCache.get(currentNoteGuid));
3012 browserWindow.getBrowser().setContent(new QByteArray(cachedContent));
3015 browserWindow.getBrowser().page().setContentEditable(!inkNote); // We don't allow editing of ink notes
3016 browserWindow.setNote(currentNote);
3018 // Build a list of non-closed notebooks
3019 List<Notebook> nbooks = new ArrayList<Notebook>();
3020 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
3021 boolean found=false;
3022 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
3023 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
3027 nbooks.add(listManager.getNotebookIndex().get(i));
3030 browserWindow.setNotebookList(nbooks);
3031 browserWindow.setTitle(currentNote.getTitle());
3032 browserWindow.setTag(getTagNamesForNote(currentNote));
3033 browserWindow.setAuthor(currentNote.getAttributes().getAuthor());
3035 browserWindow.setAltered(currentNote.getUpdated());
3036 browserWindow.setCreation(currentNote.getCreated());
3037 if (currentNote.getAttributes().getSubjectDate() > 0)
3038 browserWindow.setSubjectDate(currentNote.getAttributes().getSubjectDate());
3040 browserWindow.setSubjectDate(currentNote.getCreated());
3041 browserWindow.setUrl(currentNote.getAttributes().getSourceURL());
3042 browserWindow.setAllTags(listManager.getTagIndex());
3043 browserWindow.setCurrentTags(currentNote.getTagNames());
3045 scrollToGuid(currentNoteGuid);
3047 browserWindow.loadingData(false);
3048 if (thumbnailViewer.isActiveWindow())
3051 logger.log(logger.HIGH, "Leaving NeverNote.refreshEvernoteNote");
3053 // Save a generated thumbnail
3054 @SuppressWarnings("unused")
3055 private void saveThumbnail(String guid) {
3056 QFile tFile = new QFile(Global.getFileManager().getResDirPath("thumbnail-" + guid + ".png"));
3057 tFile.open(OpenModeFlag.ReadOnly);
3058 QByteArray imgBytes = tFile.readAll();
3060 conn.getNoteTable().setThumbnail(guid, imgBytes);
3061 conn.getNoteTable().setThumbnailNeeded(guid, false);
3062 thumbnailViewer.setThumbnail(QImage.fromData(imgBytes));
3063 if (thumbnailViewer.isVisible())
3064 thumbnailViewer.showFullScreen();
3067 QByteArray img2 = new QByteArray(conn.getNoteTable().getThumbnail(guid));
3068 QFile file = new QFile(Global.currentDir+"res/aaaa.png");
3069 file.open(OpenModeFlag.WriteOnly);
3074 // Show/Hide note information
3075 @SuppressWarnings("unused")
3076 private void toggleNoteInformation() {
3077 logger.log(logger.HIGH, "Entering NeverNote.toggleNoteInformation");