OSDN Git Service

Merge branch 'master' of http://git.code.sf.net/p/nevernote/code into develop
authoryuki <kimaira7@gmail.com>
Mon, 11 Nov 2013 08:58:54 +0000 (17:58 +0900)
committeryuki <kimaira7@gmail.com>
Mon, 11 Nov 2013 08:58:54 +0000 (17:58 +0900)
Conflicts:
src/cx/fbn/nevernote/Global.java
src/cx/fbn/nevernote/oauth/OAuthWindow.java
src/cx/fbn/nevernote/threads/SyncRunner.java

1  2 
src/cx/fbn/nevernote/Global.java
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/threads/SyncRunner.java

 -/*\r
 - * This file is part of NixNote \r
 - * Copyright 2009 Randy Baumgarte\r
 - * \r
 - * This file may be licensed under the terms of of the\r
 - * GNU General Public License Version 2 (the ``GPL'').\r
 - *\r
 - * Software distributed under the License is distributed\r
 - * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
 - * express or implied. See the GPL for the specific language\r
 - * governing rights and limitations.\r
 - *\r
 - * You should have received a copy of the GPL along with this\r
 - * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
 - * or write to the Free Software Foundation, Inc.,\r
 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
 - *\r
 -*/\r
 -\r
 -package cx.fbn.nevernote;\r
 -\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.text.SimpleDateFormat;\r
 -import java.util.ArrayList;\r
 -import java.util.Calendar;\r
 -import java.util.HashMap;\r
 -import java.util.List;\r
 -\r
 -import org.apache.commons.lang3.StringEscapeUtils;\r
 -\r
 -import com.evernote.edam.type.Accounting;\r
 -import com.evernote.edam.type.PrivilegeLevel;\r
 -import com.evernote.edam.type.User;\r
 -import com.evernote.edam.type.UserAttributes;\r
 -import com.swabunga.spell.engine.Configuration;\r
 -import com.trolltech.qt.core.QByteArray;\r
 -import com.trolltech.qt.core.QSettings;\r
 -import com.trolltech.qt.core.QSize;\r
 -import com.trolltech.qt.gui.QPalette;\r
 -import com.trolltech.qt.gui.QSystemTrayIcon;\r
 -\r
 -import cx.fbn.nevernote.config.FileManager;\r
 -import cx.fbn.nevernote.config.InitializationException;\r
 -import cx.fbn.nevernote.config.StartupConfig;\r
 -import cx.fbn.nevernote.gui.ContainsAttributeFilterTable;\r
 -import cx.fbn.nevernote.gui.DateAttributeFilterTable;\r
 -import cx.fbn.nevernote.gui.ShortcutKeys;\r
 -import cx.fbn.nevernote.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
 -      // Set current version and the known versions.\r
 -      public static String version = "1.6";\r
 -      public static String[] validVersions = {"1.6", "1.5", "1.4", "1.3", "1.2", "1.1", "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
 -    public static final int trashCounterThreadId=3;   // This should always be the highest thread ID\r
 -    public static final int indexThreadId=4;          // Thread for indexing words\r
 -    public static final int saveThreadId=5;           // Thread used for processing data to saving content\r
 -    public static final int notebookCounterThreadId=6;   // Notebook Thread\r
 -    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
 -\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
 -    \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 String userStoreUrl;\r
 -    public static String noteStoreUrl;\r
 -    public static String noteStoreUrlBase;\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
 -    public static int noteTableNotebookPosition = 3;\r
 -    public static int noteTableChangedPosition = 4;\r
 -    public static int noteTableGuidPosition = 5;\r
 -    public static int noteTableAuthorPosition = 6;\r
 -    public static int noteTableSourceUrlPosition = 7;\r
 -    public static int noteTableSubjectDatePosition = 8;\r
 -    public static int noteTableSynchronizedPosition = 9;\r
 -    public static int noteTableThumbnailPosition = 10;\r
 -    public static int noteTablePinnedPosition = 11;\r
 -    public static int noteTableColumnCount = 12;\r
 -    public static Integer cryptCounter = 0;\r
 -    \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
 -    // 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
 -      \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
 -      \r
 -      // Application key shortcuts & appearance\r
 -      public static QPalette                          originalPalette;\r
 -      public static ShortcutKeys                      shortcutKeys;\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
 -      \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
 -      static boolean syncOnly;\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
 -        settings = new QSettings("fbn.cx", startupConfig.getName());\r
 -        disableViewing = startupConfig.getDisableViewing();\r
 -        syncOnly = startupConfig.isSyncOnly();\r
 -\r
 -        fileManager = new FileManager(startupConfig.getHomeDirPath(), startupConfig.getProgramDirPath());\r
 -\r
 -\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 false.\r
 -              //disableUploads = true;  //***** DELETE THIS LINE *******\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();  // Set database cache size     \r
 -              \r
 -              Global.username = getUserInformation().getUsername();\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
 -\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
 -                      messageLevel = 2;\r
 -              if (msglevel.equalsIgnoreCase("high")) \r
 -                              messageLevel = 3;\r
 -              if (msglevel.equalsIgnoreCase("extreme")) \r
 -                                      messageLevel = 4;\r
 -              settings.beginGroup("Debug");\r
 -              settings.setValue("messageLevel", msglevel);\r
 -              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
 -              settings.setValue("username", user.getUsername());\r
 -              settings.setValue("email", user.getEmail());\r
 -              settings.setValue("name", user.getName());\r
 -              settings.setValue("timezone", user.getTimezone());\r
 -              settings.setValue("privilege", user.getPrivilege().getValue());\r
 -              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
 -                      saveUserAttributes(user.getAttributes());\r
 -              if (user.getAccounting()!=null)\r
 -                      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
 -              settings.setValue("defaultLatitude", attrib.getDefaultLocationName());\r
 -              settings.setValue("defaultLongitude", attrib.getDefaultLocationName());\r
 -              settings.setValue("incomingEmailAddress", attrib.getIncomingEmailAddress());\r
 -              settings.endGroup();\r
 -    }\r
 -    public static UserAttributes getUserAttributes() {\r
 -      settings.beginGroup("UserAttributes");\r
 -      UserAttributes attrib = new UserAttributes();\r
 -              attrib.setDefaultLocationName((String)settings.value("defaultLocationName",""));\r
 -              attrib.setDefaultLatitudeIsSet(false);\r
 -              attrib.setDefaultLongitudeIsSet(false);\r
 -              attrib.setIncomingEmailAddress((String)settings.value("incomingEmailAddress", ""));\r
 -              settings.endGroup();\r
 -              return attrib;\r
 -    }\r
 -    public static void saveUserAccounting(Accounting acc) {\r
 -      settings.beginGroup("UserAccounting");\r
 -              settings.setValue("uploadLimit", acc.getUploadLimit());\r
 -              settings.setValue("uploadLimitEnd", acc.getUploadLimitEnd());\r
 -              settings.setValue("uploadLimitNextMonth", acc.getUploadLimitNextMonth());\r
 -              settings.setValue("premiumServiceStart", acc.getPremiumServiceStart());\r
 -              settings.setValue("nextPaymentDue", acc.getNextPaymentDue());\r
 -              settings.setValue("uploadAmount", acc.getUpdated());\r
 -              settings.endGroup();\r
 -    }\r
 -    public static long getUploadLimitEnd() {\r
 -      Long limit;\r
 -      settings.beginGroup("UserAccounting");\r
 -      \r
 -      // Upload limit\r
 -              try {\r
 -                      String val  = (String)settings.value("uploadLimitEnd", "0");\r
 -                      limit = new Long(val.trim());\r
 -              } catch (Exception e) {\r
 -                      try {\r
 -                              limit = (Long)settings.value("uploadLimitEnd", 0);\r
 -                      } catch (Exception e1) {\r
 -                              limit = new Long(0);\r
 -                      }\r
 -              }\r
 -      \r
 -              // return value\r
 -      settings.endGroup();\r
 -      return limit;\r
 -    }\r
 -    public static void saveUploadAmount(long amount) {\r
 -      settings.beginGroup("UserAccounting");\r
 -              settings.setValue("uploadAmount", amount);\r
 -              settings.endGroup();\r
 -   }\r
 -    public static long getUploadAmount() {\r
 -              long amt=0;\r
 -              settings.beginGroup("UserAccounting");\r
 -              try {\r
 -                      String num = (String)settings.value("uploadAmount", "0");\r
 -                      amt = new Long(num.trim());\r
 -              } catch (Exception e) {\r
 -                      try {\r
 -                              amt = (Integer)settings.value("uploadAmount", 0);\r
 -                      } catch (Exception e1) {\r
 -                              amt = 0;\r
 -                      }\r
 -              }\r
 -              settings.endGroup();\r
 -              return amt;\r
 -    }\r
 -    public static void saveEvernoteUpdateCount(long amount) {\r
 -      settings.beginGroup("UserAccounting");\r
 -              settings.setValue("updateCount", amount);\r
 -              settings.endGroup();\r
 -    }\r
 -    public static long getEvernoteUpdateCount() {\r
 -              long amt;\r
 -              settings.beginGroup("UserAccounting");\r
 -              try {\r
 -                      String num = (String)settings.value("updateCount", new Long(0).toString());\r
 -                      amt = new Long(num.trim());\r
 -              } catch (java.lang.ClassCastException e) {\r
 -                      amt = 0;\r
 -              }\r
 -              settings.endGroup();\r
 -              return amt;\r
 -    }\r
 -    public static boolean isPremium() {\r
 -              int level;\r
 -              settings.beginGroup("User");\r
 -              try {\r
 -                      String num = (String)settings.value("privilege", "1");\r
 -                      level = new Integer(num.trim());\r
 -              } catch (java.lang.ClassCastException e) {\r
 -                      try {\r
 -                              level = (Integer)settings.value("privilege", 1);\r
 -                      } catch (Exception e1) {\r
 -                              level = 1;\r
 -                      }\r
 -              }\r
 -              settings.endGroup();\r
 -              PrivilegeLevel userLevel = PrivilegeLevel.findByValue(level);\r
 -              if (userLevel == PrivilegeLevel.NORMAL)\r
 -                      return false;\r
 -              return true;\r
 -              \r
 -   }\r
 -    public static long getUploadLimit() {\r
 -              settings.beginGroup("UserAccounting");\r
 -              long limit;\r
 -              try {\r
 -                      String num = (String)settings.value("uploadLimit", new Long(0).toString());\r
 -                      limit = new Long(num.trim());\r
 -              } catch (java.lang.ClassCastException e) {\r
 -                      limit = 0;\r
 -              }\r
 -              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", "false");\r
 -                      settings.endGroup();\r
 -                      if (!max.equalsIgnoreCase("true") || !QSystemTrayIcon.isSystemTrayAvailable())\r
 -                              return false;\r
 -                      else\r
 -                              return true;    \r
 -              } catch (java.lang.ClassCastException e) {\r
 -                      Boolean value = (Boolean) settings.value("showTrayIcon", false);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void setShowTrayIcon(boolean val) {\r
 -              settings.beginGroup("General");\r
 -              if (val)\r
 -                      settings.setValue("showTrayIcon", "true");\r
 -              else\r
 -                      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
 -                      String max = (String) settings.value("isMaximized", "true");\r
 -                      settings.endGroup();\r
 -                      if (!max.equalsIgnoreCase("true"))\r
 -                              return false;\r
 -                      return true;    \r
 -              } catch (java.lang.ClassCastException e) {\r
 -                      Boolean value = (Boolean) settings.value("isMaximized", true);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void saveWindowMaximized(boolean isMax) {\r
 -              settings.beginGroup("General");\r
 -              if (isMax)\r
 -                      settings.setValue("isMaximized", "true");\r
 -              else\r
 -                      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
 -              settings.endGroup();\r
 -              return guid;    \r
 -    }\r
 -    public static void saveCurrentNoteGuid(String guid) {\r
 -              settings.beginGroup("General");\r
 -              if (guid != null)\r
 -                      settings.setValue("lastViewedNote", guid);\r
 -              else\r
 -                      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
 -      if (view == Global.View_List_Wide)\r
 -              settings.setValue("sortColumn", i);\r
 -      else\r
 -              settings.setValue("sortColumn-Narrow", i);\r
 -              settings.endGroup();\r
 -    }\r
 -    public static int getSortColumn() {;\r
 -    String key;\r
 -      if (Global.getListView() == Global.View_List_Wide)\r
 -              key = "sortColumn";\r
 -      else\r
 -              key = "sortColumn-Narrow";\r
 -\r
 -      settings.beginGroup("General");\r
 -      int order;      \r
 -      try {\r
 -              String val  = settings.value(key, new Integer(0)).toString();\r
 -              order = new Integer(val.trim());\r
 -      } catch (Exception e) {\r
 -              try {\r
 -                      order = (Integer)settings.value(key, 0);\r
 -              } catch (Exception e1) {\r
 -                  order = 0;\r
 -              }\r
 -      }\r
 -      \r
 -      settings.endGroup();\r
 -      return order;\r
 -    }\r
 -    public static void setSortOrder(int i) {\r
 -      int view = Global.getListView();\r
 -              settings.beginGroup("General");\r
 -      if (view == Global.View_List_Wide)\r
 -              settings.setValue("sortOrder", i);\r
 -      else\r
 -              settings.setValue("sortOrder-Narrow", i);\r
 -              settings.endGroup();\r
 -    }\r
 -    public static int getSortOrder() {\r
 -      int view = Global.getListView();\r
 -              settings.beginGroup("General");\r
 -              String key;\r
 -      if (view == Global.View_List_Wide)\r
 -              key = "sortOrder";\r
 -              else\r
 -                      key = "sortOrder-Narrow";\r
 -\r
 -              int order;      \r
 -              try {\r
 -                      String val  = settings.value(key, new Integer(0)).toString();\r
 -                      order = new Integer(val.trim());\r
 -              } catch (Exception e) {\r
 -                      try {\r
 -                              order = (Integer)settings.value(key, 0);\r
 -                      } catch (Exception e1) {\r
 -                          order = 0;\r
 -                      }\r
 -              }\r
 -              \r
 -              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
 -              String text = (String)settings.value("automaticLogin", "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("automaticLogin", false);\r
 -              settings.endGroup();\r
 -              return value;\r
 -      }\r
 -    }\r
 -    public static void setAutomaticLogin(boolean val) {\r
 -              settings.beginGroup("General");\r
 -              if (val)\r
 -                      settings.setValue("automaticLogin", "true");\r
 -              else\r
 -                      settings.setValue("automaticLogin", "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
 -              settings.endGroup();            \r
 -    }\r
 -    public static String getServer() {\r
 -              settings.beginGroup("General");\r
 -              String text = (String)settings.value("server", "www.evernote.com");\r
 -              if (text.equals("www.evernote.com")) {\r
 -                      userStoreUrl = "https://www.evernote.com/edam/user";\r
 -                  noteStoreUrlBase = "www.evernote.com/edam/note/";   \r
 -              } else {\r
 -                      userStoreUrl = "https://sandbox.evernote.com/edam/user";\r
 -                      noteStoreUrlBase = "sandbox.evernote.com/edam/note/";\r
 -              }\r
 -              settings.endGroup();\r
 -//            if (isPremium())\r
 -                      noteStoreUrlBase = "https://" + noteStoreUrlBase;\r
 -//            else\r
 -//                    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
 -              String text = (String)settings.value("disableUploads", "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("disableUploads", false);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void setDisableUploads(boolean val) {\r
 -              settings.beginGroup("General");\r
 -              if (val)\r
 -                      settings.setValue("disableUploads", "true");\r
 -              else\r
 -                      settings.setValue("disableUploads", "false");\r
 -              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
 -                      String text = (String)settings.value("pdfPreview", "true");\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("pdfPreview", true);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void setPdfPreview(boolean val) {\r
 -              settings.beginGroup("General");\r
 -              if (val)\r
 -                      settings.setValue("pdfPreview", "true");\r
 -              else\r
 -                      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
 -                      String text = (String)settings.value("newNoteWithSelectedTags", "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("newNoteWithSelectedTags", false);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void setNewNoteWithSelectedTags(boolean val) {\r
 -              settings.beginGroup("General");\r
 -              if (val)\r
 -                      settings.setValue("newNoteWithSelectedTags", "true");\r
 -              else\r
 -                      settings.setValue("newNoteWithSelectedTags", "false");\r
 -              settings.endGroup();\r
 -    }\r
 -    \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
 -              settings.endGroup();            \r
 -    }\r
 -    public static int getRecognitionWeight() {\r
 -              settings.beginGroup("General");\r
 -              Integer len;\r
 -              try {\r
 -                      len = (Integer)settings.value("recognitionWeight", 30);\r
 -              } catch (Exception e) {\r
 -                      len = 80;\r
 -              }\r
 -              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
 -              settings.endGroup();\r
 -              setMessageLevel(text);\r
 -              return text;\r
 -    }\r
 -    public static void setDateFormat(String format) {\r
 -              settings.beginGroup("General");\r
 -              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
 -              settings.endGroup();\r
 -              return text;\r
 -    }\r
 -    public static void setTimeFormat(String format) {\r
 -              settings.beginGroup("General");\r
 -              settings.setValue("timeFormat", format);\r
 -              settings.endGroup();            \r
 -    }\r
 -    public static String getTimeFormat() {\r
 -              settings.beginGroup("General");\r
 -              String text = (String)settings.value("timeFormat", "HH:mm:ss");\r
 -              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
 -              settings.endGroup();\r
 -              return text;            \r
 -    }\r
 -    public static void setSyncInterval(String format) {\r
 -              settings.beginGroup("General");\r
 -              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
 -      else \r
 -              settings.beginGroup("ColumnWidths-Narrow");\r
 -              settings.setValue(col, width);\r
 -              settings.endGroup();\r
 -      }\r
 -    public static int getColumnWidth(String col) {\r
 -      int view = Global.getListView();\r
 -      if (view == Global.View_List_Wide)\r
 -              settings.beginGroup("ColumnWidths");\r
 -      else\r
 -              settings.beginGroup("ColumnWidths-Narrow");\r
 -              Integer width;\r
 -              try {\r
 -                      String val  = (String)settings.value(col, "0");\r
 -                      width = new Integer(val.trim());\r
 -              } catch (Exception e) {\r
 -                      try {\r
 -                              width = (Integer)settings.value(col, 0);\r
 -                      } catch (Exception e1) {\r
 -                              width = 0;\r
 -                      }\r
 -              }\r
 -              settings.endGroup();\r
 -              return width;\r
 -    }\r
 -    public static void setColumnPosition(String col, int width) {\r
 -      if (Global.getListView() == Global.View_List_Wide)\r
 -              settings.beginGroup("ColumnPosition");\r
 -      else\r
 -              settings.beginGroup("ColumnPosition-Narrow");\r
 -              settings.setValue(col, width);\r
 -              settings.endGroup();\r
 -    }\r
 -    public static int getColumnPosition(String col) {\r
 -      if (Global.getListView() == Global.View_List_Wide)\r
 -              settings.beginGroup("ColumnPosition");\r
 -      else\r
 -              settings.beginGroup("ColumnPosition-Narrow");\r
 -              Integer width;\r
 -              try {\r
 -                      String val  = (String)settings.value(col, "-1");\r
 -                      width = new Integer(val.trim());\r
 -              } catch (Exception e) {\r
 -                      try {\r
 -                              width = (Integer)settings.value(col, 0);\r
 -                      } catch (Exception e1) {\r
 -                              width = 0;\r
 -                      }\r
 -              }\r
 -              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
 -                      String text = (String)settings.value("verifyDelete", "true");\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("verifyDelete", true);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void setVerifyDelete(boolean val) {\r
 -              settings.beginGroup("General");\r
 -              if (val)\r
 -                      settings.setValue("verifyDelete", "true");\r
 -              else\r
 -                      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
 -                      String text = (String)settings.value("startMinimized", "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("startMinimized", false);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void setStartMinimized(boolean val) {\r
 -              settings.beginGroup("General");\r
 -              if (val)\r
 -                      settings.setValue("startMinimized", "true");\r
 -              else\r
 -                      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
 -                      String text = (String)settings.value("syncDeletedContent", "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("syncDeletedContent", false);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    } \r
 -    public static void setSynchronizeDeletedContent(boolean val) {\r
 -              settings.beginGroup("General");\r
 -              if (val)\r
 -                      settings.setValue("syncDeletedContent", "true");\r
 -              else\r
 -                      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
 -                      String defaultValue = "true";\r
 -                      if (window.equalsIgnoreCase("noteInformation"))\r
 -                              defaultValue = "false";\r
 -                      String text = (String)settings.value(window, defaultValue);\r
 -                      settings.endGroup();\r
 -                      if (text.equalsIgnoreCase("true"))\r
 -                              return true;\r
 -              else\r
 -                      return false;           \r
 -              } catch (java.lang.ClassCastException e) {\r
 -                      boolean defaultValue = true;\r
 -                      if (window.equalsIgnoreCase("noteInformation"))\r
 -                              defaultValue = false;\r
 -                      Boolean value = (Boolean) settings.value("showTrayIcon", defaultValue);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void saveWindowVisible(String window, boolean val) {\r
 -              settings.beginGroup("WindowsVisible");\r
 -              if (val)\r
 -                      settings.setValue(window, "true");\r
 -              else\r
 -                      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
 -      if (Global.getListView() == Global.View_List_Wide)\r
 -              settings.beginGroup("ColumnsVisible");\r
 -      else\r
 -              settings.beginGroup("ColumnsVisible-Narrow"); \r
 -              if (window.equalsIgnoreCase("thumbnail") && view == Global.View_List_Wide)\r
 -                      defaultValue = "false";\r
 -              if (window.equalsIgnoreCase("thumbnail"))\r
 -                      defaultValue = "false";\r
 -              if (window.equalsIgnoreCase("Guid"))\r
 -                      defaultValue = "false";\r
 -              try {\r
 -                      String text = (String)settings.value(window, defaultValue);\r
 -                      settings.endGroup();\r
 -                      if (text.equalsIgnoreCase("true"))\r
 -                              return true;\r
 -                      else\r
 -                              return false;\r
 -              } catch (java.lang.ClassCastException e) {\r
 -                      boolean defBool = false;\r
 -                      if (window.equalsIgnoreCase("true"))\r
 -                              defBool = true;\r
 -                      else\r
 -                              defBool = false;\r
 -                      Boolean value = (Boolean) settings.value(window, defBool);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void saveColumnVisible(String column, boolean val) {\r
 -      if (Global.getListView() == Global.View_List_Wide)\r
 -              settings.beginGroup("ColumnsVisible");\r
 -      else\r
 -              settings.beginGroup("ColumnsVisible-Narrow");                   \r
 -              if (val)\r
 -                      settings.setValue(column, "true");\r
 -              else\r
 -                      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
 -                      String text = (String)settings.value(window, "true");\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(window, true);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void saveEditorButtonsVisible(String column, boolean val) {\r
 -              settings.beginGroup("EditorButtonsVisible");\r
 -              if (val)\r
 -                      settings.setValue(column, "true");\r
 -              else\r
 -                      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
 -              String text = (String)settings.value("enableCarriageReturnFix", "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("enableCarriageReturnFix", false);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void saveCarriageReturnFix(boolean val) {\r
 -              settings.beginGroup("Debug");\r
 -              if (val)\r
 -                      settings.setValue("enableCarriageReturnFix", "true");\r
 -              else\r
 -                      settings.setValue("enableCarriageReturnFix", "false");\r
 -              settings.endGroup();\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
 -    }\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
 -              settings.endGroup();\r
 -    }\r
 -    public static double getZoomFactor() {\r
 -              settings.beginGroup("General");\r
 -              Double threads;\r
 -              try {\r
 -                      String val  = (String)settings.value("zoomFactor", "1.0");\r
 -                      threads = new Double(val.trim());\r
 -              } catch (Exception e) {\r
 -                      try {\r
 -                              threads = (Double)settings.value("zoomFactor", 1.0);\r
 -                      } catch (Exception e1) {\r
 -                              threads = new Double(1);\r
 -                      }\r
 -              }\r
 -              settings.endGroup();\r
 -              return threads;\r
 -    }\r
 -    public static void setTextSizeMultiplier(double val) {\r
 -              settings.beginGroup("General");\r
 -              settings.setValue("textMultiplier", val);\r
 -              settings.endGroup();\r
 -    }\r
 -    public static double getTextSizeMultiplier() {\r
 -              settings.beginGroup("General");\r
 -              Double threads;\r
 -              try {\r
 -                      String val  = (String)settings.value("textMultiplier", "1");\r
 -                      threads = new Double(val.trim());\r
 -              } catch (Exception e) {\r
 -                      try {\r
 -                              threads = (Double)settings.value("textMultiplier", 1);\r
 -                      } catch (Exception e1) {\r
 -                              threads = new Double(1);\r
 -                      }\r
 -              }\r
 -              settings.endGroup();\r
 -              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
 -                      String text = (String)settings.value("mimicEvernoteInterface", "true");\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("mimicEvernoteInterface", true);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void setMimicEvernoteInterface(boolean value) {\r
 -      settings.beginGroup("General");\r
 -      if (value)\r
 -              settings.setValue("mimicEvernoteInterface", "true");\r
 -      else\r
 -              settings.setValue("mimicEvernoteInterface", "false"); \r
 -      settings.endGroup();\r
 -    }\r
 -    \r
 -    \r
 -    // Synchronize with Evernote when closing?\r
 -    public static boolean synchronizeOnClose() {\r
 -              settings.beginGroup("General");\r
 -              try {\r
 -                      String text = (String)settings.value("synchronizeOnClose", "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("synchronizeOnClose", false);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void setSynchronizeOnClose(boolean val) {\r
 -              settings.beginGroup("General");\r
 -              if (val)\r
 -                      settings.setValue("synchronizeOnClose", "true");\r
 -              else\r
 -                      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
 -              settings.endGroup();\r
 -    }\r
 -    public static String getDatabaseVersion() {\r
 -              settings.beginGroup("General");\r
 -              String val  = (String)settings.value("databaseVersion", "0.70");\r
 -              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
 -              settings.endGroup();\r
 -              if (val.equals(""))\r
 -                      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("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("ResourceDatabaseURL", "");\r
 -              settings.endGroup();\r
 -              if (val.equals(""))\r
 -                      val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.resourceDatabaseName);\r
 -              return val;\r
 -    }\r
 -    public static void setDatabaseUrl(String value) {\r
 -              settings.beginGroup("General");\r
 -              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
 -              settings.endGroup();\r
 -              return val;\r
 -    }\r
 -    public static String getDatabaseUserPassword() {\r
 -              settings.beginGroup("General");\r
 -              String val  = (String)settings.value("databaseUserPassword", "");\r
 -              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
 -              settings.endGroup();\r
 -    }\r
 -    public static String getStyle() {\r
 -              settings.beginGroup("General");\r
 -              String val  = (String)settings.value("style", "Cleanlooks");\r
 -              settings.endGroup();\r
 -              return val;\r
 -    }\r
 -    public static boolean useStandardPalette() {\r
 -              settings.beginGroup("General");\r
 -              try {\r
 -                      String text = (String)settings.value("standardPalette", "true");\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("standardPalette", true);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void setStandardPalette(boolean val) {\r
 -              settings.beginGroup("General");\r
 -              if (val)\r
 -                      settings.setValue("standardPalette", "true");\r
 -              else\r
 -                      settings.setValue("standardPalette", "false");\r
 -              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
 -              settings.setValue("IndexThreadSleepInterval", sleep);\r
 -              settings.endGroup();\r
 -    }\r
 -    public static int getIndexThreadSleepInterval() {\r
 -              settings.beginGroup("General");\r
 -              Integer sleep;\r
 -              try {\r
 -                      String val  = (String)settings.value("IndexThreadSleepInterval", "300");\r
 -                      sleep = new Integer(val.trim());\r
 -              } catch (Exception e) {\r
 -                      try {\r
 -                              sleep = (Integer)settings.value("IndexThreadSleepInterval", 0);\r
 -                      } catch (Exception e1) {\r
 -                              sleep = 300;\r
 -                      }\r
 -              }\r
 -              settings.endGroup();\r
 -              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
 -              name = name +"Narrow";\r
 -              settings.beginGroup("SaveState");\r
 -              settings.setValue(name, state);\r
 -              settings.endGroup();\r
 -    }\r
 -    \r
 -    public static QByteArray restoreState(String name) {\r
 -      int view = Global.getListView();\r
 -      if (view == Global.View_List_Narrow)\r
 -              name = name +"Narrow";\r
 -              settings.beginGroup("SaveState");\r
 -              QByteArray state = (QByteArray)settings.value(name);\r
 -              settings.endGroup();\r
 -              return state;\r
 -    }\r
 -    public static void saveGeometry(String name, QByteArray state) {\r
 -      int view = Global.getListView();\r
 -      if (view == Global.View_List_Narrow)\r
 -              settings.beginGroup("SaveGeometryNarrow");\r
 -      else\r
 -              settings.beginGroup("SaveGeometry");\r
 -              settings.setValue(name, state);\r
 -              settings.endGroup();\r
 -    }\r
 -    \r
 -    public static QByteArray restoreGeometry(String name) {\r
 -      int view = Global.getListView();\r
 -      if (view == Global.View_List_Narrow)\r
 -              settings.beginGroup("SaveGeometryNarrow");\r
 -      else\r
 -              settings.beginGroup("SaveGeometry");\r
 -              QByteArray state = (QByteArray)settings.value(name);\r
 -              settings.endGroup();\r
 -              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
 -              settings.endGroup();\r
 -    }\r
 -    public static int getAutoSaveInterval() {\r
 -              settings.beginGroup("General");\r
 -              Integer value;\r
 -              try {\r
 -                      String val  = (String)settings.value("autoSaveInterval", "5");\r
 -                      value = new Integer(val.trim());\r
 -              } catch (Exception e) {\r
 -                      try {\r
 -                              value = (Integer)settings.value("autoSaveInterval", 5);\r
 -                      } catch (Exception e1) {\r
 -                              value = 5;\r
 -                      }\r
 -              }\r
 -              settings.endGroup();\r
 -              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
 -              List<String> attributes = invalidAttributes.get(element);\r
 -              if (attributes != null) {\r
 -                      for (int i=0; i<attributes.size(); i++)\r
 -                              if (attribute.equalsIgnoreCase(attributes.get(i))) {\r
 -                                      return;\r
 -                      }\r
 -      }\r
 -      \r
 -      ArrayList<String> attributeList;\r
 -      if (!invalidAttributes.containsKey(element)) {\r
 -              attributeList = new ArrayList<String>();\r
 -              attributeList.add(attribute);\r
 -              invalidAttributes.put(element, attributeList);\r
 -      }\r
 -      else {\r
 -              attributeList = invalidAttributes.get(element);\r
 -              attributeList.add(attribute);\r
 -              invalidAttributes.put(element,attributeList);\r
 -      }\r
 -    }\r
 -   \r
 -    // Add invalid attributes\r
 -    public static void addInvalidElement(String element) {\r
 -              for (int i=0; i<invalidElements.size(); i++) {\r
 -                      if (element.equalsIgnoreCase(invalidElements.get(i)))\r
 -                              return;\r
 -              }\r
 -      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
 -              String val  = (String)settings.value(key, "");\r
 -              settings.endGroup();\r
 -              return val;\r
 -    }\r
 -    public static void setProxyValue(String key, String value) {\r
 -              settings.beginGroup("Proxy");\r
 -              settings.setValue(key, value);\r
 -              settings.endGroup();\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
 -          for (byte element : data) {\r
 -              int halfbyte = (element >>> 4) & 0x0F;\r
 -              int two_halfs = 0;\r
 -              do {\r
 -                      if ((0 <= halfbyte) && (halfbyte <= 9))\r
 -                             buf.append((char) ('0' + halfbyte));\r
 -                         else\r
 -                              buf.append((char) ('a' + (halfbyte - 10)));\r
 -                      halfbyte = element & 0x0F;\r
 -              } while(two_halfs++ < 1);\r
 -          }\r
 -          return buf.toString();              \r
 -      }\r
 -\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
 -              if (text.equalsIgnoreCase("true"))\r
 -                      return true;\r
 -              if (text.equalsIgnoreCase("false"))\r
 -                      return false;\r
 -              if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREDIGITWORDS))\r
 -                      return true;\r
 -              if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREINTERNETADDRESSES))\r
 -                      return true;\r
 -              if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREUPPERCASE))\r
 -                      return true;\r
 -              if (value.equalsIgnoreCase(Configuration.SPELL_IGNORESENTENCECAPITALIZATION))\r
 -                      return true;\r
 -              return false;\r
 -    }\r
 -    public static void setSpellSetting(String setting, boolean val) {\r
 -              settings.beginGroup("Spell");\r
 -              if (val)\r
 -                      settings.setValue(setting, "true");\r
 -              else\r
 -                      settings.setValue(setting, "false");\r
 -              settings.endGroup();\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
 -              String text = (String)settings.value("tagBehavior", "DoNothing");\r
 -              settings.endGroup();\r
 -              return text;\r
 -      }\r
 -      // What to do with inactive tags?\r
 -      public static void setTagBehavior(String value) {\r
 -              settings.beginGroup("General");\r
 -              settings.setValue("tagBehavior", value);\r
 -              settings.endGroup();\r
 -      }\r
 -\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
 -                      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(window, true);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void saveToolbarButtonsVisible(String column, boolean val) {\r
 -              settings.beginGroup("ToolbarButtonsVisible");\r
 -              if (val)\r
 -                      settings.setValue(column, "true");\r
 -              else\r
 -                      settings.setValue(column, "false");\r
 -              settings.endGroup();\r
 -    }\r
 -      \r
 -    // Are thumbnails enabled?\r
 -    \r
 -    public static boolean enableThumbnails() {\r
 -              settings.beginGroup("Debug");\r
 -              try {\r
 -                      String text = (String)settings.value("thumbnails", "true");\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("thumbnails", true);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void setEnableThumbnails(boolean val) {\r
 -              settings.beginGroup("Debug");\r
 -              if (val)\r
 -                      settings.setValue("thumbnails", "true");\r
 -              else\r
 -                      settings.setValue("thumbnails", "false");\r
 -              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
 -              String dateTimeFormat = new String(fmt);\r
 -              SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);\r
 -              Calendar cal = Calendar.getInstance();\r
 -              if (intervalTraceTime == null) \r
 -                      intervalTraceTime = Calendar.getInstance();\r
 -              if (startTraceTime == null)\r
 -                      startTraceTime = Calendar.getInstance();\r
 -              \r
 -              float interval = (cal.getTimeInMillis() - intervalTraceTime.getTimeInMillis());\r
 -              float total = (cal.getTimeInMillis() - startTraceTime.getTimeInMillis());\r
 -              \r
 -//            if (interval > 00.0) {\r
 -                      StackTraceElement[] exceptions = Thread.currentThread().getStackTrace();\r
 -                      System.out.println("------------------------------------------");\r
 -\r
 -                      System.out.println("Date/Time " +simple.format(cal.getTime()));\r
 -                      System.out.format("Interval Time: %-10.6f%n", interval);\r
 -                      System.out.format("Total Time: %-10.6f%n", total);\r
 -                      for (int i=2; i<5 && i<exceptions.length; i++) {\r
 -                              System.out.println(exceptions[i]);\r
 -                      }\r
 -//            }\r
 -              if (resetInterval)\r
 -                      intervalTraceTime = cal;\r
 -      }\r
 -      public static void traceReset() {\r
 -              intervalTraceTime = null;\r
 -              startTraceTime = null;\r
 -      }\r
 -\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
 -\r
 -    //**********************\r
 -    //* Thumbnail zoom level\r
 -    //**********************\r
 -    public static int calculateThumbnailZoom(String content) {\r
 -      int zoom = 1;\r
 -              if (content.indexOf("application/pdf") == -1) {\r
 -                      if (content.indexOf("image/") == -1) {\r
 -                              String text =  StringEscapeUtils.unescapeHtml4(content.replaceAll("\\<.*?\\>", ""));\r
 -                              zoom = 2;\r
 -                              if (text.length() < 500) \r
 -                                      zoom = 2;\r
 -                              if (text.length() < 250)\r
 -                                      zoom = 3;\r
 -                              if (text.length() < 100)\r
 -                                      zoom = 4;\r
 -                              if (text.length() < 50)\r
 -                                      zoom = 5;\r
 -                              if (text.length() < 10)\r
 -                                      zoom = 6;\r
 -                      }\r
 -              }\r
 -              return zoom;\r
 -    }\r
 -    \r
 -    //**********************\r
 -    //* List View settings \r
 -    //**********************\r
 -    public static void setListView(int view) {\r
 -              settings.beginGroup("General");\r
 -              settings.setValue("listView", view);\r
 -              settings.endGroup();\r
 -    }\r
 -    public static int getListView() {\r
 -              settings.beginGroup("General");\r
 -              Integer value;\r
 -              try {\r
 -                      String val  = (String)settings.value("listView", View_List_Wide);\r
 -                      value = new Integer(val.trim());\r
 -              } catch (Exception e) {\r
 -                      try {\r
 -                              value = (Integer)settings.value("listView", View_List_Wide);\r
 -                      } catch (Exception e1) {\r
 -                              value = View_List_Wide;\r
 -                      }\r
 -              }\r
 -              settings.endGroup();\r
 -              return value;\r
 -    }\r
 -\r
 -    \r
 -    \r
 -    //*******************\r
 -    // Font Settings\r
 -    //*******************\r
 -    public static boolean overrideDefaultFont() {\r
 -              settings.beginGroup("Font");\r
 -              try {\r
 -                      String text = (String)settings.value("overrideFont", "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("overrideFont", false);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\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
 -              settings.endGroup();    \r
 -    }\r
 -    public static String getDefaultFont() {\r
 -              settings.beginGroup("Font");\r
 -              String val  = (String)settings.value("font", "");\r
 -              settings.endGroup();\r
 -              return val;\r
 -    }\r
 -    public static void setDefaultFont(String value) {\r
 -              settings.beginGroup("Font");\r
 -              settings.setValue("font", value);\r
 -              settings.endGroup();\r
 -    }\r
 -    public static String getDefaultFontSize() {\r
 -              settings.beginGroup("Font");\r
 -              String val  = (String)settings.value("fontSize", "");\r
 -              settings.endGroup();\r
 -              return val;\r
 -    }\r
 -    public static void setDefaultFontSize(String value) {\r
 -              settings.beginGroup("Font");\r
 -              settings.setValue("fontSize", value);\r
 -              settings.endGroup();\r
 -    }\r
 -    \r
 -    \r
 -    //*******************************************\r
 -    // Override the close & minimize instead.\r
 -    //*******************************************\r
 -    public static boolean minimizeOnClose() {\r
 -              settings.beginGroup("General");\r
 -              try {\r
 -                      String text = (String)settings.value("minimizeOnClose", "false");\r
 -                      settings.endGroup();\r
 -                      if (text.equalsIgnoreCase("true") && QSystemTrayIcon.isSystemTrayAvailable())\r
 -                              return true;\r
 -                      else\r
 -                              return false;\r
 -              } catch (java.lang.ClassCastException e) {\r
 -                      Boolean value = (Boolean) settings.value("minimizeOnClose", false);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void setMinimizeOnClose(boolean value) {\r
 -              settings.beginGroup("General");\r
 -              settings.setValue("minimizeOnClose", value);\r
 -              settings.endGroup();    \r
 -    }\r
 -\r
 -    //*********************************\r
 -    // Check version information\r
 -    //*********************************\r
 -    public static boolean checkVersionUpgrade() {\r
 -              settings.beginGroup("Upgrade");\r
 -              try {\r
 -                      String text = (String)settings.value("checkForUpdates", "true");\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("checkForUpdates", true);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -    }\r
 -    public static void setCheckVersionUpgrade(boolean value) {\r
 -              settings.beginGroup("Upgrade");\r
 -              settings.setValue("checkForUpdates", value);\r
 -              settings.endGroup();    \r
 -    }\r
 -    public static String getUpdatesAvailableUrl() {\r
 -              settings.beginGroup("Upgrade");\r
 -              String text = (String)settings.value("avialableUrl", "http://nevernote.sourceforge.net/versions.txt");\r
 -              settings.endGroup();    \r
 -              return text;\r
 -    }\r
 -    public static String getUpdateAnnounceUrl() {\r
 -              settings.beginGroup("Upgrade");\r
 -              String text = (String)settings.value("announceUrl", "http://nevernote.sourceforge.net/upgrade.html");\r
 -              settings.endGroup();    \r
 -              return text;\r
 -    }\r
 -    \r
 -    //*******************\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("Index");\r
 -              try {\r
 -                      String value = (String)settings.value("indexAttachmentsLocally", "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("indexAttachmentsLocally", true);\r
 -                      settings.endGroup();\r
 -                      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("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 if a user receives a warning when trying to create a note-to-note link\r
 -    // when the DB is not synchronized.\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
 -    public static String getDatabaseCacheSize() {\r
 -              settings.beginGroup("Debug");\r
 -              String text = (String)settings.value("databaseCache", "16384");\r
 -              settings.endGroup();    \r
 -              return text;\r
 -    }\r
 -    public static void setDatabaseCache(String value) {\r
 -              settings.beginGroup("Debug");\r
 -              settings.setValue("databaseCache", value);\r
 -              settings.endGroup();    \r
 -              databaseCache = value;\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
 -       ObjectInputStream ois = null;\r
 -       try\r
 -       {\r
 -          ByteArrayOutputStream bos = \r
 -                new ByteArrayOutputStream(); // A\r
 -          oos = new ObjectOutputStream(bos); // B\r
 -          // serialize and pass the object\r
 -          oos.writeObject(oldObj);   // C\r
 -          oos.flush();               // D\r
 -          ByteArrayInputStream bin = \r
 -                new ByteArrayInputStream(bos.toByteArray()); // E\r
 -          ois = new ObjectInputStream(bin);                  // F\r
 -          // return the new object\r
 -          return ois.readObject(); // G\r
 -       }\r
 -       catch(Exception e)\r
 -       {\r
 -          Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e);\r
 -       }\r
 -          try {\r
 -                      oos.close();\r
 -              ois.close();\r
 -              } catch (IOException e) {\r
 -                      Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e);\r
 -                      e.printStackTrace();\r
 -              }\r
 -\r
 -              return null;\r
 -    }\r
 -\r
 -    // If we should automatically select the children of any tag\r
 -    public static boolean includeTagChildren() {\r
 -              settings.beginGroup("General");\r
 -              try {\r
 -                      String value = (String)settings.value("includeTagChildren", "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("includeTagChildren", false);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -\r
 -    }\r
 -    public static void setIncludeTagChildren(boolean value) {\r
 -              settings.beginGroup("General");\r
 -              settings.setValue("includeTagChildren", value);\r
 -              settings.endGroup();    \r
 -    }\r
 -    \r
 -    // If we should automatically wildcard searches\r
 -    public static boolean automaticWildcardSearches() {\r
 -              settings.beginGroup("General");\r
 -              try {\r
 -                      String value = (String)settings.value("automaticWildcard", "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("automaticWildcard", false);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -\r
 -    }\r
 -    public static void setAutomaticWildcardSearches(boolean value) {\r
 -              settings.beginGroup("General");\r
 -              settings.setValue("automaticWildcard", value);\r
 -              settings.endGroup();    \r
 -    }\r
 -\r
 -    // If we should automatically select the children of any tag\r
 -    public static boolean displayRightToLeft() {\r
 -              settings.beginGroup("General");\r
 -              try {\r
 -                      String value = (String)settings.value("displayRightToLeft", "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("displayRightToLeft", false);\r
 -                      settings.endGroup();\r
 -                      return value;\r
 -              }\r
 -\r
 -    }\r
 -    public static void setDisplayRightToLeft(boolean value) {\r
 -              settings.beginGroup("General");\r
 -              settings.setValue("displayRightToLeft", value);\r
 -              settings.endGroup();    \r
 -    }\r
 -\r
 -\r
 -    //***********************\r
 -    //* Startup Notebook\r
 -    //***********************\r
 -    public static String getStartupNotebook() {\r
 -              settings.beginGroup("General");\r
 -              String text = (String)settings.value("startupNotebook", "");\r
 -              settings.endGroup();    \r
 -              return text;\r
 -    }\r
 -    public static void setStartupNotebook(String value) {\r
 -              settings.beginGroup("General");\r
 -              settings.setValue("startupNotebook", value);\r
 -              settings.endGroup();    \r
 -              databaseCache = value;\r
 -    }\r
 -}\r
 -\r
 +/*
 + * This file is part of NixNote/NeighborNote 
 + * Copyright 2009 Randy Baumgarte
 + * Copyright 2013 Yuki Takahashi
 + * 
 + * This file may be licensed under the terms of of the
 + * GNU General Public License Version 2 (the ``GPL'').
 + *
 + * Software distributed under the License is distributed
 + * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
 + * express or implied. See the GPL for the specific language
 + * governing rights and limitations.
 + *
 + * You should have received a copy of the GPL along with this
 + * program. If not, go to http://www.gnu.org/licenses/gpl.html
 + * or write to the Free Software Foundation, Inc.,
 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 +*/
 +
 +package cx.fbn.nevernote;
 +
 +
 +import java.io.ByteArrayInputStream;
 +import java.io.ByteArrayOutputStream;
 +import java.io.File;
 +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.lang3.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.QFile;
 +import com.trolltech.qt.core.QSettings;
 +import com.trolltech.qt.core.QSize;
 +import com.trolltech.qt.gui.QPalette;
 +import com.trolltech.qt.gui.QSystemTrayIcon;
 +
 +import cx.fbn.nevernote.config.FileManager;
 +import cx.fbn.nevernote.config.InitializationException;
 +import cx.fbn.nevernote.config.StartupConfig;
 +import cx.fbn.nevernote.gui.ContainsAttributeFilterTable;
 +import cx.fbn.nevernote.gui.DateAttributeFilterTable;
 +import cx.fbn.nevernote.gui.ShortcutKeys;
 +import cx.fbn.nevernote.sql.DatabaseConnection;
 +import cx.fbn.nevernote.sql.driver.NSqlQuery;
 +import cx.fbn.nevernote.utilities.ApplicationLogger;
 +import cx.fbn.nevernote.utilities.Pair;
 +
 +
 +//*****************************************************
 +//*****************************************************
 +//* Global constants & static functions used by 
 +//* multiple threads.
 +//*****************************************************
 +//*****************************************************
 +
 +public class Global {
 +      // Set current version and the known versions.
 +      public static String version = "0.3";
 +      public static String[] validVersions = {"0.3", "0.2", "0.1.3", "0.1.2", "0.1.1", "0.1"};
 +      
 +    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<String,Pair<String,String>> passwordSafe = new HashMap<String, Pair<String,String>>();
 +    public static List<Pair<String,String>> passwordRemember = new ArrayList<Pair<String,String>>();
 +    
 +    
 +    //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 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;
 +    public static int noteTableNotebookPosition = 3;
 +    public static int noteTableChangedPosition = 4;
 +    public static int noteTableGuidPosition = 5;
 +    public static int noteTableAuthorPosition = 6;
 +    public static int noteTableSourceUrlPosition = 7;
 +    public static int noteTableSubjectDatePosition = 8;
 +    public static int noteTableSynchronizedPosition = 9;
 +    public static int noteTableThumbnailPosition = 10;
 +    public static int noteTablePinnedPosition = 11;
 +    public static int noteTableColumnCount = 12;
 +    public static Integer cryptCounter = 0;
 +    
 +    //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;
 +    
 +    // 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
 +      
 +      
 +      //* 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 String behaviorDatabaseName = new String("Behavior"); // 操作履歴データベース   
 +      
 +      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;
 +      
 +      // Application key shortcuts & appearance
 +      public static QPalette                          originalPalette;
 +      public static ShortcutKeys                      shortcutKeys;
 +      
 +      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<String>                              invalidElements = new ArrayList<String>();
 +      public static HashMap<String, ArrayList<String>>        invalidAttributes = new HashMap<String, ArrayList<String>>();
 +      
 +      public static boolean mimicEvernoteInterface; // Try to mimic Evernote or allow multiple notebook selection
 +      public static HashMap<String,String> 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;
 +      
 +      static boolean syncOnly;
 +      
 +      private static FileManager fileManager;  // Used to access files & directories
 +      
 +    // Do initial setup 
 +    public static void setup(StartupConfig startupConfig) throws InitializationException  {
 +      String settingFileName = new String("NeighborNote.ini");
 +      
 +      // バージョン0.1.2以下で作成された古い設定ファイルを見つけたら、ホームディレクトリに移動させる。
 +      String oldSettingPath = new QSettings(settingFileName, QSettings.Format.IniFormat).fileName();
 +      File homeDir = new File(FileManager.toPlatformPathSeparator(startupConfig.getHomeDirPath()));
 +      String homePath = FileManager.slashTerminatePath(homeDir.getPath());
 +      if (QFile.exists(oldSettingPath)) {
 +              QFile file = new QFile(oldSettingPath);
 +              file.copy(homePath + settingFileName);
 +              file.remove();
 +      }
 +      
 +        settings = new QSettings(homePath + settingFileName, QSettings.Format.IniFormat);
 +        
 +        disableViewing = startupConfig.getDisableViewing();
 +        syncOnly = startupConfig.isSyncOnly();
 +
 +        fileManager = new FileManager(startupConfig.getHomeDirPath(), startupConfig.getProgramDirPath());
 +
 +
 +              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 false.\r
-               //disableUploads = true;  //***** DELETE THIS LINE *******\r
++              disableUploads = disableUploads();  // Should we upload anything?  Normally false.
++              //disableUploads = true;  //***** DELETE THIS LINE *******
 +              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<String,String>();  // Setup resource map used to store attachments when editing
 +                      
 +              databaseCache = getDatabaseCacheSize();  // Set database cache size     
 +              
 +              Global.username = getUserInformation().getUsername();
 +    }
 +
 +    // Get/Set word parsing regular expression
 +//    public static String getWordRegex() {
 +//            return wordRegex;
 +//    }
 +//    public static void setWordRegex(String r) {
 +//            wordRegex = r;
 +//    }
 +
 +   // Set the debug message level
 +   public static void setMessageLevel(String msglevel) {
 +      if (msglevel.equalsIgnoreCase("low")) 
 +                      messageLevel = 1;
 +              if (msglevel.equalsIgnoreCase("medium")) 
 +                      messageLevel = 2;
 +              if (msglevel.equalsIgnoreCase("high")) 
 +                              messageLevel = 3;
 +              if (msglevel.equalsIgnoreCase("extreme")) 
 +                                      messageLevel = 4;
 +              settings.beginGroup("Debug");
 +              settings.setValue("messageLevel", msglevel);
 +              settings.endGroup();            
 +    }
 +
 +   //****************************************************
 +   //****************************************************
 +   //** Save user account information from Evernote
 +   //****************************************************
 +   //****************************************************
 +    public static void saveUserInformation(User user) {
 +      settings.beginGroup("User");
 +              settings.setValue("id", user.getId());
 +              settings.setValue("username", user.getUsername());
 +              settings.setValue("email", user.getEmail());
 +              settings.setValue("name", user.getName());
 +              settings.setValue("timezone", user.getTimezone());
 +              settings.setValue("privilege", user.getPrivilege().getValue());
 +              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)
 +                      saveUserAttributes(user.getAttributes());
 +              if (user.getAccounting()!=null)
 +                      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());
 +              settings.setValue("defaultLatitude", attrib.getDefaultLocationName());
 +              settings.setValue("defaultLongitude", attrib.getDefaultLocationName());
 +              settings.setValue("incomingEmailAddress", attrib.getIncomingEmailAddress());
 +              settings.endGroup();
 +    }
 +    public static UserAttributes getUserAttributes() {
 +      settings.beginGroup("UserAttributes");
 +      UserAttributes attrib = new UserAttributes();
 +              attrib.setDefaultLocationName((String)settings.value("defaultLocationName",""));
 +              attrib.setDefaultLatitudeIsSet(false);
 +              attrib.setDefaultLongitudeIsSet(false);
 +              attrib.setIncomingEmailAddress((String)settings.value("incomingEmailAddress", ""));
 +              settings.endGroup();
 +              return attrib;
 +    }
 +    public static void saveUserAccounting(Accounting acc) {
 +      settings.beginGroup("UserAccounting");
 +              settings.setValue("uploadLimit", acc.getUploadLimit());
 +              settings.setValue("uploadLimitEnd", acc.getUploadLimitEnd());
 +              settings.setValue("uploadLimitNextMonth", acc.getUploadLimitNextMonth());
 +              settings.setValue("premiumServiceStart", acc.getPremiumServiceStart());
 +              settings.setValue("nextPaymentDue", acc.getNextPaymentDue());
 +              settings.setValue("uploadAmount", acc.getUpdated());
 +              settings.endGroup();
 +    }
 +    public static long getUploadLimitEnd() {
 +      Long limit;
 +      settings.beginGroup("UserAccounting");
 +      
 +      // Upload limit
 +              try {
 +                      String val  = (String)settings.value("uploadLimitEnd", "0");
 +                      limit = new Long(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              limit = (Long)settings.value("uploadLimitEnd", 0);
 +                      } catch (Exception e1) {
 +                              limit = new Long(0);
 +                      }
 +              }
 +      
 +              // return value
 +      settings.endGroup();
 +      return limit;
 +    }
 +    public static void saveUploadAmount(long amount) {
 +      settings.beginGroup("UserAccounting");
 +              settings.setValue("uploadAmount", amount);
 +              settings.endGroup();
 +   }
 +    public static long getUploadAmount() {
 +              long amt=0;
 +              settings.beginGroup("UserAccounting");
 +              try {
 +                      String num = (String)settings.value("uploadAmount", "0");
 +                      amt = new Long(num.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              amt = (Integer)settings.value("uploadAmount", 0);
 +                      } catch (Exception e1) {
 +                              amt = 0;
 +                      }
 +              }
 +              settings.endGroup();
 +              return amt;
 +    }
 +    public static void saveEvernoteUpdateCount(long amount) {
 +      settings.beginGroup("UserAccounting");
 +              settings.setValue("updateCount", amount);
 +              settings.endGroup();
 +    }
 +    public static long getEvernoteUpdateCount() {
 +              long amt;
 +              settings.beginGroup("UserAccounting");
 +              try {
 +                      String num = (String)settings.value("updateCount", new Long(0).toString());
 +                      amt = new Long(num.trim());
 +              } catch (java.lang.ClassCastException e) {
 +                      amt = 0;
 +              }
 +              settings.endGroup();
 +              return amt;
 +    }
 +    public static boolean isPremium() {
 +              int level;
 +              settings.beginGroup("User");
 +              try {
 +                      String num = (String)settings.value("privilege", "1");
 +                      level = new Integer(num.trim());
 +              } catch (java.lang.ClassCastException e) {
 +                      try {
 +                              level = (Integer)settings.value("privilege", 1);
 +                      } catch (Exception e1) {
 +                              level = 1;
 +                      }
 +              }
 +              settings.endGroup();
 +              PrivilegeLevel userLevel = PrivilegeLevel.findByValue(level);
 +              if (userLevel == PrivilegeLevel.NORMAL)
 +                      return false;
 +              return true;
 +              
 +   }
 +    public static long getUploadLimit() {
 +              settings.beginGroup("UserAccounting");
 +              long limit;
 +              try {
 +                      String num = (String)settings.value("uploadLimit", new Long(0).toString());
 +                      limit = new Long(num.trim());
 +              } catch (java.lang.ClassCastException e) {
 +                      limit = 0;
 +              }
 +              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");
 +              try {
 +                      String max = (String) settings.value("showTrayIcon", "false");
 +                      settings.endGroup();
 +                      if (!max.equalsIgnoreCase("true") || !QSystemTrayIcon.isSystemTrayAvailable())
 +                              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");
 +              if (val)
 +                      settings.setValue("showTrayIcon", "true");
 +              else
 +                      settings.setValue("showTrayIcon", "false");
 +              settings.endGroup();
 +    }
 +    
 +    // Get/Set window maximized when closed last
 +    public static boolean wasWindowMaximized() {
 +      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");
 +              if (isMax)
 +                      settings.setValue("isMaximized", "true");
 +              else
 +                      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", "");
 +              settings.endGroup();
 +              return guid;    
 +    }
 +    public static void saveCurrentNoteGuid(String guid) {
 +              settings.beginGroup("General");
 +              if (guid != null)
 +                      settings.setValue("lastViewedNote", guid);
 +              else
 +                      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");
 +      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(key, new Integer(0)).toString();
 +              order = new Integer(val.trim());
 +      } catch (Exception e) {
 +              try {
 +                      order = (Integer)settings.value(key, 0);
 +              } catch (Exception e1) {
 +                  order = 0;
 +              }
 +      }
 +      
 +      settings.endGroup();
 +      return order;
 +    }
 +    public static void setSortOrder(int i) {
 +      int view = Global.getListView();
 +              settings.beginGroup("General");
 +      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(key, new Integer(0)).toString();
 +                      order = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              order = (Integer)settings.value(key, 0);
 +                      } catch (Exception e1) {
 +                          order = 0;
 +                      }
 +              }
 +              
 +              settings.endGroup();
 +              return order;
 +    }
 +    
 +    // Should we automatically log in to Evernote when starting?
 +    public static boolean automaticLogin() {
 +      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");
 +              if (val)
 +                      settings.setValue("automaticLogin", "true");
 +              else
 +                      settings.setValue("automaticLogin", "false");
 +              settings.endGroup();
 +    }
 +
 +    // Get/set the Evernote server Url.  
 +    public static void setServer(String server) {
 +              settings.beginGroup("General");
 +              settings.setValue("server", server);
 +              settings.endGroup();            
 +    }
 +    public static String getServer() {
 +              settings.beginGroup("General");
 +              String text = (String)settings.value("server", "www.evernote.com");
 +              if (text.equals("www.evernote.com")) {
 +                      userStoreUrl = "https://www.evernote.com/edam/user";
 +                  noteStoreUrlBase = "www.evernote.com/edam/note/";   
 +              } else {
 +                      userStoreUrl = "https://sandbox.evernote.com/edam/user";
 +                      noteStoreUrlBase = "sandbox.evernote.com/edam/note/";
 +              }
 +              settings.endGroup();
 +//            if (isPremium())
 +                      noteStoreUrlBase = "https://" + noteStoreUrlBase;
 +//            else
 +//                    noteStoreUrlBase = "http://" + noteStoreUrlBase;
 +              return text;
 +    }
 +
 +    // Get/Set if we should disable uploads to Evernote
 +    public static boolean disableUploads() {
 +      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");
 +              if (val)
 +                      settings.setValue("disableUploads", "true");
 +              else
 +                      settings.setValue("disableUploads", "false");
 +              settings.endGroup();
 +              disableUploads = val;
 +    }
 + 
 +    // Should we view PDF documents inline?
 +    public static boolean pdfPreview() {
 +              settings.beginGroup("General");
 +              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");
 +              if (val)
 +                      settings.setValue("pdfPreview", "true");
 +              else
 +                      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");
 +              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");
 +              if (val)
 +                      settings.setValue("newNoteWithSelectedTags", "true");
 +              else
 +                      settings.setValue("newNoteWithSelectedTags", "false");
 +              settings.endGroup();
 +    }
 +    
 +    // 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);
 +              settings.endGroup();            
 +    }
 +    public static int getRecognitionWeight() {
 +              settings.beginGroup("General");
 +              Integer len;
 +              try {
-                       len = (Integer)settings.value("recognitionWeight", 30);\r
++                      len = (Integer)settings.value("recognitionWeight", 30);
 +              } catch (Exception e) {
-                       len = 80;\r
++                      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");
 +              settings.endGroup();
 +              setMessageLevel(text);
 +              return text;
 +    }
 +    public static void setDateFormat(String format) {
 +              settings.beginGroup("General");
 +              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");
 +              settings.endGroup();
 +              return text;
 +    }
 +    public static void setTimeFormat(String format) {
 +              settings.beginGroup("General");
 +              settings.setValue("timeFormat", format);
 +              settings.endGroup();            
 +    }
 +    public static String getTimeFormat() {
 +              settings.beginGroup("General");
 +              String text = (String)settings.value("timeFormat", "HH:mm:ss");
 +              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");
 +              settings.endGroup();
 +              return text;            
 +    }
 +    public static void setSyncInterval(String format) {
 +              settings.beginGroup("General");
 +              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) {
 +      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) {
 +      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");
 +                      width = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              width = (Integer)settings.value(col, 0);
 +                      } catch (Exception e1) {
 +                              width = 0;
 +                      }
 +              }
 +              settings.endGroup();
 +              return width;
 +    }
 +    public static void setColumnPosition(String col, int width) {
 +      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) {
 +      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");
 +                      width = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              width = (Integer)settings.value(col, 0);
 +                      } catch (Exception e1) {
 +                              width = 0;
 +                      }
 +              }
 +              settings.endGroup();
 +              return width;
 +    }
 +    
 +    // Ping the user when they try to delete or just do it.
 +    public static boolean verifyDelete() {
 +              settings.beginGroup("General");
 +              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");
 +              if (val)
 +                      settings.setValue("verifyDelete", "true");
 +              else
 +                      settings.setValue("verifyDelete", "false");
 +              settings.endGroup();
 +    }
 +    
 +    // Should it start minimized?
 +    public static boolean startMinimized() {
 +              settings.beginGroup("General");
 +              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
 +                      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)
 +                      settings.setValue("syncDeletedContent", "true");
 +              else
 +                      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");
 +              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");
 +              if (val)
 +                      settings.setValue(window, "true");
 +              else
 +                      settings.setValue(window, "false");
 +              settings.endGroup();
 +    }
 +    
 +    // Is a list in the column in the note list visible?  
 +    public static boolean isColumnVisible(String window) {
 +      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) {
 +      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");
 +              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");
 +              if (val)
 +                      settings.setValue(column, "true");
 +              else
 +                      settings.setValue(column, "false");
 +              settings.endGroup();
 +    }
 +    
 +    // Should the test fixes be enabled
 +    public static boolean enableCarriageReturnFix() {
 +      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");
 +              if (val)
 +                      settings.setValue("enableCarriageReturnFix", "true");
 +              else
 +                      settings.setValue("enableCarriageReturnFix", "false");
 +              settings.endGroup();
 +    }
 +    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();
 +    }
 +
 +//    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);
 +              settings.endGroup();
 +    }
 +    public static double getZoomFactor() {
 +              settings.beginGroup("General");
 +              Double threads;
 +              try {
 +                      String val  = (String)settings.value("zoomFactor", "1.0");
 +                      threads = new Double(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              threads = (Double)settings.value("zoomFactor", 1.0);
 +                      } catch (Exception e1) {
 +                              threads = new Double(1);
 +                      }
 +              }
 +              settings.endGroup();
 +              return threads;
 +    }
 +    public static void setTextSizeMultiplier(double val) {
 +              settings.beginGroup("General");
 +              settings.setValue("textMultiplier", val);
 +              settings.endGroup();
 +    }
 +    public static double getTextSizeMultiplier() {
 +              settings.beginGroup("General");
 +              Double threads;
 +              try {
 +                      String val  = (String)settings.value("textMultiplier", "1");
 +                      threads = new Double(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              threads = (Double)settings.value("textMultiplier", 1);
 +                      } catch (Exception e1) {
 +                              threads = new Double(1);
 +                      }
 +              }
 +              settings.endGroup();
 +              return threads;
 +    }
 +    
 +    
 +    // Should we mimic Evernote and restrict the notebooks selected?
 +    public static boolean getMimicEvernoteInterface() {
 +              settings.beginGroup("General");
 +              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");
 +      if (value)
 +              settings.setValue("mimicEvernoteInterface", "true");
 +      else
 +              settings.setValue("mimicEvernoteInterface", "false"); 
 +      settings.endGroup();
 +    }
 +    
 +    
 +    // Synchronize with Evernote when closing?
 +    public static boolean synchronizeOnClose() {
 +              settings.beginGroup("General");
 +              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");
 +              if (val)
 +                      settings.setValue("synchronizeOnClose", "true");
 +              else
 +                      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);
 +              settings.endGroup();
 +    }
 +    public static String getDatabaseVersion() {
 +              settings.beginGroup("General");
 +              String val  = (String)settings.value("databaseVersion", "0.70");
 +              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", "");
 +              settings.endGroup();
 +              if (val.equals(""))
 +                      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("IndexDatabaseURL", "");
 +              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("ResourceDatabaseURL", "");
 +              settings.endGroup();
 +              if (val.equals(""))
 +                      val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.resourceDatabaseName);
 +              return val;
 +    }
 +    
 +      // 操作履歴データベースのURL(フルパス)をゲット
 +      public static String getBehaviorDatabaseUrl() {
 +              settings.beginGroup("General");
 +              String val = (String) settings.value("BehaviorDatabaseURL", "");
 +              settings.endGroup();
 +              if (val.equals(""))
 +                      val = "jdbc:h2:"
 +                                      + Global.getFileManager().getDbDirPath(
 +                                                      Global.behaviorDatabaseName);
 +              return val;
 +      }
 +      
 +    public static void setDatabaseUrl(String value) {
 +              settings.beginGroup("General");
 +              settings.setValue("DatabaseURL", value);
 +              settings.endGroup();
 +    }
 +    public static void setIndexDatabaseUrl(String value) {
 +              settings.beginGroup("General");
 +              settings.setValue("IndexDatabaseURL", value);
 +              settings.endGroup();
 +    }
 +    public static void setResourceDatabaseUrl(String value) {
 +              settings.beginGroup("General");
 +              settings.setValue("ResourceDatabaseURL", value);
 +              settings.endGroup();
 +    }
 +    
 +      public static void setBehaviorDatabaseUrl(String value) {
 +              settings.beginGroup("General");
 +              settings.setValue("BehaviorDatabaseURL", value);
 +              settings.endGroup();
 +      }
 +      
 +    public static String getDatabaseUserid() {
 +              settings.beginGroup("General");
 +              String val  = (String)settings.value("databaseUserid", "");
 +              settings.endGroup();
 +              return val;
 +    }
 +    public static String getDatabaseUserPassword() {
 +              settings.beginGroup("General");
 +              String val  = (String)settings.value("databaseUserPassword", "");
 +              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);
 +              settings.endGroup();
 +    }
 +    public static String getStyle() {
 +              settings.beginGroup("General");
 +              String val  = (String)settings.value("style", "Cleanlooks");
 +              settings.endGroup();
 +              return val;
 +    }
 +    public static boolean useStandardPalette() {
 +              settings.beginGroup("General");
 +              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");
 +              if (val)
 +                      settings.setValue("standardPalette", "true");
 +              else
 +                      settings.setValue("standardPalette", "false");
 +              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");
 +              settings.setValue("IndexThreadSleepInterval", sleep);
 +              settings.endGroup();
 +    }
 +    public static int getIndexThreadSleepInterval() {
 +              settings.beginGroup("General");
 +              Integer sleep;
 +              try {
 +                      String val  = (String)settings.value("IndexThreadSleepInterval", "300");
 +                      sleep = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              sleep = (Integer)settings.value("IndexThreadSleepInterval", 0);
 +                      } catch (Exception e1) {
 +                              sleep = 300;
 +                      }
 +              }
 +              settings.endGroup();
 +              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) {
 +      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) {
 +      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);
 +              settings.endGroup();
 +    }
 +    public static int getAutoSaveInterval() {
 +              settings.beginGroup("General");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("autoSaveInterval", "5");
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("autoSaveInterval", 5);
 +                      } catch (Exception e1) {
 +                              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) {
 +      
 +              List<String> attributes = invalidAttributes.get(element);
 +              if (attributes != null) {
 +                      for (int i=0; i<attributes.size(); i++)
 +                              if (attribute.equalsIgnoreCase(attributes.get(i))) {
 +                                      return;
 +                      }
 +      }
 +      
 +      ArrayList<String> attributeList;
 +      if (!invalidAttributes.containsKey(element)) {
 +              attributeList = new ArrayList<String>();
 +              attributeList.add(attribute);
 +              invalidAttributes.put(element, attributeList);
 +      }
 +      else {
 +              attributeList = invalidAttributes.get(element);
 +              attributeList.add(attribute);
 +              invalidAttributes.put(element,attributeList);
 +      }
 +    }
 +   
 +    // Add invalid attributes
 +    public static void addInvalidElement(String element) {
 +              for (int i=0; i<invalidElements.size(); i++) {
 +                      if (element.equalsIgnoreCase(invalidElements.get(i)))
 +                              return;
 +              }
 +      invalidElements.add(element);
 +    }
 +    
 +    // Get/Set proxy information
 +    // Proxy settings
 +    public static String getProxyValue(String key) {
 +              settings.beginGroup("Proxy");
 +              String val  = (String)settings.value(key, "");
 +              settings.endGroup();
 +              return val;
 +    }
 +    public static void setProxyValue(String key, String value) {
 +              settings.beginGroup("Proxy");
 +              settings.setValue(key, value);
 +              settings.endGroup();
 +    }
 +    
 +    // Change a byte array to a hex string
 +    // Convert a byte array to a hex string
 +      public static String byteArrayToHexString(byte data[]) {
 +              StringBuffer buf = new StringBuffer();
 +          for (byte element : data) {
 +              int halfbyte = (element >>> 4) & 0x0F;
 +              int two_halfs = 0;
 +              do {
 +                      if ((0 <= halfbyte) && (halfbyte <= 9))
 +                             buf.append((char) ('0' + halfbyte));
 +                         else
 +                              buf.append((char) ('a' + (halfbyte - 10)));
 +                      halfbyte = element & 0x0F;
 +              } while(two_halfs++ < 1);
 +          }
 +          return buf.toString();              
 +      }
 +
 +    
 +      // Get/Set spelling settings
 +      public static boolean getSpellSetting(String value) {
 +              settings.beginGroup("Spell");
 +              String text = (String)settings.value(value, "");
 +              settings.endGroup();
 +              if (text.equalsIgnoreCase("true"))
 +                      return true;
 +              if (text.equalsIgnoreCase("false"))
 +                      return false;
 +              if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREDIGITWORDS))
 +                      return true;
 +              if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREINTERNETADDRESSES))
 +                      return true;
 +              if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREUPPERCASE))
 +                      return true;
 +              if (value.equalsIgnoreCase(Configuration.SPELL_IGNORESENTENCECAPITALIZATION))
 +                      return true;
 +              return false;
 +    }
 +    public static void setSpellSetting(String setting, boolean val) {
 +              settings.beginGroup("Spell");
 +              if (val)
 +                      settings.setValue(setting, "true");
 +              else
 +                      settings.setValue(setting, "false");
 +              settings.endGroup();
 +    }
 +      
 +      // Get/Set how we should display tags (color them, hide unused, or do nothing)
 +      // What to do with inactive tags?
 +      public static String tagBehavior() {
 +              settings.beginGroup("General");
 +              String text = (String)settings.value("tagBehavior", "DoNothing");
 +              settings.endGroup();
 +              return text;
 +      }
 +      // What to do with inactive tags?
 +      public static void setTagBehavior(String value) {
 +              settings.beginGroup("General");
 +              settings.setValue("tagBehavior", value);
 +              settings.endGroup();
 +      }
 +
 +    
 +      // Should the toolbar be visible?
 +      public static boolean isToolbarButtonVisible(String window, Boolean val) {
 +              settings.beginGroup("ToolbarButtonsVisible");
 +              try {
 +                      String text = (String)settings.value(window, val.toString());
 +                      settings.endGroup();
 +                      if (text.equalsIgnoreCase("true"))
 +                              return true;
 +                      else
 +                              return false;   
 +              } catch (java.lang.ClassCastException e) {
 +                      Boolean value = (Boolean) settings.value(window, val);
 +                      settings.endGroup();
 +                      return value;
 +              }
 +    }
 +    public static void saveToolbarButtonsVisible(String column, boolean val) {
 +              settings.beginGroup("ToolbarButtonsVisible");
 +              if (val)
 +                      settings.setValue(column, "true");
 +              else
 +                      settings.setValue(column, "false");
 +              settings.endGroup();
 +    }
 +      
 +    // Are thumbnails enabled?
 +    
 +    public static boolean enableThumbnails() {
 +              settings.beginGroup("Debug");
 +              try {
 +                      String text = (String)settings.value("thumbnails", "true");
 +                      settings.endGroup();
 +                      if (text.equalsIgnoreCase("true"))
 +                              return true;
 +                      else
 +                              return false;
 +              } catch (java.lang.ClassCastException e) {
 +                      Boolean value = (Boolean) settings.value("thumbnails", true);
 +                      settings.endGroup();
 +                      return value;
 +              }
 +    }
 +    public static void setEnableThumbnails(boolean val) {
 +              settings.beginGroup("Debug");
 +              if (val)
 +                      settings.setValue("thumbnails", "true");
 +              else
 +                      settings.setValue("thumbnails", "false");
 +              settings.endGroup();
 +    }
 +      
 +    // Trace used for performance tuning.  Not normally used in production.
 +      // Print date/time.  Used mainly for performance tracing
 +      public static void trace(boolean resetInterval) {
 +              String fmt = "MM/dd/yy HH:mm:ss.SSSSSS";
 +              String dateTimeFormat = new String(fmt);
 +              SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);
 +              Calendar cal = Calendar.getInstance();
 +              if (intervalTraceTime == null) 
 +                      intervalTraceTime = Calendar.getInstance();
 +              if (startTraceTime == null)
 +                      startTraceTime = Calendar.getInstance();
 +              
 +              float interval = (cal.getTimeInMillis() - intervalTraceTime.getTimeInMillis());
 +              float total = (cal.getTimeInMillis() - startTraceTime.getTimeInMillis());
 +              
 +//            if (interval > 00.0) {
 +                      StackTraceElement[] exceptions = Thread.currentThread().getStackTrace();
 +                      System.out.println("------------------------------------------");
 +
 +                      System.out.println("Date/Time " +simple.format(cal.getTime()));
 +                      System.out.format("Interval Time: %-10.6f%n", interval);
 +                      System.out.format("Total Time: %-10.6f%n", total);
 +                      for (int i=2; i<5 && i<exceptions.length; i++) {
 +                              System.out.println(exceptions[i]);
 +                      }
 +//            }
 +              if (resetInterval)
 +                      intervalTraceTime = cal;
 +      }
 +      public static void traceReset() {
 +              intervalTraceTime = null;
 +              startTraceTime = null;
 +      }
 +
 +    
 +      // Get the FileManager class to manage local files & directories
 +      public static FileManager getFileManager() {
 +        return fileManager;
 +    }
 +      
 +      // Should the note editor be disabled?
 +    public static boolean getDisableViewing() {
 +        return disableViewing;
 +    }
 +
 +    //**********************
 +    //* Thumbnail zoom level
 +    //**********************
 +    public static int calculateThumbnailZoom(String content) {
 +      int zoom = 1;
 +              if (content.indexOf("application/pdf") == -1) {
 +                      if (content.indexOf("image/") == -1) {
 +                              String text =  StringEscapeUtils.unescapeHtml4(content.replaceAll("\\<.*?\\>", ""));
 +                              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") && QSystemTrayIcon.isSystemTrayAvailable())
 +                              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://puma.cis.ibaraki.ac.jp/products/neighbornote/develop/versions.txt");
 +              settings.endGroup();    
 +              return text;
 +    }
 +    public static String getUpdateAnnounceUrl() {
 +              settings.beginGroup("Upgrade");
 +              String text = (String)settings.value("announceUrl", "http://puma.cis.ibaraki.ac.jp/products/neighbornote/develop/upgrade.html");
 +              settings.endGroup();    
 +              return text;
 +    }
 +    public static String getUpdateDownloadUrl() {
 +              settings.beginGroup("Upgrade");
 +              String text = (String)settings.value("downloadUrl", "http://puma.cis.ibaraki.ac.jp/products/neighbornote/download.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 if a user receives a warning when trying to create a note-to-note link
 +    // when the DB is not synchronized.
 +    //*****************************************************************************
 +    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;
 +    }
 +
 +    // If we should automatically select the children of any tag
 +    public static boolean includeTagChildren() {
 +              settings.beginGroup("General");
 +              try {
 +                      String value = (String)settings.value("includeTagChildren", "false");
 +                      settings.endGroup();
 +                      if (value.equals("true"))
 +                              return true;
 +                      else
 +                              return false;
 +              } catch (java.lang.ClassCastException e) {
 +                      Boolean value = (Boolean) settings.value("includeTagChildren", false);
 +                      settings.endGroup();
 +                      return value;
 +              }
 +
 +    }
 +    public static void setIncludeTagChildren(boolean value) {
 +              settings.beginGroup("General");
 +              settings.setValue("includeTagChildren", value);
 +              settings.endGroup();    
 +    }
 +    
 +    // If we should automatically wildcard searches
 +//    public static boolean automaticWildcardSearches() {
 +//            settings.beginGroup("General");
 +//            try {
 +//                    String value = (String)settings.value("automaticWildcard", "false");
 +//                    settings.endGroup();
 +//                    if (value.equals("true"))
 +//                            return true;
 +//                    else
 +//                            return false;
 +//            } catch (java.lang.ClassCastException e) {
 +//                    Boolean value = (Boolean) settings.value("automaticWildcard", false);
 +//                    settings.endGroup();
 +//                    return value;
 +//            }
 +//
 +//    }
 +//    public static void setAutomaticWildcardSearches(boolean value) {
 +//            settings.beginGroup("General");
 +//            settings.setValue("automaticWildcard", value);
 +//            settings.endGroup();    
 +//    }
 +
 +    // If we should automatically select the children of any tag
 +    public static boolean displayRightToLeft() {
 +              settings.beginGroup("General");
 +              try {
 +                      String value = (String)settings.value("displayRightToLeft", "false");
 +                      settings.endGroup();
 +                      if (value.equals("true"))
 +                              return true;
 +                      else
 +                              return false;
 +              } catch (java.lang.ClassCastException e) {
 +                      Boolean value = (Boolean) settings.value("displayRightToLeft", false);
 +                      settings.endGroup();
 +                      return value;
 +              }
 +
 +    }
 +    public static void setDisplayRightToLeft(boolean value) {
 +              settings.beginGroup("General");
 +              settings.setValue("displayRightToLeft", value);
 +              settings.endGroup();    
 +    }
 +
 +
 +    //***********************
 +    //* Startup Notebook
 +    //***********************
 +    public static String getStartupNotebook() {
 +              settings.beginGroup("General");
 +              String text = (String)settings.value("startupNotebook", "");
 +              settings.endGroup();    
 +              return text;
 +    }
 +    public static void setStartupNotebook(String value) {
 +              settings.beginGroup("General");
 +              settings.setValue("startupNotebook", value);
 +              settings.endGroup();    
 +              databaseCache = value;
 +    }
 +    
 +    // 複数ノート同時閲覧操作に対する重み付け
 +    public static void setBrowseWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("browseWeight", weight);
 +              settings.endGroup();            
 +    }
 +    public static int getBrowseWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("browseWeight", 1);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("browseWeight", 1);
 +                      } catch (Exception e1) {
 +                              value = 1;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +    }
 +    
 +    // ノート内容のコピー&ペースト操作に対する重み付け
 +    public static void setCopyPasteWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("copyPasteWeight", weight);
 +              settings.endGroup();            
 +    }
 +    public static int getCopyPasteWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("copyPasteWeight", 3);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("copyPasteWeight", 3);
 +                      } catch (Exception e1) {
 +                              value = 3;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +    }
 +    
 +    // 新規ノート追加操作に対する重み付け
 +    public static void setAddNewNoteWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("addNewNoteWeight", weight);
 +              settings.endGroup();            
 +    }
 +      public static int getAddNewNoteWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("addNewNoteWeight", 3);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("addNewNoteWeight", 3);
 +                      } catch (Exception e1) {
 +                              value = 1;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +      }
 +      
 +      // 連想ノートクリック操作に対する重み付け
 +    public static void setRensoItemClickWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("rensoItemClickWeight", weight);
 +              settings.endGroup();            
 +    }
 +      public static int getRensoItemClickWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("rensoItemClickWeight", 10);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("rensoItemClickWeight", 10);
 +                      } catch (Exception e1) {
 +                              value = 10;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +      }
 +      
 +      // タグ付け操作に対する重み付け
 +    public static void setSameTagWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("sameTagWeight", weight);
 +              settings.endGroup();            
 +    }
 +      public static int getSameTagWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("sameTagWeight", 2);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("sameTagWeight", 2);
 +                      } catch (Exception e1) {
 +                              value = 2;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +      }
 +      
 +      // ノートブック変更操作に対する重み付け
 +    public static void setSameNotebookWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("sameNotebookWeight", weight);
 +              settings.endGroup();            
 +    }
 +      public static int getSameNotebookWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("sameNotebookWeight", 2);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("sameNotebookWeight", 2);
 +                      } catch (Exception e1) {
 +                              value = 2;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +      }
 +      
 +      // Evernote関連ノート機能統合に対する重み付け
 +      public static void setENRelatedNotesWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("enRelatedNotesWeight", weight);
 +              settings.endGroup();
 +      }
 +      public static int getENRelatedNotesWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val = (String)settings.value("enRelatedNotesWeight", 5);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("enRelatedNotesWeight", 5);
 +                      } catch (Exception e1) {
 +                              value = 10;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +      }
 +    
 +    //*******************
 +    // ノートのマージ・複製の関連ノートリストへの適用
 +    //*******************
 +    public static void setMergeRensoNote(boolean value) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("mergeRensoNoteList", value);
 +              settings.endGroup();    
 +    }
 +    
 +    public static boolean getMergeRensoNote() {
 +              settings.beginGroup("RensoNoteList");
 +              try {
 +                      String value = (String)settings.value("mergeRensoNoteList", "true");
 +                      settings.endGroup();
 +                      if (value.equals("true"))
 +                              return true;
 +                      else
 +                              return false;
 +              } catch (java.lang.ClassCastException e) {
 +                      Boolean value = (Boolean) settings.value("mergeRensoNoteList", true);
 +                      settings.endGroup();
 +                      return value;
 +              }
 +    }
 +    
 +    public static void setDuplicateRensoNote(boolean value) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("duplicateRensoNoteList", value);
 +              settings.endGroup();    
 +    }
 +    
 +    public static boolean getDuplicateRensoNote() {
 +              settings.beginGroup("RensoNoteList");
 +              try {
 +                      String value = (String)settings.value("duplicateRensoNoteList", "true");
 +                      settings.endGroup();
 +                      if (value.equals("true"))
 +                              return true;
 +                      else
 +                              return false;
 +              } catch (java.lang.ClassCastException e) {
 +                      Boolean value = (Boolean) settings.value("duplicateRensoNoteList", true);
 +                      settings.endGroup();
 +                      return value;
 +              }
 +    }
 +    
 +    // 連想ノートリストからノートを除外するときに確認メッセージを表示するかどうか
 +    public static boolean verifyExclude() {
 +              settings.beginGroup("RensoNoteList");
 +              try {
 +                      String text = (String)settings.value("verifyExclude", "true");
 +                      settings.endGroup();
 +                      if (text.equalsIgnoreCase("true"))
 +                              return true;
 +                      else
 +                              return false;
 +              } catch (java.lang.ClassCastException e) {
 +                      Boolean value = (Boolean) settings.value("verifyExclude", true);
 +                      settings.endGroup();
 +                      return value;
 +              }
 +    }
 +    
 +    public static void setVerifyExclude(boolean val) {
 +              settings.beginGroup("RensoNoteList");
 +              if (val)
 +                      settings.setValue("verifyExclude", "true");
 +              else
 +                      settings.setValue("verifyExclude", "false");
 +              settings.endGroup();
 +    }
 +    
 +      // 連想ノートリスト最大表示アイテム数
 +    public static void setRensoListItemMaximum(int maximum) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("rensoListMaximum", maximum);
 +              settings.endGroup();            
 +    }
 +      public static int getRensoListItemMaximum() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("rensoListMaximum", 10);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("rensoListMaximum", 10);
 +                      } catch (Exception e1) {
 +                              value = 10;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +      }
 +      
 +      // タグを排除してプレーンテキストを抽出
 +      public static String extractPlainText(String sourceText) {
 +              String plainText = sourceText.replaceAll("<.+?>", "");  // タグを除去
 +              plainText = plainText.replaceAll("\\s{2,}", " ");               // 2個以上の空白文字を1文字の空白に変換
 +              String kaigyo = System.getProperty("line.separator");
 +              plainText = plainText.replaceAll(kaigyo, "");                   // 改行を除去
 +//            plainText = plainText.replaceAll("&lt;.+?&gt;", "");    // &lt;で始まり&gt;で終わる文字列を除去
 +              
 +              // HTML特殊文字のサニタイジングを解除
 +              plainText = plainText.replaceAll("&#39;", "'");
 +              plainText = plainText.replaceAll("&quot;", "\"");
 +              plainText = plainText.replaceAll("&gt;", ">");
 +              plainText = plainText.replaceAll("&lt;", "<");
 +              plainText = plainText.replaceAll("&amp;", "&");
 +              
 +              plainText = plainText.replaceAll("&.+?;", "");                  // その他HTML特殊文字があれば除去
 +              
 +              return plainText;
 +      }
 +      
 +      // 全文検索機能の対象となるテーブルとカラムを再構築
 +      public static boolean rebuildFullTextNoteTarget(DatabaseConnection dbConn) {
 +              NSqlQuery nQuery = new NSqlQuery(dbConn.getConnection());
 +              StringBuilder noteTableTarget = new StringBuilder();
 +              boolean success = true;
 +              
 +              if (Global.indexNoteBody()) {
 +                      noteTableTarget.append("CONTENTTEXT");
 +              }
 +              if (Global.indexNoteTitle()) {
 +                      if (noteTableTarget.length() > 0) {
 +                              noteTableTarget.append(", ");
 +                      }
 +                      noteTableTarget.append("TITLE");
 +              }
 +              
 +              if (noteTableTarget.length() > 0) {
 +                      nQuery.prepare("CALL FTL_CREATE_INDEX('PUBLIC', 'NOTE', :column);");
 +                      nQuery.bindValue(":column", noteTableTarget.toString());
 +                      if (!nQuery.exec()) {
 +                              success = false;
 +                      }
 +              }
 +              
 +              return success;
 +      }
 +      
 +      public static boolean rebuildFullTextResourceTarget(DatabaseConnection dbConn) {
 +              NSqlQuery rQuery = new NSqlQuery(dbConn.getResourceConnection());
 +              StringBuilder resourceTableTarget = new StringBuilder();
 +              boolean success = true;
 +              
 +              if (Global.indexAttachmentsLocally()) {
 +                      resourceTableTarget.append("RESOURCETEXT");
 +              }
 +              
 +              if (resourceTableTarget.length() > 0) {
 +                      rQuery.prepare("CALL FTL_CREATE_INDEX('PUBLIC', 'NOTERESOURCES', :column);");
 +                      rQuery.bindValue(":column", resourceTableTarget.toString());
 +                      if (!rQuery.exec()) {
 +                              success = false;
 +                      }
 +              }
 +              
 +              return success;
 +      }
 +      
 +    // 操作ログを取らないモードのボタン状態
 +    public static boolean isHaltLogButton() {
 +              settings.beginGroup("RensoNoteList");
 +              try {
 +                      String text = (String)settings.value("haltOperationLog", "false");
 +                      settings.endGroup();
 +                      if (text.equalsIgnoreCase("true"))
 +                              return true;
 +                      else
 +                              return false;
 +              } catch (java.lang.ClassCastException e) {
 +                      Boolean value = (Boolean) settings.value("haltOperationLog", true);
 +                      settings.endGroup();
 +                      return value;
 +              }
 +    }
 +    public static void saveHaltLogButton(boolean val) {
 +              settings.beginGroup("RensoNoteList");
 +              if (val)
 +                      settings.setValue("haltOperationLog", "true");
 +              else
 +                      settings.setValue("haltOperationLog", "false");
 +              settings.endGroup();
 +    }
 +    
 +    // 連想ノートリストの重み付けモードの状態
 +    public static String rensoWeightingSelect() {
 +              settings.beginGroup("RensoNoteList");
 +              String text = (String)settings.value("rensoWeightingSelect", "Standard");
 +              settings.endGroup();
 +              return text;
 +    }
 +    public static void saveRensoWeightingSelect(String val) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("rensoWeightingSelect", val);
 +              settings.endGroup();
 +    }
 +    
 +    // ordinal から指定した Enum の要素に変換する汎用関数
 +      public static <E extends Enum<E>> E fromOrdinal(Class<E> enumClass, int ordinal) {
 +          E[] enumArray = enumClass.getEnumConstants();
 +          return enumArray[ordinal];
 +      }
 +      
 +      // 連想ノートリスト重み付けモード:カスタムの設定値(同時閲覧)
 +    public static int customBrowseWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("customBrowseWeight", 1);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("customBrowseWeight", 1);
 +                      } catch (Exception e1) {
 +                              value = 1;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +    }
 +      public static void saveCustomBrowseWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("customBrowseWeight", weight);
 +              settings.endGroup();
 +      }
 +      // 連想ノートリスト重み付けモード:カスタムの設定値(コピー&ペースト)
 +    public static int customCopyPasteWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("customCopyPasteWeight", 3);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("customCopyPasteWeight", 3);
 +                      } catch (Exception e1) {
 +                              value = 3;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +    }
 +      public static void saveCustomCopyPasteWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("customCopyPasteWeight", weight);
 +              settings.endGroup();
 +      }
 +      // 連想ノートリスト重み付けモード:カスタムの設定値(新規ノート追加)
 +    public static int customAddNewNoteWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("customAddNewNoteWeight", 3);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("customAddNewNoteWeight", 3);
 +                      } catch (Exception e1) {
 +                              value = 3;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +    }
 +      public static void saveCustomAddNewNoteWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("customAddNewNoteWeight", weight);
 +              settings.endGroup();
 +      }
 +      // 連想ノートリスト重み付けモード:カスタムの設定値(連想ノートクリック)
 +    public static int customRensoItemClickWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("customRensoItemClickWeight", 10);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("customRensoItemClickWeight", 10);
 +                      } catch (Exception e1) {
 +                              value = 10;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +    }
 +      public static void saveCustomRensoItemClickWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("customRensoItemClickWeight", weight);
 +              settings.endGroup();
 +      }
 +      // 連想ノートリスト重み付けモード:カスタムの設定値(同じタグ)
 +    public static int customSameTagWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("customSameTagWeight", 2);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("customSameTagWeight", 2);
 +                      } catch (Exception e1) {
 +                              value = 2;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +    }
 +      public static void saveCustomSameTagWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("customSameTagWeight", weight);
 +              settings.endGroup();
 +      }
 +      // 連想ノートリスト重み付けモード:カスタムの設定値(同じノートブック)
 +    public static int customSameNotebookWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("customSameNotebookWeight", 2);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("customSameNotebookWeight", 2);
 +                      } catch (Exception e1) {
 +                              value = 2;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +    }
 +      public static void saveCustomSameNotebookWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("customSameNotebookWeight", weight);
 +              settings.endGroup();
 +      }
 +      // 連想ノートリスト重み付けモード:カスタムの設定値(Evernote関連ノート)
 +    public static int customENRelatedNotesWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val  = (String)settings.value("customENRelatedNotesWeight", 5);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("customENRelatedNotesWeight", 5);
 +                      } catch (Exception e1) {
 +                              value = 5;
 +                      }
 +              }
 +              settings.endGroup();
 +              return value;
 +    }
 +      public static void saveCustomENRelatedNotesWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("customENRelatedNotesWeight", weight);
 +              settings.endGroup();
 +      }
 +
 +      // ツールバーの「新規」ボタンを押した時、新規ノートをタブで開くかどうか
 +      public static boolean toolBarNewAction() {
 +              settings.beginGroup("General");
 +              try {
 +                      String text = (String)settings.value("toolBarNewAction", "true");
 +                      settings.endGroup();
 +                      if (text.equalsIgnoreCase("true"))
 +                              return true;
 +                      else
 +                              return false;
 +              } catch (java.lang.ClassCastException e) {
 +                      Boolean value = (Boolean) settings.value("toolBarNewAction", true);
 +                      settings.endGroup();
 +                      return value;
 +              }
 +      }
 +      public static void setToolBarNewAction(boolean value) {
 +              settings.beginGroup("General");
 +              settings.setValue("toolBarNewAction", value);
 +              settings.endGroup();    
 +      }
 +}
 +
