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.net.Authenticator;
25 import java.net.PasswordAuthentication;
26 import java.security.MessageDigest;
27 import java.security.NoSuchAlgorithmException;
28 import java.sql.Connection;
29 import java.sql.DriverManager;
30 import java.sql.SQLException;
31 import java.sql.Statement;
32 import java.text.SimpleDateFormat;
33 import java.util.ArrayList;
34 import java.util.Calendar;
35 import java.util.Collection;
36 import java.util.Collections;
37 import java.util.Comparator;
38 import java.util.Date;
39 import java.util.GregorianCalendar;
40 import java.util.HashMap;
41 import java.util.Iterator;
42 import java.util.List;
43 import java.util.SortedMap;
44 import java.util.Vector;
46 import org.apache.log4j.Level;
47 import org.apache.log4j.Logger;
48 import org.apache.thrift.TException;
49 import org.h2.tools.ChangeFileEncryption;
51 import com.evernote.edam.error.EDAMNotFoundException;
52 import com.evernote.edam.error.EDAMSystemException;
53 import com.evernote.edam.error.EDAMUserException;
54 import com.evernote.edam.notestore.NoteFilter;
55 import com.evernote.edam.notestore.NoteVersionId;
56 import com.evernote.edam.type.Data;
57 import com.evernote.edam.type.LinkedNotebook;
58 import com.evernote.edam.type.Note;
59 import com.evernote.edam.type.NoteAttributes;
60 import com.evernote.edam.type.Notebook;
61 import com.evernote.edam.type.Publishing;
62 import com.evernote.edam.type.QueryFormat;
63 import com.evernote.edam.type.Resource;
64 import com.evernote.edam.type.SavedSearch;
65 import com.evernote.edam.type.Tag;
66 import com.evernote.edam.type.User;
67 import com.trolltech.qt.QThread;
68 import com.trolltech.qt.core.QByteArray;
69 import com.trolltech.qt.core.QDateTime;
70 import com.trolltech.qt.core.QDir;
71 import com.trolltech.qt.core.QEvent;
72 import com.trolltech.qt.core.QFile;
73 import com.trolltech.qt.core.QFileInfo;
74 import com.trolltech.qt.core.QFileSystemWatcher;
75 import com.trolltech.qt.core.QIODevice;
76 import com.trolltech.qt.core.QIODevice.OpenModeFlag;
77 import com.trolltech.qt.core.QLocale;
78 import com.trolltech.qt.core.QModelIndex;
79 import com.trolltech.qt.core.QSize;
80 import com.trolltech.qt.core.QTemporaryFile;
81 import com.trolltech.qt.core.QTextCodec;
82 import com.trolltech.qt.core.QThreadPool;
83 import com.trolltech.qt.core.QTimer;
84 import com.trolltech.qt.core.QTranslator;
85 import com.trolltech.qt.core.QUrl;
86 import com.trolltech.qt.core.Qt;
87 import com.trolltech.qt.core.Qt.BGMode;
88 import com.trolltech.qt.core.Qt.ItemDataRole;
89 import com.trolltech.qt.core.Qt.SortOrder;
90 import com.trolltech.qt.core.Qt.WidgetAttribute;
91 import com.trolltech.qt.gui.QAbstractItemView;
92 import com.trolltech.qt.gui.QAbstractItemView.ScrollHint;
93 import com.trolltech.qt.gui.QAction;
94 import com.trolltech.qt.gui.QApplication;
95 import com.trolltech.qt.gui.QCloseEvent;
96 import com.trolltech.qt.gui.QColor;
97 import com.trolltech.qt.gui.QComboBox;
98 import com.trolltech.qt.gui.QComboBox.InsertPolicy;
99 import com.trolltech.qt.gui.QCursor;
100 import com.trolltech.qt.gui.QDesktopServices;
101 import com.trolltech.qt.gui.QDialog;
102 import com.trolltech.qt.gui.QFileDialog;
103 import com.trolltech.qt.gui.QFileDialog.AcceptMode;
104 import com.trolltech.qt.gui.QFileDialog.FileMode;
105 import com.trolltech.qt.gui.QGridLayout;
106 import com.trolltech.qt.gui.QHBoxLayout;
107 import com.trolltech.qt.gui.QIcon;
108 import com.trolltech.qt.gui.QImage;
109 import com.trolltech.qt.gui.QLabel;
110 import com.trolltech.qt.gui.QListWidget;
111 import com.trolltech.qt.gui.QMainWindow;
112 import com.trolltech.qt.gui.QMenu;
113 import com.trolltech.qt.gui.QMessageBox;
114 import com.trolltech.qt.gui.QMessageBox.StandardButton;
115 import com.trolltech.qt.gui.QPainter;
116 import com.trolltech.qt.gui.QPalette.ColorRole;
117 import com.trolltech.qt.gui.QPixmap;
118 import com.trolltech.qt.gui.QPrintDialog;
119 import com.trolltech.qt.gui.QPrinter;
120 import com.trolltech.qt.gui.QSizePolicy;
121 import com.trolltech.qt.gui.QSizePolicy.Policy;
122 import com.trolltech.qt.gui.QSpinBox;
123 import com.trolltech.qt.gui.QSplashScreen;
124 import com.trolltech.qt.gui.QSplitter;
125 import com.trolltech.qt.gui.QStatusBar;
126 import com.trolltech.qt.gui.QSystemTrayIcon;
127 import com.trolltech.qt.gui.QTableWidgetItem;
128 import com.trolltech.qt.gui.QTextEdit;
129 import com.trolltech.qt.gui.QToolBar;
130 import com.trolltech.qt.gui.QTreeWidgetItem;
131 import com.trolltech.qt.network.QNetworkAccessManager;
132 import com.trolltech.qt.network.QNetworkReply;
133 import com.trolltech.qt.network.QNetworkRequest;
134 import com.trolltech.qt.webkit.QWebPage.WebAction;
135 import com.trolltech.qt.webkit.QWebSettings;
137 import cx.fbn.nevernote.config.InitializationException;
138 import cx.fbn.nevernote.config.StartupConfig;
139 import cx.fbn.nevernote.dialog.AccountDialog;
140 import cx.fbn.nevernote.dialog.ConfigDialog;
141 import cx.fbn.nevernote.dialog.DBEncryptDialog;
142 import cx.fbn.nevernote.dialog.DatabaseLoginDialog;
143 import cx.fbn.nevernote.dialog.DatabaseStatus;
144 import cx.fbn.nevernote.dialog.FindDialog;
145 import cx.fbn.nevernote.dialog.IgnoreSync;
146 import cx.fbn.nevernote.dialog.LoginDialog;
147 import cx.fbn.nevernote.dialog.NotebookArchive;
148 import cx.fbn.nevernote.dialog.NotebookEdit;
149 import cx.fbn.nevernote.dialog.OnlineNoteHistory;
150 import cx.fbn.nevernote.dialog.PublishNotebook;
151 import cx.fbn.nevernote.dialog.SavedSearchEdit;
152 import cx.fbn.nevernote.dialog.SetIcon;
153 import cx.fbn.nevernote.dialog.ShareNotebook;
154 import cx.fbn.nevernote.dialog.StackNotebook;
155 import cx.fbn.nevernote.dialog.TagEdit;
156 import cx.fbn.nevernote.dialog.ThumbnailViewer;
157 import cx.fbn.nevernote.dialog.UpgradeAvailableDialog;
158 import cx.fbn.nevernote.dialog.WatchFolder;
159 import cx.fbn.nevernote.filters.FilterEditorNotebooks;
160 import cx.fbn.nevernote.filters.FilterEditorTags;
161 import cx.fbn.nevernote.gui.AttributeTreeWidget;
162 import cx.fbn.nevernote.gui.BrowserWindow;
163 import cx.fbn.nevernote.gui.DateAttributeFilterTable;
164 import cx.fbn.nevernote.gui.ExternalBrowse;
165 import cx.fbn.nevernote.gui.MainMenuBar;
166 import cx.fbn.nevernote.gui.NotebookTreeWidget;
167 import cx.fbn.nevernote.gui.SavedSearchTreeWidget;
168 import cx.fbn.nevernote.gui.TableView;
169 import cx.fbn.nevernote.gui.TagTreeWidget;
170 import cx.fbn.nevernote.gui.Thumbnailer;
171 import cx.fbn.nevernote.gui.TrashTreeWidget;
172 import cx.fbn.nevernote.gui.controls.QuotaProgressBar;
173 import cx.fbn.nevernote.sql.DatabaseConnection;
174 import cx.fbn.nevernote.sql.WatchFolderRecord;
175 import cx.fbn.nevernote.threads.IndexRunner;
176 import cx.fbn.nevernote.threads.SyncRunner;
177 import cx.fbn.nevernote.threads.ThumbnailRunner;
178 import cx.fbn.nevernote.utilities.AESEncrypter;
179 import cx.fbn.nevernote.utilities.ApplicationLogger;
180 import cx.fbn.nevernote.utilities.FileImporter;
181 import cx.fbn.nevernote.utilities.FileUtils;
182 import cx.fbn.nevernote.utilities.ListManager;
183 import cx.fbn.nevernote.utilities.SyncTimes;
184 import cx.fbn.nevernote.xml.ExportData;
185 import cx.fbn.nevernote.xml.ImportData;
186 import cx.fbn.nevernote.xml.NoteFormatter;
189 public class NeverNote extends QMainWindow{
191 QStatusBar statusBar; // Application status bar
193 DatabaseConnection conn;
195 MainMenuBar menuBar; // Main menu bar
196 FindDialog find; // Text search in note dialog
197 List<String> emitLog; // Messages displayed in the status bar;
198 QSystemTrayIcon trayIcon; // little tray icon
199 QMenu trayMenu; // System tray menu
200 QAction trayExitAction; // Exit the application
201 QAction trayShowAction; // toggle the show/hide action
202 QAction trayAddNoteAction; // Add a note from the system tray
203 QNetworkAccessManager versionChecker; // Used when checking for new versions
205 NotebookTreeWidget notebookTree; // List of notebooks
206 AttributeTreeWidget attributeTree; // List of note attributes
207 TagTreeWidget tagTree; // list of user created tags
208 SavedSearchTreeWidget savedSearchTree; // list of saved searches
209 TrashTreeWidget trashTree; // Trashcan
210 TableView noteTableView; // List of notes (the widget).
212 public BrowserWindow browserWindow; // Window containing browser & labels
213 public QToolBar toolBar; // The tool bar under the menu
214 QComboBox searchField; // search filter bar on the toolbar;
215 boolean searchPerformed = false; // Search was done?
216 QuotaProgressBar quotaBar; // The current quota usage
218 ApplicationLogger logger;
219 List<String> selectedNotebookGUIDs; // List of notebook GUIDs
220 List<String> selectedTagGUIDs; // List of selected tag GUIDs
221 List<String> selectedNoteGUIDs; // List of selected notes
222 String selectedSavedSearchGUID; // Currently selected saved searches
223 private final HashMap<String, ExternalBrowse> externalWindows; // Notes being edited by an external window;
225 NoteFilter filter; // Note filter
226 String currentNoteGuid; // GUID of the current note
227 Note currentNote; // The currently viewed note
228 boolean noteDirty; // Has the note been changed?
229 boolean inkNote; // if this is an ink note, it is read only
230 boolean readOnly; // Is this note read-only?
233 ListManager listManager; // DB runnable task
235 List<QTemporaryFile> tempFiles; // Array of temporary files;
237 QTimer indexTimer; // timer to start the index thread
238 IndexRunner indexRunner; // thread to index notes
241 QTimer syncTimer; // Sync on an interval
242 QTimer syncDelayTimer; // Sync delay to free up database
243 SyncRunner syncRunner; // thread to do a sync.
244 QThread syncThread; // Thread which talks to evernote
245 ThumbnailRunner thumbnailRunner; // Runner for thumbnail thread
246 QThread thumbnailThread; // Thread that generates pretty pictures
247 QTimer saveTimer; // Timer to save note contents
249 QTimer authTimer; // Refresh authentication
250 QTimer externalFileSaveTimer; // Save files altered externally
251 QTimer thumbnailTimer; // Wakeup & scan for thumbnails
252 List<String> externalFiles; // External files to save later
253 List<String> importFilesKeep; // Auto-import files to save later
254 List<String> importFilesDelete; // Auto-import files to save later
256 int indexTime; // how often to try and index
257 boolean indexRunning; // Is indexing running?
258 boolean indexDisabled; // Is indexing disabled?
260 int syncThreadsReady; // number of sync threads that are free
261 int syncTime; // Sync interval
262 boolean syncRunning; // Is sync running?
263 boolean automaticSync; // do sync automatically?
264 QTreeWidgetItem attributeTreeSelected;
266 QAction prevButton; // Go to the previous item viewed
267 QAction nextButton; // Go to the next item in the history
268 QAction downButton; // Go to the next item in the list
269 QAction upButton; // Go to the prev. item in the list;
270 QAction synchronizeButton; // Synchronize with Evernote
271 QAction allNotesButton; // Reset & view all notes
272 QTimer synchronizeAnimationTimer; // Timer to change animation button
273 int synchronizeIconAngle; // Used to rotate sync icon
274 QAction printButton; // Print Button
275 QAction tagButton; // Tag edit button
276 QAction attributeButton; // Attribute information button
277 QAction emailButton; // Email button
278 QAction deleteButton; // Delete button
279 QAction newButton; // new Note Button;
280 QSpinBox zoomSpinner; // Zoom zoom
281 QAction searchClearButton; // Clear the search field
283 QSplitter mainLeftRightSplitter; // main splitter for left/right side
284 QSplitter leftSplitter1; // first left hand splitter
285 QSplitter browserIndexSplitter; // splitter between note index & note text
287 QFileSystemWatcher importKeepWatcher; // Watch & keep auto-import
288 QFileSystemWatcher importDeleteWatcher; // Watch & Delete auto-import
289 List<String> importedFiles; // History of imported files (so we don't import twice)
291 OnlineNoteHistory historyWindow; // online history window
292 List<NoteVersionId> versions; // history versions
294 QTimer threadMonitorTimer; // Timer to watch threads.
295 int dbThreadDeadCount=0; // number of consecutive dead times for the db thread
296 int syncThreadDeadCount=0; // number of consecutive dead times for the sync thread
297 int indexThreadDeadCount=0; // number of consecutive dead times for the index thread
298 int notebookThreadDeadCount=0; // number of consecutive dead times for the notebook thread
299 int tagDeadCount=0; // number of consecutive dead times for the tag thread
300 int trashDeadCount=0; // number of consecutive dead times for the trash thread
301 int saveThreadDeadCount=0; // number of consecutive dead times for the save thread
303 HashMap<String, String> noteCache; // Cash of note content
304 HashMap<String, Boolean> readOnlyCache; // List of cashe notes that are read-only
305 HashMap<String, Boolean> inkNoteCache; // List of cache notes that are ink notes
306 List<String> historyGuids; // GUIDs of previously viewed items
307 int historyPosition; // Position within the viewed items
308 boolean fromHistory; // Is this from the history queue?
309 String trashNoteGuid; // Guid to restore / set into or out of trash to save position
310 List<Thumbnailer> thumbGenerators; // generate preview image
311 ThumbnailViewer thumbnailViewer; // View preview thumbnail;
312 boolean encryptOnShutdown; // should I encrypt when I close?
313 boolean decryptOnShutdown; // should I decrypt on shutdown;
314 String encryptCipher; // What cipher should I use?
315 Signal0 minimizeToTray;
316 boolean windowMaximized = false; // Keep track of the window state for restores
317 List<String> pdfReadyQueue; // Queue of PDFs that are ready to be rendered.
318 List<QPixmap> syncIcons; // Array of icons used in sync animation
319 private boolean closeAction = false; // Used to say when to close or when to minimize
320 private static Logger log = Logger.getLogger(NeverNote.class);
323 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
326 //***************************************************************
327 //***************************************************************
328 //** Constructor & main entry point
329 //***************************************************************
330 //***************************************************************
331 // Application Constructor
332 @SuppressWarnings("static-access")
333 public NeverNote(DatabaseConnection dbConn) {
335 if (conn.getConnection() == null) {
336 String msg = new String(tr("Unable to connect to the database.\n\nThe most probable reason is that some other process\n" +
337 "is accessing the database or NeverNote is already running.\n\n" +
338 "Please end any other process or shutdown the other NeverNote before starting.\n\nExiting program."));
340 QMessageBox.critical(null, tr("Database Connection Error") ,msg);
344 thread().setPriority(Thread.MAX_PRIORITY);
346 logger = new ApplicationLogger("nevernote.log");
347 logger.log(logger.HIGH, "Starting Application");
349 decryptOnShutdown = false;
350 encryptOnShutdown = false;
351 conn.checkDatabaseVersion();
355 // Start building the invalid XML tables
356 Global.invalidElements = conn.getInvalidXMLTable().getInvalidElements();
357 List<String> elements = conn.getInvalidXMLTable().getInvalidAttributeElements();
359 for (int i=0; i<elements.size(); i++) {
360 Global.invalidAttributes.put(elements.get(i), conn.getInvalidXMLTable().getInvalidAttributes(elements.get(i)));
363 logger.log(logger.EXTREME, "Starting GUI build");
365 QTranslator nevernoteTranslator = new QTranslator();
366 nevernoteTranslator.load(Global.getFileManager().getTranslateFilePath("nevernote_" + QLocale.system().name() + ".qm"));
367 QApplication.instance().installTranslator(nevernoteTranslator);
369 Global.originalPalette = QApplication.palette();
370 QApplication.setStyle(Global.getStyle());
371 if (Global.useStandardPalette())
372 QApplication.setPalette(QApplication.style().standardPalette());
373 setWindowTitle("NeverNote");
375 mainLeftRightSplitter = new QSplitter();
376 setCentralWidget(mainLeftRightSplitter);
377 leftSplitter1 = new QSplitter();
378 leftSplitter1.setOrientation(Qt.Orientation.Vertical);
380 browserIndexSplitter = new QSplitter();
381 browserIndexSplitter.setOrientation(Qt.Orientation.Vertical);
383 //* Setup threads & thread timers
384 int indexRunnerCount = Global.getIndexThreads();
385 indexRunnerCount = 1;
386 QThreadPool.globalInstance().setMaxThreadCount(indexRunnerCount+5); // increase max thread count
388 logger.log(logger.EXTREME, "Building list manager");
389 listManager = new ListManager(conn, logger);
391 logger.log(logger.EXTREME, "Building index runners & timers");
392 indexRunner = new IndexRunner("indexRunner.log", Global.getDatabaseUrl(), Global.getDatabaseUserid(), Global.getDatabaseUserPassword(), Global.cipherPassword);
393 indexThread = new QThread(indexRunner, "Index Thread");
394 indexRunner.indexAttachmentsLocally = Global.indexAttachmentsLocally();
397 synchronizeAnimationTimer = new QTimer();
398 synchronizeAnimationTimer.timeout.connect(this, "updateSyncButton()");
400 indexTimer = new QTimer();
401 indexTime = 1000*Global.getIndexThreadSleepInterval();
402 indexTimer.start(indexTime); // Start indexing timer
403 indexTimer.timeout.connect(this, "indexTimer()");
404 indexDisabled = false;
405 indexRunning = false;
407 logger.log(logger.EXTREME, "Setting sync thread & timers");
409 syncRunner = new SyncRunner("syncRunner.log", Global.getDatabaseUrl(), Global.getDatabaseUserid(), Global.getDatabaseUserPassword(), Global.cipherPassword);
410 syncTime = new SyncTimes().timeValue(Global.getSyncInterval());
411 syncTimer = new QTimer();
412 syncTimer.timeout.connect(this, "syncTimer()");
413 syncRunner.status.message.connect(this, "setMessage(String)");
414 syncRunner.syncSignal.finished.connect(this, "syncThreadComplete(Boolean)");
415 syncRunner.syncSignal.errorDisconnect.connect(this, "remoteErrorDisconnect()");
418 automaticSync = true;
419 syncTimer.start(syncTime*60*1000);
421 automaticSync = false;
424 syncRunner.setEvernoteUpdateCount(Global.getEvernoteUpdateCount());
425 syncThread = new QThread(syncRunner, "Synchronization Thread");
429 logger.log(logger.EXTREME, "Starting thumnail thread");
430 pdfReadyQueue = new ArrayList<String>();
431 thumbnailRunner = new ThumbnailRunner("thumbnailRunner.log", Global.getDatabaseUrl(), Global.getDatabaseUserid(), Global.getDatabaseUserPassword(), Global.cipherPassword);
432 thumbnailThread = new QThread(thumbnailRunner, "Thumbnail Thread");
433 thumbnailRunner.noteSignal.thumbnailPageReady.connect(this, "thumbnailHTMLReady(String,QByteArray,Integer)");
434 thumbnailThread.start();
435 thumbGenerators = new ArrayList<Thumbnailer>();
436 thumbnailTimer = new QTimer();
437 thumbnailTimer.timeout.connect(this, "thumbnailTimer()");
439 thumbnailTimer.setInterval(60*1000); // Thumbnail every minute
440 thumbnailTimer.start();
442 logger.log(logger.EXTREME, "Starting authentication timer");
443 authTimer = new QTimer();
444 authTimer.timeout.connect(this, "authTimer()");
445 authTimer.start(1000*60*15);
446 syncRunner.syncSignal.authRefreshComplete.connect(this, "authRefreshComplete(boolean)");
448 logger.log(logger.EXTREME, "Setting save note timer");
449 saveTimer = new QTimer();
450 saveTimer.timeout.connect(this, "saveNote()");
451 if (Global.getAutoSaveInterval() > 0) {
452 saveTimer.setInterval(1000*60*Global.getAutoSaveInterval());
455 listManager.saveRunner.noteSignals.noteSaveRunnerError.connect(this, "saveRunnerError(String, String)");
457 logger.log(logger.EXTREME, "Starting external file monitor timer");
458 externalFileSaveTimer = new QTimer();
459 externalFileSaveTimer.timeout.connect(this, "externalFileEditedSaver()");
460 externalFileSaveTimer.setInterval(1000*5); // save every 5 seconds;
461 externalFiles = new ArrayList<String>();
462 importFilesDelete = new ArrayList<String>();
463 importFilesKeep = new ArrayList<String>();
464 externalFileSaveTimer.start();
466 notebookTree = new NotebookTreeWidget(conn);
467 attributeTree = new AttributeTreeWidget();
468 tagTree = new TagTreeWidget(conn);
469 savedSearchTree = new SavedSearchTreeWidget();
470 trashTree = new TrashTreeWidget();
471 noteTableView = new TableView(logger, listManager);
473 QGridLayout leftGrid = new QGridLayout();
474 leftSplitter1.setLayout(leftGrid);
475 leftGrid.addWidget(notebookTree, 1, 1);
476 leftGrid.addWidget(tagTree,2,1);
477 leftGrid.addWidget(attributeTree,3,1);
478 leftGrid.addWidget(savedSearchTree,4,1);
479 leftGrid.addWidget(trashTree, 5, 1);
481 // Setup the browser window
482 noteCache = new HashMap<String,String>();
483 readOnlyCache = new HashMap<String, Boolean>();
484 inkNoteCache = new HashMap<String, Boolean>();
485 browserWindow = new BrowserWindow(conn);
487 mainLeftRightSplitter.addWidget(leftSplitter1);
488 mainLeftRightSplitter.addWidget(browserIndexSplitter);
490 if (Global.getListView() == Global.View_List_Wide) {
491 browserIndexSplitter.addWidget(noteTableView);
492 browserIndexSplitter.addWidget(browserWindow);
494 mainLeftRightSplitter.addWidget(noteTableView);
495 mainLeftRightSplitter.addWidget(browserWindow);
498 searchField = new QComboBox();
499 searchField.setEditable(true);
500 searchField.activatedIndex.connect(this, "searchFieldChanged()");
501 searchField.setDuplicatesEnabled(false);
502 searchField.editTextChanged.connect(this,"searchFieldTextChanged(String)");
504 quotaBar = new QuotaProgressBar();
506 // Setup the thumbnail viewer
507 thumbnailViewer = new ThumbnailViewer();
508 thumbnailViewer.upArrow.connect(this, "upAction()");
509 thumbnailViewer.downArrow.connect(this, "downAction()");
510 thumbnailViewer.leftArrow.connect(this, "nextViewedAction()");
511 thumbnailViewer.rightArrow.connect(this, "previousViewedAction()");
513 //Setup external browser manager
514 externalWindows = new HashMap<String, ExternalBrowse>();
516 listManager.loadNotesIndex();
517 initializeNotebookTree();
519 initializeSavedSearchTree();
520 attributeTree.itemClicked.connect(this, "attributeTreeClicked(QTreeWidgetItem, Integer)");
521 attributeTreeSelected = null;
522 initializeNoteTable();
524 selectedNoteGUIDs = new ArrayList<String>();
525 statusBar = new QStatusBar();
526 setStatusBar(statusBar);
527 menuBar = new MainMenuBar(this);
528 emitLog = new ArrayList<String>();
530 tagTree.setDeleteAction(menuBar.tagDeleteAction);
531 tagTree.setEditAction(menuBar.tagEditAction);
532 tagTree.setAddAction(menuBar.tagAddAction);
533 tagTree.setIconAction(menuBar.tagIconAction);
534 tagTree.setVisible(Global.isWindowVisible("tagTree"));
535 tagTree.noteSignal.tagsAdded.connect(this, "tagsAdded(String, String)");
536 menuBar.hideTags.setChecked(Global.isWindowVisible("tagTree"));
537 listManager.tagSignal.listChanged.connect(this, "reloadTagTree()");
539 notebookTree.setDeleteAction(menuBar.notebookDeleteAction);
540 notebookTree.setEditAction(menuBar.notebookEditAction);
541 notebookTree.setAddAction(menuBar.notebookAddAction);
542 notebookTree.setIconAction(menuBar.notebookIconAction);
543 notebookTree.setStackAction(menuBar.notebookStackAction);
544 notebookTree.setPublishAction(menuBar.notebookPublishAction);
545 notebookTree.setShareAction(menuBar.notebookShareAction);
546 notebookTree.setVisible(Global.isWindowVisible("notebookTree"));
547 notebookTree.noteSignal.notebookChanged.connect(this, "updateNoteNotebook(String, String)");
548 notebookTree.noteSignal.tagsChanged.connect(this, "updateNoteTags(String, List)");
549 notebookTree.noteSignal.tagsChanged.connect(this, "updateListTags(String, List)");
550 menuBar.hideNotebooks.setChecked(Global.isWindowVisible("notebookTree"));
552 savedSearchTree.setAddAction(menuBar.savedSearchAddAction);
553 savedSearchTree.setEditAction(menuBar.savedSearchEditAction);
554 savedSearchTree.setDeleteAction(menuBar.savedSearchDeleteAction);
555 savedSearchTree.setIconAction(menuBar.savedSearchIconAction);
556 savedSearchTree.itemSelectionChanged.connect(this, "updateSavedSearchSelection()");
557 savedSearchTree.setVisible(Global.isWindowVisible("savedSearchTree"));
558 menuBar.hideSavedSearches.setChecked(Global.isWindowVisible("savedSearchTree"));
560 noteTableView.setAddAction(menuBar.noteAdd);
561 noteTableView.setDeleteAction(menuBar.noteDelete);
562 noteTableView.setRestoreAction(menuBar.noteRestoreAction);
563 noteTableView.setNoteDuplicateAction(menuBar.noteDuplicateAction);
564 noteTableView.setNoteHistoryAction(menuBar.noteOnlineHistoryAction);
565 noteTableView.noteSignal.titleColorChanged.connect(this, "titleColorChanged(Integer)");
566 noteTableView.setMergeNotesAction(menuBar.noteMergeAction);
567 noteTableView.rowChanged.connect(this, "scrollToGuid(String)");
568 noteTableView.resetViewport.connect(this, "scrollToCurrentGuid()");
569 noteTableView.doubleClicked.connect(this, "listDoubleClick()");
570 listManager.trashSignal.countChanged.connect(trashTree, "updateCounts(Integer)");
572 quotaBar.setMouseClickAction(menuBar.accountAction);
575 trashTree.itemSelectionChanged.connect(this, "trashTreeSelection()");
576 trashTree.setEmptyAction(menuBar.emptyTrashAction);
577 trashTree.setVisible(Global.isWindowVisible("trashTree"));
578 menuBar.hideTrash.setChecked(Global.isWindowVisible("trashTree"));
579 trashTree.updateCounts(listManager.getTrashCount());
580 attributeTree.setVisible(Global.isWindowVisible("attributeTree"));
581 menuBar.hideAttributes.setChecked(Global.isWindowVisible("attributeTree"));
583 noteTableView.setVisible(Global.isWindowVisible("noteList"));
584 menuBar.hideNoteList.setChecked(Global.isWindowVisible("noteList"));
586 if (!Global.isWindowVisible("editorButtonBar"))
587 toggleEditorButtonBar();
588 if (!Global.isWindowVisible("leftPanel"))
589 menuBar.hideLeftSide.setChecked(true);
590 if (Global.isWindowVisible("noteInformation"))
591 toggleNoteInformation();
595 find = new FindDialog();
596 find.getOkButton().clicked.connect(this, "doFindText()");
598 // Setup the tray icon menu bar
599 trayShowAction = new QAction("Show/Hide", this);
600 trayExitAction = new QAction("Exit", this);
601 trayAddNoteAction = new QAction("Add Note", this);
603 trayExitAction.triggered.connect(this, "closeNeverNote()");
604 trayAddNoteAction.triggered.connect(this, "addNote()");
605 trayShowAction.triggered.connect(this, "trayToggleVisible()");
607 trayMenu = new QMenu(this);
608 trayMenu.addAction(trayAddNoteAction);
609 trayMenu.addAction(trayShowAction);
610 trayMenu.addAction(trayExitAction);
613 trayIcon = new QSystemTrayIcon(this);
614 trayIcon.setToolTip("NeverNote");
615 trayIcon.setContextMenu(trayMenu);
616 trayIcon.activated.connect(this, "trayActivated(com.trolltech.qt.gui.QSystemTrayIcon$ActivationReason)");
619 currentNoteGuid = Global.getLastViewedNoteGuid();
620 historyGuids = new ArrayList<String>();
624 if (!currentNoteGuid.trim().equals("")) {
625 currentNote = conn.getNoteTable().getNote(currentNoteGuid, true,true,false,false,true);
628 noteIndexUpdated(true);
630 menuBar.showEditorBar.setChecked(Global.isWindowVisible("editorButtonBar"));
631 if (menuBar.showEditorBar.isChecked())
632 showEditorButtons(browserWindow);
633 tagIndexUpdated(true);
634 savedSearchIndexUpdated();
635 notebookIndexUpdated();
637 setupSyncSignalListeners();
638 setupBrowserSignalListeners();
639 setupIndexListeners();
642 tagTree.tagSignal.listChanged.connect(this, "tagIndexUpdated()");
643 tagTree.showAllTags(true);
645 QIcon appIcon = new QIcon(iconPath+"nevernote.png");
646 setWindowIcon(appIcon);
647 trayIcon.setIcon(appIcon);
648 if (Global.showTrayIcon())
653 scrollToGuid(currentNoteGuid);
654 if (Global.automaticLogin()) {
656 if (Global.isConnected)
659 setupFolderImports();
662 restoreWindowState(true);
664 if (Global.mimicEvernoteInterface) {
665 notebookTree.selectGuid("");
668 threadMonitorTimer = new QTimer();
669 threadMonitorTimer.timeout.connect(this, "threadMonitorCheck()");
670 threadMonitorTimer.start(1000*10); // Check for threads every 10 seconds;
672 historyGuids.add(currentNoteGuid);
675 menuBar.blockSignals(true);
676 menuBar.narrowListView.blockSignals(true);
677 menuBar.wideListView.blockSignals(true);
678 if (Global.getListView() == Global.View_List_Narrow) {
679 menuBar.narrowListView.setChecked(true);
682 menuBar.wideListView.setChecked(true);
684 menuBar.blockSignals(false);
685 menuBar.narrowListView.blockSignals(false);
686 menuBar.wideListView.blockSignals(false);
688 if (Global.getListView() == Global.View_List_Wide) {
689 browserIndexSplitter.addWidget(noteTableView);
690 browserIndexSplitter.addWidget(browserWindow);
692 mainLeftRightSplitter.addWidget(noteTableView);
693 mainLeftRightSplitter.addWidget(browserWindow);
696 int sortCol = Global.getSortColumn();
697 int sortOrder = Global.getSortOrder();
698 noteTableView.sortByColumn(sortCol, SortOrder.resolve(sortOrder));
699 if (Global.checkVersionUpgrade())
703 public void checkForUpdates() {
704 // Send off thread to check for a new version
705 versionChecker = new QNetworkAccessManager(this);
706 versionChecker.finished.connect(this, "upgradeFileRead(QNetworkReply)");
707 QNetworkRequest request = new QNetworkRequest();
708 request.setUrl(new QUrl(Global.getUpdatesAvailableUrl()));
709 versionChecker.get(request);
711 private void upgradeFileRead(QNetworkReply reply) {
712 if (!reply.isReadable())
715 String winVersion = Global.version;
716 String osxVersion = Global.version;
717 String linuxVersion = Global.version;
718 String linux64Version = Global.version;
719 String version = Global.version;
721 // Determine the versions available
722 QByteArray data = reply.readLine();
723 while (data != null && !reply.atEnd()) {
724 String line = data.toString();
726 if (line.contains(":"))
727 lineVersion = line.substring(line.indexOf(":")+1).replace(" ", "").replace("\n", "");
730 if (line.toLowerCase().contains("windows"))
731 winVersion = lineVersion;
732 else if (line.toLowerCase().contains("os-x"))
733 osxVersion = lineVersion;
734 else if (line.toLowerCase().contains("linux amd64"))
735 linux64Version = lineVersion;
736 else if (line.toLowerCase().contains("linux i386"))
737 linuxVersion = lineVersion;
738 else if (line.toLowerCase().contains("default"))
739 version = lineVersion;
741 // Read the next line
742 data = reply.readLine();
745 // Now we need to determine what system we are on.
746 if (System.getProperty("os.name").toLowerCase().contains("windows"))
747 version = winVersion;
748 if (System.getProperty("os.name").toLowerCase().contains("mac os"))
749 version = osxVersion;
750 if (System.getProperty("os.name").toLowerCase().contains("Linux")) {
751 if (System.getProperty("os.arch").contains("amd64") ||
752 System.getProperty("os.arch").contains("x86_64") ||
753 System.getProperty("os.arch").contains("i686"))
754 version = linux64Version;
756 version = linuxVersion;
760 if (Global.version.equals(version))
763 UpgradeAvailableDialog dialog = new UpgradeAvailableDialog();
765 if (dialog.remindMe())
766 Global.setCheckVersionUpgrade(true);
768 Global.setCheckVersionUpgrade(false);
773 public static void main(String[] args) {
774 log.setLevel(Level.FATAL);
775 QApplication.initialize(args);
776 QPixmap pixmap = new QPixmap("classpath:cx/fbn/nevernote/icons/splash_logo.png");
777 QSplashScreen splash = new QSplashScreen(pixmap);
780 DatabaseConnection dbConn;
783 initializeGlobalSettings(args);
785 showSplash = Global.isWindowVisible("SplashScreen");
789 dbConn = setupDatabaseConnection();
791 // Must be last stage of setup - only safe once DB is open hence we know we are the only instance running
792 Global.getFileManager().purgeResDirectory(true);
794 } catch (InitializationException e) {
797 QMessageBox.critical(null, "Startup error", "Aborting: " + e.getMessage());
801 NeverNote application = new NeverNote(dbConn);
803 application.setAttribute(WidgetAttribute.WA_DeleteOnClose, true);
804 if (Global.startMinimized())
805 application.showMinimized();
807 if (Global.wasWindowMaximized())
808 application.showMaximized();
814 splash.finish(application);
816 System.out.println("Goodbye.");
821 * Open the internal database, or create if not present
823 * @throws InitializationException when opening the database fails, e.g. because another process has it locked
825 private static DatabaseConnection setupDatabaseConnection() throws InitializationException {
826 ApplicationLogger logger = new ApplicationLogger("nevernote-database.log");
828 File f = Global.getFileManager().getDbDirFile(Global.databaseName + ".h2.db");
829 boolean dbExists = f.exists();
831 Global.setDatabaseUrl("");
833 if (Global.getDatabaseUrl().toUpperCase().indexOf("CIPHER=") > -1) {
834 boolean goodCheck = false;
836 DatabaseLoginDialog dialog = new DatabaseLoginDialog();
838 if (!dialog.okPressed())
840 Global.cipherPassword = dialog.getPassword();
841 goodCheck = databaseCheck(Global.getDatabaseUrl(), Global.getDatabaseUserid(),
842 Global.getDatabaseUserPassword(), Global.cipherPassword);
845 DatabaseConnection dbConn = new DatabaseConnection(logger,Global.getDatabaseUrl(), Global.getDatabaseUserid(), Global.getDatabaseUserPassword(), Global.cipherPassword);
849 // Encrypt the database upon shutdown
850 private void encryptOnShutdown() {
851 String dbPath= Global.getFileManager().getDbDirPath("");
852 String dbName = "NeverNote";
854 Statement st = conn.getConnection().createStatement();
855 st.execute("shutdown");
856 if (QMessageBox.question(this, "Are you sure",
857 "Are you sure you wish to encrypt the database?",
858 QMessageBox.StandardButton.Yes,
859 QMessageBox.StandardButton.No) == StandardButton.Yes.value()) {
860 ChangeFileEncryption.execute(dbPath, dbName, encryptCipher, null, Global.cipherPassword.toCharArray(), true);
861 Global.setDatabaseUrl(Global.getDatabaseUrl() + ";CIPHER="+encryptCipher);
862 QMessageBox.information(this, "Encryption Complete", "Encryption is complete");
864 } catch (SQLException e) {
869 // Decrypt the database upon shutdown
870 private void decryptOnShutdown() {
871 String dbPath= Global.getFileManager().getDbDirPath("");
872 String dbName = "NeverNote";
874 Statement st = conn.getConnection().createStatement();
875 st.execute("shutdown");
876 if (Global.getDatabaseUrl().toUpperCase().indexOf(";CIPHER=AES") > -1)
877 encryptCipher = "AES";
879 encryptCipher = "XTEA";
880 if (QMessageBox.question(this, tr("Confirmation"), tr("Are you sure",
881 "Are you sure you wish to decrypt the database?"),
882 QMessageBox.StandardButton.Yes,
883 QMessageBox.StandardButton.No) == StandardButton.Yes.value()) {
885 ChangeFileEncryption.execute(dbPath, dbName, encryptCipher, Global.cipherPassword.toCharArray(), null, true);
886 Global.setDatabaseUrl("");
887 QMessageBox.information(this, tr("Decryption Complete"), tr("Decryption is complete"));
889 } catch (SQLException e) {
894 * Encrypt/Decrypt the local database
896 public void doDatabaseEncrypt() {
897 // The database is not currently encrypted
898 if (Global.getDatabaseUrl().toUpperCase().indexOf("CIPHER=") == -1) {
899 if (QMessageBox.question(this, tr("Confirmation"), tr("Encrypting the database is used" +
900 "to enhance security and is performed\nupon shutdown, but please be aware that if"+
901 " you lose the password your\nis lost forever.\n\nIt is highly recommended you " +
902 "perform a backup and/or fully synchronize\n prior to executing this funtction.\n\n" +
903 "Do you wish to proceed?"),
904 QMessageBox.StandardButton.Yes,
905 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
908 DBEncryptDialog dialog = new DBEncryptDialog();
910 if (dialog.okPressed()) {
911 Global.cipherPassword = dialog.getPassword();
912 encryptOnShutdown = true;
913 encryptCipher = dialog.getEncryptionMethod();
916 DBEncryptDialog dialog = new DBEncryptDialog();
917 dialog.setWindowTitle("Database Decryption");
918 dialog.hideEncryption();
920 if (dialog.okPressed()) {
921 if (!dialog.getPassword().equals(Global.cipherPassword)) {
922 QMessageBox.critical(null, tr("Incorrect Password"), tr("Incorrect Password"));
925 decryptOnShutdown = true;
932 private static void initializeGlobalSettings(String[] args) throws InitializationException {
933 StartupConfig startupConfig = new StartupConfig();
935 for (String arg : args) {
936 String lower = arg.toLowerCase();
937 if (lower.startsWith("--name="))
938 startupConfig.setName(arg.substring(arg.indexOf('=') + 1));
939 if (lower.startsWith("--home="))
940 startupConfig.setHomeDirPath(arg.substring(arg.indexOf('=') + 1));
941 if (lower.startsWith("--disable-viewing"))
942 startupConfig.setDisableViewing(true);
944 Global.setup(startupConfig);
949 public void closeEvent(QCloseEvent event) {
950 if (Global.minimizeOnClose() && !closeAction && Global.showTrayIcon()) {
955 logger.log(logger.HIGH, "Entering NeverNote.closeEvent");
958 if (currentNote!= null & browserWindow!=null) {
959 if (!currentNote.getTitle().equals(browserWindow.getTitle()))
960 conn.getNoteTable().updateNoteTitle(currentNote.getGuid(), browserWindow.getTitle());
963 setMessage(tr("Beginning shutdown."));
965 // Close down external windows
966 Collection<ExternalBrowse> windows = externalWindows.values();
967 Iterator<ExternalBrowse> iterator = windows.iterator();
968 while (iterator.hasNext()) {
969 ExternalBrowse browser = iterator.next();
970 browser.windowClosing.disconnect();
975 externalFileEditedSaver();
976 if (Global.isConnected && Global.synchronizeOnClose()) {
977 setMessage(tr("Performing synchronization before closing."));
978 syncRunner.addWork("SYNC");
980 setMessage("Closing Program.");
981 threadMonitorTimer.stop();
983 syncRunner.addWork("STOP");
984 syncRunner.keepRunning = false;
985 thumbnailRunner.addWork("STOP");
986 syncRunner.keepRunning = false;
987 indexRunner.addWork("STOP");
988 syncRunner.keepRunning = false;
993 if (tempFiles != null)
996 browserWindow.noteSignal.tagsChanged.disconnect();
997 browserWindow.noteSignal.titleChanged.disconnect();
998 browserWindow.noteSignal.noteChanged.disconnect();
999 browserWindow.noteSignal.notebookChanged.disconnect();
1000 browserWindow.noteSignal.createdDateChanged.disconnect();
1001 browserWindow.noteSignal.alteredDateChanged.disconnect();
1002 syncRunner.searchSignal.listChanged.disconnect();
1003 syncRunner.tagSignal.listChanged.disconnect();
1004 syncRunner.notebookSignal.listChanged.disconnect();
1005 syncRunner.noteIndexSignal.listChanged.disconnect();
1008 Global.saveWindowVisible("toolBar", toolBar.isVisible());
1009 saveNoteColumnPositions();
1010 saveNoteIndexWidth();
1012 int width = notebookTree.columnWidth(0);
1013 Global.setColumnWidth("notebookTreeName", width);
1014 width = tagTree.columnWidth(0);
1015 Global.setColumnWidth("tagTreeName", width);
1017 Global.saveWindowMaximized(isMaximized());
1018 Global.saveCurrentNoteGuid(currentNoteGuid);
1020 int sortCol = noteTableView.proxyModel.sortColumn();
1021 int sortOrder = noteTableView.proxyModel.sortOrder().value();
1022 Global.setSortColumn(sortCol);
1023 Global.setSortOrder(sortOrder);
1027 Global.keepRunning = false;
1029 logger.log(logger.MEDIUM, "Waiting for indexThread to stop");
1030 if (indexRunner.thread().isAlive())
1031 indexRunner.thread().join(50);
1032 if (!indexRunner.thread().isAlive())
1033 logger.log(logger.MEDIUM, "Index thread has stopped");
1035 logger.log(logger.MEDIUM, "Index thread still running - bypassing");
1036 } catch (InterruptedException e1) {
1037 e1.printStackTrace();
1039 if (!syncRunner.isIdle()) {
1041 logger.log(logger.MEDIUM, "Waiting for syncThread to stop");
1043 logger.log(logger.MEDIUM, "Sync thread has stopped");
1044 } catch (InterruptedException e1) {
1045 e1.printStackTrace();
1049 if (encryptOnShutdown) {
1050 encryptOnShutdown();
1052 if (decryptOnShutdown) {
1053 decryptOnShutdown();
1055 logger.log(logger.HIGH, "Leaving NeverNote.closeEvent");
1058 @SuppressWarnings("unused")
1059 private void closeNeverNote() {
1063 public void setMessage(String s) {
1064 logger.log(logger.HIGH, "Entering NeverNote.setMessage");
1065 logger.log(logger.HIGH, "Message: " +s);
1066 statusBar.showMessage(s);
1068 logger.log(logger.HIGH, "Leaving NeverNote.setMessage");
1071 private void waitCursor(boolean wait) {
1073 if (QApplication.overrideCursor() == null)
1074 QApplication.setOverrideCursor(new QCursor(Qt.CursorShape.WaitCursor));
1077 while (QApplication.overrideCursor() != null)
1078 QApplication.restoreOverrideCursor();
1082 private void setupIndexListeners() {
1083 // indexRunner.noteSignal.noteIndexed.connect(this, "indexThreadComplete(String)");
1084 // indexRunner.resourceSignal.resourceIndexed.connect(this, "indexThreadComplete(String)");
1085 indexRunner.signal.indexStarted.connect(this, "indexStarted()");
1086 indexRunner.signal.indexFinished.connect(this, "indexComplete()");
1088 private void setupSyncSignalListeners() {
1089 syncRunner.tagSignal.listChanged.connect(this, "tagIndexUpdated()");
1090 syncRunner.searchSignal.listChanged.connect(this, "savedSearchIndexUpdated()");
1091 syncRunner.notebookSignal.listChanged.connect(this, "notebookIndexUpdated()");
1092 syncRunner.noteIndexSignal.listChanged.connect(this, "noteIndexUpdated(boolean)");
1093 syncRunner.noteSignal.quotaChanged.connect(this, "updateQuotaBar()");
1095 syncRunner.syncSignal.saveUploadAmount.connect(this,"saveUploadAmount(long)");
1096 syncRunner.syncSignal.saveUserInformation.connect(this,"saveUserInformation(User)");
1097 syncRunner.syncSignal.saveEvernoteUpdateCount.connect(this,"saveEvernoteUpdateCount(int)");
1099 syncRunner.noteSignal.guidChanged.connect(this, "noteGuidChanged(String, String)");
1100 syncRunner.noteSignal.noteChanged.connect(this, "invalidateNoteCache(String, String)");
1101 syncRunner.resourceSignal.resourceGuidChanged.connect(this, "noteResourceGuidChanged(String,String,String)");
1102 syncRunner.noteSignal.noteDownloaded.connect(listManager, "noteDownloaded(Note)");
1104 syncRunner.syncSignal.refreshLists.connect(this, "refreshLists()");
1107 private void setupBrowserSignalListeners() {
1108 setupBrowserWindowListeners(browserWindow, true);
1111 private void setupBrowserWindowListeners(BrowserWindow browser, boolean master) {
1112 browser.fileWatcher.fileChanged.connect(this, "externalFileEdited(String)");
1113 browser.noteSignal.tagsChanged.connect(this, "updateNoteTags(String, List)");
1114 browser.noteSignal.tagsChanged.connect(this, "updateListTags(String, List)");
1115 if (master) browser.noteSignal.noteChanged.connect(this, "setNoteDirty()");
1116 browser.noteSignal.titleChanged.connect(listManager, "updateNoteTitle(String, String)");
1117 browser.noteSignal.titleChanged.connect(this, "updateNoteTitle(String, String)");
1118 browser.noteSignal.notebookChanged.connect(this, "updateNoteNotebook(String, String)");
1119 browser.noteSignal.createdDateChanged.connect(listManager, "updateNoteCreatedDate(String, QDateTime)");
1120 browser.noteSignal.alteredDateChanged.connect(listManager, "updateNoteAlteredDate(String, QDateTime)");
1121 browser.noteSignal.subjectDateChanged.connect(listManager, "updateNoteSubjectDate(String, QDateTime)");
1122 browser.noteSignal.authorChanged.connect(listManager, "updateNoteAuthor(String, String)");
1123 browser.noteSignal.geoChanged.connect(listManager, "updateNoteGeoTag(String, Double,Double,Double)");
1124 browser.noteSignal.geoChanged.connect(this, "setNoteDirty()");
1125 browser.noteSignal.sourceUrlChanged.connect(listManager, "updateNoteSourceUrl(String, String)");
1126 if (master) browser.focusLost.connect(this, "saveNote()");
1127 browser.resourceSignal.contentChanged.connect(this, "externalFileEdited(String)");
1130 //***************************************************************
1131 //***************************************************************
1132 //* Settings and look & feel
1133 //***************************************************************
1134 //***************************************************************
1135 @SuppressWarnings("unused")
1136 private void settings() {
1137 logger.log(logger.HIGH, "Entering NeverNote.settings");
1138 saveNoteColumnPositions();
1139 saveNoteIndexWidth();
1141 ConfigDialog settings = new ConfigDialog(this);
1142 String dateFormat = Global.getDateFormat();
1143 String timeFormat = Global.getTimeFormat();
1145 indexTime = 1000*Global.getIndexThreadSleepInterval();
1146 indexTimer.start(indexTime); // reset indexing timer
1149 indexRunner.indexAttachmentsLocally = Global.indexAttachmentsLocally();
1150 if (Global.showTrayIcon())
1155 if (menuBar.showEditorBar.isChecked())
1156 showEditorButtons(browserWindow);
1158 // Reset the save timer
1159 if (Global.getAutoSaveInterval() > 0)
1160 saveTimer.setInterval(1000*60*Global.getAutoSaveInterval());
1164 // This is a hack to force a reload of the index in case the date or time changed.
1165 // if (!dateFormat.equals(Global.getDateFormat()) ||
1166 // !timeFormat.equals(Global.getTimeFormat())) {
1168 readOnlyCache.clear();
1169 inkNoteCache.clear();
1170 noteIndexUpdated(true);
1173 logger.log(logger.HIGH, "Leaving NeverNote.settings");
1175 // Restore things to the way they were
1176 private void restoreWindowState(boolean mainWindow) {
1177 // We need to name things or this doesn't work.
1178 setObjectName("NeverNote");
1179 mainLeftRightSplitter.setObjectName("mainLeftRightSplitter");
1180 browserIndexSplitter.setObjectName("browserIndexSplitter");
1181 leftSplitter1.setObjectName("leftSplitter1");
1183 // Restore the actual positions.
1185 restoreGeometry(Global.restoreGeometry(objectName()));
1186 mainLeftRightSplitter.restoreState(Global.restoreState(mainLeftRightSplitter.objectName()));
1187 browserIndexSplitter.restoreState(Global.restoreState(browserIndexSplitter.objectName()));
1188 leftSplitter1.restoreState(Global.restoreState(leftSplitter1.objectName()));
1191 // Save window positions for the next start
1192 private void saveWindowState() {
1193 Global.saveGeometry(objectName(), saveGeometry());
1194 Global.saveState(mainLeftRightSplitter.objectName(), mainLeftRightSplitter.saveState());
1195 Global.saveState(browserIndexSplitter.objectName(), browserIndexSplitter.saveState());
1196 Global.saveState(leftSplitter1.objectName(), leftSplitter1.saveState());
1198 // Load the style sheet
1199 private void loadStyleSheet() {
1200 String fileName = Global.getFileManager().getQssDirPath("default.qss");
1201 QFile file = new QFile(fileName);
1202 file.open(OpenModeFlag.ReadOnly);
1203 String styleSheet = file.readAll().toString();
1205 setStyleSheet(styleSheet);
1207 // Save column positions for the next time
1208 private void saveNoteColumnPositions() {
1209 int position = noteTableView.header.visualIndex(Global.noteTableCreationPosition);
1210 Global.setColumnPosition("noteTableCreationPosition", position);
1211 position = noteTableView.header.visualIndex(Global.noteTableTagPosition);
1212 Global.setColumnPosition("noteTableTagPosition", position);
1213 position = noteTableView.header.visualIndex(Global.noteTableNotebookPosition);
1214 Global.setColumnPosition("noteTableNotebookPosition", position);
1215 position = noteTableView.header.visualIndex(Global.noteTableChangedPosition);
1216 Global.setColumnPosition("noteTableChangedPosition", position);
1217 position = noteTableView.header.visualIndex(Global.noteTableAuthorPosition);
1218 Global.setColumnPosition("noteTableAuthorPosition", position);
1219 position = noteTableView.header.visualIndex(Global.noteTableSourceUrlPosition);
1220 Global.setColumnPosition("noteTableSourceUrlPosition", position);
1221 position = noteTableView.header.visualIndex(Global.noteTableSubjectDatePosition);
1222 Global.setColumnPosition("noteTableSubjectDatePosition", position);
1223 position = noteTableView.header.visualIndex(Global.noteTableTitlePosition);
1224 Global.setColumnPosition("noteTableTitlePosition", position);
1225 position = noteTableView.header.visualIndex(Global.noteTableSynchronizedPosition);
1226 Global.setColumnPosition("noteTableSynchronizedPosition", position);
1227 position = noteTableView.header.visualIndex(Global.noteTableGuidPosition);
1228 Global.setColumnPosition("noteTableGuidPosition", position);
1229 position = noteTableView.header.visualIndex(Global.noteTableThumbnailPosition);
1230 Global.setColumnPosition("noteTableThumbnailPosition", position);
1233 // Save column widths for the next time
1234 private void saveNoteIndexWidth() {
1236 width = noteTableView.getColumnWidth(Global.noteTableCreationPosition);
1237 Global.setColumnWidth("noteTableCreationPosition", width);
1238 width = noteTableView.getColumnWidth(Global.noteTableChangedPosition);
1239 Global.setColumnWidth("noteTableChangedPosition", width);
1240 width = noteTableView.getColumnWidth(Global.noteTableGuidPosition);
1241 Global.setColumnWidth("noteTableGuidPosition", width);
1242 width = noteTableView.getColumnWidth(Global.noteTableNotebookPosition);
1243 Global.setColumnWidth("noteTableNotebookPosition", width);
1244 width = noteTableView.getColumnWidth(Global.noteTableTagPosition);
1245 Global.setColumnWidth("noteTableTagPosition", width);
1246 width = noteTableView.getColumnWidth(Global.noteTableTitlePosition);
1247 Global.setColumnWidth("noteTableTitlePosition", width);
1248 width = noteTableView.getColumnWidth(Global.noteTableSourceUrlPosition);
1249 Global.setColumnWidth("noteTableSourceUrlPosition", width);
1250 width = noteTableView.getColumnWidth(Global.noteTableAuthorPosition);
1251 Global.setColumnWidth("noteTableAuthorPosition", width);
1252 width = noteTableView.getColumnWidth(Global.noteTableSubjectDatePosition);
1253 Global.setColumnWidth("noteTableSubjectDatePosition", width);
1254 width = noteTableView.getColumnWidth(Global.noteTableSynchronizedPosition);
1255 Global.setColumnWidth("noteTableSynchronizedPosition", width);
1256 width = noteTableView.getColumnWidth(Global.noteTableThumbnailPosition);
1257 Global.setColumnWidth("noteTableThumbnailPosition", width);
1258 width = noteTableView.getColumnWidth(Global.noteTableGuidPosition);
1259 Global.setColumnWidth("noteTableGuidPosition", width);
1263 //***************************************************************
1264 //***************************************************************
1265 //** These functions deal with Notebook menu items
1266 //***************************************************************
1267 //***************************************************************
1268 // Setup the tree containing the user's notebooks.
1269 private void initializeNotebookTree() {
1270 logger.log(logger.HIGH, "Entering NeverNote.initializeNotebookTree");
1271 // notebookTree.itemClicked.connect(this, "notebookTreeSelection()");
1272 notebookTree.selectionSignal.connect(this, "notebookTreeSelection()");
1273 listManager.notebookSignal.refreshNotebookTreeCounts.connect(notebookTree, "updateCounts(List, List)");
1274 logger.log(logger.HIGH, "Leaving NeverNote.initializeNotebookTree");
1276 // Listener when a notebook is selected
1277 private void notebookTreeSelection() {
1278 logger.log(logger.HIGH, "Entering NeverNote.notebookTreeSelection");
1281 clearAttributeFilter();
1282 clearSavedSearchFilter();
1283 if (Global.mimicEvernoteInterface) {
1285 searchField.clear();
1287 menuBar.noteRestoreAction.setVisible(false);
1288 menuBar.notebookEditAction.setEnabled(true);
1289 menuBar.notebookDeleteAction.setEnabled(true);
1290 menuBar.notebookPublishAction.setEnabled(true);
1291 menuBar.notebookShareAction.setEnabled(true);
1292 menuBar.notebookIconAction.setEnabled(true);
1293 menuBar.notebookStackAction.setEnabled(true);
1294 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1295 selectedNotebookGUIDs.clear();
1297 String stackName = "";
1298 if (selections.size() > 0) {
1299 guid = (selections.get(0).text(2));
1300 stackName = selections.get(0).text(0);
1302 if (!Global.mimicEvernoteInterface) {
1303 // If no notebooks are selected, we make it look like the "all notebooks" one was selected
1304 if (selections.size()==0) {
1305 selectedNotebookGUIDs.clear();
1306 for (int i=0; i < listManager.getNotebookIndex().size(); i++) {
1307 selectedNotebookGUIDs.add(listManager.getNotebookIndex().get(i).getGuid());
1309 menuBar.notebookEditAction.setEnabled(false);
1310 menuBar.notebookDeleteAction.setEnabled(false);
1311 menuBar.notebookStackAction.setEnabled(false);
1312 menuBar.notebookIconAction.setEnabled(false);
1315 if (!guid.equals("") && !guid.equals("STACK")) {
1316 selectedNotebookGUIDs.add(guid);
1317 menuBar.notebookIconAction.setEnabled(true);
1319 menuBar.notebookIconAction.setEnabled(true);
1320 for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
1321 Notebook book = listManager.getNotebookIndex().get(j);
1322 if (book.getStack() != null && book.getStack().equalsIgnoreCase(stackName))
1323 selectedNotebookGUIDs.add(book.getGuid());
1326 listManager.setSelectedNotebooks(selectedNotebookGUIDs);
1327 listManager.loadNotesIndex();
1328 noteIndexUpdated(false);
1329 logger.log(logger.HIGH, "Leaving NeverNote.notebookTreeSelection");
1332 private void clearNotebookFilter() {
1333 notebookTree.blockSignals(true);
1334 notebookTree.clearSelection();
1335 menuBar.noteRestoreAction.setVisible(false);
1336 menuBar.notebookEditAction.setEnabled(false);
1337 menuBar.notebookDeleteAction.setEnabled(false);
1338 selectedNotebookGUIDs.clear();
1339 listManager.setSelectedNotebooks(selectedNotebookGUIDs);
1340 notebookTree.blockSignals(false);
1342 // Triggered when the notebook DB has been updated
1343 private void notebookIndexUpdated() {
1344 logger.log(logger.HIGH, "Entering NeverNote.notebookIndexUpdated");
1346 // Get the possible icons
1347 HashMap<String, QIcon> icons = conn.getNotebookTable().getAllIcons();
1348 notebookTree.setIcons(icons);
1350 if (selectedNotebookGUIDs == null)
1351 selectedNotebookGUIDs = new ArrayList<String>();
1352 List<Notebook> books = conn.getNotebookTable().getAll();
1353 for (int i=books.size()-1; i>=0; i--) {
1354 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1355 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(books.get(i).getGuid())) {
1357 j=listManager.getArchiveNotebookIndex().size();
1363 listManager.countNotebookResults(listManager.getNoteIndex());
1364 notebookTree.blockSignals(true);
1365 notebookTree.load(books, listManager.getLocalNotebooks());
1366 for (int i=selectedNotebookGUIDs.size()-1; i>=0; i--) {
1367 boolean found = notebookTree.selectGuid(selectedNotebookGUIDs.get(i));
1369 selectedNotebookGUIDs.remove(i);
1371 notebookTree.blockSignals(false);
1373 logger.log(logger.HIGH, "Leaving NeverNote.notebookIndexUpdated");
1375 // Show/Hide note information
1376 private void toggleNotebookWindow() {
1377 logger.log(logger.HIGH, "Entering NeverNote.toggleNotebookWindow");
1378 if (notebookTree.isVisible())
1379 notebookTree.hide();
1381 notebookTree.show();
1382 menuBar.hideNotebooks.setChecked(notebookTree.isVisible());
1383 Global.saveWindowVisible("notebookTree", notebookTree.isVisible());
1384 logger.log(logger.HIGH, "Leaving NeverNote.toggleNotebookWindow");
1386 // Add a new notebook
1387 @SuppressWarnings("unused")
1388 private void addNotebook() {
1389 logger.log(logger.HIGH, "Inside NeverNote.addNotebook");
1390 NotebookEdit edit = new NotebookEdit();
1391 edit.setNotebooks(listManager.getNotebookIndex());
1394 if (!edit.okPressed())
1397 Calendar currentTime = new GregorianCalendar();
1398 Long l = new Long(currentTime.getTimeInMillis());
1399 String randint = new String(Long.toString(l));
1401 Notebook newBook = new Notebook();
1402 newBook.setUpdateSequenceNum(0);
1403 newBook.setGuid(randint);
1404 newBook.setName(edit.getNotebook());
1405 newBook.setServiceCreated(new Date().getTime());
1406 newBook.setServiceUpdated(new Date().getTime());
1407 newBook.setDefaultNotebook(false);
1408 newBook.setPublished(false);
1410 listManager.getNotebookIndex().add(newBook);
1412 listManager.getLocalNotebooks().add(newBook.getGuid());
1413 conn.getNotebookTable().addNotebook(newBook, true, edit.isLocal());
1414 notebookIndexUpdated();
1415 listManager.countNotebookResults(listManager.getNoteIndex());
1416 // notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
1417 logger.log(logger.HIGH, "Leaving NeverNote.addNotebook");
1419 // Edit an existing notebook
1420 @SuppressWarnings("unused")
1421 private void stackNotebook() {
1422 logger.log(logger.HIGH, "Entering NeverNote.stackNotebook");
1423 StackNotebook edit = new StackNotebook();
1425 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1426 QTreeWidgetItem currentSelection;
1427 for (int i=0; i<selections.size(); i++) {
1428 currentSelection = selections.get(0);
1429 String guid = currentSelection.text(2);
1430 if (guid.equalsIgnoreCase("")) {
1431 QMessageBox.critical(this, tr("Unable To Stack") ,tr("You can't stack the \"All Notebooks\" item."));
1434 if (guid.equalsIgnoreCase("STACK")) {
1435 QMessageBox.critical(this, tr("Unable To Stack") ,tr("You can't stack a stack."));
1440 edit.setStackNames(conn.getNotebookTable().getAllStackNames());
1445 if (!edit.okPressed())
1448 String stack = edit.getStackName();
1450 for (int i=0; i<selections.size(); i++) {
1451 currentSelection = selections.get(i);
1452 String guid = currentSelection.text(2);
1453 listManager.updateNotebookStack(guid, stack);
1455 notebookIndexUpdated();
1456 logger.log(logger.HIGH, "Leaving NeverNote.stackNotebook");
1458 // Edit an existing notebook
1459 @SuppressWarnings("unused")
1460 private void editNotebook() {
1461 logger.log(logger.HIGH, "Entering NeverNote.editNotebook");
1462 NotebookEdit edit = new NotebookEdit();
1464 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1465 QTreeWidgetItem currentSelection;
1466 currentSelection = selections.get(0);
1467 edit.setNotebook(currentSelection.text(0));
1469 String guid = currentSelection.text(2);
1470 if (!guid.equalsIgnoreCase("STACK")) {
1471 edit.setTitle(tr("Edit Notebook"));
1472 edit.setNotebooks(listManager.getNotebookIndex());
1473 edit.setLocalCheckboxEnabled(false);
1474 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1475 if (listManager.getNotebookIndex().get(i).getGuid().equals(guid)) {
1476 edit.setDefaultNotebook(listManager.getNotebookIndex().get(i).isDefaultNotebook());
1477 i=listManager.getNotebookIndex().size();
1481 edit.setTitle(tr("Edit Stack"));
1482 edit.setStacks(conn.getNotebookTable().getAllStackNames());
1483 edit.hideLocalCheckbox();
1484 edit.hideDefaultCheckbox();
1489 if (!edit.okPressed())
1493 if (guid.equalsIgnoreCase("STACK")) {
1494 conn.getNotebookTable().renameStacks(currentSelection.text(0), edit.getNotebook());
1495 for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
1496 if (listManager.getNotebookIndex().get(j).getStack().equalsIgnoreCase(currentSelection.text(0)))
1497 listManager.getNotebookIndex().get(j).setStack(edit.getNotebook());
1499 conn.getNotebookTable().renameStacks(currentSelection.text(0), edit.getNotebook());
1500 currentSelection.setText(0, edit.getNotebook());
1504 updateListNotebookName(currentSelection.text(0), edit.getNotebook());
1505 currentSelection.setText(0, edit.getNotebook());
1507 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1508 if (listManager.getNotebookIndex().get(i).getGuid().equals(guid)) {
1509 listManager.getNotebookIndex().get(i).setName(edit.getNotebook());
1510 if (!listManager.getNotebookIndex().get(i).isDefaultNotebook() && edit.isDefaultNotebook()) {
1511 for (int j=0; j<listManager.getNotebookIndex().size(); j++)
1512 listManager.getNotebookIndex().get(j).setDefaultNotebook(false);
1513 listManager.getNotebookIndex().get(i).setDefaultNotebook(true);
1514 conn.getNotebookTable().setDefaultNotebook(listManager.getNotebookIndex().get(i).getGuid());
1516 conn.getNotebookTable().updateNotebook(listManager.getNotebookIndex().get(i), true);
1517 if (conn.getNotebookTable().isLinked(listManager.getNotebookIndex().get(i).getGuid())) {
1518 LinkedNotebook linkedNotebook = conn.getLinkedNotebookTable().getByNotebookGuid(listManager.getNotebookIndex().get(i).getGuid());
1519 linkedNotebook.setShareName(edit.getNotebook());
1520 conn.getLinkedNotebookTable().updateNotebook(linkedNotebook, true);
1522 i=listManager.getNotebookIndex().size();
1526 // Build a list of non-closed notebooks
1527 List<Notebook> nbooks = new ArrayList<Notebook>();
1528 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1529 boolean found=false;
1530 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1531 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
1535 nbooks.add(listManager.getNotebookIndex().get(i));
1539 FilterEditorNotebooks notebookFilter = new FilterEditorNotebooks(conn, logger);
1540 List<Notebook> filteredBooks = notebookFilter.getValidNotebooks(currentNote, listManager.getNotebookIndex());
1541 browserWindow.setNotebookList(filteredBooks);
1542 Iterator<String> set = externalWindows.keySet().iterator();
1543 while(set.hasNext())
1544 externalWindows.get(set.next()).getBrowserWindow().setNotebookList(filteredBooks);
1545 logger.log(logger.HIGH, "Leaving NeverNote.editNotebook");
1547 // Publish a notebook
1548 @SuppressWarnings("unused")
1549 private void publishNotebook() {
1550 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1551 QTreeWidgetItem currentSelection;
1552 currentSelection = selections.get(0);
1553 String guid = currentSelection.text(2);
1555 if (guid.equalsIgnoreCase("STACK") || guid.equalsIgnoreCase(""))
1560 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1561 if (guid.equals(listManager.getNotebookIndex().get(i).getGuid())) {
1562 n = listManager.getNotebookIndex().get(i);
1564 i = listManager.getNotebookIndex().size();
1570 PublishNotebook publish = new PublishNotebook(Global.username, Global.getServer(), n);
1573 if (!publish.okClicked())
1576 Publishing p = publish.getPublishing();
1577 boolean isPublished = !publish.isStopPressed();
1578 conn.getNotebookTable().setPublishing(n.getGuid(), isPublished, p);
1579 n.setPublished(isPublished);
1581 listManager.getNotebookIndex().set(position, n);
1582 notebookIndexUpdated();
1584 // Publish a notebook
1585 @SuppressWarnings("unused")
1586 private void shareNotebook() {
1587 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1588 QTreeWidgetItem currentSelection;
1589 currentSelection = selections.get(0);
1590 String guid = currentSelection.text(2);
1592 if (guid.equalsIgnoreCase("STACK") || guid.equalsIgnoreCase(""))
1596 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1597 if (guid.equals(listManager.getNotebookIndex().get(i).getGuid())) {
1598 n = listManager.getNotebookIndex().get(i);
1599 i = listManager.getNotebookIndex().size();
1603 String authToken = null;
1604 if (syncRunner.isConnected)
1605 authToken = syncRunner.authToken;
1606 ShareNotebook share = new ShareNotebook(n.getName(), conn, n, syncRunner);
1611 // Delete an existing notebook
1612 @SuppressWarnings("unused")
1613 private void deleteNotebook() {
1614 logger.log(logger.HIGH, "Entering NeverNote.deleteNotebook");
1615 boolean stacksFound = false;
1616 boolean notebooksFound = false;
1617 boolean assigned = false;
1618 // Check if any notes have this notebook
1619 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1620 for (int i=0; i<selections.size(); i++) {
1621 QTreeWidgetItem currentSelection;
1622 currentSelection = selections.get(i);
1623 String guid = currentSelection.text(2);
1624 if (!guid.equalsIgnoreCase("STACK")) {
1625 notebooksFound = true;
1626 for (int j=0; j<listManager.getNoteIndex().size(); j++) {
1627 String noteGuid = listManager.getNoteIndex().get(j).getNotebookGuid();
1628 if (noteGuid.equals(guid)) {
1630 j=listManager.getNoteIndex().size();
1631 i=selections.size();
1639 QMessageBox.information(this, tr("Unable to Delete"), tr("Some of the selected notebook(s) contain notes.\n"+
1640 "Please delete the notes or move them to another notebook before deleting any notebooks."));
1644 if (conn.getNotebookTable().getAll().size() == 1) {
1645 QMessageBox.information(this, tr("Unable to Delete"), tr("You must have at least one notebook."));
1649 // If all notebooks are clear, verify the delete
1650 String msg1 = new String(tr("Delete selected notebooks?"));
1651 String msg2 = new String(tr("Remove selected stacks (notebooks will not be deleted)?"));
1652 String msg3 = new String(tr("Delete selected notebooks & remove stacks? Notebooks under the stacks are" +
1653 " not deleted unless selected?"));
1655 if (stacksFound && notebooksFound)
1657 if (!stacksFound && notebooksFound)
1659 if (stacksFound && !notebooksFound)
1661 if (QMessageBox.question(this, tr("Confirmation"), msg,
1662 QMessageBox.StandardButton.Yes,
1663 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
1667 // If confirmed, delete the notebook
1668 for (int i=selections.size()-1; i>=0; i--) {
1669 QTreeWidgetItem currentSelection;
1670 currentSelection = selections.get(i);
1671 String guid = currentSelection.text(2);
1672 if (currentSelection.text(2).equalsIgnoreCase("STACK")) {
1673 conn.getNotebookTable().renameStacks(currentSelection.text(0), "");
1674 listManager.renameStack(currentSelection.text(0), "");
1676 conn.getNotebookTable().expungeNotebook(guid, true);
1677 listManager.deleteNotebook(guid);
1681 notebookIndexUpdated();
1682 // notebookTreeSelection();
1683 // notebookTree.load(listManager.getNotebookIndex(), listManager.getLocalNotebooks());
1684 // listManager.countNotebookResults(listManager.getNoteIndex());
1685 logger.log(logger.HIGH, "Entering NeverNote.deleteNotebook");
1687 // A note's notebook has been updated
1688 @SuppressWarnings("unused")
1689 private void updateNoteNotebook(String guid, String notebookGuid) {
1691 // Update the list manager
1692 listManager.updateNoteNotebook(guid, notebookGuid);
1693 listManager.countNotebookResults(listManager.getNoteIndex());
1694 // notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
1696 // Find the name of the notebook
1697 String notebookName = null;
1698 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1699 if (listManager.getNotebookIndex().get(i).getGuid().equals(notebookGuid)) {
1700 notebookName = listManager.getNotebookIndex().get(i).getName();
1705 // If we found the name, update the browser window
1706 if (notebookName != null) {
1707 updateListNoteNotebook(guid, notebookName);
1708 if (guid.equals(currentNoteGuid)) {
1709 int pos = browserWindow.notebookBox.findText(notebookName);
1711 browserWindow.notebookBox.setCurrentIndex(pos);
1715 // If we're dealing with the current note, then we need to be sure and update the notebook there
1716 if (guid.equals(currentNoteGuid)) {
1717 if (currentNote != null) {
1718 currentNote.setNotebookGuid(notebookGuid);
1722 // Open/close notebooks
1723 @SuppressWarnings("unused")
1724 private void closeNotebooks() {
1725 NotebookArchive na = new NotebookArchive(listManager.getNotebookIndex(), listManager.getArchiveNotebookIndex());
1727 if (!na.okClicked())
1731 listManager.getArchiveNotebookIndex().clear();
1733 for (int i=na.getClosedBookList().count()-1; i>=0; i--) {
1734 String text = na.getClosedBookList().takeItem(i).text();
1735 for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
1736 if (listManager.getNotebookIndex().get(j).getName().equalsIgnoreCase(text)) {
1737 Notebook n = listManager.getNotebookIndex().get(j);
1738 conn.getNotebookTable().setArchived(n.getGuid(),true);
1739 listManager.getArchiveNotebookIndex().add(n);
1740 j=listManager.getNotebookIndex().size();
1745 for (int i=na.getOpenBookList().count()-1; i>=0; i--) {
1746 String text = na.getOpenBookList().takeItem(i).text();
1747 for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
1748 if (listManager.getNotebookIndex().get(j).getName().equalsIgnoreCase(text)) {
1749 Notebook n = listManager.getNotebookIndex().get(j);
1750 conn.getNotebookTable().setArchived(n.getGuid(),false);
1751 j=listManager.getNotebookIndex().size();
1755 notebookTreeSelection();
1756 listManager.loadNotesIndex();
1757 notebookIndexUpdated();
1758 noteIndexUpdated(false);
1759 reloadTagTree(true);
1760 // noteIndexUpdated(false);
1762 // Build a list of non-closed notebooks
1763 List<Notebook> nbooks = new ArrayList<Notebook>();
1764 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1765 boolean found=false;
1766 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1767 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
1771 nbooks.add(listManager.getNotebookIndex().get(i));
1774 FilterEditorNotebooks notebookFilter = new FilterEditorNotebooks(conn, logger);
1775 List<Notebook> filteredBooks = notebookFilter.getValidNotebooks(currentNote, listManager.getNotebookIndex());
1776 browserWindow.setNotebookList(filteredBooks);
1778 // Update any external windows
1779 Iterator<String> set = externalWindows.keySet().iterator();
1780 while(set.hasNext())
1781 externalWindows.get(set.next()).getBrowserWindow().setNotebookList(filteredBooks);
1785 // Change the notebook's icon
1786 @SuppressWarnings("unused")
1787 private void setNotebookIcon() {
1788 boolean stackSelected = false;
1789 boolean allNotebookSelected = false;
1791 QTreeWidgetItem currentSelection;
1792 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1793 if (selections.size() == 0)
1796 currentSelection = selections.get(0);
1797 String guid = currentSelection.text(2);
1798 if (guid.equalsIgnoreCase(""))
1799 allNotebookSelected = true;
1800 if (guid.equalsIgnoreCase("STACK"))
1801 stackSelected = true;
1803 QIcon currentIcon = currentSelection.icon(0);
1807 if (!stackSelected && !allNotebookSelected) {
1808 icon = conn.getNotebookTable().getIcon(guid);
1810 dialog = new SetIcon(currentIcon);
1811 dialog.setUseDefaultIcon(true);
1813 dialog = new SetIcon(icon);
1814 dialog.setUseDefaultIcon(false);
1817 if (stackSelected) {
1818 icon = conn.getSystemIconTable().getIcon(currentSelection.text(0), "STACK");
1820 icon = conn.getSystemIconTable().getIcon(currentSelection.text(0), "ALLNOTEBOOK");
1823 dialog = new SetIcon(currentIcon);
1824 dialog.setUseDefaultIcon(true);
1826 dialog = new SetIcon(icon);
1827 dialog.setUseDefaultIcon(false);
1831 if (dialog.okPressed()) {
1832 QIcon newIcon = dialog.getIcon();
1833 if (stackSelected) {
1834 conn.getSystemIconTable().setIcon(currentSelection.text(0), "STACK", newIcon, dialog.getFileType());
1835 if (newIcon == null) {
1836 newIcon = new QIcon(iconPath+"books2.png");
1838 currentSelection.setIcon(0,newIcon);
1841 if (allNotebookSelected) {
1842 conn.getSystemIconTable().setIcon(currentSelection.text(0), "ALLNOTEBOOK", newIcon, dialog.getFileType());
1843 if (newIcon == null) {
1844 newIcon = new QIcon(iconPath+"notebook-green.png");
1846 currentSelection.setIcon(0,newIcon);
1849 conn.getNotebookTable().setIcon(guid, newIcon, dialog.getFileType());
1850 if (newIcon == null) {
1851 boolean isPublished = false;;
1852 boolean found = false;
1853 for (int i=0; i<listManager.getNotebookIndex().size() && !found; i++) {
1854 if (listManager.getNotebookIndex().get(i).getGuid().equals(guid)) {
1855 isPublished = listManager.getNotebookIndex().get(i).isPublished();
1859 newIcon = notebookTree.findDefaultIcon(guid, currentSelection.text(1), listManager.getLocalNotebooks(), isPublished);
1861 currentSelection.setIcon(0, newIcon);
1867 //***************************************************************
1868 //***************************************************************
1869 //** These functions deal with Tag menu items
1870 //***************************************************************
1871 //***************************************************************
1872 // Add a new notebook
1873 @SuppressWarnings("unused")
1874 private void addTag() {
1875 logger.log(logger.HIGH, "Inside NeverNote.addTag");
1876 TagEdit edit = new TagEdit();
1877 edit.setTagList(listManager.getTagIndex());
1880 if (!edit.okPressed())
1883 Calendar currentTime = new GregorianCalendar();
1884 Long l = new Long(currentTime.getTimeInMillis());
1885 String randint = new String(Long.toString(l));
1887 Tag newTag = new Tag();
1888 newTag.setUpdateSequenceNum(0);
1889 newTag.setGuid(randint);
1890 newTag.setName(edit.getTag());
1891 conn.getTagTable().addTag(newTag, true);
1892 listManager.getTagIndex().add(newTag);
1893 reloadTagTree(true);
1895 logger.log(logger.HIGH, "Leaving NeverNote.addTag");
1897 @SuppressWarnings("unused")
1898 private void reloadTagTree() {
1899 reloadTagTree(false);
1901 private void reloadTagTree(boolean reload) {
1902 logger.log(logger.HIGH, "Entering NeverNote.reloadTagTree");
1903 tagIndexUpdated(reload);
1904 boolean filter = false;
1905 listManager.countTagResults(listManager.getNoteIndex());
1906 if (notebookTree.selectedItems().size() > 0
1907 && !notebookTree.selectedItems().get(0).text(0).equalsIgnoreCase("All Notebooks"))
1909 if (tagTree.selectedItems().size() > 0)
1911 tagTree.showAllTags(!filter);
1912 logger.log(logger.HIGH, "Leaving NeverNote.reloadTagTree");
1914 // Edit an existing tag
1915 @SuppressWarnings("unused")
1916 private void editTag() {
1917 logger.log(logger.HIGH, "Entering NeverNote.editTag");
1918 TagEdit edit = new TagEdit();
1919 edit.setTitle("Edit Tag");
1920 List<QTreeWidgetItem> selections = tagTree.selectedItems();
1921 QTreeWidgetItem currentSelection;
1922 currentSelection = selections.get(0);
1923 edit.setTag(currentSelection.text(0));
1924 edit.setTagList(listManager.getTagIndex());
1927 if (!edit.okPressed())
1930 String guid = currentSelection.text(2);
1931 currentSelection.setText(0,edit.getTag());
1933 for (int i=0; i<listManager.getTagIndex().size(); i++) {
1934 if (listManager.getTagIndex().get(i).getGuid().equals(guid)) {
1935 listManager.getTagIndex().get(i).setName(edit.getTag());
1936 conn.getTagTable().updateTag(listManager.getTagIndex().get(i), true);
1937 updateListTagName(guid);
1938 if (currentNote != null && currentNote.getTagGuids().contains(guid))
1939 browserWindow.setTag(getTagNamesForNote(currentNote));
1940 logger.log(logger.HIGH, "Leaving NeverNote.editTag");
1944 browserWindow.setTag(getTagNamesForNote(currentNote));
1945 logger.log(logger.HIGH, "Leaving NeverNote.editTag...");
1947 // Delete an existing tag
1948 @SuppressWarnings("unused")
1949 private void deleteTag() {
1950 logger.log(logger.HIGH, "Entering NeverNote.deleteTag");
1952 if (QMessageBox.question(this, tr("Confirmation"), tr("Delete the selected tags?"),
1953 QMessageBox.StandardButton.Yes,
1954 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
1958 List<QTreeWidgetItem> selections = tagTree.selectedItems();
1959 for (int i=selections.size()-1; i>=0; i--) {
1960 QTreeWidgetItem currentSelection;
1961 currentSelection = selections.get(i);
1962 removeTagItem(currentSelection.text(2));
1964 tagIndexUpdated(true);
1966 listManager.countTagResults(listManager.getNoteIndex());
1967 // tagTree.updateCounts(listManager.getTagCounter());
1968 logger.log(logger.HIGH, "Leaving NeverNote.deleteTag");
1970 // Remove a tag tree item. Go recursively down & remove the children too
1971 private void removeTagItem(String guid) {
1972 for (int j=listManager.getTagIndex().size()-1; j>=0; j--) {
1973 String parent = listManager.getTagIndex().get(j).getParentGuid();
1974 if (parent != null && parent.equals(guid)) {
1975 //Remove this tag's children
1976 removeTagItem(listManager.getTagIndex().get(j).getGuid());
1979 //Now, remove this tag
1980 removeListTagName(guid);
1981 conn.getTagTable().expungeTag(guid, true);
1982 for (int a=0; a<listManager.getTagIndex().size(); a++) {
1983 if (listManager.getTagIndex().get(a).getGuid().equals(guid)) {
1984 listManager.getTagIndex().remove(a);
1989 // Setup the tree containing the user's tags
1990 private void initializeTagTree() {
1991 logger.log(logger.HIGH, "Entering NeverNote.initializeTagTree");
1992 // tagTree.itemSelectionChanged.connect(this, "tagTreeSelection()");
1993 // tagTree.itemClicked.connect(this, "tagTreeSelection()");
1994 tagTree.selectionSignal.connect(this, "tagTreeSelection()");
1995 listManager.tagSignal.refreshTagTreeCounts.connect(tagTree, "updateCounts(List)");
1996 logger.log(logger.HIGH, "Leaving NeverNote.initializeTagTree");
1998 // Listener when a tag is selected
1999 private void tagTreeSelection() {
2000 logger.log(logger.HIGH, "Entering NeverNote.tagTreeSelection");
2003 clearAttributeFilter();
2004 clearSavedSearchFilter();
2006 menuBar.noteRestoreAction.setVisible(false);
2008 List<QTreeWidgetItem> selections = tagTree.selectedItems();
2009 QTreeWidgetItem currentSelection;
2010 selectedTagGUIDs.clear();
2011 for (int i=0; i<selections.size(); i++) {
2012 currentSelection = selections.get(i);
2013 selectedTagGUIDs.add(currentSelection.text(2));
2015 if (selections.size() > 0) {
2016 menuBar.tagEditAction.setEnabled(true);
2017 menuBar.tagDeleteAction.setEnabled(true);
2018 menuBar.tagIconAction.setEnabled(true);
2021 menuBar.tagEditAction.setEnabled(false);
2022 menuBar.tagDeleteAction.setEnabled(false);
2023 menuBar.tagIconAction.setEnabled(true);
2025 listManager.setSelectedTags(selectedTagGUIDs);
2026 listManager.loadNotesIndex();
2027 noteIndexUpdated(false);
2028 logger.log(logger.HIGH, "Leaving NeverNote.tagTreeSelection");
2030 // trigger the tag index to be refreshed
2031 @SuppressWarnings("unused")
2032 private void tagIndexUpdated() {
2033 tagIndexUpdated(true);
2035 private void tagIndexUpdated(boolean reload) {
2036 logger.log(logger.HIGH, "Entering NeverNote.tagIndexUpdated");
2037 if (selectedTagGUIDs == null)
2038 selectedTagGUIDs = new ArrayList<String>();
2040 listManager.reloadTagIndex();
2042 tagTree.blockSignals(true);
2044 tagTree.setIcons(conn.getTagTable().getAllIcons());
2045 tagTree.load(listManager.getTagIndex());
2047 for (int i=selectedTagGUIDs.size()-1; i>=0; i--) {
2048 boolean found = tagTree.selectGuid(selectedTagGUIDs.get(i));
2050 selectedTagGUIDs.remove(i);
2052 tagTree.blockSignals(false);
2054 browserWindow.setTag(getTagNamesForNote(currentNote));
2055 logger.log(logger.HIGH, "Leaving NeverNote.tagIndexUpdated");
2057 // Show/Hide note information
2058 private void toggleTagWindow() {
2059 logger.log(logger.HIGH, "Entering NeverNote.toggleTagWindow");
2060 if (tagTree.isVisible())
2064 menuBar.hideTags.setChecked(tagTree.isVisible());
2065 Global.saveWindowVisible("tagTree", tagTree.isVisible());
2066 logger.log(logger.HIGH, "Leaving NeverNote.toggleTagWindow");
2068 // A note's tags have been updated
2069 @SuppressWarnings("unused")
2070 private void updateNoteTags(String guid, List<String> tags) {
2071 // Save any new tags. We'll need them later.
2072 List<String> newTags = new ArrayList<String>();
2073 for (int i=0; i<tags.size(); i++) {
2074 if (conn.getTagTable().findTagByName(tags.get(i))==null)
2075 newTags.add(tags.get(i));
2078 listManager.saveNoteTags(guid, tags);
2079 listManager.countTagResults(listManager.getNoteIndex());
2080 StringBuffer names = new StringBuffer("");
2081 for (int i=0; i<tags.size(); i++) {
2082 names = names.append(tags.get(i));
2083 if (i<tags.size()-1) {
2084 names.append(Global.tagDelimeter + " ");
2087 browserWindow.setTag(names.toString());
2090 // Now, we need to add any new tags to the tag tree
2091 for (int i=0; i<newTags.size(); i++)
2092 tagTree.insertTag(newTags.get(i), conn.getTagTable().findTagByName(newTags.get(i)));
2094 // Get a string containing all tag names for a note
2095 private String getTagNamesForNote(Note n) {
2096 logger.log(logger.HIGH, "Entering NeverNote.getTagNamesForNote");
2097 if (n==null || n.getGuid() == null || n.getGuid().equals(""))
2099 StringBuffer buffer = new StringBuffer(100);
2100 Vector<String> v = new Vector<String>();
2101 List<String> guids = n.getTagGuids();
2106 for (int i=0; i<guids.size(); i++) {
2107 v.add(listManager.getTagNameByGuid(guids.get(i)));
2109 Comparator<String> comparator = Collections.reverseOrder();
2110 Collections.sort(v,comparator);
2111 Collections.reverse(v);
2113 for (int i = 0; i<v.size(); i++) {
2115 buffer.append(", ");
2116 buffer.append(v.get(i));
2119 logger.log(logger.HIGH, "Leaving NeverNote.getTagNamesForNote");
2120 return buffer.toString();
2122 // Tags were added via dropping notes from the note list
2123 @SuppressWarnings("unused")
2124 private void tagsAdded(String noteGuid, String tagGuid) {
2125 String tagName = null;
2126 for (int i=0; i<listManager.getTagIndex().size(); i++) {
2127 if (listManager.getTagIndex().get(i).getGuid().equals(tagGuid)) {
2128 tagName = listManager.getTagIndex().get(i).getName();
2129 i=listManager.getTagIndex().size();
2132 if (tagName == null)
2135 for (int i=0; i<listManager.getMasterNoteIndex().size(); i++) {
2136 if (listManager.getMasterNoteIndex().get(i).getGuid().equals(noteGuid)) {
2137 List<String> tagNames = new ArrayList<String>();
2138 tagNames.add(new String(tagName));
2139 Note n = listManager.getMasterNoteIndex().get(i);
2140 for (int j=0; j<n.getTagNames().size(); j++) {
2141 tagNames.add(new String(n.getTagNames().get(j)));
2143 listManager.getNoteTableModel().updateNoteTags(noteGuid, n.getTagGuids(), tagNames);
2144 if (n.getGuid().equals(currentNoteGuid)) {
2145 Collections.sort(tagNames);
2146 String display = "";
2147 for (int j=0; j<tagNames.size(); j++) {
2148 display = display+tagNames.get(j);
2149 if (j+2<tagNames.size())
2150 display = display+Global.tagDelimeter+" ";
2152 browserWindow.setTag(display);
2154 i=listManager.getMasterNoteIndex().size();
2159 listManager.getNoteTableModel().updateNoteSyncStatus(noteGuid, false);
2161 private void clearTagFilter() {
2162 tagTree.blockSignals(true);
2163 tagTree.clearSelection();
2164 menuBar.noteRestoreAction.setVisible(false);
2165 menuBar.tagEditAction.setEnabled(false);
2166 menuBar.tagDeleteAction.setEnabled(false);
2167 menuBar.tagIconAction.setEnabled(false);
2168 selectedTagGUIDs.clear();
2169 listManager.setSelectedTags(selectedTagGUIDs);
2170 tagTree.blockSignals(false);
2172 // Change the icon for a tag
2173 @SuppressWarnings("unused")
2174 private void setTagIcon() {
2175 QTreeWidgetItem currentSelection;
2176 List<QTreeWidgetItem> selections = tagTree.selectedItems();
2177 if (selections.size() == 0)
2180 currentSelection = selections.get(0);
2181 String guid = currentSelection.text(2);
2183 QIcon currentIcon = currentSelection.icon(0);
2184 QIcon icon = conn.getTagTable().getIcon(guid);
2187 dialog = new SetIcon(currentIcon);
2188 dialog.setUseDefaultIcon(true);
2190 dialog = new SetIcon(icon);
2191 dialog.setUseDefaultIcon(false);
2194 if (dialog.okPressed()) {
2195 QIcon newIcon = dialog.getIcon();
2196 conn.getTagTable().setIcon(guid, newIcon, dialog.getFileType());
2197 if (newIcon == null)
2198 newIcon = new QIcon(iconPath+"tag.png");
2199 currentSelection.setIcon(0, newIcon);
2205 //***************************************************************
2206 //***************************************************************
2207 //** These functions deal with Saved Search menu items
2208 //***************************************************************
2209 //***************************************************************
2210 // Add a new notebook
2211 @SuppressWarnings("unused")
2212 private void addSavedSearch() {
2213 logger.log(logger.HIGH, "Inside NeverNote.addSavedSearch");
2214 SavedSearchEdit edit = new SavedSearchEdit();
2215 edit.setSearchList(listManager.getSavedSearchIndex());
2218 if (!edit.okPressed())
2221 Calendar currentTime = new GregorianCalendar();
2222 Long l = new Long(currentTime.getTimeInMillis());
2223 String randint = new String(Long.toString(l));
2225 SavedSearch search = new SavedSearch();
2226 search.setUpdateSequenceNum(0);
2227 search.setGuid(randint);
2228 search.setName(edit.getName());
2229 search.setQuery(edit.getQuery());
2230 search.setFormat(QueryFormat.USER);
2231 listManager.getSavedSearchIndex().add(search);
2232 conn.getSavedSearchTable().addSavedSearch(search, true);
2233 savedSearchIndexUpdated();
2234 logger.log(logger.HIGH, "Leaving NeverNote.addSavedSearch");
2236 // Edit an existing tag
2237 @SuppressWarnings("unused")
2238 private void editSavedSearch() {
2239 logger.log(logger.HIGH, "Entering NeverNote.editSavedSearch");
2240 SavedSearchEdit edit = new SavedSearchEdit();
2241 edit.setTitle(tr("Edit Search"));
2242 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
2243 QTreeWidgetItem currentSelection;
2244 currentSelection = selections.get(0);
2245 String guid = currentSelection.text(1);
2246 SavedSearch s = conn.getSavedSearchTable().getSavedSearch(guid);
2247 edit.setName(currentSelection.text(0));
2248 edit.setQuery(s.getQuery());
2249 edit.setSearchList(listManager.getSavedSearchIndex());
2252 if (!edit.okPressed())
2255 List<SavedSearch> list = listManager.getSavedSearchIndex();
2256 SavedSearch search = null;
2257 boolean found = false;
2258 for (int i=0; i<list.size(); i++) {
2259 search = list.get(i);
2260 if (search.getGuid().equals(guid)) {
2267 search.setName(edit.getName());
2268 search.setQuery(edit.getQuery());
2269 conn.getSavedSearchTable().updateSavedSearch(search, true);
2270 savedSearchIndexUpdated();
2271 logger.log(logger.HIGH, "Leaving NeverNote.editSavedSearch");
2273 // Delete an existing tag
2274 @SuppressWarnings("unused")
2275 private void deleteSavedSearch() {
2276 logger.log(logger.HIGH, "Entering NeverNote.deleteSavedSearch");
2278 if (QMessageBox.question(this, "Confirmation", "Delete the selected search?",
2279 QMessageBox.StandardButton.Yes,
2280 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
2284 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
2285 for (int i=selections.size()-1; i>=0; i--) {
2286 QTreeWidgetItem currentSelection;
2287 currentSelection = selections.get(i);
2288 for (int j=0; j<listManager.getSavedSearchIndex().size(); j++) {
2289 if (listManager.getSavedSearchIndex().get(j).getGuid().equals(currentSelection.text(1))) {
2290 conn.getSavedSearchTable().expungeSavedSearch(listManager.getSavedSearchIndex().get(j).getGuid(), true);
2291 listManager.getSavedSearchIndex().remove(j);
2292 j=listManager.getSavedSearchIndex().size()+1;
2295 selections.remove(i);
2297 savedSearchIndexUpdated();
2298 logger.log(logger.HIGH, "Leaving NeverNote.deleteSavedSearch");
2300 // Setup the tree containing the user's tags
2301 private void initializeSavedSearchTree() {
2302 logger.log(logger.HIGH, "Entering NeverNote.initializeSavedSearchTree");
2303 savedSearchTree.itemSelectionChanged.connect(this, "savedSearchTreeSelection()");
2304 logger.log(logger.HIGH, "Leaving NeverNote.initializeSavedSearchTree");
2306 // Listener when a tag is selected
2307 @SuppressWarnings("unused")
2308 private void savedSearchTreeSelection() {
2309 logger.log(logger.HIGH, "Entering NeverNote.savedSearchTreeSelection");
2311 clearNotebookFilter();
2314 clearAttributeFilter();
2316 String currentGuid = selectedSavedSearchGUID;
2317 menuBar.savedSearchEditAction.setEnabled(true);
2318 menuBar.savedSearchDeleteAction.setEnabled(true);
2319 menuBar.savedSearchIconAction.setEnabled(true);
2320 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
2321 QTreeWidgetItem currentSelection;
2322 selectedSavedSearchGUID = "";
2323 for (int i=0; i<selections.size(); i++) {
2324 currentSelection = selections.get(i);
2325 if (currentSelection.text(1).equals(currentGuid)) {
2326 currentSelection.setSelected(false);
2328 selectedSavedSearchGUID = currentSelection.text(1);
2330 // i = selections.size() +1;
2333 // There is the potential for no notebooks to be selected if this
2334 // happens then we make it look like all notebooks were selecetd.
2335 // If that happens, just select the "all notebooks"
2336 if (selections.size()==0) {
2337 clearSavedSearchFilter();
2339 listManager.setSelectedSavedSearch(selectedSavedSearchGUID);
2341 logger.log(logger.HIGH, "Leaving NeverNote.savedSearchTreeSelection");
2343 private void clearSavedSearchFilter() {
2344 menuBar.savedSearchEditAction.setEnabled(false);
2345 menuBar.savedSearchDeleteAction.setEnabled(false);
2346 menuBar.savedSearchIconAction.setEnabled(false);
2347 savedSearchTree.blockSignals(true);
2348 savedSearchTree.clearSelection();
2349 savedSearchTree.blockSignals(false);
2350 selectedSavedSearchGUID = "";
2351 searchField.setEditText("");
2352 searchPerformed = false;
2353 listManager.setSelectedSavedSearch(selectedSavedSearchGUID);
2355 // trigger the tag index to be refreshed
2356 private void savedSearchIndexUpdated() {
2357 if (selectedSavedSearchGUID == null)
2358 selectedSavedSearchGUID = new String();
2359 savedSearchTree.blockSignals(true);
2360 savedSearchTree.setIcons(conn.getSavedSearchTable().getAllIcons());
2361 savedSearchTree.load(listManager.getSavedSearchIndex());
2362 savedSearchTree.selectGuid(selectedSavedSearchGUID);
2363 savedSearchTree.blockSignals(false);
2365 // trigger when the saved search selection changes
2366 @SuppressWarnings("unused")
2367 private void updateSavedSearchSelection() {
2368 logger.log(logger.HIGH, "Entering NeverNote.updateSavedSearchSelection()");
2370 menuBar.savedSearchEditAction.setEnabled(true);
2371 menuBar.savedSearchDeleteAction.setEnabled(true);
2372 menuBar.savedSearchIconAction.setEnabled(true);
2373 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
2375 if (selections.size() > 0) {
2376 menuBar.savedSearchEditAction.setEnabled(true);
2377 menuBar.savedSearchDeleteAction.setEnabled(true);
2378 menuBar.savedSearchIconAction.setEnabled(true);
2379 selectedSavedSearchGUID = selections.get(0).text(1);
2380 SavedSearch s = conn.getSavedSearchTable().getSavedSearch(selectedSavedSearchGUID);
2381 searchField.setEditText(s.getQuery());
2383 menuBar.savedSearchEditAction.setEnabled(false);
2384 menuBar.savedSearchDeleteAction.setEnabled(false);
2385 menuBar.savedSearchIconAction.setEnabled(false);
2386 selectedSavedSearchGUID = "";
2387 searchField.setEditText("");
2389 searchFieldChanged();
2391 logger.log(logger.HIGH, "Leaving NeverNote.updateSavedSearchSelection()");
2395 // Show/Hide note information
2396 private void toggleSavedSearchWindow() {
2397 logger.log(logger.HIGH, "Entering NeverNote.toggleSavedSearchWindow");
2398 if (savedSearchTree.isVisible())
2399 savedSearchTree.hide();
2401 savedSearchTree.show();
2402 menuBar.hideSavedSearches.setChecked(savedSearchTree.isVisible());
2404 Global.saveWindowVisible("savedSearchTree", savedSearchTree.isVisible());
2405 logger.log(logger.HIGH, "Leaving NeverNote.toggleSavedSearchWindow");
2407 // Change the icon for a saved search
2408 @SuppressWarnings("unused")
2409 private void setSavedSearchIcon() {
2410 QTreeWidgetItem currentSelection;
2411 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
2412 if (selections.size() == 0)
2415 currentSelection = selections.get(0);
2416 String guid = currentSelection.text(1);
2418 QIcon currentIcon = currentSelection.icon(0);
2419 QIcon icon = conn.getSavedSearchTable().getIcon(guid);
2422 dialog = new SetIcon(currentIcon);
2423 dialog.setUseDefaultIcon(true);
2425 dialog = new SetIcon(icon);
2426 dialog.setUseDefaultIcon(false);
2429 if (dialog.okPressed()) {
2430 QIcon newIcon = dialog.getIcon();
2431 conn.getSavedSearchTable().setIcon(guid, newIcon, dialog.getFileType());
2432 if (newIcon == null)
2433 newIcon = new QIcon(iconPath+"search.png");
2434 currentSelection.setIcon(0, newIcon);
2442 //***************************************************************
2443 //***************************************************************
2444 //** These functions deal with Help menu & tool menu items
2445 //***************************************************************
2446 //***************************************************************
2447 // Show database status
2448 @SuppressWarnings("unused")
2449 private void databaseStatus() {
2451 int dirty = conn.getNoteTable().getDirtyCount();
2452 int unindexed = conn.getNoteTable().getUnindexedCount();
2453 DatabaseStatus status = new DatabaseStatus();
2454 status.setUnsynchronized(dirty);
2455 status.setUnindexed(unindexed);
2456 status.setNoteCount(conn.getNoteTable().getNoteCount());
2457 status.setNotebookCount(listManager.getNotebookIndex().size());
2458 status.setUnindexedResourceCount(conn.getNoteTable().noteResourceTable.getUnindexedCount());
2459 status.setSavedSearchCount(listManager.getSavedSearchIndex().size());
2460 status.setTagCount(listManager.getTagIndex().size());
2461 status.setResourceCount(conn.getNoteTable().noteResourceTable.getResourceCount());
2462 status.setWordCount(conn.getWordsTable().getWordCount());
2466 // Compact the database
2467 @SuppressWarnings("unused")
2468 private void compactDatabase() {
2469 logger.log(logger.HIGH, "Entering NeverNote.compactDatabase");
2470 if (QMessageBox.question(this, tr("Confirmation"), tr("This will free unused space in the database, "+
2471 "but please be aware that depending upon the size of your database this can be time consuming " +
2472 "and NeverNote will be unresponsive until it is complete. Do you wish to continue?"),
2473 QMessageBox.StandardButton.Yes,
2474 QMessageBox.StandardButton.No)==StandardButton.No.value() && Global.verifyDelete() == true) {
2477 setMessage("Compacting database.");
2479 listManager.compactDatabase();
2481 setMessage("Database compact is complete.");
2482 logger.log(logger.HIGH, "Leaving NeverNote.compactDatabase");
2484 @SuppressWarnings("unused")
2485 private void accountInformation() {
2486 logger.log(logger.HIGH, "Entering NeverNote.accountInformation");
2487 AccountDialog dialog = new AccountDialog();
2489 logger.log(logger.HIGH, "Leaving NeverNote.accountInformation");
2491 @SuppressWarnings("unused")
2492 private void releaseNotes() {
2493 logger.log(logger.HIGH, "Entering NeverNote.releaseNotes");
2494 QDialog dialog = new QDialog(this);
2495 QHBoxLayout layout = new QHBoxLayout();
2496 QTextEdit textBox = new QTextEdit();
2497 layout.addWidget(textBox);
2498 textBox.setReadOnly(true);
2499 QFile file = new QFile(Global.getFileManager().getHomeDirPath("release.txt"));
2500 if (!file.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly,
2501 QIODevice.OpenModeFlag.Text)))
2503 textBox.setText(file.readAll().toString());
2505 dialog.setWindowTitle(tr("Release Notes"));
2506 dialog.setLayout(layout);
2508 logger.log(logger.HIGH, "Leaving NeverNote.releaseNotes");
2510 // Called when user picks Log from the help menu
2511 @SuppressWarnings("unused")
2512 private void logger() {
2513 logger.log(logger.HIGH, "Entering NeverNote.logger");
2514 QDialog dialog = new QDialog(this);
2515 QHBoxLayout layout = new QHBoxLayout();
2516 QListWidget textBox = new QListWidget();
2517 layout.addWidget(textBox);
2518 textBox.addItems(emitLog);
2520 dialog.setLayout(layout);
2521 dialog.setWindowTitle(tr("Mesasge Log"));
2523 logger.log(logger.HIGH, "Leaving NeverNote.logger");
2525 // Menu option "help/about" was selected
2526 @SuppressWarnings("unused")
2527 private void about() {
2528 logger.log(logger.HIGH, "Entering NeverNote.about");
2529 QMessageBox.about(this,
2530 tr("About NeverNote"),
2531 tr("<h4><center><b>NeverNote</b></center></h4><hr><center>Version ")
2533 +tr("<hr></center>Evernote"
2534 +"An Open Source Evernote Client.<br><br>"
2535 +"Licensed under GPL v2. <br><hr><br>"
2536 +"Evernote is copyright 2001-2010 by Evernote Corporation<br>"
2537 +"Jambi and QT are the licensed trademark of Nokia Corporation<br>"
2538 +"PDFRenderer is licened under the LGPL<br>"
2539 +"JTidy is copyrighted under the World Wide Web Consortium<br>"
2540 +"Apache Common Utilities licensed under the Apache License Version 2.0<br>"
2541 +"Jazzy is licened under the LGPL<br>"
2542 +"Java is a registered trademark of Oracle Corporation.<br><hr>"));
2543 logger.log(logger.HIGH, "Leaving NeverNote.about");
2545 // Hide the entire left hand side
2546 @SuppressWarnings("unused")
2547 private void toggleLeftSide() {
2550 hidden = !menuBar.hideLeftSide.isChecked();
2551 menuBar.hideLeftSide.setChecked(!hidden);
2553 if (notebookTree.isVisible() != hidden)
2554 toggleNotebookWindow();
2555 if (savedSearchTree.isVisible() != hidden)
2556 toggleSavedSearchWindow();
2557 if (tagTree.isVisible() != hidden)
2559 if (attributeTree.isVisible() != hidden)
2560 toggleAttributesWindow();
2561 if (trashTree.isVisible() != hidden)
2562 toggleTrashWindow();
2564 Global.saveWindowVisible("leftPanel", hidden);
2569 //***************************************************************
2570 //***************************************************************
2571 //** These functions deal with the Toolbar
2572 //***************************************************************
2573 //***************************************************************
2574 // Text in the search bar has been cleared
2575 private void searchFieldCleared() {
2578 // This is done because we want to force a reload of
2579 // images. Some images we may want to highlight the text.
2580 readOnlyCache.clear();
2581 inkNoteCache.clear();
2583 QWebSettings.setMaximumPagesInCache(0);
2584 QWebSettings.setObjectCacheCapacities(0, 0, 0);
2586 searchField.setEditText("");
2587 saveNoteColumnPositions();
2588 saveNoteIndexWidth();
2589 noteIndexUpdated(true);
2590 if (currentNote == null && listManager.getNoteIndex().size() > 0) {
2591 currentNote = listManager.getNoteIndex().get(0);
2592 currentNoteGuid = currentNote.getGuid();
2594 if (currentNote != null)
2595 loadNoteBrowserInformation(browserWindow);
2597 // text in the search bar changed. We only use this to tell if it was cleared,
2598 // otherwise we trigger off searchFieldChanged.
2599 @SuppressWarnings("unused")
2600 private void searchFieldTextChanged(String text) {
2601 QWebSettings.setMaximumPagesInCache(0);
2602 QWebSettings.setObjectCacheCapacities(0, 0, 0);
2604 if (text.trim().equals("")) {
2605 searchFieldCleared();
2606 if (searchPerformed) {
2608 // This is done because we want to force a reload of
2609 // images. Some images we may want to highlight the text.
2611 readOnlyCache.clear();
2612 inkNoteCache.clear();
2614 listManager.setEnSearch("");
2615 listManager.loadNotesIndex();
2616 refreshEvernoteNote(true);
2617 noteIndexUpdated(false);
2619 searchPerformed = false;
2622 // Text in the toolbar has changed
2623 private void searchFieldChanged() {
2624 logger.log(logger.HIGH, "Entering NeverNote.searchFieldChanged");
2626 readOnlyCache.clear();
2627 inkNoteCache.clear();
2628 saveNoteColumnPositions();
2629 saveNoteIndexWidth();
2630 String text = searchField.currentText();
2631 listManager.setEnSearch(text.trim());
2632 listManager.loadNotesIndex();
2633 //--->>> noteIndexUpdated(true);
2634 noteIndexUpdated(false);
2635 refreshEvernoteNote(true);
2636 searchPerformed = true;
2637 logger.log(logger.HIGH, "Leaving NeverNote.searchFieldChanged");
2640 // Build the window tool bar
2641 private void setupToolBar() {
2642 logger.log(logger.HIGH, "Entering NeverNote.setupToolBar");
2643 toolBar = addToolBar(tr("Tool Bar"));
2644 menuBar.setupToolBarVisible();
2645 if (!Global.isWindowVisible("toolBar"))
2646 toolBar.setVisible(false);
2648 toolBar.setVisible(true);
2650 prevButton = toolBar.addAction("Previous");
2651 QIcon prevIcon = new QIcon(iconPath+"back.png");
2652 prevButton.setIcon(prevIcon);
2653 prevButton.triggered.connect(this, "previousViewedAction()");
2654 togglePrevArrowButton(Global.isToolbarButtonVisible("prevArrow"));
2656 nextButton = toolBar.addAction("Next");
2657 QIcon nextIcon = new QIcon(iconPath+"forward.png");
2658 nextButton.setIcon(nextIcon);
2659 nextButton.triggered.connect(this, "nextViewedAction()");
2660 toggleNextArrowButton(Global.isToolbarButtonVisible("nextArrow"));
2662 upButton = toolBar.addAction("Up");
2663 QIcon upIcon = new QIcon(iconPath+"up.png");
2664 upButton.setIcon(upIcon);
2665 upButton.triggered.connect(this, "upAction()");
2666 toggleUpArrowButton(Global.isToolbarButtonVisible("upArrow"));
2669 downButton = toolBar.addAction("Down");
2670 QIcon downIcon = new QIcon(iconPath+"down.png");
2671 downButton.setIcon(downIcon);
2672 downButton.triggered.connect(this, "downAction()");
2673 toggleDownArrowButton(Global.isToolbarButtonVisible("downArrow"));
2675 synchronizeButton = toolBar.addAction("Synchronize");
2676 synchronizeButton.setIcon(new QIcon(iconPath+"synchronize.png"));
2677 synchronizeIconAngle = 0;
2678 synchronizeButton.triggered.connect(this, "evernoteSync()");
2679 toggleSynchronizeButton(Global.isToolbarButtonVisible("synchronize"));
2681 printButton = toolBar.addAction("Print");
2682 QIcon printIcon = new QIcon(iconPath+"print.png");
2683 printButton.setIcon(printIcon);
2684 printButton.triggered.connect(this, "printNote()");
2685 togglePrintButton(Global.isToolbarButtonVisible("print"));
2687 tagButton = toolBar.addAction("Tag");
2688 QIcon tagIcon = new QIcon(iconPath+"tag.png");
2689 tagButton.setIcon(tagIcon);
2690 tagButton.triggered.connect(browserWindow, "modifyTags()");
2691 toggleTagButton(Global.isToolbarButtonVisible("tag"));
2693 attributeButton = toolBar.addAction("Attributes");
2694 QIcon attributeIcon = new QIcon(iconPath+"attribute.png");
2695 attributeButton.setIcon(attributeIcon);
2696 attributeButton.triggered.connect(this, "toggleNoteInformation()");
2697 toggleAttributeButton(Global.isToolbarButtonVisible("attribute"));
2699 emailButton = toolBar.addAction("Email");
2700 QIcon emailIcon = new QIcon(iconPath+"email.png");
2701 emailButton.setIcon(emailIcon);
2702 emailButton.triggered.connect(this, "emailNote()");
2703 toggleEmailButton(Global.isToolbarButtonVisible("email"));
2705 deleteButton = toolBar.addAction("Delete");
2706 QIcon deleteIcon = new QIcon(iconPath+"delete.png");
2707 deleteButton.setIcon(deleteIcon);
2708 deleteButton.triggered.connect(this, "deleteNote()");
2709 toggleDeleteButton(Global.isToolbarButtonVisible("delete"));
2711 newButton = toolBar.addAction("New");
2712 QIcon newIcon = new QIcon(iconPath+"new.png");
2713 newButton.triggered.connect(this, "addNote()");
2714 newButton.setIcon(newIcon);
2715 toggleNewButton(Global.isToolbarButtonVisible("new"));
2717 allNotesButton = toolBar.addAction("All Notes");
2718 QIcon allIcon = new QIcon(iconPath+"books.png");
2719 allNotesButton.triggered.connect(this, "allNotes()");
2720 allNotesButton.setIcon(allIcon);
2721 toggleAllNotesButton(Global.isToolbarButtonVisible("allNotes"));
2723 toolBar.addSeparator();
2724 toolBar.addWidget(new QLabel(tr("Quota:")));
2725 toolBar.addWidget(quotaBar);
2726 //quotaBar.setSizePolicy(Policy.Minimum, Policy.Minimum);
2728 toolBar.addSeparator();
2731 zoomSpinner = new QSpinBox();
2732 zoomSpinner.setMinimum(10);
2733 zoomSpinner.setMaximum(1000);
2734 zoomSpinner.setAccelerated(true);
2735 zoomSpinner.setSingleStep(10);
2736 zoomSpinner.setValue(100);
2737 zoomSpinner.valueChanged.connect(this, "zoomChanged()");
2738 toolBar.addWidget(new QLabel(tr("Zoom")));
2739 toolBar.addWidget(zoomSpinner);
2741 //toolBar.addWidget(new QLabel(" "));
2742 toolBar.addSeparator();
2743 toolBar.addWidget(new QLabel(tr(" Search:")));
2744 toolBar.addWidget(searchField);
2745 QSizePolicy sizePolicy = new QSizePolicy();
2746 sizePolicy.setHorizontalPolicy(Policy.MinimumExpanding);
2747 searchField.setSizePolicy(sizePolicy);
2748 searchField.setInsertPolicy(InsertPolicy.InsertAtTop);
2750 searchClearButton = toolBar.addAction("Search Clear");
2751 QIcon searchClearIcon = new QIcon(iconPath+"searchclear.png");
2752 searchClearButton.setIcon(searchClearIcon);
2753 searchClearButton.triggered.connect(this, "searchFieldCleared()");
2754 toggleSearchClearButton(Global.isToolbarButtonVisible("searchClear"));
2756 logger.log(logger.HIGH, "Leaving NeverNote.setupToolBar");
2758 // Update the sychronize button picture
2760 public QMenu createPopupMenu() {
2761 QMenu contextMenu = super.createPopupMenu();
2763 contextMenu.addSeparator();
2764 QAction prevAction = addContextAction("prevArrow", tr("Previous Arrow"));
2765 contextMenu.addAction(prevAction);
2766 prevAction.triggered.connect(this, "togglePrevArrowButton(Boolean)");
2768 QAction nextAction = addContextAction("nextArrow", tr("Next Arrow"));
2769 contextMenu.addAction(nextAction);
2770 nextAction.triggered.connect(this, "toggleNextArrowButton(Boolean)");
2772 QAction upAction = addContextAction("upArrow", tr("Up Arrow"));
2773 contextMenu.addAction(upAction);
2774 upAction.triggered.connect(this, "toggleUpArrowButton(Boolean)");
2776 QAction downAction = addContextAction("downArrow", tr("Down Arrow"));
2777 contextMenu.addAction(downAction);
2778 downAction.triggered.connect(this, "toggleDownArrowButton(Boolean)");
2780 QAction synchronizeAction = addContextAction("synchronize", tr("Synchronize"));
2781 contextMenu.addAction(synchronizeAction);
2782 synchronizeAction.triggered.connect(this, "toggleSynchronizeButton(Boolean)");
2784 QAction printAction = addContextAction("print", tr("Print"));
2785 contextMenu.addAction(printAction);
2786 printAction.triggered.connect(this, "togglePrintButton(Boolean)");
2788 QAction tagAction = addContextAction("tag", tr("Tag"));
2789 contextMenu.addAction(tagAction);
2790 tagAction.triggered.connect(this, "toggleTagButton(Boolean)");
2792 QAction attributeAction = addContextAction("attribute", tr("Attribute"));
2793 contextMenu.addAction(attributeAction);
2794 attributeAction.triggered.connect(this, "toggleAttributeButton(Boolean)");
2796 QAction emailAction = addContextAction("email", tr("Email"));
2797 contextMenu.addAction(emailAction);
2798 emailAction.triggered.connect(this, "toggleEmailButton(Boolean)");
2800 QAction deleteAction = addContextAction("delete", tr("Delete"));
2801 contextMenu.addAction(deleteAction);
2802 deleteAction.triggered.connect(this, "toggleDeleteButton(Boolean)");
2804 QAction newAction = addContextAction("new", tr("Add"));
2805 contextMenu.addAction(newAction);
2806 newAction.triggered.connect(this, "toggleNewButton(Boolean)");
2808 QAction allNotesAction = addContextAction("allNotes", tr("All Notes"));
2809 contextMenu.addAction(allNotesAction);
2810 allNotesAction.triggered.connect(this, "toggleAllNotesButton(Boolean)");
2812 QAction searchClearAction = addContextAction("searchClear", tr("Search Clear"));
2813 contextMenu.addAction(searchClearAction);
2814 searchClearAction.triggered.connect(this, "toggleSearchClearButton(Boolean)");
2819 private QAction addContextAction(String config, String name) {
2820 QAction newAction = new QAction(this);
2821 newAction.setText(name);
2822 newAction.setCheckable(true);
2823 newAction.setChecked(Global.isToolbarButtonVisible(config));
2826 private void togglePrevArrowButton(Boolean toggle) {
2827 prevButton.setVisible(toggle);
2828 Global.saveToolbarButtonsVisible("prevArrow", toggle);
2830 private void toggleNextArrowButton(Boolean toggle) {
2831 nextButton.setVisible(toggle);
2832 Global.saveToolbarButtonsVisible("nextArrow", toggle);
2834 private void toggleUpArrowButton(Boolean toggle) {
2835 upButton.setVisible(toggle);
2836 Global.saveToolbarButtonsVisible("upArrow", toggle);
2838 private void toggleDownArrowButton(Boolean toggle) {
2839 downButton.setVisible(toggle);
2840 Global.saveToolbarButtonsVisible("downArrow", toggle);
2842 private void toggleSynchronizeButton(Boolean toggle) {
2843 synchronizeButton.setVisible(toggle);
2844 Global.saveToolbarButtonsVisible("synchronize", toggle);
2846 private void togglePrintButton(Boolean toggle) {
2847 printButton.setVisible(toggle);
2848 Global.saveToolbarButtonsVisible("print", toggle);
2850 private void toggleTagButton(Boolean toggle) {
2851 tagButton.setVisible(toggle);
2852 Global.saveToolbarButtonsVisible("tag", toggle);
2854 private void toggleAttributeButton(Boolean toggle) {
2855 attributeButton.setVisible(toggle);
2856 Global.saveToolbarButtonsVisible("attribute", toggle);
2858 private void toggleEmailButton(Boolean toggle) {
2859 emailButton.setVisible(toggle);
2860 Global.saveToolbarButtonsVisible("email", toggle);
2862 private void toggleDeleteButton(Boolean toggle) {
2863 deleteButton.setVisible(toggle);
2864 Global.saveToolbarButtonsVisible("delete", toggle);
2866 private void toggleNewButton(Boolean toggle) {
2867 newButton.setVisible(toggle);
2868 Global.saveToolbarButtonsVisible("new", toggle);
2870 private void toggleAllNotesButton(Boolean toggle) {
2871 allNotesButton.setVisible(toggle);
2872 Global.saveToolbarButtonsVisible("allNotes", toggle);
2874 private void toggleSearchClearButton(Boolean toggle) {
2875 searchClearButton.setVisible(toggle);
2876 Global.saveToolbarButtonsVisible("searchClear", toggle);
2883 @SuppressWarnings("unused")
2884 private void updateSyncButton() {
2886 if (syncIcons == null) {
2887 syncIcons = new ArrayList<QPixmap>();
2889 synchronizeIconAngle = 0;
2890 QPixmap pix = new QPixmap(iconPath+"synchronize.png");
2892 for (int i=0; i<=360; i++) {
2893 QPixmap rotatedPix = new QPixmap(pix.size());
2894 QPainter p = new QPainter(rotatedPix);
2895 rotatedPix.fill(toolBar.palette().color(ColorRole.Button));
2896 QSize size = pix.size();
2897 p.translate(size.width()/2, size.height()/2);
2900 p.setBackgroundMode(BGMode.OpaqueMode);
2901 p.translate(-size.width()/2, -size.height()/2);
2902 p.drawPixmap(0,0, pix);
2904 syncIcons.add(rotatedPix);
2908 synchronizeIconAngle++;
2909 if (synchronizeIconAngle > 359)
2910 synchronizeIconAngle=0;
2911 synchronizeButton.setIcon(syncIcons.get(synchronizeIconAngle));
2914 // Synchronize with Evernote
2915 @SuppressWarnings("unused")
2916 private void evernoteSync() {
2917 logger.log(logger.HIGH, "Entering NeverNote.evernoteSync");
2918 if (!Global.isConnected)
2920 if (Global.isConnected)
2921 synchronizeAnimationTimer.start(5);
2922 // synchronizeAnimationTimer.start(200);
2924 logger.log(logger.HIGH, "Leaving NeverNote.evernoteSync");
2926 private void updateQuotaBar() {
2927 long limit = Global.getUploadLimit();
2928 long amount = Global.getUploadAmount();
2929 if (amount>0 && limit>0) {
2930 int percent =(int)(amount*100/limit);
2931 quotaBar.setValue(percent);
2933 quotaBar.setValue(0);
2936 @SuppressWarnings("unused")
2937 private void zoomChanged() {
2938 browserWindow.getBrowser().setZoomFactor(new Double(zoomSpinner.value())/100);
2941 //****************************************************************
2942 //****************************************************************
2943 //* System Tray functions
2944 //****************************************************************
2945 //****************************************************************
2946 private void trayToggleVisible() {
2951 if (windowMaximized)
2958 @SuppressWarnings("unused")
2959 private void trayActivated(QSystemTrayIcon.ActivationReason reason) {
2960 if (reason == QSystemTrayIcon.ActivationReason.DoubleClick) {
2961 String name = QSystemTrayIcon.MessageIcon.resolve(reason.value()).name();
2962 trayToggleVisible();
2967 //***************************************************************
2968 //***************************************************************
2969 //** These functions deal with the trash tree
2970 //***************************************************************
2971 //***************************************************************
2972 // Setup the tree containing the trash.
2973 @SuppressWarnings("unused")
2974 private void trashTreeSelection() {
2975 logger.log(logger.HIGH, "Entering NeverNote.trashTreeSelection");
2977 clearNotebookFilter();
2979 clearAttributeFilter();
2980 clearSavedSearchFilter();
2982 String tempGuid = currentNoteGuid;
2984 // currentNoteGuid = "";
2985 currentNote = new Note();
2986 selectedNoteGUIDs.clear();
2987 listManager.getSelectedNotebooks().clear();
2988 listManager.getSelectedTags().clear();
2989 listManager.setSelectedSavedSearch("");
2990 browserWindow.clear();
2992 // toggle the add buttons
2993 newButton.setEnabled(!newButton.isEnabled());
2994 menuBar.noteAdd.setEnabled(newButton.isEnabled());
2995 menuBar.noteAdd.setVisible(true);
2997 List<QTreeWidgetItem> selections = trashTree.selectedItems();
2998 if (selections.size() == 0) {
2999 currentNoteGuid = trashNoteGuid;
3000 trashNoteGuid = tempGuid;
3001 Global.showDeleted = false;
3002 menuBar.noteRestoreAction.setEnabled(false);
3003 menuBar.noteRestoreAction.setVisible(false);
3006 currentNoteGuid = trashNoteGuid;
3007 trashNoteGuid = tempGuid;
3008 menuBar.noteRestoreAction.setEnabled(true);
3009 menuBar.noteRestoreAction.setVisible(true);
3010 Global.showDeleted = true;
3012 listManager.loadNotesIndex();
3013 noteIndexUpdated(false);
3014 //// browserWindow.setEnabled(newButton.isEnabled());
3015 browserWindow.setReadOnly(!newButton.isEnabled());
3016 logger.log(logger.HIGH, "Leaving NeverNote.trashTreeSelection");
3018 // Empty the trash file
3019 @SuppressWarnings("unused")
3020 private void emptyTrash() {
3021 // browserWindow.clear();
3022 listManager.emptyTrash();
3023 if (trashTree.selectedItems().size() > 0) {
3024 listManager.getSelectedNotebooks().clear();
3025 listManager.getSelectedTags().clear();
3026 listManager.setSelectedSavedSearch("");
3027 newButton.setEnabled(!newButton.isEnabled());
3028 menuBar.noteAdd.setEnabled(newButton.isEnabled());
3029 menuBar.noteAdd.setVisible(true);
3030 browserWindow.clear();
3033 clearNotebookFilter();
3034 clearSavedSearchFilter();
3035 clearAttributeFilter();
3037 Global.showDeleted = false;
3038 menuBar.noteRestoreAction.setEnabled(false);
3039 menuBar.noteRestoreAction.setVisible(false);
3041 listManager.loadNotesIndex();
3042 //--->>> noteIndexUpdated(true);
3043 noteIndexUpdated(false);
3046 // Show/Hide trash window
3047 private void toggleTrashWindow() {
3048 logger.log(logger.HIGH, "Entering NeverNote.toggleTrashWindow");
3049 if (trashTree.isVisible())
3053 menuBar.hideTrash.setChecked(trashTree.isVisible());
3055 Global.saveWindowVisible("trashTree", trashTree.isVisible());
3056 logger.log(logger.HIGH, "Leaving NeverNote.trashWindow");
3058 private void clearTrashFilter() {
3059 Global.showDeleted = false;
3060 newButton.setEnabled(true);
3061 menuBar.noteAdd.setEnabled(true);
3062 menuBar.noteAdd.setVisible(true);
3063 trashTree.blockSignals(true);
3064 trashTree.clearSelection();
3065 trashTree.blockSignals(false);
3070 //***************************************************************
3071 //***************************************************************
3072 //** These functions deal with connection settings
3073 //***************************************************************
3074 //***************************************************************
3075 // SyncRunner had a problem and things are disconnected
3076 @SuppressWarnings("unused")
3077 private void remoteErrorDisconnect() {
3078 menuBar.connectAction.setText(tr("Connect"));
3079 menuBar.connectAction.setToolTip(tr("Connect to Evernote"));
3080 menuBar.synchronizeAction.setEnabled(false);
3081 Global.isConnected = false;
3082 synchronizeAnimationTimer.stop();
3085 // Do a manual connect/disconnect
3086 private void remoteConnect() {
3087 logger.log(logger.HIGH, "Entering NeverNote.remoteConnect");
3089 if (Global.isConnected) {
3090 Global.isConnected = false;
3091 syncRunner.enDisconnect();
3092 setupConnectMenuOptions();
3097 AESEncrypter aes = new AESEncrypter();
3099 aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("secure.txt")));
3100 } catch (FileNotFoundException e) {
3101 // File not found, so we'll just get empty strings anyway.
3103 String userid = aes.getUserid();
3104 String password = aes.getPassword();
3105 if (!userid.equals("") && !password.equals("")) {
3106 Global.username = userid;
3107 Global.password = password;
3110 // Show the login dialog box
3111 if (!Global.automaticLogin() || userid.equals("")|| password.equals("")) {
3112 LoginDialog login = new LoginDialog();
3115 if (!login.okPressed()) {
3119 Global.username = login.getUserid();
3120 Global.password = login.getPassword();
3122 syncRunner.username = Global.username;
3123 syncRunner.password = Global.password;
3124 syncRunner.userStoreUrl = Global.userStoreUrl;
3125 syncRunner.noteStoreUrl = Global.noteStoreUrl;
3126 syncRunner.noteStoreUrlBase = Global.noteStoreUrlBase;
3128 if (Global.getProxyValue("url").equals("")) {
3129 System.setProperty("http.proxyHost","") ;
3130 System.setProperty("http.proxyPort", "") ;
3131 System.setProperty("https.proxyHost","") ;
3132 System.setProperty("https.proxyPort", "") ;
3135 System.setProperty("http.proxyHost",Global.getProxyValue("url")) ;
3136 System.setProperty("http.proxyPort", Global.getProxyValue("port")) ;
3137 System.setProperty("https.proxyHost",Global.getProxyValue("url")) ;
3138 System.setProperty("https.proxyPort", Global.getProxyValue("port")) ;
3140 if (Global.getProxyValue("userid").equals("")) {
3141 Authenticator.setDefault(new Authenticator() {
3143 protected PasswordAuthentication getPasswordAuthentication() {
3145 PasswordAuthentication(Global.getProxyValue("userid"),Global.getProxyValue("password").toCharArray());
3151 syncRunner.enConnect();
3152 Global.isConnected = syncRunner.isConnected;
3154 setupConnectMenuOptions();
3155 logger.log(logger.HIGH, "Leaving NeverNote.remoteConnect");
3157 private void setupConnectMenuOptions() {
3158 logger.log(logger.HIGH, "entering NeverNote.setupConnectMenuOptions");
3159 if (!Global.isConnected) {
3160 menuBar.connectAction.setText(tr("Connect"));
3161 menuBar.connectAction.setToolTip(tr("Connect to Evernote"));
3162 menuBar.synchronizeAction.setEnabled(false);
3164 menuBar.connectAction.setText(tr("Disconnect"));
3165 menuBar.connectAction.setToolTip(tr("Disconnect from Evernote"));
3166 menuBar.synchronizeAction.setEnabled(true);
3168 logger.log(logger.HIGH, "Leaving NeverNote.setupConnectionMenuOptions");
3173 //***************************************************************
3174 //***************************************************************
3175 //** These functions deal with the GUI Attribute tree
3176 //***************************************************************
3177 //***************************************************************
3178 @SuppressWarnings("unused")
3179 private void attributeTreeClicked(QTreeWidgetItem item, Integer integer) {
3181 // clearTagFilter();
3182 // clearNotebookFilter();
3184 // clearSavedSearchFilter();
3186 if (attributeTreeSelected == null || item.nativeId() != attributeTreeSelected.nativeId()) {
3187 if (item.childCount() > 0) {
3188 item.setSelected(false);
3190 Global.createdBeforeFilter.reset();
3191 Global.createdSinceFilter.reset();
3192 Global.changedBeforeFilter.reset();
3193 Global.changedSinceFilter.reset();
3194 Global.containsFilter.reset();
3195 attributeTreeSelected = item;
3196 DateAttributeFilterTable f = null;
3197 f = findDateAttributeFilterTable(item.parent());
3199 f.select(item.parent().indexOfChild(item));
3201 Global.containsFilter.select(item.parent().indexOfChild(item));
3204 listManager.loadNotesIndex();
3205 noteIndexUpdated(false);
3208 attributeTreeSelected = null;
3209 item.setSelected(false);
3210 Global.createdBeforeFilter.reset();
3211 Global.createdSinceFilter.reset();
3212 Global.changedBeforeFilter.reset();
3213 Global.changedSinceFilter.reset();
3214 Global.containsFilter.reset();
3215 listManager.loadNotesIndex();
3216 noteIndexUpdated(false);
3218 // This determines what attribute filter we need, depending upon the selection
3219 private DateAttributeFilterTable findDateAttributeFilterTable(QTreeWidgetItem w) {
3220 if (w.parent() != null && w.childCount() > 0) {
3221 QTreeWidgetItem parent = w.parent();
3222 if (parent.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Created &&
3223 w.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Since)
3224 return Global.createdSinceFilter;
3225 if (parent.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Created &&
3226 w.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Before)
3227 return Global.createdBeforeFilter;
3228 if (parent.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.LastModified &&
3229 w.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Since)
3230 return Global.changedSinceFilter;
3231 if (parent.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.LastModified &&
3232 w.data(0,ItemDataRole.UserRole)==AttributeTreeWidget.Attributes.Before)
3233 return Global.changedBeforeFilter;
3238 // Show/Hide attribute search window
3239 private void toggleAttributesWindow() {
3240 logger.log(logger.HIGH, "Entering NeverNote.toggleAttributesWindow");
3241 if (attributeTree.isVisible())
3242 attributeTree.hide();
3244 attributeTree.show();
3245 menuBar.hideAttributes.setChecked(attributeTree.isVisible());
3247 Global.saveWindowVisible("attributeTree", attributeTree.isVisible());
3248 logger.log(logger.HIGH, "Leaving NeverNote.toggleAttributeWindow");
3250 private void clearAttributeFilter() {
3251 Global.createdBeforeFilter.reset();
3252 Global.createdSinceFilter.reset();
3253 Global.changedBeforeFilter.reset();
3254 Global.changedSinceFilter.reset();
3255 Global.containsFilter.reset();
3256 attributeTreeSelected = null;
3257 attributeTree.blockSignals(true);
3258 attributeTree.clearSelection();
3259 attributeTree.blockSignals(false);
3263 //***************************************************************
3264 //***************************************************************
3265 //** These functions deal with the GUI Note index table
3266 //***************************************************************
3267 //***************************************************************
3268 // Initialize the note list table
3269 private void initializeNoteTable() {
3270 logger.log(logger.HIGH, "Entering NeverNote.initializeNoteTable");
3271 noteTableView.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection);
3272 noteTableView.selectionModel().selectionChanged.connect(this, "noteTableSelection()");
3273 logger.log(logger.HIGH, "Leaving NeverNote.initializeNoteTable");
3275 // Show/Hide trash window
3276 @SuppressWarnings("unused")
3277 private void toggleNoteListWindow() {
3278 logger.log(logger.HIGH, "Entering NeverNote.toggleNoteListWindow");
3279 if (noteTableView.isVisible())
3280 noteTableView.hide();
3282 noteTableView.show();
3283 menuBar.hideNoteList.setChecked(noteTableView.isVisible());
3285 Global.saveWindowVisible("noteList", noteTableView.isVisible());
3286 logger.log(logger.HIGH, "Leaving NeverNote.toggleNoteListWindow");
3288 // Handle the event that a user selects a note from the table
3289 @SuppressWarnings("unused")
3290 private void noteTableSelection() {
3291 logger.log(logger.HIGH, "Entering NeverNote.noteTableSelection");
3293 if (historyGuids.size() == 0) {
3294 historyGuids.add(currentNoteGuid);
3295 historyPosition = 1;
3297 noteTableView.showColumn(Global.noteTableGuidPosition);
3299 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
3300 if (!Global.isColumnVisible("guid"))
3301 noteTableView.hideColumn(Global.noteTableGuidPosition);
3303 if (selections.size() > 0) {
3305 menuBar.noteDuplicateAction.setEnabled(true);
3306 menuBar.noteOnlineHistoryAction.setEnabled(true);
3307 menuBar.noteMergeAction.setEnabled(true);
3308 selectedNoteGUIDs.clear();
3309 if (selections.size() != 1 || Global.showDeleted) {
3310 menuBar.noteDuplicateAction.setEnabled(false);
3312 if (selections.size() != 1 || !Global.isConnected) {
3313 menuBar.noteOnlineHistoryAction.setEnabled(false);
3315 if (selections.size() == 1) {
3316 menuBar.noteMergeAction.setEnabled(false);
3318 for (int i=0; i<selections.size(); i++) {
3319 int row = selections.get(i).row();
3321 upButton.setEnabled(false);
3323 upButton.setEnabled(true);
3324 if (row < listManager.getNoteTableModel().rowCount()-1)
3325 downButton.setEnabled(true);
3327 downButton.setEnabled(false);
3328 index = noteTableView.proxyModel.index(row, Global.noteTableGuidPosition);
3329 SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(index);
3330 currentNoteGuid = (String)ix.values().toArray()[0];
3331 selectedNoteGUIDs.add(currentNoteGuid);
3335 nextButton.setEnabled(true);
3336 prevButton.setEnabled(true);
3338 int endPosition = historyGuids.size()-1;
3339 for (int j=historyPosition; j<=endPosition; j++) {
3340 historyGuids.remove(historyGuids.size()-1);
3342 historyGuids.add(currentNoteGuid);
3343 historyPosition = historyGuids.size();
3345 if (historyPosition <= 1)
3346 prevButton.setEnabled(false);
3347 if (historyPosition == historyGuids.size())
3348 nextButton.setEnabled(false);
3350 fromHistory = false;
3351 scrollToGuid(currentNoteGuid);
3352 refreshEvernoteNote(true);
3353 logger.log(logger.HIGH, "Leaving NeverNote.noteTableSelection");
3355 // Trigger a refresh when the note db has been updated
3356 private void noteIndexUpdated(boolean reload) {
3357 logger.log(logger.HIGH, "Entering NeverNote.noteIndexUpdated");
3359 refreshEvernoteNoteList();
3360 logger.log(logger.HIGH, "Calling note table reload in NeverNote.noteIndexUpdated() - "+reload);
3361 noteTableView.load(reload);
3362 scrollToGuid(currentNoteGuid);
3363 logger.log(logger.HIGH, "Leaving NeverNote.noteIndexUpdated");
3365 // Called when the list of notes is updated
3366 private void refreshEvernoteNoteList() {
3367 logger.log(logger.HIGH, "Entering NeverNote.refreshEvernoteNoteList");
3368 browserWindow.setDisabled(false);
3369 if (selectedNoteGUIDs == null)
3370 selectedNoteGUIDs = new ArrayList<String>();
3371 selectedNoteGUIDs.clear(); // clear out old entries
3373 String saveCurrentNoteGuid = new String();
3374 String tempNoteGuid = new String();
3376 historyGuids.clear();
3377 historyPosition = 0;
3378 prevButton.setEnabled(false);
3379 nextButton.setEnabled(false);
3381 if (currentNoteGuid == null)
3382 currentNoteGuid = new String();
3384 //determine current note guid
3385 for (Note note : listManager.getNoteIndex()) {
3386 tempNoteGuid = note.getGuid();
3387 if (currentNoteGuid.equals(tempNoteGuid)) {
3388 saveCurrentNoteGuid = tempNoteGuid;
3392 if (listManager.getNoteIndex().size() == 0) {
3393 currentNoteGuid = "";
3395 browserWindow.clear();
3396 browserWindow.setDisabled(true);
3399 if (saveCurrentNoteGuid.equals("") && listManager.getNoteIndex().size() > 0) {
3400 currentNote = listManager.getNoteIndex().get(listManager.getNoteIndex().size()-1);
3401 currentNoteGuid = currentNote.getGuid();
3402 refreshEvernoteNote(true);
3404 //we can reload if note not dirty
3405 // refreshEvernoteNote(!noteDirty);
3406 refreshEvernoteNote(false);
3408 reloadTagTree(false);
3410 logger.log(logger.HIGH, "Leaving NeverNote.refreshEvernoteNoteList");
3412 // Called when the previous arrow button is clicked
3413 @SuppressWarnings("unused")
3414 private void previousViewedAction() {
3415 if (!prevButton.isEnabled())
3417 if (historyPosition == 0)
3420 if (historyPosition <= 0)
3422 String historyGuid = historyGuids.get(historyPosition-1);
3424 for (int i=0; i<noteTableView.model().rowCount(); i++) {
3425 QModelIndex modelIndex = noteTableView.model().index(i, Global.noteTableGuidPosition);
3426 if (modelIndex != null) {
3427 SortedMap<Integer, Object> ix = noteTableView.model().itemData(modelIndex);
3428 String tableGuid = (String)ix.values().toArray()[0];
3429 if (tableGuid.equals(historyGuid)) {
3430 noteTableView.selectRow(i);
3436 @SuppressWarnings("unused")
3437 private void nextViewedAction() {
3438 if (!nextButton.isEnabled())
3440 String historyGuid = historyGuids.get(historyPosition);
3443 for (int i=0; i<noteTableView.model().rowCount(); i++) {
3444 QModelIndex modelIndex = noteTableView.model().index(i, Global.noteTableGuidPosition);
3445 if (modelIndex != null) {
3446 SortedMap<Integer, Object> ix = noteTableView.model().itemData(modelIndex);
3447 String tableGuid = (String)ix.values().toArray()[0];
3448 if (tableGuid.equals(historyGuid)) {
3449 noteTableView.selectRow(i);
3455 // Called when the up arrow is clicked
3456 @SuppressWarnings("unused")
3457 private void upAction() {
3458 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
3459 int row = selections.get(0).row();
3461 noteTableView.selectRow(row-1);
3464 // Called when the down arrow is clicked
3465 @SuppressWarnings("unused")
3466 private void downAction() {
3467 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
3468 int row = selections.get(0).row();
3469 int max = listManager.getNoteTableModel().rowCount();
3471 noteTableView.selectRow(row+1);
3474 // Update a tag string for a specific note in the list
3475 @SuppressWarnings("unused")
3476 private void updateListTags(String guid, List<String> tags) {
3477 logger.log(logger.HIGH, "Entering NeverNote.updateListTags");
3478 StringBuffer tagBuffer = new StringBuffer();
3479 for (int i=0; i<tags.size(); i++) {
3480 tagBuffer.append(tags.get(i));
3481 if (i<tags.size()-1)
3482 tagBuffer.append(", ");
3485 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
3486 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
3487 if (modelIndex != null) {
3488 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
3489 String tableGuid = (String)ix.values().toArray()[0];
3490 if (tableGuid.equals(guid)) {
3491 listManager.getNoteTableModel().setData(i, Global.noteTableTagPosition,tagBuffer.toString());
3492 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
3493 noteTableView.proxyModel.invalidate();
3498 logger.log(logger.HIGH, "Leaving NeverNote.updateListTags");
3500 // Update a title for a specific note in the list
3501 @SuppressWarnings("unused")
3502 private void updateListAuthor(String guid, String author) {
3503 logger.log(logger.HIGH, "Entering NeverNote.updateListAuthor");
3505 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
3506 //QModelIndex modelIndex = noteTableView.proxyModel.index(i, Global.noteTableGuidPosition);
3507 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
3508 if (modelIndex != null) {
3509 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
3510 String tableGuid = (String)ix.values().toArray()[0];
3511 if (tableGuid.equals(guid)) {
3512 listManager.getNoteTableModel().setData(i, Global.noteTableAuthorPosition,author);
3513 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
3514 noteTableView.proxyModel.invalidate();
3520 logger.log(logger.HIGH, "Leaving NeverNote.updateListAuthor");
3522 private void updateListNoteNotebook(String guid, String notebook) {
3523 logger.log(logger.HIGH, "Entering NeverNote.updateListNoteNotebook");
3524 listManager.getNoteTableModel().updateNoteSyncStatus(guid, false);
3525 logger.log(logger.HIGH, "Leaving NeverNote.updateListNoteNotebook");
3527 // Update a title for a specific note in the list
3528 @SuppressWarnings("unused")
3529 private void updateListSourceUrl(String guid, String url) {
3530 logger.log(logger.HIGH, "Entering NeverNote.updateListAuthor");
3532 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
3533 //QModelIndex modelIndex = noteTableView.proxyModel.index(i, Global.noteTableGuidPosition);
3534 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
3535 if (modelIndex != null) {
3536 // SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(modelIndex);
3537 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
3538 String tableGuid = (String)ix.values().toArray()[0];
3539 if (tableGuid.equals(guid)) {
3540 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
3541 listManager.getNoteTableModel().setData(i, Global.noteTableSourceUrlPosition,url);
3542 noteTableView.proxyModel.invalidate();
3547 logger.log(logger.HIGH, "Leaving NeverNote.updateListAuthor");
3549 @SuppressWarnings("unused")
3550 private void updateListGuid(String oldGuid, String newGuid) {
3551 logger.log(logger.HIGH, "Entering NeverNote.updateListTitle");
3553 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
3554 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
3555 if (modelIndex != null) {
3556 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
3557 String tableGuid = (String)ix.values().toArray()[0];
3558 if (tableGuid.equals(oldGuid)) {
3559 listManager.getNoteTableModel().setData(i, Global.noteTableGuidPosition,newGuid);
3560 //listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
3565 logger.log(logger.HIGH, "Leaving NeverNote.updateListTitle");
3567 private void updateListTagName(String guid) {
3568 logger.log(logger.HIGH, "Entering NeverNote.updateTagName");
3570 for (int j=0; j<listManager.getNoteIndex().size(); j++) {
3571 if (listManager.getNoteIndex().get(j).getTagGuids().contains(guid)) {
3572 String newName = listManager.getTagNamesForNote(listManager.getNoteIndex().get(j));
3574 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
3575 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
3576 if (modelIndex != null) {
3577 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
3578 String noteGuid = (String)ix.values().toArray()[0];
3579 if (noteGuid.equalsIgnoreCase(listManager.getNoteIndex().get(j).getGuid())) {
3580 listManager.getNoteTableModel().setData(i, Global.noteTableTagPosition, newName);
3581 i=listManager.getNoteTableModel().rowCount();
3587 logger.log(logger.HIGH, "Leaving NeverNote.updateListNotebook");
3589 private void removeListTagName(String guid) {
3590 logger.log(logger.HIGH, "Entering NeverNote.updateTagName");
3592 for (int j=0; j<listManager.getNoteIndex().size(); j++) {
3593 if (listManager.getNoteIndex().get(j).getTagGuids().contains(guid)) {
3594 for (int i=listManager.getNoteIndex().get(j).getTagGuids().size()-1; i>=0; i--) {
3595 if (listManager.getNoteIndex().get(j).getTagGuids().get(i).equals(guid))
3596 listManager.getNoteIndex().get(j).getTagGuids().remove(i);
3599 String newName = listManager.getTagNamesForNote(listManager.getNoteIndex().get(j));
3600 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
3601 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
3602 if (modelIndex != null) {
3603 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
3604 String noteGuid = (String)ix.values().toArray()[0];
3605 if (noteGuid.equalsIgnoreCase(listManager.getNoteIndex().get(j).getGuid())) {
3606 listManager.getNoteTableModel().setData(i, Global.noteTableTagPosition, newName);
3607 i=listManager.getNoteTableModel().rowCount();
3613 logger.log(logger.HIGH, "Leaving NeverNote.updateListNotebook");
3615 private void updateListNotebookName(String oldName, String newName) {
3616 logger.log(logger.HIGH, "Entering NeverNote.updateListNotebookName");
3618 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
3619 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableNotebookPosition);
3620 if (modelIndex != null) {
3621 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
3622 String tableName = (String)ix.values().toArray()[0];
3623 if (tableName.equalsIgnoreCase(oldName)) {
3624 listManager.getNoteTableModel().setData(i, Global.noteTableNotebookPosition, newName);
3628 logger.log(logger.HIGH, "Leaving NeverNote.updateListNotebookName");
3630 @SuppressWarnings("unused")
3631 private void updateListDateCreated(String guid, QDateTime date) {
3632 logger.log(logger.HIGH, "Entering NeverNote.updateListDateCreated");
3634 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
3635 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
3636 if (modelIndex != null) {
3637 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
3638 String tableGuid = (String)ix.values().toArray()[0];
3639 if (tableGuid.equals(guid)) {
3640 listManager.getNoteTableModel().setData(i, Global.noteTableCreationPosition, date.toString(Global.getDateFormat()+" " +Global.getTimeFormat()));
3641 noteTableView.proxyModel.invalidate();
3646 logger.log(logger.HIGH, "Leaving NeverNote.updateListDateCreated");
3648 @SuppressWarnings("unused")
3649 private void updateListDateSubject(String guid, QDateTime date) {
3650 logger.log(logger.HIGH, "Entering NeverNote.updateListDateSubject");
3652 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
3653 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
3654 if (modelIndex != null) {
3655 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
3656 String tableGuid = (String)ix.values().toArray()[0];
3657 if (tableGuid.equals(guid)) {
3658 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
3659 listManager.getNoteTableModel().setData(i, Global.noteTableSubjectDatePosition, date.toString(Global.getDateFormat()+" " +Global.getTimeFormat()));
3660 noteTableView.proxyModel.invalidate();
3665 logger.log(logger.HIGH, "Leaving NeverNote.updateListDateCreated");
3667 private void updateListDateChanged(String guid, QDateTime date) {
3668 logger.log(logger.HIGH, "Entering NeverNote.updateListDateChanged");
3670 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
3671 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
3672 if (modelIndex != null) {
3673 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
3674 String tableGuid = (String)ix.values().toArray()[0];
3675 if (tableGuid.equals(guid)) {
3676 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
3677 listManager.getNoteTableModel().setData(i, Global.noteTableChangedPosition, date.toString(Global.getDateFormat()+" " +Global.getTimeFormat()));
3682 logger.log(logger.HIGH, "Leaving NeverNote.updateListDateChanged");
3684 private void updateListDateChanged() {
3685 logger.log(logger.HIGH, "Entering NeverNote.updateListDateChanged");
3686 QDateTime date = new QDateTime(QDateTime.currentDateTime());
3687 updateListDateChanged(currentNoteGuid, date);
3688 logger.log(logger.HIGH, "Leaving NeverNote.updateListDateChanged");
3691 private void scrollToCurrentGuid() {
3692 //scrollToGuid(currentNoteGuid);
3693 List<QModelIndex> selections = noteTableView.selectionModel().selectedRows();
3694 if (selections.size() == 0)
3696 QModelIndex index = selections.get(0);
3697 int row = selections.get(0).row();
3698 String guid = (String)index.model().index(row, Global.noteTableGuidPosition).data();
3701 // Scroll to a particular index item
3702 private void scrollToGuid(String guid) {
3703 if (currentNote == null || guid == null)
3705 if (currentNote.isActive() && Global.showDeleted) {
3706 for (int i=0; i<listManager.getNoteIndex().size(); i++) {
3707 if (!listManager.getNoteIndex().get(i).isActive()) {
3708 currentNote = listManager.getNoteIndex().get(i);
3709 currentNoteGuid = currentNote.getGuid();
3710 i = listManager.getNoteIndex().size();
3715 if (!currentNote.isActive() && !Global.showDeleted) {
3716 for (int i=0; i<listManager.getNoteIndex().size(); i++) {
3717 if (listManager.getNoteIndex().get(i).isActive()) {
3718 currentNote = listManager.getNoteIndex().get(i);
3719 currentNoteGuid = currentNote.getGuid();
3720 i = listManager.getNoteIndex().size();
3726 for (int i=0; i<noteTableView.model().rowCount(); i++) {
3727 index = noteTableView.model().index(i, Global.noteTableGuidPosition);
3728 if (currentNoteGuid.equals(index.data())) {
3729 // noteTableView.setCurrentIndex(index);
3730 noteTableView.selectRow(i);
3731 noteTableView.scrollTo(index, ScrollHint.EnsureVisible); // This should work, but it doesn't
3732 i=listManager.getNoteTableModel().rowCount();
3735 noteTableView.repaint();
3737 // Show/Hide columns
3738 private void showColumns() {
3739 noteTableView.setColumnHidden(Global.noteTableCreationPosition, !Global.isColumnVisible("dateCreated"));
3740 noteTableView.setColumnHidden(Global.noteTableChangedPosition, !Global.isColumnVisible("dateChanged"));
3741 noteTableView.setColumnHidden(Global.noteTableSubjectDatePosition, !Global.isColumnVisible("dateSubject"));
3742 noteTableView.setColumnHidden(Global.noteTableAuthorPosition, !Global.isColumnVisible("author"));
3743 noteTableView.setColumnHidden(Global.noteTableSourceUrlPosition, !Global.isColumnVisible("sourceUrl"));
3744 noteTableView.setColumnHidden(Global.noteTableTagPosition, !Global.isColumnVisible("tags"));
3745 noteTableView.setColumnHidden(Global.noteTableNotebookPosition, !Global.isColumnVisible("notebook"));
3746 noteTableView.setColumnHidden(Global.noteTableSynchronizedPosition, !Global.isColumnVisible("synchronized"));
3747 noteTableView.setColumnHidden(Global.noteTableGuidPosition, !Global.isColumnVisible("guid"));
3748 noteTableView.setColumnHidden(Global.noteTableThumbnailPosition, !Global.isColumnVisible("thumbnail"));
3749 noteTableView.setColumnHidden(Global.noteTableTitlePosition, !Global.isColumnVisible("title"));
3751 // Title color has changed
3752 @SuppressWarnings("unused")
3753 private void titleColorChanged(Integer color) {
3754 logger.log(logger.HIGH, "Entering NeverNote.updateListAuthor");
3756 QColor backgroundColor = new QColor();
3757 QColor foregroundColor = new QColor(QColor.black);
3758 backgroundColor.setRgb(color);
3760 if (backgroundColor.rgb() == QColor.black.rgb() || backgroundColor.rgb() == QColor.blue.rgb())
3761 foregroundColor.setRgb(QColor.white.rgb());
3763 if (selectedNoteGUIDs.size() == 0)
3764 selectedNoteGUIDs.add(currentNoteGuid);
3766 for (int j=0; j<selectedNoteGUIDs.size(); j++) {
3767 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
3768 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
3769 if (modelIndex != null) {
3770 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
3771 String tableGuid = (String)ix.values().toArray()[0];
3772 if (tableGuid.equals(selectedNoteGUIDs.get(j))) {
3773 for (int k=0; k<Global.noteTableColumnCount; k++) {
3774 listManager.getNoteTableModel().setData(i, k, backgroundColor, Qt.ItemDataRole.BackgroundRole);
3775 listManager.getNoteTableModel().setData(i, k, foregroundColor, Qt.ItemDataRole.ForegroundRole);
3776 listManager.updateNoteTitleColor(selectedNoteGUIDs.get(j), backgroundColor.rgb());
3778 i=listManager.getNoteTableModel().rowCount();
3783 logger.log(logger.HIGH, "Leaving NeverNote.updateListAuthor");
3785 // Wide list was chosen
3786 public void narrowListView() {
3787 saveNoteColumnPositions();
3788 saveNoteIndexWidth();
3790 int sortCol = noteTableView.proxyModel.sortColumn();
3791 int sortOrder = noteTableView.proxyModel.sortOrder().value();
3792 Global.setSortColumn(sortCol);
3793 Global.setSortOrder(sortOrder);
3795 Global.setListView(Global.View_List_Narrow);
3797 menuBar.wideListView.blockSignals(true);
3798 menuBar.narrowListView.blockSignals(true);
3800 menuBar.wideListView.setChecked(false);
3801 menuBar.narrowListView.setChecked(true);
3803 menuBar.wideListView.blockSignals(false);
3804 menuBar.narrowListView.blockSignals(false);
3806 mainLeftRightSplitter.addWidget(noteTableView);
3807 mainLeftRightSplitter.addWidget(browserWindow);
3808 restoreWindowState(false);
3809 noteTableView.repositionColumns();
3810 noteTableView.resizeColumnWidths();
3811 noteTableView.resizeRowHeights();
3813 sortCol = Global.getSortColumn();
3814 sortOrder = Global.getSortOrder();
3815 noteTableView.sortByColumn(sortCol, SortOrder.resolve(sortOrder));
3818 noteTableView.load(false);
3819 scrollToCurrentGuid();
3821 public void wideListView() {
3822 int sortCol = noteTableView.proxyModel.sortColumn();
3823 int sortOrder = noteTableView.proxyModel.sortOrder().value();
3824 Global.setSortColumn(sortCol);
3825 Global.setSortOrder(sortOrder);
3828 saveNoteColumnPositions();
3829 saveNoteIndexWidth();
3830 Global.setListView(Global.View_List_Wide);
3832 menuBar.wideListView.blockSignals(true);
3833 menuBar.narrowListView.blockSignals(true);
3835 menuBar.wideListView.setChecked(true);
3836 menuBar.narrowListView.setChecked(false);
3838 menuBar.wideListView.blockSignals(false);
3839 menuBar.narrowListView.blockSignals(false);
3840 browserIndexSplitter.setVisible(true);
3841 browserIndexSplitter.addWidget(noteTableView);
3842 browserIndexSplitter.addWidget(browserWindow);
3843 restoreWindowState(false);
3844 noteTableView.repositionColumns();
3845 noteTableView.resizeColumnWidths();
3846 noteTableView.resizeRowHeights();
3848 sortCol = Global.getSortColumn();
3849 sortOrder = Global.getSortOrder();
3850 noteTableView.sortByColumn(sortCol, SortOrder.resolve(sortOrder));
3853 noteTableView.load(false);
3854 scrollToCurrentGuid();
3858 //***************************************************************
3859 //***************************************************************
3860 //** External editor window functions
3861 //***************************************************************
3862 //***************************************************************
3863 private void listDoubleClick() {
3865 if (externalWindows.containsKey(currentNoteGuid)) {
3866 externalWindows.get(currentNoteGuid).raise();
3869 // We have a new external editor to create
3870 QIcon appIcon = new QIcon(iconPath+"nevernote.png");
3871 ExternalBrowse newBrowser = new ExternalBrowse(conn);
3872 newBrowser.setWindowIcon(appIcon);
3873 externalWindows.put(currentNoteGuid, newBrowser);
3874 showEditorButtons(newBrowser.getBrowserWindow());
3875 loadNoteBrowserInformation(newBrowser.getBrowserWindow());
3876 setupBrowserWindowListeners(newBrowser.getBrowserWindow(), false);
3877 newBrowser.windowClosing.connect(this, "externalWindowClosing(String)");
3878 newBrowser.getBrowserWindow().noteSignal.titleChanged.connect(this, "externalWindowTitleEdited(String, String)");
3879 newBrowser.getBrowserWindow().noteSignal.tagsChanged.connect(this, "externalWindowTagsEdited(String, List)");
3880 newBrowser.contentsChanged.connect(this, "saveNoteExternalBrowser(String, String, Boolean, BrowserWindow)");
3882 browserWindow.noteSignal.tagsChanged.connect(newBrowser, "updateTags(String, List)");
3883 browserWindow.noteSignal.titleChanged.connect(newBrowser, "updateTitle(String, String)");
3884 browserWindow.noteSignal.notebookChanged.connect(newBrowser, "updateNotebook(String, String)");
3888 @SuppressWarnings("unused")
3889 private void externalWindowTitleEdited(String guid, String text) {
3890 if (guid.equals(currentNoteGuid)) {
3891 browserWindow.setTitle(text);
3894 @SuppressWarnings({ "rawtypes", "unused" })
3895 private void externalWindowTagsEdited(String guid, List values) {
3896 StringBuffer line = new StringBuffer(100);
3897 for (int i=0; i<values.size(); i++) {
3899 line.append(Global.tagDelimeter+" ");
3900 line.append(values.get(i));
3902 if (guid.equals(currentNoteGuid)) {
3903 browserWindow.setTag(line.toString());
3906 @SuppressWarnings("unused")
3907 private void externalWindowClosing(String guid) {
3908 externalWindows.remove(guid);
3913 //***************************************************************
3914 //***************************************************************
3915 //** These functions deal with Note specific things
3916 //***************************************************************
3917 //***************************************************************
3918 @SuppressWarnings("unused")
3919 private void setNoteDirty() {
3920 logger.log(logger.EXTREME, "Entering NeverNote.setNoteDirty()");
3921 // Find if the note is being edited externally. If it is, update it.
3922 if (externalWindows.containsKey(currentNoteGuid)) {
3923 QTextCodec codec = QTextCodec.codecForName("UTF-8");
3924 QByteArray unicode = codec.fromUnicode(browserWindow.getContent());
3925 ExternalBrowse window = externalWindows.get(currentNoteGuid);
3926 window.getBrowserWindow().getBrowser().setContent(unicode);
3929 // If the note is dirty, then it is unsynchronized by default.
3933 // Set the note as dirty and check if its status is synchronized in the display table
3935 for (int i=0; i<listManager.getUnsynchronizedNotes().size(); i++) {
3936 if (listManager.getUnsynchronizedNotes().get(i).equals(currentNoteGuid))
3940 // If this wasn't already marked as unsynchronized, then we need to update the table
3941 listManager.getNoteTableModel().updateNoteSyncStatus(currentNoteGuid, false);
3942 /* listManager.getUnsynchronizedNotes().add(currentNoteGuid);
3943 for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
3944 QModelIndex modelIndex = listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
3945 if (modelIndex != null) {
3946 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
3947 String tableGuid = (String)ix.values().toArray()[0];
3948 if (tableGuid.equals(currentNoteGuid)) {
3949 listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
3955 logger.log(logger.EXTREME, "Leaving NeverNote.setNoteDirty()");
3957 @SuppressWarnings("unused")
3958 private void saveNoteExternalBrowser(String guid, String content, Boolean save, BrowserWindow browser) {
3959 QTextCodec codec = QTextCodec.codecForName("UTF-8");
3960 QByteArray unicode = codec.fromUnicode(content);
3961 noteCache.remove(guid);
3962 noteCache.put(guid, unicode.toString());
3963 if (guid.equals(currentNoteGuid)) {
3965 browserWindow.getBrowser().setContent(unicode);
3968 thumbnailRunner.addWork("GENERATE "+ guid);
3969 saveNote(guid, browser);
3973 private void saveNote() {
3975 saveNote(currentNoteGuid, browserWindow);
3976 thumbnailRunner.addWork("GENERATE "+ currentNoteGuid);
3980 private void saveNote(String guid, BrowserWindow window) {
3981 logger.log(logger.EXTREME, "Inside NeverNote.saveNote()");
3982 logger.log(logger.EXTREME, "Note is dirty.");
3985 logger.log(logger.EXTREME, "Saving to cache");
3986 QTextCodec codec = QTextCodec.codecForLocale();
3987 // QTextDecoder decoder = codec.makeDecoder();
3988 codec = QTextCodec.codecForName("UTF-8");
3989 QByteArray unicode = codec.fromUnicode(window.getContent());
3990 noteCache.put(guid, unicode.toString());
3992 logger.log(logger.EXTREME, "updating list manager");
3993 listManager.updateNoteContent(guid, window.getContent());
3994 logger.log(logger.EXTREME, "Updating title");
3995 listManager.updateNoteTitle(guid, window.getTitle());
3996 updateListDateChanged();
3998 logger.log(logger.EXTREME, "Looking through note index for refreshed note");
3999 for (int i=0; i<listManager.getNoteIndex().size(); i++) {
4000 if (listManager.getNoteIndex().get(i).getGuid().equals(guid)) {
4001 currentNote = listManager.getNoteIndex().get(i);
4002 i = listManager.getNoteIndex().size();
4007 // Get a note from Evernote (and put it in the browser)
4008 private void refreshEvernoteNote(boolean reload) {
4009 logger.log(logger.HIGH, "Entering NeverNote.refreshEvernoteNote");
4011 if (Global.disableViewing) {
4012 browserWindow.setEnabled(false);
4017 if (Global.showDeleted)
4019 Global.cryptCounter =0;
4020 if (currentNoteGuid.equals("")) {
4021 browserWindow.setReadOnly(true);
4029 browserWindow.loadingData(true);
4031 currentNote = conn.getNoteTable().getNote(currentNoteGuid, true,true,false,false,true);
4032 if (currentNote == null)
4035 loadNoteBrowserInformation(browserWindow);
4038 private void loadNoteBrowserInformation(BrowserWindow browser) {
4039 NoteFormatter formatter = new NoteFormatter(logger, conn, tempFiles);
4040 formatter.setNote(currentNote, Global.pdfPreview());
4041 formatter.setHighlight(listManager.getEnSearch());
4043 if (!noteCache.containsKey(currentNoteGuid) || conn.getNoteTable().isThumbnailNeeded(currentNoteGuid)) {
4044 js = new QByteArray();
4045 // We need to prepend the note with <HEAD></HEAD> or encoded characters are ugly
4046 js.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
4047 js.append("<style type=\"text/css\">.en-crypt-temp { border-collapse:collapse; border-style:solid; border-color:blue; padding:0.0mm 0.0mm 0.0mm 0.0mm; }</style>");
4048 js.append("<style type=\"text/css\">en-hilight { background-color: rgb(255,255,0) }</style>");
4049 js.append("<style> img { max-width:100%; }</style>");
4050 js.append("<style type=\"text/css\">en-spell { text-decoration: none; border-bottom: dotted 1px #cc0000; }</style>");
4051 js.append("</head>");
4052 formatter.setNote(currentNote, Global.pdfPreview());
4053 js.append(formatter.rebuildNoteHTML());
4054 js.append("</HTML>");
4055 js.replace("<!DOCTYPE en-note SYSTEM 'http://xml.evernote.com/pub/enml.dtd'>", "");
4056 js.replace("<!DOCTYPE en-note SYSTEM 'http://xml.evernote.com/pub/enml2.dtd'>", "");
4057 js.replace("<?xml version='1.0' encoding='UTF-8'?>", "");
4058 browser.getBrowser().setContent(js);
4059 noteCache.put(currentNoteGuid, js.toString());
4061 if (formatter.resourceError)
4062 resourceErrorMessage();
4063 readOnly = formatter.readOnly;
4064 inkNote = formatter.inkNote;
4066 readOnlyCache.put(currentNoteGuid, true);
4068 inkNoteCache.put(currentNoteGuid, true);
4070 logger.log(logger.HIGH, "Note content is being pulled from the cache");
4071 String cachedContent = formatter.modifyCachedTodoTags(noteCache.get(currentNoteGuid));
4072 js = new QByteArray(cachedContent);
4073 browser.getBrowser().setContent(js);
4074 if (readOnlyCache.containsKey(currentNoteGuid))
4076 if (inkNoteCache.containsKey(currentNoteGuid))
4079 if (conn.getNoteTable().isThumbnailNeeded(currentNoteGuid)) {
4080 thumbnailHTMLReady(currentNoteGuid, js, Global.calculateThumbnailZoom(js.toString()));
4083 if (readOnly || inkNote)
4084 browser.getBrowser().page().setContentEditable(false); // We don't allow editing of ink notes
4086 browser.getBrowser().page().setContentEditable(true);
4087 browser.setReadOnly(readOnly);
4088 deleteButton.setEnabled(!readOnly);
4089 tagButton.setEnabled(!readOnly);
4090 menuBar.noteDelete.setEnabled(!readOnly);
4091 menuBar.noteTags.setEnabled(!readOnly);
4092 browser.setNote(currentNote);
4094 if (conn.getNotebookTable().isLinked(currentNote.getNotebookGuid())) {
4095 deleteButton.setEnabled(false);
4096 menuBar.notebookDeleteAction.setEnabled(false);
4098 deleteButton.setEnabled(true);
4099 menuBar.notebookDeleteAction.setEnabled(true);
4102 // Build a list of non-closed notebooks
4103 List<Notebook> nbooks = new ArrayList<Notebook>();
4104 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
4105 boolean found=false;
4106 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
4107 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
4111 nbooks.add(listManager.getNotebookIndex().get(i));
4114 browser.setTitle(currentNote.getTitle());
4115 browser.setTag(getTagNamesForNote(currentNote));
4116 browser.setAuthor(currentNote.getAttributes().getAuthor());
4118 browser.setAltered(currentNote.getUpdated());
4119 browser.setCreation(currentNote.getCreated());
4120 if (currentNote.getAttributes().getSubjectDate() > 0)
4121 browser.setSubjectDate(currentNote.getAttributes().getSubjectDate());
4123 browser.setSubjectDate(currentNote.getCreated());
4124 browser.setUrl(currentNote.getAttributes().getSourceURL());
4126 FilterEditorTags tagFilter = new FilterEditorTags(conn, logger);
4127 List<Tag> tagList = tagFilter.getValidTags(currentNote);
4128 browser.setAllTags(tagList);
4130 browser.setCurrentTags(currentNote.getTagNames());
4132 scrollToGuid(currentNoteGuid);
4134 browser.loadingData(false);
4135 if (thumbnailViewer.isActiveWindow())
4138 FilterEditorNotebooks notebookFilter = new FilterEditorNotebooks(conn, logger);
4139 browser.setNotebookList(notebookFilter.getValidNotebooks(currentNote, listManager.getNotebookIndex()));
4142 logger.log(logger.HIGH, "Leaving NeverNote.refreshEvernoteNote");
4144 // Save a generated thumbnail
4145 private void toggleNoteInformation() {
4146 logger.log(logger.HIGH, "Entering NeverNote.toggleNoteInformation");
4147 browserWindow.toggleInformation();
4148 menuBar.noteAttributes.setChecked(browserWindow.isExtended());
4149 Global.saveWindowVisible("noteInformation", browserWindow.isExtended());
4150 logger.log(logger.HIGH, "Leaving NeverNote.toggleNoteInformation");
4152 // Listener triggered when a print button is pressed
4153 @SuppressWarnings("unused")
4154 private void printNote() {
4155 logger.log(logger.HIGH, "Entering NeverNote.printNote");
4157 QPrintDialog dialog = new QPrintDialog();
4158 if (dialog.exec() == QDialog.DialogCode.Accepted.value()) {
4159 QPrinter printer = dialog.printer();
4160 browserWindow.getBrowser().print(printer);
4162 logger.log(logger.HIGH, "Leaving NeverNote.printNote");
4165 // Listener triggered when the email button is pressed
4166 @SuppressWarnings("unused")
4167 private void emailNote() {
4168 logger.log(logger.HIGH, "Entering NeverNote.emailNote");
4170 if (Desktop.isDesktopSupported()) {
4171 Desktop desktop = Desktop.getDesktop();
4173 String text2 = browserWindow.getContentsToEmail();
4174 QUrl url = new QUrl("mailto:");
4175 url.addQueryItem("subject", currentNote.getTitle());
4176 // url.addQueryItem("body", QUrl.toPercentEncoding(text2).toString());
4177 url.addQueryItem("body", text2);
4178 QDesktopServices.openUrl(url);
4182 if (desktop.isSupported(Desktop.Action.MAIL)) {
4183 URI uriMailTo = null;
4185 //String text = browserWindow.getBrowser().page().currentFrame().toPlainText();
4186 String text = browserWindow.getContentsToEmail();
4187 //text = "<b>" +text +"</b>";
4188 uriMailTo = new URI("mailto", "&SUBJECT="+currentNote.getTitle()
4189 +"&BODY=" +text, null);
4190 uriMailTo = new URI("mailto", "&SUBJECT="+currentNote.getTitle()
4191 +"&ATTACHMENT=d:/test.pdf", null);
4192 desktop.mail(uriMailTo);
4193 } catch (URISyntaxException e) {
4194 e.printStackTrace();
4195 } catch (IOException e) {
4196 e.printStackTrace();
4203 logger.log(logger.HIGH, "Leaving NeverNote.emailNote");
4205 // Reindex all notes
4206 @SuppressWarnings("unused")
4207 private void fullReindex() {
4208 logger.log(logger.HIGH, "Entering NeverNote.fullReindex");
4209 indexRunner.addWork("REINDEXALL");
4210 setMessage(tr("Database will be reindexed."));
4211 logger.log(logger.HIGH, "Leaving NeverNote.fullReindex");
4213 // Listener when a user wants to reindex a specific note
4214 @SuppressWarnings("unused")
4215 private void reindexNote() {
4216 logger.log(logger.HIGH, "Entering NeverNote.reindexNote");
4217 for (int i=0; i<selectedNoteGUIDs.size(); i++) {
4218 indexRunner.addWork("REINDEXNOTE "+selectedNoteGUIDs.get(i));
4220 if (selectedNotebookGUIDs.size() > 1)
4221 setMessage(tr("Notes will be reindexed."));
4223 setMessage(tr("Note will be reindexed."));
4224 logger.log(logger.HIGH, "Leaving NeverNote.reindexNote");
4227 @SuppressWarnings("unused")
4228 private void deleteNote() {
4229 logger.log(logger.HIGH, "Entering NeverNote.deleteNote");
4230 if (currentNote == null)
4232 if (currentNoteGuid.equals(""))
4235 // If we are deleting non-trash notes
4236 if (currentNote.isActive()) {
4237 if (Global.verifyDelete()) {
4238 if (QMessageBox.question(this, tr("Confirmation"), tr("Delete selected note(s)?"),
4239 QMessageBox.StandardButton.Yes,
4240 QMessageBox.StandardButton.No)==StandardButton.No.value() && Global.verifyDelete() == true) {
4244 if (selectedNoteGUIDs.size() == 0 && !currentNoteGuid.equals(""))
4245 selectedNoteGUIDs.add(currentNoteGuid);
4246 for (int i=0; i<selectedNoteGUIDs.size(); i++) {
4247 listManager.deleteNote(selectedNoteGUIDs.get(i));
4250 // If we are deleting from the trash.
4251 if (Global.verifyDelete()) {
4252 if (QMessageBox.question(this, "Confirmation", "Permanently delete selected note(s)?",
4253 QMessageBox.StandardButton.Yes,
4254 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
4258 if (selectedNoteGUIDs.size() == 0 && !currentNoteGuid.equals(""))
4259 selectedNoteGUIDs.add(currentNoteGuid);
4260 for (int i=selectedNoteGUIDs.size()-1; i>=0; i--) {
4261 for (int j=listManager.getNoteTableModel().rowCount()-1; j>=0; j--) {
4262 QModelIndex modelIndex = listManager.getNoteTableModel().index(j, Global.noteTableGuidPosition);
4263 if (modelIndex != null) {
4264 SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
4265 String tableGuid = (String)ix.values().toArray()[0];
4266 if (tableGuid.equals(selectedNoteGUIDs.get(i))) {
4267 listManager.getNoteTableModel().removeRow(j);
4272 listManager.expungeNote(selectedNoteGUIDs.get(i));
4275 currentNoteGuid = "";
4276 listManager.loadNotesIndex();
4277 noteIndexUpdated(false);
4278 refreshEvernoteNote(true);
4279 scrollToGuid(currentNoteGuid);
4280 logger.log(logger.HIGH, "Leaving NeverNote.deleteNote");
4283 @SuppressWarnings("unused")
4284 private void addNote() {
4285 logger.log(logger.HIGH, "Inside NeverNote.addNote");
4286 // browserWindow.setEnabled(true);
4287 browserWindow.setReadOnly(false);
4289 Calendar currentTime = new GregorianCalendar();
4290 StringBuffer noteString = new StringBuffer(100);
4291 noteString.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
4292 "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">\n" +
4295 if (Global.overrideDefaultFont()) {
4296 noteString.append("<font face=\"" +Global.getDefaultFont() +"\" >");
4297 noteString.append("<span style=\"font-size:" +Global.getDefaultFontSize() +"pt;\">");
4298 noteString.append("<br clear=\"none\" />\n");
4299 noteString.append("</span>\n</font>\n");
4301 noteString.append("<br clear=\"none\" />\n");
4302 noteString.append("</en-note>");
4304 Long l = new Long(currentTime.getTimeInMillis());
4305 String randint = new String(Long.toString(l));
4307 // Find a notebook. We first look for a selected notebook (the "All Notebooks" one doesn't count).
4309 // for the first non-archived notebook. Finally, if nothing else we
4310 // pick the first notebook in the list.
4311 String notebook = null;
4312 listManager.getNotebookIndex().get(0).getGuid();
4313 List<QTreeWidgetItem> selectedNotebook = notebookTree.selectedItems();
4314 if (selectedNotebook.size() > 0 && !selectedNotebook.get(0).text(0).equalsIgnoreCase("All Notebooks")) {
4315 QTreeWidgetItem currentSelectedNotebook = selectedNotebook.get(0);
4316 notebook = currentSelectedNotebook.text(2);
4318 boolean found = false;
4319 List<Notebook> goodNotebooks = new ArrayList<Notebook>();
4320 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
4321 boolean match = false;
4322 for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
4323 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid())) {
4325 j = listManager.getArchiveNotebookIndex().size();
4329 goodNotebooks.add(listManager.getNotebookIndex().get(i).deepCopy());
4331 // Now we have a list of good notebooks, so we can look for the default
4333 for (int i=0; i<goodNotebooks.size(); i++) {
4334 if (goodNotebooks.get(i).isDefaultNotebook()) {
4335 notebook = goodNotebooks.get(i).getGuid();
4337 i = goodNotebooks.size();
4341 if (goodNotebooks.size() > 0 && !found)
4342 notebook = goodNotebooks.get(0).getGuid();
4345 notebook = listManager.getNotebookIndex().get(0).getGuid();
4348 Note newNote = new Note();
4349 newNote.setUpdateSequenceNum(0);
4350 newNote.setGuid(randint);
4351 newNote.setNotebookGuid(notebook);
4352 newNote.setTitle("");
4353 newNote.setContent(noteString.toString());
4354 newNote.setDeleted(0);
4355 newNote.setCreated(System.currentTimeMillis());
4356 newNote.setUpdated(System.currentTimeMillis());
4357 newNote.setActive(true);
4358 NoteAttributes na = new NoteAttributes();
4359 na.setLatitude(0.0);
4360 na.setLongitude(0.0);
4361 na.setAltitude(0.0);
4362 newNote.setAttributes(new NoteAttributes());
4363 newNote.setTagGuids(new ArrayList<String>());
4364 newNote.setTagNames(new ArrayList<String>());
4366 // If new notes are to be created based upon the selected tags, then we need to assign the tags
4367 if (Global.newNoteWithSelectedTags()) {
4368 List<QTreeWidgetItem> selections = tagTree.selectedItems();
4369 QTreeWidgetItem currentSelection;
4370 for (int i=0; i<selections.size(); i++) {
4371 currentSelection = selections.get(i);
4372 newNote.getTagGuids().add(currentSelection.text(2));
4373 newNote.getTagNames().add(currentSelection.text(0));
4377 conn.getNoteTable().addNote(newNote, true);
4378 listManager.getUnsynchronizedNotes().add(newNote.getGuid());
4379 listManager.addNote(newNote);
4380 // noteTableView.insertRow(newNote, true, -1);
4382 currentNote = newNote;
4383 currentNoteGuid = currentNote.getGuid();
4384 refreshEvernoteNote(true);
4385 listManager.countNotebookResults(listManager.getNoteIndex());
4386 browserWindow.titleLabel.setFocus();
4387 browserWindow.titleLabel.selectAll();
4388 // notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
4390 // If the window is hidden, then we want to popup this in an external window &
4393 logger.log(logger.HIGH, "Leaving NeverNote.addNote");
4395 // Restore a note from the trash;
4396 @SuppressWarnings("unused")
4397 private void restoreNote() {
4399 if (selectedNoteGUIDs.size() == 0 && !currentNoteGuid.equals(""))
4400 selectedNoteGUIDs.add(currentNoteGuid);
4401 for (int i=0; i<selectedNoteGUIDs.size(); i++) {
4402 listManager.restoreNote(selectedNoteGUIDs.get(i));
4404 currentNoteGuid = "";
4405 listManager.loadNotesIndex();
4406 noteIndexUpdated(false);
4409 // Search a note for specific txt
4410 @SuppressWarnings("unused")
4411 private void findText() {
4413 find.setFocusOnTextField();
4415 @SuppressWarnings("unused")
4416 private void doFindText() {
4417 browserWindow.getBrowser().page().findText(find.getText(), find.getFlags());
4420 @SuppressWarnings("unused")
4421 private void updateNoteTitle(String guid, String title) {
4422 listManager.setNoteSynchronized(guid, false);
4424 // Signal received that note content has changed. Normally we just need the guid to remove
4425 // it from the cache.
4426 @SuppressWarnings("unused")
4427 private void invalidateNoteCache(String guid, String content) {
4428 String v = noteCache.remove(guid);
4429 // if (guid.equals(currentNoteGuid) && !noteDirty)
4430 refreshEvernoteNote(true);
4432 // Signal received that a note guid has changed
4433 @SuppressWarnings("unused")
4434 private void noteGuidChanged(String oldGuid, String newGuid) {
4435 if (noteCache.containsKey(oldGuid)) {
4436 if (!oldGuid.equals(currentNoteGuid)) {
4437 String cache = noteCache.get(oldGuid);
4438 noteCache.put(newGuid, cache);
4439 noteCache.remove(oldGuid);
4441 noteCache.remove(oldGuid);
4442 noteCache.put(newGuid, browserWindow.getContent());
4446 listManager.updateNoteGuid(oldGuid, newGuid, false);
4447 if (currentNoteGuid.equals(oldGuid)) {
4448 if (currentNote != null)
4449 currentNote.setGuid(newGuid);
4450 currentNoteGuid = newGuid;
4453 if (externalWindows.containsKey(oldGuid)) {
4454 ExternalBrowse b = externalWindows.get(oldGuid);
4455 externalWindows.remove(oldGuid);
4456 b.getBrowserWindow().getNote().setGuid(newGuid);
4457 externalWindows.put(newGuid, b);
4460 for (int i=0; i<listManager.getNoteIndex().size(); i++) {
4461 if (listManager.getNoteIndex().get(i).getGuid().equals(newGuid)) {
4462 noteTableView.proxyModel.addGuid(newGuid);
4463 i=listManager.getNoteIndex().size();
4467 if (listManager.getNoteTableModel().titleColors.containsKey(oldGuid)) {
4468 int color = listManager.getNoteTableModel().titleColors.get(oldGuid);
4469 listManager.getNoteTableModel().titleColors.put(newGuid, color);
4470 listManager.getNoteTableModel().titleColors.remove(oldGuid);
4474 // Toggle the note editor button bar
4475 private void toggleEditorButtonBar() {
4476 if (browserWindow.buttonsVisible) {
4477 browserWindow.hideButtons();
4478 menuBar.showEditorBar.setChecked(browserWindow.buttonsVisible);
4479 // Global.saveWindowVisible("editorButtonBar", browserWindow.buttonsVisible);
4481 browserWindow.buttonsVisible = true;
4482 showEditorButtons(browserWindow);
4484 Global.saveWindowVisible("editorButtonBar", browserWindow.buttonsVisible);
4486 // Show editor buttons
4487 private void showEditorButtons(BrowserWindow browser) {
4488 browser.buttonLayout.setVisible(true);
4489 browser.undoAction.setVisible(false);
4491 browser.undoButton.setVisible(false);
4493 browser.undoAction.setVisible(Global.isEditorButtonVisible("undo"));
4494 browser.redoAction.setVisible(Global.isEditorButtonVisible("redo"));
4495 browser.cutAction.setVisible(Global.isEditorButtonVisible("cut"));
4496 browser.copyAction.setVisible(Global.isEditorButtonVisible("copy"));
4497 browser.pasteAction.setVisible(Global.isEditorButtonVisible("paste"));
4498 browser.strikethroughAction.setVisible(Global.isEditorButtonVisible("strikethrough"));
4499 browser.underlineAction.setVisible(Global.isEditorButtonVisible("underline"));
4500 browser.boldAction.setVisible(Global.isEditorButtonVisible("bold"));
4501 browser.italicAction.setVisible(Global.isEditorButtonVisible("italic"));
4502 browser.hlineAction.setVisible(Global.isEditorButtonVisible("hline"));
4503 browser.indentAction.setVisible(Global.isEditorButtonVisible("indent"));
4504 browser.outdentAction.setVisible(Global.isEditorButtonVisible("outdent"));
4505 browser.bulletListAction.setVisible(Global.isEditorButtonVisible("bulletList"));
4506 browser.numberListAction.setVisible(Global.isEditorButtonVisible("numberList"));
4507 browser.fontListAction.setVisible(Global.isEditorButtonVisible("font"));
4508 browser.fontSizeAction.setVisible(Global.isEditorButtonVisible("fontSize"));
4509 browser.fontColorAction.setVisible(Global.isEditorButtonVisible("fontColor"));
4510 browser.fontHilightAction.setVisible(Global.isEditorButtonVisible("fontHilight"));
4511 browser.leftAlignAction.setVisible(Global.isEditorButtonVisible("alignLeft"));
4512 browser.centerAlignAction.setVisible(Global.isEditorButtonVisible("alignCenter"));
4513 browser.rightAlignAction.setVisible(Global.isEditorButtonVisible("alignRight"));
4514 browser.spellCheckAction.setVisible(Global.isEditorButtonVisible("spellCheck"));
4515 browser.todoAction.setVisible(Global.isEditorButtonVisible("todo"));
4517 private void duplicateNote(String guid) {
4519 Note oldNote = conn.getNoteTable().getNote(guid, true, true, false, false, false);
4520 List<Resource> resList = conn.getNoteTable().noteResourceTable.getNoteResources(guid, true);
4521 oldNote.setContent(conn.getNoteTable().getNoteContentBinary(guid));
4522 oldNote.setResources(resList);
4523 duplicateNote(oldNote);
4525 private void duplicateNote(Note oldNote) {
4527 // Now that we have a good notebook guid, we need to move the conflicting note
4528 // to the local notebook
4529 Calendar currentTime = new GregorianCalendar();
4530 Long l = new Long(currentTime.getTimeInMillis());
4531 String newGuid = new String(Long.toString(l));
4533 Note newNote = oldNote.deepCopy();
4534 newNote.setUpdateSequenceNum(0);
4535 newNote.setGuid(newGuid);
4536 newNote.setDeleted(0);
4537 newNote.setActive(true);
4538 List<Resource> resList = oldNote.getResources();
4539 if (resList == null)
4540 resList = new ArrayList<Resource>();
4542 for (int i=0; i<resList.size(); i++) {
4544 while (l == prevGuid) {
4545 currentTime = new GregorianCalendar();
4546 l = new Long(currentTime.getTimeInMillis());
4549 String newResGuid = new String(Long.toString(l));
4550 resList.get(i).setNoteGuid(newGuid);
4551 resList.get(i).setGuid(newResGuid);
4552 resList.get(i).setUpdateSequenceNum(0);
4553 resList.get(i).setActive(true);
4554 conn.getNoteTable().noteResourceTable.saveNoteResource(new Resource(resList.get(i).deepCopy()), true);
4556 newNote.setResources(resList);
4557 listManager.addNote(newNote);
4558 conn.getNoteTable().addNote(newNote, true);
4559 listManager.getUnsynchronizedNotes().add(newNote.getGuid());
4560 noteTableView.insertRow(newNote, true, -1);
4561 listManager.countNotebookResults(listManager.getNoteIndex());
4565 @SuppressWarnings("unused")
4566 private void allNotes() {
4567 clearAttributeFilter();
4568 clearNotebookFilter();
4569 clearSavedSearchFilter();
4572 searchField.clear();
4573 if (Global.mimicEvernoteInterface) {
4574 notebookTree.selectGuid("");
4576 notebookTreeSelection();
4579 @SuppressWarnings("unused")
4580 private void mergeNotes() {
4581 logger.log(logger.HIGH, "Merging notes");
4584 String masterGuid = null;
4585 List<String> sources = new ArrayList<String>();
4587 for (int i=0; i<noteTableView.selectionModel().selectedRows().size(); i++) {
4588 int r = noteTableView.selectionModel().selectedRows().get(i).row();
4589 index = noteTableView.proxyModel.index(r, Global.noteTableGuidPosition);
4590 SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(index);
4592 masterGuid = (String)ix.values().toArray()[0];
4594 sources.add((String)ix.values().toArray()[0]);
4597 logger.log(logger.EXTREME, "Master guid=" +masterGuid);
4598 logger.log(logger.EXTREME, "Children count: "+sources.size());
4599 mergeNoteContents(masterGuid, sources);
4600 currentNoteGuid = masterGuid;
4601 noteIndexUpdated(false);
4602 refreshEvernoteNote(true);
4605 private void mergeNoteContents(String targetGuid, List<String> sources) {
4606 Note target = conn.getNoteTable().getNote(targetGuid, true, false, false, false, false);
4607 String newContent = target.getContent();
4608 newContent = newContent.replace("</en-note>", "<br></br>");
4610 for (int i=0; i<sources.size(); i++) {
4611 Note source = conn.getNoteTable().getNote(sources.get(i), true, true, false, false, false);
4612 if (source.isSetTitle()) {
4613 newContent = newContent +("<table bgcolor=\"lightgrey\"><tr><td><font size=\"6\"><b>" +source.getTitle() +"</b></font></td></tr></table>");
4615 String sourceContent = source.getContent();
4616 logger.log(logger.EXTREME, "Merging contents into note");
4617 logger.log(logger.EXTREME, sourceContent);
4618 logger.log(logger.EXTREME, "End of content");
4619 int startOfNote = sourceContent.indexOf("<en-note>");
4620 sourceContent = sourceContent.substring(startOfNote+9);
4621 int endOfNote = sourceContent.indexOf("</en-note>");
4622 sourceContent = sourceContent.substring(0,endOfNote);
4623 newContent = newContent + sourceContent;
4624 logger.log(logger.EXTREME, "New note content");
4625 logger.log(logger.EXTREME, newContent);
4626 logger.log(logger.EXTREME, "End of content");
4627 for (int j=0; j<source.getResourcesSize(); j++) {
4628 logger.log(logger.EXTREME, "Reassigning resource: "+source.getResources().get(j).getGuid());
4629 Resource r = source.getResources().get(j);
4630 Resource newRes = conn.getNoteTable().noteResourceTable.getNoteResource(r.getGuid(), true);
4632 Calendar currentTime = new GregorianCalendar();
4633 Long l = new Long(currentTime.getTimeInMillis());
4637 while (l == prevGuid) {
4638 currentTime = new GregorianCalendar();
4639 l = new Long(currentTime.getTimeInMillis());
4641 String newResGuid = new String(Long.toString(l));
4642 newRes.setNoteGuid(targetGuid);
4643 newRes.setGuid(newResGuid);
4644 newRes.setUpdateSequenceNum(0);
4645 newRes.setActive(true);
4646 conn.getNoteTable().noteResourceTable.saveNoteResource(newRes, true);
4649 logger.log(logger.EXTREME, "Updating note");
4650 conn.getNoteTable().updateNoteContent(targetGuid, newContent +"</en-note>");
4651 for (int i=0; i<sources.size(); i++) {
4652 logger.log(logger.EXTREME, "Deleting note " +sources.get(i));
4653 listManager.deleteNote(sources.get(i));
4655 logger.log(logger.EXTREME, "Exiting merge note");
4657 // A resource within a note has had a guid change
4658 @SuppressWarnings("unused")
4659 private void noteResourceGuidChanged(String noteGuid, String oldGuid, String newGuid) {
4660 if (!oldGuid.equals(newGuid))
4661 Global.resourceMap.put(oldGuid, newGuid);
4663 // View a thumbnail of the note
4664 public void thumbnailView() {
4666 String thumbnailName = Global.getFileManager().getResDirPath("thumbnail-" + currentNoteGuid + ".png");
4667 QFile thumbnail = new QFile(thumbnailName);
4668 if (!thumbnail.exists()) {
4670 QImage img = new QImage();
4671 img.loadFromData(conn.getNoteTable().getThumbnail(currentNoteGuid));
4672 thumbnailViewer.setThumbnail(img);
4674 thumbnailViewer.setThumbnail(thumbnailName);
4675 if (!thumbnailViewer.isVisible())
4676 thumbnailViewer.showFullScreen();
4678 // An error happened while saving a note. Inform the user
4679 @SuppressWarnings("unused")
4680 private void saveRunnerError(String guid, String msg) {
4682 String title = "*Unknown*";
4683 for (int i=0; i<listManager.getMasterNoteIndex().size(); i++) {
4684 if (listManager.getMasterNoteIndex().get(i).getGuid().equals(guid)) {
4685 title = listManager.getMasterNoteIndex().get(i).getTitle();
4686 i=listManager.getMasterNoteIndex().size();
4689 msg = "An error has happened while saving the note \"" +title+
4690 "\".\n\nThis is probably due to a document that is too complex for Nevernote to process. "+
4691 "As a result, changes to the note may not be saved properly in the database."+
4692 "\n\nA cached copy is being preserved so you can recover any data, but data may" +
4693 "\nbe lost. Please review the note to recover any critical data before restarting.";
4695 QMessageBox.information(this, tr("Error Saving Note"), tr(msg));
4698 private void thumbnailHTMLReady(String guid, QByteArray html, Integer zoom) {
4699 logger.log(logger.HIGH, "Entering thumnailHTMLReady()");
4700 logger.log(logger.HIGH, "Thumbnail ready for " +guid);
4701 // Find an idle preview object
4702 for (int i=0; i<thumbGenerators.size(); i++) {
4703 if (thumbGenerators.get(i).mutex.tryLock()) {
4704 logger.log(logger.EXTREME, "Idle generator found - loading thumbnail for " +guid);
4705 thumbGenerators.get(i).loadContent(guid, html, zoom);
4709 if (thumbGenerators.size() >= 1) {
4710 logger.log(logger.EXTREME, "No available thumbnail generators. Aborting " +guid);
4714 logger.log(logger.EXTREME, "Creating new thumbnail generator " +guid);
4715 Thumbnailer preview = new Thumbnailer(logger, conn, listManager, thumbnailRunner);
4716 thumbGenerators.add(preview);
4718 if (preview.mutex.tryLock()) {
4719 logger.log(logger.EXTREME, "Loading thumbnail for " +guid);
4720 preview.loadContent(guid, html, zoom);
4722 logger.log(logger.HIGH, "Exiting thumnailHTMLReady()");
4727 //**********************************************************
4728 //**********************************************************
4729 //* Online user actions
4730 //**********************************************************
4731 //**********************************************************
4732 private void setupOnlineMenu() {
4733 if (!Global.isConnected) {
4734 menuBar.noteOnlineHistoryAction.setEnabled(false);
4735 menuBar.selectiveSyncAction.setEnabled(false);
4738 menuBar.noteOnlineHistoryAction.setEnabled(true);
4739 menuBar.selectiveSyncAction.setEnabled(true);
4742 @SuppressWarnings("unused")
4743 private void viewNoteHistory() {
4744 if (currentNoteGuid == null || currentNoteGuid.equals(""))
4746 if (currentNote.getUpdateSequenceNum() == 0) {
4747 setMessage(tr("Note has never been synchronized."));
4748 QMessageBox.information(this, tr("Error"), tr("This note has never been sent to Evernote, so there is no history."));
4752 setMessage(tr("Getting Note History"));
4754 Note currentOnlineNote = null;
4757 if (Global.isPremium())
4758 versions = syncRunner.noteStore.listNoteVersions(syncRunner.authToken, currentNoteGuid);
4760 versions = new ArrayList<NoteVersionId>();
4761 currentOnlineNote = syncRunner.noteStore.getNote(syncRunner.authToken, currentNoteGuid, true, true, false, false);
4762 } catch (EDAMUserException e) {
4763 setMessage("EDAMUserException: " +e.getMessage());
4765 } catch (EDAMSystemException e) {
4766 setMessage("EDAMSystemException: " +e.getMessage());
4768 } catch (EDAMNotFoundException e) {
4769 setMessage(tr("Note not found on server."));
4770 QMessageBox.information(this, "Error", "This note could not be found on Evernote's servers.");
4772 } catch (TException e) {
4773 setMessage("EDAMTransactionException: " +e.getMessage());
4777 // If we've gotten this far, we have a good note.
4778 if (historyWindow == null) {
4779 historyWindow = new OnlineNoteHistory(logger, conn);
4780 historyWindow.historyCombo.activated.connect(this, "reloadHistoryWindow(String)");
4781 historyWindow.restoreAsNew.clicked.connect(this, "restoreHistoryNoteAsNew()");
4782 historyWindow.restore.clicked.connect(this, "restoreHistoryNote()");
4784 historyWindow.historyCombo.clear();
4786 boolean isDirty = conn.getNoteTable().isNoteDirty(currentNoteGuid);
4787 if (currentNote.getUpdateSequenceNum() != currentOnlineNote.getUpdateSequenceNum())
4789 historyWindow.setCurrent(isDirty);
4791 loadHistoryWindowContent(currentOnlineNote);
4792 historyWindow.load(versions);
4793 setMessage(tr("History retrieved"));
4795 historyWindow.exec();
4797 private Note reloadHistoryWindow(String selection) {
4799 String fmt = Global.getDateFormat() + " " + Global.getTimeFormat();
4800 String dateTimeFormat = new String(fmt);
4801 SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);
4805 for (int i=0; i<versions.size(); i++) {
4806 StringBuilder versionDate = new StringBuilder(simple.format(versions.get(i).getSaved()));
4807 if (versionDate.toString().equals(selection))
4811 if (index > -1 || selection.indexOf("Current") > -1) {
4812 Note historyNote = null;
4815 usn = versions.get(index).getUpdateSequenceNum();
4816 historyNote = syncRunner.noteStore.getNoteVersion(syncRunner.authToken, currentNoteGuid, usn, true, true, true);
4818 historyNote = syncRunner.noteStore.getNote(syncRunner.authToken, currentNoteGuid, true,true,true,true);
4819 } catch (EDAMUserException e) {
4820 setMessage("EDAMUserException: " +e.getMessage());
4823 } catch (EDAMSystemException e) {
4824 setMessage("EDAMSystemException: " +e.getMessage());
4827 } catch (EDAMNotFoundException e) {
4828 setMessage("EDAMNotFoundException: " +e.getMessage());
4831 } catch (TException e) {
4832 setMessage("EDAMTransactionException: " +e.getMessage());
4838 if (historyNote != null)
4839 historyWindow.setContent(historyNote);
4845 private void loadHistoryWindowContent(Note note) {
4846 note.setUpdateSequenceNum(0);
4847 historyWindow.setContent(note);
4849 @SuppressWarnings("unused")
4850 private void restoreHistoryNoteAsNew() {
4851 setMessage(tr("Restoring as new note."));
4852 duplicateNote(reloadHistoryWindow(historyWindow.historyCombo.currentText()));
4853 setMessage(tr("Note has been restored as a new note."));
4855 @SuppressWarnings("unused")
4856 private void restoreHistoryNote() {
4857 setMessage(tr("Restoring note."));
4858 Note n = reloadHistoryWindow(historyWindow.historyCombo.currentText());
4859 conn.getNoteTable().expungeNote(n.getGuid(), true, false);
4862 for (int i=0; i<n.getResourcesSize(); i++) {
4863 n.getResources().get(i).setActive(true);
4864 conn.getNoteTable().noteResourceTable.saveNoteResource(n.getResources().get(i), true);
4866 listManager.addNote(n);
4867 conn.getNoteTable().addNote(n, true);
4868 refreshEvernoteNote(true);
4869 setMessage(tr("Note has been restored."));
4871 @SuppressWarnings("unused")
4872 private void setupSelectiveSync() {
4874 // Get a list of valid notebooks
4875 List<Notebook> notebooks = null;
4876 List<Tag> tags = null;
4878 notebooks = syncRunner.noteStore.listNotebooks(syncRunner.authToken);
4879 tags = syncRunner.noteStore.listTags(syncRunner.authToken);
4880 } catch (EDAMUserException e) {
4881 setMessage("EDAMUserException: " +e.getMessage());
4883 } catch (EDAMSystemException e) {
4884 setMessage("EDAMSystemException: " +e.getMessage());
4886 } catch (TException e) {
4887 setMessage("EDAMTransactionException: " +e.getMessage());
4891 // Split up notebooks into synchronized & non-synchronized
4892 List<Notebook> ignoredBooks = new ArrayList<Notebook>();
4893 List<String> dbIgnoredNotebooks = conn.getSyncTable().getIgnoreRecords("NOTEBOOK");
4895 for (int i=notebooks.size()-1; i>=0; i--) {
4896 for (int j=0; j<dbIgnoredNotebooks.size(); j++) {
4897 if (notebooks.get(i).getGuid().equalsIgnoreCase(dbIgnoredNotebooks.get(j))) {
4898 ignoredBooks.add(notebooks.get(i));
4899 j=dbIgnoredNotebooks.size();
4904 // split up tags into synchronized & non-synchronized
4905 List<Tag> ignoredTags = new ArrayList<Tag>();
4906 List<String> dbIgnoredTags = conn.getSyncTable().getIgnoreRecords("TAG");
4908 for (int i=tags.size()-1; i>=0; i--) {
4909 for (int j=0; j<dbIgnoredTags.size(); j++) {
4910 if (tags.get(i).getGuid().equalsIgnoreCase(dbIgnoredTags.get(j))) {
4911 ignoredTags.add(tags.get(i));
4912 j=dbIgnoredTags.size();
4917 IgnoreSync ignore = new IgnoreSync(notebooks, ignoredBooks, tags, ignoredTags);
4919 if (!ignore.okClicked())
4924 // Clear out old notebooks & add the new ones
4925 List<String> oldIgnoreNotebooks = conn.getSyncTable().getIgnoreRecords("NOTEBOOK");
4926 for (int i=0; i<oldIgnoreNotebooks.size(); i++) {
4927 conn.getSyncTable().deleteRecord("IGNORENOTEBOOK-"+oldIgnoreNotebooks.get(i));
4930 List<String> newNotebooks = new ArrayList<String>();
4931 for (int i=ignore.getIgnoredBookList().count()-1; i>=0; i--) {
4932 String text = ignore.getIgnoredBookList().takeItem(i).text();
4933 for (int j=0; j<notebooks.size(); j++) {
4934 if (notebooks.get(j).getName().equalsIgnoreCase(text)) {
4935 Notebook n = notebooks.get(j);
4936 conn.getSyncTable().addRecord("IGNORENOTEBOOK-"+n.getGuid(), n.getGuid());
4938 newNotebooks.add(n.getGuid());
4943 // Clear out old tags & add new ones
4944 List<String> oldIgnoreTags = conn.getSyncTable().getIgnoreRecords("TAG");
4945 for (int i=0; i<oldIgnoreTags.size(); i++) {
4946 conn.getSyncTable().deleteRecord("IGNORETAG-"+oldIgnoreTags.get(i));
4949 List<String> newTags = new ArrayList<String>();
4950 for (int i=ignore.getIgnoredTagList().count()-1; i>=0; i--) {
4951 String text = ignore.getIgnoredTagList().takeItem(i).text();
4952 for (int j=0; j<tags.size(); j++) {
4953 if (tags.get(j).getName().equalsIgnoreCase(text)) {
4954 Tag t = tags.get(j);
4955 conn.getSyncTable().addRecord("IGNORETAG-"+t.getGuid(), t.getGuid());
4956 newTags.add(t.getGuid());
4962 conn.getNoteTable().expungeIgnoreSynchronizedNotes(newNotebooks, newTags);
4968 //**********************************************************
4969 //**********************************************************
4970 //* XML Modifying methods
4971 //**********************************************************
4972 //**********************************************************
4973 // An error has happended fetching a resource. let the user know
4974 private void resourceErrorMessage() {
4977 QMessageBox.information(this, tr("DOUGH!!!"), tr("Well, this is embarrassing."+
4978 "\n\nSome attachments or images for this note appear to be missing from my database.\n"+
4979 "In a perfect world this wouldn't happen, but it has.\n" +
4980 "It is embarasing when a program like me, designed to save all your\n"+
4981 "precious data, has a problem finding data.\n\n" +
4982 "I guess life isn't fair, but I'll survive. Somehow...\n\n" +
4983 "In the mean time, I'm not going to let you make changes to this note.\n" +
4984 "Don't get angry. I'm doing it to prevent you from messing up\n"+
4985 "this note on the Evernote servers. Sorry."+
4986 "\n\nP.S. You might want to re-synchronize to see if it corrects this problem.\nWho knows, you might get lucky."));
4988 browserWindow.setReadOnly(true);
4994 //**********************************************************
4995 //**********************************************************
4997 //**********************************************************
4998 //**********************************************************
4999 // We should now do a sync with Evernote
5000 private void syncTimer() {
5001 logger.log(logger.EXTREME, "Entering NeverNote.syncTimer()");
5002 syncRunner.syncNeeded = true;
5003 syncRunner.disableUploads = Global.disableUploads;
5005 logger.log(logger.EXTREME, "Leaving NeverNote.syncTimer()");
5007 private void syncStart() {
5008 logger.log(logger.EXTREME, "Entering NeverNote.syncStart()");
5010 if (!syncRunning && Global.isConnected) {
5011 syncRunner.setConnected(true);
5012 syncRunner.setKeepRunning(Global.keepRunning);
5013 syncRunner.syncDeletedContent = Global.synchronizeDeletedContent();
5015 if (syncThreadsReady > 0) {
5016 indexRunner.interrupt = true;
5017 saveNoteIndexWidth();
5018 saveNoteColumnPositions();
5019 if (syncRunner.addWork("SYNC")) {
5021 syncRunner.syncNeeded = true;
5026 logger.log(logger.EXTREME, "Leaving NeverNote.syncStart");
5028 @SuppressWarnings("unused")
5029 private void syncThreadComplete(Boolean refreshNeeded) {
5030 setMessage(tr("Finalizing Synchronization"));
5032 syncRunning = false;
5033 syncRunner.syncNeeded = false;
5034 synchronizeAnimationTimer.stop();
5035 synchronizeButton.setIcon(new QIcon(iconPath+"synchronize.png"));
5037 if (currentNote == null) {
5038 currentNote = conn.getNoteTable().getNote(currentNoteGuid, false, false, false, false, true);
5040 listManager.setUnsynchronizedNotes(conn.getNoteTable().getUnsynchronizedGUIDs());
5041 noteIndexUpdated(false);
5042 noteTableView.selectionModel().blockSignals(true);
5043 scrollToGuid(currentNoteGuid);
5044 noteTableView.selectionModel().blockSignals(false);
5045 refreshEvernoteNote(false);
5046 scrollToGuid(currentNoteGuid);
5048 if (!syncRunner.error)
5049 setMessage(tr("Synchronization Complete"));
5051 setMessage(tr("Synchronization completed with errors. Please check the log for details."));
5052 logger.log(logger.MEDIUM, "Sync complete.");
5054 public void saveUploadAmount(long t) {
5055 Global.saveUploadAmount(t);
5057 public void saveUserInformation(User user) {
5058 Global.saveUserInformation(user);
5060 public void saveEvernoteUpdateCount(int i) {
5061 Global.saveEvernoteUpdateCount(i);
5063 public void refreshLists() {
5064 logger.log(logger.EXTREME, "Entering NeverNote.refreshLists");
5066 listManager.refreshLists(currentNote, noteDirty, browserWindow.getContent());
5067 tagIndexUpdated(true);
5068 notebookIndexUpdated();
5069 savedSearchIndexUpdated();
5070 listManager.loadNotesIndex();
5072 noteTableView.selectionModel().blockSignals(true);
5073 noteIndexUpdated(true);
5074 noteTableView.selectionModel().blockSignals(false);
5075 logger.log(logger.EXTREME, "Leaving NeverNote.refreshLists");
5079 @SuppressWarnings("unused")
5080 private void authTimer() {
5081 Calendar cal = Calendar.getInstance();
5083 // If we are not connected let's get out of here
5084 if (!Global.isConnected)
5087 // If this is the first time through, then we need to set this
5088 // if (syncRunner.authRefreshTime == 0 || cal.getTimeInMillis() > syncRunner.authRefreshTime)
5089 // syncRunner.authRefreshTime = cal.getTimeInMillis();
5091 // long now = new Date().getTime();
5092 // if (now > Global.authRefreshTime && Global.isConnected) {
5093 syncRunner.authRefreshNeeded = true;
5097 @SuppressWarnings("unused")
5098 private void authRefreshComplete(boolean goodSync) {
5099 logger.log(logger.EXTREME, "Entering NeverNote.authRefreshComplete");
5100 Global.isConnected = syncRunner.isConnected;
5102 // authTimer.start((int)syncRunner.authTimeRemaining/4);
5103 authTimer.start(1000*60*15);
5104 logger.log(logger.LOW, "Authentication token has been renewed");
5105 // setMessage("Authentication token has been renewed.");
5107 authTimer.start(1000*60*5);
5108 logger.log(logger.LOW, "Authentication token renew has failed - retry in 5 minutes.");
5109 // setMessage("Authentication token renew has failed - retry in 5 minutes.");
5111 logger.log(logger.EXTREME, "Leaving NeverNote.authRefreshComplete");
5115 @SuppressWarnings("unused")
5116 private synchronized void indexTimer() {
5117 logger.log(logger.EXTREME, "Index timer activated. Sync running="+syncRunning);
5120 if (!indexDisabled && indexRunner.idle) {
5121 indexRunner.addWork("SCAN");
5123 logger.log(logger.EXTREME, "Leaving neverNote index timer");
5126 @SuppressWarnings("unused")
5127 private void indexStarted() {
5128 setMessage(tr("Indexing notes"));
5130 @SuppressWarnings("unused")
5131 private void indexComplete() {
5132 setMessage(tr("Index complete"));
5134 @SuppressWarnings("unused")
5135 private synchronized void toggleNoteIndexing() {
5136 logger.log(logger.HIGH, "Entering NeverNote.toggleIndexing");
5137 indexDisabled = !indexDisabled;
5139 setMessage(tr("Indexing is now enabled."));
5141 setMessage(tr("Indexing is now disabled."));
5142 menuBar.disableIndexing.setChecked(indexDisabled);
5143 logger.log(logger.HIGH, "Leaving NeverNote.toggleIndexing");
5146 @SuppressWarnings("unused")
5147 private void threadMonitorCheck() {
5152 alive = listManager.threadCheck(Global.tagCounterThreadId);
5155 if (tagDeadCount > MAX)
5156 QMessageBox.information(this, tr("A thread his died."), tr("It appears as the tag counter thread has died. I recommend "+
5157 "checking stopping NeverNote, saving the logs for later viewing, and restarting. Sorry."));
5161 alive = listManager.threadCheck(Global.notebookCounterThreadId);
5163 notebookThreadDeadCount++;
5164 QMessageBox.information(this, tr("A thread his died."), tr("It appears as the notebook counter thread has died. I recommend "+
5165 "checking stopping NeverNote, saving the logs for later viewing, and restarting. Sorry."));
5167 notebookThreadDeadCount=0;
5169 alive = listManager.threadCheck(Global.trashCounterThreadId);
5172 QMessageBox.information(this, tr("A thread his died."), ("It appears as the trash counter thread has died. I recommend "+
5173 "checking stopping NeverNote, saving the logs for later viewing, and restarting. Sorry."));
5177 alive = listManager.threadCheck(Global.saveThreadId);
5179 saveThreadDeadCount++;
5180 QMessageBox.information(this, tr("A thread his died."), tr("It appears as the note saver thread has died. I recommend "+
5181 "checking stopping NeverNote, saving the logs for later viewing, and restarting. Sorry."));
5183 saveThreadDeadCount=0;
5185 if (!syncThread.isAlive()) {
5186 syncThreadDeadCount++;
5187 QMessageBox.information(this, tr("A thread his died."), tr("It appears as the synchronization thread has died. I recommend "+
5188 "checking stopping NeverNote, saving the logs for later viewing, and restarting. Sorry."));
5190 syncThreadDeadCount=0;
5192 if (!indexThread.isAlive()) {
5193 indexThreadDeadCount++;
5194 QMessageBox.information(this, tr("A thread his died."), tr("It appears as the index thread has died. I recommend "+
5195 "checking stopping NeverNote, saving the logs for later viewing, and restarting. Sorry."));
5197 indexThreadDeadCount=0;
5202 private void thumbnailTimer() {
5203 if (Global.enableThumbnails() && conn.getNoteTable().getThumbnailNeededCount() > 1) {
5204 thumbnailTimer.setInterval(10*1000);
5205 thumbnailRunner.addWork("SCAN");
5207 thumbnailTimer.setInterval(60*1000);
5211 //**************************************************
5212 //* Backup & Restore
5213 //**************************************************
5214 @SuppressWarnings("unused")
5215 private void databaseBackup() {
5216 QFileDialog fd = new QFileDialog(this);
5217 fd.setFileMode(FileMode.AnyFile);
5218 fd.setConfirmOverwrite(true);
5219 fd.setWindowTitle(tr("Backup Database"));
5220 fd.setFilter(tr("NeverNote Export (*.nnex);;All Files (*.*)"));
5221 fd.setAcceptMode(AcceptMode.AcceptSave);
5222 fd.setDirectory(System.getProperty("user.home"));
5223 if (fd.exec() == 0 || fd.selectedFiles().size() == 0) {
5229 setMessage(tr("Backing up database"));
5231 // conn.backupDatabase(Global.getUpdateSequenceNumber(), Global.getSequenceDate());
5233 ExportData noteWriter = new ExportData(conn, true);
5234 String fileName = fd.selectedFiles().get(0);
5236 if (!fileName.endsWith(".nnex"))
5237 fileName = fileName +".nnex";
5238 noteWriter.exportData(fileName);
5239 setMessage(tr("Database backup completed."));
5244 @SuppressWarnings("unused")
5245 private void databaseRestore() {
5246 if (QMessageBox.question(this, tr("Confirmation"),
5247 tr("This is used to restore a database from backups.\n" +
5248 "It is HIGHLY recommened that this only be used to populate\n" +
5249 "an empty database. Restoring into a database that\n already has data" +
5250 " can cause problems.\n\nAre you sure you want to continue?"),
5251 QMessageBox.StandardButton.Yes,
5252 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
5257 QFileDialog fd = new QFileDialog(this);
5258 fd.setFileMode(FileMode.ExistingFile);
5259 fd.setConfirmOverwrite(true);
5260 fd.setWindowTitle(tr("Restore Database"));
5261 fd.setFilter(tr("NeverNote Export (*.nnex);;All Files (*.*)"));
5262 fd.setAcceptMode(AcceptMode.AcceptOpen);
5263 fd.setDirectory(System.getProperty("user.home"));
5264 if (fd.exec() == 0 || fd.selectedFiles().size() == 0) {
5270 setMessage(tr("Restoring database"));
5271 ImportData noteReader = new ImportData(conn, true);
5272 noteReader.importData(fd.selectedFiles().get(0));
5274 if (noteReader.lastError != 0) {
5275 setMessage(noteReader.getErrorMessage());
5276 logger.log(logger.LOW, "Restore problem: " +noteReader.lastError);
5281 listManager.loadNoteTitleColors();
5283 refreshEvernoteNote(true);
5284 setMessage(tr("Database has been restored."));
5287 @SuppressWarnings("unused")
5288 private void exportNotes() {
5289 QFileDialog fd = new QFileDialog(this);
5290 fd.setFileMode(FileMode.AnyFile);
5291 fd.setConfirmOverwrite(true);
5292 fd.setWindowTitle(tr("Backup Database"));
5293 fd.setFilter(tr("NeverNote Export (*.nnex);;All Files (*.*)"));
5294 fd.setAcceptMode(AcceptMode.AcceptSave);
5295 fd.setDirectory(System.getProperty("user.home"));
5296 if (fd.exec() == 0 || fd.selectedFiles().size() == 0) {
5302 setMessage(tr("Exporting Notes"));
5305 if (selectedNoteGUIDs.size() == 0 && !currentNoteGuid.equals(""))
5306 selectedNoteGUIDs.add(currentNoteGuid);
5308 ExportData noteWriter = new ExportData(conn, false, selectedNoteGUIDs);
5309 String fileName = fd.selectedFiles().get(0);
5311 if (!fileName.endsWith(".nnex"))
5312 fileName = fileName +".nnex";
5313 noteWriter.exportData(fileName);
5314 setMessage(tr("Export completed."));
5320 @SuppressWarnings("unused")
5321 private void importNotes() {
5322 QFileDialog fd = new QFileDialog(this);
5323 fd.setFileMode(FileMode.ExistingFile);
5324 fd.setConfirmOverwrite(true);
5325 fd.setWindowTitle(tr("Import Notes"));
5326 fd.setFilter(tr("NeverNote Export (*.nnex);;All Files (*.*)"));
5327 fd.setAcceptMode(AcceptMode.AcceptOpen);
5328 fd.setDirectory(System.getProperty("user.home"));
5329 if (fd.exec() == 0 || fd.selectedFiles().size() == 0) {
5335 setMessage("Importing Notes");
5338 if (selectedNoteGUIDs.size() == 0 && !currentNoteGuid.equals(""))
5339 selectedNoteGUIDs.add(currentNoteGuid);
5341 ImportData noteReader = new ImportData(conn, false);
5342 String fileName = fd.selectedFiles().get(0);
5344 if (!fileName.endsWith(".nnex"))
5345 fileName = fileName +".nnex";
5346 if (selectedNotebookGUIDs != null && selectedNotebookGUIDs.size() > 0)
5347 noteReader.setNotebookGuid(selectedNotebookGUIDs.get(0));
5349 noteReader.setNotebookGuid(listManager.getNotebookIndex().get(0).getGuid());
5351 noteReader.importData(fileName);
5353 if (noteReader.lastError != 0) {
5354 setMessage(noteReader.getErrorMessage());
5355 logger.log(logger.LOW, "Import problem: " +noteReader.lastError);
5360 listManager.loadNoteTitleColors();
5362 refreshEvernoteNote(false);
5363 setMessage(tr("Notes have been imported."));
5366 setMessage("Import completed.");
5373 //**************************************************
5374 //* Duplicate a note
5375 //**************************************************
5376 @SuppressWarnings("unused")
5377 private void duplicateNote() {
5379 duplicateNote(currentNoteGuid);
5384 //**************************************************
5386 //**************************************************
5387 public void setupFolderImports() {
5388 List<WatchFolderRecord> records = conn.getWatchFolderTable().getAll();
5390 if (importKeepWatcher == null)
5391 importKeepWatcher = new QFileSystemWatcher();
5392 if (importDeleteWatcher == null) {
5393 importDeleteWatcher = new QFileSystemWatcher();
5394 for (int i=0; i<records.size(); i++) {
5395 if (!records.get(i).keep)
5396 folderImportDelete(records.get(i).folder);
5402 // importKeepWatcher.addPath(records.get(i).folder.replace('\\', '/'));
5403 for (int i=0; i<records.size(); i++) {
5404 if (records.get(i).keep)
5405 importKeepWatcher.addPath(records.get(i).folder);
5407 importDeleteWatcher.addPath(records.get(i).folder);
5410 importKeepWatcher.directoryChanged.connect(this, "folderImportKeep(String)");
5411 importDeleteWatcher.directoryChanged.connect(this, "folderImportDelete(String)");
5413 // Look at the files already there so we don't import them again if a new file is created
5414 if (importedFiles == null) {
5415 importedFiles = new ArrayList<String>();
5416 for (int j=0; j<records.size(); j++) {
5417 QDir dir = new QDir(records.get(j).folder);
5418 List<QFileInfo> list = dir.entryInfoList();
5419 for (int k=0; k<list.size(); k++) {
5420 if (list.get(k).isFile())
5421 importedFiles.add(list.get(k).absoluteFilePath());
5426 public void folderImport() {
5427 List<WatchFolderRecord> recs = conn.getWatchFolderTable().getAll();
5428 WatchFolder dialog = new WatchFolder(recs, listManager.getNotebookIndex());
5430 if (!dialog.okClicked())
5433 // We have some sort of update.
5434 if (importKeepWatcher.directories().size() > 0)
5435 importKeepWatcher.removePaths(importKeepWatcher.directories());
5436 if (importDeleteWatcher.directories().size() > 0)
5437 importDeleteWatcher.removePaths(importDeleteWatcher.directories());
5439 conn.getWatchFolderTable().expungeAll();
5440 // Start building from the table
5441 for (int i=0; i<dialog.table.rowCount(); i++) {
5442 QTableWidgetItem item = dialog.table.item(i, 0);
5443 String dir = item.text();
5444 item = dialog.table.item(i, 1);
5445 String notebook = item.text();
5446 item = dialog.table.item(i, 2);
5448 if (item.text().equalsIgnoreCase("Keep"))
5453 String guid = conn.getNotebookTable().findNotebookByName(notebook);
5454 conn.getWatchFolderTable().addWatchFolder(dir, guid, keep, 0);
5456 setupFolderImports();
5459 public void folderImportKeep(String dirName) throws NoSuchAlgorithmException {
5461 String whichOS = System.getProperty("os.name");
5462 if (whichOS.contains("Windows"))
5463 dirName = dirName.replace('/','\\');
5465 FileImporter importer = new FileImporter(logger, conn);
5467 QDir dir = new QDir(dirName);
5468 List<QFileInfo> list = dir.entryInfoList();
5469 String notebook = conn.getWatchFolderTable().getNotebook(dirName);
5471 for (int i=0; i<list.size(); i++){
5473 boolean redundant = false;
5474 // Check if we've already imported this one or if it existed before
5475 for (int j=0; j<importedFiles.size(); j++) {
5476 if (importedFiles.get(j).equals(list.get(i).absoluteFilePath()))
5481 importer.setFileInfo(list.get(i));
5482 importer.setFileName(list.get(i).absoluteFilePath());
5485 if (list.get(i).isFile() && importer.isValidType()) {
5487 if (!importer.importFile()) {
5488 // If we can't get to the file, it is probably locked. We'll try again later.
5489 logger.log(logger.LOW, "Unable to save externally edited file. Saving for later.");
5490 importFilesKeep.add(list.get(i).absoluteFilePath());
5494 Note newNote = importer.getNote();
5495 newNote.setNotebookGuid(notebook);
5496 newNote.setTitle(dir.at(i));
5497 listManager.addNote(newNote);
5498 conn.getNoteTable().addNote(newNote, true);
5499 listManager.getUnsynchronizedNotes().add(newNote.getGuid());
5500 noteTableView.insertRow(newNote, true, -1);
5501 listManager.updateNoteContent(newNote.getGuid(), importer.getNoteContent());
5502 listManager.countNotebookResults(listManager.getNoteIndex());
5503 importedFiles.add(list.get(i).absoluteFilePath());
5511 public void folderImportDelete(String dirName) {
5513 String whichOS = System.getProperty("os.name");
5514 if (whichOS.contains("Windows"))
5515 dirName = dirName.replace('/','\\');
5517 FileImporter importer = new FileImporter(logger, conn);
5518 QDir dir = new QDir(dirName);
5519 List<QFileInfo> list = dir.entryInfoList();
5520 String notebook = conn.getWatchFolderTable().getNotebook(dirName);
5522 for (int i=0; i<list.size(); i++){
5523 importer.setFileInfo(list.get(i));
5524 importer.setFileName(list.get(i).absoluteFilePath());
5526 if (list.get(i).isFile() && importer.isValidType()) {
5528 if (!importer.importFile()) {
5529 // If we can't get to the file, it is probably locked. We'll try again later.
5530 logger.log(logger.LOW, "Unable to save externally edited file. Saving for later.");
5531 importFilesKeep.add(list.get(i).absoluteFilePath());
5535 Note newNote = importer.getNote();
5536 newNote.setNotebookGuid(notebook);
5537 newNote.setTitle(dir.at(i));
5538 listManager.addNote(newNote);
5539 conn.getNoteTable().addNote(newNote, true);
5540 listManager.getUnsynchronizedNotes().add(newNote.getGuid());
5541 noteTableView.insertRow(newNote, true, -1);
5542 listManager.updateNoteContent(newNote.getGuid(), importer.getNoteContent());
5543 listManager.countNotebookResults(listManager.getNoteIndex());
5544 dir.remove(dir.at(i));
5550 //**************************************************
5552 //**************************************************
5553 private void externalFileEdited(String fileName) throws NoSuchAlgorithmException {
5554 logger.log(logger.HIGH, "Entering exernalFileEdited");
5556 // Strip URL prefix and base dir path
5557 String dPath = FileUtils.toForwardSlashedPath(Global.getFileManager().getResDirPath());
5558 String name = fileName.replace(dPath, "");
5559 int pos = name.lastIndexOf('.');
5562 guid = guid.substring(0,pos);
5564 pos = name.lastIndexOf(Global.attachmentNameDelimeter);
5566 guid = name.substring(0, pos);
5569 QFile file = new QFile(fileName);
5570 if (!file.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly))) {
5571 // If we can't get to the file, it is probably locked. We'll try again later.
5572 logger.log(logger.LOW, "Unable to save externally edited file. Saving for later.");
5573 externalFiles.add(fileName);
5576 QByteArray binData = file.readAll();
5578 if (binData.size() == 0) {
5579 // If we can't get to the file, it is probably locked. We'll try again later.
5580 logger.log(logger.LOW, "Unable to save externally edited file. Saving for later.");
5581 externalFiles.add(fileName);
5585 Resource r = conn.getNoteTable().noteResourceTable.getNoteResource(guid, true);
5587 r = conn.getNoteTable().noteResourceTable.getNoteResource(Global.resourceMap.get(guid), true);
5588 if (r == null || r.getData() == null || r.getData().getBody() == null)
5590 String oldHash = Global.byteArrayToHexString(r.getData().getBodyHash());
5591 MessageDigest md = MessageDigest.getInstance("MD5");
5592 md.update(binData.toByteArray());
5593 byte[] hash = md.digest();
5594 String newHash = Global.byteArrayToHexString(hash);
5595 if (r.getNoteGuid().equalsIgnoreCase(currentNoteGuid)) {
5596 updateResourceContentHash(browserWindow, r.getGuid(), oldHash, newHash);
5598 if (externalWindows.containsKey(r.getNoteGuid())) {
5599 updateResourceContentHash(externalWindows.get(r.getNoteGuid()).getBrowserWindow(),
5600 r.getGuid(), oldHash, newHash);
5602 conn.getNoteTable().updateResourceContentHash(r.getNoteGuid(), oldHash, newHash);
5603 Data data = r.getData();
5604 data.setBody(binData.toByteArray());
5605 data.setBodyHash(hash);
5606 logger.log(logger.LOW, "externalFileEdited: " +data.getSize() +" bytes");
5608 conn.getNoteTable().noteResourceTable.updateNoteResource(r,true);
5610 if (r.getNoteGuid().equals(currentNoteGuid)) {
5611 QWebSettings.setMaximumPagesInCache(0);
5612 QWebSettings.setObjectCacheCapacities(0, 0, 0);
5613 refreshEvernoteNote(true);
5614 browserWindow.getBrowser().triggerPageAction(WebAction.Reload);
5617 if (externalWindows.containsKey(r.getNoteGuid())) {
5618 QWebSettings.setMaximumPagesInCache(0);
5619 QWebSettings.setObjectCacheCapacities(0, 0, 0);
5620 externalWindows.get(r.getNoteGuid()).getBrowserWindow().getBrowser().triggerPageAction(WebAction.Reload);
5624 logger.log(logger.HIGH, "Exiting externalFielEdited");
5626 // This is a timer event that tries to save any external files that were edited. This
5627 // is only needed if we couldn't save a file earlier.
5628 public void externalFileEditedSaver() {
5629 for (int i=externalFiles.size()-1; i>=0; i--) {
5631 logger.log(logger.MEDIUM, "Trying to save " +externalFiles.get(i));
5632 externalFileEdited(externalFiles.get(i));
5633 externalFiles.remove(i);
5634 } catch (NoSuchAlgorithmException e) {e.printStackTrace();}
5636 for (int i=0; i<importFilesKeep.size(); i++) {
5638 logger.log(logger.MEDIUM, "Trying to save " +importFilesKeep.get(i));
5639 folderImportKeep(importFilesKeep.get(i));
5640 importFilesKeep.remove(i);
5641 } catch (NoSuchAlgorithmException e) {e.printStackTrace();}
5643 for (int i=0; i<importFilesDelete.size(); i++) {
5644 logger.log(logger.MEDIUM, "Trying to save " +importFilesDelete.get(i));
5645 folderImportDelete(importFilesDelete.get(i));
5646 importFilesDelete.remove(i);
5653 // If an attachment on the current note was edited, we need to update the current notes's hash
5654 // Update a note content's hash. This happens if a resource is edited outside of NN
5655 public void updateResourceContentHash(BrowserWindow browser, String guid, String oldHash, String newHash) {
5656 int position = browserWindow.getContent().indexOf("en-tag=\"en-media\" guid=\""+guid+"\" type=");
5658 for (;position>-1;) {
5659 endPos = browser.getContent().indexOf(">", position+1);
5660 String oldSegment = browser.getContent().substring(position,endPos);
5661 int hashPos = oldSegment.indexOf("hash=\"");
5662 int hashEnd = oldSegment.indexOf("\"", hashPos+7);
5663 String hash = oldSegment.substring(hashPos+6, hashEnd);
5664 if (hash.equalsIgnoreCase(oldHash)) {
5665 String newSegment = oldSegment.replace(oldHash, newHash);
5666 String content = browser.getContent().substring(0,position) +
5668 browser.getContent().substring(endPos);
5669 browser.getBrowser().setContent(new QByteArray(content));;
5672 position = browser.getContent().indexOf("en-tag=\"en-media\" guid=\""+guid+"\" type=", position+1);
5677 //*************************************************
5678 //* Minimize to tray
5679 //*************************************************
5681 public void changeEvent(QEvent e) {
5682 if (e.type() == QEvent.Type.WindowStateChange) {
5683 if (isMinimized() && Global.showTrayIcon()) {
5685 QTimer.singleShot(10, this, "hide()");
5689 windowMaximized = true;
5691 windowMaximized = false;
5695 //*************************************************
5696 //* Check database userid & passwords
5697 //*************************************************
5698 private static boolean databaseCheck(String url,String userid, String userPassword, String cypherPassword) {
5699 Connection connection;
5702 Class.forName("org.h2.Driver");
5703 } catch (ClassNotFoundException e1) {
5704 e1.printStackTrace();
5709 String passwordString = null;
5710 if (cypherPassword==null || cypherPassword.trim().equals(""))
5711 passwordString = userPassword;
5713 passwordString = cypherPassword+" "+userPassword;
5714 connection = DriverManager.getConnection(url,userid,passwordString);
5715 } catch (SQLException e) {
5720 } catch (SQLException e) {
5721 e.printStackTrace();