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 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 saveNoteIndexWidth();
744 int width = notebookTree.columnWidth(0);
745 Global.setColumnWidth("notebookTreeName", width);
746 width = tagTree.columnWidth(0);
747 Global.setColumnWidth("tagTreeName", width);
749 Global.saveWindowMaximized(isMaximized());
750 Global.saveCurrentNoteGuid(currentNoteGuid);
752 int sortCol = noteTableView.proxyModel.sortColumn();
753 int sortOrder = noteTableView.proxyModel.sortOrder().value();
754 Global.setSortColumn(sortCol);
755 Global.setSortOrder(sortOrder);
759 Global.keepRunning = false;
761 logger.log(logger.MEDIUM, "Waiting for indexThread to stop");
762 indexRunner.thread().join(50);
763 logger.log(logger.MEDIUM, "Index thread has stopped");
764 } catch (InterruptedException e1) {
765 e1.printStackTrace();
767 if (!syncRunner.isIdle()) {
769 logger.log(logger.MEDIUM, "Waiting for syncThread to stop");
771 logger.log(logger.MEDIUM, "Sync thread has stopped");
772 } catch (InterruptedException e1) {
773 e1.printStackTrace();
777 logger.log(logger.HIGH, "Leaving NeverNote.closeEvent");
780 public void setMessage(String s) {
781 logger.log(logger.HIGH, "Entering NeverNote.setMessage");
782 logger.log(logger.HIGH, "Message: " +s);
783 statusBar.showMessage(s);
785 logger.log(logger.HIGH, "Leaving NeverNote.setMessage");
788 private void waitCursor(boolean wait) {
790 // QApplication.setOverrideCursor(new QCursor(Qt.CursorShape.WaitCursor));
792 // QApplication.restoreOverrideCursor();
795 private void setupIndexListeners() {
796 indexRunner.noteSignal.noteIndexed.connect(this, "indexThreadComplete(String)");
797 indexRunner.resourceSignal.resourceIndexed.connect(this, "indexThreadComplete(String)");
798 // indexRunner.threadSignal.indexNeeded.connect(listManager, "setIndexNeeded(String, String, Boolean)");
800 private void setupSyncSignalListeners() {
801 syncRunner.tagSignal.listChanged.connect(this, "tagIndexUpdated()");
802 syncRunner.searchSignal.listChanged.connect(this, "savedSearchIndexUpdated()");
803 syncRunner.notebookSignal.listChanged.connect(this, "notebookIndexUpdated()");
804 syncRunner.noteIndexSignal.listChanged.connect(this, "noteIndexUpdated(boolean)");
805 syncRunner.noteSignal.quotaChanged.connect(this, "updateQuotaBar()");
807 syncRunner.syncSignal.saveUploadAmount.connect(this,"saveUploadAmount(long)");
808 syncRunner.syncSignal.saveUserInformation.connect(this,"saveUserInformation(User)");
809 syncRunner.syncSignal.saveEvernoteUpdateCount.connect(this,"saveEvernoteUpdateCount(int)");
811 syncRunner.noteSignal.guidChanged.connect(this, "noteGuidChanged(String, String)");
812 syncRunner.noteSignal.noteChanged.connect(this, "invalidateNoteCache(String, String)");
813 syncRunner.resourceSignal.resourceGuidChanged.connect(this, "noteResourceGuidChanged(String,String,String)");
814 syncRunner.noteSignal.noteDownloaded.connect(listManager, "noteDownloaded(Note)");
816 syncRunner.syncSignal.refreshLists.connect(this, "refreshLists()");
819 private void setupBrowserSignalListeners() {
821 browserWindow.fileWatcher.fileChanged.connect(this, "externalFileEdited(String)");
822 browserWindow.noteSignal.tagsChanged.connect(this, "updateNoteTags(String, List)");
823 browserWindow.noteSignal.tagsChanged.connect(this, "updateListTags(String, List)");
824 //browserWindow.noteSignal.noteChanged.connect(this, "invalidateNoteCache(String, String)");
825 browserWindow.noteSignal.noteChanged.connect(this, "setNoteDirty()");
826 browserWindow.noteSignal.titleChanged.connect(listManager, "updateNoteTitle(String, String)");
827 browserWindow.noteSignal.notebookChanged.connect(this, "updateNoteNotebook(String, String)");
828 browserWindow.noteSignal.createdDateChanged.connect(listManager, "updateNoteCreatedDate(String, QDateTime)");
829 browserWindow.noteSignal.alteredDateChanged.connect(listManager, "updateNoteAlteredDate(String, QDateTime)");
830 browserWindow.noteSignal.subjectDateChanged.connect(listManager, "updateNoteSubjectDate(String, QDateTime)");
831 browserWindow.noteSignal.authorChanged.connect(listManager, "updateNoteAuthor(String, String)");
832 browserWindow.noteSignal.geoChanged.connect(listManager, "updateNoteGeoTag(String, Double,Double,Double)");
833 browserWindow.noteSignal.geoChanged.connect(this, "setNoteDirty()");
834 browserWindow.noteSignal.sourceUrlChanged.connect(listManager, "updateNoteSourceUrl(String, String)");
835 browserWindow.focusLost.connect(this, "saveNote()");
836 browserWindow.resourceSignal.contentChanged.connect(this, "externalFileEdited(String)");
841 //***************************************************************
842 //***************************************************************
843 //* Settings and look & feel
844 //***************************************************************
845 //***************************************************************
846 @SuppressWarnings("unused")
847 private void settings() {
848 logger.log(logger.HIGH, "Entering NeverNote.settings");
849 ConfigDialog settings = new ConfigDialog(this);
850 String dateFormat = Global.getDateFormat();
851 String timeFormat = Global.getTimeFormat();
854 if (Global.showTrayIcon())
859 if (menuBar.showEditorBar.isChecked())
862 // Reset the save timer
863 if (Global.getAutoSaveInterval() > 0)
864 saveTimer.setInterval(1000*60*Global.getAutoSaveInterval());
868 // This is a hack to force a reload of the index in case the date or time changed.
869 // if (!dateFormat.equals(Global.getDateFormat()) ||
870 // !timeFormat.equals(Global.getTimeFormat())) {
872 noteIndexUpdated(true);
875 logger.log(logger.HIGH, "Leaving NeverNote.settings");
877 // Restore things to the way they were
878 private void restoreWindowState() {
879 // We need to name things or this doesn't work.
880 setObjectName("NeverNote");
881 mainLeftRightSplitter.setObjectName("mainLeftRightSplitter");
882 browserIndexSplitter.setObjectName("browserIndexSplitter");
883 leftSplitter1.setObjectName("leftSplitter1");
885 // Restore the actual positions.
886 restoreGeometry(Global.restoreGeometry(objectName()));
887 mainLeftRightSplitter.restoreState(Global.restoreState(mainLeftRightSplitter.objectName()));
888 browserIndexSplitter.restoreState(Global.restoreState(browserIndexSplitter.objectName()));
889 leftSplitter1.restoreState(Global.restoreState(leftSplitter1.objectName()));
892 // Save window positions for the next start
893 private void saveWindowState() {
894 Global.saveGeometry(objectName(), saveGeometry());
895 Global.saveState(mainLeftRightSplitter.objectName(), mainLeftRightSplitter.saveState());
896 Global.saveState(browserIndexSplitter.objectName(), browserIndexSplitter.saveState());
897 Global.saveState(leftSplitter1.objectName(), leftSplitter1.saveState());
899 // Load the style sheet
900 private void loadStyleSheet() {
901 String fileName = Global.getFileManager().getQssDirPath("default.qss");
902 QFile file = new QFile(fileName);
903 file.open(OpenModeFlag.ReadOnly);
904 String styleSheet = file.readAll().toString();
906 setStyleSheet(styleSheet);
908 // Save column widths for the next time
909 private void saveNoteIndexWidth() {
911 width = noteTableView.getColumnWidth(Global.noteTableCreationPosition);
912 Global.setColumnWidth("noteTableCreationPosition", width);
913 width = noteTableView.getColumnWidth(Global.noteTableChangedPosition);
914 Global.setColumnWidth("noteTableChangedPosition", width);
915 width = noteTableView.getColumnWidth(Global.noteTableGuidPosition);
916 Global.setColumnWidth("noteTableGuidPosition", width);
917 width = noteTableView.getColumnWidth(Global.noteTableNotebookPosition);
918 Global.setColumnWidth("noteTableNotebookPosition", width);
919 width = noteTableView.getColumnWidth(Global.noteTableTagPosition);
920 Global.setColumnWidth("noteTableTagPosition", width);
921 width = noteTableView.getColumnWidth(Global.noteTableTitlePosition);
922 Global.setColumnWidth("noteTableTitlePosition", width);
923 width = noteTableView.getColumnWidth(Global.noteTableSourceUrlPosition);
924 Global.setColumnWidth("noteTableSourceUrlPosition", width);
925 width = noteTableView.getColumnWidth(Global.noteTableAuthorPosition);
926 Global.setColumnWidth("noteTableAuthorPosition", width);
927 width = noteTableView.getColumnWidth(Global.noteTableSubjectDatePosition);
928 Global.setColumnWidth("noteTableSubjectDatePosition", width);
929 width = noteTableView.getColumnWidth(Global.noteTableSynchronizedPosition);
930 Global.setColumnWidth("noteTableSynchronizedPosition", width);
934 //***************************************************************
935 //***************************************************************
936 //** These functions deal with Notebook menu items
937 //***************************************************************
938 //***************************************************************
939 // Setup the tree containing the user's notebooks.
940 private void initializeNotebookTree() {
941 logger.log(logger.HIGH, "Entering NeverNote.initializeNotebookTree");
942 notebookTree.itemSelectionChanged.connect(this, "notebookTreeSelection()");
943 listManager.notebookSignal.refreshNotebookTreeCounts.connect(notebookTree, "updateCounts(List, List)");
944 // notebookTree.resize(Global.getSize("notebookTree"));
945 logger.log(logger.HIGH, "Leaving NeverNote.initializeNotebookTree");
947 // Listener when a notebook is selected
948 private void notebookTreeSelection() {
949 logger.log(logger.HIGH, "Entering NeverNote.notebookTreeSelection");
952 clearAttributeFilter();
953 clearSavedSearchFilter();
954 if (Global.mimicEvernoteInterface) {
958 menuBar.noteRestoreAction.setVisible(false);
959 menuBar.notebookEditAction.setEnabled(true);
960 menuBar.notebookDeleteAction.setEnabled(true);
961 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
962 QTreeWidgetItem currentSelection;
963 selectedNotebookGUIDs.clear();
964 if (!Global.mimicEvernoteInterface) {
965 for (int i=0; i<selections.size(); i++) {
966 currentSelection = selections.get(i);
967 selectedNotebookGUIDs.add(currentSelection.text(2));
971 // There is the potential for no notebooks to be selected if this
972 // happens then we make it look like all notebooks were selecetd.
973 // If that happens, just select the "all notebooks"
974 selections = notebookTree.selectedItems();
975 if (selections.size()==0) {
976 selectedNotebookGUIDs.clear();
977 menuBar.notebookEditAction.setEnabled(false);
978 menuBar.notebookDeleteAction.setEnabled(false);
982 if (selections.size() > 0)
983 guid = (selections.get(0).text(2));
984 if (!guid.equals(""))
985 selectedNotebookGUIDs.add(guid);
987 listManager.setSelectedNotebooks(selectedNotebookGUIDs);
988 listManager.loadNotesIndex();
989 noteIndexUpdated(false);
990 logger.log(logger.HIGH, "Leaving NeverNote.notebookTreeSelection");
993 private void clearNotebookFilter() {
994 notebookTree.blockSignals(true);
995 notebookTree.clearSelection();
996 menuBar.noteRestoreAction.setVisible(false);
997 menuBar.notebookEditAction.setEnabled(false);
998 menuBar.notebookDeleteAction.setEnabled(false);
999 selectedNotebookGUIDs.clear();
1000 listManager.setSelectedNotebooks(selectedNotebookGUIDs);
1001 notebookTree.blockSignals(false);
1003 // Triggered when the notebook DB has been updated
1004 private void notebookIndexUpdated() {
1005 logger.log(logger.HIGH, "Entering NeverNote.notebookIndexUpdated");
1006 if (selectedNotebookGUIDs == null)
1007 selectedNotebookGUIDs = new ArrayList<String>();
1008 List<Notebook> books = conn.getNotebookTable().getAll();
1009 for (int i=books.size()-1; i>=0; i--) {
1010 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1011 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(books.get(i).getGuid())) {
1013 j=listManager.getArchiveNotebookIndex().size();
1019 listManager.countNotebookResults(listManager.getNoteIndex());
1020 notebookTree.blockSignals(true);
1021 notebookTree.load(books, listManager.getLocalNotebooks());
1022 for (int i=selectedNotebookGUIDs.size()-1; i>=0; i--) {
1023 boolean found = notebookTree.selectGuid(selectedNotebookGUIDs.get(i));
1025 selectedNotebookGUIDs.remove(i);
1027 notebookTree.blockSignals(false);
1029 logger.log(logger.HIGH, "Leaving NeverNote.notebookIndexUpdated");
1031 // Show/Hide note information
1032 private void toggleNotebookWindow() {
1033 logger.log(logger.HIGH, "Entering NeverNote.toggleNotebookWindow");
1034 if (notebookTree.isVisible())
1035 notebookTree.hide();
1037 notebookTree.show();
1038 menuBar.hideNotebooks.setChecked(notebookTree.isVisible());
1039 Global.saveWindowVisible("notebookTree", notebookTree.isVisible());
1040 logger.log(logger.HIGH, "Leaving NeverNote.toggleNotebookWindow");
1042 // Add a new notebook
1043 @SuppressWarnings("unused")
1044 private void addNotebook() {
1045 logger.log(logger.HIGH, "Inside NeverNote.addNotebook");
1046 NotebookEdit edit = new NotebookEdit();
1047 edit.setNotebooks(listManager.getNotebookIndex());
1050 if (!edit.okPressed())
1053 Calendar currentTime = new GregorianCalendar();
1054 Long l = new Long(currentTime.getTimeInMillis());
1055 String randint = new String(Long.toString(l));
1057 Notebook newBook = new Notebook();
1058 newBook.setUpdateSequenceNum(0);
1059 newBook.setGuid(randint);
1060 newBook.setName(edit.getNotebook());
1061 newBook.setServiceCreated(new Date().getTime());
1062 newBook.setServiceUpdated(new Date().getTime());
1063 newBook.setDefaultNotebook(false);
1064 newBook.setPublished(false);
1066 listManager.getNotebookIndex().add(newBook);
1068 listManager.getLocalNotebooks().add(newBook.getGuid());
1069 conn.getNotebookTable().addNotebook(newBook, true, edit.isLocal());
1070 notebookIndexUpdated();
1071 listManager.countNotebookResults(listManager.getNoteIndex());
1072 // notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
1073 logger.log(logger.HIGH, "Leaving NeverNote.addNotebook");
1075 // Edit an existing notebook
1076 @SuppressWarnings("unused")
1077 private void editNotebook() {
1078 logger.log(logger.HIGH, "Entering NeverNote.editNotebook");
1079 NotebookEdit edit = new NotebookEdit();
1080 edit.setTitle(tr("Edit Notebook"));
1081 edit.setLocalCheckboxEnabled(false);
1082 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1083 QTreeWidgetItem currentSelection;
1084 currentSelection = selections.get(0);
1085 edit.setNotebook(currentSelection.text(0));
1086 edit.setNotebooks(listManager.getNotebookIndex());
1089 if (!edit.okPressed())
1092 String guid = currentSelection.text(2);
1093 updateListNotebookName(currentSelection.text(0), edit.getNotebook());
1094 currentSelection.setText(0, edit.getNotebook());
1096 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1097 if (listManager.getNotebookIndex().get(i).getGuid().equals(guid)) {
1098 listManager.getNotebookIndex().get(i).setName(edit.getNotebook());
1099 conn.getNotebookTable().updateNotebook(listManager.getNotebookIndex().get(i), true);
1100 i=listManager.getNotebookIndex().size();
1104 // Build a list of non-closed notebooks
1105 List<Notebook> nbooks = new ArrayList<Notebook>();
1106 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1107 boolean found=false;
1108 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1109 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
1113 nbooks.add(listManager.getNotebookIndex().get(i));
1116 browserWindow.setNotebookList(nbooks);
1117 logger.log(logger.HIGH, "Leaving NeverNote.editNotebook");
1119 // Delete an existing notebook
1120 @SuppressWarnings("unused")
1121 private void deleteNotebook() {
1122 logger.log(logger.HIGH, "Entering NeverNote.deleteNotebook");
1123 boolean assigned = false;
1124 // Check if any notes have this notebook
1125 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1126 for (int i=0; i<selections.size(); i++) {
1127 QTreeWidgetItem currentSelection;
1128 currentSelection = selections.get(i);
1129 String guid = currentSelection.text(2);
1130 for (int j=0; j<listManager.getNoteIndex().size(); j++) {
1131 String noteGuid = listManager.getNoteIndex().get(j).getNotebookGuid();
1132 if (noteGuid.equals(guid)) {
1134 j=listManager.getNoteIndex().size();
1135 i=selections.size();
1140 QMessageBox.information(this, tr("Unable to Delete"), tr("Some of the selected notebook(s) contain notes.\n"+
1141 "Please delete the notes or move them to another notebook before deleting any notebooks."));
1145 if (conn.getNotebookTable().getAll().size() == 1) {
1146 QMessageBox.information(this, tr("Unable to Delete"), tr("You must have at least one notebook."));
1150 // If all notebooks are clear, verify the delete
1151 if (QMessageBox.question(this, tr("Confirmation"), tr("Delete the selected notebooks?"),
1152 QMessageBox.StandardButton.Yes,
1153 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
1157 // If confirmed, delete the notebook
1158 for (int i=selections.size()-1; i>=0; i--) {
1159 QTreeWidgetItem currentSelection;
1160 currentSelection = selections.get(i);
1161 String guid = currentSelection.text(2);
1162 conn.getNotebookTable().expungeNotebook(guid, true);
1163 listManager.deleteNotebook(guid);
1165 // for (int i=<dbRunner.getLocalNotebooks().size()-1; i>=0; i--) {
1166 // if (dbRunner.getLocalNotebooks().get(i).equals(arg0))
1168 notebookTreeSelection();
1169 notebookTree.load(listManager.getNotebookIndex(), listManager.getLocalNotebooks());
1170 listManager.countNotebookResults(listManager.getNoteIndex());
1171 // notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
1172 logger.log(logger.HIGH, "Entering NeverNote.deleteNotebook");
1174 // A note's notebook has been updated
1175 @SuppressWarnings("unused")
1176 private void updateNoteNotebook(String guid, String notebookGuid) {
1178 // Update the list manager
1179 listManager.updateNoteNotebook(guid, notebookGuid);
1180 listManager.countNotebookResults(listManager.getNoteIndex());
1181 // notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
1183 // Find the name of the notebook
1184 String notebookName = null;
1185 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1186 if (listManager.getNotebookIndex().get(i).getGuid().equals(notebookGuid)) {
1187 notebookName = listManager.getNotebookIndex().get(i).getName();
1192 // If we found the name, update the browser window
1193 if (notebookName != null) {
1194 updateListNoteNotebook(guid, notebookName);
1195 if (guid.equals(currentNoteGuid)) {
1196 int pos = browserWindow.notebookBox.findText(notebookName);
1198 browserWindow.notebookBox.setCurrentIndex(pos);
1202 // If we're dealing with the current note, then we need to be sure and update the notebook there
1203 if (guid.equals(currentNoteGuid)) {
1204 if (currentNote != null) {
1205 currentNote.setNotebookGuid(notebookGuid);
1209 // Open/close notebooks
1210 @SuppressWarnings("unused")
1211 private void closeNotebooks() {
1212 NotebookArchive na = new NotebookArchive(listManager.getNotebookIndex(), listManager.getArchiveNotebookIndex());
1214 if (!na.okClicked())
1218 listManager.getArchiveNotebookIndex().clear();
1220 for (int i=na.getClosedBookList().count()-1; i>=0; i--) {
1221 String text = na.getClosedBookList().takeItem(i).text();
1222 for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
1223 if (listManager.getNotebookIndex().get(j).getName().equalsIgnoreCase(text)) {
1224 Notebook n = listManager.getNotebookIndex().get(j);
1225 conn.getNotebookTable().setArchived(n.getGuid(),true);
1226 listManager.getArchiveNotebookIndex().add(n);
1227 j=listManager.getNotebookIndex().size();
1232 for (int i=na.getOpenBookList().count()-1; i>=0; i--) {
1233 String text = na.getOpenBookList().takeItem(i).text();
1234 for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
1235 if (listManager.getNotebookIndex().get(j).getName().equalsIgnoreCase(text)) {
1236 Notebook n = listManager.getNotebookIndex().get(j);
1237 conn.getNotebookTable().setArchived(n.getGuid(),false);
1238 j=listManager.getNotebookIndex().size();
1242 notebookTreeSelection();
1243 listManager.loadNotesIndex();
1244 notebookIndexUpdated();
1245 noteIndexUpdated(false);
1246 // noteIndexUpdated(false);
1248 // Build a list of non-closed notebooks
1249 List<Notebook> nbooks = new ArrayList<Notebook>();
1250 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1251 boolean found=false;
1252 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1253 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
1257 nbooks.add(listManager.getNotebookIndex().get(i));
1260 browserWindow.setNotebookList(nbooks);
1267 //***************************************************************
1268 //***************************************************************
1269 //** These functions deal with Tag menu items
1270 //***************************************************************
1271 //***************************************************************
1272 // Add a new notebook
1273 @SuppressWarnings("unused")
1274 private void addTag() {
1275 logger.log(logger.HIGH, "Inside NeverNote.addTag");
1276 TagEdit edit = new TagEdit();
1277 edit.setTagList(listManager.getTagIndex());
1280 if (!edit.okPressed())
1283 Calendar currentTime = new GregorianCalendar();
1284 Long l = new Long(currentTime.getTimeInMillis());
1285 String randint = new String(Long.toString(l));
1287 Tag newTag = new Tag();
1288 newTag.setUpdateSequenceNum(0);
1289 newTag.setGuid(randint);
1290 newTag.setName(edit.getTag());
1291 conn.getTagTable().addTag(newTag, true);
1292 listManager.getTagIndex().add(newTag);
1295 logger.log(logger.HIGH, "Leaving NeverNote.addTag");
1297 private void reloadTagTree() {
1298 logger.log(logger.HIGH, "Entering NeverNote.reloadTagTree");
1299 tagIndexUpdated(false);
1300 boolean filter = false;
1301 listManager.countTagResults(listManager.getNoteIndex());
1302 if (notebookTree.selectedItems().size() > 0
1303 && !notebookTree.selectedItems().get(0).text(0).equalsIgnoreCase("All Notebooks"))
1305 if (tagTree.selectedItems().size() > 0)
1307 tagTree.showAllTags(!filter);
1308 logger.log(logger.HIGH, "Leaving NeverNote.reloadTagTree");
1310 // Edit an existing tag
1311 @SuppressWarnings("unused")
1312 private void editTag() {
1313 logger.log(logger.HIGH, "Entering NeverNote.editTag");
1314 TagEdit edit = new TagEdit();
1315 edit.setTitle("Edit Tag");
1316 List<QTreeWidgetItem> selections = tagTree.selectedItems();
1317 QTreeWidgetItem currentSelection;
1318 currentSelection = selections.get(0);
1319 edit.setTag(currentSelection.text(0));
1320 edit.setTagList(listManager.getTagIndex());
1323 if (!edit.okPressed())
1326 String guid = currentSelection.text(2);
1327 currentSelection.setText(0,edit.getTag());
1329 for (int i=0; i<listManager.getTagIndex().size(); i++) {
1330 if (listManager.getTagIndex().get(i).getGuid().equals(guid)) {
1331 listManager.getTagIndex().get(i).setName(edit.getTag());
1332 conn.getTagTable().updateTag(listManager.getTagIndex().get(i), true);
1333 updateListTagName(guid);
1334 if (currentNote != null && currentNote.getTagGuids().contains(guid))
1335 browserWindow.setTag(getTagNamesForNote(currentNote));
1336 logger.log(logger.HIGH, "Leaving NeverNote.editTag");
1340 browserWindow.setTag(getTagNamesForNote(currentNote));
1341 logger.log(logger.HIGH, "Leaving NeverNote.editTag...");
1343 // Delete an existing tag
1344 @SuppressWarnings("unused")
1345 private void deleteTag() {
1346 logger.log(logger.HIGH, "Entering NeverNote.deleteTag");
1348 if (QMessageBox.question(this, tr("Confirmation"), tr("Delete the selected tags?"),
1349 QMessageBox.StandardButton.Yes,
1350 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
1354 List<QTreeWidgetItem> selections = tagTree.selectedItems();
1355 for (int i=selections.size()-1; i>=0; i--) {
1356 QTreeWidgetItem currentSelection;
1357 currentSelection = selections.get(i);
1358 removeTagItem(currentSelection.text(2));
1360 tagIndexUpdated(true);
1362 listManager.countTagResults(listManager.getNoteIndex());
1363 // tagTree.updateCounts(listManager.getTagCounter());
1364 logger.log(logger.HIGH, "Leaving NeverNote.deleteTag");
1366 // Remove a tag tree item. Go recursively down & remove the children too
1367 private void removeTagItem(String guid) {
1368 for (int j=listManager.getTagIndex().size()-1; j>=0; j--) {
1369 String parent = listManager.getTagIndex().get(j).getParentGuid();
1370 if (parent != null && parent.equals(guid)) {
1371 //Remove this tag's children
1372 removeTagItem(listManager.getTagIndex().get(j).getGuid());
1375 //Now, remove this tag
1376 removeListTagName(guid);
1377 conn.getTagTable().expungeTag(guid, true);
1378 for (int a=0; a<listManager.getTagIndex().size(); a++) {
1379 if (listManager.getTagIndex().get(a).getGuid().equals(guid)) {
1380 listManager.getTagIndex().remove(a);
1385 // Setup the tree containing the user's tags
1386 private void initializeTagTree() {
1387 logger.log(logger.HIGH, "Entering NeverNote.initializeTagTree");
1388 tagTree.itemSelectionChanged.connect(this, "tagTreeSelection()");
1389 listManager.tagSignal.refreshTagTreeCounts.connect(tagTree, "updateCounts(List)");
1390 logger.log(logger.HIGH, "Leaving NeverNote.initializeTagTree");
1392 // Listener when a tag is selected
1393 private void tagTreeSelection() {
1394 logger.log(logger.HIGH, "Entering NeverNote.tagTreeSelection");
1397 clearAttributeFilter();
1398 clearSavedSearchFilter();
1400 menuBar.noteRestoreAction.setVisible(false);
1402 List<QTreeWidgetItem> selections = tagTree.selectedItems();
1403 QTreeWidgetItem currentSelection;
1404 selectedTagGUIDs.clear();
1405 for (int i=0; i<selections.size(); i++) {
1406 currentSelection = selections.get(i);
1407 selectedTagGUIDs.add(currentSelection.text(2));
1409 if (selections.size() > 0) {
1410 menuBar.tagEditAction.setEnabled(true);
1411 menuBar.tagDeleteAction.setEnabled(true);
1414 menuBar.tagEditAction.setEnabled(false);
1415 menuBar.tagDeleteAction.setEnabled(false);
1417 listManager.setSelectedTags(selectedTagGUIDs);
1418 listManager.loadNotesIndex();
1419 noteIndexUpdated(false);
1420 logger.log(logger.HIGH, "Leaving NeverNote.tagTreeSelection");
1422 // trigger the tag index to be refreshed
1423 @SuppressWarnings("unused")
1424 private void tagIndexUpdated() {
1425 tagIndexUpdated(true);
1427 private void tagIndexUpdated(boolean reload) {
1428 logger.log(logger.HIGH, "Entering NeverNote.tagIndexUpdated");
1429 if (selectedTagGUIDs == null)
1430 selectedTagGUIDs = new ArrayList<String>();
1431 // selectedTagGUIDs.clear(); // clear out old entries
1433 tagTree.blockSignals(true);
1435 tagTree.load(listManager.getTagIndex());
1436 for (int i=selectedTagGUIDs.size()-1; i>=0; i--) {
1437 boolean found = tagTree.selectGuid(selectedTagGUIDs.get(i));
1439 selectedTagGUIDs.remove(i);
1441 tagTree.blockSignals(false);
1443 browserWindow.setTag(getTagNamesForNote(currentNote));
1444 logger.log(logger.HIGH, "Leaving NeverNote.tagIndexUpdated");
1446 // Show/Hide note information
1447 private void toggleTagWindow() {
1448 logger.log(logger.HIGH, "Entering NeverNote.toggleTagWindow");
1449 if (tagTree.isVisible())
1453 menuBar.hideTags.setChecked(tagTree.isVisible());
1454 Global.saveWindowVisible("tagTree", tagTree.isVisible());
1455 logger.log(logger.HIGH, "Leaving NeverNote.toggleTagWindow");
1457 // A note's tags have been updated
1458 @SuppressWarnings("unused")
1459 private void updateNoteTags(String guid, List<String> tags) {
1460 // Save any new tags. We'll need them later.
1461 List<String> newTags = new ArrayList<String>();
1462 for (int i=0; i<tags.size(); i++) {
1463 if (conn.getTagTable().findTagByName(tags.get(i))==null)
1464 newTags.add(tags.get(i));
1467 listManager.saveNoteTags(guid, tags);
1468 listManager.countTagResults(listManager.getNoteIndex());
1469 StringBuffer names = new StringBuffer("");
1470 for (int i=0; i<tags.size(); i++) {
1471 names = names.append(tags.get(i));
1472 if (i<tags.size()-1) {
1473 names.append(Global.tagDelimeter + " ");
1476 browserWindow.setTag(names.toString());
1479 // Now, we need to add any new tags to the tag tree
1480 for (int i=0; i<newTags.size(); i++)
1481 tagTree.insertTag(newTags.get(i), conn.getTagTable().findTagByName(newTags.get(i)));
1483 // Get a string containing all tag names for a note
1484 private String getTagNamesForNote(Note n) {
1485 logger.log(logger.HIGH, "Entering NeverNote.getTagNamesForNote");
1486 if (n==null || n.getGuid() == null || n.getGuid().equals(""))
1488 StringBuffer buffer = new StringBuffer(100);
1489 Vector<String> v = new Vector<String>();
1490 List<String> guids = n.getTagGuids();
1495 for (int i=0; i<guids.size(); i++) {
1496 v.add(listManager.getTagNameByGuid(guids.get(i)));
1498 Comparator<String> comparator = Collections.reverseOrder();
1499 Collections.sort(v,comparator);
1500 Collections.reverse(v);
1502 for (int i = 0; i<v.size(); i++) {
1504 buffer.append(", ");
1505 buffer.append(v.get(i));
1508 logger.log(logger.HIGH, "Leaving NeverNote.getTagNamesForNote");
1509 return buffer.toString();
1511 // Tags were added via dropping notes from the note list
1512 @SuppressWarnings("unused")
1513 private void tagsAdded(String noteGuid, String tagGuid) {
1514 String tagName = null;
1515 for (int i=0; i<listManager.getTagIndex().size(); i++) {
1516 if (listManager.getTagIndex().get(i).getGuid().equals(tagGuid)) {
1517 tagName = listManager.getTagIndex().get(i).getName();
1518 i=listManager.getTagIndex().size();
1521 if (tagName == null)
1524 for (int i=0; i<listManager.getMasterNoteIndex().size(); i++) {
1525 if (listManager.getMasterNoteIndex().get(i).getGuid().equals(noteGuid)) {
1526 List<String> tagNames = new ArrayList<String>();
1527 tagNames.add(new String(tagName));
1528 Note n = listManager.getMasterNoteIndex().get(i);
1529 for (int j=0; j<n.getTagNames().size(); j++) {
1530 tagNames.add(new String(n.getTagNames().get(j)));
1532 listManager.getNoteTableModel().updateNoteTags(noteGuid, n.getTagGuids(), tagNames);
1533 if (n.getGuid().equals(currentNoteGuid)) {
1534 Collections.sort(tagNames);
1535 String display = "";
1536 for (int j=0; j<tagNames.size(); j++) {
1537 display = display+tagNames.get(j);
1538 if (j+2<tagNames.size())
1539 display = display+Global.tagDelimeter+" ";
1541 browserWindow.setTag(display);
1543 i=listManager.getMasterNoteIndex().size();
1548 listManager.getNoteTableModel().updateNoteSyncStatus(noteGuid, false);
1550 private void clearTagFilter() {
1551 tagTree.blockSignals(true);
1552 tagTree.clearSelection();
1553 menuBar.noteRestoreAction.setVisible(false);
1554 menuBar.tagEditAction.setEnabled(false);
1555 menuBar.tagDeleteAction.setEnabled(false);
1556 selectedTagGUIDs.clear();
1557 listManager.setSelectedTags(selectedTagGUIDs);
1558 tagTree.blockSignals(false);
1562 //***************************************************************
1563 //***************************************************************
1564 //** These functions deal with Saved Search menu items
1565 //***************************************************************
1566 //***************************************************************
1567 // Add a new notebook
1568 @SuppressWarnings("unused")
1569 private void addSavedSearch() {
1570 logger.log(logger.HIGH, "Inside NeverNote.addSavedSearch");
1571 SavedSearchEdit edit = new SavedSearchEdit();
1572 edit.setSearchList(listManager.getSavedSearchIndex());
1575 if (!edit.okPressed())
1578 Calendar currentTime = new GregorianCalendar();
1579 Long l = new Long(currentTime.getTimeInMillis());
1580 String randint = new String(Long.toString(l));
1582 SavedSearch search = new SavedSearch();
1583 search.setUpdateSequenceNum(0);
1584 search.setGuid(randint);
1585 search.setName(edit.getName());
1586 search.setQuery(edit.getQuery());
1587 search.setFormat(QueryFormat.USER);
1588 listManager.getSavedSearchIndex().add(search);
1589 conn.getSavedSearchTable().addSavedSearch(search, true);
1590 savedSearchIndexUpdated();
1591 logger.log(logger.HIGH, "Leaving NeverNote.addSavedSearch");
1593 // Edit an existing tag
1594 @SuppressWarnings("unused")
1595 private void editSavedSearch() {
1596 logger.log(logger.HIGH, "Entering NeverNote.editSavedSearch");
1597 SavedSearchEdit edit = new SavedSearchEdit();
1598 edit.setTitle(tr("Edit Search"));
1599 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
1600 QTreeWidgetItem currentSelection;
1601 currentSelection = selections.get(0);
1602 String guid = currentSelection.text(1);
1603 SavedSearch s = conn.getSavedSearchTable().getSavedSearch(guid);
1604 edit.setName(currentSelection.text(0));
1605 edit.setQuery(s.getQuery());
1606 edit.setSearchList(listManager.getSavedSearchIndex());
1609 if (!edit.okPressed())
1612 List<SavedSearch> list = listManager.getSavedSearchIndex();
1613 SavedSearch search = null;
1614 boolean found = false;
1615 for (int i=0; i<list.size(); i++) {
1616 search = list.get(i);
1617 if (search.getGuid().equals(guid)) {
1624 search.setName(edit.getName());
1625 search.setQuery(edit.getQuery());
1626 conn.getSavedSearchTable().updateSavedSearch(search, true);
1627 savedSearchIndexUpdated();
1628 logger.log(logger.HIGH, "Leaving NeverNote.editSavedSearch");
1630 // Delete an existing tag
1631 @SuppressWarnings("unused")
1632 private void deleteSavedSearch() {
1633 logger.log(logger.HIGH, "Entering NeverNote.deleteSavedSearch");
1635 if (QMessageBox.question(this, "Confirmation", "Delete the selected search?",
1636 QMessageBox.StandardButton.Yes,
1637 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
1641 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
1642 for (int i=selections.size()-1; i>=0; i--) {
1643 QTreeWidgetItem currentSelection;
1644 currentSelection = selections.get(i);
1645 for (int j=0; j<listManager.getSavedSearchIndex().size(); j++) {
1646 if (listManager.getSavedSearchIndex().get(j).getGuid().equals(currentSelection.text(1))) {
1647 conn.getSavedSearchTable().expungeSavedSearch(listManager.getSavedSearchIndex().get(j).getGuid(), true);
1648 listManager.getSavedSearchIndex().remove(j);
1649 j=listManager.getSavedSearchIndex().size()+1;
1652 selections.remove(i);
1654 savedSearchIndexUpdated();
1655 logger.log(logger.HIGH, "Leaving NeverNote.deleteSavedSearch");
1657 // Setup the tree containing the user's tags
1658 private void initializeSavedSearchTree() {
1659 logger.log(logger.HIGH, "Entering NeverNote.initializeSavedSearchTree");
1660 savedSearchTree.itemSelectionChanged.connect(this, "savedSearchTreeSelection()");
1661 logger.log(logger.HIGH, "Leaving NeverNote.initializeSavedSearchTree");
1663 // Listener when a tag is selected
1664 @SuppressWarnings("unused")
1665 private void savedSearchTreeSelection() {
1666 logger.log(logger.HIGH, "Entering NeverNote.savedSearchTreeSelection");
1668 clearNotebookFilter();
1671 clearAttributeFilter();
1673 String currentGuid = selectedSavedSearchGUID;
1674 menuBar.savedSearchEditAction.setEnabled(true);
1675 menuBar.savedSearchDeleteAction.setEnabled(true);
1676 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
1677 QTreeWidgetItem currentSelection;
1678 selectedSavedSearchGUID = "";
1679 for (int i=0; i<selections.size(); i++) {
1680 currentSelection = selections.get(i);
1681 if (currentSelection.text(1).equals(currentGuid)) {
1682 currentSelection.setSelected(false);
1684 selectedSavedSearchGUID = currentSelection.text(1);
1686 // i = selections.size() +1;
1689 // There is the potential for no notebooks to be selected if this
1690 // happens then we make it look like all notebooks were selecetd.
1691 // If that happens, just select the "all notebooks"
1692 if (selections.size()==0) {
1693 clearSavedSearchFilter();
1695 listManager.setSelectedSavedSearch(selectedSavedSearchGUID);
1697 logger.log(logger.HIGH, "Leaving NeverNote.savedSearchTreeSelection");
1699 private void clearSavedSearchFilter() {
1700 menuBar.savedSearchEditAction.setEnabled(false);
1701 menuBar.savedSearchDeleteAction.setEnabled(false);
1702 savedSearchTree.blockSignals(true);
1703 savedSearchTree.clearSelection();
1704 savedSearchTree.blockSignals(false);
1705 selectedSavedSearchGUID = "";
1706 searchField.setEditText("");
1707 searchPerformed = false;
1708 listManager.setSelectedSavedSearch(selectedSavedSearchGUID);
1710 // trigger the tag index to be refreshed
1711 private void savedSearchIndexUpdated() {
1712 if (selectedSavedSearchGUID == null)
1713 selectedSavedSearchGUID = new String();
1714 savedSearchTree.blockSignals(true);
1715 savedSearchTree.load(listManager.getSavedSearchIndex());
1716 savedSearchTree.selectGuid(selectedSavedSearchGUID);
1717 savedSearchTree.blockSignals(false);
1719 // trigger when the saved search selection changes
1720 @SuppressWarnings("unused")
1721 private void updateSavedSearchSelection() {
1722 logger.log(logger.HIGH, "Entering NeverNote.updateSavedSearchSelection()");
1724 menuBar.savedSearchEditAction.setEnabled(true);
1725 menuBar.savedSearchDeleteAction.setEnabled(true);
1726 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
1728 if (selections.size() > 0) {
1729 menuBar.savedSearchEditAction.setEnabled(true);
1730 menuBar.savedSearchDeleteAction.setEnabled(true);
1731 selectedSavedSearchGUID = selections.get(0).text(1);
1732 SavedSearch s = conn.getSavedSearchTable().getSavedSearch(selectedSavedSearchGUID);
1733 searchField.setEditText(s.getQuery());
1735 menuBar.savedSearchEditAction.setEnabled(false);
1736 menuBar.savedSearchDeleteAction.setEnabled(false);
1737 selectedSavedSearchGUID = "";
1738 searchField.setEditText("");
1740 searchFieldChanged();
1742 logger.log(logger.HIGH, "Leaving NeverNote.updateSavedSearchSelection()");
1746 // Show/Hide note information
1747 private void toggleSavedSearchWindow() {
1748 logger.log(logger.HIGH, "Entering NeverNote.toggleSavedSearchWindow");
1749 if (savedSearchTree.isVisible())
1750 savedSearchTree.hide();
1752 savedSearchTree.show();
1753 menuBar.hideSavedSearches.setChecked(savedSearchTree.isVisible());
1755 Global.saveWindowVisible("savedSearchTree", savedSearchTree.isVisible());
1756 logger.log(logger.HIGH, "Leaving NeverNote.toggleSavedSearchWindow");
1762 //***************************************************************
1763 //***************************************************************
1764 //** These functions deal with Help menu & tool menu items
1765 //***************************************************************
1766 //***************************************************************
1767 // Show database status
1768 @SuppressWarnings("unused")
1769 private void databaseStatus() {
1771 int dirty = conn.getNoteTable().getDirtyCount();
1772 int unindexed = conn.getNoteTable().getUnindexedCount();
1773 DatabaseStatus status = new DatabaseStatus();
1774 status.setUnsynchronized(dirty);
1775 status.setUnindexed(unindexed);
1776 status.setNoteCount(conn.getNoteTable().getNoteCount());
1777 status.setNotebookCount(listManager.getNotebookIndex().size());
1778 status.setSavedSearchCount(listManager.getSavedSearchIndex().size());
1779 status.setTagCount(listManager.getTagIndex().size());
1780 status.setResourceCount(conn.getNoteTable().noteResourceTable.getResourceCount());
1781 status.setWordCount(conn.getWordsTable().getWordCount());
1785 // Compact the database
1786 @SuppressWarnings("unused")
1787 private void compactDatabase() {
1788 logger.log(logger.HIGH, "Entering NeverNote.compactDatabase");
1789 if (QMessageBox.question(this, tr("Confirmation"), tr("This will free unused space in the database, "+
1790 "but please be aware that depending upon the size of your database this can be time consuming " +
1791 "and NeverNote will be unresponsive until it is complete. Do you wish to continue?"),
1792 QMessageBox.StandardButton.Yes,
1793 QMessageBox.StandardButton.No)==StandardButton.No.value() && Global.verifyDelete() == true) {
1796 setMessage("Compacting database.");
1798 listManager.compactDatabase();
1800 setMessage("Database compact is complete.");
1801 logger.log(logger.HIGH, "Leaving NeverNote.compactDatabase");
1803 @SuppressWarnings("unused")
1804 private void accountInformation() {
1805 logger.log(logger.HIGH, "Entering NeverNote.accountInformation");
1806 AccountDialog dialog = new AccountDialog();
1808 logger.log(logger.HIGH, "Leaving NeverNote.accountInformation");
1810 @SuppressWarnings("unused")
1811 private void releaseNotes() {
1812 logger.log(logger.HIGH, "Entering NeverNote.releaseNotes");
1813 QDialog dialog = new QDialog(this);
1814 QHBoxLayout layout = new QHBoxLayout();
1815 QTextEdit textBox = new QTextEdit();
1816 layout.addWidget(textBox);
1817 textBox.setReadOnly(true);
1818 QFile file = new QFile(Global.getFileManager().getHomeDirPath("release.txt"));
1819 if (!file.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly,
1820 QIODevice.OpenModeFlag.Text)))
1822 textBox.setText(file.readAll().toString());
1824 dialog.setWindowTitle(tr("Release Notes"));
1825 dialog.setLayout(layout);
1827 logger.log(logger.HIGH, "Leaving NeverNote.releaseNotes");
1829 // Called when user picks Log from the help menu
1830 @SuppressWarnings("unused")
1831 private void logger() {
1832 logger.log(logger.HIGH, "Entering NeverNote.logger");
1833 QDialog dialog = new QDialog(this);
1834 QHBoxLayout layout = new QHBoxLayout();
1835 QListWidget textBox = new QListWidget();
1836 layout.addWidget(textBox);
1837 textBox.addItems(emitLog);
1839 dialog.setLayout(layout);
1840 dialog.setWindowTitle(tr("Mesasge Log"));
1842 logger.log(logger.HIGH, "Leaving NeverNote.logger");
1844 // Menu option "help/about" was selected
1845 @SuppressWarnings("unused")
1846 private void about() {
1847 logger.log(logger.HIGH, "Entering NeverNote.about");
1848 QMessageBox.about(this,
1849 tr("About NeverNote"),
1850 tr("<h4><center><b>NeverNote</b></center></h4><hr><center>Version ")
1852 +tr("<hr></center>Evernote"
1853 +" Generic client.<br><br>"
1854 +"Licensed under GPL v2. <br><hr><br>"
1855 +"Evernote is copyright 2001-2010 by Evernote Corporation<br>"
1856 +"Jambi and QT are the licensed trademark of Nokia Corporation<br>"
1857 +"PDFRenderer is licened under the LGPL<br>"
1858 +"Jazzy is licened under the LGPL<br>"
1859 +"Java is a registered trademark of Sun Microsystems.<br><hr>"));
1860 logger.log(logger.HIGH, "Leaving NeverNote.about");
1862 // Hide the entire left hand side
1863 @SuppressWarnings("unused")
1864 private void toggleLeftSide() {
1867 hidden = !menuBar.hideLeftSide.isChecked();
1868 menuBar.hideLeftSide.setChecked(!hidden);
1870 if (notebookTree.isVisible() != hidden)
1871 toggleNotebookWindow();
1872 if (savedSearchTree.isVisible() != hidden)
1873 toggleSavedSearchWindow();
1874 if (tagTree.isVisible() != hidden)
1876 if (attributeTree.isVisible() != hidden)
1877 toggleAttributesWindow();
1878 if (trashTree.isVisible() != hidden)
1879 toggleTrashWindow();
1881 Global.saveWindowVisible("leftPanel", hidden);
1886 //***************************************************************
1887 //***************************************************************
1888 //** These functions deal with the Toolbar
1889 //***************************************************************
1890 //***************************************************************
1891 // Text in the search bar has been cleared
1892 private void searchFieldCleared() {
1893 searchField.setEditText("");
1894 saveNoteIndexWidth();
1896 // text in the search bar changed. We only use this to tell if it was cleared,
1897 // otherwise we trigger off searchFieldChanged.
1898 @SuppressWarnings("unused")
1899 private void searchFieldTextChanged(String text) {
1900 if (text.trim().equals("")) {
1901 searchFieldCleared();
1902 if (searchPerformed) {
1904 listManager.setEnSearch("");
1905 ///// listManager.clearNoteIndexSearch();
1906 //noteIndexUpdated(true);
1907 listManager.loadNotesIndex();
1908 refreshEvernoteNote(true);
1909 noteIndexUpdated(false);
1911 searchPerformed = false;
1914 // Text in the toolbar has changed
1915 private void searchFieldChanged() {
1916 logger.log(logger.HIGH, "Entering NeverNote.searchFieldChanged");
1918 saveNoteIndexWidth();
1919 String text = searchField.currentText();
1920 listManager.setEnSearch(text.trim());
1921 listManager.loadNotesIndex();
1922 //--->>> noteIndexUpdated(true);
1923 noteIndexUpdated(false);
1924 refreshEvernoteNote(true);
1925 searchPerformed = true;
1926 logger.log(logger.HIGH, "Leaving NeverNote.searchFieldChanged");
1928 // Build the window tool bar
1929 private void setupToolBar() {
1930 logger.log(logger.HIGH, "Entering NeverNote.setupToolBar");
1931 toolBar = addToolBar(tr("toolBar"));
1933 prevButton = toolBar.addAction("Previous");
1934 QIcon prevIcon = new QIcon(iconPath+"back.png");
1935 prevButton.setIcon(prevIcon);
1936 prevButton.triggered.connect(this, "previousViewedAction()");
1938 nextButton = toolBar.addAction("Next");
1939 QIcon nextIcon = new QIcon(iconPath+"forward.png");
1940 nextButton.setIcon(nextIcon);
1941 nextButton.triggered.connect(this, "nextViewedAction()");
1943 upButton = toolBar.addAction("Up");
1944 QIcon upIcon = new QIcon(iconPath+"up.png");
1945 upButton.setIcon(upIcon);
1946 upButton.triggered.connect(this, "upAction()");
1948 downButton = toolBar.addAction("Down");
1949 QIcon downIcon = new QIcon(iconPath+"down.png");
1950 downButton.setIcon(downIcon);
1951 downButton.triggered.connect(this, "downAction()");
1953 synchronizeButton = toolBar.addAction("Synchronize");
1954 synchronizeAnimation = new ArrayList<QIcon>();
1955 synchronizeAnimation.add(new QIcon(iconPath+"synchronize-0.png"));
1956 synchronizeAnimation.add(new QIcon(iconPath+"synchronize-1.png"));
1957 synchronizeAnimation.add(new QIcon(iconPath+"synchronize-2.png"));
1958 synchronizeAnimation.add(new QIcon(iconPath+"synchronize-3.png"));
1959 synchronizeButton.setIcon(synchronizeAnimation.get(0));
1960 synchronizeFrame = 0;
1961 synchronizeButton.triggered.connect(this, "evernoteSync()");
1963 printButton = toolBar.addAction("Print");
1964 QIcon printIcon = new QIcon(iconPath+"print.png");
1965 printButton.setIcon(printIcon);
1966 printButton.triggered.connect(this, "printNote()");
1968 tagButton = toolBar.addAction("Tag");
1969 QIcon tagIcon = new QIcon(iconPath+"tag.png");
1970 tagButton.setIcon(tagIcon);
1971 tagButton.triggered.connect(browserWindow, "modifyTags()");
1973 attributeButton = toolBar.addAction("Attributes");
1974 QIcon attributeIcon = new QIcon(iconPath+"attribute.png");
1975 attributeButton.setIcon(attributeIcon);
1976 attributeButton.triggered.connect(this, "toggleNoteInformation()");
1978 emailButton = toolBar.addAction("Email");
1979 QIcon emailIcon = new QIcon(iconPath+"email.png");
1980 emailButton.setIcon(emailIcon);
1981 emailButton.triggered.connect(this, "emailNote()");
1983 deleteButton = toolBar.addAction("Delete");
1984 QIcon deleteIcon = new QIcon(iconPath+"delete.png");
1985 deleteButton.setIcon(deleteIcon);
1986 deleteButton.triggered.connect(this, "deleteNote()");
1988 newButton = toolBar.addAction("New");
1989 QIcon newIcon = new QIcon(iconPath+"new.png");
1990 newButton.triggered.connect(this, "addNote()");
1991 newButton.setIcon(newIcon);
1992 toolBar.addSeparator();
1993 toolBar.addWidget(new QLabel(tr("Quota:")));
1994 toolBar.addWidget(quotaBar);
1995 //quotaBar.setSizePolicy(Policy.Minimum, Policy.Minimum);
1999 zoomSpinner = new QSpinBox();
2000 zoomSpinner.setMinimum(10);
2001 zoomSpinner.setMaximum(1000);
2002 zoomSpinner.setAccelerated(true);
2003 zoomSpinner.setSingleStep(10);
2004 zoomSpinner.setValue(100);
2005 zoomSpinner.valueChanged.connect(this, "zoomChanged()");
2006 toolBar.addWidget(new QLabel(tr("Zoom")));
2007 toolBar.addWidget(zoomSpinner);
2009 //toolBar.addWidget(new QLabel(" "));
2010 toolBar.addSeparator();
2011 toolBar.addWidget(new QLabel(tr(" Search:")));
2012 toolBar.addWidget(searchField);
2013 QSizePolicy sizePolicy = new QSizePolicy();
2014 sizePolicy.setHorizontalPolicy(Policy.MinimumExpanding);
2015 searchField.setSizePolicy(sizePolicy);
2016 searchField.setInsertPolicy(InsertPolicy.InsertAtTop);
2018 searchClearButton = toolBar.addAction("Search Clear");
2019 QIcon searchClearIcon = new QIcon(iconPath+"searchclear.png");
2020 searchClearButton.setIcon(searchClearIcon);
2021 searchClearButton.triggered.connect(this, "searchFieldCleared()");
2023 logger.log(logger.HIGH, "Leaving NeverNote.setupToolBar");
2025 // Update the sychronize button picture
2026 @SuppressWarnings("unused")
2027 private void updateSyncButton() {
2029 if (synchronizeFrame == 4)
2030 synchronizeFrame = 0;
2031 synchronizeButton.setIcon(synchronizeAnimation.get(synchronizeFrame));
2033 // Synchronize with Evernote
2034 @SuppressWarnings("unused")
2035 private void evernoteSync() {
2036 logger.log(logger.HIGH, "Entering NeverNote.evernoteSync");
2037 if (!Global.isConnected)
2039 if (Global.isConnected)
2040 synchronizeAnimationTimer.start(200);
2042 logger.log(logger.HIGH, "Leaving NeverNote.evernoteSync");
2044 private void updateQuotaBar() {
2045 long limit = Global.getUploadLimit();
2046 long amount = Global.getUploadAmount();
2047 if (amount>0 && limit>0) {
2048 int percent =(int)(amount*100/limit);
2049 quotaBar.setValue(percent);
2051 quotaBar.setValue(0);
2054 @SuppressWarnings("unused")
2055 private void zoomChanged() {
2056 browserWindow.getBrowser().setZoomFactor(new Double(zoomSpinner.value())/100);
2059 //****************************************************************
2060 //****************************************************************
2061 //* System Tray functions
2062 //****************************************************************
2063 //****************************************************************
2064 private void trayToggleVisible() {
2072 @SuppressWarnings("unused")
2073 private void trayActivated(QSystemTrayIcon.ActivationReason reason) {
2074 if (reason == QSystemTrayIcon.ActivationReason.DoubleClick) {
2075 String name = QSystemTrayIcon.MessageIcon.resolve(reason.value()).name();
2076 trayToggleVisible();
2081 //***************************************************************
2082 //***************************************************************
2083 //** These functions deal with the trash tree
2084 //***************************************************************
2085 //***************************************************************
2086 // Setup the tree containing the trash.
2087 @SuppressWarnings("unused")
2088 private void trashTreeSelection() {
2089 logger.log(logger.HIGH, "Entering NeverNote.trashTreeSelection");
2091 clearNotebookFilter();
2093 clearAttributeFilter();
2094 clearSavedSearchFilter();
2096 String tempGuid = currentNoteGuid;
2098 // currentNoteGuid = "";
2099 currentNote = new Note();
2100 selectedNoteGUIDs.clear();
2101 listManager.getSelectedNotebooks().clear();
2102 listManager.getSelectedTags().clear();
2103 listManager.setSelectedSavedSearch("");
2104 browserWindow.clear();
2106 // toggle the add buttons
2107 newButton.setEnabled(!newButton.isEnabled());
2108 menuBar.noteAdd.setEnabled(newButton.isEnabled());
2109 menuBar.noteAdd.setVisible(true);
2111 List<QTreeWidgetItem> selections = trashTree.selectedItems();
2112 if (selections.size() == 0) {
2113 currentNoteGuid = trashNoteGuid;
2114 trashNoteGuid = tempGuid;
2115 Global.showDeleted = false;
2116 menuBar.noteRestoreAction.setEnabled(false);
2117 menuBar.noteRestoreAction.setVisible(false);
2120 currentNoteGuid = trashNoteGuid;
2121 trashNoteGuid = tempGuid;
2122 menuBar.noteRestoreAction.setEnabled(true);
2123 menuBar.noteRestoreAction.setVisible(true);
2124 Global.showDeleted = true;
2126 listManager.loadNotesIndex();
2127 noteIndexUpdated(false);
2128 //// browserWindow.setEnabled(newButton.isEnabled());
2129 browserWindow.setReadOnly(!newButton.isEnabled());
2130 logger.log(logger.HIGH, "Leaving NeverNote.trashTreeSelection");
2132 // Empty the trash file
2133 @SuppressWarnings("unused")
2134 private void emptyTrash() {
2135 // browserWindow.clear();
2136 listManager.emptyTrash();
2137 if (trashTree.selectedItems().size() > 0) {
2138 listManager.getSelectedNotebooks().clear();
2139 listManager.getSelectedTags().clear();
2140 listManager.setSelectedSavedSearch("");
2141 newButton.setEnabled(!newButton.isEnabled());
2142 menuBar.noteAdd.setEnabled(newButton.isEnabled());
2143 menuBar.noteAdd.setVisible(true);
2144 browserWindow.clear();
2147 clearNotebookFilter();
2148 clearSavedSearchFilter();
2149 clearAttributeFilter();
2151 Global.showDeleted = false;
2152 menuBar.noteRestoreAction.setEnabled(false);
2153 menuBar.noteRestoreAction.setVisible(false);
2155 listManager.loadNotesIndex();
2156 //--->>> noteIndexUpdated(true);
2157 noteIndexUpdated(false);
2160 // Show/Hide trash window
2161 private void toggleTrashWindow() {
2162 logger.log(logger.HIGH, "Entering NeverNote.toggleTrashWindow");
2163 if (trashTree.isVisible())
2167 menuBar.hideTrash.setChecked(trashTree.isVisible());
2169 Global.saveWindowVisible("trashTree", trashTree.isVisible());
2170 logger.log(logger.HIGH, "Leaving NeverNote.trashWindow");
2172 private void clearTrashFilter() {
2173 Global.showDeleted = false;
2174 newButton.setEnabled(true);
2175 menuBar.noteAdd.setEnabled(true);
2176 menuBar.noteAdd.setVisible(true);
2177 trashTree.blockSignals(true);
2178 trashTree.clearSelection();
2179 trashTree.blockSignals(false);
2184 //***************************************************************
2185 //***************************************************************
2186 //** These functions deal with connection settings
2187 //***************************************************************
2188 //***************************************************************
2189 // SyncRunner had a problem and things are disconnected
2190 @SuppressWarnings("unused")
2191 private void remoteErrorDisconnect() {
2192 menuBar.connectAction.setText(tr("Connect"));
2193 menuBar.connectAction.setToolTip(tr("Connect to Evernote"));
2194 menuBar.synchronizeAction.setEnabled(false);
2195 synchronizeAnimationTimer.stop();
2198 // Do a manual connect/disconnect
2199 private void remoteConnect() {
2200 logger.log(logger.HIGH, "Entering NeverNote.remoteConnect");
2202 if (Global.isConnected) {
2203 Global.isConnected = false;
2204 syncRunner.enDisconnect();
2205 setupConnectMenuOptions();
2210 AESEncrypter aes = new AESEncrypter();
2212 aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("secure.txt")));
2213 } catch (FileNotFoundException e) {
2214 // File not found, so we'll just get empty strings anyway.
2216 String userid = aes.getUserid();
2217 String password = aes.getPassword();
2218 if (!userid.equals("") && !password.equals("")) {
2219 Global.username = userid;
2220 Global.password = password;
2223 // Show the login dialog box
2224 if (!Global.automaticLogin() || userid.equals("")|| password.equals("")) {
2225 LoginDialog login = new LoginDialog();
2228 if (!login.okPressed()) {
2232 Global.username = login.getUserid();
2233 Global.password = login.getPassword();
2235 syncRunner.username = Global.username;
2236 syncRunner.password = Global.password;
2237 syncRunner.userStoreUrl = Global.userStoreUrl;
2238 syncRunner.noteStoreUrl = Global.noteStoreUrl;
2239 syncRunner.noteStoreUrlBase = Global.noteStoreUrlBase;
2240 syncRunner.enConnect();
2241 Global.isConnected = syncRunner.isConnected;
2243 setupConnectMenuOptions();
2244 logger.log(logger.HIGH, "Leaving NeverNote.remoteConnect");
2246 private void setupConnectMenuOptions() {
2247 logger.log(logger.HIGH, "entering NeverNote.setupConnectMenuOptions");
2248 if (!Global.isConnected) {
2249 menuBar.connectAction.setText(tr("Connect"));
2250 menuBar.connectAction.setToolTip(tr("Connect to Evernote"));
2251 menuBar.synchronizeAction.setEnabled(false);
2253 menuBar.connectAction.setText(tr("Disconnect"));
2254 menuBar.connectAction.setToolTip(tr("Disconnect from Evernote"));
2255 menuBar.synchronizeAction.setEnabled(true);
2257 logger.log(logger.HIGH, "Leaving NeverNote.setupConnectionMenuOptions");
2262 //***************************************************************
2263 //***************************************************************
2264 //** These functions deal with the GUI Attribute tree
2265 //***************************************************************
2266 //***************************************************************
2267 @SuppressWarnings("unused")
2268 private void attributeTreeClicked(QTreeWidgetItem item, Integer integer) {
2271 clearNotebookFilter();
2273 clearSavedSearchFilter();
2275 if (attributeTreeSelected == null || item.nativeId() != attributeTreeSelected.nativeId()) {
2276 if (item.childCount() > 0) {
2277 item.setSelected(false);
2279 Global.createdBeforeFilter.reset();
2280 Global.createdSinceFilter.reset();
2281 Global.changedBeforeFilter.reset();
2282 Global.changedSinceFilter.reset();
2283 Global.containsFilter.reset();
2284 attributeTreeSelected = item;
2285 DateAttributeFilterTable f = null;
2286 f = findDateAttributeFilterTable(item.parent());
2288 f.select(item.parent().indexOfChild(item));
2290 Global.containsFilter.select(item.parent().indexOfChild(item));
2293 listManager.loadNotesIndex();
2294 noteIndexUpdated(false);
2297 attributeTreeSelected = null;
2298 item.setSelected(false);
2299 Global.createdBeforeFilter.reset();
2300 Global.createdSinceFilter.reset();
2301 Global.changedBeforeFilter.reset();
2302 Global.changedSinceFilter.reset();
2303 Global.containsFilter.reset();
2304 listManager.loadNotesIndex();
2305 noteIndexUpdated(false);
2307 // This determines what attribute filter we need, depending upon the selection
2308 private DateAttributeFilterTable findDateAttributeFilterTable(QTreeWidgetItem w) {
2309 if (w.parent() != null && w.childCount() > 0) {
2310 QTreeWidgetItem parent = w.parent();
2311 if (parent.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Created &&
2312 w.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Since)
2313 return Global.createdSinceFilter;
2314 if (parent.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Created &&
2315 w.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Before)
2316 return Global.createdBeforeFilter;
2317 if (parent.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.LastModified &&
2318 w.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Since)
2319 return Global.changedSinceFilter;
2320 if (parent.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.LastModified &&
2321 w.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Before)
2322 return Global.changedBeforeFilter;
2327 // Show/Hide attribute search window
2328 private void toggleAttributesWindow() {
2329 logger.log(logger.HIGH, "Entering NeverNote.toggleAttributesWindow");
2330 if (attributeTree.isVisible())
2331 attributeTree.hide();
2333 attributeTree.show();
2334 menuBar.hideAttributes.setChecked(attributeTree.isVisible());
2336 Global.saveWindowVisible("attributeTree", attributeTree.isVisible());
2337 logger.log(logger.HIGH, "Leaving NeverNote.toggleAttributeWindow");
2339 private void clearAttributeFilter() {
2340 Global.createdBeforeFilter.reset();
2341 Global.createdSinceFilter.reset();
2342 Global.changedBeforeFilter.reset();
2343 Global.changedSinceFilter.reset();
2344 Global.containsFilter.reset();
2345 attributeTreeSelected = null;
2346 attributeTree.blockSignals(true);
2347 attributeTree.clearSelection();
2348 attributeTree.blockSignals(false);
2352 //***************************************************************
2353 //***************************************************************
2354 //** These functions deal with the GUI Note index table
2355 //***************************************************************
2356 //***************************************************************
2357 // Initialize the note list table
2358 private void initializeNoteTable() {
2359 logger.log(logger.HIGH, "Entering NeverNote.initializeNoteTable");
2360 noteTableView.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection);
2361 noteTableView.selectionModel().selectionChanged.connect(this, "noteTableSelection()");
2362 logger.log(logger.HIGH, "Leaving NeverNote.initializeNoteTable");
2364 // Show/Hide trash window
2365 @SuppressWarnings("unused")
2366 private void toggleNoteListWindow() {
2367 logger.log(logger.HIGH, "Entering NeverNote.toggleNoteListWindow");
2368 if (noteTableView.isVisible())
2369 noteTableView.hide();
2371 noteTableView.show();
2372 menuBar.hideNoteList.setChecked(noteTableView.isVisible());
2374 Global.saveWindowVisible("noteList", noteTableView.isVisible());
2375 logger.log(logger.HIGH, "Leaving NeverNote.toggleNoteListWindow");
2377 // Handle the event that a user selects a note from the table
2378 @SuppressWarnings("unused")
2379 private void noteTableSelection() {
2380 logger.log(logger.HIGH, "Entering NeverNote.noteTableSelection");
2382 if (historyGuids.size() == 0) {
2383 historyGuids.add(currentNoteGuid);
2384 historyPosition = 1;
2386 noteTableView.showColumn(Global.noteTableGuidPosition);
2388 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
2389 noteTableView.hideColumn(Global.noteTableGuidPosition);
2391 if (selections.size() > 0) {
2393 menuBar.noteDuplicateAction.setEnabled(true);
2394 menuBar.noteOnlineHistoryAction.setEnabled(true);
2395 menuBar.noteMergeAction.setEnabled(true);
2396 selectedNoteGUIDs.clear();
2397 if (selections.size() != 1 || Global.showDeleted) {
2398 menuBar.noteDuplicateAction.setEnabled(false);
2400 if (selections.size() != 1 || !Global.isConnected) {
2401 menuBar.noteOnlineHistoryAction.setEnabled(false);
2403 if (selections.size() == 1) {
2404 menuBar.noteMergeAction.setEnabled(false);
2406 for (int i=0; i<selections.size(); i++) {
2407 int row = selections.get(i).row();
2409 upButton.setEnabled(false);
2411 upButton.setEnabled(true);
2412 if (row < listManager.getNoteTableModel().rowCount()-1)
2413 downButton.setEnabled(true);
2415 downButton.setEnabled(false);
2416 index = noteTableView.proxyModel.index(row, Global.noteTableGuidPosition);
2417 SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(index);
2418 currentNoteGuid = (String)ix.values().toArray()[0];
2419 selectedNoteGUIDs.add(currentNoteGuid);
2423 nextButton.setEnabled(true);
2424 prevButton.setEnabled(true);
2426 int endPosition = historyGuids.size()-1;
2427 for (int j=historyPosition; j<=endPosition; j++) {
2428 historyGuids.remove(historyGuids.size()-1);
2430 historyGuids.add(currentNoteGuid);
2431 historyPosition = historyGuids.size();
2433 if (historyPosition <= 1)
2434 prevButton.setEnabled(false);
2435 if (historyPosition == historyGuids.size())
2436 nextButton.setEnabled(false);
2438 fromHistory = false;
2439 scrollToGuid(currentNoteGuid);
2440 refreshEvernoteNote(true);
2441 logger.log(logger.HIGH, "Leaving NeverNote.noteTableSelection");
2443 // Trigger a refresh when the note db has been updated
2444 private void noteIndexUpdated(boolean reload) {
2445 logger.log(logger.HIGH, "Entering NeverNote.noteIndexUpdated");
2447 refreshEvernoteNoteList();
2448 logger.log(logger.HIGH, "Calling note table reload in NeverNote.noteIndexUpdated() - "+reload);
2449 noteTableView.load(reload);
2450 scrollToGuid(currentNoteGuid);
2451 logger.log(logger.HIGH, "Leaving NeverNote.noteIndexUpdated");
2453 // Called when the list of notes is updated
2454 private void refreshEvernoteNoteList() {
2455 logger.log(logger.HIGH, "Entering NeverNote.refreshEvernoteNoteList");
2456 browserWindow.setDisabled(false);
2457 if (selectedNoteGUIDs == null)
2458 selectedNoteGUIDs = new ArrayList<String>();
2459 selectedNoteGUIDs.clear(); // clear out old entries
2461 String saveCurrentNoteGuid = new String();
2462 String tempNoteGuid = new String();
2464 historyGuids.clear();
2465 historyPosition = 0;
2466 prevButton.setEnabled(false);
2467 nextButton.setEnabled(false);
2469 if (currentNoteGuid == null)
2470 currentNoteGuid = new String();
2472 for (Note note : listManager.getNoteIndex()) {
2473 tempNoteGuid = note.getGuid();
2474 if (currentNoteGuid.equals(tempNoteGuid)) {
2475 saveCurrentNoteGuid = new String(tempNoteGuid);
2479 if (listManager.getNoteIndex().size() == 0) {
2480 currentNoteGuid = "";
2482 browserWindow.clear();
2483 browserWindow.setDisabled(true);
2486 if (saveCurrentNoteGuid.equals("") && listManager.getNoteIndex().size() >0) {
2487 currentNoteGuid = listManager.getNoteIndex().get(listManager.getNoteIndex().size()-1).getGuid();
2488 currentNote = listManager.getNoteIndex().get(listManager.getNoteIndex().size()-1);
2489 refreshEvernoteNote(true);
2491 refreshEvernoteNote(false);
2495 logger.log(logger.HIGH, "Leaving NeverNote.refreshEvernoteNoteList");
2497 // Called when the previous arrow button is clicked
2498 @SuppressWarnings("unused")
2499 private void previousViewedAction() {
2500 if (!prevButton.isEnabled())
2502 if (historyPosition == 0)
2505 if (historyPosition <= 0)
2507 String historyGuid = historyGuids.get(historyPosition-1);
2509 for (int i=0; i<noteTableView.model().rowCount(); i++) {
2510 QModelIndex modelIndex = noteTableView.model().index(i, Global.noteTableGuidPosition);
2511 if (modelIndex != null) {
2512 SortedMap<Integer, Object> ix = noteTableView.model().itemData(modelIndex);
2513 String tableGuid = (String)ix.values().toArray()[0];
2514 if (tableGuid.equals(historyGuid)) {
2515 noteTableView.selectRow(i);
2521 @SuppressWarnings("unused")
2522 private void nextViewedAction() {
2523 if (!nextButton.isEnabled())
2525 String historyGuid = historyGuids.get(historyPosition);
2528 for (int i=0; i<noteTableView.model().rowCount(); i++) {
2529 QModelIndex modelIndex = noteTableView.model().index(i, Global.noteTableGuidPosition);
2530 if (modelIndex != null) {
2531 SortedMap<Integer, Object> ix = noteTableView.model().itemData(modelIndex);
2532 String tableGuid = (String)ix.values().toArray()[0];
2533 if (tableGuid.equals(historyGuid)) {
2534 noteTableView.selectRow(i);
2540 // Called when the up arrow is clicked
2541 @SuppressWarnings("unused")
2542 private void upAction() {
2543 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
2544 int row = selections.get(0).row();
2546 noteTableView.selectRow(row-1);
2549 // Called when the down arrow is clicked
2550 @SuppressWarnings("unused")
2551 private void downAction() {
2552 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
2553 int row = selections.get(0).row();
2554 int max = listManager.getNoteTableModel().rowCount();
2556 noteTableView.selectRow(row+1);
2559 // Update a tag string for a specific note in the list
2560 @SuppressWarnings("unused")
2561 private void updateListTags(String guid, List<String> tags) {
2562 logger.log(logger.HIGH, "Entering NeverNote.updateListTags");
2563 StringBuffer tagBuffer = new StringBuffer();
2564 for (int i=0; i<tags.size(); i++) {
2565 tagBuffer.append(tags.get(i));
2566 if (i<tags.size()-1)
2567 tagBuffer.append(", ");
2570 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2571 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2572 if (modelIndex != null) {
2573 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2574 String tableGuid = (String)ix.values().toArray()[0];
2575 if (tableGuid.equals(guid)) {
2576 listManager.getNoteTableModel().setData(i, Global.noteTableTagPosition,tagBuffer.toString());
2577 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2582 logger.log(logger.HIGH, "Leaving NeverNote.updateListTags");
2584 // Update a title for a specific note in the list
2585 @SuppressWarnings("unused")
2586 private void updateListAuthor(String guid, String author) {
2587 logger.log(logger.HIGH, "Entering NeverNote.updateListAuthor");
2589 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2590 //QModelIndex modelIndex = noteTableView.proxyModel.index(i, Global.noteTableGuidPosition);
2591 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2592 if (modelIndex != null) {
2593 // SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(modelIndex);
2594 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2595 String tableGuid = (String)ix.values().toArray()[0];
2596 if (tableGuid.equals(guid)) {
2597 listManager.getNoteTableModel().setData(i, Global.noteTableAuthorPosition,author);
2598 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2603 logger.log(logger.HIGH, "Leaving NeverNote.updateListAuthor");
2605 private void updateListNoteNotebook(String guid, String notebook) {
2606 logger.log(logger.HIGH, "Entering NeverNote.updateListNoteNotebook");
2607 listManager.getNoteTableModel().updateNoteSyncStatus(guid, false);
2608 logger.log(logger.HIGH, "Leaving NeverNote.updateListNoteNotebook");
2610 // Update a title for a specific note in the list
2611 @SuppressWarnings("unused")
2612 private void updateListSourceUrl(String guid, String url) {
2613 logger.log(logger.HIGH, "Entering NeverNote.updateListAuthor");
2615 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2616 //QModelIndex modelIndex = noteTableView.proxyModel.index(i, Global.noteTableGuidPosition);
2617 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2618 if (modelIndex != null) {
2619 // SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(modelIndex);
2620 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2621 String tableGuid = (String)ix.values().toArray()[0];
2622 if (tableGuid.equals(guid)) {
2623 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2624 listManager.getNoteTableModel().setData(i, Global.noteTableSourceUrlPosition,url);
2629 logger.log(logger.HIGH, "Leaving NeverNote.updateListAuthor");
2631 private void updateListGuid(String oldGuid, String newGuid) {
2632 logger.log(logger.HIGH, "Entering NeverNote.updateListTitle");
2634 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2635 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2636 if (modelIndex != null) {
2637 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2638 String tableGuid = (String)ix.values().toArray()[0];
2639 if (tableGuid.equals(oldGuid)) {
2640 listManager.getNoteTableModel().setData(i, Global.noteTableGuidPosition,newGuid);
2641 //listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2646 logger.log(logger.HIGH, "Leaving NeverNote.updateListTitle");
2648 private void updateListTagName(String guid) {
2649 logger.log(logger.HIGH, "Entering NeverNote.updateTagName");
2651 for (int j=0; j<listManager.getNoteIndex().size(); j++) {
2652 if (listManager.getNoteIndex().get(j).getTagGuids().contains(guid)) {
2653 String newName = listManager.getTagNamesForNote(listManager.getNoteIndex().get(j));
2655 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2656 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2657 if (modelIndex != null) {
2658 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2659 String noteGuid = (String)ix.values().toArray()[0];
2660 if (noteGuid.equalsIgnoreCase(listManager.getNoteIndex().get(j).getGuid())) {
2661 listManager.getNoteTableModel().setData(i, Global.noteTableTagPosition, newName);
2662 //listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2663 i=listManager.getNoteTableModel().rowCount();
2669 logger.log(logger.HIGH, "Leaving NeverNote.updateListNotebook");
2671 private void removeListTagName(String guid) {
2672 logger.log(logger.HIGH, "Entering NeverNote.updateTagName");
2674 for (int j=0; j<listManager.getNoteIndex().size(); j++) {
2675 if (listManager.getNoteIndex().get(j).getTagGuids().contains(guid)) {
2676 for (int i=listManager.getNoteIndex().get(j).getTagGuids().size()-1; i>=0; i--) {
2677 if (listManager.getNoteIndex().get(j).getTagGuids().get(i).equals(guid))
2678 listManager.getNoteIndex().get(j).getTagGuids().remove(i);
2681 String newName = listManager.getTagNamesForNote(listManager.getNoteIndex().get(j));
2682 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2683 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2684 if (modelIndex != null) {
2685 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2686 String noteGuid = (String)ix.values().toArray()[0];
2687 if (noteGuid.equalsIgnoreCase(listManager.getNoteIndex().get(j).getGuid())) {
2688 listManager.getNoteTableModel().setData(i, Global.noteTableTagPosition, newName);
2689 // listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2690 i=listManager.getNoteTableModel().rowCount();
2696 logger.log(logger.HIGH, "Leaving NeverNote.updateListNotebook");
2698 private void updateListNotebookName(String oldName, String newName) {
2699 logger.log(logger.HIGH, "Entering NeverNote.updateListNotebookName");
2701 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2702 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableNotebookPosition);
2703 if (modelIndex != null) {
2704 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2705 String tableName = (String)ix.values().toArray()[0];
2706 if (tableName.equalsIgnoreCase(oldName)) {
2707 // listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2708 listManager.getNoteTableModel().setData(i, Global.noteTableNotebookPosition, newName);
2712 logger.log(logger.HIGH, "Leaving NeverNote.updateListNotebookName");
2714 @SuppressWarnings("unused")
2715 private void updateListDateCreated(String guid, QDateTime date) {
2716 logger.log(logger.HIGH, "Entering NeverNote.updateListDateCreated");
2718 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2719 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2720 if (modelIndex != null) {
2721 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2722 String tableGuid = (String)ix.values().toArray()[0];
2723 if (tableGuid.equals(guid)) {
2724 listManager.getNoteTableModel().setData(i, Global.noteTableCreationPosition, date.toString(Global.getDateFormat()+" " +Global.getTimeFormat()));
2729 logger.log(logger.HIGH, "Leaving NeverNote.updateListDateCreated");
2731 @SuppressWarnings("unused")
2732 private void updateListDateSubject(String guid, QDateTime date) {
2733 logger.log(logger.HIGH, "Entering NeverNote.updateListDateSubject");
2735 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2736 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2737 if (modelIndex != null) {
2738 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2739 String tableGuid = (String)ix.values().toArray()[0];
2740 if (tableGuid.equals(guid)) {
2741 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2742 listManager.getNoteTableModel().setData(i, Global.noteTableSubjectDatePosition, date.toString(Global.getDateFormat()+" " +Global.getTimeFormat()));
2747 logger.log(logger.HIGH, "Leaving NeverNote.updateListDateCreated");
2749 @SuppressWarnings("unused")
2750 private void updateListDateChanged(String guid, QDateTime date) {
2751 logger.log(logger.HIGH, "Entering NeverNote.updateListDateChanged");
2753 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2754 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2755 if (modelIndex != null) {
2756 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2757 String tableGuid = (String)ix.values().toArray()[0];
2758 if (tableGuid.equals(guid)) {
2759 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2760 listManager.getNoteTableModel().setData(i, Global.noteTableChangedPosition, date.toString(Global.getDateFormat()+" " +Global.getTimeFormat()));
2765 logger.log(logger.HIGH, "Leaving NeverNote.updateListDateChanged");
2767 private void updateListDateChanged() {
2768 logger.log(logger.HIGH, "Entering NeverNote.updateListDateChanged");
2769 QDateTime date = new QDateTime(QDateTime.currentDateTime());
2770 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2771 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2772 if (modelIndex != null) {
2773 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2774 String tableGuid = (String)ix.values().toArray()[0];
2775 if (tableGuid.equals(currentNoteGuid)) {
2776 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2777 listManager.getNoteTableModel().setData(i, Global.noteTableChangedPosition, date.toString(Global.getDateFormat()+" " +Global.getTimeFormat()));
2782 logger.log(logger.HIGH, "Leaving NeverNote.updateListDateChanged");
2785 @SuppressWarnings("unused")
2786 private void scrollToCurrentGuid() {
2787 //scrollToGuid(currentNoteGuid);
2788 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
2789 if (selections.size() == 0)
2791 QModelIndex index = selections.get(0);
2792 int row = selections.get(0).row();
2793 String guid = (String)index.model().index(row, Global.noteTableGuidPosition).data();
2796 // Scroll to a particular index item
2797 private void scrollToGuid(String guid) {
2798 if (currentNote == null || guid == null)
2800 if (currentNote.isActive() && Global.showDeleted) {
2801 for (int i=0; i<listManager.getNoteIndex().size(); i++) {
2802 if (!listManager.getNoteIndex().get(i).isActive()) {
2803 currentNote = listManager.getNoteIndex().get(i);
2804 currentNoteGuid = currentNote.getGuid();
2805 i = listManager.getNoteIndex().size();
2810 if (!currentNote.isActive() && !Global.showDeleted) {
2811 for (int i=0; i<listManager.getNoteIndex().size(); i++) {
2812 if (listManager.getNoteIndex().get(i).isActive()) {
2813 currentNote = listManager.getNoteIndex().get(i);
2814 currentNoteGuid = currentNote.getGuid();
2815 i = listManager.getNoteIndex().size();
2821 for (int i=0; i<noteTableView.model().rowCount(); i++) {
2822 index = noteTableView.model().index(i, Global.noteTableGuidPosition);
2823 if (currentNoteGuid.equals(index.data())) {
2824 // noteTableView.setCurrentIndex(index);
2825 noteTableView.selectRow(i);
2826 noteTableView.scrollTo(index, ScrollHint.EnsureVisible); // This should work, but it doesn't
2827 i=listManager.getNoteTableModel().rowCount();
2831 // Show/Hide columns
2832 private void showColumns() {
2833 noteTableView.setColumnHidden(Global.noteTableCreationPosition, !Global.isColumnVisible("dateCreated"));
2834 noteTableView.setColumnHidden(Global.noteTableChangedPosition, !Global.isColumnVisible("dateChanged"));
2835 noteTableView.setColumnHidden(Global.noteTableSubjectDatePosition, !Global.isColumnVisible("dateSubject"));
2836 noteTableView.setColumnHidden(Global.noteTableAuthorPosition, !Global.isColumnVisible("author"));
2837 noteTableView.setColumnHidden(Global.noteTableSourceUrlPosition, !Global.isColumnVisible("sourceUrl"));
2838 noteTableView.setColumnHidden(Global.noteTableTagPosition, !Global.isColumnVisible("tags"));
2839 noteTableView.setColumnHidden(Global.noteTableNotebookPosition, !Global.isColumnVisible("notebook"));
2840 noteTableView.setColumnHidden(Global.noteTableSynchronizedPosition, !Global.isColumnVisible("synchronized"));
2842 // Open a separate window
2843 @SuppressWarnings("unused")
2844 private void listDoubleClick() {
2847 // Title color has changed
2848 @SuppressWarnings("unused")
2849 private void titleColorChanged(Integer color) {
2850 logger.log(logger.HIGH, "Entering NeverNote.updateListAuthor");
2852 QColor backgroundColor = new QColor();
2853 QColor foregroundColor = new QColor(QColor.black);
2854 backgroundColor.setRgb(color);
2856 if (backgroundColor.rgb() == QColor.black.rgb() || backgroundColor.rgb() == QColor.blue.rgb())
2857 foregroundColor.setRgb(QColor.white.rgb());
2859 if (selectedNoteGUIDs.size() == 0)
2860 selectedNoteGUIDs.add(currentNoteGuid);
2862 for (int j=0; j<selectedNoteGUIDs.size(); j++) {
2863 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2864 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2865 if (modelIndex != null) {
2866 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2867 String tableGuid = (String)ix.values().toArray()[0];
2868 if (tableGuid.equals(selectedNoteGUIDs.get(j))) {
2869 for (int k=0; k<Global.noteTableColumnCount; k++) {
2870 listManager.getNoteTableModel().setData(i, k, backgroundColor, Qt.ItemDataRole.BackgroundRole);
2871 listManager.getNoteTableModel().setData(i, k, foregroundColor, Qt.ItemDataRole.ForegroundRole);
2872 listManager.updateNoteTitleColor(selectedNoteGUIDs.get(j), backgroundColor.rgb());
2874 i=listManager.getNoteTableModel().rowCount();
2879 logger.log(logger.HIGH, "Leaving NeverNote.updateListAuthor");
2883 //***************************************************************
2884 //***************************************************************
2885 //** These functions deal with Note specific things
2886 //***************************************************************
2887 //***************************************************************
2888 @SuppressWarnings("unused")
2889 private void setNoteDirty() {
2890 logger.log(logger.EXTREME, "Entering NeverNote.setNoteDirty()");
2892 // If the note is dirty, then it is unsynchronized by default.
2896 // Set the note as dirty and check if its status is synchronized in the display table
2898 for (int i=0; i<listManager.getUnsynchronizedNotes().size(); i++) {
2899 if (listManager.getUnsynchronizedNotes().get(i).equals(currentNoteGuid))
2903 // If this wasn't already marked as unsynchronized, then we need to update the table
2904 listManager.getNoteTableModel().updateNoteSyncStatus(currentNoteGuid, false);
2905 /* listManager.getUnsynchronizedNotes().add(currentNoteGuid);
2906 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
2907 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
2908 if (modelIndex != null) {
2909 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
2910 String tableGuid = (String)ix.values().toArray()[0];
2911 if (tableGuid.equals(currentNoteGuid)) {
2912 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
2918 logger.log(logger.EXTREME, "Leaving NeverNote.setNoteDirty()");
2920 private void saveNote() {
2921 logger.log(logger.EXTREME, "Inside NeverNote.saveNote()");
2923 logger.log(logger.EXTREME, "Note is dirty.");
2926 preview = new Thumbnailer(currentNoteGuid, new QSize(1024,768));
2927 preview.finished.connect(this, "saveThumbnail(String)");
2928 preview.setContent(browserWindow.getContent());
2930 logger.log(logger.EXTREME, "Saving to cache");
2931 QTextCodec codec = QTextCodec.codecForLocale();
2932 // QTextDecoder decoder = codec.makeDecoder();
2933 codec = QTextCodec.codecForName("UTF-8");
2934 QByteArray unicode = codec.fromUnicode(browserWindow.getContent());
2935 noteCache.put(currentNoteGuid, unicode.toString());
2937 logger.log(logger.EXTREME, "updating list manager");
2938 listManager.updateNoteContent(currentNoteGuid, browserWindow.getContent());
2939 noteCache.put(currentNoteGuid, browserWindow.getContent());
2940 logger.log(logger.EXTREME, "Updating title");
2941 listManager.updateNoteTitle(currentNoteGuid, browserWindow.getTitle());
2942 updateListDateChanged();
2944 logger.log(logger.EXTREME, "Looking through note index for refreshed note");
2945 for (int i=0; i<listManager.getNoteIndex().size(); i++) {
2946 if (listManager.getNoteIndex().get(i).getGuid().equals(currentNoteGuid)) {
2947 currentNote = listManager.getNoteIndex().get(i);
2948 i = listManager.getNoteIndex().size();
2955 // Get a note from Evernote (and put it in the browser)
2956 private void refreshEvernoteNote(boolean reload) {
2957 logger.log(logger.HIGH, "Entering NeverNote.refreshEvernoteNote");
2958 if (Global.disableViewing) {
2959 browserWindow.setEnabled(false);
2963 if (!Global.showDeleted)
2964 browserWindow.setReadOnly(false);
2965 Global.cryptCounter =0;
2966 if (currentNoteGuid.equals("")) {
2967 browserWindow.setReadOnly(true);
2974 browserWindow.loadingData(true);
2976 currentNote = conn.getNoteTable().getNote(currentNoteGuid, true,true,false,false,true);
2977 if (currentNote == null)
2980 if (!noteCache.containsKey(currentNoteGuid) || conn.getNoteTable().isThumbnailNeeded(currentNoteGuid)) {
2981 QByteArray js = new QByteArray();
2982 // We need to prepend the note with <HEAD></HEAD> or encoded characters are ugly
2983 js.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
2984 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>");
2985 js.append("<style type=\"text/css\">en-hilight { background-color: rgb(255,255,0) }</style>");
2986 js.append("<style type=\"text/css\">en-spell { text-decoration: none; border-bottom: dotted 1px #cc0000; }</style>");
2987 js.append("</head>");
2988 js.append(rebuildNoteHTML(currentNoteGuid, currentNote.getContent()));
2989 js.append("</HTML>");
2990 js.replace("<!DOCTYPE en-note SYSTEM 'http://xml.evernote.com/pub/enml.dtd'>", "");
2991 js.replace("<!DOCTYPE en-note SYSTEM 'http://xml.evernote.com/pub/enml2.dtd'>", "");
2992 js.replace("<?xml version='1.0' encoding='UTF-8'?>", "");
2993 browserWindow.getBrowser().setContent(js);
2994 noteCache.put(currentNoteGuid, js.toString());
2995 if (conn.getNoteTable().isThumbnailNeeded(currentNoteGuid)) {
2996 preview = new Thumbnailer(currentNoteGuid, new QSize(1024,768));
2997 preview.finished.connect(this, "saveThumbnail(String)");
2998 preview.setContent(js.toString());
3001 logger.log(logger.HIGH, "Note content is being pulled from the cache");
3002 String cachedContent = modifyCachedTodoTags(noteCache.get(currentNoteGuid));
3003 browserWindow.getBrowser().setContent(new QByteArray(cachedContent));
3006 browserWindow.getBrowser().page().setContentEditable(!inkNote); // We don't allow editing of ink notes
3007 browserWindow.setNote(currentNote);
3009 // Build a list of non-closed notebooks
3010 List<Notebook> nbooks = new ArrayList<Notebook>();
3011 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
3012 boolean found=false;
3013 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
3014 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
3018 nbooks.add(listManager.getNotebookIndex().get(i));
3021 browserWindow.setNotebookList(nbooks);
3022 browserWindow.setTitle(currentNote.getTitle());
3023 browserWindow.setTag(getTagNamesForNote(currentNote));
3024 browserWindow.setAuthor(currentNote.getAttributes().getAuthor());
3026 browserWindow.setAltered(currentNote.getUpdated());
3027 browserWindow.setCreation(currentNote.getCreated());
3028 if (currentNote.getAttributes().getSubjectDate() > 0)
3029 browserWindow.setSubjectDate(currentNote.getAttributes().getSubjectDate());
3031 browserWindow.setSubjectDate(currentNote.getCreated());
3032 browserWindow.setUrl(currentNote.getAttributes().getSourceURL());
3033 browserWindow.setAllTags(listManager.getTagIndex());
3034 browserWindow.setCurrentTags(currentNote.getTagNames());
3036 scrollToGuid(currentNoteGuid);
3038 browserWindow.loadingData(false);
3039 if (thumbnailViewer.isActiveWindow())
3042 logger.log(logger.HIGH, "Leaving NeverNote.refreshEvernoteNote");
3044 // Save a generated thumbnail
3045 @SuppressWarnings("unused")
3046 private void saveThumbnail(String guid) {
3047 QFile tFile = new QFile(Global.getFileManager().getResDirPath("thumbnail-" + guid + ".png"));
3048 tFile.open(OpenModeFlag.ReadOnly);
3049 QByteArray imgBytes = tFile.readAll();
3051 conn.getNoteTable().setThumbnail(guid, imgBytes);
3052 conn.getNoteTable().setThumbnailNeeded(guid, false);
3053 thumbnailViewer.setThumbnail(QImage.fromData(imgBytes));
3054 if (thumbnailViewer.isVisible())
3055 thumbnailViewer.showFullScreen();
3058 QByteArray img2 = new QByteArray(conn.getNoteTable().getThumbnail(guid));
3059 QFile file = new QFile(Global.currentDir+"res/aaaa.png");
3060 file.open(OpenModeFlag.WriteOnly);
3065 // Show/Hide note information
3066 @SuppressWarnings("unused")
3067 private void toggleNoteInformation() {
3068 logger.log(logger.HIGH, "Entering NeverNote.toggleNoteInformation");
3069 browserWindow.toggleInformation();
3070 menuBar.noteAttributes.setChecked(browserWindow.isExtended());
3071 logger.log(logger.HIGH, "Leaving NeverNote.toggleNoteInformation");
3073 // Listener triggered when a print button is pressed
3074 @SuppressWarnings("unused")
3075 private void printNote() {
3076 logger.log(logger.HIGH, "Entering NeverNote.printNote");
3078 QPrintDialog dialog = new QPrintDialog();
3079 if (dialog.exec() == QDialog.DialogCode.Accepted.value()) {
3080 QPrinter printer = dialog.printer();
3081 browserWindow.getBrowser().print(printer);
3083 logger.log(logger.HIGH, "Leaving NeverNote.printNote");
3086 // Listener triggered when the email button is pressed
3087 @SuppressWarnings("unused")
3088 private void emailNote() {
3089 logger.log(logger.HIGH, "Entering NeverNote.emailNote");
3091 if (Desktop.isDesktopSupported()) {
3092 Desktop desktop = Desktop.getDesktop();
3094 String text2 = browserWindow.getContentsToEmail();
3095 QUrl url = new QUrl("mailto:");