OSDN Git Service

- Added the ability to disable indexing of attachments locally. - Added the ability...
authorRandy Baumgarte <randy@fbn.cx>
Thu, 2 Dec 2010 16:24:55 +0000 (11:24 -0500)
committerRandy Baumgarte <randy@fbn.cx>
Wed, 15 Dec 2010 15:17:03 +0000 (10:17 -0500)
src/cx/fbn/nevernote/Global.java
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/dialog/ConfigAppearancePage.java
src/cx/fbn/nevernote/dialog/ConfigDialog.java
src/cx/fbn/nevernote/dialog/ConfigIndexPage.java
src/cx/fbn/nevernote/gui/MainMenuBar.java
src/cx/fbn/nevernote/threads/IndexRunner.java

index 90f9cc9..ab17364 100644 (file)
@@ -1328,6 +1328,44 @@ public class Global {
                settings.endGroup();\r
     }\r
     \r
+    \r
+    //*******************\r
+    // Close/Minimize\r
+    //*******************\r
+    public static boolean minimizeOnClose() {\r
+               settings.beginGroup("General");\r
+               String text = (String)settings.value("minimizeOnClose", "false");\r
+               settings.endGroup();\r
+               if (text.equalsIgnoreCase("true"))\r
+                       return true;\r
+               else\r
+                       return false;   \r
+    }\r
+    public static void setMinimizeOnClose(boolean value) {\r
+               settings.beginGroup("General");\r
+               settings.setValue("minimizeOnClose", value);\r
+               settings.endGroup();    \r
+    }\r
+\r
+    \r
+    //*******************\r
+    // Index attachments\r
+    //*******************\r
+    public static boolean indexAttachmentsLocally() {\r
+               settings.beginGroup("Debug");\r
+               String text = (String)settings.value("indexAttachmentsLocally", "true");\r
+               settings.endGroup();\r
+               if (text.equalsIgnoreCase("true"))\r
+                       return true;\r
+               else\r
+                       return false;   \r
+    }\r
+    public static void setIndexAttachmentsLocally(boolean value) {\r
+               settings.beginGroup("Debug");\r
+               settings.setValue("indexAttachmentsLocally", value);\r
+               settings.endGroup();    \r
+    }\r
+\r
 \r
 }\r
 \r
