OSDN Git Service

- Added the ability to do special refreshes for debugging. - Added the ability to...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / Global.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote;\r
21 \r
22 \r
23 import java.io.ByteArrayInputStream;\r
24 import java.io.ByteArrayOutputStream;\r
25 import java.io.IOException;\r
26 import java.io.ObjectInputStream;\r
27 import java.io.ObjectOutputStream;\r
28 import java.text.SimpleDateFormat;\r
29 import java.util.ArrayList;\r
30 import java.util.Calendar;\r
31 import java.util.HashMap;\r
32 import java.util.List;\r
33 \r
34 import org.apache.commons.lang.StringEscapeUtils;\r
35 \r
36 import com.evernote.edam.type.Accounting;\r
37 import com.evernote.edam.type.PrivilegeLevel;\r
38 import com.evernote.edam.type.User;\r
39 import com.evernote.edam.type.UserAttributes;\r
40 import com.swabunga.spell.engine.Configuration;\r
41 import com.trolltech.qt.core.QByteArray;\r
42 import com.trolltech.qt.core.QSettings;\r
43 import com.trolltech.qt.core.QSize;\r
44 import com.trolltech.qt.gui.QPalette;\r
45 \r
46 import cx.fbn.nevernote.config.FileManager;\r
47 import cx.fbn.nevernote.config.InitializationException;\r
48 import cx.fbn.nevernote.config.StartupConfig;\r
49 import cx.fbn.nevernote.gui.ContainsAttributeFilterTable;\r
50 import cx.fbn.nevernote.gui.DateAttributeFilterTable;\r
51 import cx.fbn.nevernote.gui.ShortcutKeys;\r
52 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
53 import cx.fbn.nevernote.utilities.Pair;\r
54 \r
55 \r
56 //*****************************************************\r
57 //*****************************************************\r
58 //* Global constants & static functions used by \r
59 //* multiple threads.\r
60 //*****************************************************\r
61 //*****************************************************\r
62 \r
63 public class Global {\r
64         // Set current version and the known versions.\r
65         public static String version = "0.99";\r
66         public static String[] validVersions = {"0.99", "0.98", "0.97", "0.96"};\r
67     public static String username = ""; \r
68     public static String password = "";     \r
69     \r
70 \r
71     // Each thread has an ID.  This is used primarily to check the status\r
72     // of running threads.\r
73     public static final int mainThreadId=0;\r
74     public static final int syncThreadId=1;\r
75     public static final int tagCounterThreadId=2;\r
76     public static final int trashCounterThreadId=3;   // This should always be the highest thread ID\r
77     public static final int indexThreadId=4;    // Thread for indexing words\r
78     public static final int saveThreadId=5;     // Thread used for processing data to saving content\r
79     public static final int notebookCounterThreadId=6;   // Notebook Thread\r
80     public static final int indexThread03Id=7;   // unused\r
81     public static final int indexThread04Id=8;   // unused\r
82     public static final int dbThreadId=9;   // This should always be the highest thread ID\r
83     public static final int threadCount = 10;\r
84     \r
85     \r
86     // These variables deal with where the list of notes appears\r
87     // They will either be vertical (View_List_Narrow) or will be\r
88     // on top of the note (View_List_Wide).  It also has the size of\r
89     // thumbnails displayed in each view\r
90     public static int View_List_Wide = 1;\r
91     public static int View_List_Narrow = 2;\r
92     public static QSize smallThumbnailSize = new QSize(100,75);\r
93     public static QSize largeThumbnailSize = new QSize(300,225);\r
94 \r
95     // This is used to keep a running list of passwords that the user\r
96     // wants us to remember.\r
97     public static HashMap<String,Pair<String,String>> passwordSafe = new HashMap<String, Pair<String,String>>();\r
98     public static List<Pair<String,String>> passwordRemember = new ArrayList<Pair<String,String>>();\r
99     \r
100     \r
101     //public static String currentNotebookGuid;\r
102     \r
103     // These deal with Evernote user settings\r
104     public static User user; \r
105     public static long authTimeRemaining;\r
106     public static long authRefreshTime;\r
107     public static long failedRefreshes = 0; \r
108     public static String userStoreUrl;\r
109     public static String noteStoreUrl;\r
110     public static String noteStoreUrlBase;\r
111 \r
112     // When we want to shut down we set this to true to short\r
113     // circut other threads\r
114     public static boolean keepRunning;\r
115         \r
116     // In the note list, these are the column numbers\r
117     // so I don't need to hard code numbers.\r
118     public static int noteTableCreationPosition = 0;\r
119     public static int noteTableTitlePosition = 1;\r
120     public static int noteTableTagPosition = 2;\r
121     public static int noteTableNotebookPosition = 3;\r
122     public static int noteTableChangedPosition = 4;\r
123     public static int noteTableGuidPosition = 5;\r
124     public static int noteTableAuthorPosition = 6;\r
125     public static int noteTableSourceUrlPosition = 7;\r
126     public static int noteTableSubjectDatePosition = 8;\r
127     public static int noteTableSynchronizedPosition = 9;\r
128     public static int noteTableThumbnailPosition = 10;\r
129     public static int noteTableColumnCount = 11;\r
130     public static Integer cryptCounter = 0;\r
131     \r
132     //public static int minimumWordCount = 2;\r
133     \r
134     // Regular expression to parse text with when indexing\r
135     private static String wordRegex;\r
136     \r
137     // Experimental fixes.  Set via Edit/Preferences/Debugging\r
138     public static boolean enableCarriageReturnFix = false;\r
139     public static boolean enableHTMLEntitiesFix = false;\r
140     \r
141     //public static String name = null;   \r
142     \r
143     // Used to set & retrieve ini & Windows registry settings\r
144     public static QSettings     settings;     // Set & get ini settings\r
145     public static boolean isConnected;    // Are we connected to Evernote\r
146     public static boolean showDeleted = false;   // Show deleted notes?\r
147     public static boolean disableUploads = false;  // Should we disable uploads (used in testing features)\r
148         public static int messageLevel;   // The level of messages to write to the log files\r
149         public static String tagDelimeter = ",";   // This is used to separate out tag names when entering above note\r
150         public static String attachmentNameDelimeter = "------";  // Used to separate out attachment names in the res directory\r
151         \r
152         \r
153         //* Database fields\r
154         public static String    databaseName = new String("NeverNote");  // database name.  used for multiple databases to separate settings.\r
155         public static String    indexDatabaseName = new String("Index"); // searchable words database\r
156         public static String    resourceDatabaseName = new String("Resources");  // attachments database\r
157         public static DateAttributeFilterTable createdSinceFilter;\r
158         public static DateAttributeFilterTable createdBeforeFilter;\r
159         public static DateAttributeFilterTable changedSinceFilter;\r
160         public static DateAttributeFilterTable changedBeforeFilter;\r
161         public static ContainsAttributeFilterTable containsFilter;\r
162         \r
163         // Log file used for debugging\r
164         public static ApplicationLogger    logger;\r
165         //PrintStream stdoutStream;\r
166         \r
167         // Application key shortcuts & appearance\r
168         public static QPalette                          originalPalette;\r
169         public static ShortcutKeys                      shortcutKeys;\r
170         \r
171         public static boolean                           disableViewing;  // used to disable the editor\r
172         \r
173         // When saving a note, this is a list of things we strip out because Evernote hates them\r
174         public static List<String>                              invalidElements = new ArrayList<String>();\r
175         public static HashMap<String, ArrayList<String>>        invalidAttributes = new HashMap<String, ArrayList<String>>();\r
176         \r
177         public static boolean mimicEvernoteInterface; // Try to mimic Evernote or allow multiple notebook selection\r
178         public static HashMap<String,String> resourceMap;   // List of attachments for a note.\r
179         public static String cipherPassword = "";    // If the database is encrypted, this stores the password\r
180         public static String databaseCache = "16384";  // Default DB cache size\r
181         \r
182         // These are used for performance testing\r
183         static Calendar startTraceTime;   \r
184         static Calendar intervalTraceTime;\r
185         \r
186         private static FileManager fileManager;  // Used to access files & directories\r
187         \r
188     // Do initial setup \r
189     public static void setup(StartupConfig startupConfig) throws InitializationException  {\r
190         settings = new QSettings("fbn.cx", startupConfig.getName());\r
191         disableViewing = startupConfig.getDisableViewing();\r
192 \r
193         fileManager = new FileManager(startupConfig.getHomeDirPath(), startupConfig.getProgramDirPath());\r
194 \r
195 \r
196                 getServer();  // Setup URL to connect to\r
197                 \r
198                 // Get regular expressions used to parse out words\r
199                 settings.beginGroup("General");\r
200                 String regex = (String) settings.value("regex", "[,\\s]+");\r
201                 setWordRegex(regex);\r
202                 settings.endGroup();\r
203                 \r
204                 // Setup debugging information\r
205                 //settings.beginGroup("Debug");\r
206                 //String msglevel = (String) settings.value("messageLevel", "Low");\r
207                 //settings.endGroup();\r
208                 \r
209                 \r
210                 //messageLevel = 1;\r
211                 //setMessageLevel(msglevel);\r
212                 keepRunning = true;  // Make sure child threads stay running\r
213                 disableUploads = disableUploads();  // Should we upload anything?  Normally true.\r
214                 enableCarriageReturnFix = enableCarriageReturnFix();  // Enable test fix?\r
215                 enableHTMLEntitiesFix = enableHtmlEntitiesFix();  // Enable test fix?\r
216                 \r
217                 logger = new ApplicationLogger("global.log");  // Setup log for this class \r
218                 shortcutKeys = new ShortcutKeys();  // Setup keyboard shortcuts.\r
219                 mimicEvernoteInterface = getMimicEvernoteInterface();  // Should we mimic Evernote's notebook behavior\r
220                 resourceMap = new HashMap<String,String>();  // Setup resource map used to store attachments when editing\r
221                         \r
222                 databaseCache = getDatabaseCacheSize();  // Set database cache size     \r
223     }\r
224 \r
225     // Get/Set word parsing regular expression\r
226     public static String getWordRegex() {\r
227         return wordRegex;\r
228     }\r
229     public static void setWordRegex(String r) {\r
230         wordRegex = r;\r
231     }\r
232 \r
233    // Set the debug message level\r
234    public static void setMessageLevel(String msglevel) {\r
235         if (msglevel.equalsIgnoreCase("low")) \r
236                         messageLevel = 1;\r
237                 if (msglevel.equalsIgnoreCase("medium")) \r
238                         messageLevel = 2;\r
239                 if (msglevel.equalsIgnoreCase("high")) \r
240                                 messageLevel = 3;\r
241                 if (msglevel.equalsIgnoreCase("extreme")) \r
242                                         messageLevel = 4;\r
243                 settings.beginGroup("Debug");\r
244                 settings.setValue("messageLevel", msglevel);\r
245                 settings.endGroup();            \r
246     }\r
247 \r
248    //****************************************************\r
249    //****************************************************\r
250    //** Save user account information from Evernote\r
251    //****************************************************\r
252    //****************************************************\r
253     public static void saveUserInformation(User user) {\r
254         settings.beginGroup("User");\r
255                 settings.setValue("id", user.getId());\r
256                 settings.setValue("username", user.getUsername());\r
257                 settings.setValue("email", user.getEmail());\r
258                 settings.setValue("name", user.getName());\r
259                 settings.setValue("timezone", user.getTimezone());\r
260                 settings.setValue("privilege", user.getPrivilege().getValue());\r
261                 settings.setValue("created", user.getCreated());\r
262                 settings.setValue("updated", user.getUpdated());\r
263                 settings.setValue("deleted", user.getDeleted());\r
264                 settings.endGroup();\r
265                 isPremium();\r
266                 if (user.getAttributes()!=null)\r
267                         saveUserAttributes(user.getAttributes());\r
268                 if (user.getAccounting()!=null)\r
269                         saveUserAccounting(user.getAccounting());\r
270 \r
271     }\r
272     public static void saveUserAttributes(UserAttributes attrib) {\r
273         settings.beginGroup("UserAttributes");\r
274                 settings.setValue("defaultLocationName", attrib.getDefaultLocationName());\r
275                 settings.setValue("defaultLatitude", attrib.getDefaultLocationName());\r
276                 settings.setValue("defaultLongitude", attrib.getDefaultLocationName());\r
277                 settings.setValue("incomingEmailAddress", attrib.getIncomingEmailAddress());\r
278                 settings.endGroup();\r
279     }\r
280     public static UserAttributes getUserAttributes() {\r
281         settings.beginGroup("UserAttributes");\r
282         UserAttributes attrib = new UserAttributes();\r
283                 attrib.setDefaultLocationName((String)settings.value("defaultLocationName",""));\r
284                 attrib.setDefaultLatitudeIsSet(false);\r
285                 attrib.setDefaultLongitudeIsSet(false);\r
286                 attrib.setIncomingEmailAddress((String)settings.value("incomingEmailAddress", ""));\r
287                 settings.endGroup();\r
288                 return attrib;\r
289     }\r
290     public static void saveUserAccounting(Accounting acc) {\r
291         settings.beginGroup("UserAccounting");\r
292                 settings.setValue("uploadLimit", acc.getUploadLimit());\r
293                 settings.setValue("uploadLimitEnd", acc.getUploadLimitEnd());\r
294                 settings.setValue("uploadLimitNextMonth", acc.getUploadLimitNextMonth());\r
295                 settings.setValue("premiumServiceStart", acc.getPremiumServiceStart());\r
296                 settings.setValue("nextPaymentDue", acc.getNextPaymentDue());\r
297                 settings.setValue("uploadAmount", acc.getUpdated());\r
298                 settings.endGroup();\r
299     }\r
300     public static long getUploadLimitEnd() {\r
301         Long limit;\r
302         settings.beginGroup("UserAccounting");\r
303         \r
304         // Upload limit\r
305                 try {\r
306                         String val  = (String)settings.value("uploadLimitEnd", "0");\r
307                         limit = new Long(val.trim());\r
308                 } catch (Exception e) {\r
309                         try {\r
310                                 limit = (Long)settings.value("uploadLimitEnd", 0);\r
311                         } catch (Exception e1) {\r
312                                 limit = new Long(0);\r
313                         }\r
314                 }\r
315         \r
316                 // return value\r
317         settings.endGroup();\r
318         return limit;\r
319     }\r
320     public static void saveUploadAmount(long amount) {\r
321         settings.beginGroup("UserAccounting");\r
322                 settings.setValue("uploadAmount", amount);\r
323                 settings.endGroup();\r
324    }\r
325     public static long getUploadAmount() {\r
326                 long amt=0;\r
327                 settings.beginGroup("UserAccounting");\r
328                 try {\r
329                         String num = (String)settings.value("uploadAmount", "0");\r
330                         amt = new Long(num.trim());\r
331                 } catch (Exception e) {\r
332                         try {\r
333                                 amt = (Integer)settings.value("uploadAmount", 0);\r
334                         } catch (Exception e1) {\r
335                                 amt = 0;\r
336                         }\r
337                 }\r
338                 settings.endGroup();\r
339                 return amt;\r
340     }\r
341     public static void saveEvernoteUpdateCount(long amount) {\r
342         settings.beginGroup("UserAccounting");\r
343                 settings.setValue("updateCount", amount);\r
344                 settings.endGroup();\r
345     }\r
346     public static long getEvernoteUpdateCount() {\r
347                 long amt;\r
348                 settings.beginGroup("UserAccounting");\r
349                 try {\r
350                         String num = (String)settings.value("updateCount", new Long(0).toString());\r
351                         amt = new Long(num.trim());\r
352                 } catch (java.lang.ClassCastException e) {\r
353                         amt = 0;\r
354                 }\r
355                 settings.endGroup();\r
356                 return amt;\r
357     }\r
358     public static boolean isPremium() {\r
359                 int level;\r
360                 settings.beginGroup("User");\r
361                 try {\r
362                         String num = (String)settings.value("privilege", "1");\r
363                         level = new Integer(num.trim());\r
364                 } catch (java.lang.ClassCastException e) {\r
365                         try {\r
366                                 level = (Integer)settings.value("privilege", 1);\r
367                         } catch (Exception e1) {\r
368                                 level = 1;\r
369                         }\r
370                 }\r
371                 settings.endGroup();\r
372                 PrivilegeLevel userLevel = PrivilegeLevel.findByValue(level);\r
373                 if (userLevel == PrivilegeLevel.NORMAL)\r
374                         return false;\r
375                 return true;\r
376                 \r
377    }\r
378     public static long getUploadLimit() {\r
379                 settings.beginGroup("UserAccounting");\r
380                 long limit;\r
381                 try {\r
382                         String num = (String)settings.value("uploadLimit", new Long(0).toString());\r
383                         limit = new Long(num.trim());\r
384                 } catch (java.lang.ClassCastException e) {\r
385                         limit = 0;\r
386                 }\r
387                 settings.endGroup();\r
388                 return limit;\r
389     }\r
390 \r
391     \r
392     \r
393     //****************************************************\r
394     //****************************************************\r
395     //** View settings.  Used to restore settings \r
396     //** when starting and to control how the program\r
397     //** behaves.\r
398     //****************************************************\r
399     //****************************************************\r
400     \r
401     //* Get/Set if we should show a tray icon\r
402     public static boolean showTrayIcon() {\r
403                 settings.beginGroup("General");\r
404                 try {\r
405                         String max = (String) settings.value("showTrayIcon", "false");\r
406                         settings.endGroup();\r
407                         if (!max.equalsIgnoreCase("true"))\r
408                                 return false;\r
409                         else\r
410                                 return true;    \r
411                 } catch (java.lang.ClassCastException e) {\r
412                         Boolean value = (Boolean) settings.value("showTrayIcon", false);\r
413                         settings.endGroup();\r
414                         return value;\r
415                 }\r
416     }\r
417     public static void setShowTrayIcon(boolean val) {\r
418                 settings.beginGroup("General");\r
419                 if (val)\r
420                         settings.setValue("showTrayIcon", "true");\r
421                 else\r
422                         settings.setValue("showTrayIcon", "false");\r
423                 settings.endGroup();\r
424     }\r
425     \r
426     // Get/Set window maximized when closed last\r
427     public static boolean wasWindowMaximized() {\r
428         try {\r
429                         settings.beginGroup("General");\r
430                         String max = (String) settings.value("isMaximized", "true");\r
431                         settings.endGroup();\r
432                         if (!max.equalsIgnoreCase("true"))\r
433                                 return false;\r
434                         return true;    \r
435                 } catch (java.lang.ClassCastException e) {\r
436                         Boolean value = (Boolean) settings.value("isMaximized", true);\r
437                         settings.endGroup();\r
438                         return value;\r
439                 }\r
440     }\r
441     public static void saveWindowMaximized(boolean isMax) {\r
442                 settings.beginGroup("General");\r
443                 if (isMax)\r
444                         settings.setValue("isMaximized", "true");\r
445                 else\r
446                         settings.setValue("isMaximized", "false");\r
447                 settings.endGroup();\r
448     }\r
449     \r
450     // Get/set currently viewed note Guid\r
451     public static String getLastViewedNoteGuid() {\r
452                 settings.beginGroup("General");\r
453                 String guid = (String) settings.value("lastViewedNote", "");\r
454                 settings.endGroup();\r
455                 return guid;    \r
456     }\r
457     public static void saveCurrentNoteGuid(String guid) {\r
458                 settings.beginGroup("General");\r
459                 if (guid != null)\r
460                         settings.setValue("lastViewedNote", guid);\r
461                 else\r
462                         settings.setValue("lastViewedNote", "");\r
463                 settings.endGroup();\r
464     }\r
465     \r
466     // Get/Set the note column we are sorted on and the order\r
467     public static void setSortColumn(int i) {\r
468         int view = Global.getListView();\r
469                 settings.beginGroup("General");\r
470         if (view == Global.View_List_Wide)\r
471                 settings.setValue("sortColumn", i);\r
472         else\r
473                 settings.setValue("sortColumn-Narrow", i);\r
474                 settings.endGroup();\r
475     }\r
476     public static int getSortColumn() {;\r
477     String key;\r
478         if (Global.getListView() == Global.View_List_Wide)\r
479                 key = "sortColumn";\r
480         else\r
481                 key = "sortColumn-Narrow";\r
482 \r
483         settings.beginGroup("General");\r
484         int order;      \r
485         try {\r
486                 String val  = settings.value(key, new Integer(0)).toString();\r
487                 order = new Integer(val.trim());\r
488         } catch (Exception e) {\r
489                 try {\r
490                         order = (Integer)settings.value(key, 0);\r
491                 } catch (Exception e1) {\r
492                     order = 0;\r
493                 }\r
494         }\r
495         \r
496         settings.endGroup();\r
497         return order;\r
498     }\r
499     public static void setSortOrder(int i) {\r
500         int view = Global.getListView();\r
501                 settings.beginGroup("General");\r
502         if (view == Global.View_List_Wide)\r
503                 settings.setValue("sortOrder", i);\r
504         else\r
505                 settings.setValue("sortOrder-Narrow", i);\r
506                 settings.endGroup();\r
507     }\r
508     public static int getSortOrder() {\r
509         int view = Global.getListView();\r
510                 settings.beginGroup("General");\r
511                 String key;\r
512         if (view == Global.View_List_Wide)\r
513                 key = "sortOrder";\r
514                 else\r
515                         key = "sortOrder-Narrow";\r
516 \r
517                 int order;      \r
518                 try {\r
519                         String val  = settings.value(key, new Integer(0)).toString();\r
520                         order = new Integer(val.trim());\r
521                 } catch (Exception e) {\r
522                         try {\r
523                                 order = (Integer)settings.value(key, 0);\r
524                         } catch (Exception e1) {\r
525                             order = 0;\r
526                         }\r
527                 }\r
528                 \r
529                 settings.endGroup();\r
530                 return order;\r
531     }\r
532     \r
533     // Should we automatically log in to Evernote when starting?\r
534     public static boolean automaticLogin() {\r
535         try {\r
536                 settings.beginGroup("General");\r
537                 String text = (String)settings.value("automaticLogin", "false");\r
538                 settings.endGroup();\r
539                 if (text.equalsIgnoreCase("true"))\r
540                         return true;\r
541                 else\r
542                         return false;           \r
543         } catch (java.lang.ClassCastException e) {\r
544                 Boolean value = (Boolean) settings.value("automaticLogin", false);\r
545                 settings.endGroup();\r
546                 return value;\r
547         }\r
548     }\r
549     public static void setAutomaticLogin(boolean val) {\r
550                 settings.beginGroup("General");\r
551                 if (val)\r
552                         settings.setValue("automaticLogin", "true");\r
553                 else\r
554                         settings.setValue("automaticLogin", "false");\r
555                 settings.endGroup();\r
556     }\r
557     \r
558     // Should it save the Evernote password?\r
559     public static boolean rememberPassword() {\r
560         try {\r
561                         settings.beginGroup("General");\r
562                         String text = (String)settings.value("rememberPassword", "false");\r
563                         settings.endGroup();\r
564                         if (text.equalsIgnoreCase("true"))\r
565                                 return true;\r
566                         else\r
567                                 return false;   \r
568                 } catch (java.lang.ClassCastException e) {\r
569                         Boolean value = (Boolean) settings.value("rememberPassword", false);\r
570                         settings.endGroup();\r
571                         return value;\r
572                 }\r
573     }\r
574     public static void setRememberPassword(boolean val) {\r
575                 settings.beginGroup("General");\r
576                 if (val)\r
577                         settings.setValue("rememberPassword", "true");\r
578                 else\r
579                         settings.setValue("rememberPassword", "false");\r
580                 settings.endGroup();\r
581     }\r
582 \r
583     // Get/set the Evernote server Url.  \r
584     public static void setServer(String server) {\r
585                 settings.beginGroup("General");\r
586                 settings.setValue("server", server);\r
587                 settings.endGroup();            \r
588     }\r
589     public static String getServer() {\r
590                 settings.beginGroup("General");\r
591                 String text = (String)settings.value("server", "www.evernote.com");\r
592                 if (text.equals("www.evernote.com")) {\r
593                         userStoreUrl = "https://www.evernote.com/edam/user";\r
594                     noteStoreUrlBase = "www.evernote.com/edam/note/";   \r
595                 } else {\r
596                         userStoreUrl = "https://sandbox.evernote.com/edam/user";\r
597                         noteStoreUrlBase = "sandbox.evernote.com/edam/note/";\r
598                 }\r
599                 settings.endGroup();\r
600 //              if (isPremium())\r
601                         noteStoreUrlBase = "https://" + noteStoreUrlBase;\r
602 //              else\r
603 //                      noteStoreUrlBase = "http://" + noteStoreUrlBase;\r
604                 return text;\r
605     }\r
606 \r
607     // Get/Set if we should disable uploads to Evernote\r
608     public static boolean disableUploads() {\r
609         settings.beginGroup("General");\r
610         try {\r
611                 String text = (String)settings.value("disableUploads", "false");\r
612                 settings.endGroup();\r
613                 if (text.equalsIgnoreCase("true"))\r
614                         return true;\r
615                 else\r
616                         return false;\r
617                 } catch (java.lang.ClassCastException e) {\r
618                         Boolean value = (Boolean) settings.value("disableUploads", false);\r
619                         settings.endGroup();\r
620                         return value;\r
621                 }\r
622     }\r
623     public static void setDisableUploads(boolean val) {\r
624                 settings.beginGroup("General");\r
625                 if (val)\r
626                         settings.setValue("disableUploads", "true");\r
627                 else\r
628                         settings.setValue("disableUploads", "false");\r
629                 settings.endGroup();\r
630                 disableUploads = val;\r
631     }\r
632  \r
633     // Should we view PDF documents inline?\r
634     public static boolean pdfPreview() {\r
635                 settings.beginGroup("General");\r
636                 try {\r
637                         String text = (String)settings.value("pdfPreview", "true");\r
638                         settings.endGroup();\r
639                         if (text.equalsIgnoreCase("true"))\r
640                                 return true;\r
641                         else\r
642                                 return false;\r
643                 } catch (java.lang.ClassCastException e) {\r
644                         Boolean value = (Boolean) settings.value("pdfPreview", true);\r
645                         settings.endGroup();\r
646                         return value;\r
647                 }\r
648     }\r
649     public static void setPdfPreview(boolean val) {\r
650                 settings.beginGroup("General");\r
651                 if (val)\r
652                         settings.setValue("pdfPreview", "true");\r
653                 else\r
654                         settings.setValue("pdfPreview", "false");\r
655                 settings.endGroup();\r
656     }\r
657     \r
658     // When creating a new note, should it inherit tags that are currently selected?\r
659     public static boolean newNoteWithSelectedTags() {\r
660                 settings.beginGroup("General");\r
661                 try {\r
662                         String text = (String)settings.value("newNoteWithSelectedTags", "false");\r
663                         settings.endGroup();\r
664                         if (text.equalsIgnoreCase("true"))\r
665                                 return true;\r
666                         else\r
667                                 return false;\r
668                 } catch (java.lang.ClassCastException e) {\r
669                         Boolean value = (Boolean) settings.value("newNoteWithSelectedTags", false);\r
670                         settings.endGroup();\r
671                         return value;\r
672                 }\r
673     }\r
674     public static void setNewNoteWithSelectedTags(boolean val) {\r
675                 settings.beginGroup("General");\r
676                 if (val)\r
677                         settings.setValue("newNoteWithSelectedTags", "true");\r
678                 else\r
679                         settings.setValue("newNoteWithSelectedTags", "false");\r
680                 settings.endGroup();\r
681     }\r
682     \r
683     // Minimum weight for text OCRed from Evernote. Anything below this\r
684     // Won't be shown to the user when they search\r
685     public static void setRecognitionWeight(int len) {\r
686                 settings.beginGroup("General");\r
687                 settings.setValue("recognitionWeight", len);\r
688                 settings.endGroup();            \r
689     }\r
690     public static int getRecognitionWeight() {\r
691                 settings.beginGroup("General");\r
692                 Integer len;\r
693                 try {\r
694                         len = (Integer)settings.value("recognitionWeight", 30);\r
695                 } catch (Exception e) {\r
696                         len = 80;\r
697                 }\r
698                 settings.endGroup();\r
699                 return len;\r
700     }\r
701     \r
702     // get/set current debug message level\r
703     public static String getMessageLevel() {\r
704                 settings.beginGroup("Debug");\r
705                 String text = (String)settings.value("messageLevel", "Low");\r
706                 settings.endGroup();\r
707                 return text;\r
708     }\r
709     public static void setDateFormat(String format) {\r
710                 settings.beginGroup("General");\r
711                 settings.setValue("dateFormat", format);\r
712                 settings.endGroup();            \r
713     }\r
714     \r
715     // Get/Set user date/time formats\r
716     public static String getDateFormat() {\r
717                 settings.beginGroup("General");\r
718                 String text = (String)settings.value("dateFormat", "MM/dd/yyyy");\r
719                 settings.endGroup();\r
720                 return text;\r
721     }\r
722     public static void setTimeFormat(String format) {\r
723                 settings.beginGroup("General");\r
724                 settings.setValue("timeFormat", format);\r
725                 settings.endGroup();            \r
726     }\r
727     public static String getTimeFormat() {\r
728                 settings.beginGroup("General");\r
729                 String text = (String)settings.value("timeFormat", "HH:mm:ss");\r
730                 settings.endGroup();\r
731                 return text;\r
732     }\r
733     \r
734     // How often should we sync with Evernote?\r
735     public static String getSyncInterval() {\r
736                 settings.beginGroup("General");\r
737                 String text = (String)settings.value("syncInterval", "15 minutes");\r
738                 settings.endGroup();\r
739                 return text;            \r
740     }\r
741     public static void setSyncInterval(String format) {\r
742                 settings.beginGroup("General");\r
743                 settings.setValue("syncInterval", format);\r
744                 settings.endGroup();            \r
745     }\r
746     \r
747     // Get/Set the width of columns and their position for the \r
748     // next start.\r
749     public static void setColumnWidth(String col, int width) {\r
750         if (Global.getListView() == Global.View_List_Wide)\r
751                 settings.beginGroup("ColumnWidths");\r
752         else \r
753                 settings.beginGroup("ColumnWidths-Narrow");\r
754                 settings.setValue(col, width);\r
755                 settings.endGroup();\r
756         }\r
757     public static int getColumnWidth(String col) {\r
758         int view = Global.getListView();\r
759         if (view == Global.View_List_Wide)\r
760                 settings.beginGroup("ColumnWidths");\r
761         else\r
762                 settings.beginGroup("ColumnWidths-Narrow");\r
763                 Integer width;\r
764                 try {\r
765                         String val  = (String)settings.value(col, "0");\r
766                         width = new Integer(val.trim());\r
767                 } catch (Exception e) {\r
768                         try {\r
769                                 width = (Integer)settings.value(col, 0);\r
770                         } catch (Exception e1) {\r
771                                 width = 0;\r
772                         }\r
773                 }\r
774                 settings.endGroup();\r
775                 return width;\r
776     }\r
777     public static void setColumnPosition(String col, int width) {\r
778         if (Global.getListView() == Global.View_List_Wide)\r
779                 settings.beginGroup("ColumnPosition");\r
780         else\r
781                 settings.beginGroup("ColumnPosition-Narrow");\r
782                 settings.setValue(col, width);\r
783                 settings.endGroup();\r
784     }\r
785     public static int getColumnPosition(String col) {\r
786         if (Global.getListView() == Global.View_List_Wide)\r
787                 settings.beginGroup("ColumnPosition");\r
788         else\r
789                 settings.beginGroup("ColumnPosition-Narrow");\r
790                 Integer width;\r
791                 try {\r
792                         String val  = (String)settings.value(col, "-1");\r
793                         width = new Integer(val.trim());\r
794                 } catch (Exception e) {\r
795                         try {\r
796                                 width = (Integer)settings.value(col, 0);\r
797                         } catch (Exception e1) {\r
798                                 width = 0;\r
799                         }\r
800                 }\r
801                 settings.endGroup();\r
802                 return width;\r
803     }\r
804     \r
805     // Ping the user when they try to delete or just do it.\r
806     public static boolean verifyDelete() {\r
807                 settings.beginGroup("General");\r
808                 try {\r
809                         String text = (String)settings.value("verifyDelete", "true");\r
810                         settings.endGroup();\r
811                         if (text.equalsIgnoreCase("true"))\r
812                                 return true;\r
813                         else\r
814                                 return false;\r
815                 } catch (java.lang.ClassCastException e) {\r
816                         Boolean value = (Boolean) settings.value("verifyDelete", true);\r
817                         settings.endGroup();\r
818                         return value;\r
819                 }\r
820     }\r
821     public static void setVerifyDelete(boolean val) {\r
822                 settings.beginGroup("General");\r
823                 if (val)\r
824                         settings.setValue("verifyDelete", "true");\r
825                 else\r
826                         settings.setValue("verifyDelete", "false");\r
827                 settings.endGroup();\r
828     }\r
829     \r
830     // Should it start minimized?\r
831     public static boolean startMinimized() {\r
832                 settings.beginGroup("General");\r
833                 try {\r
834                         String text = (String)settings.value("startMinimized", "false");\r
835                         settings.endGroup();\r
836                         if (text.equalsIgnoreCase("true"))\r
837                                 return true;\r
838                         else\r
839                                 return false;\r
840                 } catch (java.lang.ClassCastException e) {\r
841                         Boolean value = (Boolean) settings.value("startMinimized", false);\r
842                         settings.endGroup();\r
843                         return value;\r
844                 }\r
845     }\r
846     public static void setStartMinimized(boolean val) {\r
847                 settings.beginGroup("General");\r
848                 if (val)\r
849                         settings.setValue("startMinimized", "true");\r
850                 else\r
851                         settings.setValue("startMinimized", "false");\r
852                 settings.endGroup();\r
853     }\r
854     \r
855     // Should we upload the content of any deleted notes\r
856     public static boolean synchronizeDeletedContent() {\r
857                 settings.beginGroup("General");\r
858                 try {\r
859                         String text = (String)settings.value("syncDeletedContent", "false");\r
860                         settings.endGroup();\r
861                         if (text.equalsIgnoreCase("true"))\r
862                                 return true;\r
863                         else\r
864                                 return false;\r
865                 } catch (java.lang.ClassCastException e) {\r
866                         Boolean value = (Boolean) settings.value("syncDeletedContent", false);\r
867                         settings.endGroup();\r
868                         return value;\r
869                 }\r
870     }   \r
871     public static void setSynchronizeDeletedContent(boolean val) {\r
872                 settings.beginGroup("General");\r
873                 if (val)\r
874                         settings.setValue("syncDeletedContent", "true");\r
875                 else\r
876                         settings.setValue("syncDeletedContent", "false");\r
877                 settings.endGroup();\r
878     }\r
879     \r
880     // Is a section of the window visible?  Used to hide things people don't\r
881     // want to see.\r
882     public static boolean isWindowVisible(String window) {\r
883                 settings.beginGroup("WindowsVisible");\r
884                 try {\r
885                         String defaultValue = "true";\r
886                         if (window.equalsIgnoreCase("noteInformation"))\r
887                                 defaultValue = "false";\r
888                         String text = (String)settings.value(window, defaultValue);\r
889                         settings.endGroup();\r
890                         if (text.equalsIgnoreCase("true"))\r
891                                 return true;\r
892                 else\r
893                         return false;           \r
894                 } catch (java.lang.ClassCastException e) {\r
895                         boolean defaultValue = true;\r
896                         if (window.equalsIgnoreCase("noteInformation"))\r
897                                 defaultValue = false;\r
898                         Boolean value = (Boolean) settings.value("showTrayIcon", defaultValue);\r
899                         settings.endGroup();\r
900                         return value;\r
901                 }\r
902     }\r
903     public static void saveWindowVisible(String window, boolean val) {\r
904                 settings.beginGroup("WindowsVisible");\r
905                 if (val)\r
906                         settings.setValue(window, "true");\r
907                 else\r
908                         settings.setValue(window, "false");\r
909                 settings.endGroup();\r
910     }\r
911     \r
912     // Is a list in the column in the note list visible?  \r
913     public static boolean isColumnVisible(String window) {\r
914         String defaultValue = "true";\r
915         int view = Global.getListView();\r
916         if (Global.getListView() == Global.View_List_Wide)\r
917                 settings.beginGroup("ColumnsVisible");\r
918         else\r
919                 settings.beginGroup("ColumnsVisible-Narrow"); \r
920                 if (window.equalsIgnoreCase("thumbnail") && view == Global.View_List_Wide)\r
921                         defaultValue = "false";\r
922                 if (window.equalsIgnoreCase("thumbnail"))\r
923                         defaultValue = "false";\r
924                 if (window.equalsIgnoreCase("Guid"))\r
925                         defaultValue = "false";\r
926                 try {\r
927                         String text = (String)settings.value(window, defaultValue);\r
928                         settings.endGroup();\r
929                         if (text.equalsIgnoreCase("true"))\r
930                                 return true;\r
931                         else\r
932                                 return false;\r
933                 } catch (java.lang.ClassCastException e) {\r
934                         boolean defBool = false;\r
935                         if (window.equalsIgnoreCase("true"))\r
936                                 defBool = true;\r
937                         else\r
938                                 defBool = false;\r
939                         Boolean value = (Boolean) settings.value(window, defBool);\r
940                         settings.endGroup();\r
941                         return value;\r
942                 }\r
943     }\r
944     public static void saveColumnVisible(String column, boolean val) {\r
945         if (Global.getListView() == Global.View_List_Wide)\r
946                 settings.beginGroup("ColumnsVisible");\r
947         else\r
948                 settings.beginGroup("ColumnsVisible-Narrow");                   \r
949                 if (val)\r
950                         settings.setValue(column, "true");\r
951                 else\r
952                         settings.setValue(column, "false");\r
953                 settings.endGroup();\r
954     }\r
955     \r
956     // Is a particular editor button visible?\r
957     public static boolean isEditorButtonVisible(String window) {\r
958                 settings.beginGroup("EditorButtonsVisible");\r
959                 try {\r
960                         String text = (String)settings.value(window, "true");\r
961                         settings.endGroup();\r
962                         if (text.equalsIgnoreCase("true"))\r
963                                 return true;\r
964                         else\r
965                                 return false;\r
966                 } catch (java.lang.ClassCastException e) {\r
967                         Boolean value = (Boolean) settings.value(window, true);\r
968                         settings.endGroup();\r
969                         return value;\r
970                 }\r
971     }\r
972     public static void saveEditorButtonsVisible(String column, boolean val) {\r
973                 settings.beginGroup("EditorButtonsVisible");\r
974                 if (val)\r
975                         settings.setValue(column, "true");\r
976                 else\r
977                         settings.setValue(column, "false");\r
978                 settings.endGroup();\r
979     }\r
980     \r
981     // Should the test fixes be enabled\r
982     public static boolean enableCarriageReturnFix() {\r
983         try {\r
984                 settings.beginGroup("Debug");\r
985                 String text = (String)settings.value("enableCarriageReturnFix", "false");\r
986                 settings.endGroup();\r
987                 if (text.equalsIgnoreCase("true"))\r
988                         return true;\r
989                 else\r
990                         return false;\r
991                 } catch (java.lang.ClassCastException e) {\r
992                         Boolean value = (Boolean) settings.value("enableCarriageReturnFix", false);\r
993                         settings.endGroup();\r
994                         return value;\r
995                 }\r
996     }\r
997     public static void saveCarriageReturnFix(boolean val) {\r
998                 settings.beginGroup("Debug");\r
999                 if (val)\r
1000                         settings.setValue("enableCarriageReturnFix", "true");\r
1001                 else\r
1002                         settings.setValue("enableCarriageReturnFix", "false");\r
1003                 settings.endGroup();\r
1004     }\r
1005     public static boolean enableHtmlEntitiesFix() {\r
1006         try {\r
1007                 settings.beginGroup("Debug");\r
1008                 String text = (String)settings.value("enableHtmlEntitiesFix", "false");\r
1009                 settings.endGroup();\r
1010                 if (text.equalsIgnoreCase("true"))\r
1011                         return true;\r
1012                 else\r
1013                         return false;\r
1014                 } catch (java.lang.ClassCastException e) {\r
1015                         Boolean value = (Boolean) settings.value("enableHtmlEntitiesFix", false);\r
1016                         settings.endGroup();\r
1017                         return value;\r
1018                 }\r
1019     }\r
1020     public static void saveHtmlEntitiesFix(boolean val) {\r
1021                 settings.beginGroup("Debug");\r
1022                 if (val)\r
1023                         settings.setValue("enableHtmlEntitiesFix", "true");\r
1024                 else\r
1025                         settings.setValue("enableHtmlEntitiesFix", "false");\r
1026                 settings.endGroup();\r
1027     }\r
1028 \r
1029 //    public static void setIndexThreads(int val) {\r
1030 //              settings.beginGroup("General");\r
1031 //              settings.setValue("indexThreads", val);\r
1032 //              settings.endGroup();\r
1033 //   }\r
1034 //    public static int getIndexThreads() {\r
1035 //              settings.beginGroup("General");\r
1036 //              Integer threads;\r
1037 //              try {\r
1038 //                      String val  = (String)settings.value("indexThreads", "1");\r
1039 //                      threads = new Integer(val.trim());\r
1040 //              } catch (Exception e) {\r
1041 //                      try {\r
1042 //                              threads = (Integer)settings.value("indexThreads", 1);\r
1043 //                      } catch (Exception e1) {\r
1044 //                              threads = 1;\r
1045 //                      }\r
1046 //              }\r
1047 //              settings.endGroup();\r
1048 //              threads = 1;\r
1049 //              return threads;\r
1050     \r
1051     // Get/Set text zoom factor\r
1052 //   }\r
1053     public static void setZoomFactor(double val) {\r
1054                 settings.beginGroup("General");\r
1055                 settings.setValue("zoomFactor", val);\r
1056                 settings.endGroup();\r
1057     }\r
1058     public static double getZoomFactor() {\r
1059                 settings.beginGroup("General");\r
1060                 Double threads;\r
1061                 try {\r
1062                         String val  = (String)settings.value("zoomFactor", "1.0");\r
1063                         threads = new Double(val.trim());\r
1064                 } catch (Exception e) {\r
1065                         try {\r
1066                                 threads = (Double)settings.value("zoomFactor", 1.0);\r
1067                         } catch (Exception e1) {\r
1068                                 threads = new Double(1);\r
1069                         }\r
1070                 }\r
1071                 settings.endGroup();\r
1072                 return threads;\r
1073     }\r
1074     public static void setTextSizeMultiplier(double val) {\r
1075                 settings.beginGroup("General");\r
1076                 settings.setValue("textMultiplier", val);\r
1077                 settings.endGroup();\r
1078     }\r
1079     public static double getTextSizeMultiplier() {\r
1080                 settings.beginGroup("General");\r
1081                 Double threads;\r
1082                 try {\r
1083                         String val  = (String)settings.value("textMultiplier", "1");\r
1084                         threads = new Double(val.trim());\r
1085                 } catch (Exception e) {\r
1086                         try {\r
1087                                 threads = (Double)settings.value("textMultiplier", 1);\r
1088                         } catch (Exception e1) {\r
1089                                 threads = new Double(1);\r
1090                         }\r
1091                 }\r
1092                 settings.endGroup();\r
1093                 return threads;\r
1094     }\r
1095     \r
1096     \r
1097     // Should we mimic Evernote and restrict the notebooks selected?\r
1098     public static boolean getMimicEvernoteInterface() {\r
1099                 settings.beginGroup("General");\r
1100                 try {\r
1101                         String text = (String)settings.value("mimicEvernoteInterface", "true");\r
1102                         settings.endGroup();\r
1103                         if (text.equalsIgnoreCase("true"))\r
1104                                 return true;\r
1105                         else\r
1106                                 return false;\r
1107                 } catch (java.lang.ClassCastException e) {\r
1108                         Boolean value = (Boolean) settings.value("mimicEvernoteInterface", true);\r
1109                         settings.endGroup();\r
1110                         return value;\r
1111                 }\r
1112     }\r
1113     public static void setMimicEvernoteInterface(boolean value) {\r
1114         settings.beginGroup("General");\r
1115         if (value)\r
1116                 settings.setValue("mimicEvernoteInterface", "true");\r
1117         else\r
1118                 settings.setValue("mimicEvernoteInterface", "false"); \r
1119         settings.endGroup();\r
1120     }\r
1121     \r
1122     \r
1123     // Synchronize with Evernote when closing?\r
1124     public static boolean synchronizeOnClose() {\r
1125                 settings.beginGroup("General");\r
1126                 try {\r
1127                         String text = (String)settings.value("synchronizeOnClose", "false");\r
1128                         settings.endGroup();\r
1129                         if (text.equalsIgnoreCase("true"))\r
1130                                 return true;\r
1131                         else\r
1132                                 return false;\r
1133                 } catch (java.lang.ClassCastException e) {\r
1134                         Boolean value = (Boolean) settings.value("synchronizeOnClose", false);\r
1135                         settings.endGroup();\r
1136                         return value;\r
1137                 }\r
1138     }\r
1139     public static void setSynchronizeOnClose(boolean val) {\r
1140                 settings.beginGroup("General");\r
1141                 if (val)\r
1142                         settings.setValue("synchronizeOnClose", "true");\r
1143                 else\r
1144                         settings.setValue("synchronizeOnClose", "false");\r
1145                 settings.endGroup();\r
1146     }\r
1147 \r
1148     // Get/set the database version.  Not really used any more, but kept\r
1149     // for compatibility.\r
1150     public static void setDatabaseVersion(String version) {\r
1151                 settings.beginGroup("General");\r
1152                 settings.setValue("databaseVersion", version);\r
1153                 settings.endGroup();\r
1154     }\r
1155     public static String getDatabaseVersion() {\r
1156                 settings.beginGroup("General");\r
1157                 String val  = (String)settings.value("databaseVersion", "0.70");\r
1158                 settings.endGroup();\r
1159                 return val;\r
1160     }\r
1161 \r
1162     // Get the URL (full path) of the main database\r
1163     public static String getDatabaseUrl() {\r
1164                 settings.beginGroup("General");\r
1165                 String val  = (String)settings.value("DatabaseURL", "");\r
1166                 settings.endGroup();\r
1167                 if (val.equals(""))\r
1168                         val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.databaseName);\r
1169                 return val;\r
1170     }\r
1171     \r
1172     // get the url (full path) of the searchable word database\r
1173     public static String getIndexDatabaseUrl() {\r
1174                 settings.beginGroup("General");\r
1175                 String val  = (String)settings.value("DatabaseURL", "");\r
1176                 settings.endGroup();\r
1177                 if (val.equals(""))\r
1178                         val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.indexDatabaseName);\r
1179                 return val;\r
1180     }\r
1181     \r
1182     // Get the url (full path) of the attachment database\r
1183     public static String getResourceDatabaseUrl() {\r
1184                 settings.beginGroup("General");\r
1185                 String val  = (String)settings.value("DatabaseURL", "");\r
1186                 settings.endGroup();\r
1187                 if (val.equals(""))\r
1188                         val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.resourceDatabaseName);\r
1189                 return val;\r
1190     }\r
1191     public static void setDatabaseUrl(String value) {\r
1192                 settings.beginGroup("General");\r
1193                 settings.setValue("DatabaseURL", value);\r
1194                 settings.endGroup();\r
1195     }\r
1196     public static String getDatabaseUserid() {\r
1197                 settings.beginGroup("General");\r
1198                 String val  = (String)settings.value("databaseUserid", "");\r
1199                 settings.endGroup();\r
1200                 return val;\r
1201     }\r
1202     public static String getDatabaseUserPassword() {\r
1203                 settings.beginGroup("General");\r
1204                 String val  = (String)settings.value("databaseUserPassword", "");\r
1205                 settings.endGroup();\r
1206                 return val;\r
1207     }\r
1208     \r
1209     // get/Set the style sheet and the palette to control the look & feel\r
1210     public static void setStyle(String style) {\r
1211                 settings.beginGroup("General");\r
1212                 settings.setValue("style", style);\r
1213                 settings.endGroup();\r
1214     }\r
1215     public static String getStyle() {\r
1216                 settings.beginGroup("General");\r
1217                 String val  = (String)settings.value("style", "Cleanlooks");\r
1218                 settings.endGroup();\r
1219                 return val;\r
1220     }\r
1221     public static boolean useStandardPalette() {\r
1222                 settings.beginGroup("General");\r
1223                 try {\r
1224                         String text = (String)settings.value("standardPalette", "true");\r
1225                         settings.endGroup();\r
1226                         if (text.equalsIgnoreCase("true"))\r
1227                                 return true;\r
1228                         else\r
1229                                 return false;\r
1230                 } catch (java.lang.ClassCastException e) {\r
1231                         Boolean value = (Boolean) settings.value("standardPalette", true);\r
1232                         settings.endGroup();\r
1233                         return value;\r
1234                 }\r
1235     }\r
1236     public static void setStandardPalette(boolean val) {\r
1237                 settings.beginGroup("General");\r
1238                 if (val)\r
1239                         settings.setValue("standardPalette", "true");\r
1240                 else\r
1241                         settings.setValue("standardPalette", "false");\r
1242                 settings.endGroup();\r
1243     }\r
1244     \r
1245     // Set the amount of time to wait between indexing\r
1246     // Get/Set interval when the index thread wakes up.\r
1247     public static void setIndexThreadSleepInterval(int sleep) {\r
1248                 settings.beginGroup("General");\r
1249                 settings.setValue("IndexThreadSleepInterval", sleep);\r
1250                 settings.endGroup();\r
1251     }\r
1252     public static int getIndexThreadSleepInterval() {\r
1253                 settings.beginGroup("General");\r
1254                 Integer sleep;\r
1255                 try {\r
1256                         String val  = (String)settings.value("IndexThreadSleepInterval", "300");\r
1257                         sleep = new Integer(val.trim());\r
1258                 } catch (Exception e) {\r
1259                         try {\r
1260                                 sleep = (Integer)settings.value("IndexThreadSleepInterval", 0);\r
1261                         } catch (Exception e1) {\r
1262                                 sleep = 300;\r
1263                         }\r
1264                 }\r
1265                 settings.endGroup();\r
1266                 return sleep;\r
1267     }\r
1268     \r
1269     \r
1270     // Get/Set a window state for later restoring\r
1271     public static void saveState(String name, QByteArray state) {\r
1272         int view = Global.getListView();\r
1273         if (view == Global.View_List_Narrow)\r
1274                 name = name +"Narrow";\r
1275                 settings.beginGroup("SaveState");\r
1276                 settings.setValue(name, state);\r
1277                 settings.endGroup();\r
1278     }\r
1279     \r
1280     public static QByteArray restoreState(String name) {\r
1281         int view = Global.getListView();\r
1282         if (view == Global.View_List_Narrow)\r
1283                 name = name +"Narrow";\r
1284                 settings.beginGroup("SaveState");\r
1285                 QByteArray state = (QByteArray)settings.value(name);\r
1286                 settings.endGroup();\r
1287                 return state;\r
1288     }\r
1289     public static void saveGeometry(String name, QByteArray state) {\r
1290         int view = Global.getListView();\r
1291         if (view == Global.View_List_Narrow)\r
1292                 settings.beginGroup("SaveGeometryNarrow");\r
1293         else\r
1294                 settings.beginGroup("SaveGeometry");\r
1295                 settings.setValue(name, state);\r
1296                 settings.endGroup();\r
1297     }\r
1298     \r
1299     public static QByteArray restoreGeometry(String name) {\r
1300         int view = Global.getListView();\r
1301         if (view == Global.View_List_Narrow)\r
1302                 settings.beginGroup("SaveGeometryNarrow");\r
1303         else\r
1304                 settings.beginGroup("SaveGeometry");\r
1305                 QByteArray state = (QByteArray)settings.value(name);\r
1306                 settings.endGroup();\r
1307                 return state;\r
1308     }\r
1309     \r
1310     \r
1311     // Set how often to do an automatic save\r
1312     public static void setAutoSaveInterval(int interval) {\r
1313                 settings.beginGroup("General");\r
1314                 settings.setValue("autoSaveInterval", interval);\r
1315                 settings.endGroup();\r
1316     }\r
1317     public static int getAutoSaveInterval() {\r
1318                 settings.beginGroup("General");\r
1319                 Integer value;\r
1320                 try {\r
1321                         String val  = (String)settings.value("autoSaveInterval", "5");\r
1322                         value = new Integer(val.trim());\r
1323                 } catch (Exception e) {\r
1324                         try {\r
1325                                 value = (Integer)settings.value("autoSaveInterval", 5);\r
1326                         } catch (Exception e1) {\r
1327                                 value = 5;\r
1328                         }\r
1329                 }\r
1330                 settings.endGroup();\r
1331                 return value;\r
1332     }\r
1333      \r
1334     // Add an invalid attribute & element to the database so we don't bother parsing it in the future\r
1335     // These values we automatically remove from any note.\r
1336     // Add invalid attributes\r
1337     public static void addInvalidAttribute(String element, String attribute) {\r
1338         \r
1339                 List<String> attributes = invalidAttributes.get(element);\r
1340                 if (attributes != null) {\r
1341                         for (int i=0; i<attributes.size(); i++)\r
1342                                 if (attribute.equalsIgnoreCase(attributes.get(i))) {\r
1343                                         return;\r
1344                         }\r
1345         }\r
1346         \r
1347         ArrayList<String> attributeList;\r
1348         if (!invalidAttributes.containsKey(element)) {\r
1349                 attributeList = new ArrayList<String>();\r
1350                 attributeList.add(attribute);\r
1351                 invalidAttributes.put(element, attributeList);\r
1352         }\r
1353         else {\r
1354                 attributeList = invalidAttributes.get(element);\r
1355                 attributeList.add(attribute);\r
1356                 invalidAttributes.put(element,attributeList);\r
1357         }\r
1358     }\r
1359    \r
1360     // Add invalid attributes\r
1361     public static void addInvalidElement(String element) {\r
1362                 for (int i=0; i<invalidElements.size(); i++) {\r
1363                         if (element.equalsIgnoreCase(invalidElements.get(i)))\r
1364                                 return;\r
1365                 }\r
1366         invalidElements.add(element);\r
1367     }\r
1368     \r
1369     // Get/Set proxy information\r
1370     // Proxy settings\r
1371     public static String getProxyValue(String key) {\r
1372                 settings.beginGroup("Proxy");\r
1373                 String val  = (String)settings.value(key, "");\r
1374                 settings.endGroup();\r
1375                 return val;\r
1376     }\r
1377     public static void setProxyValue(String key, String value) {\r
1378                 settings.beginGroup("Proxy");\r
1379                 settings.setValue(key, value);\r
1380                 settings.endGroup();\r
1381     }\r
1382     \r
1383     // Change a byte array to a hex string\r
1384     // Convert a byte array to a hex string\r
1385         public static String byteArrayToHexString(byte data[]) {\r
1386                 StringBuffer buf = new StringBuffer();\r
1387             for (byte element : data) {\r
1388                 int halfbyte = (element >>> 4) & 0x0F;\r
1389                 int two_halfs = 0;\r
1390                 do {\r
1391                         if ((0 <= halfbyte) && (halfbyte <= 9))\r
1392                                buf.append((char) ('0' + halfbyte));\r
1393                            else\r
1394                                 buf.append((char) ('a' + (halfbyte - 10)));\r
1395                         halfbyte = element & 0x0F;\r
1396                 } while(two_halfs++ < 1);\r
1397             }\r
1398             return buf.toString();              \r
1399         }\r
1400 \r
1401     \r
1402         // Get/Set spelling settings\r
1403         public static boolean getSpellSetting(String value) {\r
1404                 settings.beginGroup("Spell");\r
1405                 String text = (String)settings.value(value, "");\r
1406                 settings.endGroup();\r
1407                 if (text.equalsIgnoreCase("true"))\r
1408                         return true;\r
1409                 if (text.equalsIgnoreCase("false"))\r
1410                         return false;\r
1411                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREDIGITWORDS))\r
1412                         return true;\r
1413                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREINTERNETADDRESSES))\r
1414                         return true;\r
1415                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREUPPERCASE))\r
1416                         return true;\r
1417                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNORESENTENCECAPITALIZATION))\r
1418                         return true;\r
1419                 return false;\r
1420     }\r
1421     public static void setSpellSetting(String setting, boolean val) {\r
1422                 settings.beginGroup("Spell");\r
1423                 if (val)\r
1424                         settings.setValue(setting, "true");\r
1425                 else\r
1426                         settings.setValue(setting, "false");\r
1427                 settings.endGroup();\r
1428     }\r
1429         \r
1430         // Get/Set how we should display tags (color them, hide unused, or do nothing)\r
1431         // What to do with inactive tags?\r
1432         public static String tagBehavior() {\r
1433                 settings.beginGroup("General");\r
1434                 String text = (String)settings.value("tagBehavior", "DoNothing");\r
1435                 settings.endGroup();\r
1436                 return text;\r
1437         }\r
1438         // What to do with inactive tags?\r
1439         public static void setTagBehavior(String value) {\r
1440                 settings.beginGroup("General");\r
1441                 settings.setValue("tagBehavior", value);\r
1442                 settings.endGroup();\r
1443         }\r
1444 \r
1445     \r
1446         // Should the toolbar be visible?\r
1447         public static boolean isToolbarButtonVisible(String window) {\r
1448                 settings.beginGroup("ToolbarButtonsVisible");\r
1449                 try {\r
1450                         String text = (String)settings.value(window, "true");\r
1451                         settings.endGroup();\r
1452                         if (text.equalsIgnoreCase("true"))\r
1453                                 return true;\r
1454                         else\r
1455                                 return false;   \r
1456                 } catch (java.lang.ClassCastException e) {\r
1457                         Boolean value = (Boolean) settings.value(window, true);\r
1458                         settings.endGroup();\r
1459                         return value;\r
1460                 }\r
1461     }\r
1462     public static void saveToolbarButtonsVisible(String column, boolean val) {\r
1463                 settings.beginGroup("ToolbarButtonsVisible");\r
1464                 if (val)\r
1465                         settings.setValue(column, "true");\r
1466                 else\r
1467                         settings.setValue(column, "false");\r
1468                 settings.endGroup();\r
1469     }\r
1470         \r
1471     // Are thumbnails enabled?\r
1472     \r
1473     public static boolean enableThumbnails() {\r
1474                 settings.beginGroup("Debug");\r
1475                 try {\r
1476                         String text = (String)settings.value("thumbnails", "true");\r
1477                         settings.endGroup();\r
1478                         if (text.equalsIgnoreCase("true"))\r
1479                                 return true;\r
1480                         else\r
1481                                 return false;\r
1482                 } catch (java.lang.ClassCastException e) {\r
1483                         Boolean value = (Boolean) settings.value("thumbnails", true);\r
1484                         settings.endGroup();\r
1485                         return value;\r
1486                 }\r
1487     }\r
1488     public static void setEnableThumbnails(boolean val) {\r
1489                 settings.beginGroup("Debug");\r
1490                 if (val)\r
1491                         settings.setValue("thumbnails", "true");\r
1492                 else\r
1493                         settings.setValue("thumbnails", "false");\r
1494                 settings.endGroup();\r
1495     }\r
1496         \r
1497     // Trace used for performance tuning.  Not normally used in production.\r
1498         // Print date/time.  Used mainly for performance tracing\r
1499         public static void trace(boolean resetInterval) {\r
1500                 String fmt = "MM/dd/yy HH:mm:ss.SSSSSS";\r
1501                 String dateTimeFormat = new String(fmt);\r
1502                 SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);\r
1503                 Calendar cal = Calendar.getInstance();\r
1504                 if (intervalTraceTime == null) \r
1505                         intervalTraceTime = Calendar.getInstance();\r
1506                 if (startTraceTime == null)\r
1507                         startTraceTime = Calendar.getInstance();\r
1508                 \r
1509                 float interval = (cal.getTimeInMillis() - intervalTraceTime.getTimeInMillis());\r
1510                 float total = (cal.getTimeInMillis() - startTraceTime.getTimeInMillis());\r
1511                 \r
1512 //              if (interval > 00.0) {\r
1513                         StackTraceElement[] exceptions = Thread.currentThread().getStackTrace();\r
1514                         System.out.println("------------------------------------------");\r
1515 \r
1516                         System.out.println("Date/Time " +simple.format(cal.getTime()));\r
1517                         System.out.format("Interval Time: %-10.6f%n", interval);\r
1518                         System.out.format("Total Time: %-10.6f%n", total);\r
1519                         for (int i=2; i<5 && i<exceptions.length; i++) {\r
1520                                 System.out.println(exceptions[i]);\r
1521                         }\r
1522 //              }\r
1523                 if (resetInterval)\r
1524                         intervalTraceTime = cal;\r
1525         }\r
1526         public static void traceReset() {\r
1527                 intervalTraceTime = null;\r
1528                 startTraceTime = null;\r
1529         }\r
1530 \r
1531     \r
1532         // Get the FileManager class to manage local files & directories\r
1533         public static FileManager getFileManager() {\r
1534         return fileManager;\r
1535     }\r
1536         \r
1537         // Should the note editor be disabled?\r
1538     public static boolean getDisableViewing() {\r
1539         return disableViewing;\r
1540     }\r
1541 \r
1542     //**********************\r
1543     //* Thumbnail zoom level\r
1544     //**********************\r
1545     public static int calculateThumbnailZoom(String content) {\r
1546         int zoom = 1;\r
1547                 if (content.indexOf("application/pdf") == -1) {\r
1548                         if (content.indexOf("image/") == -1) {\r
1549                                 String text =  StringEscapeUtils.unescapeHtml(content.replaceAll("\\<.*?\\>", ""));\r
1550                                 zoom = 2;\r
1551                                 if (text.length() < 500) \r
1552                                         zoom = 2;\r
1553                                 if (text.length() < 250)\r
1554                                         zoom = 3;\r
1555                                 if (text.length() < 100)\r
1556                                         zoom = 4;\r
1557                                 if (text.length() < 50)\r
1558                                         zoom = 5;\r
1559                                 if (text.length() < 10)\r
1560                                         zoom = 6;\r
1561                         }\r
1562                 }\r
1563                 return zoom;\r
1564     }\r
1565     \r
1566     //**********************\r
1567     //* List View settings \r
1568     //**********************\r
1569     public static void setListView(int view) {\r
1570                 settings.beginGroup("General");\r
1571                 settings.setValue("listView", view);\r
1572                 settings.endGroup();\r
1573     }\r
1574     public static int getListView() {\r
1575                 settings.beginGroup("General");\r
1576                 Integer value;\r
1577                 try {\r
1578                         String val  = (String)settings.value("listView", View_List_Wide);\r
1579                         value = new Integer(val.trim());\r
1580                 } catch (Exception e) {\r
1581                         try {\r
1582                                 value = (Integer)settings.value("listView", View_List_Wide);\r
1583                         } catch (Exception e1) {\r
1584                                 value = View_List_Wide;\r
1585                         }\r
1586                 }\r
1587                 settings.endGroup();\r
1588                 return value;\r
1589     }\r
1590 \r
1591     \r
1592     \r
1593     //*******************\r
1594     // Font Settings\r
1595     //*******************\r
1596     public static boolean overrideDefaultFont() {\r
1597                 settings.beginGroup("Font");\r
1598                 try {\r
1599                         String text = (String)settings.value("overrideFont", "false");\r
1600                         settings.endGroup();\r
1601                         if (text.equalsIgnoreCase("true"))\r
1602                                 return true;\r
1603                         else\r
1604                                 return false;   \r
1605                 } catch (java.lang.ClassCastException e) {\r
1606                         Boolean value = (Boolean) settings.value("overrideFont", false);\r
1607                         settings.endGroup();\r
1608                         return value;\r
1609                 }\r
1610 \r
1611     }\r
1612     \r
1613     //****************************************************\r
1614     // Get/Set the default font settings for a new note\r
1615     //****************************************************\r
1616     public static void setOverrideDefaultFont(boolean value) {\r
1617                 settings.beginGroup("Font");\r
1618                 settings.setValue("overrideFont", value);\r
1619                 settings.endGroup();    \r
1620     }\r
1621     public static String getDefaultFont() {\r
1622                 settings.beginGroup("Font");\r
1623                 String val  = (String)settings.value("font", "");\r
1624                 settings.endGroup();\r
1625                 return val;\r
1626     }\r
1627     public static void setDefaultFont(String value) {\r
1628                 settings.beginGroup("Font");\r
1629                 settings.setValue("font", value);\r
1630                 settings.endGroup();\r
1631     }\r
1632     public static String getDefaultFontSize() {\r
1633                 settings.beginGroup("Font");\r
1634                 String val  = (String)settings.value("fontSize", "");\r
1635                 settings.endGroup();\r
1636                 return val;\r
1637     }\r
1638     public static void setDefaultFontSize(String value) {\r
1639                 settings.beginGroup("Font");\r
1640                 settings.setValue("fontSize", value);\r
1641                 settings.endGroup();\r
1642     }\r
1643     \r
1644     \r
1645     //*******************************************\r
1646     // Override the close & minimize instead.\r
1647     //*******************************************\r
1648     public static boolean minimizeOnClose() {\r
1649                 settings.beginGroup("General");\r
1650                 try {\r
1651                         String text = (String)settings.value("minimizeOnClose", "false");\r
1652                         settings.endGroup();\r
1653                         if (text.equalsIgnoreCase("true"))\r
1654                                 return true;\r
1655                         else\r
1656                                 return false;\r
1657                 } catch (java.lang.ClassCastException e) {\r
1658                         Boolean value = (Boolean) settings.value("minimizeOnClose", false);\r
1659                         settings.endGroup();\r
1660                         return value;\r
1661                 }\r
1662     }\r
1663     public static void setMinimizeOnClose(boolean value) {\r
1664                 settings.beginGroup("General");\r
1665                 settings.setValue("minimizeOnClose", value);\r
1666                 settings.endGroup();    \r
1667     }\r
1668 \r
1669     //*********************************\r
1670     // Check version information\r
1671     //*********************************\r
1672     public static boolean checkVersionUpgrade() {\r
1673                 settings.beginGroup("Upgrade");\r
1674                 try {\r
1675                         String text = (String)settings.value("checkForUpdates", "true");\r
1676                         settings.endGroup();\r
1677                         if (text.equalsIgnoreCase("true"))\r
1678                                 return true;\r
1679                         else\r
1680                                 return false;\r
1681                 } catch (java.lang.ClassCastException e) {\r
1682                         Boolean value = (Boolean) settings.value("checkForUpdates", true);\r
1683                         settings.endGroup();\r
1684                         return value;\r
1685                 }\r
1686     }\r
1687     public static void setCheckVersionUpgrade(boolean value) {\r
1688                 settings.beginGroup("Upgrade");\r
1689                 settings.setValue("checkForUpdates", value);\r
1690                 settings.endGroup();    \r
1691     }\r
1692     public static String getUpdatesAvailableUrl() {\r
1693                 settings.beginGroup("Upgrade");\r
1694                 String text = (String)settings.value("avialableUrl", "http://nevernote.sourceforge.net/versions.txt");\r
1695                 settings.endGroup();    \r
1696                 return text;\r
1697     }\r
1698     public static String getUpdateAnnounceUrl() {\r
1699                 settings.beginGroup("Upgrade");\r
1700                 String text = (String)settings.value("announceUrl", "http://nevernote.sourceforge.net/upgrade.html");\r
1701                 settings.endGroup();    \r
1702                 return text;\r
1703     }\r
1704     \r
1705     //*******************\r
1706     // Index settings\r
1707     //*******************\r
1708     // Set/Get if we should index the text of a note\r
1709     public static boolean indexNoteBody() {\r
1710                 settings.beginGroup("Index");\r
1711                 try {\r
1712                         String value = (String)settings.value("indexNoteBody", "true");\r
1713                         settings.endGroup();\r
1714                         if (value.equals("true"))\r
1715                                 return true;\r
1716                         else\r
1717                                 return false;\r
1718                 } catch (java.lang.ClassCastException e) {\r
1719                         Boolean value = (Boolean) settings.value("indexNoteBody", true);\r
1720                         settings.endGroup();\r
1721                         return value;\r
1722                 }\r
1723     }\r
1724     public static void setIndexNoteTitle(boolean value) {\r
1725                 settings.beginGroup("Index");\r
1726                 settings.setValue("indexNoteTitle", value);\r
1727                 settings.endGroup();    \r
1728     }\r
1729     // Set/Get if we should index the title of a note\r
1730     public static boolean indexNoteTitle() {\r
1731                 settings.beginGroup("Index");\r
1732                 try {\r
1733                         String value = (String)settings.value("indexNoteTitle", "true");\r
1734                         settings.endGroup();\r
1735                         if (value.equals("true"))\r
1736                                 return true;\r
1737                         else\r
1738                                 return false;\r
1739                 } catch (java.lang.ClassCastException e) {\r
1740                         Boolean value = (Boolean) settings.value("indexNoteTitle", true);\r
1741                         settings.endGroup();\r
1742                         return value;\r
1743                 }\r
1744     }\r
1745     public static void setIndexNoteBody(boolean value) {\r
1746                 settings.beginGroup("Index");\r
1747                 settings.setValue("indexNoteBody", value);\r
1748                 settings.endGroup();    \r
1749     }\r
1750     // Set/Get if we should index any attachments\r
1751     public static boolean indexAttachmentsLocally() {\r
1752                 settings.beginGroup("Index");\r
1753                 try {\r
1754                         String value = (String)settings.value("indexAttachmentsLocally", "true");\r
1755                         settings.endGroup();\r
1756                         if (value.equals("true"))\r
1757                                 return true;\r
1758                         else\r
1759                                 return false;\r
1760                 } catch (java.lang.ClassCastException e) {\r
1761                         Boolean value = (Boolean) settings.value("indexAttachmentsLocally", true);\r
1762                         settings.endGroup();\r
1763                         return value;\r
1764                 }\r
1765     }\r
1766     public static void setIndexImageRecognition(boolean value) {\r
1767                 settings.beginGroup("Index");\r
1768                 settings.setValue("indexImageRecognition", value);\r
1769                 settings.endGroup();    \r
1770     }\r
1771     public static boolean indexImageRecognition() {\r
1772                 settings.beginGroup("Index");\r
1773                 try {\r
1774                         String value = (String)settings.value("indexImageRecognition", "true");\r
1775                         settings.endGroup();\r
1776                         if (value.equals("true"))\r
1777                                 return true;\r
1778                         else\r
1779                                 return false;\r
1780                 } catch (java.lang.ClassCastException e) {\r
1781                         Boolean value = (Boolean) settings.value("indexImageRecognition", true);\r
1782                         settings.endGroup();\r
1783                         return value;\r
1784                 }\r
1785     }\r
1786     public static void setIndexAttachmentsLocally(boolean value) {\r
1787                 settings.beginGroup("Index");\r
1788                 settings.setValue("indexAttachmentsLocally", value);\r
1789                 settings.endGroup();    \r
1790     }\r
1791     // Get/Set characters that shouldn't be removed from a word\r
1792     public static String getSpecialIndexCharacters() {\r
1793                 settings.beginGroup("Index");\r
1794                 String text = (String)settings.value("specialCharacters", "");\r
1795                 settings.endGroup();    \r
1796                 return text;\r
1797     }\r
1798     public static void setSpecialIndexCharacters(String value) {\r
1799                 settings.beginGroup("Index");\r
1800                 settings.setValue("specialCharacters", value);\r
1801                 settings.endGroup();    \r
1802                 databaseCache = value;\r
1803     }\r
1804     \r
1805     //*****************************************************************************\r
1806     // Control how tag selection behaves (should they be "and" or "or" selections\r
1807     //*****************************************************************************\r
1808     public static boolean anyTagSelectionMatch() {\r
1809                 settings.beginGroup("General");\r
1810                 try {\r
1811                         String value = (String)settings.value("anyTagSelectionMatch", "false");\r
1812                         settings.endGroup();\r
1813                         if (value.equals("true"))\r
1814                                 return true;\r
1815                         else\r
1816                                 return false;\r
1817                 } catch (java.lang.ClassCastException e) {\r
1818                         Boolean value = (Boolean) settings.value("anyTagSelectionMatch", false);\r
1819                         settings.endGroup();\r
1820                         return value;\r
1821                 }\r
1822     }\r
1823     public static void setAnyTagSelectionMatch(boolean value) {\r
1824                 settings.beginGroup("General");\r
1825                 settings.setValue("anyTagSelectionMatch", value);\r
1826                 settings.endGroup();    \r
1827     }\r
1828 \r
1829     //***********************\r
1830     //* Database cache size\r
1831     //***********************\r
1832     public static String getDatabaseCacheSize() {\r
1833                 settings.beginGroup("Debug");\r
1834                 String text = (String)settings.value("databaseCache", "16384");\r
1835                 settings.endGroup();    \r
1836                 return text;\r
1837     }\r
1838     public static void setDatabaseCache(String value) {\r
1839                 settings.beginGroup("Debug");\r
1840                 settings.setValue("databaseCache", value);\r
1841                 settings.endGroup();    \r
1842                 databaseCache = value;\r
1843     }\r
1844 \r
1845     \r
1846     // This is used to copy a class since Java's normal deep copy is wacked\r
1847     public static Object deepCopy(Object oldObj) \r
1848     {\r
1849        ObjectOutputStream oos = null;\r
1850        ObjectInputStream ois = null;\r
1851        try\r
1852        {\r
1853           ByteArrayOutputStream bos = \r
1854                 new ByteArrayOutputStream(); // A\r
1855           oos = new ObjectOutputStream(bos); // B\r
1856           // serialize and pass the object\r
1857           oos.writeObject(oldObj);   // C\r
1858           oos.flush();               // D\r
1859           ByteArrayInputStream bin = \r
1860                 new ByteArrayInputStream(bos.toByteArray()); // E\r
1861           ois = new ObjectInputStream(bin);                  // F\r
1862           // return the new object\r
1863           return ois.readObject(); // G\r
1864        }\r
1865        catch(Exception e)\r
1866        {\r
1867           Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e);\r
1868        }\r
1869           try {\r
1870                         oos.close();\r
1871                 ois.close();\r
1872                 } catch (IOException e) {\r
1873                         Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e);\r
1874                         e.printStackTrace();\r
1875                 }\r
1876 \r
1877                 return null;\r
1878     }\r
1879 \r
1880 }\r
1881 \r