X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=src%2Fcx%2Ffbn%2Fnevernote%2FGlobal.java;h=b0da172fcf1c4330921042a2a09a3043b68ee9bb;hb=d3224704f464d7b6bc601565d276184ee8e722bc;hp=8a082dceaf57a08e6215de9ef43f890d172097ff;hpb=158b1b9035ff634198bfd5b6271758b96b9fa430;p=neighbornote%2FNeighborNote.git diff --git a/src/cx/fbn/nevernote/Global.java b/src/cx/fbn/nevernote/Global.java index 8a082dc..b0da172 100644 --- a/src/cx/fbn/nevernote/Global.java +++ b/src/cx/fbn/nevernote/Global.java @@ -20,21 +20,27 @@ package cx.fbn.nevernote; -//import java.io.ByteArrayOutputStream; - -import java.io.PrintStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; +import org.apache.commons.lang.StringEscapeUtils; + import com.evernote.edam.type.Accounting; import com.evernote.edam.type.PrivilegeLevel; import com.evernote.edam.type.User; import com.evernote.edam.type.UserAttributes; +import com.swabunga.spell.engine.Configuration; import com.trolltech.qt.core.QByteArray; import com.trolltech.qt.core.QSettings; +import com.trolltech.qt.core.QSize; import com.trolltech.qt.gui.QPalette; import cx.fbn.nevernote.config.FileManager; @@ -44,47 +50,71 @@ import cx.fbn.nevernote.gui.ContainsAttributeFilterTable; import cx.fbn.nevernote.gui.DateAttributeFilterTable; import cx.fbn.nevernote.gui.ShortcutKeys; import cx.fbn.nevernote.utilities.ApplicationLogger; +import cx.fbn.nevernote.utilities.Pair; + + +//***************************************************** +//***************************************************** +//* Global constants & static functions used by +//* multiple threads. +//***************************************************** +//***************************************************** public class Global { - public static String version = "0.90"; + // Set current version and the known versions. + public static String version = "0.99"; + public static String[] validVersions = {"0.99", "0.98", "0.97", "0.96"}; public static String username = ""; public static String password = ""; + // Each thread has an ID. This is used primarily to check the status + // of running threads. public static final int mainThreadId=0; - public static final int syncThreadId=1; - public static final int tagCounterThreadId=2; - public static final int trashCounterThreadId=3; // This should always be the highest thread ID - public static final int indexThreadId=4; // Thread for indexing words - public static final int saveThreadId=5; // Thread used for processing data to saving content - public static final int notebookCounterThreadId=6; // Notebook Thread - public static final int indexThread03Id=7; // unused - public static final int indexThread04Id=8; // unused - public static final int dbThreadId=9; // This should always be the highest thread ID + public static final int threadCount = 10; + + + // These variables deal with where the list of notes appears + // They will either be vertical (View_List_Narrow) or will be + // on top of the note (View_List_Wide). It also has the size of + // thumbnails displayed in each view + public static int View_List_Wide = 1; + public static int View_List_Narrow = 2; + public static QSize smallThumbnailSize = new QSize(100,75); + public static QSize largeThumbnailSize = new QSize(300,225); + + // This is used to keep a running list of passwords that the user + // wants us to remember. + public static HashMap> passwordSafe = new HashMap>(); + public static List> passwordRemember = new ArrayList>(); - public static HashMap passwordSafe = new HashMap(); - public static List passwordRemember = new ArrayList(); - public static String currentNotebookGuid; + //public static String currentNotebookGuid; + + // These deal with Evernote user settings public static User user; public static long authTimeRemaining; public static long authRefreshTime; - public static long failedRefreshes = 0; - public static boolean keepRunning; - + public static long failedRefreshes = 0; public static String userStoreUrl; public static String noteStoreUrl; public static String noteStoreUrlBase; - + + // When we want to shut down we set this to true to short + // circut other threads + public static boolean keepRunning; + + // In the note list, these are the column numbers + // so I don't need to hard code numbers. public static int noteTableCreationPosition = 0; public static int noteTableTitlePosition = 1; public static int noteTableTagPosition = 2; @@ -95,44 +125,65 @@ public class Global { public static int noteTableSourceUrlPosition = 7; public static int noteTableSubjectDatePosition = 8; public static int noteTableSynchronizedPosition = 9; - public static int noteTableColumnCount = 10; + public static int noteTableThumbnailPosition = 10; + public static int noteTableColumnCount = 11; public static Integer cryptCounter = 0; - public static int minimumWordCount = 2; + //public static int minimumWordCount = 2; + + // Regular expression to parse text with when indexing private static String wordRegex; + + // Experimental fixes. Set via Edit/Preferences/Debugging public static boolean enableCarriageReturnFix = false; + public static boolean enableHTMLEntitiesFix = false; - public static String name = null; - public static QSettings settings; - public static boolean isConnected; - public static boolean showDeleted = false; - public static boolean disableUploads = false; - public static int messageLevel; - public static String tagDelimeter = ","; - public static String attachmentNameDelimeter = "------"; + //public static String name = null; + + // Used to set & retrieve ini & Windows registry settings + public static QSettings settings; // Set & get ini settings + public static boolean isConnected; // Are we connected to Evernote + public static boolean showDeleted = false; // Show deleted notes? + public static boolean disableUploads = false; // Should we disable uploads (used in testing features) + public static int messageLevel; // The level of messages to write to the log files + public static String tagDelimeter = ","; // This is used to separate out tag names when entering above note + public static String attachmentNameDelimeter = "------"; // Used to separate out attachment names in the res directory + - public static String databaseName = new String("NeverNote"); + //* Database fields + public static String databaseName = new String("NeverNote"); // database name. used for multiple databases to separate settings. + public static String indexDatabaseName = new String("Index"); // searchable words database + public static String resourceDatabaseName = new String("Resources"); // attachments database public static DateAttributeFilterTable createdSinceFilter; public static DateAttributeFilterTable createdBeforeFilter; public static DateAttributeFilterTable changedSinceFilter; public static DateAttributeFilterTable changedBeforeFilter; public static ContainsAttributeFilterTable containsFilter; + + // Log file used for debugging public static ApplicationLogger logger; - PrintStream stdoutStream; + //PrintStream stdoutStream; + + // Application key shortcuts & appearance public static QPalette originalPalette; public static ShortcutKeys shortcutKeys; - public static boolean disableViewing; + public static boolean disableViewing; // used to disable the editor + + // When saving a note, this is a list of things we strip out because Evernote hates them public static List invalidElements = new ArrayList(); public static HashMap> invalidAttributes = new HashMap>(); - public static boolean mimicEvernoteInterface; - public static HashMap resourceMap; - public static String cipherPassword = ""; - static Calendar startTraceTime; + public static boolean mimicEvernoteInterface; // Try to mimic Evernote or allow multiple notebook selection + public static HashMap resourceMap; // List of attachments for a note. + public static String cipherPassword = ""; // If the database is encrypted, this stores the password + public static String databaseCache = "16384"; // Default DB cache size + + // These are used for performance testing + static Calendar startTraceTime; static Calendar intervalTraceTime; - - private static FileManager fileManager; + + private static FileManager fileManager; // Used to access files & directories // Do initial setup public static void setup(StartupConfig startupConfig) throws InitializationException { @@ -142,36 +193,45 @@ public class Global { fileManager = new FileManager(startupConfig.getHomeDirPath(), startupConfig.getProgramDirPath()); - getServer(); - settings.beginGroup("General"); - String regex = (String) settings.value("regex", "[,\\s]+"); - setWordRegex(regex); - String wordString = settings.value("minimumWordLength", "4").toString(); - Integer wordLen = new Integer(wordString); - Global.minimumWordCount = wordLen; - settings.endGroup(); - settings.beginGroup("Debug"); - String msglevel = (String) settings.value("messageLevel", "Low"); - settings.endGroup(); - messageLevel = 1; - setMessageLevel(msglevel); - keepRunning = true; - disableUploads = disableUploads(); - enableCarriageReturnFix = enableCarriageReturnFix(); - logger = new ApplicationLogger("global.log"); - shortcutKeys = new ShortcutKeys(); - mimicEvernoteInterface = getMimicEvernoteInterface(); - resourceMap = new HashMap(); - + getServer(); // Setup URL to connect to + + // Get regular expressions used to parse out words + settings.beginGroup("General"); + String regex = (String) settings.value("regex", "[,\\s]+"); + setWordRegex(regex); + settings.endGroup(); + + // Setup debugging information + //settings.beginGroup("Debug"); + //String msglevel = (String) settings.value("messageLevel", "Low"); + //settings.endGroup(); + + + //messageLevel = 1; + //setMessageLevel(msglevel); + keepRunning = true; // Make sure child threads stay running + disableUploads = disableUploads(); // Should we upload anything? Normally true. + enableCarriageReturnFix = enableCarriageReturnFix(); // Enable test fix? + enableHTMLEntitiesFix = enableHtmlEntitiesFix(); // Enable test fix? + + logger = new ApplicationLogger("global.log"); // Setup log for this class + shortcutKeys = new ShortcutKeys(); // Setup keyboard shortcuts. + mimicEvernoteInterface = getMimicEvernoteInterface(); // Should we mimic Evernote's notebook behavior + resourceMap = new HashMap(); // Setup resource map used to store attachments when editing + + databaseCache = getDatabaseCacheSize(); // Set database cache size } + // Get/Set word parsing regular expression public static String getWordRegex() { return wordRegex; } public static void setWordRegex(String r) { wordRegex = r; } - public static void setMessageLevel(String msglevel) { + + // Set the debug message level + public static void setMessageLevel(String msglevel) { if (msglevel.equalsIgnoreCase("low")) messageLevel = 1; if (msglevel.equalsIgnoreCase("medium")) @@ -185,6 +245,11 @@ public class Global { settings.endGroup(); } + //**************************************************** + //**************************************************** + //** Save user account information from Evernote + //**************************************************** + //**************************************************** public static void saveUserInformation(User user) { settings.beginGroup("User"); settings.setValue("id", user.getId()); @@ -196,6 +261,7 @@ public class Global { settings.setValue("created", user.getCreated()); settings.setValue("updated", user.getUpdated()); settings.setValue("deleted", user.getDeleted()); + settings.setValue("shard", user.getShardId()); settings.endGroup(); isPremium(); if (user.getAttributes()!=null) @@ -204,6 +270,54 @@ public class Global { saveUserAccounting(user.getAccounting()); } + public static User getUserInformation() { + User user = new User(); + settings.beginGroup("User"); + try { + user.setId((Integer)settings.value("id", 0)); + } catch (java.lang.ClassCastException e) { + user.setId(new Integer((String)settings.value("id", "0"))); + } + String username = (String)settings.value("username", ""); + String email = (String)settings.value("email", ""); + String name = (String)settings.value("name", ""); + String timezone = (String)settings.value("timezone", ""); + Integer privilege = 0; + try { + privilege = new Integer((String)settings.value("privilege", "0")); + } catch (java.lang.ClassCastException e) { + privilege = (Integer)settings.value("privilege", 0); + } + + try { + String date = (String)settings.value("created", "0"); + user.setCreated(new Long(date)); + date = (String)settings.value("updated", "0"); + user.setUpdated(new Long(date)); + date = (String)settings.value("deleted", "0"); + user.setDeleted(new Long(date)); + } catch (java.lang.ClassCastException e) { + Long date = (Long)settings.value("created", 0); + user.setCreated(date); + date = (Long)settings.value("updated", 0); + user.setUpdated(date); + date = (Long)settings.value("deleted", 0); + user.setDeleted(date); + } + + String shard = (String)settings.value("shard", ""); + settings.endGroup(); + + user.setUsername(username); + user.setEmail(email); + user.setName(name); + user.setTimezone(timezone); + PrivilegeLevel userLevel = PrivilegeLevel.findByValue(privilege); + user.setPrivilege(userLevel); + user.setShardId(shard); + return user; + } + public static void saveUserAttributes(UserAttributes attrib) { settings.beginGroup("UserAttributes"); settings.setValue("defaultLocationName", attrib.getDefaultLocationName()); @@ -322,13 +436,32 @@ public class Global { settings.endGroup(); return limit; } + + + + //**************************************************** + //**************************************************** + //** View settings. Used to restore settings + //** when starting and to control how the program + //** behaves. + //**************************************************** + //**************************************************** + + //* Get/Set if we should show a tray icon public static boolean showTrayIcon() { settings.beginGroup("General"); - String max = (String) settings.value("showTrayIcon", "true"); - settings.endGroup(); - if (!max.equalsIgnoreCase("true")) - return false; - return true; + try { + String max = (String) settings.value("showTrayIcon", "false"); + settings.endGroup(); + if (!max.equalsIgnoreCase("true")) + return false; + else + return true; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("showTrayIcon", false); + settings.endGroup(); + return value; + } } public static void setShowTrayIcon(boolean val) { settings.beginGroup("General"); @@ -338,13 +471,21 @@ public class Global { settings.setValue("showTrayIcon", "false"); settings.endGroup(); } + + // Get/Set window maximized when closed last public static boolean wasWindowMaximized() { - settings.beginGroup("General"); - String max = (String) settings.value("isMaximized", "true"); - settings.endGroup(); - if (!max.equalsIgnoreCase("true")) - return false; - return true; + try { + settings.beginGroup("General"); + String max = (String) settings.value("isMaximized", "true"); + settings.endGroup(); + if (!max.equalsIgnoreCase("true")) + return false; + return true; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("isMaximized", true); + settings.endGroup(); + return value; + } } public static void saveWindowMaximized(boolean isMax) { settings.beginGroup("General"); @@ -354,6 +495,8 @@ public class Global { settings.setValue("isMaximized", "false"); settings.endGroup(); } + + // Get/set currently viewed note Guid public static String getLastViewedNoteGuid() { settings.beginGroup("General"); String guid = (String) settings.value("lastViewedNote", ""); @@ -368,20 +511,32 @@ public class Global { settings.setValue("lastViewedNote", ""); settings.endGroup(); } + + // Get/Set the note column we are sorted on and the order public static void setSortColumn(int i) { + int view = Global.getListView(); settings.beginGroup("General"); - settings.setValue("sortColumn", i); + if (view == Global.View_List_Wide) + settings.setValue("sortColumn", i); + else + settings.setValue("sortColumn-Narrow", i); settings.endGroup(); } public static int getSortColumn() {; + String key; + if (Global.getListView() == Global.View_List_Wide) + key = "sortColumn"; + else + key = "sortColumn-Narrow"; + settings.beginGroup("General"); int order; try { - String val = settings.value("sortColumn", new Integer(0)).toString(); + String val = settings.value(key, new Integer(0)).toString(); order = new Integer(val.trim()); } catch (Exception e) { try { - order = (Integer)settings.value("sortColumn", 0); + order = (Integer)settings.value(key, 0); } catch (Exception e1) { order = 0; } @@ -391,19 +546,30 @@ public class Global { return order; } public static void setSortOrder(int i) { + int view = Global.getListView(); settings.beginGroup("General"); - settings.setValue("sortOrder", i); + if (view == Global.View_List_Wide) + settings.setValue("sortOrder", i); + else + settings.setValue("sortOrder-Narrow", i); settings.endGroup(); } public static int getSortOrder() { + int view = Global.getListView(); settings.beginGroup("General"); + String key; + if (view == Global.View_List_Wide) + key = "sortOrder"; + else + key = "sortOrder-Narrow"; + int order; try { - String val = settings.value("sortOrder", new Integer(0)).toString(); + String val = settings.value(key, new Integer(0)).toString(); order = new Integer(val.trim()); } catch (Exception e) { try { - order = (Integer)settings.value("sortOrder", 0); + order = (Integer)settings.value(key, 0); } catch (Exception e1) { order = 0; } @@ -412,14 +578,22 @@ public class Global { settings.endGroup(); return order; } + + // Should we automatically log in to Evernote when starting? public static boolean automaticLogin() { - settings.beginGroup("General"); - String text = (String)settings.value("automaticLogin", "false"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; - else - return false; + try { + settings.beginGroup("General"); + String text = (String)settings.value("automaticLogin", "false"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("automaticLogin", false); + settings.endGroup(); + return value; + } } public static void setAutomaticLogin(boolean val) { settings.beginGroup("General"); @@ -429,14 +603,22 @@ public class Global { settings.setValue("automaticLogin", "false"); settings.endGroup(); } + + // Should it save the Evernote password? public static boolean rememberPassword() { - settings.beginGroup("General"); - String text = (String)settings.value("rememberPassword", "false"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; - else - return false; + try { + settings.beginGroup("General"); + String text = (String)settings.value("rememberPassword", "false"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("rememberPassword", false); + settings.endGroup(); + return value; + } } public static void setRememberPassword(boolean val) { settings.beginGroup("General"); @@ -446,6 +628,8 @@ public class Global { settings.setValue("rememberPassword", "false"); settings.endGroup(); } + + // Get/set the Evernote server Url. public static void setServer(String server) { settings.beginGroup("General"); settings.setValue("server", server); @@ -462,20 +646,28 @@ public class Global { noteStoreUrlBase = "sandbox.evernote.com/edam/note/"; } settings.endGroup(); - if (isPremium()) +// if (isPremium()) noteStoreUrlBase = "https://" + noteStoreUrlBase; - else - noteStoreUrlBase = "http://" + noteStoreUrlBase; +// else +// noteStoreUrlBase = "http://" + noteStoreUrlBase; return text; } + + // Get/Set if we should disable uploads to Evernote public static boolean disableUploads() { - settings.beginGroup("General"); - String text = (String)settings.value("disableUploads", "false"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; - else - return false; + settings.beginGroup("General"); + try { + String text = (String)settings.value("disableUploads", "false"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("disableUploads", false); + settings.endGroup(); + return value; + } } public static void setDisableUploads(boolean val) { settings.beginGroup("General"); @@ -486,14 +678,22 @@ public class Global { settings.endGroup(); disableUploads = val; } + + // Should we view PDF documents inline? public static boolean pdfPreview() { settings.beginGroup("General"); - String text = (String)settings.value("pdfPreview", "true"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; - else - return false; + try { + String text = (String)settings.value("pdfPreview", "true"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("pdfPreview", true); + settings.endGroup(); + return value; + } } public static void setPdfPreview(boolean val) { settings.beginGroup("General"); @@ -503,14 +703,22 @@ public class Global { settings.setValue("pdfPreview", "false"); settings.endGroup(); } + + // When creating a new note, should it inherit tags that are currently selected? public static boolean newNoteWithSelectedTags() { settings.beginGroup("General"); - String text = (String)settings.value("newNoteWithSelectedTags", "false"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; - else - return false; + try { + String text = (String)settings.value("newNoteWithSelectedTags", "false"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("newNoteWithSelectedTags", false); + settings.endGroup(); + return value; + } } public static void setNewNoteWithSelectedTags(boolean val) { settings.beginGroup("General"); @@ -520,28 +728,9 @@ public class Global { settings.setValue("newNoteWithSelectedTags", "false"); settings.endGroup(); } - public static void setMinimumWordLength(int len) { - settings.beginGroup("General"); - settings.setValue("minimumWordLength", len); - settings.endGroup(); - } - public static int getMinimumWordLength() { - settings.beginGroup("General"); - Integer len = 4; - try { - String val = (String)settings.value("minimumWordLength", "4"); - len = new Integer(val); - } catch (Exception e) { - try { - len = (Integer)settings.value("minimumWordLength", 4); - } catch (Exception e1) { - len = 4; - } - } - settings.endGroup(); - return len; - - } + + // Minimum weight for text OCRed from Evernote. Anything below this + // Won't be shown to the user when they search public static void setRecognitionWeight(int len) { settings.beginGroup("General"); settings.setValue("recognitionWeight", len); @@ -551,13 +740,15 @@ public class Global { settings.beginGroup("General"); Integer len; try { - len = (Integer)settings.value("recognitionWeight", 80); + len = (Integer)settings.value("recognitionWeight", 30); } catch (Exception e) { len = 80; } settings.endGroup(); return len; } + + // get/set current debug message level public static String getMessageLevel() { settings.beginGroup("Debug"); String text = (String)settings.value("messageLevel", "Low"); @@ -569,6 +760,8 @@ public class Global { settings.setValue("dateFormat", format); settings.endGroup(); } + + // Get/Set user date/time formats public static String getDateFormat() { settings.beginGroup("General"); String text = (String)settings.value("dateFormat", "MM/dd/yyyy"); @@ -586,6 +779,8 @@ public class Global { settings.endGroup(); return text; } + + // How often should we sync with Evernote? public static String getSyncInterval() { settings.beginGroup("General"); String text = (String)settings.value("syncInterval", "15 minutes"); @@ -597,13 +792,23 @@ public class Global { settings.setValue("syncInterval", format); settings.endGroup(); } + + // Get/Set the width of columns and their position for the + // next start. public static void setColumnWidth(String col, int width) { - settings.beginGroup("ColumnWidths"); - settings.setValue(col, width); - settings.endGroup(); - } + if (Global.getListView() == Global.View_List_Wide) + settings.beginGroup("ColumnWidths"); + else + settings.beginGroup("ColumnWidths-Narrow"); + settings.setValue(col, width); + settings.endGroup(); + } public static int getColumnWidth(String col) { - settings.beginGroup("ColumnWidths"); + int view = Global.getListView(); + if (view == Global.View_List_Wide) + settings.beginGroup("ColumnWidths"); + else + settings.beginGroup("ColumnWidths-Narrow"); Integer width; try { String val = (String)settings.value(col, "0"); @@ -619,12 +824,18 @@ public class Global { return width; } public static void setColumnPosition(String col, int width) { - settings.beginGroup("ColumnPosition"); + if (Global.getListView() == Global.View_List_Wide) + settings.beginGroup("ColumnPosition"); + else + settings.beginGroup("ColumnPosition-Narrow"); settings.setValue(col, width); settings.endGroup(); } public static int getColumnPosition(String col) { - settings.beginGroup("ColumnPosition"); + if (Global.getListView() == Global.View_List_Wide) + settings.beginGroup("ColumnPosition"); + else + settings.beginGroup("ColumnPosition-Narrow"); Integer width; try { String val = (String)settings.value(col, "-1"); @@ -639,14 +850,22 @@ public class Global { settings.endGroup(); return width; } + + // Ping the user when they try to delete or just do it. public static boolean verifyDelete() { settings.beginGroup("General"); - String text = (String)settings.value("verifyDelete", "true"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; - else - return false; + try { + String text = (String)settings.value("verifyDelete", "true"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("verifyDelete", true); + settings.endGroup(); + return value; + } } public static void setVerifyDelete(boolean val) { settings.beginGroup("General"); @@ -656,15 +875,48 @@ public class Global { settings.setValue("verifyDelete", "false"); settings.endGroup(); } - public static boolean synchronizeDeletedContent() { + + // Should it start minimized? + public static boolean startMinimized() { settings.beginGroup("General"); - String text = (String)settings.value("syncDeletedContent", "false"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; + try { + String text = (String)settings.value("startMinimized", "false"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("startMinimized", false); + settings.endGroup(); + return value; + } + } + public static void setStartMinimized(boolean val) { + settings.beginGroup("General"); + if (val) + settings.setValue("startMinimized", "true"); else - return false; + settings.setValue("startMinimized", "false"); + settings.endGroup(); } + + // Should we upload the content of any deleted notes + public static boolean synchronizeDeletedContent() { + settings.beginGroup("General"); + try { + String text = (String)settings.value("syncDeletedContent", "false"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("syncDeletedContent", false); + settings.endGroup(); + return value; + } + } public static void setSynchronizeDeletedContent(boolean val) { settings.beginGroup("General"); if (val) @@ -673,14 +925,29 @@ public class Global { settings.setValue("syncDeletedContent", "false"); settings.endGroup(); } + + // Is a section of the window visible? Used to hide things people don't + // want to see. public static boolean isWindowVisible(String window) { settings.beginGroup("WindowsVisible"); - String text = (String)settings.value(window, "true"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; + try { + String defaultValue = "true"; + if (window.equalsIgnoreCase("noteInformation")) + defaultValue = "false"; + String text = (String)settings.value(window, defaultValue); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; else return false; + } catch (java.lang.ClassCastException e) { + boolean defaultValue = true; + if (window.equalsIgnoreCase("noteInformation")) + defaultValue = false; + Boolean value = (Boolean) settings.value("showTrayIcon", defaultValue); + settings.endGroup(); + return value; + } } public static void saveWindowVisible(String window, boolean val) { settings.beginGroup("WindowsVisible"); @@ -690,31 +957,66 @@ public class Global { settings.setValue(window, "false"); settings.endGroup(); } + + // Is a list in the column in the note list visible? public static boolean isColumnVisible(String window) { - settings.beginGroup("ColumnsVisible"); - String text = (String)settings.value(window, "true"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; - else - return false; + String defaultValue = "true"; + int view = Global.getListView(); + if (Global.getListView() == Global.View_List_Wide) + settings.beginGroup("ColumnsVisible"); + else + settings.beginGroup("ColumnsVisible-Narrow"); + if (window.equalsIgnoreCase("thumbnail") && view == Global.View_List_Wide) + defaultValue = "false"; + if (window.equalsIgnoreCase("thumbnail")) + defaultValue = "false"; + if (window.equalsIgnoreCase("Guid")) + defaultValue = "false"; + try { + String text = (String)settings.value(window, defaultValue); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + boolean defBool = false; + if (window.equalsIgnoreCase("true")) + defBool = true; + else + defBool = false; + Boolean value = (Boolean) settings.value(window, defBool); + settings.endGroup(); + return value; + } } public static void saveColumnVisible(String column, boolean val) { - settings.beginGroup("ColumnsVisible"); + if (Global.getListView() == Global.View_List_Wide) + settings.beginGroup("ColumnsVisible"); + else + settings.beginGroup("ColumnsVisible-Narrow"); if (val) settings.setValue(column, "true"); else settings.setValue(column, "false"); settings.endGroup(); } + + // Is a particular editor button visible? public static boolean isEditorButtonVisible(String window) { settings.beginGroup("EditorButtonsVisible"); - String text = (String)settings.value(window, "true"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; - else - return false; + try { + String text = (String)settings.value(window, "true"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value(window, true); + settings.endGroup(); + return value; + } } public static void saveEditorButtonsVisible(String column, boolean val) { settings.beginGroup("EditorButtonsVisible"); @@ -724,14 +1026,22 @@ public class Global { settings.setValue(column, "false"); settings.endGroup(); } + + // Should the test fixes be enabled public static boolean enableCarriageReturnFix() { - settings.beginGroup("Debug"); - String text = (String)settings.value("enableCarriageReturnFix", "false"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; - else - return false; + try { + settings.beginGroup("Debug"); + String text = (String)settings.value("enableCarriageReturnFix", "false"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("enableCarriageReturnFix", false); + settings.endGroup(); + return value; + } } public static void saveCarriageReturnFix(boolean val) { settings.beginGroup("Debug"); @@ -741,28 +1051,54 @@ public class Global { settings.setValue("enableCarriageReturnFix", "false"); settings.endGroup(); } - public static void setIndexThreads(int val) { - settings.beginGroup("General"); - settings.setValue("indexThreads", val); - settings.endGroup(); - } - public static int getIndexThreads() { - settings.beginGroup("General"); - Integer threads; - try { - String val = (String)settings.value("indexThreads", "1"); - threads = new Integer(val.trim()); - } catch (Exception e) { - try { - threads = (Integer)settings.value("indexThreads", 1); - } catch (Exception e1) { - threads = 1; - } + public static boolean enableHtmlEntitiesFix() { + try { + settings.beginGroup("Debug"); + String text = (String)settings.value("enableHtmlEntitiesFix", "false"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("enableHtmlEntitiesFix", false); + settings.endGroup(); + return value; } + } + public static void saveHtmlEntitiesFix(boolean val) { + settings.beginGroup("Debug"); + if (val) + settings.setValue("enableHtmlEntitiesFix", "true"); + else + settings.setValue("enableHtmlEntitiesFix", "false"); settings.endGroup(); - threads = 1; - return threads; } + +// public static void setIndexThreads(int val) { +// settings.beginGroup("General"); +// settings.setValue("indexThreads", val); +// settings.endGroup(); +// } +// public static int getIndexThreads() { +// settings.beginGroup("General"); +// Integer threads; +// try { +// String val = (String)settings.value("indexThreads", "1"); +// threads = new Integer(val.trim()); +// } catch (Exception e) { +// try { +// threads = (Integer)settings.value("indexThreads", 1); +// } catch (Exception e1) { +// threads = 1; +// } +// } +// settings.endGroup(); +// threads = 1; +// return threads; + + // Get/Set text zoom factor +// } public static void setZoomFactor(double val) { settings.beginGroup("General"); settings.setValue("zoomFactor", val); @@ -805,15 +1141,23 @@ public class Global { settings.endGroup(); return threads; } - + + + // Should we mimic Evernote and restrict the notebooks selected? public static boolean getMimicEvernoteInterface() { settings.beginGroup("General"); - String text = (String)settings.value("mimicEvernoteInterface", "true"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; - else - return false; + try { + String text = (String)settings.value("mimicEvernoteInterface", "true"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("mimicEvernoteInterface", true); + settings.endGroup(); + return value; + } } public static void setMimicEvernoteInterface(boolean value) { settings.beginGroup("General"); @@ -824,14 +1168,22 @@ public class Global { settings.endGroup(); } + + // Synchronize with Evernote when closing? public static boolean synchronizeOnClose() { settings.beginGroup("General"); - String text = (String)settings.value("synchronizeOnClose", "false"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; - else - return false; + try { + String text = (String)settings.value("synchronizeOnClose", "false"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("synchronizeOnClose", false); + settings.endGroup(); + return value; + } } public static void setSynchronizeOnClose(boolean val) { settings.beginGroup("General"); @@ -841,6 +1193,9 @@ public class Global { settings.setValue("synchronizeOnClose", "false"); settings.endGroup(); } + + // Get/set the database version. Not really used any more, but kept + // for compatibility. public static void setDatabaseVersion(String version) { settings.beginGroup("General"); settings.setValue("databaseVersion", version); @@ -852,6 +1207,8 @@ public class Global { settings.endGroup(); return val; } + + // Get the URL (full path) of the main database public static String getDatabaseUrl() { settings.beginGroup("General"); String val = (String)settings.value("DatabaseURL", ""); @@ -860,6 +1217,26 @@ public class Global { val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.databaseName); return val; } + + // get the url (full path) of the searchable word database + public static String getIndexDatabaseUrl() { + settings.beginGroup("General"); + String val = (String)settings.value("DatabaseURL", ""); + settings.endGroup(); + if (val.equals("")) + val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.indexDatabaseName); + return val; + } + + // Get the url (full path) of the attachment database + public static String getResourceDatabaseUrl() { + settings.beginGroup("General"); + String val = (String)settings.value("DatabaseURL", ""); + settings.endGroup(); + if (val.equals("")) + val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.resourceDatabaseName); + return val; + } public static void setDatabaseUrl(String value) { settings.beginGroup("General"); settings.setValue("DatabaseURL", value); @@ -877,6 +1254,8 @@ public class Global { settings.endGroup(); return val; } + + // get/Set the style sheet and the palette to control the look & feel public static void setStyle(String style) { settings.beginGroup("General"); settings.setValue("style", style); @@ -884,18 +1263,24 @@ public class Global { } public static String getStyle() { settings.beginGroup("General"); - String val = (String)settings.value("style", ""); + String val = (String)settings.value("style", "Cleanlooks"); settings.endGroup(); return val; } public static boolean useStandardPalette() { settings.beginGroup("General"); - String text = (String)settings.value("standardPalette", "true"); - settings.endGroup(); - if (text.equalsIgnoreCase("true")) - return true; - else - return false; + try { + String text = (String)settings.value("standardPalette", "true"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("standardPalette", true); + settings.endGroup(); + return value; + } } public static void setStandardPalette(boolean val) { settings.beginGroup("General"); @@ -906,6 +1291,7 @@ public class Global { settings.endGroup(); } + // Set the amount of time to wait between indexing // Get/Set interval when the index thread wakes up. public static void setIndexThreadSleepInterval(int sleep) { settings.beginGroup("General"); @@ -929,31 +1315,49 @@ public class Global { return sleep; } + + // Get/Set a window state for later restoring public static void saveState(String name, QByteArray state) { + int view = Global.getListView(); + if (view == Global.View_List_Narrow) + name = name +"Narrow"; settings.beginGroup("SaveState"); settings.setValue(name, state); settings.endGroup(); } public static QByteArray restoreState(String name) { + int view = Global.getListView(); + if (view == Global.View_List_Narrow) + name = name +"Narrow"; settings.beginGroup("SaveState"); QByteArray state = (QByteArray)settings.value(name); settings.endGroup(); return state; } public static void saveGeometry(String name, QByteArray state) { - settings.beginGroup("SaveGeometry"); + int view = Global.getListView(); + if (view == Global.View_List_Narrow) + settings.beginGroup("SaveGeometryNarrow"); + else + settings.beginGroup("SaveGeometry"); settings.setValue(name, state); settings.endGroup(); } public static QByteArray restoreGeometry(String name) { - settings.beginGroup("SaveGeometry"); + int view = Global.getListView(); + if (view == Global.View_List_Narrow) + settings.beginGroup("SaveGeometryNarrow"); + else + settings.beginGroup("SaveGeometry"); QByteArray state = (QByteArray)settings.value(name); settings.endGroup(); return state; } + + // Set how often to do an automatic save public static void setAutoSaveInterval(int interval) { settings.beginGroup("General"); settings.setValue("autoSaveInterval", interval); @@ -969,13 +1373,15 @@ public class Global { try { value = (Integer)settings.value("autoSaveInterval", 5); } catch (Exception e1) { - value = 0; + value = 5; } } settings.endGroup(); return value; } + // Add an invalid attribute & element to the database so we don't bother parsing it in the future + // These values we automatically remove from any note. // Add invalid attributes public static void addInvalidAttribute(String element, String attribute) { @@ -999,8 +1405,7 @@ public class Global { invalidAttributes.put(element,attributeList); } } - - + // Add invalid attributes public static void addInvalidElement(String element) { for (int i=0; i", "")); + zoom = 2; + if (text.length() < 500) + zoom = 2; + if (text.length() < 250) + zoom = 3; + if (text.length() < 100) + zoom = 4; + if (text.length() < 50) + zoom = 5; + if (text.length() < 10) + zoom = 6; + } + } + return zoom; + } + + //********************** + //* List View settings + //********************** + public static void setListView(int view) { + settings.beginGroup("General"); + settings.setValue("listView", view); + settings.endGroup(); + } + public static int getListView() { + settings.beginGroup("General"); + Integer value; + try { + String val = (String)settings.value("listView", View_List_Wide); + value = new Integer(val.trim()); + } catch (Exception e) { + try { + value = (Integer)settings.value("listView", View_List_Wide); + } catch (Exception e1) { + value = View_List_Wide; + } + } + settings.endGroup(); + return value; + } + + + + //******************* + // Font Settings + //******************* + public static boolean overrideDefaultFont() { + settings.beginGroup("Font"); + try { + String text = (String)settings.value("overrideFont", "false"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("overrideFont", false); + settings.endGroup(); + return value; + } + + } + + //**************************************************** + // Get/Set the default font settings for a new note + //**************************************************** + public static void setOverrideDefaultFont(boolean value) { + settings.beginGroup("Font"); + settings.setValue("overrideFont", value); + settings.endGroup(); + } + public static String getDefaultFont() { + settings.beginGroup("Font"); + String val = (String)settings.value("font", ""); + settings.endGroup(); + return val; + } + public static void setDefaultFont(String value) { + settings.beginGroup("Font"); + settings.setValue("font", value); + settings.endGroup(); + } + public static String getDefaultFontSize() { + settings.beginGroup("Font"); + String val = (String)settings.value("fontSize", ""); + settings.endGroup(); + return val; + } + public static void setDefaultFontSize(String value) { + settings.beginGroup("Font"); + settings.setValue("fontSize", value); + settings.endGroup(); + } + + + //******************************************* + // Override the close & minimize instead. + //******************************************* + public static boolean minimizeOnClose() { + settings.beginGroup("General"); + try { + String text = (String)settings.value("minimizeOnClose", "false"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("minimizeOnClose", false); + settings.endGroup(); + return value; + } + } + public static void setMinimizeOnClose(boolean value) { + settings.beginGroup("General"); + settings.setValue("minimizeOnClose", value); + settings.endGroup(); + } + + //********************************* + // Check version information + //********************************* + public static boolean checkVersionUpgrade() { + settings.beginGroup("Upgrade"); + try { + String text = (String)settings.value("checkForUpdates", "true"); + settings.endGroup(); + if (text.equalsIgnoreCase("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("checkForUpdates", true); + settings.endGroup(); + return value; + } + } + public static void setCheckVersionUpgrade(boolean value) { + settings.beginGroup("Upgrade"); + settings.setValue("checkForUpdates", value); + settings.endGroup(); + } + public static String getUpdatesAvailableUrl() { + settings.beginGroup("Upgrade"); + String text = (String)settings.value("avialableUrl", "http://nevernote.sourceforge.net/versions.txt"); + settings.endGroup(); + return text; + } + public static String getUpdateAnnounceUrl() { + settings.beginGroup("Upgrade"); + String text = (String)settings.value("announceUrl", "http://nevernote.sourceforge.net/upgrade.html"); + settings.endGroup(); + return text; + } + + //******************* + // Index settings + //******************* + // Set/Get if we should index the text of a note + public static boolean indexNoteBody() { + settings.beginGroup("Index"); + try { + String value = (String)settings.value("indexNoteBody", "true"); + settings.endGroup(); + if (value.equals("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("indexNoteBody", true); + settings.endGroup(); + return value; + } + } + public static void setIndexNoteTitle(boolean value) { + settings.beginGroup("Index"); + settings.setValue("indexNoteTitle", value); + settings.endGroup(); + } + // Set/Get if we should index the title of a note + public static boolean indexNoteTitle() { + settings.beginGroup("Index"); + try { + String value = (String)settings.value("indexNoteTitle", "true"); + settings.endGroup(); + if (value.equals("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("indexNoteTitle", true); + settings.endGroup(); + return value; + } + } + public static void setIndexNoteBody(boolean value) { + settings.beginGroup("Index"); + settings.setValue("indexNoteBody", value); + settings.endGroup(); + } + // Set/Get if we should index any attachments + public static boolean indexAttachmentsLocally() { + settings.beginGroup("Index"); + try { + String value = (String)settings.value("indexAttachmentsLocally", "true"); + settings.endGroup(); + if (value.equals("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("indexAttachmentsLocally", true); + settings.endGroup(); + return value; + } + } + public static void setIndexImageRecognition(boolean value) { + settings.beginGroup("Index"); + settings.setValue("indexImageRecognition", value); + settings.endGroup(); + } + public static boolean indexImageRecognition() { + settings.beginGroup("Index"); + try { + String value = (String)settings.value("indexImageRecognition", "true"); + settings.endGroup(); + if (value.equals("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("indexImageRecognition", true); + settings.endGroup(); + return value; + } + } + public static void setIndexAttachmentsLocally(boolean value) { + settings.beginGroup("Index"); + settings.setValue("indexAttachmentsLocally", value); + settings.endGroup(); + } + // Get/Set characters that shouldn't be removed from a word + public static String getSpecialIndexCharacters() { + settings.beginGroup("Index"); + String text = (String)settings.value("specialCharacters", ""); + settings.endGroup(); + return text; + } + public static void setSpecialIndexCharacters(String value) { + settings.beginGroup("Index"); + settings.setValue("specialCharacters", value); + settings.endGroup(); + databaseCache = value; + } + //***************************************************************************** + // Control how tag selection behaves (should they be "and" or "or" selections + //***************************************************************************** + public static boolean anyTagSelectionMatch() { + settings.beginGroup("General"); + try { + String value = (String)settings.value("anyTagSelectionMatch", "false"); + settings.endGroup(); + if (value.equals("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("anyTagSelectionMatch", false); + settings.endGroup(); + return value; + } + } + public static void setAnyTagSelectionMatch(boolean value) { + settings.beginGroup("General"); + settings.setValue("anyTagSelectionMatch", value); + settings.endGroup(); + } + + //***************************************************************************** + // Control how tag selection behaves (should they be "and" or "or" selections + //***************************************************************************** + public static boolean bypassSynchronizationWarning() { + settings.beginGroup("User"); + try { + String value = (String)settings.value("bypassSynchronizationWarning", "false"); + settings.endGroup(); + if (value.equals("true")) + return true; + else + return false; + } catch (java.lang.ClassCastException e) { + Boolean value = (Boolean) settings.value("bypassSynchronizationWarning", false); + settings.endGroup(); + return value; + } + } + public static void setBypassSynchronizationWarning(boolean value) { + settings.beginGroup("User"); + settings.setValue("bypassSynchronizationWarning", value); + settings.endGroup(); + } + + + //*********************** + //* Database cache size + //*********************** + public static String getDatabaseCacheSize() { + settings.beginGroup("Debug"); + String text = (String)settings.value("databaseCache", "16384"); + settings.endGroup(); + return text; + } + public static void setDatabaseCache(String value) { + settings.beginGroup("Debug"); + settings.setValue("databaseCache", value); + settings.endGroup(); + databaseCache = value; + } + + + // This is used to copy a class since Java's normal deep copy is wacked + public static Object deepCopy(Object oldObj) + { + ObjectOutputStream oos = null; + ObjectInputStream ois = null; + try + { + ByteArrayOutputStream bos = + new ByteArrayOutputStream(); // A + oos = new ObjectOutputStream(bos); // B + // serialize and pass the object + oos.writeObject(oldObj); // C + oos.flush(); // D + ByteArrayInputStream bin = + new ByteArrayInputStream(bos.toByteArray()); // E + ois = new ObjectInputStream(bin); // F + // return the new object + return ois.readObject(); // G + } + catch(Exception e) + { + Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e); + } + try { + oos.close(); + ois.close(); + } catch (IOException e) { + Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e); + e.printStackTrace(); + } + + return null; + } }