OSDN Git Service

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