OSDN Git Service

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