OSDN Git Service

Correct problem parsing notes where carriage returns did not separate some XML lines...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / Global.java
index 328d5cb..0090c4d 100644 (file)
@@ -21,21 +21,19 @@ package cx.fbn.nevernote;
 \r
 \r
 //import java.io.ByteArrayOutputStream;\r
-import java.io.File;\r
+\r
 import java.io.PrintStream;\r
 import java.text.SimpleDateFormat;\r
 import java.util.ArrayList;\r
 import java.util.Calendar;\r
 import java.util.HashMap;\r
 import java.util.List;\r
-import java.util.concurrent.ArrayBlockingQueue;\r
 \r
 import com.evernote.edam.type.Accounting;\r
 import com.evernote.edam.type.PrivilegeLevel;\r
 import com.evernote.edam.type.User;\r
 import com.evernote.edam.type.UserAttributes;\r
 import com.trolltech.qt.core.QByteArray;\r
-import com.trolltech.qt.core.QMutex;\r
 import com.trolltech.qt.core.QSettings;\r
 import com.trolltech.qt.gui.QPalette;\r
 \r
@@ -45,48 +43,33 @@ import cx.fbn.nevernote.config.StartupConfig;
 import cx.fbn.nevernote.gui.ContainsAttributeFilterTable;\r
 import cx.fbn.nevernote.gui.DateAttributeFilterTable;\r
 import cx.fbn.nevernote.gui.ShortcutKeys;\r
