OSDN Git Service

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