OSDN Git Service

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