Simple merge
 -/*\r
 - * This file is part of NixNote \r
 - * Copyright 2009 Randy Baumgarte\r
 - * \r
 - * This file may be licensed under the terms of of the\r
 - * GNU General Public License Version 2 (the ``GPL'').\r
 - *\r
 - * Software distributed under the License is distributed\r
 - * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
 - * express or implied. See the GPL for the specific language\r
 - * governing rights and limitations.\r
 - *\r
 - * You should have received a copy of the GPL along with this\r
 - * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
 - * or write to the Free Software Foundation, Inc.,\r
 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
 - *\r
 -*/\r
 -package cx.fbn.nevernote.threads;\r
 -\r
 -import java.io.BufferedOutputStream;\r
 -import java.io.File;\r
 -import java.io.FileOutputStream;\r
 -import java.io.IOException;\r
 -import java.io.InputStream;\r
 -import java.io.UnsupportedEncodingException;\r
 -import java.net.UnknownHostException;\r
 -import java.util.ArrayList;\r
 -import java.util.Calendar;\r
 -import java.util.Date;\r
 -import java.util.GregorianCalendar;\r
 -import java.util.HashMap;\r
 -import java.util.List;\r
 -import java.util.TreeSet;\r
 -import java.util.concurrent.LinkedBlockingQueue;\r
 -\r
 -import org.apache.http.HttpEntity;\r
 -import org.apache.http.HttpResponse;\r
 -import org.apache.http.NameValuePair;\r
 -import org.apache.http.client.ClientProtocolException;\r
 -import org.apache.http.client.HttpClient;\r
 -import org.apache.http.client.entity.UrlEncodedFormEntity;\r
 -import org.apache.http.client.methods.HttpPost;\r
 -import org.apache.http.impl.client.DefaultHttpClient;\r
 -import org.apache.http.message.BasicNameValuePair;\r
 -import org.apache.http.protocol.HTTP;\r
 -import org.apache.thrift.TException;\r
 -import org.apache.thrift.protocol.TBinaryProtocol;\r
 -import org.apache.thrift.transport.THttpClient;\r
 -import org.apache.thrift.transport.TTransportException;\r
 -\r
 -import com.evernote.edam.error.EDAMNotFoundException;\r
 -import com.evernote.edam.error.EDAMSystemException;\r
 -import com.evernote.edam.error.EDAMUserException;\r
 -import com.evernote.edam.notestore.NoteStore;\r
 -import com.evernote.edam.notestore.NoteStore.Client;\r
 -import com.evernote.edam.notestore.SyncChunk;\r
 -import com.evernote.edam.notestore.SyncState;\r
 -import com.evernote.edam.type.Data;\r
 -import com.evernote.edam.type.LinkedNotebook;\r
 -import com.evernote.edam.type.Note;\r
 -import com.evernote.edam.type.Notebook;\r
 -import com.evernote.edam.type.Resource;\r
 -import com.evernote.edam.type.SavedSearch;\r
 -import com.evernote.edam.type.SharedNotebook;\r
 -import com.evernote.edam.type.Tag;\r
 -import com.evernote.edam.type.User;\r
 -import com.evernote.edam.userstore.AuthenticationResult;\r
 -import com.evernote.edam.userstore.UserStore;\r
 -import com.trolltech.qt.core.QByteArray;\r
 -import com.trolltech.qt.core.QFile;\r
 -import com.trolltech.qt.core.QIODevice.OpenModeFlag;\r
 -import com.trolltech.qt.core.QObject;\r
 -import com.trolltech.qt.core.QTextCodec;\r
 -import com.trolltech.qt.gui.QMessageBox;\r
 -\r
 -import cx.fbn.nevernote.signals.NoteIndexSignal;\r
 -import cx.fbn.nevernote.signals.NoteResourceSignal;\r
 -import cx.fbn.nevernote.signals.NoteSignal;\r
 -import cx.fbn.nevernote.signals.NotebookSignal;\r
 -import cx.fbn.nevernote.signals.SavedSearchSignal;\r
 -import cx.fbn.nevernote.signals.StatusSignal;\r
 -import cx.fbn.nevernote.signals.SyncSignal;\r
 -import cx.fbn.nevernote.signals.TagSignal;\r
 -import cx.fbn.nevernote.sql.DatabaseConnection;\r
 -import cx.fbn.nevernote.sql.DeletedItemRecord;\r
 -import cx.fbn.nevernote.utilities.ApplicationLogger;\r
 -\r
 -public class SyncRunner extends QObject implements Runnable {\r
 -      \r
 -      private final ApplicationLogger logger;\r
 -              private DatabaseConnection              conn;\r
 -              private boolean                                 idle;\r
 -              public boolean                                  error;\r
 -              public volatile List<String>    errorSharedNotebooks;\r
 -              public volatile HashMap<String,String>  errorSharedNotebooksIgnored;\r
 -              public volatile boolean                 isConnected;\r
 -              public volatile boolean                 keepRunning;\r
 -              public volatile String                  authToken;\r
 -              private long                                    evernoteUpdateCount;\r
 -              private final String userAgent = "NixNote/" + System.getProperty("os.name")\r
 -                                                              +"/"+System.getProperty("java.vendor") + "/"\r
 -                                                              + System.getProperty("java.version") +";";\r
 -              \r
 -              public volatile NoteStore.Client                localNoteStore;\r
 -              private UserStore.Client                                userStore;\r
 -              \r
 -              public volatile StatusSignal                    status;\r
 -              public volatile TagSignal                               tagSignal;\r
 -              public volatile NotebookSignal                  notebookSignal;\r
 -              public volatile NoteIndexSignal                 noteIndexSignal;\r
 -              public volatile NoteSignal                              noteSignal;\r
 -              public volatile SavedSearchSignal               searchSignal;\r
 -              public volatile NoteResourceSignal              resourceSignal;\r
 -              public volatile SyncSignal                              syncSignal;\r
 -              public volatile boolean                                 authRefreshNeeded;\r
 -              public volatile boolean                                 syncNeeded;\r
 -              public volatile boolean                                 disableUploads;\r
 -              public volatile boolean                                 syncDeletedContent;\r
 -              private volatile List<String>                   dirtyNoteGuids;\r
 -              \r
 -          public volatile String username = ""; \r
 -          public volatile String password = ""; \r
 -              public volatile String userStoreUrl;\r
 -//        private final static String consumerKey = "baumgarte"; \r
 -//        private final static String consumerSecret = "eb8b5740e17cb55f";\r
 -          public String noteStoreUrlBase;\r
 -          private THttpClient userStoreTrans;\r
 -          private TBinaryProtocol userStoreProt;\r
 -          //private AuthenticationResult authResult;\r
 -          private AuthenticationResult linkedAuthResult;\r
 -          private User user; \r
 -//        private long authTimeRemaining;\r
 -          public long authRefreshTime;\r
 -          public long failedRefreshes = 0;\r
 -          public  THttpClient noteStoreTrans;\r
 -          public TBinaryProtocol noteStoreProt;\r
 -          public String noteStoreUrl;\r
 -          public long sequenceDate;\r
 -          public int updateSequenceNumber;\r
 -          private boolean refreshNeeded;\r
 -          private volatile LinkedBlockingQueue<String> workQueue;\r
 -              private static int MAX_QUEUED_WAITING = 1000;\r
 -              String dbuid;\r
 -              String dburl;\r
 -              String indexUrl;\r
 -              String resourceUrl;\r
 -              String dbpswd;\r
 -              String dbcpswd;\r
 -              private final TreeSet<String> ignoreTags;\r
 -              private final TreeSet<String> ignoreNotebooks;\r
 -              private final TreeSet<String> ignoreLinkedNotebooks;\r
 -              private HashMap<String,String> badTagSync;\r
 -      \r
 -              \r
 -              \r
 -      public SyncRunner(String logname, String u, String i, String r, String uid, String pswd, String cpswd) {\r
 -              logger = new ApplicationLogger(logname);\r
 -              \r
 -              noteSignal = new NoteSignal();\r
 -              status = new StatusSignal();\r
 -              tagSignal = new TagSignal();\r
 -              notebookSignal = new NotebookSignal();\r
 -              noteIndexSignal = new NoteIndexSignal();\r
 -              noteSignal = new NoteSignal();\r
 -              searchSignal = new SavedSearchSignal();\r
 -              syncSignal = new SyncSignal();\r
 -              resourceSignal = new NoteResourceSignal();\r
 -              resourceUrl = r;\r
 -              indexUrl = i;\r
 -              dbuid = uid;\r
 -              dburl = u;\r
 -              dbpswd = pswd;\r
 -              dbcpswd = cpswd;\r
 -//            this.setAutoDelete(false);\r
 -              \r
 -              isConnected = false;\r
 -              syncNeeded = false;\r
 -              authRefreshNeeded = false;\r
 -              keepRunning = true;\r
 -              idle = true;\r
 -              disableUploads = false;\r
 -              ignoreTags = new TreeSet<String>();\r
 -              ignoreNotebooks = new TreeSet<String>();\r
 -              ignoreLinkedNotebooks = new TreeSet<String>();\r
 -              \r
 -//            setAutoDelete(false);\r
 -              workQueue=new LinkedBlockingQueue<String>(MAX_QUEUED_WAITING);\r
 -      }\r
 -      @Override\r
 -      public void run() {\r
 -              errorSharedNotebooks = new ArrayList<String>();\r
 -              errorSharedNotebooksIgnored = new HashMap<String,String>();\r
 -              try {\r
 -                      logger.log(logger.EXTREME, "Starting thread");\r
 -                      conn = new DatabaseConnection(logger, dburl, indexUrl, resourceUrl, dbuid, dbpswd, dbcpswd, 200);\r
 -                      while(keepRunning) {\r
 -                              logger.log(logger.EXTREME, "Blocking until work is found");\r
 -                              String work = workQueue.take();\r
 -                              logger.log(logger.LOW, "Dirty Notes Before Sync: " +new Integer(conn.getNoteTable().getDirtyCount()).toString());\r
 -                              logger.log(logger.EXTREME, "Work found: " +work);\r
 -                              if (work.equalsIgnoreCase("stop")) {\r
 -                                      idle=false;\r
 -                                      return;\r
 -                              }\r
 -                              conn.getNoteTable().dumpDirtyNotes();  // Debugging statement\r
 -                              idle=false;\r
 -                              error=false;\r
 -                              if (syncNeeded) {\r
 -                                      logger.log(logger.EXTREME, "SyncNeeded is true");\r
 -                                      refreshNeeded=false;\r
 -                                      sequenceDate = conn.getSyncTable().getLastSequenceDate();\r
 -                                      updateSequenceNumber = conn.getSyncTable().getUpdateSequenceNumber();\r
 -                                      try {\r
 -                                              logger.log(logger.EXTREME, "Beginning sync");\r
 -                                              evernoteSync(localNoteStore);\r
 -                                              logger.log(logger.EXTREME, "Sync finished");\r
 -                                      } catch (UnknownHostException e) {\r
 -                                              status.message.emit(e.getMessage());\r
 -                                      }\r
 -                              }\r
 -                              idle=true;\r
 -                              logger.log(logger.EXTREME, "Signaling refresh finished.  refreshNeeded=" +refreshNeeded);\r
 -                              syncSignal.finished.emit(refreshNeeded);\r
 -                              if (error) {\r
 -                                      syncSignal.errorDisconnect.emit();\r
 -                                      status.message.emit(tr("Error synchronizing - see log for details."));\r
 -                              }\r
 -                              logger.log(logger.LOW, "Dirty Notes After Sync: " +new Integer(conn.getNoteTable().getDirtyCount()).toString());\r
 -                              conn.getNoteTable().dumpDirtyNotes();\r
 -                              logger.log(logger.LOW, "---");\r
 -                      }\r
 -              }       \r
 -              catch (InterruptedException e1) {\r
 -                      e1.printStackTrace();\r
 -              }\r
 -              conn.dbShutdown();\r
 -      }\r
 -\r
 -      \r
 -      public DatabaseConnection getConnection() {\r
 -              return conn;\r
 -      }\r
 -\r
 -      public boolean isIdle() {\r
 -              return idle;\r
 -      }\r
 -\r
 -\r
 -      public void setConnected(boolean c) {\r
 -              isConnected = c;\r
 -      }\r
 -      public void setKeepRunning(boolean r) {\r
 -              logger.log(logger.EXTREME, "Setting keepRunning=" +r);\r
 -              keepRunning = r;\r
 -      }\r
 -      public void setNoteStore(NoteStore.Client c) {\r
 -              logger.log(logger.EXTREME, "Setting NoteStore in sync thread");\r
 -              localNoteStore = c;\r
 -      }\r
 -      public void setUserStore(UserStore.Client c) {\r
 -              logger.log(logger.EXTREME, "Setting UserStore in sync thread");\r
 -              userStore = c;\r
 -      }\r
 -\r
 -      public void setEvernoteUpdateCount(long s) {\r
 -              logger.log(logger.EXTREME, "Setting Update Count in sync thread");\r
 -              evernoteUpdateCount = s;\r
 -      }\r
 -      \r
 -      //***************************************************************\r
 -    //***************************************************************\r
 -    //** These functions deal with Evernote communications\r
 -    //***************************************************************\r
 -    //***************************************************************\r
 -      // Synchronize changes with Evernote\r
 -      @SuppressWarnings("unused")\r
 -      private void evernoteSync(Client noteStore) throws java.net.UnknownHostException {\r
 -              logger.log(logger.HIGH, "Entering SyncRunner.evernoteSync");\r
 -              \r
 -              // Rebuild list of tags & notebooks to ignore\r
 -              ignoreNotebooks.clear();\r
 -              List<String> ignore = conn.getSyncTable().getIgnoreRecords("NOTEBOOK");\r
 -              for (int i=0; i<ignore.size(); i++) \r
 -                      ignoreNotebooks.add(ignore.get(i));\r
 -              \r
 -              ignore.clear();\r
 -              ignore = conn.getSyncTable().getIgnoreRecords("LINKEDNOTEBOOK");\r
 -              for (int i=0; i<ignore.size(); i++) \r
 -                      ignoreLinkedNotebooks.add(ignore.get(i));\r
 -              \r
 -              ignoreTags.clear();\r
 -              ignore = conn.getSyncTable().getIgnoreRecords("TAG");\r
 -              for (int i=0; i<ignore.size(); i++) \r
 -                      ignoreTags.add(ignore.get(i));\r
 -\r
 -              // Make sure we are connected & should keep running\r
 -              if (isConnected && keepRunning) {\r
 -                      error = false;\r
 -                      logger.log(logger.EXTREME, "Synchronizing with Evernote");\r
 -                      status.message.emit(tr("Synchronizing with Evernote"));\r
 -                      \r
 -                      // Get user information\r
 -                      try {\r
 -                              logger.log(logger.EXTREME, "getting user from userstore");\r
 -                              User user = userStore.getUser(authToken);\r
 -                              logger.log(logger.EXTREME, "Saving user information");\r
 -                              syncSignal.saveUserInformation.emit(user);\r
 -                      } catch (EDAMUserException e1) {\r
 -                              e1.printStackTrace();\r
 -                              status.message.emit(tr("User exception getting user account information.  Aborting sync and disconnecting"));\r
 -                              syncSignal.errorDisconnect.emit();\r
 -                              error = true;\r
 -                              enDisconnect();\r
 -                              return;\r
 -                      } catch (EDAMSystemException e1) {\r
 -                              e1.printStackTrace();\r
 -                              status.message.emit(tr("System error user account information.  Aborting sync and disconnecting!"));\r
 -                              syncSignal.errorDisconnect.emit();\r
 -                              error = true;\r
 -                              enDisconnect();\r
 -                              return;\r
 -                      } catch (TException e1) {\r
 -                              e1.printStackTrace();\r
 -                              syncSignal.errorDisconnect.emit();\r
 -                              error = true;\r
 -                              status.message.emit(tr("Transaction error getting user account information.  Aborting sync and disconnecting!"));\r
 -                              enDisconnect();\r
 -                              return;\r
 -                      }\r
 -                      \r
 -                      // Get sync state\r
 -                      SyncState syncState = null;\r
 -                      try {   \r
 -                              logger.log(logger.EXTREME, "Getting sync state");\r
 -                              syncState = noteStore.getSyncState(authToken);  \r
 -                              syncSignal.saveUploadAmount.emit(syncState.getUploaded());\r
 -                              syncSignal.saveEvernoteUpdateCount.emit(syncState.getUpdateCount());\r
 -                              evernoteUpdateCount = syncState.getUpdateCount();\r
 -                      } catch (EDAMUserException e) {\r
 -                              e.printStackTrace();\r
 -                              status.message.emit(tr("Error getting sync state! Aborting sync and disconnecting!"));\r
 -                              syncSignal.errorDisconnect.emit();\r
 -                              enDisconnect();\r
 -                              return;\r
 -                      } catch (EDAMSystemException e) {\r
 -                              e.printStackTrace();\r
 -                              status.message.emit(tr("Error getting sync state! Aborting sync and disconnecting!"));\r
 -                              syncSignal.errorDisconnect.emit();\r
 -                              enDisconnect();\r
 -                              return;\r
 -                      } catch (TException e) {\r
 -                              e.printStackTrace();\r
 -                              status.message.emit(tr("Error getting sync state! Aborting sync and disconnecting!"));\r
 -                              syncSignal.errorDisconnect.emit();\r
 -                              enDisconnect();\r
 -                              return;\r
 -                      }\r
 -                      \r
 -                      if (syncState == null) {\r
 -                              logger.log(logger.EXTREME, "Sync State is null");\r
 -                              status.message.emit(tr("Syncronization Error!"));\r
 -                              return;\r
 -                      }\r
 -\r
 -                      // Determine what to do. \r
 -                      // If we need to do a full sync.\r
 -                      logger.log(logger.LOW, "Full Sequence Before: " +syncState.getFullSyncBefore());\r
 -                      logger.log(logger.LOW, "Last Sequence Date: " +sequenceDate);\r
 -                      logger.log(logger.LOW, "Var Last Sequence Number: " +updateSequenceNumber);\r
 -                      logger.log(logger.LOW, "DB Last Sequence Number: " + conn.getSyncTable().getUpdateSequenceNumber());\r
 -                      if (syncState.getFullSyncBefore() > sequenceDate) {\r
 -                              logger.log(logger.EXTREME, "Full sequence date has expired");\r
 -                              sequenceDate = 0;\r
 -                              conn.getSyncTable().setLastSequenceDate(0);\r
 -                              updateSequenceNumber = 0;\r
 -                              conn.getSyncTable().setUpdateSequenceNumber(0);\r
 -                      }\r
 -                      // Check for "special" sync instructions\r
 -                      String syncLinked = conn.getSyncTable().getRecord("FullLinkedNotebookSync");\r
 -                      String syncShared = conn.getSyncTable().getRecord("FullSharedNotebookSync");\r
 -                      String syncNotebooks = conn.getSyncTable().getRecord("FullNotebookSync");\r
 -                      String syncInkNoteImages = conn.getSyncTable().getRecord("FullInkNoteImageSync");\r
 -                      if (syncLinked != null) {\r
 -                              downloadAllLinkedNotebooks(localNoteStore);\r
 -                      }\r
 -                      if (syncShared != null) {\r
 -                              downloadAllSharedNotebooks(localNoteStore);\r
 -                      }\r
 -                      if (syncNotebooks != null) {\r
 -                              downloadAllNotebooks(localNoteStore);\r
 -                      }\r
 -                      \r
 -                      if (syncInkNoteImages != null) {\r
 -                              List<String> guids = conn.getNoteTable().noteResourceTable.findInkNotes();\r
 -                              for (int i=0; i<guids.size(); i++) {\r
 -                                      downloadInkNoteImage(guids.get(i), authToken);\r
 -                              }\r
 -                              conn.getSyncTable().deleteRecord("FullInkNoteImageSync");\r
 -                      }\r
 -                      \r
 -                      // If there are remote changes\r
 -                      logger.log(logger.LOW, "Update Count: " +syncState.getUpdateCount());\r
 -                      logger.log(logger.LOW, "Last Update Count: " +updateSequenceNumber);\r
 -                      \r
 -                      if (syncState.getUpdateCount() > updateSequenceNumber) {\r
 -                              logger.log(logger.EXTREME, "Refresh needed is true");\r
 -                              refreshNeeded = true;\r
 -                              logger.log(logger.EXTREME, "Downloading changes");\r
 -                              syncRemoteToLocal(localNoteStore);\r
 -                      }\r
 -                      \r
 -                      //*****************************************\r
 -                      //* Sync linked/shared notebooks \r
 -                      //*****************************************\r
 -                      syncLinkedNotebooks();\r
 -                      //conn.getNoteTable().getDirty();\r
 -                      //disableUploads = true;   /// DELETE THIS LINE!!!!\r
 -                      if (!disableUploads) {\r
 -                              logger.log(logger.EXTREME, "Uploading changes");\r
 -                              // Synchronize remote changes\r
 -                              if (!error)\r
 -                                      syncExpunged(localNoteStore);\r
 -                              if (!error)\r
 -                                      syncLocalTags(localNoteStore);\r
 -                              if (!error)\r
 -                                      syncLocalNotebooks(localNoteStore);\r
 -                              if (!error)\r
 -                                      syncLocalLinkedNotebooks(localNoteStore);\r
 -                              if (!error) \r
 -                                      syncDeletedNotes(localNoteStore);\r
 -                              if (!error)\r
 -                                      syncLocalNotes();\r
 -                              if (!error)\r
 -                                      syncLocalSavedSearches(localNoteStore);\r
 -                      }\r
 -                      \r
 -                      status.message.emit(tr("Cleaning up"));\r
 -                      List<String> notes = conn.getNoteTable().expungeIgnoreSynchronizedNotes(conn.getSyncTable().getIgnoreRecords("NOTEBOOK"), \r
 -                                      conn.getSyncTable().getIgnoreRecords("TAG"), conn.getSyncTable().getIgnoreRecords("LINKEDNOTEBOOK"));\r
 -                      if (notes.size() > 0)\r
 -                              syncSignal.refreshLists.emit();\r
 -                      \r
 -                      //*****************************************\r
 -                      //* End of synchronization\r
 -                      //*****************************************\r
 -                      if (refreshNeeded)\r
 -                              syncSignal.refreshLists.emit();\r
 -                      \r
 -                      if (!error) {\r
 -                              logger.log(logger.LOW, "Sync completed.  Errors=" +error);\r
 -                              if (!disableUploads) \r
 -                                      status.message.emit(tr("Synchronizing complete"));\r
 -                              else\r
 -                                      status.message.emit(tr("Download syncronization complete.  Uploads have been disabled."));\r
 -                              \r
 -                              logger.log(logger.EXTREME, "Saving sync time");\r
 -                              if (syncState.getCurrentTime() > sequenceDate)\r
 -                                      sequenceDate = syncState.getCurrentTime();\r
 -                              if (syncState.getUpdateCount() > updateSequenceNumber)\r
 -                                      updateSequenceNumber = syncState.getUpdateCount();\r
 -                              conn.getSyncTable().setLastSequenceDate(sequenceDate);\r
 -                              conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
 -                      }\r
 -              }\r
 -              logger.log(logger.HIGH, "Leaving SyncRunner.evernoteSync");\r
 -      }\r
 -      \r
 -      // Sync deleted items with Evernote\r
 -      private void syncExpunged(Client noteStore) {\r
 -              logger.log(logger.HIGH, "Entering SyncRunner.syncExpunged");\r
 -              \r
 -              List<DeletedItemRecord> expunged = conn.getDeletedTable().getAllDeleted();\r
 -              boolean error = false;\r
 -              for (int i=0; i<expunged.size() && keepRunning; i++) {\r
 -\r
 -//                    if (authRefreshNeeded)\r
 -//                            if (!refreshConnection())\r
 -//                                    return;\r
 -\r
 -                      try {\r
 -                              if (expunged.get(i).type.equalsIgnoreCase("TAG")) {\r
 -                                      logger.log(logger.EXTREME, "Tag expunged");\r
 -                                      conn.getDeletedTable().expungeDeletedItem(expunged.get(i).guid, "TAG"); \r
 -                                      updateSequenceNumber = noteStore.expungeTag(authToken, expunged.get(i).guid);\r
 -                                      conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
 -                                      conn.getSyncTable().setLastSequenceDate(sequenceDate);\r
 -                                      conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);                              \r
 -                              }\r
 -                              if      (expunged.get(i).type.equalsIgnoreCase("NOTEBOOK")) {\r
 -                                      logger.log(logger.EXTREME, "Notebook expunged");\r
 -                                      conn.getDeletedTable().expungeDeletedItem(expunged.get(i).guid, "NOTEBOOK");\r
 -                                      updateSequenceNumber = noteStore.expungeNotebook(authToken, expunged.get(i).guid);\r
 -                                      conn.getSyncTable().setLastSequenceDate(sequenceDate);\r
 -                                      conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
 -                              }\r
 -                              if (expunged.get(i).type.equalsIgnoreCase("NOTE")) {\r
 -                                      logger.log(logger.EXTREME, "Note expunged");\r
 -                                      conn.getDeletedTable().expungeDeletedItem(expunged.get(i).guid, "NOTE");\r
 -                                      updateSequenceNumber = noteStore.deleteNote(authToken, expunged.get(i).guid);\r
 -                                      refreshNeeded = true;\r
 -                                      conn.getSyncTable().setLastSequenceDate(sequenceDate);\r
 -                                      conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
 -                              }\r
 -                              if (expunged.get(i).type.equalsIgnoreCase("SAVEDSEARCH")) {\r
 -                                      logger.log(logger.EXTREME, "saved search expunged");\r
 -                                      conn.getDeletedTable().expungeDeletedItem(expunged.get(i).guid, "SAVEDSEARCH");\r
 -                                      updateSequenceNumber = noteStore.expungeSearch(authToken, expunged.get(i).guid);\r
 -                                      conn.getSyncTable().setLastSequenceDate(sequenceDate);\r
 -                                      conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
 -                              }\r
 -                      } catch (EDAMUserException e) {\r
 -                              logger.log(logger.LOW, "EDAM User Excepton in syncExpunged: " +expunged.get(i).guid);   // This can happen if we try to delete a deleted note\r
 -                      } catch (EDAMSystemException e) {\r
 -                              logger.log(logger.LOW, "EDAM System Excepton in syncExpunged: "+expunged.get(i).guid);\r
 -                              logger.log(logger.LOW, e.getStackTrace());\r
 -                              error=true;\r
 -                      } catch (EDAMNotFoundException e) {\r
 -                              logger.log(logger.LOW, "EDAM Not Found Excepton in syncExpunged: "+expunged.get(i).guid);\r
 -                      } catch (TException e) {\r
 -                              logger.log(logger.LOW, "EDAM TExcepton in syncExpunged: "+expunged.get(i).guid);\r
 -                              logger.log(logger.LOW, e.getStackTrace());\r
 -                              error=true;\r
 -                      }\r
 -              }\r
 -              if (!error)\r
 -                      conn.getDeletedTable().expungeAllDeletedRecords();\r
 -              \r
 -              logger.log(logger.HIGH, "Leaving SyncRunner.syncExpunged");\r
 -\r
 -      }\r
 -      private void syncDeletedNotes(Client noteStore) {\r
 -              if (syncDeletedContent)\r
 -                      return;\r
 -              logger.log(logger.HIGH, "Entering SyncRunner.syncDeletedNotes");\r
 -              status.message.emit(tr("Synchronizing deleted notes."));\r
 -\r
 -              List<Note> notes = conn.getNoteTable().getDirty();\r
 -              // Sync the local notebooks with Evernote's\r
 -              for (int i=0; i<notes.size() && keepRunning; i++) {\r
 -                      \r
 -//                    if (authRefreshNeeded)\r
 -//                            if (!refreshConnection())\r
 -//                                    return;\r
 -                      \r
 -                      Note enNote = notes.get(i);\r
 -                      try {\r
 -                              if (enNote.getUpdateSequenceNum() > 0 && (enNote.isActive() == false || enNote.getDeleted() > 0)) {\r
 -                                      // Check that the note is valid.  \r
 -                                      if (enNote.isActive() == true || enNote.getDeleted() == 0) {\r
 -                                              conn.getNoteTable().deleteNote(enNote.getGuid());\r
 -                                              enNote = conn.getNoteTable().getNote(enNote.getGuid(), false, false, false, false, false);\r
 -                                      }\r
 -                                      if (syncDeletedContent) {\r
 -                                              logger.log(logger.EXTREME, "Deleted note found & synch content selected");\r
 -                                              Note delNote = conn.getNoteTable().getNote(enNote.getGuid(), true, true, true, true, true);\r
 -                                              delNote = getNoteContent(delNote);\r
 -                                              delNote = noteStore.updateNote(authToken, delNote);\r
 -                                              enNote.setUpdateSequenceNum(delNote.getUpdateSequenceNum());\r
 -                                              conn.getNoteTable().updateNoteSequence(enNote.getGuid(), enNote.getUpdateSequenceNum());\r
 -                                      } else {\r
 -                                              logger.log(logger.EXTREME, "Deleted note found & sync content not selected");\r
 -                                              int usn = noteStore.deleteNote(authToken, enNote.getGuid());\r
 -                                              enNote.setUpdateSequenceNum(usn);\r
 -                                              conn.getNoteTable().updateNoteSequence(enNote.getGuid(), enNote.getUpdateSequenceNum());                                                \r
 -                                      }\r
 -                                      logger.log(logger.EXTREME, "Resetting deleted dirty flag");\r
 -                                      conn.getNoteTable().resetDirtyFlag(enNote.getGuid());\r
 -                                      updateSequenceNumber = enNote.getUpdateSequenceNum();\r
 -                                      logger.log(logger.EXTREME, "Saving sequence number");\r
 -                                      conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
 -                              }                               \r
 -                      } catch (EDAMUserException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM User Excepton syncLocalNotes "+e);\r
 -                              //status.message.emit("Error sending local note: " +e.getParameter());\r
 -                              //logger.log(logger.LOW, e.toString()); \r
 -                              //error = true;\r
 -                      } catch (EDAMSystemException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM System Excepton syncLocalNotes "+e);\r
 -                              status.message.emit(tr("Error: ") +e);\r
 -                              logger.log(logger.LOW, e.toString());           \r
 -                              error = true;\r
 -                      } catch (EDAMNotFoundException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM Not Found Excepton syncLocalNotes " +e);\r
 -                              //status.message.emit("Error deleting local note: " +e +" - Continuing");\r
 -                              //logger.log(logger.LOW, e.toString());         \r
 -                              //error = true;\r
 -                      } catch (TException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM TExcepton syncLocalNotes "+e);\r
 -                              status.message.emit(tr("Error sending local note: ") +e);\r
 -                              logger.log(logger.LOW, e.toString());   \r
 -                              error = true;\r
 -                      }               \r
 -              }\r
 -      }\r
 -      // Sync notes with Evernote\r
 -      private void syncLocalNotes() {\r
 -              logger.log(logger.HIGH, "Entering SyncRunner.syncNotes");\r
 -              logger.log(logger.LOW, "Dirty local notes found: " +new Integer(conn.getNoteTable().getDirtyCount()).toString());\r
 -              status.message.emit(tr("Sending local notes."));\r
 -\r
 -              List<Note> notes = conn.getNoteTable().getDirty();\r
 -              // Sync the local notebooks with Evernote's\r
 -              for (int i=0; i<notes.size() && keepRunning; i++) {\r
 -                      syncLocalNote(localNoteStore, notes.get(i), authToken);\r
 -              }\r
 -              logger.log(logger.HIGH, "Leaving SyncRunner.syncNotes");\r
 -\r
 -      }\r
 -      // Sync notes with Evernote\r
 -      private void syncLocalNote(Client noteStore, Note enNote, String token) {\r
 -              logger.log(logger.HIGH, "Entering SyncRunner.syncNotes");\r
 -              status.message.emit(tr("Sending local notes."));\r
 -                      \r
 -              if (enNote.isActive()) {\r
 -                      try {\r
 -                              if (enNote.getUpdateSequenceNum() > 0) {\r
 -                                      logger.log(logger.EXTREME, "Active dirty note found - non new - " +enNote.getGuid());\r
 -                                      logger.log(logger.EXTREME, "Fetching note content");\r
 -                                      enNote = getNoteContent(enNote);\r
 -                                      logger.log(logger.MEDIUM, "Updating note : "+ enNote.getGuid() +" <title>" +enNote.getTitle()+"</title>");\r
 -                                      enNote = noteStore.updateNote(token, enNote);\r
 -                              } else { \r
 -                                      logger.log(logger.EXTREME, "Active dirty found - new note " +enNote.getGuid());\r
 -                                      String oldGuid = enNote.getGuid();\r
 -                                      logger.log(logger.MEDIUM, "Fetching note content");\r
 -                                      enNote = getNoteContent(enNote);\r
 -                                      logger.log(logger.MEDIUM, "Creating note : "+ enNote.getGuid() +" <title>" +enNote.getTitle()+"</title>");\r
 -                                      enNote = noteStore.createNote(token, enNote);\r
 -                                      logger.log(logger.MEDIUM, "New note Guid : "+ enNote.getGuid() +" <title>" +enNote.getTitle()+"</title>");\r
 -                                      noteSignal.guidChanged.emit(oldGuid, enNote.getGuid());\r
 -                                      conn.getNoteTable().updateNoteGuid(oldGuid, enNote.getGuid());\r
 -                              }\r
 -                              updateSequenceNumber = enNote.getUpdateSequenceNum();\r
 -                              logger.log(logger.EXTREME, "Saving note");\r
 -                              conn.getNoteTable().updateNoteSequence(enNote.getGuid(), enNote.getUpdateSequenceNum());\r
 -                              List<Resource> rl = enNote.getResources();\r
 -                              logger.log(logger.EXTREME, "Getting note resources");\r
 -                              for (int j=0; j<enNote.getResourcesSize() && keepRunning; j++) {\r
 -                                      Resource newRes = rl.get(j);\r
 -                                      Data d = newRes.getData();\r
 -                                      if (d!=null) {  \r
 -                                              logger.log(logger.EXTREME, "Calculating resource hash");\r
 -                                              String hash = byteArrayToHexString(d.getBodyHash());\r
 -                                              logger.log(logger.EXTREME, "updating resources by hash");\r
 -                                              String oldGuid = conn.getNoteTable().noteResourceTable.getNoteResourceGuidByHashHex(enNote.getGuid(), hash);\r
 -                                              conn.getNoteTable().updateNoteResourceGuidbyHash(enNote.getGuid(), newRes.getGuid(), hash);\r
 -                                              resourceSignal.resourceGuidChanged.emit(enNote.getGuid(), oldGuid, newRes.getGuid());\r
 -                                      }\r
 -                              }\r
 -                              logger.log(logger.EXTREME, "Resetting note dirty flag");\r
 -                              conn.getNoteTable().resetDirtyFlag(enNote.getGuid());\r
 -                              updateSequenceNumber = enNote.getUpdateSequenceNum();\r
 -                              logger.log(logger.EXTREME, "Emitting note sequence number change");\r
 -                              conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
 -\r
 -                      } catch (EDAMUserException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM User Excepton syncLocalNotes "+e);\r
 -                              status.message.emit(tr("Error sending local note: ")     +e.getParameter());\r
 -                              logger.log(logger.LOW, e.toString());   \r
 -                              error = true;\r
 -                      } catch (EDAMSystemException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM System Excepton syncLocalNotes "+e);\r
 -                              status.message.emit(tr("Error: ") +e);\r
 -                              logger.log(logger.LOW, e.toString());           \r
 -                              error = true;\r
 -                      } catch (EDAMNotFoundException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM Not Found Excepton syncLocalNotes " +e);\r
 -                              status.message.emit(tr("Error sending local note: ") +e);\r
 -                              logger.log(logger.LOW, e.toString());   \r
 -                              error = true;\r
 -                      } catch (TException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM TExcepton syncLocalNotes "+e);\r
 -                              status.message.emit(tr("Error sending local note: ") +e);\r
 -                              logger.log(logger.LOW, e.toString());   \r
 -                              error = true;\r
 -                      }\r
 -              }\r
 -              logger.log(logger.HIGH, "Leaving SyncRunner.syncLocalNote");\r
 -\r
 -      }\r
 -\r
 -      // Sync Notebooks with Evernote\r
 -      private void syncLocalNotebooks(Client noteStore) {\r
 -              logger.log(logger.HIGH, "Entering SyncRunner.syncLocalNotebooks");\r
 -              \r
 -              status.message.emit(tr("Sending local notebooks."));\r
 -              List<Notebook> remoteList = new ArrayList<Notebook>();\r
 -              try {\r
 -                      logger.log(logger.EXTREME, "Getting remote notebooks to compare with local");\r
 -                      remoteList = noteStore.listNotebooks(authToken);\r
 -              } catch (EDAMUserException e1) {\r
 -                      logger.log(logger.LOW, "*** EDAM User Excepton syncLocalNotebooks getting remote Notebook List");\r
 -                      status.message.emit(tr("Error: ") +e1);\r
 -                      logger.log(logger.LOW, e1.toString());          \r
 -                      error = true;\r
 -              } catch (EDAMSystemException e1) {\r
 -                      logger.log(logger.LOW, "*** EDAM System Excepton syncLocalNotebooks getting remote Notebook List");\r
 -                      status.message.emit(tr("Error: ") +e1);\r
 -                      logger.log(logger.LOW, e1.toString());  \r
 -                      error = true;\r
 -              } catch (TException e1) {\r
 -                      logger.log(logger.LOW, "*** EDAM Transaction Excepton syncLocalNotebooks getting remote Notebook List");\r
 -                      status.message.emit(tr("Error: ") +e1);\r
 -                      logger.log(logger.LOW, e1.toString());  \r
 -                      error = true;\r
 -              }\r
 -              logger.log(logger.EXTREME, "Getting local dirty notebooks");\r
 -              List<Notebook> notebooks = conn.getNotebookTable().getDirty();\r
 -              int sequence;\r
 -              // Sync the local notebooks with Evernote's\r
 -              for (int i=0; i<notebooks.size() && keepRunning; i++) {\r
 -                      \r
 -//                    if (authRefreshNeeded)\r
 -//                            if (!refreshConnection())\r
 -//                                    return;\r
 -                      \r
 -                      Notebook enNotebook = notebooks.get(i);\r
 -                      try {\r
 -                              if (enNotebook.getUpdateSequenceNum() > 0) {\r
 -                                      logger.log(logger.EXTREME, "Existing notebook is dirty");\r
 -                                      sequence = noteStore.updateNotebook(authToken, enNotebook);\r
 -                              } else {\r
 -                                      logger.log(logger.EXTREME, "New dirty notebook found");\r
 -                                      String oldGuid = enNotebook.getGuid();\r
 -                                      boolean found = false;\r
 -                                      \r
 -                                      // Look for a notebook with the same name.  If one is found, we don't need \r
 -                                      // to create another one\r
 -                                      logger.log(logger.EXTREME, "Looking for matching notebook name");\r
 -                                      for (int k=0; k<remoteList.size() && !found && keepRunning; k++) {\r
 -                                              if (remoteList.get(k).getName().equalsIgnoreCase(enNotebook.getName())) {\r
 -                                                      enNotebook = remoteList.get(k);\r
 -                                                      logger.log(logger.EXTREME, "Matching notebook found");\r
 -                                                      found = true;\r
 -                                              }\r
 -                                      }\r
 -                                      if (!found)\r
 -                                              enNotebook = noteStore.createNotebook(authToken, enNotebook);\r
 -                                      \r
 -                                      logger.log(logger.EXTREME, "Updating notebook in database");\r
 -                                      conn.getNotebookTable().updateNotebookGuid(oldGuid, enNotebook.getGuid());\r
 -                                      sequence = enNotebook.getUpdateSequenceNum();\r
 -                              }\r
 -                              logger.log(logger.EXTREME, "Updating notebook sequence in database");\r
 -                              conn.getNotebookTable().updateNotebookSequence(enNotebook.getGuid(), sequence);\r
 -                              logger.log(logger.EXTREME, "Resetting dirty flag in notebook");\r
 -                              conn.getNotebookTable().resetDirtyFlag(enNotebook.getGuid());\r
 -                              updateSequenceNumber = sequence;\r
 -                              logger.log(logger.EXTREME, "Emitting sequence number to main thread");\r
 -                              conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
 -                      } catch (EDAMUserException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM User Excepton syncLocalNotebooks");\r
 -                              logger.log(logger.LOW, e.toString() + ": Stack : " +enNotebook.getStack());     \r
 -                              error = true;\r
 -                      } catch (EDAMSystemException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM System Excepton syncLocalNotebooks");\r
 -                              logger.log(logger.LOW, e.toString());           \r
 -                              error = true;\r
 -                      } catch (EDAMNotFoundException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM Not Found Excepton syncLocalNotebooks");\r
 -                              logger.log(logger.LOW, e.toString());           \r
 -                              error = true;\r
 -                      } catch (TException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM TExcepton syncLocalNotebooks");\r
 -                              logger.log(logger.LOW, e.toString());   \r
 -                              error = true;\r
 -                      }               \r
 -              }\r
 -              logger.log(logger.HIGH, "Leaving SyncRunner.syncLocalNotebooks");\r
 -\r
 -      }\r
 -      // Sync Tags with Evernote\r
 -      private void syncLocalTags(Client noteStore) {\r
 -              logger.log(logger.HIGH, "Entering SyncRunner.syncLocalTags");\r
 -              List<Tag> remoteList = new ArrayList<Tag>();\r
 -              status.message.emit(tr("Sending local tags."));\r
 -              \r
 -              try {\r
 -                      logger.log(logger.EXTREME, "Getting remote tags to compare names with the local tags");\r
 -                      remoteList = noteStore.listTags(authToken);\r
 -              } catch (EDAMUserException e1) {\r
 -                      logger.log(logger.LOW, "*** EDAM User Excepton syncLocalTags getting remote Tag List");\r
 -                      status.message.emit(tr("Error: ") +e1);\r
 -                      logger.log(logger.LOW, e1.toString());  \r
 -                      error = true;\r
 -              } catch (EDAMSystemException e1) {\r
 -                      logger.log(logger.LOW, "*** EDAM System Excepton syncLocalTags getting remote Tag List");\r
 -                      status.message.emit(tr("Error: ") +e1);\r
 -                      logger.log(logger.LOW, e1.toString());          \r
 -                      error = true;\r
 -              } catch (TException e1) {\r
 -                      logger.log(logger.LOW, "*** EDAM Transaction Excepton syncLocalTags getting remote Tag List");\r
 -                      status.message.emit(tr("Error: ") +e1);\r
 -                      logger.log(logger.LOW, e1.toString());  \r
 -                      error = true;\r
 -              }               \r
 -              \r
 -              int sequence;\r
 -              \r
 -              if (badTagSync == null)\r
 -                      badTagSync = new HashMap<String,String>();\r
 -              else\r
 -                      badTagSync.clear();\r
 -              \r
 -              Tag enTag = findNextTag();\r
 -              \r
 -              // This is a hack.  Sometimes this function goes flookey and goes into a \r
 -              // perpetual loop.  This causes  NeverNote to flood Evernote's servers.\r
 -              // This is a safety valve to prevent unlimited loops.\r
 -              int maxCount = conn.getTagTable().getDirty().size()+10;\r
 -              int loopCount = 0;\r
 -              \r
 -              while(enTag!=null && loopCount < maxCount) {\r
 -                      loopCount++;\r
 -//                    if (authRefreshNeeded)\r
 -//                            if (!refreshConnection())\r
 -//                                    return;\r
 -\r
 -                      try {\r
 -                              if (enTag.getUpdateSequenceNum() > 0) {\r
 -                                      logger.log(logger.EXTREME, "Updating tag");\r
 -                                      sequence = noteStore.updateTag(authToken, enTag);\r
 -                              } else {\r
 -                                      \r
 -                                      // Look for a tag with the same name.  If one is found, we don't need \r
 -                                      // to create another one\r
 -                                      logger.log(logger.EXTREME, "New tag.  Comparing with remote names");\r
 -                                      boolean found = false;\r
 -                                      String oldGuid = enTag.getGuid();\r
 -                                      for (int k=0; k<remoteList.size() && !found && keepRunning; k++) {\r
 -                                              if (remoteList.get(k).getName().equalsIgnoreCase(enTag.getName())) {\r
 -                                                      conn.getTagTable().updateTagGuid(enTag.getGuid(), remoteList.get(k).getGuid());\r
 -                                                      enTag = remoteList.get(k);\r
 -                                                      logger.log(logger.EXTREME, "Matching tag name found");\r
 -                                                      found = true;\r
 -                                              }\r
 -                                      }\r
 -                                      if (!found)\r
 -                                              enTag = noteStore.createTag(authToken, enTag);\r
 -                                      else\r
 -                                              enTag.setUpdateSequenceNum(noteStore.updateTag(authToken,enTag));\r
 -                                      sequence = enTag.getUpdateSequenceNum();\r
 -                                      if (!oldGuid.equals(enTag.getGuid())) {\r
 -                                              logger.log(logger.EXTREME, "Updating tag guid");\r
 -                                              conn.getTagTable().updateTagGuid(oldGuid, enTag.getGuid());\r
 -                                      }\r
 -                              }\r
 -                              logger.log(logger.EXTREME, "Updating tag sequence number");\r
 -                              conn.getTagTable().updateTagSequence(enTag.getGuid(), sequence);\r
 -                              logger.log(logger.EXTREME, "Resetting tag dirty flag");\r
 -                              conn.getTagTable().resetDirtyFlag(enTag.getGuid());\r
 -                              logger.log(logger.EXTREME, "Emitting sequence number to the main thread.");\r
 -                              updateSequenceNumber = sequence;\r
 -                              conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
 -                      } catch (EDAMUserException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM User Excepton syncLocalTags: " +enTag.getName());\r
 -                              logger.log(logger.LOW, e.toString());\r
 -                              badTagSync.put(enTag.getGuid(),null);\r
 -                              error = true;\r
 -                      } catch (EDAMSystemException e) {\r
 -                              logger.log(logger.LOW, "** EDAM System Excepton syncLocalTags: " +enTag.getName());\r
 -                              logger.log(logger.LOW, e.toString());   \r
 -                              badTagSync.put(enTag.getGuid(),null);\r
 -                              error = true;\r
 -                      } catch (EDAMNotFoundException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM Not Found Excepton syncLocalTags: " +enTag.getName());\r
 -                              logger.log(logger.LOW, e.toString());\r
 -                              badTagSync.put(enTag.getGuid(),null);\r
 -                              error = true;\r
 -                      } catch (TException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM TExcepton syncLocalTags: " +enTag.getName());\r
 -                              logger.log(logger.LOW, e.toString());\r
 -                              badTagSync.put(enTag.getGuid(),null);\r
 -                              error = true;\r
 -                      }       \r
 -                      \r
 -                      // Find the next tag\r
 -                      logger.log(logger.EXTREME, "Finding next tag");\r
 -                      enTag = findNextTag();\r
 -              }\r
 -              logger.log(logger.HIGH, "Leaving SyncRunner.syncLocalTags");\r
 -      }\r
 -      private void syncLocalLinkedNotebooks(Client noteStore) {\r
 -              logger.log(logger.HIGH, "Entering SyncRunner.syncLocalLinkedNotebooks");\r
 -              \r
 -              List<String> list = conn.getLinkedNotebookTable().getDirtyGuids();\r
 -              for (int i=0; i<list.size(); i++) {\r
 -                      LinkedNotebook book = conn.getLinkedNotebookTable().getNotebook(list.get(i));\r
 -                      try {\r
 -                              noteStore.updateLinkedNotebook(authToken, book);\r
 -                      } catch (EDAMUserException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM User Excepton syncLocalLinkedNotebooks");\r
 -                              status.message.emit(tr("Error: ") +e);\r
 -                              logger.log(logger.LOW, e.toString());           \r
 -                              error = true;\r
 -                              e.printStackTrace();\r
 -                      } catch (EDAMNotFoundException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM Not Found Excepton syncLocalLinkedNotebooks");\r
 -                              status.message.emit(tr("Error: ") +e);\r
 -                              logger.log(logger.LOW, e.toString());           \r
 -                              error = true;\r
 -                              e.printStackTrace();\r
 -                      } catch (EDAMSystemException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM System Excepton syncLocalLinkedNotebooks");\r
 -                              status.message.emit(tr("Error: ") +e);\r
 -                              logger.log(logger.LOW, e.toString());           \r
 -                              error = true;\r
 -                              e.printStackTrace();\r
 -                      } catch (TException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM TExcepton syncLocalLinkedNotebooks");\r
 -                              status.message.emit(tr("Error: ") +e);\r
 -                              logger.log(logger.LOW, e.toString());           \r
 -                              error = true;\r
 -                              e.printStackTrace();\r
 -                      }\r
 -              }\r
 -              logger.log(logger.HIGH, "Leaving SyncRunner.syncLocalLinkedNotebooks");\r
 -      }\r
 -      // Sync Saved Searches with Evernote\r
 -      private void syncLocalSavedSearches(Client noteStore) {\r
 -              logger.log(logger.HIGH, "Entering SyncRunner.syncLocalSavedSearches");\r
 -              List<SavedSearch> remoteList = new ArrayList<SavedSearch>();\r
 -              status.message.emit(tr("Sending saved searches."));\r
 -      \r
 -              logger.log(logger.EXTREME, "Getting saved searches to compare with local");\r
 -              try {\r
 -                      remoteList = noteStore.listSearches(authToken);\r
 -              } catch (EDAMUserException e1) {\r
 -                      logger.log(logger.LOW, "*** EDAM User Excepton syncLocalTags getting remote saved search List");\r
 -                      status.message.emit(tr("Error: ") +e1);\r
 -                      logger.log(logger.LOW, e1.toString());  \r
 -                      error = true;\r
 -              } catch (EDAMSystemException e1) {\r
 -                      logger.log(logger.LOW, "*** EDAM System Excepton syncLocalTags getting remote saved search List");\r
 -                      status.message.emit(tr("Error: ") +e1);\r
 -                      logger.log(logger.LOW, e1.toString());          \r
 -                      error = true;\r
 -              } catch (TException e1) {\r
 -                      logger.log(logger.LOW, "*** EDAM Transaction Excepton syncLocalTags getting remote saved search List");\r
 -                      status.message.emit(tr("Error: ") +e1);\r
 -                      logger.log(logger.LOW, e1.toString());  \r
 -                      error = true;\r
 -              }               \r
 -              \r
 -              List<SavedSearch> searches = conn.getSavedSearchTable().getDirty();\r
 -              int sequence;\r
 -              // Sync the local notebooks with Evernote's\r
 -              logger.log(logger.EXTREME, "Beginning to send saved searches");\r
 -              for (int i=0; i<searches.size() &&  keepRunning; i++) {\r
 -                      \r
 -//                    if (authRefreshNeeded)\r
 -//                            if (!refreshConnection())\r
 -//                                    return;\r
 -                      \r
 -                      SavedSearch enSearch = searches.get(i);\r
 -                      try {\r
 -                              if (enSearch.getUpdateSequenceNum() > 0) \r
 -                                      sequence = noteStore.updateSearch(authToken, enSearch);\r
 -                              else {\r
 -                                      logger.log(logger.EXTREME, "New saved search found.");\r
 -                                      // Look for a tag with the same name.  If one is found, we don't need \r
 -                                      // to create another one\r
 -                                      boolean found = false;\r
 -                                      logger.log(logger.EXTREME, "Matching remote saved search names with local");\r
 -                                      for (int k=0; k<remoteList.size() && !found && keepRunning; k++) {\r
 -                                              if (remoteList.get(k).getName().equalsIgnoreCase(enSearch.getName())) {\r
 -                                                      enSearch = remoteList.get(k);\r
 -                                                      found = true;\r
 -                                                      logger.log(logger.EXTREME, "Matching saved search found");\r
 -                                                      sequence = enSearch.getUpdateSequenceNum();\r
 -                                              }\r
 -                                      }\r
 -\r
 -                                      String oldGuid = enSearch.getGuid();\r
 -                                      if (!found)\r
 -                                              enSearch = noteStore.createSearch(authToken, enSearch);\r
 -                                      sequence = enSearch.getUpdateSequenceNum();\r
 -                                      logger.log(logger.EXTREME, "Updating tag guid in local database");\r
 -                                      conn.getSavedSearchTable().updateSavedSearchGuid(oldGuid, enSearch.getGuid());\r
 -                              }\r
 -                              logger.log(logger.EXTREME, "Updating tag sequence in local database");\r
 -                              conn.getSavedSearchTable().updateSavedSearchSequence(enSearch.getGuid(), sequence);\r
 -                              logger.log(logger.EXTREME, "Resetting tag dirty flag");\r
 -                              conn.getSavedSearchTable().resetDirtyFlag(enSearch.getGuid());\r
 -                              logger.log(logger.EXTREME, "Emitting sequence number to the main thread.");\r
 -                              updateSequenceNumber = sequence;\r
 -                              conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
 -                      } catch (EDAMUserException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM User Excepton syncLocalTags");\r
 -                              logger.log(logger.LOW, e.toString());   \r
 -                              error = true;\r
 -                      } catch (EDAMSystemException e) {\r
 -                              logger.log(logger.LOW, "** EDAM System Excepton syncLocalTags");\r
 -                              logger.log(logger.LOW, e.toString());   \r
 -                              error = true;\r
 -                      } catch (EDAMNotFoundException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM Not Found Excepton syncLocalTags");\r
 -                              logger.log(logger.LOW, e.toString());   \r
 -                              error = true;\r
 -                      } catch (TException e) {\r
 -                              logger.log(logger.LOW, "*** EDAM TExcepton syncLocalTags");\r
 -                              logger.log(logger.LOW, e.toString());   \r
 -                              error = true;\r
 -                      }               \r
 -              }\r
 -\r
 -              logger.log(logger.HIGH, "Entering SyncRunner.syncLocalSavedSearches");\r
 -      }       \r
 -\r
 -      // Sync evernote changes with local database\r
 -      private void syncRemoteToLocal(Client noteStore) {\r
 -              logger.log(logger.HIGH, "Entering SyncRunner.syncRemoteToLocal");\r
 -\r
 -              List<Note> dirtyNotes = conn.getNoteTable().getDirty();\r
 -              dirtyNoteGuids = new ArrayList<String>();\r
 -              for (int i=0; i<dirtyNotes.size() && keepRunning; i++) {\r
 -                      dirtyNoteGuids.add(dirtyNotes.get(i).getGuid());\r
 -              }\r
 -