OSDN Git Service

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