OSDN Git Service

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