-import cx.fbn.nevernote.signals.DBRunnerSignal;\r
-import cx.fbn.nevernote.threads.DBRunner;\r
 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
 \r
 public class Global {\r
-       public static String version = "0.88";\r
+       public static String version = "0.90";\r
     public static String username = ""; \r
-    public static String password = ""; \r
-\r
-    public static DBRunner                             dbRunner;                       // Database thread\r
-    public static DBRunnerSignal               dbRunnerSignal;         // Signals to the database runner\r
-    public static QMutex                               dbrunnerWorkLock;       // mutex lock for work queue\r
+    public static String password = "";     \r
     \r
 \r
-    public static int mainThreadId=0;\r
-    private static ArrayBlockingQueue<Boolean> mainThreadWaiter = new ArrayBlockingQueue<Boolean>(1);\r
+    public static final int mainThreadId=0;\r
     \r
-    public static int syncThreadId=1;\r
-    private static ArrayBlockingQueue<Boolean> syncThreadWaiter = new ArrayBlockingQueue<Boolean>(1);\r
+    public static final int syncThreadId=1;\r
     \r
-    public static int tagCounterThreadId=2;\r
-    private static ArrayBlockingQueue<Boolean> tagCounterThreadWaiter = new ArrayBlockingQueue<Boolean>(1);\r
+    public static final int tagCounterThreadId=2;\r
     \r
-    public static int trashCounterThreadId=3;   // This should always be the highest thread ID\r
-    private static ArrayBlockingQueue<Boolean> trashCounterThreadWaiter = new ArrayBlockingQueue<Boolean>(1);\r
+    public static final int trashCounterThreadId=3;   // This should always be the highest thread ID\r
 \r
-    public static int indexThreadId=4;         // Thread for indexing words\r
-    private static ArrayBlockingQueue<Boolean> indexThreadWaiter = new ArrayBlockingQueue<Boolean>(1);\r
+    public static final int indexThreadId=4;           // Thread for indexing words\r
 \r
-    public static int saveThreadId=5;          // Thread used for processing data to saving content\r
-    private static ArrayBlockingQueue<Boolean> saveThreadWaiter = new ArrayBlockingQueue<Boolean>(1);\r
+    public static final int saveThreadId=5;    // Thread used for processing data to saving content\r
 \r
-    public static int notebookCounterThreadId=6;   // Notebook Thread\r
-    private static ArrayBlockingQueue<Boolean> notebookCounterThreadWaiter = new ArrayBlockingQueue<Boolean>(1);\r
+    public static final int notebookCounterThreadId=6;   // Notebook Thread\r
 \r
-    public static int indexThread03Id=7;   // unused\r
-    private static ArrayBlockingQueue<Boolean> indexThread03ThreadWaiter = new ArrayBlockingQueue<Boolean>(1);\r
+    public static final int indexThread03Id=7;   // unused\r
 \r
-    public static int indexThread04Id=8;   // unused\r
-    private static ArrayBlockingQueue<Boolean> indexThread04ThreadWaiter = new ArrayBlockingQueue<Boolean>(1);\r
+    public static final int indexThread04Id=8;   // unused\r
     \r
-    public static int dbThreadId=9;   // This should always be the highest thread ID\r
+    public static final int dbThreadId=9;   // This should always be the highest thread ID\r
     \r
     \r
     public static HashMap<String,String> passwordSafe = new HashMap<String, String>();\r
@@ -96,7 +79,6 @@ public class Global {
     public static long authTimeRemaining;\r
     public static long authRefreshTime;\r
     public static long failedRefreshes = 0;\r
-    public static String currentDir;\r
     public static boolean keepRunning;\r
     \r
     public static String userStoreUrl;\r
@@ -120,6 +102,7 @@ public class Global {
     private static String wordRegex;\r
     public static boolean enableCarriageReturnFix = false;\r
     \r
+    public static String name = null;\r
     public static QSettings    settings;\r
     public static boolean isConnected;\r
     public static boolean showDeleted = false;\r
@@ -129,19 +112,16 @@ public class Global {
        public static String attachmentNameDelimeter = "------";\r
        \r
        public static String    databaseName = new String("NeverNote");\r
-       public static String    indexDatabaseName = new String("IndexDatabase.db");\r
        public static DateAttributeFilterTable createdSinceFilter;\r
        public static DateAttributeFilterTable createdBeforeFilter;\r
        public static DateAttributeFilterTable changedSinceFilter;\r
        public static DateAttributeFilterTable changedBeforeFilter;\r
        public static ContainsAttributeFilterTable containsFilter;\r
-//     public static DBLock                            dbLock;\r
-//     public static DBLock                            indexLock;\r
        public static ApplicationLogger    logger;\r
        PrintStream stdoutStream;\r
        public static QPalette                          originalPalette;\r
        public static ShortcutKeys                      shortcutKeys;\r
-       private static boolean                          disableViewing;\r
+       public static boolean                           disableViewing;\r
        \r
        public static List<String>                              invalidElements = new ArrayList<String>();\r
        public static HashMap<String, ArrayList<String>>        invalidAttributes = new HashMap<String, ArrayList<String>>();\r
@@ -153,20 +133,20 @@ public class Global {
        static Calendar intervalTraceTime;\r
 \r
        private static FileManager fileManager;\r
-\r
+       \r
     // Do initial setup \r
     public static void setup(StartupConfig startupConfig) throws InitializationException  {\r
         settings = new QSettings("fbn.cx", startupConfig.getName());\r
         disableViewing = startupConfig.getDisableViewing();\r
 \r
-        fileManager = new FileManager(startupConfig.getHomeDirPath());\r
-        currentDir = fileManager.getHomeDirPath();\r
+        fileManager = new FileManager(startupConfig.getHomeDirPath(), startupConfig.getProgramDirPath());\r
+\r
 \r
                        getServer();\r
                        settings.beginGroup("General");\r
                        String regex = (String) settings.value("regex", "[,\\s]+");\r
                        setWordRegex(regex);\r
-                       String wordString = settings.value("wordLength", "4").toString();\r
+                       String wordString = settings.value("minimumWordLength", "4").toString();\r
                        Integer wordLen = new Integer(wordString);\r
                        Global.minimumWordCount = wordLen;\r
                        settings.endGroup();\r
@@ -178,26 +158,13 @@ public class Global {
                        keepRunning = true;\r
                        disableUploads = disableUploads();\r
                        enableCarriageReturnFix = enableCarriageReturnFix();\r
-//                     dbLock = new DBLock();\r
-//                     indexLock = new DBLock();\r
                        logger = new ApplicationLogger("global.log");\r
                        shortcutKeys = new ShortcutKeys();\r
-                       dbrunnerWorkLock = new QMutex();\r
                        mimicEvernoteInterface = getMimicEvernoteInterface();\r
                        resourceMap = new HashMap<String,String>();\r
                                \r
     }\r
 \r
-    public static String getDirectoryPath() {\r
-               if (currentDir == null) {\r
-                       currentDir = System.getProperty("user.dir");\r
-               }\r
-               if (!currentDir.substring(currentDir.length()-1).equals(File.separator)) {\r
-                       currentDir = currentDir+File.separator;\r
-               }\r
-               return currentDir;\r
-    }\r
-\r
     public static String getWordRegex() {\r
        return wordRegex;\r
     }\r
@@ -536,6 +503,23 @@ public class Global {
                        settings.setValue("pdfPreview", "false");\r
                settings.endGroup();\r
     }\r
+    public static boolean newNoteWithSelectedTags() {\r
+               settings.beginGroup("General");\r
+               String text = (String)settings.value("newNoteWithSelectedTags", "false");\r
+               settings.endGroup();\r
+               if (text.equalsIgnoreCase("true"))\r
+                       return true;\r
+               else\r
+                       return false;\r
+    }\r
+    public static void setNewNoteWithSelectedTags(boolean val) {\r
+               settings.beginGroup("General");\r
+               if (val)\r
+                       settings.setValue("newNoteWithSelectedTags", "true");\r
+               else\r
+                       settings.setValue("newNoteWithSelectedTags", "false");\r
+               settings.endGroup();\r
+    }\r
     public static void setMinimumWordLength(int len) {\r
                settings.beginGroup("General");\r
                settings.setValue("minimumWordLength", len);\r
@@ -873,7 +857,7 @@ public class Global {
                String val  = (String)settings.value("DatabaseURL", "");\r
                settings.endGroup();\r
                if (val.equals(""))\r
-                       val = "jdbc:h2:"+Global.getDirectoryPath() +File.separator +"db" +File.separator +Global.databaseName;\r
+                       val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.databaseName);\r
                return val;\r
     }\r
     public static String getDatabaseUserid() {\r
@@ -917,71 +901,6 @@ public class Global {
                settings.endGroup();\r
     }\r
     \r
-    public static void dbWait() {\r
- //    Global.dbThreadWait.wait(Global.dbThreadWaitMutex);\r
-    }\r
-    public static void dbContinue() {\r
-//     Global.dbThreadWait.wakeAll();\r
-    }\r
-    public static synchronized void dbClientWait(int id) {\r
-       if (id == mainThreadId) {\r
-                       try {mainThreadWaiter.take(); } catch (InterruptedException e) {e.printStackTrace();}\r
-       }\r
-       if (id == syncThreadId) {\r
-                       try {syncThreadWaiter.take();} catch (InterruptedException e) {e.printStackTrace();}\r
-       }\r
-       if (id == tagCounterThreadId) {\r
-               try {tagCounterThreadWaiter.take();} catch (InterruptedException e) {e.printStackTrace();}\r
-       }\r
-       if (id == trashCounterThreadId) {\r
-               try {trashCounterThreadWaiter.take();} catch (InterruptedException e) {e.printStackTrace();}\r
-       }\r
-       if (id == indexThreadId) {\r
-               try {indexThreadWaiter.take();} catch (InterruptedException e) {e.printStackTrace();}\r
-       }\r
-       if (id == saveThreadId) {\r
-               try {saveThreadWaiter.take();} catch (InterruptedException e) {e.printStackTrace();}\r
-       }\r
-       if (id == notebookCounterThreadId) {\r
-               try {notebookCounterThreadWaiter.take();} catch (InterruptedException e) {e.printStackTrace();}\r
-       }\r
-       if (id == indexThread03Id) {\r
-               try {indexThread03ThreadWaiter.take();} catch (InterruptedException e) {e.printStackTrace();}\r
-       }\r
-       if (id == indexThread04Id) {\r
-               try {indexThread04ThreadWaiter.take();} catch (InterruptedException e) {e.printStackTrace();}\r
-       }\r
-    }\r
-    public static void dbClientContinue(int id) {\r
-       if (id == mainThreadId) {\r
-                       try { mainThreadWaiter.put(true); } catch (InterruptedException e) { e.printStackTrace();}\r
-       }\r
-       if (id == syncThreadId) {\r
-                       try { syncThreadWaiter.put(true); } catch (InterruptedException e) { e.printStackTrace();}\r
-       }\r
-               if (id == tagCounterThreadId) { \r
-                       try { tagCounterThreadWaiter.put(true); } catch (InterruptedException e) { e.printStackTrace();}\r
-               }\r
-               if (id == trashCounterThreadId) { \r
-                       try { trashCounterThreadWaiter.put(true); } catch (InterruptedException e) { e.printStackTrace();}\r
-               }\r
-               if (id == indexThreadId) { \r
-                       try { indexThreadWaiter.put(true); } catch (InterruptedException e) { e.printStackTrace();}\r
-               }\r
-               if (id == saveThreadId) { \r
-                       try { saveThreadWaiter.put(true); } catch (InterruptedException e) { e.printStackTrace();}\r
-               }\r
-               if (id == notebookCounterThreadId) { \r
-                       try { notebookCounterThreadWaiter.put(true); } catch (InterruptedException e) { e.printStackTrace();}\r
-               }\r
-               if (id == indexThread03Id) { \r
-                       try { indexThread03ThreadWaiter.put(true); } catch (InterruptedException e) { e.printStackTrace();}\r
-               }\r
-               if (id == indexThread04Id) { \r
-                       try { indexThread04ThreadWaiter.put(true); } catch (InterruptedException e) { e.printStackTrace();}\r
-               }\r
-    }\r
-    \r
     public static void saveState(String name, QByteArray state) {\r
                settings.beginGroup("SaveState");\r
                settings.setValue(name, state);\r
@@ -1129,12 +1048,14 @@ public class Global {
                startTraceTime = null;\r
        }\r
 \r
+\r
     public static FileManager getFileManager() {\r
         return fileManager;\r
     }\r
-\r
     public static boolean getDisableViewing() {\r
         return disableViewing;\r
     }\r
+    \r
+\r
 }\r
 \r