OSDN Git Service

Correct problem where adding a new note from the tray causes the title of the new...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / NeverNote.java
index 9fd697f..866e6e2 100644 (file)
@@ -332,7 +332,7 @@ public class NeverNote extends QMainWindow{
     boolean                            encryptOnShutdown;                      // should I encrypt when I close?
     boolean                            decryptOnShutdown;                      // should I decrypt on shutdown;
     String                             encryptCipher;                          // What cipher should I use?
-    Signal0                    minimizeToTray;
+    //Signal0                  minimizeToTray;
     boolean                            windowMaximized = false;        // Keep track of the window state for restores
     List<String>               pdfReadyQueue;                          // Queue of PDFs that are ready to be rendered.
     List<QPixmap>              syncIcons;                                      // Array of icons used in sync animation
@@ -709,12 +709,14 @@ public class NeverNote extends QMainWindow{
         tagTree.showAllTags(true);
 
                QIcon appIcon = new QIcon(iconPath+"nevernote.png");
-       setWindowIcon(appIcon);
-       trayIcon.setIcon(appIcon);
-       if (Global.showTrayIcon())
-               trayIcon.show();
-       else
-               trayIcon.hide();
+               if (QSystemTrayIcon.isSystemTrayAvailable()) {
+                       setWindowIcon(appIcon);
+                       trayIcon.setIcon(appIcon);
+                       if (Global.showTrayIcon() || Global.minimizeOnClose())
+                               trayIcon.show();
+                       else
+                               trayIcon.hide();
+               }
        
        scrollToGuid(currentNoteGuid);
        if (Global.automaticLogin()) {
@@ -771,6 +773,18 @@ public class NeverNote extends QMainWindow{
                noteTableView.proxyModel.blocked = false;
                noteTableView.proxyModel.sortChanged.connect(this, "tableSortOrderChanged(Integer,Integer)");
                
+               // Set the startup notebook
+       String defaultNotebook = Global.getStartupNotebook();
+       if (!defaultNotebook.equals("AllNotebooks") && !defaultNotebook.equals("")) {
+               for (int k=0; k<listManager.getNotebookIndex().size(); k++) {
+                       if (listManager.getNotebookIndex().get(k).isDefaultNotebook()) {
+                               notebookTree.clearSelection();
+                               notebookTree.selectGuid(listManager.getNotebookIndex().get(k).getGuid());
+                               notebookTree.selectionSignal.emit();
+                       }
+               }
+       }
+               
                if (Global.checkVersionUpgrade())
                        checkForUpdates();
        }
@@ -805,6 +819,18 @@ public class NeverNote extends QMainWindow{
         }
 
         NeverNote application = new NeverNote(dbConn);
+               if (Global.syncOnly) {
+                       System.out.println("Performing synchronization only.");
+                       application.remoteConnect();
+                       if (Global.isConnected) {
+                               application.syncRunner.syncNeeded = true;
+                               application.syncRunner.addWork("SYNC");
+                               application.syncRunner.addWork("STOP");
+                               while(!application.syncRunner.isIdle());
+                               application.closeNeverNote();
+                       }
+                       return;
+               }
 
                application.setAttribute(WidgetAttribute.WA_DeleteOnClose, true);
                if (Global.startMinimized()) 
@@ -964,14 +990,17 @@ public class NeverNote extends QMainWindow{
                startupConfig.setHomeDirPath(arg.substring(arg.indexOf('=') + 1));
             if (lower.startsWith("--disable-viewing"))
                startupConfig.setDisableViewing(true);
+            if (lower.startsWith("--sync-only=true"))
+                startupConfig.setSyncOnly(true);
         }
         Global.setup(startupConfig);
+        
     }
 
     // Exit point
        @Override
        public void closeEvent(QCloseEvent event) {     
-               if (Global.minimizeOnClose() && !closeAction && Global.showTrayIcon()) {
+               if (Global.minimizeOnClose() && !closeAction) {
                        event.ignore();
                        hide();
                        return;
@@ -980,7 +1009,8 @@ public class NeverNote extends QMainWindow{
                waitCursor(true);
                
                if (currentNote!= null & browserWindow!=null) {
-                       if (!currentNote.getTitle().equals(browserWindow.getTitle()))
+                       if (currentNote.getTitle() != null && browserWindow != null 
+                                       && !currentNote.getTitle().equals(browserWindow.getTitle()))
                                conn.getNoteTable().updateNoteTitle(currentNote.getGuid(), browserWindow.getTitle());
                }
                saveNote();
@@ -1217,7 +1247,7 @@ public class NeverNote extends QMainWindow{
         indexRunner.indexNoteTitle = Global.indexNoteTitle();
         indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
         indexRunner.indexImageRecognition = Global.indexImageRecognition();
-        if (Global.showTrayIcon())
+        if (Global.showTrayIcon() || Global.minimizeOnClose())
                trayIcon.show();
         else
                trayIcon.hide();
@@ -2692,7 +2722,7 @@ public class NeverNote extends QMainWindow{
                QTextEdit textBox = new QTextEdit();
                layout.addWidget(textBox);
                textBox.setReadOnly(true);
-               QFile file = new QFile(Global.getFileManager().getHomeDirPath("release.txt"));
+               QFile file = new QFile(Global.getFileManager().getProgramDirPath("release.txt"));
                if (!file.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly,
                 QIODevice.OpenModeFlag.Text)))
                        return;
@@ -2718,11 +2748,12 @@ public class NeverNote extends QMainWindow{
                QMessageBox.about(this, 
                                                tr("About NixNote"),
                                                tr("<h4><center><b>NixNote</b></center></h4><hr><center>Version ")
-                                               +Global.version
+                                               //+Global.version
+                                               +"1.2.120404"
                                                +tr("<hr>"
                                                                +"Open Source Evernote Client.<br><br>" 
                                                                +"Licensed under GPL v2.  <br><hr><br>"
-                                                               +"</center>Evernote is copyright 2001-2010 by Evernote Corporation<br>"
+                                                               +"</center>Evernote is copyright 2001-2012 by Evernote Corporation<br>"
                                                                +"Jambi and QT are the licensed trademark of Nokia Corporation<br>"
                                                                +"PDFRenderer is licened under the LGPL<br>"
                                                                +"JTidy is copyrighted under the World Wide Web Consortium<br>"
@@ -2892,8 +2923,10 @@ public class NeverNote extends QMainWindow{
        listManager.setEnSearch(text.trim());
        listManager.loadNotesIndex();
        noteIndexUpdated(false);
+
        refreshEvernoteNote(true);
        searchPerformed = true;
+       waitCursor(false);
        logger.log(logger.HIGH, "Leaving NeverNote.searchFieldChanged");
     }
 
@@ -3262,8 +3295,8 @@ public class NeverNote extends QMainWindow{
                menuBar.noteRestoreAction.setVisible(false);
        }
        else {
+               trashNoteGuid = tempGuid;
                currentNoteGuid = trashNoteGuid;
-                       trashNoteGuid = tempGuid;
                menuBar.noteRestoreAction.setEnabled(true);
                menuBar.noteRestoreAction.setVisible(true);
                Global.showDeleted = true;
@@ -3700,10 +3733,16 @@ public class NeverNote extends QMainWindow{
                        browserWindow.setDisabled(true);
                } 
                
+               if (Global.showDeleted && listManager.getNotebookIndex().size() > 0 && saveCurrentNoteGuid.equals("")) {
+                       currentNoteGuid = listManager.getNoteIndex().get(0).getGuid();
+                       saveCurrentNoteGuid = currentNoteGuid;
+                       refreshEvernoteNote(true);
+               }
+               
                if (!saveCurrentNoteGuid.equals("")) {
                        refreshEvernoteNote(false);
                } else {
-                       currentNoteGuid = "";
+                               currentNoteGuid = "";
                }
                reloadTagTree(false);
 
@@ -4380,7 +4419,6 @@ public class NeverNote extends QMainWindow{
                Global.cryptCounter =0;
                if (readOnly) {
                        browserWindow.setReadOnly(true);
-                       return;
                }
                
                if (!reload)
@@ -4451,7 +4489,8 @@ public class NeverNote extends QMainWindow{
                if (conn.getNoteTable().isThumbnailNeeded(guid)) {
                        thumbnailHTMLReady(guid, js, Global.calculateThumbnailZoom(js.toString()));
                }
-               if (readOnly || inkNote)
+               if (readOnly || inkNote || 
+                               (note.getAttributes() != null && note.getAttributes().getContentClass() != null && note.getAttributes().getContentClass() != ""))
                        browser.getBrowser().page().setContentEditable(false);  // We don't allow editing of ink notes
                else
                        browser.getBrowser().page().setContentEditable(true);
@@ -4818,6 +4857,15 @@ public class NeverNote extends QMainWindow{
     @SuppressWarnings("unused")
        private void updateNoteTitle(String guid, String title) {
        listManager.setNoteSynchronized(guid, false);
+       
+       // We do this manually because if we've edited the note in an 
+       // external window we run into the possibility of signal recursion
+       // looping.
+       if (guid.equals(currentNoteGuid)) {
+               browserWindow.titleLabel.blockSignals(true);
+               browserWindow.titleLabel.setText(title);
+               browserWindow.titleLabel.blockSignals(false);
+       }
     }
     // Signal received that note content has changed.  Normally we just need the guid to remove
     // it from the cache.
@@ -5893,6 +5941,15 @@ public class NeverNote extends QMainWindow{
                        else
                                noteReader.setNotebookGuid(listManager.getNotebookIndex().get(0).getGuid());
   
+                       waitCursor(false);
+                       if (QMessageBox.question(this, tr("Confirmation"), 
+                                       tr("Create new tags from import?"),
+                                       QMessageBox.StandardButton.Yes, 
+                                       QMessageBox.StandardButton.No) == StandardButton.Yes.value()) {
+                                                               noteReader.createNewTags = true;
+                       } else
+                               noteReader.createNewTags = false;
+                       waitCursor(true);
                        noteReader.importData(fileName);
        
                        if (noteReader.lastError != 0) {
@@ -6308,15 +6365,17 @@ public class NeverNote extends QMainWindow{
        @Override
        public void changeEvent(QEvent e) {
                if (e.type() == QEvent.Type.WindowStateChange) {
-                       if (isMinimized() && Global.showTrayIcon()) {
-                               e.accept();
-                               QTimer.singleShot(10, this, "hide()");
-                               return;
+                       if (QSystemTrayIcon.isSystemTrayAvailable()) {
+                               if (isMinimized() && (Global.showTrayIcon() || Global.showTrayIcon())) {
+                                       e.accept();
+                                       QTimer.singleShot(10, this, "hide()");
+                                       return;
+                               }
+                               if (isMaximized())
+                                       windowMaximized = true;
+                               else 
+                                       windowMaximized = false;
                        }
-                       if (isMaximized())
-                               windowMaximized = true;
-                       else 
-                               windowMaximized = false;
                }
        }