OSDN Git Service

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