OSDN Git Service

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