OSDN Git Service

Correct name & version in about box.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / Global.java
index 19d1a6b..136b4e8 100644 (file)
 package cx.fbn.nevernote;\r
 \r
 \r
-//import java.io.ByteArrayOutputStream;\r
-\r
 import java.io.ByteArrayInputStream;\r
 import java.io.ByteArrayOutputStream;\r
 import java.io.IOException;\r
 import java.io.ObjectInputStream;\r
 import java.io.ObjectOutputStream;\r
-import java.io.PrintStream;\r
 import java.text.SimpleDateFormat;\r
 import java.util.ArrayList;\r
 import java.util.Calendar;\r
@@ -55,13 +52,24 @@ import cx.fbn.nevernote.gui.ShortcutKeys;
 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
 import cx.fbn.nevernote.utilities.Pair;\r
 \r
+\r
+//*****************************************************\r
+//*****************************************************\r
+//* Global constants & static functions used by \r
+//* multiple threads.\r
+//*****************************************************\r
+//*****************************************************\r
+\r
 public class Global {\r
-       public static String version = "0.97";\r
-       public static String[] validVersions = {"0.97", "0.96"};\r
+       // Set current version and the known versions.\r
+       public static String version = "1.0";\r
+       public static String[] validVersions = {"1.0", "0.99", "0.98", "0.97", "0.96"};\r
     public static String username = ""; \r
     public static String password = "";     \r
     \r
 \r
+    // Each thread has an ID.  This is used primarily to check the status\r
+    // of running threads.\r
     public static final int mainThreadId=0;\r
     public static final int syncThreadId=1;\r
     public static final int tagCounterThreadId=2;\r
@@ -72,27 +80,41 @@ public class Global {
     public static final int indexThread03Id=7;   // unused\r
     public static final int indexThread04Id=8;   // unused\r
     public static final int dbThreadId=9;   // This should always be the highest thread ID\r
+    public static final int threadCount = 10;\r
     \r
     \r
+    // These variables deal with where the list of notes appears\r
+    // They will either be vertical (View_List_Narrow) or will be\r
+    // on top of the note (View_List_Wide).  It also has the size of\r
+    // thumbnails displayed in each view\r
     public static int View_List_Wide = 1;\r
     public static int View_List_Narrow = 2;\r
     public static QSize smallThumbnailSize = new QSize(100,75);\r
     public static QSize largeThumbnailSize = new QSize(300,225);\r
-//    public static boolean listView = true;\r
-    \r
+\r
+    // This is used to keep a running list of passwords that the user\r
+    // wants us to remember.\r
     public static HashMap<String,Pair<String,String>> passwordSafe = new HashMap<String, Pair<String,String>>();\r
     public static List<Pair<String,String>> passwordRemember = new ArrayList<Pair<String,String>>();\r
-    public static String currentNotebookGuid;\r
+    \r
+    \r
+    //public static String currentNotebookGuid;\r
+    \r
+    // These deal with Evernote user settings\r
     public static User user; \r
     public static long authTimeRemaining;\r
     public static long authRefreshTime;\r
-    public static long failedRefreshes = 0;\r
-    public static boolean keepRunning;\r
-    \r
+    public static long failedRefreshes = 0; \r
     public static String userStoreUrl;\r
     public static String noteStoreUrl;\r
     public static String noteStoreUrlBase;\r
-    \r
+\r
+    // When we want to shut down we set this to true to short\r
+    // circut other threads\r
+    public static boolean keepRunning;\r
+        \r
+    // In the note list, these are the column numbers\r
+    // so I don't need to hard code numbers.\r
     public static int noteTableCreationPosition = 0;\r
     public static int noteTableTitlePosition = 1;\r
     public static int noteTableTagPosition = 2;\r
@@ -107,44 +129,59 @@ public class Global {
     public static int noteTableColumnCount = 11;\r
     public static Integer cryptCounter = 0;\r
     \r
-    public static int minimumWordCount = 2;\r
+    //public static int minimumWordCount = 2;\r
+    \r
+    // Regular expression to parse text with when indexing\r
     private static String wordRegex;\r
+    \r
+    // Experimental fixes.  Set via Edit/Preferences/Debugging\r
     public static boolean enableCarriageReturnFix = false;\r
+    public static boolean enableHTMLEntitiesFix = 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
-    public static boolean disableUploads = false;\r
-       public static int messageLevel;\r
-       public static String tagDelimeter = ",";\r
-       public static String attachmentNameDelimeter = "------";\r
+    // Used to set & retrieve ini & Windows registry settings\r
+    public static QSettings    settings;     // Set & get ini settings\r
+    public static boolean isConnected;    // Are we connected to Evernote\r
+    public static boolean showDeleted = false;   // Show deleted notes?\r
+    public static boolean disableUploads = false;  // Should we disable uploads (used in testing features)\r
+       public static int messageLevel;   // The level of messages to write to the log files\r
+       public static String tagDelimeter = ",";   // This is used to separate out tag names when entering above note\r
+       public static String attachmentNameDelimeter = "------";  // Used to separate out attachment names in the res directory\r
        \r
-       public static String    databaseName = new String("NeverNote");\r
-       public static String    indexDatabaseName = new String("Index");\r
-       public static String    resourceDatabaseName = new String("Resources");\r
+       \r
+       //* Database fields\r
+       public static String    databaseName = new String("NeverNote");  // database name.  used for multiple databases to separate settings.\r
+       public static String    indexDatabaseName = new String("Index"); // searchable words database\r
+       public static String    resourceDatabaseName = new String("Resources");  // attachments database\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
+       \r
+       // Log file used for debugging\r
        public static ApplicationLogger    logger;\r
-       PrintStream stdoutStream;\r
+       //PrintStream stdoutStream;\r
+       \r
+       // Application key shortcuts & appearance\r
        public static QPalette                          originalPalette;\r
        public static ShortcutKeys                      shortcutKeys;\r
-       public static boolean                           disableViewing;\r
        \r
+       public static boolean                           disableViewing;  // used to disable the editor\r
+       \r
+       // When saving a note, this is a list of things we strip out because Evernote hates them\r
        public static List<String>                              invalidElements = new ArrayList<String>();\r
        public static HashMap<String, ArrayList<String>>        invalidAttributes = new HashMap<String, ArrayList<String>>();\r
-       public static boolean mimicEvernoteInterface;\r
-       public static HashMap<String,String> resourceMap;\r
-       public static String cipherPassword = "";\r
-       public static String databaseCache = "16384";\r
        \r
-       static Calendar startTraceTime;\r
+       public static boolean mimicEvernoteInterface; // Try to mimic Evernote or allow multiple notebook selection\r
+       public static HashMap<String,String> resourceMap;   // List of attachments for a note.\r
+       public static String cipherPassword = "";    // If the database is encrypted, this stores the password\r
+       public static String databaseCache = "16384";  // Default DB cache size\r
+       \r
+       // These are used for performance testing\r
+       static Calendar startTraceTime;   \r
        static Calendar intervalTraceTime;\r
-\r
-       private static FileManager fileManager;\r
+       \r
+       private static FileManager fileManager;  // Used to access files & directories\r
        \r
     // Do initial setup \r
     public static void setup(StartupConfig startupConfig) throws InitializationException  {\r
@@ -154,38 +191,45 @@ public class Global {
         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("minimumWordLength", "4").toString();\r
-                       Integer wordLen = new Integer(wordString);\r
-                       Global.minimumWordCount = wordLen;\r
-                       settings.endGroup();\r
-                       settings.beginGroup("Debug");\r
-                       String msglevel = (String) settings.value("messageLevel", "Low");\r
-                       settings.endGroup();\r
-                       messageLevel = 1;\r
-                       setMessageLevel(msglevel);\r
-                       keepRunning = true;\r
-                       disableUploads = disableUploads();\r
-                       enableCarriageReturnFix = enableCarriageReturnFix();\r
-                       logger = new ApplicationLogger("global.log");\r
-                       shortcutKeys = new ShortcutKeys();\r
-                       mimicEvernoteInterface = getMimicEvernoteInterface();\r
-                       resourceMap = new HashMap<String,String>();\r
+               getServer();  // Setup URL to connect to\r
+               \r
+               // Get regular expressions used to parse out words\r
+               settings.beginGroup("General");\r
+               String regex = (String) settings.value("regex", "[,\\s]+");\r
+               setWordRegex(regex);\r
+               settings.endGroup();\r
+               \r
+               // Setup debugging information\r
+               //settings.beginGroup("Debug");\r
+               //String msglevel = (String) settings.value("messageLevel", "Low");\r
+               //settings.endGroup();\r
+               \r
+               \r
+               //messageLevel = 1;\r
+               //setMessageLevel(msglevel);\r
+               keepRunning = true;  // Make sure child threads stay running\r
+               disableUploads = disableUploads();  // Should we upload anything?  Normally true.\r
+               enableCarriageReturnFix = enableCarriageReturnFix();  // Enable test fix?\r
+               enableHTMLEntitiesFix = enableHtmlEntitiesFix();  // Enable test fix?\r
+               \r
+               logger = new ApplicationLogger("global.log");  // Setup log for this class \r
+               shortcutKeys = new ShortcutKeys();  // Setup keyboard shortcuts.\r
+               mimicEvernoteInterface = getMimicEvernoteInterface();  // Should we mimic Evernote's notebook behavior\r
+               resourceMap = new HashMap<String,String>();  // Setup resource map used to store attachments when editing\r
                        \r
-                       databaseCache = getDatabaseCacheSize();\r
-                               \r
+               databaseCache = getDatabaseCacheSize();  // Set database cache size     \r
     }\r
 \r
+    // Get/Set word parsing regular expression\r
     public static String getWordRegex() {\r
        return wordRegex;\r
     }\r
     public static void setWordRegex(String r) {\r
        wordRegex = r;\r
     }\r
-    public static void setMessageLevel(String msglevel) {\r
+\r
+   // Set the debug message level\r
+   public static void setMessageLevel(String msglevel) {\r
        if (msglevel.equalsIgnoreCase("low")) \r
                        messageLevel = 1;\r
                if (msglevel.equalsIgnoreCase("medium")) \r
@@ -199,6 +243,11 @@ public class Global {
                settings.endGroup();            \r
     }\r
 \r
+   //****************************************************\r
+   //****************************************************\r
+   //** Save user account information from Evernote\r
+   //****************************************************\r
+   //****************************************************\r
     public static void saveUserInformation(User user) {\r
        settings.beginGroup("User");\r
                settings.setValue("id", user.getId());\r
@@ -210,6 +259,7 @@ public class Global {
                settings.setValue("created", user.getCreated());\r
                settings.setValue("updated", user.getUpdated());\r
                settings.setValue("deleted", user.getDeleted());\r
+               settings.setValue("shard", user.getShardId());\r
                settings.endGroup();\r
                isPremium();\r
                if (user.getAttributes()!=null)\r
@@ -218,6 +268,54 @@ public class Global {
                        saveUserAccounting(user.getAccounting());\r
 \r
     }\r
+    public static User getUserInformation() {\r
+       User user = new User();\r
+       settings.beginGroup("User");\r
+       try {   \r
+               user.setId((Integer)settings.value("id", 0));                   \r
+       } catch  (java.lang.ClassCastException e) {\r
+               user.setId(new Integer((String)settings.value("id", "0")));\r
+       }\r
+               String username = (String)settings.value("username", "");\r
+               String email = (String)settings.value("email", "");\r
+               String name = (String)settings.value("name", "");\r
+               String timezone = (String)settings.value("timezone", "");\r
+               Integer privilege = 0;\r
+               try {   \r
+                       privilege = new Integer((String)settings.value("privilege", "0"));                      \r
+               } catch (java.lang.ClassCastException e) {\r
+                       privilege = (Integer)settings.value("privilege", 0);\r
+               }\r
+\r
+               try {   \r
+                       String date = (String)settings.value("created", "0");\r
+                       user.setCreated(new Long(date));\r
+                       date = (String)settings.value("updated", "0");\r
+                       user.setUpdated(new Long(date));\r
+                       date = (String)settings.value("deleted", "0");\r
+                       user.setDeleted(new Long(date));\r
+               } catch (java.lang.ClassCastException e) {\r
+                       Long date = (Long)settings.value("created", 0);\r
+                       user.setCreated(date);\r
+                       date = (Long)settings.value("updated", 0);\r
+                       user.setUpdated(date);\r
+                       date = (Long)settings.value("deleted", 0);\r
+                       user.setDeleted(date);\r
+               }\r
+\r
+               String shard = (String)settings.value("shard", "");\r
+       settings.endGroup();\r
+       \r
+       user.setUsername(username);\r
+       user.setEmail(email);\r
+       user.setName(name);\r
+       user.setTimezone(timezone);\r
+       PrivilegeLevel userLevel = PrivilegeLevel.findByValue(privilege);\r
+       user.setPrivilege(userLevel);\r
+       user.setShardId(shard);\r
+       return user;\r
+    }\r
+    \r
     public static void saveUserAttributes(UserAttributes attrib) {\r
        settings.beginGroup("UserAttributes");\r
                settings.setValue("defaultLocationName", attrib.getDefaultLocationName());\r
@@ -336,17 +434,29 @@ public class Global {
                settings.endGroup();\r
                return limit;\r
     }\r
+\r
+    \r
+    \r
+    //****************************************************\r
+    //****************************************************\r
+    //** View settings.  Used to restore settings \r
+    //** when starting and to control how the program\r
+    //** behaves.\r
+    //****************************************************\r
+    //****************************************************\r
+    \r
+    //* Get/Set if we should show a tray icon\r
     public static boolean showTrayIcon() {\r
                settings.beginGroup("General");\r
                try {\r
-                       String max = (String) settings.value("showTrayIcon", "true");\r
+                       String max = (String) settings.value("showTrayIcon", "false");\r
                        settings.endGroup();\r
                        if (!max.equalsIgnoreCase("true"))\r
                                return false;\r
                        else\r
                                return true;    \r
                } catch (java.lang.ClassCastException e) {\r
-                       Boolean value = (Boolean) settings.value("showTrayIcon", true);\r
+                       Boolean value = (Boolean) settings.value("showTrayIcon", false);\r
                        settings.endGroup();\r
                        return value;\r
                }\r
@@ -359,6 +469,8 @@ public class Global {
                        settings.setValue("showTrayIcon", "false");\r
                settings.endGroup();\r
     }\r
+    \r
+    // Get/Set window maximized when closed last\r
     public static boolean wasWindowMaximized() {\r
        try {\r
                        settings.beginGroup("General");\r
@@ -381,6 +493,8 @@ public class Global {
                        settings.setValue("isMaximized", "false");\r
                settings.endGroup();\r
     }\r
+    \r
+    // Get/set currently viewed note Guid\r
     public static String getLastViewedNoteGuid() {\r
                settings.beginGroup("General");\r
                String guid = (String) settings.value("lastViewedNote", "");\r
@@ -395,6 +509,8 @@ public class Global {
                        settings.setValue("lastViewedNote", "");\r
                settings.endGroup();\r
     }\r
+    \r
+    // Get/Set the note column we are sorted on and the order\r
     public static void setSortColumn(int i) {\r
        int view = Global.getListView();\r
                settings.beginGroup("General");\r
@@ -460,6 +576,8 @@ public class Global {
                settings.endGroup();\r
                return order;\r
     }\r
+    \r
+    // Should we automatically log in to Evernote when starting?\r
     public static boolean automaticLogin() {\r
        try {\r
                settings.beginGroup("General");\r
@@ -483,6 +601,8 @@ public class Global {
                        settings.setValue("automaticLogin", "false");\r
                settings.endGroup();\r
     }\r
+    \r
+    // Should it save the Evernote password?\r
     public static boolean rememberPassword() {\r
        try {\r
                        settings.beginGroup("General");\r
@@ -506,6 +626,8 @@ public class Global {
                        settings.setValue("rememberPassword", "false");\r
                settings.endGroup();\r
     }\r
+\r
+    // Get/set the Evernote server Url.  \r
     public static void setServer(String server) {\r
                settings.beginGroup("General");\r
                settings.setValue("server", server);\r
@@ -528,6 +650,8 @@ public class Global {
 //                     noteStoreUrlBase = "http://" + noteStoreUrlBase;\r
                return text;\r
     }\r
+\r
+    // Get/Set if we should disable uploads to Evernote\r
     public static boolean disableUploads() {\r
        settings.beginGroup("General");\r
        try {\r
@@ -552,6 +676,8 @@ public class Global {
                settings.endGroup();\r
                disableUploads = val;\r
     }\r
\r
+    // Should we view PDF documents inline?\r
     public static boolean pdfPreview() {\r
                settings.beginGroup("General");\r
                try {\r
@@ -575,6 +701,8 @@ public class Global {
                        settings.setValue("pdfPreview", "false");\r
                settings.endGroup();\r
     }\r
+    \r
+    // When creating a new note, should it inherit tags that are currently selected?\r
     public static boolean newNoteWithSelectedTags() {\r
                settings.beginGroup("General");\r
                try {\r
@@ -598,6 +726,9 @@ public class Global {
                        settings.setValue("newNoteWithSelectedTags", "false");\r
                settings.endGroup();\r
     }\r
+    \r
+    // Minimum weight for text OCRed from Evernote. Anything below this\r
+    // Won't be shown to the user when they search\r
     public static void setRecognitionWeight(int len) {\r
                settings.beginGroup("General");\r
                settings.setValue("recognitionWeight", len);\r
@@ -614,6 +745,8 @@ public class Global {
                settings.endGroup();\r
                return len;\r
     }\r
+    \r
+    // get/set current debug message level\r
     public static String getMessageLevel() {\r
                settings.beginGroup("Debug");\r
                String text = (String)settings.value("messageLevel", "Low");\r
@@ -625,6 +758,8 @@ public class Global {
                settings.setValue("dateFormat", format);\r
                settings.endGroup();            \r
     }\r
+    \r
+    // Get/Set user date/time formats\r
     public static String getDateFormat() {\r
                settings.beginGroup("General");\r
                String text = (String)settings.value("dateFormat", "MM/dd/yyyy");\r
@@ -642,6 +777,8 @@ public class Global {
                settings.endGroup();\r
                return text;\r
     }\r
+    \r
+    // How often should we sync with Evernote?\r
     public static String getSyncInterval() {\r
                settings.beginGroup("General");\r
                String text = (String)settings.value("syncInterval", "15 minutes");\r
@@ -653,6 +790,9 @@ public class Global {
                settings.setValue("syncInterval", format);\r
                settings.endGroup();            \r
     }\r
+    \r
+    // Get/Set the width of columns and their position for the \r
+    // next start.\r
     public static void setColumnWidth(String col, int width) {\r
        if (Global.getListView() == Global.View_List_Wide)\r
                settings.beginGroup("ColumnWidths");\r
@@ -708,6 +848,8 @@ public class Global {
                settings.endGroup();\r
                return width;\r
     }\r
+    \r
+    // Ping the user when they try to delete or just do it.\r
     public static boolean verifyDelete() {\r
                settings.beginGroup("General");\r
                try {\r
@@ -731,6 +873,8 @@ public class Global {
                        settings.setValue("verifyDelete", "false");\r
                settings.endGroup();\r
     }\r
+    \r
+    // Should it start minimized?\r
     public static boolean startMinimized() {\r
                settings.beginGroup("General");\r
                try {\r
@@ -754,6 +898,8 @@ public class Global {
                        settings.setValue("startMinimized", "false");\r
                settings.endGroup();\r
     }\r
+    \r
+    // Should we upload the content of any deleted notes\r
     public static boolean synchronizeDeletedContent() {\r
                settings.beginGroup("General");\r
                try {\r
@@ -777,6 +923,9 @@ public class Global {
                        settings.setValue("syncDeletedContent", "false");\r
                settings.endGroup();\r
     }\r
+    \r
+    // Is a section of the window visible?  Used to hide things people don't\r
+    // want to see.\r
     public static boolean isWindowVisible(String window) {\r
                settings.beginGroup("WindowsVisible");\r
                try {\r
@@ -806,6 +955,8 @@ public class Global {
                        settings.setValue(window, "false");\r
                settings.endGroup();\r
     }\r
+    \r
+    // Is a list in the column in the note list visible?  \r
     public static boolean isColumnVisible(String window) {\r
        String defaultValue = "true";\r
        int view = Global.getListView();\r
@@ -848,6 +999,8 @@ public class Global {
                        settings.setValue(column, "false");\r
                settings.endGroup();\r
     }\r
+    \r
+    // Is a particular editor button visible?\r
     public static boolean isEditorButtonVisible(String window) {\r
                settings.beginGroup("EditorButtonsVisible");\r
                try {\r
@@ -871,6 +1024,8 @@ public class Global {
                        settings.setValue(column, "false");\r
                settings.endGroup();\r
     }\r
+    \r
+    // Should the test fixes be enabled\r
     public static boolean enableCarriageReturnFix() {\r
        try {\r
                settings.beginGroup("Debug");\r
@@ -894,28 +1049,54 @@ public class Global {
                        settings.setValue("enableCarriageReturnFix", "false");\r
                settings.endGroup();\r
     }\r
-    public static void setIndexThreads(int val) {\r
-               settings.beginGroup("General");\r
-               settings.setValue("indexThreads", val);\r
-               settings.endGroup();\r
-    }\r
-    public static int getIndexThreads() {\r
-               settings.beginGroup("General");\r
-               Integer threads;\r
-               try {\r
-                       String val  = (String)settings.value("indexThreads", "1");\r
-                       threads = new Integer(val.trim());\r
-               } catch (Exception e) {\r
-                       try {\r
-                               threads = (Integer)settings.value("indexThreads", 1);\r
-                       } catch (Exception e1) {\r
-                               threads = 1;\r
-                       }\r
+    public static boolean enableHtmlEntitiesFix() {\r
+       try {\r
+               settings.beginGroup("Debug");\r
+               String text = (String)settings.value("enableHtmlEntitiesFix", "false");\r
+               settings.endGroup();\r
+               if (text.equalsIgnoreCase("true"))\r
+                       return true;\r
+               else\r
+                       return false;\r
+               } catch (java.lang.ClassCastException e) {\r
+                       Boolean value = (Boolean) settings.value("enableHtmlEntitiesFix", false);\r
+                       settings.endGroup();\r
+                       return value;\r
                }\r
+    }\r
+    public static void saveHtmlEntitiesFix(boolean val) {\r
+               settings.beginGroup("Debug");\r
+               if (val)\r
+                       settings.setValue("enableHtmlEntitiesFix", "true");\r
+               else\r
+                       settings.setValue("enableHtmlEntitiesFix", "false");\r
                settings.endGroup();\r
-               threads = 1;\r
-               return threads;\r
     }\r
+\r
+//    public static void setIndexThreads(int val) {\r
+//             settings.beginGroup("General");\r
+//             settings.setValue("indexThreads", val);\r
+//             settings.endGroup();\r
+//   }\r
+//    public static int getIndexThreads() {\r
+//             settings.beginGroup("General");\r
+//             Integer threads;\r
+//             try {\r
+//                     String val  = (String)settings.value("indexThreads", "1");\r
+//                     threads = new Integer(val.trim());\r
+//             } catch (Exception e) {\r
+//                     try {\r
+//                             threads = (Integer)settings.value("indexThreads", 1);\r
+//                     } catch (Exception e1) {\r
+//                             threads = 1;\r
+//                     }\r
+//             }\r
+//             settings.endGroup();\r
+//             threads = 1;\r
+//             return threads;\r
+    \r
+    // Get/Set text zoom factor\r
+//   }\r
     public static void setZoomFactor(double val) {\r
                settings.beginGroup("General");\r
                settings.setValue("zoomFactor", val);\r
@@ -959,6 +1140,8 @@ public class Global {
                return threads;\r
     }\r
     \r
+    \r
+    // Should we mimic Evernote and restrict the notebooks selected?\r
     public static boolean getMimicEvernoteInterface() {\r
                settings.beginGroup("General");\r
                try {\r
@@ -983,6 +1166,8 @@ public class Global {
        settings.endGroup();\r
     }\r
     \r
+    \r
+    // Synchronize with Evernote when closing?\r
     public static boolean synchronizeOnClose() {\r
                settings.beginGroup("General");\r
                try {\r
@@ -1006,6 +1191,9 @@ public class Global {
                        settings.setValue("synchronizeOnClose", "false");\r
                settings.endGroup();\r
     }\r
+\r
+    // Get/set the database version.  Not really used any more, but kept\r
+    // for compatibility.\r
     public static void setDatabaseVersion(String version) {\r
                settings.beginGroup("General");\r
                settings.setValue("databaseVersion", version);\r
@@ -1017,6 +1205,8 @@ public class Global {
                settings.endGroup();\r
                return val;\r
     }\r
+\r
+    // Get the URL (full path) of the main database\r
     public static String getDatabaseUrl() {\r
                settings.beginGroup("General");\r
                String val  = (String)settings.value("DatabaseURL", "");\r
@@ -1025,17 +1215,21 @@ public class Global {
                        val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.databaseName);\r
                return val;\r
     }\r
+    \r
+    // get the url (full path) of the searchable word database\r
     public static String getIndexDatabaseUrl() {\r
                settings.beginGroup("General");\r
-               String val  = (String)settings.value("DatabaseURL", "");\r
+               String val  = (String)settings.value("IndexDatabaseURL", "");\r
                settings.endGroup();\r
                if (val.equals(""))\r
                        val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.indexDatabaseName);\r
                return val;\r
     }\r
+    \r
+    // Get the url (full path) of the attachment database\r
     public static String getResourceDatabaseUrl() {\r
                settings.beginGroup("General");\r
-               String val  = (String)settings.value("DatabaseURL", "");\r
+               String val  = (String)settings.value("ResourceDatabaseURL", "");\r
                settings.endGroup();\r
                if (val.equals(""))\r
                        val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.resourceDatabaseName);\r
@@ -1046,6 +1240,16 @@ public class Global {
                settings.setValue("DatabaseURL", value);\r
                settings.endGroup();\r
     }\r
+    public static void setIndexDatabaseUrl(String value) {\r
+               settings.beginGroup("General");\r
+               settings.setValue("IndexDatabaseURL", value);\r
+               settings.endGroup();\r
+    }\r
+    public static void setResourceDatabaseUrl(String value) {\r
+               settings.beginGroup("General");\r
+               settings.setValue("ResourceDatabaseURL", value);\r
+               settings.endGroup();\r
+    }\r
     public static String getDatabaseUserid() {\r
                settings.beginGroup("General");\r
                String val  = (String)settings.value("databaseUserid", "");\r
@@ -1058,6 +1262,8 @@ public class Global {
                settings.endGroup();\r
                return val;\r
     }\r
+    \r
+    // get/Set the style sheet and the palette to control the look & feel\r
     public static void setStyle(String style) {\r
                settings.beginGroup("General");\r
                settings.setValue("style", style);\r
@@ -1065,7 +1271,7 @@ public class Global {
     }\r
     public static String getStyle() {\r
                settings.beginGroup("General");\r
-               String val  = (String)settings.value("style", "");\r
+               String val  = (String)settings.value("style", "Cleanlooks");\r
                settings.endGroup();\r
                return val;\r
     }\r
@@ -1093,6 +1299,7 @@ public class Global {
                settings.endGroup();\r
     }\r
     \r
+    // Set the amount of time to wait between indexing\r
     // Get/Set interval when the index thread wakes up.\r
     public static void setIndexThreadSleepInterval(int sleep) {\r
                settings.beginGroup("General");\r
@@ -1116,6 +1323,8 @@ public class Global {
                return sleep;\r
     }\r
     \r
+    \r
+    // Get/Set a window state for later restoring\r
     public static void saveState(String name, QByteArray state) {\r
        int view = Global.getListView();\r
        if (view == Global.View_List_Narrow)\r
@@ -1155,6 +1364,8 @@ public class Global {
                return state;\r
     }\r
     \r
+    \r
+    // Set how often to do an automatic save\r
     public static void setAutoSaveInterval(int interval) {\r
                settings.beginGroup("General");\r
                settings.setValue("autoSaveInterval", interval);\r
@@ -1177,6 +1388,8 @@ public class Global {
                return value;\r
     }\r
      \r
+    // Add an invalid attribute & element to the database so we don't bother parsing it in the future\r
+    // These values we automatically remove from any note.\r
     // Add invalid attributes\r
     public static void addInvalidAttribute(String element, String attribute) {\r
        \r
@@ -1200,8 +1413,7 @@ public class Global {
                invalidAttributes.put(element,attributeList);\r
        }\r
     }\r
-\r
-    \r
+   \r
     // Add invalid attributes\r
     public static void addInvalidElement(String element) {\r
                for (int i=0; i<invalidElements.size(); i++) {\r
@@ -1211,6 +1423,7 @@ public class Global {
        invalidElements.add(element);\r
     }\r
     \r
+    // Get/Set proxy information\r
     // Proxy settings\r
     public static String getProxyValue(String key) {\r
                settings.beginGroup("Proxy");\r
@@ -1224,7 +1437,7 @@ public class Global {
                settings.endGroup();\r
     }\r
     \r
-    \r
+    // Change a byte array to a hex string\r
     // Convert a byte array to a hex string\r
        public static String byteArrayToHexString(byte data[]) {\r
                StringBuffer buf = new StringBuffer();\r
@@ -1242,7 +1455,9 @@ public class Global {
            return buf.toString();              \r
        }\r
 \r
-    public static boolean getSpellSetting(String value) {\r
+    \r
+       // Get/Set spelling settings\r
+       public static boolean getSpellSetting(String value) {\r
                settings.beginGroup("Spell");\r
                String text = (String)settings.value(value, "");\r
                settings.endGroup();\r
@@ -1269,7 +1484,7 @@ public class Global {
                settings.endGroup();\r
     }\r
        \r
-       \r
+       // Get/Set how we should display tags (color them, hide unused, or do nothing)\r
        // What to do with inactive tags?\r
        public static String tagBehavior() {\r
                settings.beginGroup("General");\r
@@ -1284,7 +1499,9 @@ public class Global {
                settings.endGroup();\r
        }\r
 \r
-    public static boolean isToolbarButtonVisible(String window) {\r
+    \r
+       // Should the toolbar be visible?\r
+       public static boolean isToolbarButtonVisible(String window) {\r
                settings.beginGroup("ToolbarButtonsVisible");\r
                try {\r
                        String text = (String)settings.value(window, "true");\r
@@ -1308,6 +1525,7 @@ public class Global {
                settings.endGroup();\r
     }\r
        \r
+    // Are thumbnails enabled?\r
     \r
     public static boolean enableThumbnails() {\r
                settings.beginGroup("Debug");\r
@@ -1333,6 +1551,7 @@ public class Global {
                settings.endGroup();\r
     }\r
        \r
+    // Trace used for performance tuning.  Not normally used in production.\r
        // Print date/time.  Used mainly for performance tracing\r
        public static void trace(boolean resetInterval) {\r
                String fmt = "MM/dd/yy HH:mm:ss.SSSSSS";\r
@@ -1366,9 +1585,13 @@ public class Global {
                startTraceTime = null;\r
        }\r
 \r
-    public static FileManager getFileManager() {\r
+    \r
+       // Get the FileManager class to manage local files & directories\r
+       public static FileManager getFileManager() {\r
         return fileManager;\r
     }\r
+       \r
+       // Should the note editor be disabled?\r
     public static boolean getDisableViewing() {\r
         return disableViewing;\r
     }\r
@@ -1443,6 +1666,10 @@ public class Global {
                }\r
 \r
     }\r
+    \r
+    //****************************************************\r
+    // Get/Set the default font settings for a new note\r
+    //****************************************************\r
     public static void setOverrideDefaultFont(boolean value) {\r
                settings.beginGroup("Font");\r
                settings.setValue("overrideFont", value);\r
@@ -1472,9 +1699,9 @@ public class Global {
     }\r
     \r
     \r
-    //*******************\r
-    // Close/Minimize\r
-    //*******************\r
+    //*******************************************\r
+    // Override the close & minimize instead.\r
+    //*******************************************\r
     public static boolean minimizeOnClose() {\r
                settings.beginGroup("General");\r
                try {\r
@@ -1496,9 +1723,9 @@ public class Global {
                settings.endGroup();    \r
     }\r
 \r
-    //*******************\r
+    //*********************************\r
     // Check version information\r
-    //*******************\r
+    //*********************************\r
     public static boolean checkVersionUpgrade() {\r
                settings.beginGroup("Upgrade");\r
                try {\r
@@ -1533,10 +1760,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
@@ -1550,12 +1820,94 @@ 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
+    // 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
+    public static boolean anyTagSelectionMatch() {\r
+               settings.beginGroup("General");\r
+               try {\r
+                       String value = (String)settings.value("anyTagSelectionMatch", "false");\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("anyTagSelectionMatch", false);\r
+                       settings.endGroup();\r
+                       return value;\r
+               }\r
+    }\r
+    public static void setAnyTagSelectionMatch(boolean value) {\r
+               settings.beginGroup("General");\r
+               settings.setValue("anyTagSelectionMatch", value);\r
+               settings.endGroup();    \r
+    }\r
+\r
+    //*****************************************************************************\r
+    // Control how tag selection behaves (should they be "and" or "or" selections\r
+    //*****************************************************************************\r
+    public static boolean bypassSynchronizationWarning() {\r
+               settings.beginGroup("User");\r
+               try {\r
+                       String value = (String)settings.value("bypassSynchronizationWarning", "false");\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("bypassSynchronizationWarning", false);\r
+                       settings.endGroup();\r
+                       return value;\r
+               }\r
+    }\r
+    public static void setBypassSynchronizationWarning(boolean value) {\r
+               settings.beginGroup("User");\r
+               settings.setValue("bypassSynchronizationWarning", value);\r
+               settings.endGroup();    \r
+    }\r
 \r
+    \r
     //***********************\r
     //* Database cache size\r
     //***********************\r
@@ -1569,10 +1921,11 @@ public class Global {
                settings.beginGroup("Debug");\r
                settings.setValue("databaseCache", value);\r
                settings.endGroup();    \r
+               databaseCache = value;\r
     }\r
 \r
     \r
-    \r
+    // This is used to copy a class since Java's normal deep copy is wacked\r
     public static Object deepCopy(Object oldObj) \r
     {\r
        ObjectOutputStream oos = null;\r
@@ -1606,5 +1959,6 @@ public class Global {
                return null;\r
     }\r
 \r
+\r
 }\r
 \r