index 1616200..abf8534 100644 (file)
@@ -305,7 +305,8 @@ public class NeverNote extends QMainWindow{
     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;
+    List<QPixmap>              syncIcons;                                      // Array of icons used in sync animation
+    private boolean            closeAction = false;            // Used to say when to close or when to minimize
     private static Logger log = Logger.getLogger(NeverNote.class); 
     
     
@@ -380,6 +381,7 @@ public class NeverNote extends QMainWindow{
                logger.log(logger.EXTREME, "Building index runners & timers");
         indexRunner = new IndexRunner("indexRunner.log", Global.getDatabaseUrl(), Global.getDatabaseUserid(), Global.getDatabaseUserPassword(), Global.cipherPassword);
                indexThread = new QThread(indexRunner, "Index Thread");
+        indexRunner.indexAttachmentsLocally = Global.indexAttachmentsLocally();
                indexThread.start();
                
         synchronizeAnimationTimer = new QTimer();
@@ -585,7 +587,7 @@ public class NeverNote extends QMainWindow{
                trayExitAction = new QAction("Exit", this);
                trayAddNoteAction = new QAction("Add Note", this);
                
-               trayExitAction.triggered.connect(this, "close()");
+               trayExitAction.triggered.connect(this, "closeNeverNote()");
                trayAddNoteAction.triggered.connect(this, "addNote()");
                trayShowAction.triggered.connect(this, "trayToggleVisible()");
                
@@ -859,6 +861,11 @@ public class NeverNote extends QMainWindow{
     // Exit point
        @Override
        public void closeEvent(QCloseEvent event) {     
+               if (Global.minimizeOnClose() && !closeAction && Global.showTrayIcon()) {
+                       event.ignore();
+                       hide();
+                       return;
+               }
                logger.log(logger.HIGH, "Entering NeverNote.closeEvent");
                waitCursor(true);
                
@@ -958,6 +965,11 @@ public class NeverNote extends QMainWindow{
                logger.log(logger.HIGH, "Leaving NeverNote.closeEvent");
        }
 
+       @SuppressWarnings("unused")
+       private void closeNeverNote() {
+               closeAction = true;
+               close();
+       }
        public void setMessage(String s) {
                logger.log(logger.HIGH, "Entering NeverNote.setMessage");
                logger.log(logger.HIGH, "Message: " +s);
@@ -1044,6 +1056,7 @@ public class NeverNote extends QMainWindow{
                indexTimer.start(indexTime);  // reset indexing timer
         
         settings.exec();
+        indexRunner.indexAttachmentsLocally = Global.indexAttachmentsLocally();
         if (Global.showTrayIcon())
                trayIcon.show();
         else
index 5460968..4e95242 100644 (file)
@@ -49,6 +49,7 @@ public class ConfigAppearancePage extends QWidget {
        private final QCheckBox newNoteWithTags;\r
        private final QCheckBox mimicEvernote;\r
        private final QCheckBox startMinimized;\r
+       private final QCheckBox minimizeOnClose;\r
        private final QSpinBox autoSaveInterval;\r
        \r
        private final List<String> tformats;\r
@@ -133,6 +134,7 @@ public class ConfigAppearancePage extends QWidget {
                mimicEvernote = new QCheckBox(tr("Mimic Evernote Selection Behavior (Requires Restart)"));\r
                showSplashScreen = new QCheckBox(tr("Show Splash Screen on Startup"));\r
                showTrayIcon = new QCheckBox(tr("Minimize To Tray"));\r
+               minimizeOnClose = new QCheckBox(tr("Minimize On Close"));\r
                verifyDelete = new QCheckBox(tr("Verify Deletes"));\r
                startMinimized = new QCheckBox(tr("Start Minimized"));\r
                pdfPreview = new QCheckBox(tr("Display PDF Documents Inline"));\r
@@ -152,6 +154,7 @@ public class ConfigAppearancePage extends QWidget {
                mainLayout.addWidget(tagBehaviorGroup);\r
                mainLayout.addWidget(mimicEvernote); \r
                mainLayout.addWidget(showTrayIcon);\r
+               mainLayout.addWidget(minimizeOnClose);\r
                mainLayout.addWidget(startMinimized);\r
                mainLayout.addWidget(showSplashScreen);\r
                mainLayout.addWidget(verifyDelete);\r
@@ -159,9 +162,20 @@ public class ConfigAppearancePage extends QWidget {
                mainLayout.addWidget(newNoteWithTags);\r
                mainLayout.addStretch(1);\r
                setLayout(mainLayout);\r
+               \r
+               showTrayIcon.clicked.connect(this, "showTrayIconClicked(Boolean)");\r
+               showTrayIconClicked(showTrayIcon.isChecked());\r
 \r
 \r
        }\r
+       \r
+       private void showTrayIconClicked(Boolean checked) {\r
+               if (!checked) {\r
+                       minimizeOnClose.setEnabled(false);\r
+                       minimizeOnClose.setChecked(false);\r
+               } else\r
+                       minimizeOnClose.setEnabled(true);\r
+       }\r
 \r
        \r
        //*****************************************\r
@@ -231,12 +245,24 @@ public class ConfigAppearancePage extends QWidget {
        //*******************************************\r
        public void setShowTrayIcon(boolean val) {\r
                showTrayIcon.setChecked(val);   \r
+               showTrayIconClicked(showTrayIcon.isChecked());\r
        }\r
        public boolean getShowTrayIcon() {\r
                return showTrayIcon.isChecked();\r
        }\r
        \r
        \r
+       //*******************************************\r
+       //* minimize on close get/set\r
+       //*******************************************\r
+       public void setMinimizeOnClose(boolean val) {\r
+               minimizeOnClose.setChecked(val);        \r
+       }\r
+       public boolean getMinimizeOnClose() {\r
+               return minimizeOnClose.isChecked();\r
+       }\r
+       \r
+       \r
        //*****************************************\r
        //* Show the splash screen on startup\r
        //*****************************************\r
index f20def5..c8baa2d 100644 (file)
@@ -114,6 +114,7 @@ public class ConfigDialog extends QDialog {
                        Global.disableUploads = false;\r
                Global.setDisableUploads(Global.disableUploads);\r
                Global.setMimicEvernoteInterface(appearancePage.getMimicEvernote());\r
+               Global.setMinimizeOnClose(appearancePage.getMinimizeOnClose());\r
                \r
                if (appearancePage.getShowSplashScreen())\r
                        Global.saveWindowVisible("SplashScreen", true);\r
@@ -149,6 +150,7 @@ public class ConfigDialog extends QDialog {
                Global.setSynchronizeOnClose(connectionPage.getSynchronizeOnClose());\r
                Global.setSynchronizeDeletedContent(connectionPage.getSynchronizeDeletedContent());\r
                Global.setTagBehavior(appearancePage.getTagBehavior());\r
+               Global.setIndexAttachmentsLocally(indexPage.getIndexAttachmentsLocally());\r
        FileOutputStream out = null;\r
                try {\r
                        out = new FileOutputStream(Global.getFileManager().getHomeDirFile("secure.txt"));\r
@@ -302,6 +304,7 @@ public class ConfigDialog extends QDialog {
                appearancePage.setNewNoteWithTags(Global.newNoteWithSelectedTags());\r
                appearancePage.setShowSplashScreen(Global.isWindowVisible("SplashScreen"));\r
                appearancePage.setTagBehavior(Global.tagBehavior());\r
+               appearancePage.setMinimizeOnClose(Global.minimizeOnClose());\r
                \r
                indexPage.setRegex(Global.getWordRegex());\r
                indexPage.setWordLength(Global.getMinimumWordLength());\r
index 7b29789..7d9b81a 100644 (file)
@@ -19,6 +19,7 @@
 \r
 package cx.fbn.nevernote.dialog;\r
 \r
+import com.trolltech.qt.gui.QCheckBox;\r
 import com.trolltech.qt.gui.QGroupBox;\r
 import com.trolltech.qt.gui.QHBoxLayout;\r
 import com.trolltech.qt.gui.QLabel;\r
@@ -35,6 +36,7 @@ public class ConfigIndexPage extends QWidget {
        private final QSpinBox lengthSpinner;\r
        private final QSpinBox weightSpinner;\r
        private final QSpinBox sleepSpinner;\r
+       private final QCheckBox indexAttachmentsLocally;\r
        private final QLineEdit regexEdit;\r
        \r
        public ConfigIndexPage(QWidget parent) {\r
@@ -68,20 +70,27 @@ public class ConfigIndexPage extends QWidget {
                wordLengthLayout.addWidget(lengthSpinner);\r
                wordLengthGroup.setLayout(wordLengthLayout);\r
                \r
-\r
-               // Minimum word length\r
+               // Recognition weight\r
                QGroupBox weightGroup = new QGroupBox(tr("Recognition"));\r
                QLabel weightLabel = new QLabel(tr("Minimum Recognition Weight"));\r
                weightSpinner = new QSpinBox();\r
                weightSpinner.setRange(1,100);\r
                weightSpinner.setSingleStep(1);\r
                weightSpinner.setValue(Global.getRecognitionWeight());\r
-\r
+               \r
                QHBoxLayout weightLayout = new QHBoxLayout();\r
                weightLayout.addWidget(weightLabel);\r
                weightLayout.addWidget(weightSpinner);\r
                weightGroup.setLayout(weightLayout);\r
                \r
+               // Local attachment indexing\r
+               QGroupBox attachmentGroup = new QGroupBox(tr("Attachments"));\r
+               indexAttachmentsLocally = new QCheckBox(tr("Index Attachments Locally"));\r
+               indexAttachmentsLocally.setChecked(Global.indexAttachmentsLocally());\r
+               \r
+               QHBoxLayout attachmentLayout = new QHBoxLayout();\r
+               attachmentLayout.addWidget(indexAttachmentsLocally);\r
+               attachmentGroup.setLayout(attachmentLayout);\r
 \r
                // Index sleep interval\r
                QGroupBox sleepGroup = new QGroupBox(tr("Index Interval"));\r
@@ -95,8 +104,6 @@ public class ConfigIndexPage extends QWidget {
                sleepLayout.addWidget(sleepLabel);\r
                sleepLayout.addWidget(sleepSpinner);\r
                sleepGroup.setLayout(sleepLayout);\r
-\r
-               \r
                \r
                // Regular Expressions for word parsing\r
                QGroupBox regexGroup = new QGroupBox(tr("Word Parse"));\r
@@ -115,6 +122,7 @@ public class ConfigIndexPage extends QWidget {
                mainLayout.addWidget(wordLengthGroup);\r
                mainLayout.addWidget(sleepGroup);\r
                mainLayout.addWidget(weightGroup);\r
+               mainLayout.addWidget(attachmentGroup);\r
                mainLayout.addWidget(regexGroup);\r
                mainLayout.addStretch(1);\r
                setLayout(mainLayout);\r
@@ -132,6 +140,12 @@ public class ConfigIndexPage extends QWidget {
                return lengthSpinner.value();\r
        }\r
        \r
+       //*****************************************\r
+       //* Get for flag to index attachments \r
+       //*****************************************\r
+       public boolean getIndexAttachmentsLocally() {\r
+               return indexAttachmentsLocally.isChecked();\r
+       }\r
        \r
        //*****************************************\r
        //* Word length get/set methods \r
index df6369e..4cd82f4 100644 (file)
@@ -188,7 +188,7 @@ public class MainMenuBar extends QMenuBar {
                \r
                exitAction = new QAction(tr("Exit"), this);\r
                exitAction.setToolTip("Close the program");\r
-               exitAction.triggered.connect(parent, "close()");\r
+               exitAction.triggered.connect(parent, "closeNeverNote()");\r
                exitAction.setShortcut("Ctrl+Q");\r
                setupShortcut(exitAction, "File_Exit");\r
                \r
index 61158d4..208d940 100644 (file)
@@ -80,6 +80,7 @@ public class IndexRunner extends QObject implements Runnable {
        private static int MAX_QUEUED_WAITING = 1000;\r
        public boolean interrupt;\r
        public boolean idle;\r
+       public boolean indexAttachmentsLocally = true;\r
        public volatile IndexSignal                     signal;\r
 \r
        \r
@@ -234,10 +235,10 @@ public class IndexRunner extends QObject implements Runnable {
                        }\r
                }\r
                \r
-               if (Global.keepRunning) {\r
+               if (Global.keepRunning && indexAttachmentsLocally) {\r
                        indexResourceContent(guid);\r
                }\r
-               \r
+                               \r
                if (Global.keepRunning)\r
                        conn.getNoteTable().noteResourceTable.setIndexNeeded(guid,false);\r
        }\r
@@ -556,11 +557,11 @@ public class IndexRunner extends QObject implements Runnable {
                }\r
                \r
                List<String> unindexedResources = conn.getNoteTable().noteResourceTable.getUnindexed();\r
-               if (notes.size() > 0 && !started) {\r
+               if (unindexedResources.size() > 0 && !started) {\r
                        signal.indexStarted.emit();\r
                        started = true;\r
                }\r
-               for (int i=0; i>unindexedResources.size()&& !interrupt && keepRunning; i++) {\r
+               for (int i=0; i<unindexedResources.size()&& !interrupt && keepRunning; i++) {\r
                        guid = unindexedResources.get(i);\r
                        if (keepRunning) {\r
                                indexResource();\r