OSDN Git Service

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