OSDN Git Service

- Added the ability to do special refreshes for debugging. - Added the ability to...
authorRandy Baumgarte <randy@fbn.cx>
Tue, 17 May 2011 14:52:12 +0000 (10:52 -0400)
committerRandy Baumgarte <randy@Centauri.(none)>
Tue, 28 Jun 2011 13:20:44 +0000 (09:20 -0400)
src/cx/fbn/nevernote/Global.java
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/dialog/ConfigDebugPage.java
src/cx/fbn/nevernote/dialog/ConfigDialog.java
src/cx/fbn/nevernote/dialog/ConfigIndexPage.java
src/cx/fbn/nevernote/gui/TrashTreeWidget.java
src/cx/fbn/nevernote/threads/IndexRunner.java

index 495db8d..b301e4a 100644 (file)
@@ -1703,10 +1703,53 @@ public class Global {
     }\r
     \r
     //*******************\r
-    // Index attachments\r
+    // Index settings\r
     //*******************\r
+    // Set/Get if we should index the text of a note\r
+    public static boolean indexNoteBody() {\r
+               settings.beginGroup("Index");\r
+               try {\r
+                       String value = (String)settings.value("indexNoteBody", "true");\r
+                       settings.endGroup();\r
+                       if (value.equals("true"))\r
+                               return true;\r
+                       else\r
+                               return false;\r
+               } catch (java.lang.ClassCastException e) {\r
+                       Boolean value = (Boolean) settings.value("indexNoteBody", true);\r
+                       settings.endGroup();\r
+                       return value;\r
+               }\r
+    }\r
+    public static void setIndexNoteTitle(boolean value) {\r
+               settings.beginGroup("Index");\r
+               settings.setValue("indexNoteTitle", value);\r
+               settings.endGroup();    \r
+    }\r
+    // Set/Get if we should index the title of a note\r
+    public static boolean indexNoteTitle() {\r
+               settings.beginGroup("Index");\r
+               try {\r
+                       String value = (String)settings.value("indexNoteTitle", "true");\r
+                       settings.endGroup();\r
+                       if (value.equals("true"))\r
+                               return true;\r
+                       else\r
+                               return false;\r
+               } catch (java.lang.ClassCastException e) {\r
+                       Boolean value = (Boolean) settings.value("indexNoteTitle", true);\r
+                       settings.endGroup();\r
+                       return value;\r
+               }\r
+    }\r
+    public static void setIndexNoteBody(boolean value) {\r
+               settings.beginGroup("Index");\r
+               settings.setValue("indexNoteBody", value);\r
+               settings.endGroup();    \r
+    }\r
+    // Set/Get if we should index any attachments\r
     public static boolean indexAttachmentsLocally() {\r
-               settings.beginGroup("Debug");\r
+               settings.beginGroup("Index");\r
                try {\r
                        String value = (String)settings.value("indexAttachmentsLocally", "true");\r
                        settings.endGroup();\r
@@ -1720,12 +1763,45 @@ public class Global {
                        return value;\r
                }\r
     }\r
+    public static void setIndexImageRecognition(boolean value) {\r
+               settings.beginGroup("Index");\r
+               settings.setValue("indexImageRecognition", value);\r
+               settings.endGroup();    \r
+    }\r
+    public static boolean indexImageRecognition() {\r
+               settings.beginGroup("Index");\r
+               try {\r
+                       String value = (String)settings.value("indexImageRecognition", "true");\r
+                       settings.endGroup();\r
+                       if (value.equals("true"))\r
+                               return true;\r
+                       else\r
+                               return false;\r
+               } catch (java.lang.ClassCastException e) {\r
+                       Boolean value = (Boolean) settings.value("indexImageRecognition", true);\r
+                       settings.endGroup();\r
+                       return value;\r
+               }\r
+    }\r
     public static void setIndexAttachmentsLocally(boolean value) {\r
-               settings.beginGroup("Debug");\r
+               settings.beginGroup("Index");\r
                settings.setValue("indexAttachmentsLocally", value);\r
                settings.endGroup();    \r
     }\r
-\r
+    // Get/Set characters that shouldn't be removed from a word\r
+    public static String getSpecialIndexCharacters() {\r
+               settings.beginGroup("Index");\r
+               String text = (String)settings.value("specialCharacters", "");\r
+               settings.endGroup();    \r
+               return text;\r
+    }\r
+    public static void setSpecialIndexCharacters(String value) {\r
+               settings.beginGroup("Index");\r
+               settings.setValue("specialCharacters", value);\r
+               settings.endGroup();    \r
+               databaseCache = value;\r
+    }\r
+    \r
     //*****************************************************************************\r
     // Control how tag selection behaves (should they be "and" or "or" selections\r
     //*****************************************************************************\r
index 9dece7a..cf409b4 100644 (file)
@@ -409,6 +409,10 @@ public class NeverNote extends QMainWindow{
                        Global.getDatabaseUserid(), Global.getDatabaseUserPassword(), Global.cipherPassword);
                indexThread = new QThread(indexRunner, "Index Thread");
         indexRunner.indexAttachmentsLocally = Global.indexAttachmentsLocally();
+        indexRunner.indexImageRecognition = Global.indexImageRecognition();
+        indexRunner.indexNoteBody = Global.indexNoteBody();
+        indexRunner.indexNoteTitle = Global.indexNoteTitle();
+        indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
                indexThread.start();
                
         synchronizeAnimationTimer = new QTimer();
@@ -1179,6 +1183,10 @@ public class NeverNote extends QMainWindow{
         
         settings.exec();
         indexRunner.indexAttachmentsLocally = Global.indexAttachmentsLocally();
+        indexRunner.indexNoteBody = Global.indexNoteBody();
+        indexRunner.indexNoteTitle = Global.indexNoteTitle();
+        indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
+        indexRunner.indexImageRecognition = Global.indexImageRecognition();
         if (Global.showTrayIcon())
                trayIcon.show();
         else
@@ -1193,15 +1201,21 @@ public class NeverNote extends QMainWindow{
         else
                saveTimer.stop();
         
-        // This is a hack to force a reload of the index in case the date or time changed.
-//        if (!dateFormat.equals(Global.getDateFormat()) ||
-//                     !timeFormat.equals(Global.getTimeFormat())) {
-               noteCache.clear();
-               readOnlyCache.clear();
-               inkNoteCache.clear();
-               noteIndexUpdated(true);
-//        }
         
+        // Set special reloads
+        if (settings.getDebugPage().reloadSharedNotebooksClicked()) {
+               conn.executeSql("Delete from LinkedNotebook");
+               conn.executeSql("Delete from Notebook where linked=true");
+               conn.executeSql("Insert into Sync (key, value) values ('FullLinkedNotebookSync', 'true')");
+               conn.executeSql("Insert into Sync (key, value) values ('FullSharedNotebookSync', 'true')");
+        }
+
+        // Reload user data
+        noteCache.clear();
+        readOnlyCache.clear();
+        inkNoteCache.clear();
+        noteIndexUpdated(true);
+               
         logger.log(logger.HIGH, "Leaving NeverNote.settings");
        }
        // Restore things to the way they were
@@ -3215,7 +3229,9 @@ public class NeverNote extends QMainWindow{
     @SuppressWarnings("unused")
        private void emptyTrash() {
 //     browserWindow.clear();
+       logger.log(logger.EXTREME, "Emptying Trash");
        listManager.emptyTrash();
+       logger.log(logger.EXTREME, "Resetting view after trash empty");
        if (trashTree.selectedItems().size() > 0) {
                listManager.getSelectedNotebooks().clear();
                listManager.getSelectedTags().clear();
index 8ffe2de..e2bfc67 100644 (file)
@@ -48,6 +48,7 @@ public class ConfigDebugPage extends QWidget {
        QCheckBox htmlEntitiesFix;\r
        QCheckBox enableThumbnails;\r
        QSpinBox  databaseCache;\r
+       QCheckBox reloadSharedNotebooks;\r
        \r
        public ConfigDebugPage(QWidget parent) {\r
                super(parent);\r
@@ -123,7 +124,13 @@ public class ConfigDebugPage extends QWidget {
                htmlEntitiesFix.setText(tr("Enable Android Fix"));\r
                htmlLayout.addWidget(htmlEntitiesFix);\r
                htmlGroup.setLayout(htmlLayout);\r
-\r
+               \r
+               reloadSharedNotebooks = new QCheckBox(tr("Shared Notebooks"));\r
+               QGroupBox refresh = new QGroupBox(tr("Special Refresh (WARNING - This can cause unsynchronized data loss)."));\r
+               QVBoxLayout refreshLayout = new QVBoxLayout();\r
+               refreshLayout.addWidget(reloadSharedNotebooks);\r
+               refresh.setLayout(refreshLayout);\r
+               \r
                \r
                QTextBrowser msg = new QTextBrowser(this);\r
                QTextBrowser htmlMsg = new QTextBrowser(this);\r
@@ -133,6 +140,7 @@ public class ConfigDebugPage extends QWidget {
                mainLayout.addWidget(crlfGroup);\r
                htmlLayout.addWidget(htmlMsg);\r
                mainLayout.addWidget(htmlGroup);\r
+               mainLayout.addWidget(refresh);\r
 \r
                mainLayout.addStretch(1);\r
                setLayout(mainLayout);\r
@@ -215,4 +223,12 @@ public class ConfigDebugPage extends QWidget {
                return new Integer(databaseCache.value()*1024).toString();\r
        }\r
 \r
+       \r
+       //***************************************\r
+       //* Special refreshes\r
+       //***************************************\r
+       public boolean reloadSharedNotebooksClicked() {\r
+               return reloadSharedNotebooks.isChecked();\r
+       }\r
+\r
 }\r
index 9af74e7..c28df9a 100644 (file)
@@ -173,6 +173,11 @@ public class ConfigDialog extends QDialog {
                Global.setSynchronizeDeletedContent(connectionPage.getSynchronizeDeletedContent());\r
                Global.setTagBehavior(appearancePage.getTagBehavior());\r
                Global.setIndexAttachmentsLocally(indexPage.getIndexAttachmentsLocally());\r
+               Global.setIndexNoteBody(indexPage.getIndexNoteBody());\r
+               Global.setIndexNoteTitle(indexPage.getIndexNoteTitle());\r
+               Global.setIndexImageRecognition(indexPage.getIndexImageRecognition());\r
+               Global.setSpecialIndexCharacters(indexPage.getSpecialCharacters());\r
+               \r
        FileOutputStream out = null;\r
                try {\r
                        out = new FileOutputStream(Global.getFileManager().getHomeDirFile("secure.txt"));\r
index 44c4a42..06947bb 100644 (file)
@@ -42,6 +42,10 @@ public class ConfigIndexPage extends QWidget {
        private final QSpinBox weightSpinner;\r
        private final QSpinBox sleepSpinner;\r
        private final QCheckBox indexAttachmentsLocally;\r
+       private final QCheckBox indexImageRecognition;\r
+       private final QCheckBox indexTitle;\r
+       private final QLineEdit specialStrip;\r
+       private final QCheckBox indexBody;\r
        private final QLineEdit regexEdit;\r
        \r
        public ConfigIndexPage(QWidget parent) {\r
@@ -61,12 +65,29 @@ public class ConfigIndexPage extends QWidget {
                weightGroup.setLayout(weightLayout);\r
                \r
                // Local attachment indexing\r
-               QGroupBox attachmentGroup = new QGroupBox(tr("Attachments"));\r
+               QGroupBox attachmentGroup = new QGroupBox(tr("Content"));\r
+               indexBody = new QCheckBox(tr("Index Note Body"));\r
+               indexBody.setChecked(Global.indexNoteBody());\r
+               indexTitle = new QCheckBox(tr("Index Note Title"));\r
+               indexTitle.setChecked(Global.indexNoteTitle());\r
                indexAttachmentsLocally = new QCheckBox(tr("Index Attachments Locally"));\r
                indexAttachmentsLocally.setChecked(Global.indexAttachmentsLocally());\r
+               indexImageRecognition = new QCheckBox(tr("Index Image Recognition"));\r
+               indexImageRecognition.setChecked(Global.indexImageRecognition());\r
                \r
-               QHBoxLayout attachmentLayout = new QHBoxLayout();\r
+               specialStrip = new QLineEdit();\r
+               specialStrip.setText(Global.getSpecialIndexCharacters());\r
+               \r
+               QVBoxLayout attachmentLayout = new QVBoxLayout();\r
+               attachmentLayout.addWidget(indexBody);\r
+               attachmentLayout.addWidget(indexTitle);\r
                attachmentLayout.addWidget(indexAttachmentsLocally);\r
+               attachmentLayout.addWidget(indexImageRecognition);\r
+               \r
+               QHBoxLayout specialCharLayout = new QHBoxLayout();\r
+               specialCharLayout.addWidget(new QLabel(tr("Special Word Characters")));\r
+               specialCharLayout.addWidget(specialStrip);\r
+               attachmentLayout.addLayout(specialCharLayout);\r
                attachmentGroup.setLayout(attachmentLayout);\r
 \r
                // Index sleep interval\r
@@ -112,6 +133,18 @@ public class ConfigIndexPage extends QWidget {
        public boolean getIndexAttachmentsLocally() {\r
                return indexAttachmentsLocally.isChecked();\r
        }\r
+       public boolean getIndexNoteBody() {\r
+               return indexBody.isChecked();\r
+       }\r
+       public boolean getIndexNoteTitle() {\r
+               return indexTitle.isChecked();\r
+       }\r
+       public String getSpecialCharacters() {\r
+               return specialStrip.text();\r
+       }\r
+       public boolean getIndexImageRecognition() {\r
+               return indexImageRecognition.isChecked();\r
+       }\r
        \r
        //*****************************************\r
        //* Word length get/set methods \r
index 520f3e5..7eb81d1 100644 (file)
@@ -56,7 +56,7 @@ public class TrashTreeWidget extends QTreeWidget {
         trashIcon = new QIcon(iconPath+"trash.png");\r
         trashFullIcon = new QIcon(iconPath+"trash-full.png");\r
         header().hide();\r
-        setMaximumHeight(30);\r
+        //setMaximumHeight(30);\r
         setMinimumHeight(30);\r
        }\r
        \r
index b17fe94..d5fb25c 100644 (file)
@@ -74,6 +74,10 @@ public class IndexRunner extends QObject implements Runnable {
        public boolean                                          keepRunning;\r
        private final QDomDocument                      doc;\r
        private static String                           regex = Global.getWordRegex();\r
+       public String                                           specialIndexCharacters = "";\r
+       public boolean                                          indexNoteBody = true;\r
+       public boolean                                          indexNoteTitle = true;\r
+       public boolean                                          indexImageRecognition = true;\r
        private final DatabaseConnection        conn;\r
        private volatile LinkedBlockingQueue<String> workQueue;\r
        private static int MAX_QUEUED_WAITING = 1000;\r
@@ -164,14 +168,21 @@ public class IndexRunner extends QObject implements Runnable {
                \r
                logger.log(logger.EXTREME, "Getting note content");\r
                Note n = conn.getNoteTable().getNote(guid,true,false,true,true, true);\r
-               String data = n.getContent();\r
-               data = conn.getNoteTable().getNoteContentNoUTFConversion(n.getGuid());\r
+               String data;\r
+               if (indexNoteBody) {\r
+                       data = n.getContent();\r
+                       data = conn.getNoteTable().getNoteContentNoUTFConversion(n.getGuid());\r
                \r
-               logger.log(logger.EXTREME, "Removing any encrypted data");\r
-               data = removeEnCrypt(data.toString());\r
-               logger.log(logger.EXTREME, "Removing xml markups");\r
-               String text =  removeTags(StringEscapeUtils.unescapeHtml(data) +" "+\r
-               n.getTitle());\r
+                       logger.log(logger.EXTREME, "Removing any encrypted data");\r
+                       data = removeEnCrypt(data.toString());\r
+                       logger.log(logger.EXTREME, "Removing xml markups");\r
+               } else\r
+                       data = "";\r
+               String text;\r
+               if (indexNoteTitle)\r
+                       text =  removeTags(StringEscapeUtils.unescapeHtml(data) +" "+ n.getTitle());\r
+               else\r
+                       text = removeTags(StringEscapeUtils.unescapeHtml(data));\r
                                \r
                logger.log(logger.EXTREME, "Splitting words");\r
                String[] result = text.toString().split(regex);\r
@@ -235,7 +246,10 @@ public class IndexRunner extends QObject implements Runnable {
                        return;\r
                foundWords.clear();\r
                Resource r = conn.getNoteTable().noteResourceTable.getNoteResourceRecognition(guid);\r
-               if (r == null || r.getRecognition() == null || r.getRecognition().getBody() == null || r.getRecognition().getBody().length == 0) \r
+               if (!indexImageRecognition || \r
+                               r == null || r.getRecognition() == null || \r
+                               r.getRecognition().getBody() == null || \r
+                               r.getRecognition().getBody().length == 0) \r
                        resourceBinary = new QByteArray(" ");\r
                else\r
                        resourceBinary = new QByteArray(r.getRecognition().getBody());\r
@@ -605,7 +619,7 @@ public class IndexRunner extends QObject implements Runnable {
                        return;\r
                StringBuffer buffer = new StringBuffer(word.toLowerCase());\r
                for (int i=buffer.length()-1; i>=0; i--) {\r
-                       if (!Character.isLetterOrDigit(buffer.charAt(i)))\r
+                       if (!Character.isLetterOrDigit(buffer.charAt(i)) && specialIndexCharacters.indexOf(buffer.charAt(i)) == -1)\r
                                buffer.deleteCharAt(i);\r
                        else\r
                                break;\r