OSDN Git Service

Fix non-latin character search problem & remove minimum word length options.
[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 setRecognitionWeight(int len) {\r
548                 settings.beginGroup("General");\r
549                 settings.setValue("recognitionWeight", len);\r
550                 settings.endGroup();            \r
551     }\r
552     public static int getRecognitionWeight() {\r
553                 settings.beginGroup("General");\r
554                 Integer len;\r
555                 try {\r
556                         len = (Integer)settings.value("recognitionWeight", 30);\r
557                 } catch (Exception e) {\r
558                         len = 80;\r
559                 }\r
560                 settings.endGroup();\r
561                 return len;\r
562     }\r
563     public static String getMessageLevel() {\r
564                 settings.beginGroup("Debug");\r
565                 String text = (String)settings.value("messageLevel", "Low");\r
566                 settings.endGroup();\r
567                 return text;\r
568     }\r
569     public static void setDateFormat(String format) {\r
570                 settings.beginGroup("General");\r
571                 settings.setValue("dateFormat", format);\r
572                 settings.endGroup();            \r
573     }\r
574     public static String getDateFormat() {\r
575                 settings.beginGroup("General");\r
576                 String text = (String)settings.value("dateFormat", "MM/dd/yyyy");\r
577                 settings.endGroup();\r
578                 return text;\r
579     }\r
580     public static void setTimeFormat(String format) {\r
581                 settings.beginGroup("General");\r
582                 settings.setValue("timeFormat", format);\r
583                 settings.endGroup();            \r
584     }\r
585     public static String getTimeFormat() {\r
586                 settings.beginGroup("General");\r
587                 String text = (String)settings.value("timeFormat", "HH:mm:ss");\r
588                 settings.endGroup();\r
589                 return text;\r
590     }\r
591     public static String getSyncInterval() {\r
592                 settings.beginGroup("General");\r
593                 String text = (String)settings.value("syncInterval", "15 minutes");\r
594                 settings.endGroup();\r
595                 return text;            \r
596     }\r
597     public static void setSyncInterval(String format) {\r
598                 settings.beginGroup("General");\r
599                 settings.setValue("syncInterval", format);\r
600                 settings.endGroup();            \r
601     }\r
602     public static void setColumnWidth(String col, int width) {\r
603         if (Global.getListView() == Global.View_List_Wide)\r
604                 settings.beginGroup("ColumnWidths");\r
605         else \r
606                 settings.beginGroup("ColumnWidths-Narrow");\r
607                 settings.setValue(col, width);\r
608                 settings.endGroup();\r
609         }\r
610     public static int getColumnWidth(String col) {\r
611         int view = Global.getListView();\r
612         if (view == Global.View_List_Wide)\r
613                 settings.beginGroup("ColumnWidths");\r
614         else\r
615                 settings.beginGroup("ColumnWidths-Narrow");\r
616                 Integer width;\r
617                 try {\r
618                         String val  = (String)settings.value(col, "0");\r
619                         width = new Integer(val.trim());\r
620                 } catch (Exception e) {\r
621                         try {\r
622                                 width = (Integer)settings.value(col, 0);\r
623                         } catch (Exception e1) {\r
624                                 width = 0;\r
625                         }\r
626                 }\r
627                 settings.endGroup();\r
628                 return width;\r
629     }\r
630     public static void setColumnPosition(String col, int width) {\r
631         if (Global.getListView() == Global.View_List_Wide)\r
632                 settings.beginGroup("ColumnPosition");\r
633         else\r
634                 settings.beginGroup("ColumnPosition-Narrow");\r
635                 settings.setValue(col, width);\r
636                 settings.endGroup();\r
637     }\r
638     public static int getColumnPosition(String col) {\r
639         if (Global.getListView() == Global.View_List_Wide)\r
640                 settings.beginGroup("ColumnPosition");\r
641         else\r
642                 settings.beginGroup("ColumnPosition-Narrow");\r
643                 Integer width;\r
644                 try {\r
645                         String val  = (String)settings.value(col, "-1");\r
646                         width = new Integer(val.trim());\r
647                 } catch (Exception e) {\r
648                         try {\r
649                                 width = (Integer)settings.value(col, 0);\r
650                         } catch (Exception e1) {\r
651                                 width = 0;\r
652                         }\r
653                 }\r
654                 settings.endGroup();\r
655                 return width;\r
656     }\r
657     public static boolean verifyDelete() {\r
658                 settings.beginGroup("General");\r
659                 String text = (String)settings.value("verifyDelete", "true");\r
660                 settings.endGroup();\r
661                 if (text.equalsIgnoreCase("true"))\r
662                         return true;\r
663                 else\r
664                         return false;           \r
665     }\r
666     public static void setVerifyDelete(boolean val) {\r
667                 settings.beginGroup("General");\r
668                 if (val)\r
669                         settings.setValue("verifyDelete", "true");\r
670                 else\r
671                         settings.setValue("verifyDelete", "false");\r
672                 settings.endGroup();\r
673     }\r
674     public static boolean startMinimized() {\r
675                 settings.beginGroup("General");\r
676                 String text = (String)settings.value("startMinimized", "false");\r
677                 settings.endGroup();\r
678                 if (text.equalsIgnoreCase("true"))\r
679                         return true;\r
680                 else\r
681                         return false;           \r
682     }\r
683     public static void setStartMinimized(boolean val) {\r
684                 settings.beginGroup("General");\r
685                 if (val)\r
686                         settings.setValue("startMinimized", "true");\r
687                 else\r
688                         settings.setValue("startMinimized", "false");\r
689                 settings.endGroup();\r
690     }\r
691     public static boolean synchronizeDeletedContent() {\r
692                 settings.beginGroup("General");\r
693                 String text = (String)settings.value("syncDeletedContent", "false");\r
694                 settings.endGroup();\r
695                 if (text.equalsIgnoreCase("true"))\r
696                         return true;\r
697                 else\r
698                         return false;           \r
699     }\r
700     public static void setSynchronizeDeletedContent(boolean val) {\r
701                 settings.beginGroup("General");\r
702                 if (val)\r
703                         settings.setValue("syncDeletedContent", "true");\r
704                 else\r
705                         settings.setValue("syncDeletedContent", "false");\r
706                 settings.endGroup();\r
707     }\r
708     public static boolean isWindowVisible(String window) {\r
709                 settings.beginGroup("WindowsVisible");\r
710                 String defaultValue = "true";\r
711                 if (window.equalsIgnoreCase("noteInformation"))\r
712                         defaultValue = "false";\r
713                 String text = (String)settings.value(window, defaultValue);\r
714                 settings.endGroup();\r
715                 if (text.equalsIgnoreCase("true"))\r
716                         return true;\r
717                 else\r
718                         return false;           \r
719     }\r
720     public static void saveWindowVisible(String window, boolean val) {\r
721                 settings.beginGroup("WindowsVisible");\r
722                 if (val)\r
723                         settings.setValue(window, "true");\r
724                 else\r
725                         settings.setValue(window, "false");\r
726                 settings.endGroup();\r
727     }\r
728     public static boolean isColumnVisible(String window) {\r
729         String defaultValue = "true";\r
730         int view = Global.getListView();\r
731         if (Global.getListView() == Global.View_List_Wide)\r
732                 settings.beginGroup("ColumnsVisible");\r
733         else\r
734                 settings.beginGroup("ColumnsVisible-Narrow"); \r
735 //              if (view == Global.View_List_Narrow)\r
736 //                      defaultValue = "false";\r
737                 if (window.equalsIgnoreCase("thumbnail") && view == Global.View_List_Wide)\r
738                         defaultValue = "false";\r
739                 if (window.equalsIgnoreCase("thumbnail"))\r
740                         defaultValue = "false";\r
741                 if (window.equalsIgnoreCase("Guid"))\r
742                         defaultValue = "false";\r
743 //              if (window.equalsIgnoreCase("thumbnail") && view == Global.View_List_Narrow)\r
744 //                      defaultValue = "true";\r
745                 String text = (String)settings.value(window, defaultValue);\r
746                 settings.endGroup();\r
747                 if (text.equalsIgnoreCase("true"))\r
748                         return true;\r
749                 else\r
750                         return false;   \r
751     }\r
752     public static void saveColumnVisible(String column, boolean val) {\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 (val)\r
758                         settings.setValue(column, "true");\r
759                 else\r
760                         settings.setValue(column, "false");\r
761                 settings.endGroup();\r
762     }\r
763     public static boolean isEditorButtonVisible(String window) {\r
764                 settings.beginGroup("EditorButtonsVisible");\r
765                 String text = (String)settings.value(window, "true");\r
766                 settings.endGroup();\r
767                 if (text.equalsIgnoreCase("true"))\r
768                         return true;\r
769                 else\r
770                         return false;   \r
771     }\r
772     public static void saveEditorButtonsVisible(String column, boolean val) {\r
773                 settings.beginGroup("EditorButtonsVisible");\r
774                 if (val)\r
775                         settings.setValue(column, "true");\r
776                 else\r
777                         settings.setValue(column, "false");\r
778                 settings.endGroup();\r
779     }\r
780     public static boolean enableCarriageReturnFix() {\r
781                 settings.beginGroup("Debug");\r
782                 String text = (String)settings.value("enableCarriageReturnFix", "false");\r
783                 settings.endGroup();\r
784                 if (text.equalsIgnoreCase("true"))\r
785                         return true;\r
786                 else\r
787                         return false;   \r
788     }\r
789     public static void saveCarriageReturnFix(boolean val) {\r
790                 settings.beginGroup("Debug");\r
791                 if (val)\r
792                         settings.setValue("enableCarriageReturnFix", "true");\r
793                 else\r
794                         settings.setValue("enableCarriageReturnFix", "false");\r
795                 settings.endGroup();\r
796     }\r
797     public static void setIndexThreads(int val) {\r
798                 settings.beginGroup("General");\r
799                 settings.setValue("indexThreads", val);\r
800                 settings.endGroup();\r
801     }\r
802     public static int getIndexThreads() {\r
803                 settings.beginGroup("General");\r
804                 Integer threads;\r
805                 try {\r
806                         String val  = (String)settings.value("indexThreads", "1");\r
807                         threads = new Integer(val.trim());\r
808                 } catch (Exception e) {\r
809                         try {\r
810                                 threads = (Integer)settings.value("indexThreads", 1);\r
811                         } catch (Exception e1) {\r
812                                 threads = 1;\r
813                         }\r
814                 }\r
815                 settings.endGroup();\r
816                 threads = 1;\r
817                 return threads;\r
818     }\r
819     public static void setZoomFactor(double val) {\r
820                 settings.beginGroup("General");\r
821                 settings.setValue("zoomFactor", val);\r
822                 settings.endGroup();\r
823     }\r
824     public static double getZoomFactor() {\r
825                 settings.beginGroup("General");\r
826                 Double threads;\r
827                 try {\r
828                         String val  = (String)settings.value("zoomFactor", "1.0");\r
829                         threads = new Double(val.trim());\r
830                 } catch (Exception e) {\r
831                         try {\r
832                                 threads = (Double)settings.value("zoomFactor", 1.0);\r
833                         } catch (Exception e1) {\r
834                                 threads = new Double(1);\r
835                         }\r
836                 }\r
837                 settings.endGroup();\r
838                 return threads;\r
839     }\r
840     public static void setTextSizeMultiplier(double val) {\r
841                 settings.beginGroup("General");\r
842                 settings.setValue("textMultiplier", val);\r
843                 settings.endGroup();\r
844     }\r
845     public static double getTextSizeMultiplier() {\r
846                 settings.beginGroup("General");\r
847                 Double threads;\r
848                 try {\r
849                         String val  = (String)settings.value("textMultiplier", "1");\r
850                         threads = new Double(val.trim());\r
851                 } catch (Exception e) {\r
852                         try {\r
853                                 threads = (Double)settings.value("textMultiplier", 1);\r
854                         } catch (Exception e1) {\r
855                                 threads = new Double(1);\r
856                         }\r
857                 }\r
858                 settings.endGroup();\r
859                 return threads;\r
860     }\r
861     \r
862     public static boolean getMimicEvernoteInterface() {\r
863                 settings.beginGroup("General");\r
864                 String text = (String)settings.value("mimicEvernoteInterface", "true");\r
865                 settings.endGroup();\r
866                 if (text.equalsIgnoreCase("true"))\r
867                         return true;\r
868                 else\r
869                         return false;\r
870     }\r
871     public static void setMimicEvernoteInterface(boolean value) {\r
872         settings.beginGroup("General");\r
873         if (value)\r
874                 settings.setValue("mimicEvernoteInterface", "true");\r
875         else\r
876                 settings.setValue("mimicEvernoteInterface", "false"); \r
877         settings.endGroup();\r
878     }\r
879     \r
880     public static boolean synchronizeOnClose() {\r
881                 settings.beginGroup("General");\r
882                 String text = (String)settings.value("synchronizeOnClose", "false");\r
883                 settings.endGroup();\r
884                 if (text.equalsIgnoreCase("true"))\r
885                         return true;\r
886                 else\r
887                         return false;\r
888     }\r
889     public static void setSynchronizeOnClose(boolean val) {\r
890                 settings.beginGroup("General");\r
891                 if (val)\r
892                         settings.setValue("synchronizeOnClose", "true");\r
893                 else\r
894                         settings.setValue("synchronizeOnClose", "false");\r
895                 settings.endGroup();\r
896     }\r
897     public static void setDatabaseVersion(String version) {\r
898                 settings.beginGroup("General");\r
899                 settings.setValue("databaseVersion", version);\r
900                 settings.endGroup();\r
901     }\r
902     public static String getDatabaseVersion() {\r
903                 settings.beginGroup("General");\r
904                 String val  = (String)settings.value("databaseVersion", "0.70");\r
905                 settings.endGroup();\r
906                 return val;\r
907     }\r
908     public static String getDatabaseUrl() {\r
909                 settings.beginGroup("General");\r
910                 String val  = (String)settings.value("DatabaseURL", "");\r
911                 settings.endGroup();\r
912                 if (val.equals(""))\r
913                         val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.databaseName);\r
914                 return val;\r
915     }\r
916     public static void setDatabaseUrl(String value) {\r
917                 settings.beginGroup("General");\r
918                 settings.setValue("DatabaseURL", value);\r
919                 settings.endGroup();\r
920     }\r
921     public static String getDatabaseUserid() {\r
922                 settings.beginGroup("General");\r
923                 String val  = (String)settings.value("databaseUserid", "");\r
924                 settings.endGroup();\r
925                 return val;\r
926     }\r
927     public static String getDatabaseUserPassword() {\r
928                 settings.beginGroup("General");\r
929                 String val  = (String)settings.value("databaseUserPassword", "");\r
930                 settings.endGroup();\r
931                 return val;\r
932     }\r
933     public static void setStyle(String style) {\r
934                 settings.beginGroup("General");\r
935                 settings.setValue("style", style);\r
936                 settings.endGroup();\r
937     }\r
938     public static String getStyle() {\r
939                 settings.beginGroup("General");\r
940                 String val  = (String)settings.value("style", "");\r
941                 settings.endGroup();\r
942                 return val;\r
943     }\r
944     public static boolean useStandardPalette() {\r
945                 settings.beginGroup("General");\r
946                 String text = (String)settings.value("standardPalette", "true");\r
947                 settings.endGroup();\r
948                 if (text.equalsIgnoreCase("true"))\r
949                         return true;\r
950                 else\r
951                         return false;\r
952     }\r
953     public static void setStandardPalette(boolean val) {\r
954                 settings.beginGroup("General");\r
955                 if (val)\r
956                         settings.setValue("standardPalette", "true");\r
957                 else\r
958                         settings.setValue("standardPalette", "false");\r
959                 settings.endGroup();\r
960     }\r
961     \r
962     // Get/Set interval when the index thread wakes up.\r
963     public static void setIndexThreadSleepInterval(int sleep) {\r
964                 settings.beginGroup("General");\r
965                 settings.setValue("IndexThreadSleepInterval", sleep);\r
966                 settings.endGroup();\r
967     }\r
968     public static int getIndexThreadSleepInterval() {\r
969                 settings.beginGroup("General");\r
970                 Integer sleep;\r
971                 try {\r
972                         String val  = (String)settings.value("IndexThreadSleepInterval", "300");\r
973                         sleep = new Integer(val.trim());\r
974                 } catch (Exception e) {\r
975                         try {\r
976                                 sleep = (Integer)settings.value("IndexThreadSleepInterval", 0);\r
977                         } catch (Exception e1) {\r
978                                 sleep = 300;\r
979                         }\r
980                 }\r
981                 settings.endGroup();\r
982                 return sleep;\r
983     }\r
984     \r
985     public static void saveState(String name, QByteArray state) {\r
986         int view = Global.getListView();\r
987         if (view == Global.View_List_Narrow)\r
988                 name = name +"Narrow";\r
989                 settings.beginGroup("SaveState");\r
990                 settings.setValue(name, state);\r
991                 settings.endGroup();\r
992     }\r
993     \r
994     public static QByteArray restoreState(String name) {\r
995         int view = Global.getListView();\r
996         if (view == Global.View_List_Narrow)\r
997                 name = name +"Narrow";\r
998                 settings.beginGroup("SaveState");\r
999                 QByteArray state = (QByteArray)settings.value(name);\r
1000                 settings.endGroup();\r
1001                 return state;\r
1002     }\r
1003     public static void saveGeometry(String name, QByteArray state) {\r
1004         int view = Global.getListView();\r
1005         if (view == Global.View_List_Narrow)\r
1006                 settings.beginGroup("SaveGeometryNarrow");\r
1007         else\r
1008                 settings.beginGroup("SaveGeometry");\r
1009                 settings.setValue(name, state);\r
1010                 settings.endGroup();\r
1011     }\r
1012     \r
1013     public static QByteArray restoreGeometry(String name) {\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                 QByteArray state = (QByteArray)settings.value(name);\r
1020                 settings.endGroup();\r
1021                 return state;\r
1022     }\r
1023     \r
1024     public static void setAutoSaveInterval(int interval) {\r
1025                 settings.beginGroup("General");\r
1026                 settings.setValue("autoSaveInterval", interval);\r
1027                 settings.endGroup();\r
1028     }\r
1029     public static int getAutoSaveInterval() {\r
1030                 settings.beginGroup("General");\r
1031                 Integer value;\r
1032                 try {\r
1033                         String val  = (String)settings.value("autoSaveInterval", "5");\r
1034                         value = new Integer(val.trim());\r
1035                 } catch (Exception e) {\r
1036                         try {\r
1037                                 value = (Integer)settings.value("autoSaveInterval", 5);\r
1038                         } catch (Exception e1) {\r
1039                                 value = 5;\r
1040                         }\r
1041                 }\r
1042                 settings.endGroup();\r
1043                 return value;\r
1044     }\r
1045      \r
1046     // Add invalid attributes\r
1047     public static void addInvalidAttribute(String element, String attribute) {\r
1048         \r
1049                 List<String> attributes = invalidAttributes.get(element);\r
1050                 if (attributes != null) {\r
1051                         for (int i=0; i<attributes.size(); i++)\r
1052                                 if (attribute.equalsIgnoreCase(attributes.get(i))) {\r
1053                                         return;\r
1054                         }\r
1055         }\r
1056         \r
1057         ArrayList<String> attributeList;\r
1058         if (!invalidAttributes.containsKey(element)) {\r
1059                 attributeList = new ArrayList<String>();\r
1060                 attributeList.add(attribute);\r
1061                 invalidAttributes.put(element, attributeList);\r
1062         }\r
1063         else {\r
1064                 attributeList = invalidAttributes.get(element);\r
1065                 attributeList.add(attribute);\r
1066                 invalidAttributes.put(element,attributeList);\r
1067         }\r
1068     }\r
1069 \r
1070     \r
1071     // Add invalid attributes\r
1072     public static void addInvalidElement(String element) {\r
1073                 for (int i=0; i<invalidElements.size(); i++) {\r
1074                         if (element.equalsIgnoreCase(invalidElements.get(i)))\r
1075                                 return;\r
1076                 }\r
1077         invalidElements.add(element);\r
1078     }\r
1079     \r
1080     // Proxy settings\r
1081     public static String getProxyValue(String key) {\r
1082                 settings.beginGroup("Proxy");\r
1083                 String val  = (String)settings.value(key, "");\r
1084                 settings.endGroup();\r
1085                 return val;\r
1086     }\r
1087     public static void setProxyValue(String key, String value) {\r
1088                 settings.beginGroup("Proxy");\r
1089                 settings.setValue(key, value);\r
1090                 settings.endGroup();\r
1091     }\r
1092     \r
1093     \r
1094     // Convert a byte array to a hex string\r
1095         public static String byteArrayToHexString(byte data[]) {\r
1096                 StringBuffer buf = new StringBuffer();\r
1097             for (byte element : data) {\r
1098                 int halfbyte = (element >>> 4) & 0x0F;\r
1099                 int two_halfs = 0;\r
1100                 do {\r
1101                         if ((0 <= halfbyte) && (halfbyte <= 9))\r
1102                                buf.append((char) ('0' + halfbyte));\r
1103                            else\r
1104                                 buf.append((char) ('a' + (halfbyte - 10)));\r
1105                         halfbyte = element & 0x0F;\r
1106                 } while(two_halfs++ < 1);\r
1107             }\r
1108             return buf.toString();              \r
1109         }\r
1110 \r
1111     public static boolean getSpellSetting(String value) {\r
1112                 settings.beginGroup("Spell");\r
1113                 String text = (String)settings.value(value, "");\r
1114                 settings.endGroup();\r
1115                 if (text.equalsIgnoreCase("true"))\r
1116                         return true;\r
1117                 if (text.equalsIgnoreCase("false"))\r
1118                         return false;\r
1119                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREDIGITWORDS))\r
1120                         return true;\r
1121                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREINTERNETADDRESSES))\r
1122                         return true;\r
1123                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREUPPERCASE))\r
1124                         return true;\r
1125                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNORESENTENCECAPITALIZATION))\r
1126                         return true;\r
1127                 return false;\r
1128     }\r
1129     public static void setSpellSetting(String setting, boolean val) {\r
1130                 settings.beginGroup("Spell");\r
1131                 if (val)\r
1132                         settings.setValue(setting, "true");\r
1133                 else\r
1134                         settings.setValue(setting, "false");\r
1135                 settings.endGroup();\r
1136     }\r
1137         \r
1138         \r
1139         // What to do with inactive tags?\r
1140         public static String tagBehavior() {\r
1141                 settings.beginGroup("General");\r
1142                 String text = (String)settings.value("tagBehavior", "DoNothing");\r
1143                 settings.endGroup();\r
1144                 return text;\r
1145         }\r
1146         // What to do with inactive tags?\r
1147         public static void setTagBehavior(String value) {\r
1148                 settings.beginGroup("General");\r
1149                 settings.setValue("tagBehavior", value);\r
1150                 settings.endGroup();\r
1151         }\r
1152 \r
1153     public static boolean isToolbarButtonVisible(String window) {\r
1154                 settings.beginGroup("ToolbarButtonsVisible");\r
1155                 String text = (String)settings.value(window, "true");\r
1156                 settings.endGroup();\r
1157                 if (text.equalsIgnoreCase("true"))\r
1158                         return true;\r
1159                 else\r
1160                         return false;   \r
1161     }\r
1162     public static void saveToolbarButtonsVisible(String column, boolean val) {\r
1163                 settings.beginGroup("ToolbarButtonsVisible");\r
1164                 if (val)\r
1165                         settings.setValue(column, "true");\r
1166                 else\r
1167                         settings.setValue(column, "false");\r
1168                 settings.endGroup();\r
1169     }\r
1170         \r
1171     \r
1172     public static boolean enableThumbnails() {\r
1173                 settings.beginGroup("Debug");\r
1174                 String text = (String)settings.value("thumbnails", "false");\r
1175                 settings.endGroup();\r
1176                 if (text.equalsIgnoreCase("true"))\r
1177                         return true;\r
1178                 else\r
1179                         return false;   \r
1180     }\r
1181     public static void setEnableThumbnails(boolean val) {\r
1182                 settings.beginGroup("Debug");\r
1183                 if (val)\r
1184                         settings.setValue("thumbnails", "true");\r
1185                 else\r
1186                         settings.setValue("thumbnails", "false");\r
1187                 settings.endGroup();\r
1188     }\r
1189         \r
1190         // Print date/time.  Used mainly for performance tracing\r
1191         public static void trace(boolean resetInterval) {\r
1192                 String fmt = "MM/dd/yy HH:mm:ss.SSSSSS";\r
1193                 String dateTimeFormat = new String(fmt);\r
1194                 SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);\r
1195                 Calendar cal = Calendar.getInstance();\r
1196                 if (intervalTraceTime == null) \r
1197                         intervalTraceTime = Calendar.getInstance();\r
1198                 if (startTraceTime == null)\r
1199                         startTraceTime = Calendar.getInstance();\r
1200                 \r
1201                 float interval = (cal.getTimeInMillis() - intervalTraceTime.getTimeInMillis());\r
1202                 float total = (cal.getTimeInMillis() - startTraceTime.getTimeInMillis());\r
1203                 \r
1204 //              if (interval > 00.0) {\r
1205                         StackTraceElement[] exceptions = Thread.currentThread().getStackTrace();\r
1206                         System.out.println("------------------------------------------");\r
1207 \r
1208                         System.out.println("Date/Time " +simple.format(cal.getTime()));\r
1209                         System.out.format("Interval Time: %-10.6f%n", interval);\r
1210                         System.out.format("Total Time: %-10.6f%n", total);\r
1211                         for (int i=2; i<5 && i<exceptions.length; i++) {\r
1212                                 System.out.println(exceptions[i]);\r
1213                         }\r
1214 //              }\r
1215                 if (resetInterval)\r
1216                         intervalTraceTime = cal;\r
1217         }\r
1218         public static void traceReset() {\r
1219                 intervalTraceTime = null;\r
1220                 startTraceTime = null;\r
1221         }\r
1222 \r
1223     public static FileManager getFileManager() {\r
1224         return fileManager;\r
1225     }\r
1226     public static boolean getDisableViewing() {\r
1227         return disableViewing;\r
1228     }\r
1229 \r
1230     //**********************\r
1231     //* Thumbnail zoom level\r
1232     //**********************\r
1233     public static int calculateThumbnailZoom(String content) {\r
1234         int zoom = 1;\r
1235                 if (content.indexOf("application/pdf") == -1) {\r
1236                         if (content.indexOf("image/") == -1) {\r
1237                                 String text =  StringEscapeUtils.unescapeHtml(content.replaceAll("\\<.*?\\>", ""));\r
1238                                 zoom = 2;\r
1239                                 if (text.length() < 500) \r
1240                                         zoom = 2;\r
1241                                 if (text.length() < 250)\r
1242                                         zoom = 3;\r
1243                                 if (text.length() < 100)\r
1244                                         zoom = 4;\r
1245                                 if (text.length() < 50)\r
1246                                         zoom = 5;\r
1247                                 if (text.length() < 10)\r
1248                                         zoom = 6;\r
1249                         }\r
1250                 }\r
1251                 return zoom;\r
1252     }\r
1253     \r
1254     //**********************\r
1255     //* List View settings \r
1256     //**********************\r
1257     public static void setListView(int view) {\r
1258                 settings.beginGroup("General");\r
1259                 settings.setValue("listView", view);\r
1260                 settings.endGroup();\r
1261     }\r
1262     public static int getListView() {\r
1263                 settings.beginGroup("General");\r
1264                 Integer value;\r
1265                 try {\r
1266                         String val  = (String)settings.value("listView", View_List_Wide);\r
1267                         value = new Integer(val.trim());\r
1268                 } catch (Exception e) {\r
1269                         try {\r
1270                                 value = (Integer)settings.value("listView", View_List_Wide);\r
1271                         } catch (Exception e1) {\r
1272                                 value = View_List_Wide;\r
1273                         }\r
1274                 }\r
1275                 settings.endGroup();\r
1276                 return value;\r
1277     }\r
1278 \r
1279     \r
1280     \r
1281     //*******************\r
1282     // Font Settings\r
1283     //*******************\r
1284     public static boolean overrideDefaultFont() {\r
1285                 settings.beginGroup("Font");\r
1286                 String text = (String)settings.value("overrideFont", "false");\r
1287                 settings.endGroup();\r
1288                 if (text.equalsIgnoreCase("true"))\r
1289                         return true;\r
1290                 else\r
1291                         return false;   \r
1292     }\r
1293     public static void setOverrideDefaultFont(boolean value) {\r
1294                 settings.beginGroup("Font");\r
1295                 settings.setValue("overrideFont", value);\r
1296                 settings.endGroup();    \r
1297     }\r
1298     public static String getDefaultFont() {\r
1299                 settings.beginGroup("Font");\r
1300                 String val  = (String)settings.value("font", "");\r
1301                 settings.endGroup();\r
1302                 return val;\r
1303     }\r
1304     public static void setDefaultFont(String value) {\r
1305                 settings.beginGroup("Font");\r
1306                 settings.setValue("font", value);\r
1307                 settings.endGroup();\r
1308     }\r
1309     public static String getDefaultFontSize() {\r
1310                 settings.beginGroup("Font");\r
1311                 String val  = (String)settings.value("fontSize", "");\r
1312                 settings.endGroup();\r
1313                 return val;\r
1314     }\r
1315     public static void setDefaultFontSize(String value) {\r
1316                 settings.beginGroup("Font");\r
1317                 settings.setValue("fontSize", value);\r
1318                 settings.endGroup();\r
1319     }\r
1320     \r
1321     \r
1322     //*******************\r
1323     // Close/Minimize\r
1324     //*******************\r
1325     public static boolean minimizeOnClose() {\r
1326                 settings.beginGroup("General");\r
1327                 String text = (String)settings.value("minimizeOnClose", "false");\r
1328                 settings.endGroup();\r
1329                 if (text.equalsIgnoreCase("true"))\r
1330                         return true;\r
1331                 else\r
1332                         return false;   \r
1333     }\r
1334     public static void setMinimizeOnClose(boolean value) {\r
1335                 settings.beginGroup("General");\r
1336                 settings.setValue("minimizeOnClose", value);\r
1337                 settings.endGroup();    \r
1338     }\r
1339 \r
1340     \r
1341     //*******************\r
1342     // Index attachments\r
1343     //*******************\r
1344     public static boolean indexAttachmentsLocally() {\r
1345                 settings.beginGroup("Debug");\r
1346                 String text = (String)settings.value("indexAttachmentsLocally", "true");\r
1347                 settings.endGroup();\r
1348                 if (text.equalsIgnoreCase("true"))\r
1349                         return true;\r
1350                 else\r
1351                         return false;   \r
1352     }\r
1353     public static void setIndexAttachmentsLocally(boolean value) {\r
1354                 settings.beginGroup("Debug");\r
1355                 settings.setValue("indexAttachmentsLocally", value);\r
1356                 settings.endGroup();    \r
1357     }\r
1358 \r
1359 \r
1360 }\r
1361 \r