OSDN Git Service

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