OSDN Git Service

0665fabefa061c6d9363dfe97ff3d69c41e44781
[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.setValue("shard", user.getShardId());\r
265                 settings.endGroup();\r
266                 isPremium();\r
267                 if (user.getAttributes()!=null)\r
268                         saveUserAttributes(user.getAttributes());\r
269                 if (user.getAccounting()!=null)\r
270                         saveUserAccounting(user.getAccounting());\r
271 \r
272     }\r
273     public static User getUserInformation() {\r
274         User user = new User();\r
275         settings.beginGroup("User");\r
276         user.setId((Integer)settings.value("id", 0));\r
277                 String username = (String)settings.value("username", "");\r
278                 String email = (String)settings.value("email", "");\r
279                 String name = (String)settings.value("name", "");\r
280                 String timezone = (String)settings.value("timezone", "");\r
281                 Integer privilege = (Integer)settings.value("privilege", "");\r
282 \r
283                 String date = (String)settings.value("created", "0");\r
284                 user.setCreated(new Long(date));\r
285 \r
286                 date = (String)settings.value("updated", "0");\r
287                 user.setUpdated(new Long(date));\r
288                 \r
289                 date = (String)settings.value("deleted", "0");\r
290                 user.setDeleted(new Long(date));\r
291 \r
292                 String shard = (String)settings.value("shard", "");\r
293         settings.endGroup();\r
294         \r
295         user.setUsername(username);\r
296         user.setEmail(email);\r
297         user.setName(name);\r
298         user.setTimezone(timezone);\r
299         PrivilegeLevel userLevel = PrivilegeLevel.findByValue(privilege);\r
300         user.setPrivilege(userLevel);\r
301         user.setShardId(shard);\r
302         return user;\r
303     }\r
304     \r
305     public static void saveUserAttributes(UserAttributes attrib) {\r
306         settings.beginGroup("UserAttributes");\r
307                 settings.setValue("defaultLocationName", attrib.getDefaultLocationName());\r
308                 settings.setValue("defaultLatitude", attrib.getDefaultLocationName());\r
309                 settings.setValue("defaultLongitude", attrib.getDefaultLocationName());\r
310                 settings.setValue("incomingEmailAddress", attrib.getIncomingEmailAddress());\r
311                 settings.endGroup();\r
312     }\r
313     public static UserAttributes getUserAttributes() {\r
314         settings.beginGroup("UserAttributes");\r
315         UserAttributes attrib = new UserAttributes();\r
316                 attrib.setDefaultLocationName((String)settings.value("defaultLocationName",""));\r
317                 attrib.setDefaultLatitudeIsSet(false);\r
318                 attrib.setDefaultLongitudeIsSet(false);\r
319                 attrib.setIncomingEmailAddress((String)settings.value("incomingEmailAddress", ""));\r
320                 settings.endGroup();\r
321                 return attrib;\r
322     }\r
323     public static void saveUserAccounting(Accounting acc) {\r
324         settings.beginGroup("UserAccounting");\r
325                 settings.setValue("uploadLimit", acc.getUploadLimit());\r
326                 settings.setValue("uploadLimitEnd", acc.getUploadLimitEnd());\r
327                 settings.setValue("uploadLimitNextMonth", acc.getUploadLimitNextMonth());\r
328                 settings.setValue("premiumServiceStart", acc.getPremiumServiceStart());\r
329                 settings.setValue("nextPaymentDue", acc.getNextPaymentDue());\r
330                 settings.setValue("uploadAmount", acc.getUpdated());\r
331                 settings.endGroup();\r
332     }\r
333     public static long getUploadLimitEnd() {\r
334         Long limit;\r
335         settings.beginGroup("UserAccounting");\r
336         \r
337         // Upload limit\r
338                 try {\r
339                         String val  = (String)settings.value("uploadLimitEnd", "0");\r
340                         limit = new Long(val.trim());\r
341                 } catch (Exception e) {\r
342                         try {\r
343                                 limit = (Long)settings.value("uploadLimitEnd", 0);\r
344                         } catch (Exception e1) {\r
345                                 limit = new Long(0);\r
346                         }\r
347                 }\r
348         \r
349                 // return value\r
350         settings.endGroup();\r
351         return limit;\r
352     }\r
353     public static void saveUploadAmount(long amount) {\r
354         settings.beginGroup("UserAccounting");\r
355                 settings.setValue("uploadAmount", amount);\r
356                 settings.endGroup();\r
357    }\r
358     public static long getUploadAmount() {\r
359                 long amt=0;\r
360                 settings.beginGroup("UserAccounting");\r
361                 try {\r
362                         String num = (String)settings.value("uploadAmount", "0");\r
363                         amt = new Long(num.trim());\r
364                 } catch (Exception e) {\r
365                         try {\r
366                                 amt = (Integer)settings.value("uploadAmount", 0);\r
367                         } catch (Exception e1) {\r
368                                 amt = 0;\r
369                         }\r
370                 }\r
371                 settings.endGroup();\r
372                 return amt;\r
373     }\r
374     public static void saveEvernoteUpdateCount(long amount) {\r
375         settings.beginGroup("UserAccounting");\r
376                 settings.setValue("updateCount", amount);\r
377                 settings.endGroup();\r
378     }\r
379     public static long getEvernoteUpdateCount() {\r
380                 long amt;\r
381                 settings.beginGroup("UserAccounting");\r
382                 try {\r
383                         String num = (String)settings.value("updateCount", new Long(0).toString());\r
384                         amt = new Long(num.trim());\r
385                 } catch (java.lang.ClassCastException e) {\r
386                         amt = 0;\r
387                 }\r
388                 settings.endGroup();\r
389                 return amt;\r
390     }\r
391     public static boolean isPremium() {\r
392                 int level;\r
393                 settings.beginGroup("User");\r
394                 try {\r
395                         String num = (String)settings.value("privilege", "1");\r
396                         level = new Integer(num.trim());\r
397                 } catch (java.lang.ClassCastException e) {\r
398                         try {\r
399                                 level = (Integer)settings.value("privilege", 1);\r
400                         } catch (Exception e1) {\r
401                                 level = 1;\r
402                         }\r
403                 }\r
404                 settings.endGroup();\r
405                 PrivilegeLevel userLevel = PrivilegeLevel.findByValue(level);\r
406                 if (userLevel == PrivilegeLevel.NORMAL)\r
407                         return false;\r
408                 return true;\r
409                 \r
410    }\r
411     public static long getUploadLimit() {\r
412                 settings.beginGroup("UserAccounting");\r
413                 long limit;\r
414                 try {\r
415                         String num = (String)settings.value("uploadLimit", new Long(0).toString());\r
416                         limit = new Long(num.trim());\r
417                 } catch (java.lang.ClassCastException e) {\r
418                         limit = 0;\r
419                 }\r
420                 settings.endGroup();\r
421                 return limit;\r
422     }\r
423 \r
424     \r
425     \r
426     //****************************************************\r
427     //****************************************************\r
428     //** View settings.  Used to restore settings \r
429     //** when starting and to control how the program\r
430     //** behaves.\r
431     //****************************************************\r
432     //****************************************************\r
433     \r
434     //* Get/Set if we should show a tray icon\r
435     public static boolean showTrayIcon() {\r
436                 settings.beginGroup("General");\r
437                 try {\r
438                         String max = (String) settings.value("showTrayIcon", "false");\r
439                         settings.endGroup();\r
440                         if (!max.equalsIgnoreCase("true"))\r
441                                 return false;\r
442                         else\r
443                                 return true;    \r
444                 } catch (java.lang.ClassCastException e) {\r
445                         Boolean value = (Boolean) settings.value("showTrayIcon", false);\r
446                         settings.endGroup();\r
447                         return value;\r
448                 }\r
449     }\r
450     public static void setShowTrayIcon(boolean val) {\r
451                 settings.beginGroup("General");\r
452                 if (val)\r
453                         settings.setValue("showTrayIcon", "true");\r
454                 else\r
455                         settings.setValue("showTrayIcon", "false");\r
456                 settings.endGroup();\r
457     }\r
458     \r
459     // Get/Set window maximized when closed last\r
460     public static boolean wasWindowMaximized() {\r
461         try {\r
462                         settings.beginGroup("General");\r
463                         String max = (String) settings.value("isMaximized", "true");\r
464                         settings.endGroup();\r
465                         if (!max.equalsIgnoreCase("true"))\r
466                                 return false;\r
467                         return true;    \r
468                 } catch (java.lang.ClassCastException e) {\r
469                         Boolean value = (Boolean) settings.value("isMaximized", true);\r
470                         settings.endGroup();\r
471                         return value;\r
472                 }\r
473     }\r
474     public static void saveWindowMaximized(boolean isMax) {\r
475                 settings.beginGroup("General");\r
476                 if (isMax)\r
477                         settings.setValue("isMaximized", "true");\r
478                 else\r
479                         settings.setValue("isMaximized", "false");\r
480                 settings.endGroup();\r
481     }\r
482     \r
483     // Get/set currently viewed note Guid\r
484     public static String getLastViewedNoteGuid() {\r
485                 settings.beginGroup("General");\r
486                 String guid = (String) settings.value("lastViewedNote", "");\r
487                 settings.endGroup();\r
488                 return guid;    \r
489     }\r
490     public static void saveCurrentNoteGuid(String guid) {\r
491                 settings.beginGroup("General");\r
492                 if (guid != null)\r
493                         settings.setValue("lastViewedNote", guid);\r
494                 else\r
495                         settings.setValue("lastViewedNote", "");\r
496                 settings.endGroup();\r
497     }\r
498     \r
499     // Get/Set the note column we are sorted on and the order\r
500     public static void setSortColumn(int i) {\r
501         int view = Global.getListView();\r
502                 settings.beginGroup("General");\r
503         if (view == Global.View_List_Wide)\r
504                 settings.setValue("sortColumn", i);\r
505         else\r
506                 settings.setValue("sortColumn-Narrow", i);\r
507                 settings.endGroup();\r
508     }\r
509     public static int getSortColumn() {;\r
510     String key;\r
511         if (Global.getListView() == Global.View_List_Wide)\r
512                 key = "sortColumn";\r
513         else\r
514                 key = "sortColumn-Narrow";\r
515 \r
516         settings.beginGroup("General");\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     public static void setSortOrder(int i) {\r
533         int view = Global.getListView();\r
534                 settings.beginGroup("General");\r
535         if (view == Global.View_List_Wide)\r
536                 settings.setValue("sortOrder", i);\r
537         else\r
538                 settings.setValue("sortOrder-Narrow", i);\r
539                 settings.endGroup();\r
540     }\r
541     public static int getSortOrder() {\r
542         int view = Global.getListView();\r
543                 settings.beginGroup("General");\r
544                 String key;\r
545         if (view == Global.View_List_Wide)\r
546                 key = "sortOrder";\r
547                 else\r
548                         key = "sortOrder-Narrow";\r
549 \r
550                 int order;      \r
551                 try {\r
552                         String val  = settings.value(key, new Integer(0)).toString();\r
553                         order = new Integer(val.trim());\r
554                 } catch (Exception e) {\r
555                         try {\r
556                                 order = (Integer)settings.value(key, 0);\r
557                         } catch (Exception e1) {\r
558                             order = 0;\r
559                         }\r
560                 }\r
561                 \r
562                 settings.endGroup();\r
563                 return order;\r
564     }\r
565     \r
566     // Should we automatically log in to Evernote when starting?\r
567     public static boolean automaticLogin() {\r
568         try {\r
569                 settings.beginGroup("General");\r
570                 String text = (String)settings.value("automaticLogin", "false");\r
571                 settings.endGroup();\r
572                 if (text.equalsIgnoreCase("true"))\r
573                         return true;\r
574                 else\r
575                         return false;           \r
576         } catch (java.lang.ClassCastException e) {\r
577                 Boolean value = (Boolean) settings.value("automaticLogin", false);\r
578                 settings.endGroup();\r
579                 return value;\r
580         }\r
581     }\r
582     public static void setAutomaticLogin(boolean val) {\r
583                 settings.beginGroup("General");\r
584                 if (val)\r
585                         settings.setValue("automaticLogin", "true");\r
586                 else\r
587                         settings.setValue("automaticLogin", "false");\r
588                 settings.endGroup();\r
589     }\r
590     \r
591     // Should it save the Evernote password?\r
592     public static boolean rememberPassword() {\r
593         try {\r
594                         settings.beginGroup("General");\r
595                         String text = (String)settings.value("rememberPassword", "false");\r
596                         settings.endGroup();\r
597                         if (text.equalsIgnoreCase("true"))\r
598                                 return true;\r
599                         else\r
600                                 return false;   \r
601                 } catch (java.lang.ClassCastException e) {\r
602                         Boolean value = (Boolean) settings.value("rememberPassword", false);\r
603                         settings.endGroup();\r
604                         return value;\r
605                 }\r
606     }\r
607     public static void setRememberPassword(boolean val) {\r
608                 settings.beginGroup("General");\r
609                 if (val)\r
610                         settings.setValue("rememberPassword", "true");\r
611                 else\r
612                         settings.setValue("rememberPassword", "false");\r
613                 settings.endGroup();\r
614     }\r
615 \r
616     // Get/set the Evernote server Url.  \r
617     public static void setServer(String server) {\r
618                 settings.beginGroup("General");\r
619                 settings.setValue("server", server);\r
620                 settings.endGroup();            \r
621     }\r
622     public static String getServer() {\r
623                 settings.beginGroup("General");\r
624                 String text = (String)settings.value("server", "www.evernote.com");\r
625                 if (text.equals("www.evernote.com")) {\r
626                         userStoreUrl = "https://www.evernote.com/edam/user";\r
627                     noteStoreUrlBase = "www.evernote.com/edam/note/";   \r
628                 } else {\r
629                         userStoreUrl = "https://sandbox.evernote.com/edam/user";\r
630                         noteStoreUrlBase = "sandbox.evernote.com/edam/note/";\r
631                 }\r
632                 settings.endGroup();\r
633 //              if (isPremium())\r
634                         noteStoreUrlBase = "https://" + noteStoreUrlBase;\r
635 //              else\r
636 //                      noteStoreUrlBase = "http://" + noteStoreUrlBase;\r
637                 return text;\r
638     }\r
639 \r
640     // Get/Set if we should disable uploads to Evernote\r
641     public static boolean disableUploads() {\r
642         settings.beginGroup("General");\r
643         try {\r
644                 String text = (String)settings.value("disableUploads", "false");\r
645                 settings.endGroup();\r
646                 if (text.equalsIgnoreCase("true"))\r
647                         return true;\r
648                 else\r
649                         return false;\r
650                 } catch (java.lang.ClassCastException e) {\r
651                         Boolean value = (Boolean) settings.value("disableUploads", false);\r
652                         settings.endGroup();\r
653                         return value;\r
654                 }\r
655     }\r
656     public static void setDisableUploads(boolean val) {\r
657                 settings.beginGroup("General");\r
658                 if (val)\r
659                         settings.setValue("disableUploads", "true");\r
660                 else\r
661                         settings.setValue("disableUploads", "false");\r
662                 settings.endGroup();\r
663                 disableUploads = val;\r
664     }\r
665  \r
666     // Should we view PDF documents inline?\r
667     public static boolean pdfPreview() {\r
668                 settings.beginGroup("General");\r
669                 try {\r
670                         String text = (String)settings.value("pdfPreview", "true");\r
671                         settings.endGroup();\r
672                         if (text.equalsIgnoreCase("true"))\r
673                                 return true;\r
674                         else\r
675                                 return false;\r
676                 } catch (java.lang.ClassCastException e) {\r
677                         Boolean value = (Boolean) settings.value("pdfPreview", true);\r
678                         settings.endGroup();\r
679                         return value;\r
680                 }\r
681     }\r
682     public static void setPdfPreview(boolean val) {\r
683                 settings.beginGroup("General");\r
684                 if (val)\r
685                         settings.setValue("pdfPreview", "true");\r
686                 else\r
687                         settings.setValue("pdfPreview", "false");\r
688                 settings.endGroup();\r
689     }\r
690     \r
691     // When creating a new note, should it inherit tags that are currently selected?\r
692     public static boolean newNoteWithSelectedTags() {\r
693                 settings.beginGroup("General");\r
694                 try {\r
695                         String text = (String)settings.value("newNoteWithSelectedTags", "false");\r
696                         settings.endGroup();\r
697                         if (text.equalsIgnoreCase("true"))\r
698                                 return true;\r
699                         else\r
700                                 return false;\r
701                 } catch (java.lang.ClassCastException e) {\r
702                         Boolean value = (Boolean) settings.value("newNoteWithSelectedTags", false);\r
703                         settings.endGroup();\r
704                         return value;\r
705                 }\r
706     }\r
707     public static void setNewNoteWithSelectedTags(boolean val) {\r
708                 settings.beginGroup("General");\r
709                 if (val)\r
710                         settings.setValue("newNoteWithSelectedTags", "true");\r
711                 else\r
712                         settings.setValue("newNoteWithSelectedTags", "false");\r
713                 settings.endGroup();\r
714     }\r
715     \r
716     // Minimum weight for text OCRed from Evernote. Anything below this\r
717     // Won't be shown to the user when they search\r
718     public static void setRecognitionWeight(int len) {\r
719                 settings.beginGroup("General");\r
720                 settings.setValue("recognitionWeight", len);\r
721                 settings.endGroup();            \r
722     }\r
723     public static int getRecognitionWeight() {\r
724                 settings.beginGroup("General");\r
725                 Integer len;\r
726                 try {\r
727                         len = (Integer)settings.value("recognitionWeight", 30);\r
728                 } catch (Exception e) {\r
729                         len = 80;\r
730                 }\r
731                 settings.endGroup();\r
732                 return len;\r
733     }\r
734     \r
735     // get/set current debug message level\r
736     public static String getMessageLevel() {\r
737                 settings.beginGroup("Debug");\r
738                 String text = (String)settings.value("messageLevel", "Low");\r
739                 settings.endGroup();\r
740                 return text;\r
741     }\r
742     public static void setDateFormat(String format) {\r
743                 settings.beginGroup("General");\r
744                 settings.setValue("dateFormat", format);\r
745                 settings.endGroup();            \r
746     }\r
747     \r
748     // Get/Set user date/time formats\r
749     public static String getDateFormat() {\r
750                 settings.beginGroup("General");\r
751                 String text = (String)settings.value("dateFormat", "MM/dd/yyyy");\r
752                 settings.endGroup();\r
753                 return text;\r
754     }\r
755     public static void setTimeFormat(String format) {\r
756                 settings.beginGroup("General");\r
757                 settings.setValue("timeFormat", format);\r
758                 settings.endGroup();            \r
759     }\r
760     public static String getTimeFormat() {\r
761                 settings.beginGroup("General");\r
762                 String text = (String)settings.value("timeFormat", "HH:mm:ss");\r
763                 settings.endGroup();\r
764                 return text;\r
765     }\r
766     \r
767     // How often should we sync with Evernote?\r
768     public static String getSyncInterval() {\r
769                 settings.beginGroup("General");\r
770                 String text = (String)settings.value("syncInterval", "15 minutes");\r
771                 settings.endGroup();\r
772                 return text;            \r
773     }\r
774     public static void setSyncInterval(String format) {\r
775                 settings.beginGroup("General");\r
776                 settings.setValue("syncInterval", format);\r
777                 settings.endGroup();            \r
778     }\r
779     \r
780     // Get/Set the width of columns and their position for the \r
781     // next start.\r
782     public static void setColumnWidth(String col, int width) {\r
783         if (Global.getListView() == Global.View_List_Wide)\r
784                 settings.beginGroup("ColumnWidths");\r
785         else \r
786                 settings.beginGroup("ColumnWidths-Narrow");\r
787                 settings.setValue(col, width);\r
788                 settings.endGroup();\r
789         }\r
790     public static int getColumnWidth(String col) {\r
791         int view = Global.getListView();\r
792         if (view == Global.View_List_Wide)\r
793                 settings.beginGroup("ColumnWidths");\r
794         else\r
795                 settings.beginGroup("ColumnWidths-Narrow");\r
796                 Integer width;\r
797                 try {\r
798                         String val  = (String)settings.value(col, "0");\r
799                         width = new Integer(val.trim());\r
800                 } catch (Exception e) {\r
801                         try {\r
802                                 width = (Integer)settings.value(col, 0);\r
803                         } catch (Exception e1) {\r
804                                 width = 0;\r
805                         }\r
806                 }\r
807                 settings.endGroup();\r
808                 return width;\r
809     }\r
810     public static void setColumnPosition(String col, int width) {\r
811         if (Global.getListView() == Global.View_List_Wide)\r
812                 settings.beginGroup("ColumnPosition");\r
813         else\r
814                 settings.beginGroup("ColumnPosition-Narrow");\r
815                 settings.setValue(col, width);\r
816                 settings.endGroup();\r
817     }\r
818     public static int getColumnPosition(String col) {\r
819         if (Global.getListView() == Global.View_List_Wide)\r
820                 settings.beginGroup("ColumnPosition");\r
821         else\r
822                 settings.beginGroup("ColumnPosition-Narrow");\r
823                 Integer width;\r
824                 try {\r
825                         String val  = (String)settings.value(col, "-1");\r
826                         width = new Integer(val.trim());\r
827                 } catch (Exception e) {\r
828                         try {\r
829                                 width = (Integer)settings.value(col, 0);\r
830                         } catch (Exception e1) {\r
831                                 width = 0;\r
832                         }\r
833                 }\r
834                 settings.endGroup();\r
835                 return width;\r
836     }\r
837     \r
838     // Ping the user when they try to delete or just do it.\r
839     public static boolean verifyDelete() {\r
840                 settings.beginGroup("General");\r
841                 try {\r
842                         String text = (String)settings.value("verifyDelete", "true");\r
843                         settings.endGroup();\r
844                         if (text.equalsIgnoreCase("true"))\r
845                                 return true;\r
846                         else\r
847                                 return false;\r
848                 } catch (java.lang.ClassCastException e) {\r
849                         Boolean value = (Boolean) settings.value("verifyDelete", true);\r
850                         settings.endGroup();\r
851                         return value;\r
852                 }\r
853     }\r
854     public static void setVerifyDelete(boolean val) {\r
855                 settings.beginGroup("General");\r
856                 if (val)\r
857                         settings.setValue("verifyDelete", "true");\r
858                 else\r
859                         settings.setValue("verifyDelete", "false");\r
860                 settings.endGroup();\r
861     }\r
862     \r
863     // Should it start minimized?\r
864     public static boolean startMinimized() {\r
865                 settings.beginGroup("General");\r
866                 try {\r
867                         String text = (String)settings.value("startMinimized", "false");\r
868                         settings.endGroup();\r
869                         if (text.equalsIgnoreCase("true"))\r
870                                 return true;\r
871                         else\r
872                                 return false;\r
873                 } catch (java.lang.ClassCastException e) {\r
874                         Boolean value = (Boolean) settings.value("startMinimized", false);\r
875                         settings.endGroup();\r
876                         return value;\r
877                 }\r
878     }\r
879     public static void setStartMinimized(boolean val) {\r
880                 settings.beginGroup("General");\r
881                 if (val)\r
882                         settings.setValue("startMinimized", "true");\r
883                 else\r
884                         settings.setValue("startMinimized", "false");\r
885                 settings.endGroup();\r
886     }\r
887     \r
888     // Should we upload the content of any deleted notes\r
889     public static boolean synchronizeDeletedContent() {\r
890                 settings.beginGroup("General");\r
891                 try {\r
892                         String text = (String)settings.value("syncDeletedContent", "false");\r
893                         settings.endGroup();\r
894                         if (text.equalsIgnoreCase("true"))\r
895                                 return true;\r
896                         else\r
897                                 return false;\r
898                 } catch (java.lang.ClassCastException e) {\r
899                         Boolean value = (Boolean) settings.value("syncDeletedContent", false);\r
900                         settings.endGroup();\r
901                         return value;\r
902                 }\r
903     }   \r
904     public static void setSynchronizeDeletedContent(boolean val) {\r
905                 settings.beginGroup("General");\r
906                 if (val)\r
907                         settings.setValue("syncDeletedContent", "true");\r
908                 else\r
909                         settings.setValue("syncDeletedContent", "false");\r
910                 settings.endGroup();\r
911     }\r
912     \r
913     // Is a section of the window visible?  Used to hide things people don't\r
914     // want to see.\r
915     public static boolean isWindowVisible(String window) {\r
916                 settings.beginGroup("WindowsVisible");\r
917                 try {\r
918                         String defaultValue = "true";\r
919                         if (window.equalsIgnoreCase("noteInformation"))\r
920                                 defaultValue = "false";\r
921                         String text = (String)settings.value(window, defaultValue);\r
922                         settings.endGroup();\r
923                         if (text.equalsIgnoreCase("true"))\r
924                                 return true;\r
925                 else\r
926                         return false;           \r
927                 } catch (java.lang.ClassCastException e) {\r
928                         boolean defaultValue = true;\r
929                         if (window.equalsIgnoreCase("noteInformation"))\r
930                                 defaultValue = false;\r
931                         Boolean value = (Boolean) settings.value("showTrayIcon", defaultValue);\r
932                         settings.endGroup();\r
933                         return value;\r
934                 }\r
935     }\r
936     public static void saveWindowVisible(String window, boolean val) {\r
937                 settings.beginGroup("WindowsVisible");\r
938                 if (val)\r
939                         settings.setValue(window, "true");\r
940                 else\r
941                         settings.setValue(window, "false");\r
942                 settings.endGroup();\r
943     }\r
944     \r
945     // Is a list in the column in the note list visible?  \r
946     public static boolean isColumnVisible(String window) {\r
947         String defaultValue = "true";\r
948         int view = Global.getListView();\r
949         if (Global.getListView() == Global.View_List_Wide)\r
950                 settings.beginGroup("ColumnsVisible");\r
951         else\r
952                 settings.beginGroup("ColumnsVisible-Narrow"); \r
953                 if (window.equalsIgnoreCase("thumbnail") && view == Global.View_List_Wide)\r
954                         defaultValue = "false";\r
955                 if (window.equalsIgnoreCase("thumbnail"))\r
956                         defaultValue = "false";\r
957                 if (window.equalsIgnoreCase("Guid"))\r
958                         defaultValue = "false";\r
959                 try {\r
960                         String text = (String)settings.value(window, defaultValue);\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 defBool = false;\r
968                         if (window.equalsIgnoreCase("true"))\r
969                                 defBool = true;\r
970                         else\r
971                                 defBool = false;\r
972                         Boolean value = (Boolean) settings.value(window, defBool);\r
973                         settings.endGroup();\r
974                         return value;\r
975                 }\r
976     }\r
977     public static void saveColumnVisible(String column, boolean val) {\r
978         if (Global.getListView() == Global.View_List_Wide)\r
979                 settings.beginGroup("ColumnsVisible");\r
980         else\r
981                 settings.beginGroup("ColumnsVisible-Narrow");                   \r
982                 if (val)\r
983                         settings.setValue(column, "true");\r
984                 else\r
985                         settings.setValue(column, "false");\r
986                 settings.endGroup();\r
987     }\r
988     \r
989     // Is a particular editor button visible?\r
990     public static boolean isEditorButtonVisible(String window) {\r
991                 settings.beginGroup("EditorButtonsVisible");\r
992                 try {\r
993                         String text = (String)settings.value(window, "true");\r
994                         settings.endGroup();\r
995                         if (text.equalsIgnoreCase("true"))\r
996                                 return true;\r
997                         else\r
998                                 return false;\r
999                 } catch (java.lang.ClassCastException e) {\r
1000                         Boolean value = (Boolean) settings.value(window, true);\r
1001                         settings.endGroup();\r
1002                         return value;\r
1003                 }\r
1004     }\r
1005     public static void saveEditorButtonsVisible(String column, boolean val) {\r
1006                 settings.beginGroup("EditorButtonsVisible");\r
1007                 if (val)\r
1008                         settings.setValue(column, "true");\r
1009                 else\r
1010                         settings.setValue(column, "false");\r
1011                 settings.endGroup();\r
1012     }\r
1013     \r
1014     // Should the test fixes be enabled\r
1015     public static boolean enableCarriageReturnFix() {\r
1016         try {\r
1017                 settings.beginGroup("Debug");\r
1018                 String text = (String)settings.value("enableCarriageReturnFix", "false");\r
1019                 settings.endGroup();\r
1020                 if (text.equalsIgnoreCase("true"))\r
1021                         return true;\r
1022                 else\r
1023                         return false;\r
1024                 } catch (java.lang.ClassCastException e) {\r
1025                         Boolean value = (Boolean) settings.value("enableCarriageReturnFix", false);\r
1026                         settings.endGroup();\r
1027                         return value;\r
1028                 }\r
1029     }\r
1030     public static void saveCarriageReturnFix(boolean val) {\r
1031                 settings.beginGroup("Debug");\r
1032                 if (val)\r
1033                         settings.setValue("enableCarriageReturnFix", "true");\r
1034                 else\r
1035                         settings.setValue("enableCarriageReturnFix", "false");\r
1036                 settings.endGroup();\r
1037     }\r
1038     public static boolean enableHtmlEntitiesFix() {\r
1039         try {\r
1040                 settings.beginGroup("Debug");\r
1041                 String text = (String)settings.value("enableHtmlEntitiesFix", "false");\r
1042                 settings.endGroup();\r
1043                 if (text.equalsIgnoreCase("true"))\r
1044                         return true;\r
1045                 else\r
1046                         return false;\r
1047                 } catch (java.lang.ClassCastException e) {\r
1048                         Boolean value = (Boolean) settings.value("enableHtmlEntitiesFix", false);\r
1049                         settings.endGroup();\r
1050                         return value;\r
1051                 }\r
1052     }\r
1053     public static void saveHtmlEntitiesFix(boolean val) {\r
1054                 settings.beginGroup("Debug");\r
1055                 if (val)\r
1056                         settings.setValue("enableHtmlEntitiesFix", "true");\r
1057                 else\r
1058                         settings.setValue("enableHtmlEntitiesFix", "false");\r
1059                 settings.endGroup();\r
1060     }\r
1061 \r
1062 //    public static void setIndexThreads(int val) {\r
1063 //              settings.beginGroup("General");\r
1064 //              settings.setValue("indexThreads", val);\r
1065 //              settings.endGroup();\r
1066 //   }\r
1067 //    public static int getIndexThreads() {\r
1068 //              settings.beginGroup("General");\r
1069 //              Integer threads;\r
1070 //              try {\r
1071 //                      String val  = (String)settings.value("indexThreads", "1");\r
1072 //                      threads = new Integer(val.trim());\r
1073 //              } catch (Exception e) {\r
1074 //                      try {\r
1075 //                              threads = (Integer)settings.value("indexThreads", 1);\r
1076 //                      } catch (Exception e1) {\r
1077 //                              threads = 1;\r
1078 //                      }\r
1079 //              }\r
1080 //              settings.endGroup();\r
1081 //              threads = 1;\r
1082 //              return threads;\r
1083     \r
1084     // Get/Set text zoom factor\r
1085 //   }\r
1086     public static void setZoomFactor(double val) {\r
1087                 settings.beginGroup("General");\r
1088                 settings.setValue("zoomFactor", val);\r
1089                 settings.endGroup();\r
1090     }\r
1091     public static double getZoomFactor() {\r
1092                 settings.beginGroup("General");\r
1093                 Double threads;\r
1094                 try {\r
1095                         String val  = (String)settings.value("zoomFactor", "1.0");\r
1096                         threads = new Double(val.trim());\r
1097                 } catch (Exception e) {\r
1098                         try {\r
1099                                 threads = (Double)settings.value("zoomFactor", 1.0);\r
1100                         } catch (Exception e1) {\r
1101                                 threads = new Double(1);\r
1102                         }\r
1103                 }\r
1104                 settings.endGroup();\r
1105                 return threads;\r
1106     }\r
1107     public static void setTextSizeMultiplier(double val) {\r
1108                 settings.beginGroup("General");\r
1109                 settings.setValue("textMultiplier", val);\r
1110                 settings.endGroup();\r
1111     }\r
1112     public static double getTextSizeMultiplier() {\r
1113                 settings.beginGroup("General");\r
1114                 Double threads;\r
1115                 try {\r
1116                         String val  = (String)settings.value("textMultiplier", "1");\r
1117                         threads = new Double(val.trim());\r
1118                 } catch (Exception e) {\r
1119                         try {\r
1120                                 threads = (Double)settings.value("textMultiplier", 1);\r
1121                         } catch (Exception e1) {\r
1122                                 threads = new Double(1);\r
1123                         }\r
1124                 }\r
1125                 settings.endGroup();\r
1126                 return threads;\r
1127     }\r
1128     \r
1129     \r
1130     // Should we mimic Evernote and restrict the notebooks selected?\r
1131     public static boolean getMimicEvernoteInterface() {\r
1132                 settings.beginGroup("General");\r
1133                 try {\r
1134                         String text = (String)settings.value("mimicEvernoteInterface", "true");\r
1135                         settings.endGroup();\r
1136                         if (text.equalsIgnoreCase("true"))\r
1137                                 return true;\r
1138                         else\r
1139                                 return false;\r
1140                 } catch (java.lang.ClassCastException e) {\r
1141                         Boolean value = (Boolean) settings.value("mimicEvernoteInterface", true);\r
1142                         settings.endGroup();\r
1143                         return value;\r
1144                 }\r
1145     }\r
1146     public static void setMimicEvernoteInterface(boolean value) {\r
1147         settings.beginGroup("General");\r
1148         if (value)\r
1149                 settings.setValue("mimicEvernoteInterface", "true");\r
1150         else\r
1151                 settings.setValue("mimicEvernoteInterface", "false"); \r
1152         settings.endGroup();\r
1153     }\r
1154     \r
1155     \r
1156     // Synchronize with Evernote when closing?\r
1157     public static boolean synchronizeOnClose() {\r
1158                 settings.beginGroup("General");\r
1159                 try {\r
1160                         String text = (String)settings.value("synchronizeOnClose", "false");\r
1161                         settings.endGroup();\r
1162                         if (text.equalsIgnoreCase("true"))\r
1163                                 return true;\r
1164                         else\r
1165                                 return false;\r
1166                 } catch (java.lang.ClassCastException e) {\r
1167                         Boolean value = (Boolean) settings.value("synchronizeOnClose", false);\r
1168                         settings.endGroup();\r
1169                         return value;\r
1170                 }\r
1171     }\r
1172     public static void setSynchronizeOnClose(boolean val) {\r
1173                 settings.beginGroup("General");\r
1174                 if (val)\r
1175                         settings.setValue("synchronizeOnClose", "true");\r
1176                 else\r
1177                         settings.setValue("synchronizeOnClose", "false");\r
1178                 settings.endGroup();\r
1179     }\r
1180 \r
1181     // Get/set the database version.  Not really used any more, but kept\r
1182     // for compatibility.\r
1183     public static void setDatabaseVersion(String version) {\r
1184                 settings.beginGroup("General");\r
1185                 settings.setValue("databaseVersion", version);\r
1186                 settings.endGroup();\r
1187     }\r
1188     public static String getDatabaseVersion() {\r
1189                 settings.beginGroup("General");\r
1190                 String val  = (String)settings.value("databaseVersion", "0.70");\r
1191                 settings.endGroup();\r
1192                 return val;\r
1193     }\r
1194 \r
1195     // Get the URL (full path) of the main database\r
1196     public static String getDatabaseUrl() {\r
1197                 settings.beginGroup("General");\r
1198                 String val  = (String)settings.value("DatabaseURL", "");\r
1199                 settings.endGroup();\r
1200                 if (val.equals(""))\r
1201                         val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.databaseName);\r
1202                 return val;\r
1203     }\r
1204     \r
1205     // get the url (full path) of the searchable word database\r
1206     public static String getIndexDatabaseUrl() {\r
1207                 settings.beginGroup("General");\r
1208                 String val  = (String)settings.value("DatabaseURL", "");\r
1209                 settings.endGroup();\r
1210                 if (val.equals(""))\r
1211                         val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.indexDatabaseName);\r
1212                 return val;\r
1213     }\r
1214     \r
1215     // Get the url (full path) of the attachment database\r
1216     public static String getResourceDatabaseUrl() {\r
1217                 settings.beginGroup("General");\r
1218                 String val  = (String)settings.value("DatabaseURL", "");\r
1219                 settings.endGroup();\r
1220                 if (val.equals(""))\r
1221                         val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.resourceDatabaseName);\r
1222                 return val;\r
1223     }\r
1224     public static void setDatabaseUrl(String value) {\r
1225                 settings.beginGroup("General");\r
1226                 settings.setValue("DatabaseURL", value);\r
1227                 settings.endGroup();\r
1228     }\r
1229     public static String getDatabaseUserid() {\r
1230                 settings.beginGroup("General");\r
1231                 String val  = (String)settings.value("databaseUserid", "");\r
1232                 settings.endGroup();\r
1233                 return val;\r
1234     }\r
1235     public static String getDatabaseUserPassword() {\r
1236                 settings.beginGroup("General");\r
1237                 String val  = (String)settings.value("databaseUserPassword", "");\r
1238                 settings.endGroup();\r
1239                 return val;\r
1240     }\r
1241     \r
1242     // get/Set the style sheet and the palette to control the look & feel\r
1243     public static void setStyle(String style) {\r
1244                 settings.beginGroup("General");\r
1245                 settings.setValue("style", style);\r
1246                 settings.endGroup();\r
1247     }\r
1248     public static String getStyle() {\r
1249                 settings.beginGroup("General");\r
1250                 String val  = (String)settings.value("style", "Cleanlooks");\r
1251                 settings.endGroup();\r
1252                 return val;\r
1253     }\r
1254     public static boolean useStandardPalette() {\r
1255                 settings.beginGroup("General");\r
1256                 try {\r
1257                         String text = (String)settings.value("standardPalette", "true");\r
1258                         settings.endGroup();\r
1259                         if (text.equalsIgnoreCase("true"))\r
1260                                 return true;\r
1261                         else\r
1262                                 return false;\r
1263                 } catch (java.lang.ClassCastException e) {\r
1264                         Boolean value = (Boolean) settings.value("standardPalette", true);\r
1265                         settings.endGroup();\r
1266                         return value;\r
1267                 }\r
1268     }\r
1269     public static void setStandardPalette(boolean val) {\r
1270                 settings.beginGroup("General");\r
1271                 if (val)\r
1272                         settings.setValue("standardPalette", "true");\r
1273                 else\r
1274                         settings.setValue("standardPalette", "false");\r
1275                 settings.endGroup();\r
1276     }\r
1277     \r
1278     // Set the amount of time to wait between indexing\r
1279     // Get/Set interval when the index thread wakes up.\r
1280     public static void setIndexThreadSleepInterval(int sleep) {\r
1281                 settings.beginGroup("General");\r
1282                 settings.setValue("IndexThreadSleepInterval", sleep);\r
1283                 settings.endGroup();\r
1284     }\r
1285     public static int getIndexThreadSleepInterval() {\r
1286                 settings.beginGroup("General");\r
1287                 Integer sleep;\r
1288                 try {\r
1289                         String val  = (String)settings.value("IndexThreadSleepInterval", "300");\r
1290                         sleep = new Integer(val.trim());\r
1291                 } catch (Exception e) {\r
1292                         try {\r
1293                                 sleep = (Integer)settings.value("IndexThreadSleepInterval", 0);\r
1294                         } catch (Exception e1) {\r
1295                                 sleep = 300;\r
1296                         }\r
1297                 }\r
1298                 settings.endGroup();\r
1299                 return sleep;\r
1300     }\r
1301     \r
1302     \r
1303     // Get/Set a window state for later restoring\r
1304     public static void saveState(String name, QByteArray state) {\r
1305         int view = Global.getListView();\r
1306         if (view == Global.View_List_Narrow)\r
1307                 name = name +"Narrow";\r
1308                 settings.beginGroup("SaveState");\r
1309                 settings.setValue(name, state);\r
1310                 settings.endGroup();\r
1311     }\r
1312     \r
1313     public static QByteArray restoreState(String name) {\r
1314         int view = Global.getListView();\r
1315         if (view == Global.View_List_Narrow)\r
1316                 name = name +"Narrow";\r
1317                 settings.beginGroup("SaveState");\r
1318                 QByteArray state = (QByteArray)settings.value(name);\r
1319                 settings.endGroup();\r
1320                 return state;\r
1321     }\r
1322     public static void saveGeometry(String name, QByteArray state) {\r
1323         int view = Global.getListView();\r
1324         if (view == Global.View_List_Narrow)\r
1325                 settings.beginGroup("SaveGeometryNarrow");\r
1326         else\r
1327                 settings.beginGroup("SaveGeometry");\r
1328                 settings.setValue(name, state);\r
1329                 settings.endGroup();\r
1330     }\r
1331     \r
1332     public static QByteArray restoreGeometry(String name) {\r
1333         int view = Global.getListView();\r
1334         if (view == Global.View_List_Narrow)\r
1335                 settings.beginGroup("SaveGeometryNarrow");\r
1336         else\r
1337                 settings.beginGroup("SaveGeometry");\r
1338                 QByteArray state = (QByteArray)settings.value(name);\r
1339                 settings.endGroup();\r
1340                 return state;\r
1341     }\r
1342     \r
1343     \r
1344     // Set how often to do an automatic save\r
1345     public static void setAutoSaveInterval(int interval) {\r
1346                 settings.beginGroup("General");\r
1347                 settings.setValue("autoSaveInterval", interval);\r
1348                 settings.endGroup();\r
1349     }\r
1350     public static int getAutoSaveInterval() {\r
1351                 settings.beginGroup("General");\r
1352                 Integer value;\r
1353                 try {\r
1354                         String val  = (String)settings.value("autoSaveInterval", "5");\r
1355                         value = new Integer(val.trim());\r
1356                 } catch (Exception e) {\r
1357                         try {\r
1358                                 value = (Integer)settings.value("autoSaveInterval", 5);\r
1359                         } catch (Exception e1) {\r
1360                                 value = 5;\r
1361                         }\r
1362                 }\r
1363                 settings.endGroup();\r
1364                 return value;\r
1365     }\r
1366      \r
1367     // Add an invalid attribute & element to the database so we don't bother parsing it in the future\r
1368     // These values we automatically remove from any note.\r
1369     // Add invalid attributes\r
1370     public static void addInvalidAttribute(String element, String attribute) {\r
1371         \r
1372                 List<String> attributes = invalidAttributes.get(element);\r
1373                 if (attributes != null) {\r
1374                         for (int i=0; i<attributes.size(); i++)\r
1375                                 if (attribute.equalsIgnoreCase(attributes.get(i))) {\r
1376                                         return;\r
1377                         }\r
1378         }\r
1379         \r
1380         ArrayList<String> attributeList;\r
1381         if (!invalidAttributes.containsKey(element)) {\r
1382                 attributeList = new ArrayList<String>();\r
1383                 attributeList.add(attribute);\r
1384                 invalidAttributes.put(element, attributeList);\r
1385         }\r
1386         else {\r
1387                 attributeList = invalidAttributes.get(element);\r
1388                 attributeList.add(attribute);\r
1389                 invalidAttributes.put(element,attributeList);\r
1390         }\r
1391     }\r
1392    \r
1393     // Add invalid attributes\r
1394     public static void addInvalidElement(String element) {\r
1395                 for (int i=0; i<invalidElements.size(); i++) {\r
1396                         if (element.equalsIgnoreCase(invalidElements.get(i)))\r
1397                                 return;\r
1398                 }\r
1399         invalidElements.add(element);\r
1400     }\r
1401     \r
1402     // Get/Set proxy information\r
1403     // Proxy settings\r
1404     public static String getProxyValue(String key) {\r
1405                 settings.beginGroup("Proxy");\r
1406                 String val  = (String)settings.value(key, "");\r
1407                 settings.endGroup();\r
1408                 return val;\r
1409     }\r
1410     public static void setProxyValue(String key, String value) {\r
1411                 settings.beginGroup("Proxy");\r
1412                 settings.setValue(key, value);\r
1413                 settings.endGroup();\r
1414     }\r
1415     \r
1416     // Change a byte array to a hex string\r
1417     // Convert a byte array to a hex string\r
1418         public static String byteArrayToHexString(byte data[]) {\r
1419                 StringBuffer buf = new StringBuffer();\r
1420             for (byte element : data) {\r
1421                 int halfbyte = (element >>> 4) & 0x0F;\r
1422                 int two_halfs = 0;\r
1423                 do {\r
1424                         if ((0 <= halfbyte) && (halfbyte <= 9))\r
1425                                buf.append((char) ('0' + halfbyte));\r
1426                            else\r
1427                                 buf.append((char) ('a' + (halfbyte - 10)));\r
1428                         halfbyte = element & 0x0F;\r
1429                 } while(two_halfs++ < 1);\r
1430             }\r
1431             return buf.toString();              \r
1432         }\r
1433 \r
1434     \r
1435         // Get/Set spelling settings\r
1436         public static boolean getSpellSetting(String value) {\r
1437                 settings.beginGroup("Spell");\r
1438                 String text = (String)settings.value(value, "");\r
1439                 settings.endGroup();\r
1440                 if (text.equalsIgnoreCase("true"))\r
1441                         return true;\r
1442                 if (text.equalsIgnoreCase("false"))\r
1443                         return false;\r
1444                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREDIGITWORDS))\r
1445                         return true;\r
1446                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREINTERNETADDRESSES))\r
1447                         return true;\r
1448                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREUPPERCASE))\r
1449                         return true;\r
1450                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNORESENTENCECAPITALIZATION))\r
1451                         return true;\r
1452                 return false;\r
1453     }\r
1454     public static void setSpellSetting(String setting, boolean val) {\r
1455                 settings.beginGroup("Spell");\r
1456                 if (val)\r
1457                         settings.setValue(setting, "true");\r
1458                 else\r
1459                         settings.setValue(setting, "false");\r
1460                 settings.endGroup();\r
1461     }\r
1462         \r
1463         // Get/Set how we should display tags (color them, hide unused, or do nothing)\r
1464         // What to do with inactive tags?\r
1465         public static String tagBehavior() {\r
1466                 settings.beginGroup("General");\r
1467                 String text = (String)settings.value("tagBehavior", "DoNothing");\r
1468                 settings.endGroup();\r
1469                 return text;\r
1470         }\r
1471         // What to do with inactive tags?\r
1472         public static void setTagBehavior(String value) {\r
1473                 settings.beginGroup("General");\r
1474                 settings.setValue("tagBehavior", value);\r
1475                 settings.endGroup();\r
1476         }\r
1477 \r
1478     \r
1479         // Should the toolbar be visible?\r
1480         public static boolean isToolbarButtonVisible(String window) {\r
1481                 settings.beginGroup("ToolbarButtonsVisible");\r
1482                 try {\r
1483                         String text = (String)settings.value(window, "true");\r
1484                         settings.endGroup();\r
1485                         if (text.equalsIgnoreCase("true"))\r
1486                                 return true;\r
1487                         else\r
1488                                 return false;   \r
1489                 } catch (java.lang.ClassCastException e) {\r
1490                         Boolean value = (Boolean) settings.value(window, true);\r
1491                         settings.endGroup();\r
1492                         return value;\r
1493                 }\r
1494     }\r
1495     public static void saveToolbarButtonsVisible(String column, boolean val) {\r
1496                 settings.beginGroup("ToolbarButtonsVisible");\r
1497                 if (val)\r
1498                         settings.setValue(column, "true");\r
1499                 else\r
1500                         settings.setValue(column, "false");\r
1501                 settings.endGroup();\r
1502     }\r
1503         \r
1504     // Are thumbnails enabled?\r
1505     \r
1506     public static boolean enableThumbnails() {\r
1507                 settings.beginGroup("Debug");\r
1508                 try {\r
1509                         String text = (String)settings.value("thumbnails", "true");\r
1510                         settings.endGroup();\r
1511                         if (text.equalsIgnoreCase("true"))\r
1512                                 return true;\r
1513                         else\r
1514                                 return false;\r
1515                 } catch (java.lang.ClassCastException e) {\r
1516                         Boolean value = (Boolean) settings.value("thumbnails", true);\r
1517                         settings.endGroup();\r
1518                         return value;\r
1519                 }\r
1520     }\r
1521     public static void setEnableThumbnails(boolean val) {\r
1522                 settings.beginGroup("Debug");\r
1523                 if (val)\r
1524                         settings.setValue("thumbnails", "true");\r
1525                 else\r
1526                         settings.setValue("thumbnails", "false");\r
1527                 settings.endGroup();\r
1528     }\r
1529         \r
1530     // Trace used for performance tuning.  Not normally used in production.\r
1531         // Print date/time.  Used mainly for performance tracing\r
1532         public static void trace(boolean resetInterval) {\r
1533                 String fmt = "MM/dd/yy HH:mm:ss.SSSSSS";\r
1534                 String dateTimeFormat = new String(fmt);\r
1535                 SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);\r
1536                 Calendar cal = Calendar.getInstance();\r
1537                 if (intervalTraceTime == null) \r
1538                         intervalTraceTime = Calendar.getInstance();\r
1539                 if (startTraceTime == null)\r
1540                         startTraceTime = Calendar.getInstance();\r
1541                 \r
1542                 float interval = (cal.getTimeInMillis() - intervalTraceTime.getTimeInMillis());\r
1543                 float total = (cal.getTimeInMillis() - startTraceTime.getTimeInMillis());\r
1544                 \r
1545 //              if (interval > 00.0) {\r
1546                         StackTraceElement[] exceptions = Thread.currentThread().getStackTrace();\r
1547                         System.out.println("------------------------------------------");\r
1548 \r
1549                         System.out.println("Date/Time " +simple.format(cal.getTime()));\r
1550                         System.out.format("Interval Time: %-10.6f%n", interval);\r
1551                         System.out.format("Total Time: %-10.6f%n", total);\r
1552                         for (int i=2; i<5 && i<exceptions.length; i++) {\r
1553                                 System.out.println(exceptions[i]);\r
1554                         }\r
1555 //              }\r
1556                 if (resetInterval)\r
1557                         intervalTraceTime = cal;\r
1558         }\r
1559         public static void traceReset() {\r
1560                 intervalTraceTime = null;\r
1561                 startTraceTime = null;\r
1562         }\r
1563 \r
1564     \r
1565         // Get the FileManager class to manage local files & directories\r
1566         public static FileManager getFileManager() {\r
1567         return fileManager;\r
1568     }\r
1569         \r
1570         // Should the note editor be disabled?\r
1571     public static boolean getDisableViewing() {\r
1572         return disableViewing;\r
1573     }\r
1574 \r
1575     //**********************\r
1576     //* Thumbnail zoom level\r
1577     //**********************\r
1578     public static int calculateThumbnailZoom(String content) {\r
1579         int zoom = 1;\r
1580                 if (content.indexOf("application/pdf") == -1) {\r
1581                         if (content.indexOf("image/") == -1) {\r
1582                                 String text =  StringEscapeUtils.unescapeHtml(content.replaceAll("\\<.*?\\>", ""));\r
1583                                 zoom = 2;\r
1584                                 if (text.length() < 500) \r
1585                                         zoom = 2;\r
1586                                 if (text.length() < 250)\r
1587                                         zoom = 3;\r
1588                                 if (text.length() < 100)\r
1589                                         zoom = 4;\r
1590                                 if (text.length() < 50)\r
1591                                         zoom = 5;\r
1592                                 if (text.length() < 10)\r
1593                                         zoom = 6;\r
1594                         }\r
1595                 }\r
1596                 return zoom;\r
1597     }\r
1598     \r
1599     //**********************\r
1600     //* List View settings \r
1601     //**********************\r
1602     public static void setListView(int view) {\r
1603                 settings.beginGroup("General");\r
1604                 settings.setValue("listView", view);\r
1605                 settings.endGroup();\r
1606     }\r
1607     public static int getListView() {\r
1608                 settings.beginGroup("General");\r
1609                 Integer value;\r
1610                 try {\r
1611                         String val  = (String)settings.value("listView", View_List_Wide);\r
1612                         value = new Integer(val.trim());\r
1613                 } catch (Exception e) {\r
1614                         try {\r
1615                                 value = (Integer)settings.value("listView", View_List_Wide);\r
1616                         } catch (Exception e1) {\r
1617                                 value = View_List_Wide;\r
1618                         }\r
1619                 }\r
1620                 settings.endGroup();\r
1621                 return value;\r
1622     }\r
1623 \r
1624     \r
1625     \r
1626     //*******************\r
1627     // Font Settings\r
1628     //*******************\r
1629     public static boolean overrideDefaultFont() {\r
1630                 settings.beginGroup("Font");\r
1631                 try {\r
1632                         String text = (String)settings.value("overrideFont", "false");\r
1633                         settings.endGroup();\r
1634                         if (text.equalsIgnoreCase("true"))\r
1635                                 return true;\r
1636                         else\r
1637                                 return false;   \r
1638                 } catch (java.lang.ClassCastException e) {\r
1639                         Boolean value = (Boolean) settings.value("overrideFont", false);\r
1640                         settings.endGroup();\r
1641                         return value;\r
1642                 }\r
1643 \r
1644     }\r
1645     \r
1646     //****************************************************\r
1647     // Get/Set the default font settings for a new note\r
1648     //****************************************************\r
1649     public static void setOverrideDefaultFont(boolean value) {\r
1650                 settings.beginGroup("Font");\r
1651                 settings.setValue("overrideFont", value);\r
1652                 settings.endGroup();    \r
1653     }\r
1654     public static String getDefaultFont() {\r
1655                 settings.beginGroup("Font");\r
1656                 String val  = (String)settings.value("font", "");\r
1657                 settings.endGroup();\r
1658                 return val;\r
1659     }\r
1660     public static void setDefaultFont(String value) {\r
1661                 settings.beginGroup("Font");\r
1662                 settings.setValue("font", value);\r
1663                 settings.endGroup();\r
1664     }\r
1665     public static String getDefaultFontSize() {\r
1666                 settings.beginGroup("Font");\r
1667                 String val  = (String)settings.value("fontSize", "");\r
1668                 settings.endGroup();\r
1669                 return val;\r
1670     }\r
1671     public static void setDefaultFontSize(String value) {\r
1672                 settings.beginGroup("Font");\r
1673                 settings.setValue("fontSize", value);\r
1674                 settings.endGroup();\r
1675     }\r
1676     \r
1677     \r
1678     //*******************************************\r
1679     // Override the close & minimize instead.\r
1680     //*******************************************\r
1681     public static boolean minimizeOnClose() {\r
1682                 settings.beginGroup("General");\r
1683                 try {\r
1684                         String text = (String)settings.value("minimizeOnClose", "false");\r
1685                         settings.endGroup();\r
1686                         if (text.equalsIgnoreCase("true"))\r
1687                                 return true;\r
1688                         else\r
1689                                 return false;\r
1690                 } catch (java.lang.ClassCastException e) {\r
1691                         Boolean value = (Boolean) settings.value("minimizeOnClose", false);\r
1692                         settings.endGroup();\r
1693                         return value;\r
1694                 }\r
1695     }\r
1696     public static void setMinimizeOnClose(boolean value) {\r
1697                 settings.beginGroup("General");\r
1698                 settings.setValue("minimizeOnClose", value);\r
1699                 settings.endGroup();    \r
1700     }\r
1701 \r
1702     //*********************************\r
1703     // Check version information\r
1704     //*********************************\r
1705     public static boolean checkVersionUpgrade() {\r
1706                 settings.beginGroup("Upgrade");\r
1707                 try {\r
1708                         String text = (String)settings.value("checkForUpdates", "true");\r
1709                         settings.endGroup();\r
1710                         if (text.equalsIgnoreCase("true"))\r
1711                                 return true;\r
1712                         else\r
1713                                 return false;\r
1714                 } catch (java.lang.ClassCastException e) {\r
1715                         Boolean value = (Boolean) settings.value("checkForUpdates", true);\r
1716                         settings.endGroup();\r
1717                         return value;\r
1718                 }\r
1719     }\r
1720     public static void setCheckVersionUpgrade(boolean value) {\r
1721                 settings.beginGroup("Upgrade");\r
1722                 settings.setValue("checkForUpdates", value);\r
1723                 settings.endGroup();    \r
1724     }\r
1725     public static String getUpdatesAvailableUrl() {\r
1726                 settings.beginGroup("Upgrade");\r
1727                 String text = (String)settings.value("avialableUrl", "http://nevernote.sourceforge.net/versions.txt");\r
1728                 settings.endGroup();    \r
1729                 return text;\r
1730     }\r
1731     public static String getUpdateAnnounceUrl() {\r
1732                 settings.beginGroup("Upgrade");\r
1733                 String text = (String)settings.value("announceUrl", "http://nevernote.sourceforge.net/upgrade.html");\r
1734                 settings.endGroup();    \r
1735                 return text;\r
1736     }\r
1737     \r
1738     //*******************\r
1739     // Index settings\r
1740     //*******************\r
1741     // Set/Get if we should index the text of a note\r
1742     public static boolean indexNoteBody() {\r
1743                 settings.beginGroup("Index");\r
1744                 try {\r
1745                         String value = (String)settings.value("indexNoteBody", "true");\r
1746                         settings.endGroup();\r
1747                         if (value.equals("true"))\r
1748                                 return true;\r
1749                         else\r
1750                                 return false;\r
1751                 } catch (java.lang.ClassCastException e) {\r
1752                         Boolean value = (Boolean) settings.value("indexNoteBody", true);\r
1753                         settings.endGroup();\r
1754                         return value;\r
1755                 }\r
1756     }\r
1757     public static void setIndexNoteTitle(boolean value) {\r
1758                 settings.beginGroup("Index");\r
1759                 settings.setValue("indexNoteTitle", value);\r
1760                 settings.endGroup();    \r
1761     }\r
1762     // Set/Get if we should index the title of a note\r
1763     public static boolean indexNoteTitle() {\r
1764                 settings.beginGroup("Index");\r
1765                 try {\r
1766                         String value = (String)settings.value("indexNoteTitle", "true");\r
1767                         settings.endGroup();\r
1768                         if (value.equals("true"))\r
1769                                 return true;\r
1770                         else\r
1771                                 return false;\r
1772                 } catch (java.lang.ClassCastException e) {\r
1773                         Boolean value = (Boolean) settings.value("indexNoteTitle", true);\r
1774                         settings.endGroup();\r
1775                         return value;\r
1776                 }\r
1777     }\r
1778     public static void setIndexNoteBody(boolean value) {\r
1779                 settings.beginGroup("Index");\r
1780                 settings.setValue("indexNoteBody", value);\r
1781                 settings.endGroup();    \r
1782     }\r
1783     // Set/Get if we should index any attachments\r
1784     public static boolean indexAttachmentsLocally() {\r
1785                 settings.beginGroup("Index");\r
1786                 try {\r
1787                         String value = (String)settings.value("indexAttachmentsLocally", "true");\r
1788                         settings.endGroup();\r
1789                         if (value.equals("true"))\r
1790                                 return true;\r
1791                         else\r
1792                                 return false;\r
1793                 } catch (java.lang.ClassCastException e) {\r
1794                         Boolean value = (Boolean) settings.value("indexAttachmentsLocally", true);\r
1795                         settings.endGroup();\r
1796                         return value;\r
1797                 }\r
1798     }\r
1799     public static void setIndexImageRecognition(boolean value) {\r
1800                 settings.beginGroup("Index");\r
1801                 settings.setValue("indexImageRecognition", value);\r
1802                 settings.endGroup();    \r
1803     }\r
1804     public static boolean indexImageRecognition() {\r
1805                 settings.beginGroup("Index");\r
1806                 try {\r
1807                         String value = (String)settings.value("indexImageRecognition", "true");\r
1808                         settings.endGroup();\r
1809                         if (value.equals("true"))\r
1810                                 return true;\r
1811                         else\r
1812                                 return false;\r
1813                 } catch (java.lang.ClassCastException e) {\r
1814                         Boolean value = (Boolean) settings.value("indexImageRecognition", true);\r
1815                         settings.endGroup();\r
1816                         return value;\r
1817                 }\r
1818     }\r
1819     public static void setIndexAttachmentsLocally(boolean value) {\r
1820                 settings.beginGroup("Index");\r
1821                 settings.setValue("indexAttachmentsLocally", value);\r
1822                 settings.endGroup();    \r
1823     }\r
1824     // Get/Set characters that shouldn't be removed from a word\r
1825     public static String getSpecialIndexCharacters() {\r
1826                 settings.beginGroup("Index");\r
1827                 String text = (String)settings.value("specialCharacters", "");\r
1828                 settings.endGroup();    \r
1829                 return text;\r
1830     }\r
1831     public static void setSpecialIndexCharacters(String value) {\r
1832                 settings.beginGroup("Index");\r
1833                 settings.setValue("specialCharacters", value);\r
1834                 settings.endGroup();    \r
1835                 databaseCache = value;\r
1836     }\r
1837     \r
1838     //*****************************************************************************\r
1839     // Control how tag selection behaves (should they be "and" or "or" selections\r
1840     //*****************************************************************************\r
1841     public static boolean anyTagSelectionMatch() {\r
1842                 settings.beginGroup("General");\r
1843                 try {\r
1844                         String value = (String)settings.value("anyTagSelectionMatch", "false");\r
1845                         settings.endGroup();\r
1846                         if (value.equals("true"))\r
1847                                 return true;\r
1848                         else\r
1849                                 return false;\r
1850                 } catch (java.lang.ClassCastException e) {\r
1851                         Boolean value = (Boolean) settings.value("anyTagSelectionMatch", false);\r
1852                         settings.endGroup();\r
1853                         return value;\r
1854                 }\r
1855     }\r
1856     public static void setAnyTagSelectionMatch(boolean value) {\r
1857                 settings.beginGroup("General");\r
1858                 settings.setValue("anyTagSelectionMatch", value);\r
1859                 settings.endGroup();    \r
1860     }\r
1861 \r
1862     //*****************************************************************************\r
1863     // Control how tag selection behaves (should they be "and" or "or" selections\r
1864     //*****************************************************************************\r
1865     public static boolean bypassSynchronizationWarning() {\r
1866                 settings.beginGroup("User");\r
1867                 try {\r
1868                         String value = (String)settings.value("bypassSynchronizationWarning", "false");\r
1869                         settings.endGroup();\r
1870                         if (value.equals("true"))\r
1871                                 return true;\r
1872                         else\r
1873                                 return false;\r
1874                 } catch (java.lang.ClassCastException e) {\r
1875                         Boolean value = (Boolean) settings.value("bypassSynchronizationWarning", false);\r
1876                         settings.endGroup();\r
1877                         return value;\r
1878                 }\r
1879     }\r
1880     public static void setBypassSynchronizationWarning(boolean value) {\r
1881                 settings.beginGroup("User");\r
1882                 settings.setValue("bypassSynchronizationWarning", value);\r
1883                 settings.endGroup();    \r
1884     }\r
1885 \r
1886     \r
1887     //***********************\r
1888     //* Database cache size\r
1889     //***********************\r
1890     public static String getDatabaseCacheSize() {\r
1891                 settings.beginGroup("Debug");\r
1892                 String text = (String)settings.value("databaseCache", "16384");\r
1893                 settings.endGroup();    \r
1894                 return text;\r
1895     }\r
1896     public static void setDatabaseCache(String value) {\r
1897                 settings.beginGroup("Debug");\r
1898                 settings.setValue("databaseCache", value);\r
1899                 settings.endGroup();    \r
1900                 databaseCache = value;\r
1901     }\r
1902 \r
1903     \r
1904     // This is used to copy a class since Java's normal deep copy is wacked\r
1905     public static Object deepCopy(Object oldObj) \r
1906     {\r
1907        ObjectOutputStream oos = null;\r
1908        ObjectInputStream ois = null;\r
1909        try\r
1910        {\r
1911           ByteArrayOutputStream bos = \r
1912                 new ByteArrayOutputStream(); // A\r
1913           oos = new ObjectOutputStream(bos); // B\r
1914           // serialize and pass the object\r
1915           oos.writeObject(oldObj);   // C\r
1916           oos.flush();               // D\r
1917           ByteArrayInputStream bin = \r
1918                 new ByteArrayInputStream(bos.toByteArray()); // E\r
1919           ois = new ObjectInputStream(bin);                  // F\r
1920           // return the new object\r
1921           return ois.readObject(); // G\r
1922        }\r
1923        catch(Exception e)\r
1924        {\r
1925           Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e);\r
1926        }\r
1927           try {\r
1928                         oos.close();\r
1929                 ois.close();\r
1930                 } catch (IOException e) {\r
1931                         Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e);\r
1932                         e.printStackTrace();\r
1933                 }\r
1934 \r
1935                 return null;\r
1936     }\r
1937 \r
1938 }\r
1939 \r