OSDN Git Service

Correct problem parsing notes where carriage returns did not separate some XML lines...
[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 com.evernote.edam.type.Accounting;\r
33 import com.evernote.edam.type.PrivilegeLevel;\r
34 import com.evernote.edam.type.User;\r
35 import com.evernote.edam.type.UserAttributes;\r
36 import com.trolltech.qt.core.QByteArray;\r
37 import com.trolltech.qt.core.QSettings;\r
38 import com.trolltech.qt.gui.QPalette;\r
39 \r
40 import cx.fbn.nevernote.config.FileManager;\r
41 import cx.fbn.nevernote.config.InitializationException;\r
42 import cx.fbn.nevernote.config.StartupConfig;\r
43 import cx.fbn.nevernote.gui.ContainsAttributeFilterTable;\r
44 import cx.fbn.nevernote.gui.DateAttributeFilterTable;\r
45 import cx.fbn.nevernote.gui.ShortcutKeys;\r
46 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
47 \r
48 public class Global {\r
49         public static String version = "0.90";\r
50     public static String username = ""; \r
51     public static String password = "";     \r
52     \r
53 \r
54     public static final int mainThreadId=0;\r
55     \r
56     public static final int syncThreadId=1;\r
57     \r
58     public static final int tagCounterThreadId=2;\r
59     \r
60     public static final int trashCounterThreadId=3;   // This should always be the highest thread ID\r
61 \r
62     public static final int indexThreadId=4;    // Thread for indexing words\r
63 \r
64     public static final int saveThreadId=5;     // Thread used for processing data to saving content\r
65 \r
66     public static final int notebookCounterThreadId=6;   // Notebook Thread\r
67 \r
68     public static final int indexThread03Id=7;   // unused\r
69 \r
70     public static final int indexThread04Id=8;   // unused\r
71     \r
72     public static final int dbThreadId=9;   // This should always be the highest thread ID\r
73     \r
74     \r
75     public static HashMap<String,String> passwordSafe = new HashMap<String, String>();\r
76     public static List<String> passwordRemember = new ArrayList<String>();\r
77     public static String currentNotebookGuid;\r
78     public static User user; \r
79     public static long authTimeRemaining;\r
80     public static long authRefreshTime;\r
81     public static long failedRefreshes = 0;\r
82     public static boolean keepRunning;\r
83     \r
84     public static String userStoreUrl;\r
85     public static String noteStoreUrl;\r
86     public static String noteStoreUrlBase;\r
87     \r
88     public static int noteTableCreationPosition = 0;\r
89     public static int noteTableTitlePosition = 1;\r
90     public static int noteTableTagPosition = 2;\r
91     public static int noteTableNotebookPosition = 3;\r
92     public static int noteTableChangedPosition = 4;\r
93     public static int noteTableGuidPosition = 5;\r
94     public static int noteTableAuthorPosition = 6;\r
95     public static int noteTableSourceUrlPosition = 7;\r
96     public static int noteTableSubjectDatePosition = 8;\r
97     public static int noteTableSynchronizedPosition = 9;\r
98     public static int noteTableColumnCount = 10;\r
99     public static Integer cryptCounter = 0;\r
100     \r
101     public static int minimumWordCount = 2;\r
102     private static String wordRegex;\r
103     public static boolean enableCarriageReturnFix = false;\r
104     \r
105     public static String name = null;\r
106     public static QSettings     settings;\r
107     public static boolean isConnected;\r
108     public static boolean showDeleted = false;\r
109     public static boolean disableUploads = false;\r
110         public static int messageLevel;\r
111         public static String tagDelimeter = ",";\r
112         public static String attachmentNameDelimeter = "------";\r
113         \r
114         public static String    databaseName = new String("NeverNote");\r
115         public static DateAttributeFilterTable createdSinceFilter;\r
116         public static DateAttributeFilterTable createdBeforeFilter;\r
117         public static DateAttributeFilterTable changedSinceFilter;\r
118         public static DateAttributeFilterTable changedBeforeFilter;\r
119         public static ContainsAttributeFilterTable containsFilter;\r
120         public static ApplicationLogger    logger;\r
121         PrintStream stdoutStream;\r
122         public static QPalette                          originalPalette;\r
123         public static ShortcutKeys                      shortcutKeys;\r
124         public static boolean                           disableViewing;\r
125         \r
126         public static List<String>                              invalidElements = new ArrayList<String>();\r
127         public static HashMap<String, ArrayList<String>>        invalidAttributes = new HashMap<String, ArrayList<String>>();\r
128         public static boolean mimicEvernoteInterface;\r
129         public static HashMap<String,String> resourceMap;\r
130         public static String cipherPassword = "";\r
131         \r
132         static Calendar startTraceTime;\r
133         static Calendar intervalTraceTime;\r
134 \r
135         private static FileManager fileManager;\r
136         \r
137     // Do initial setup \r
138     public static void setup(StartupConfig startupConfig) throws InitializationException  {\r
139         settings = new QSettings("fbn.cx", startupConfig.getName());\r
140         disableViewing = startupConfig.getDisableViewing();\r
141 \r
142         fileManager = new FileManager(startupConfig.getHomeDirPath(), startupConfig.getProgramDirPath());\r
143 \r
144 \r
145                         getServer();\r
146                         settings.beginGroup("General");\r
147                         String regex = (String) settings.value("regex", "[,\\s]+");\r
148                         setWordRegex(regex);\r
149                         String wordString = settings.value("minimumWordLength", "4").toString();\r
150                         Integer wordLen = new Integer(wordString);\r
151                         Global.minimumWordCount = wordLen;\r
152                         settings.endGroup();\r
153                         settings.beginGroup("Debug");\r
154                         String msglevel = (String) settings.value("messageLevel", "Low");\r
155                         settings.endGroup();\r
156                         messageLevel = 1;\r
157                         setMessageLevel(msglevel);\r
158                         keepRunning = true;\r
159                         disableUploads = disableUploads();\r
160                         enableCarriageReturnFix = enableCarriageReturnFix();\r
161                         logger = new ApplicationLogger("global.log");\r
162                         shortcutKeys = new ShortcutKeys();\r
163                         mimicEvernoteInterface = getMimicEvernoteInterface();\r
164                         resourceMap = new HashMap<String,String>();\r
165                                 \r
166     }\r
167 \r
168     public static String getWordRegex() {\r
169         return wordRegex;\r
170     }\r
171     public static void setWordRegex(String r) {\r
172         wordRegex = r;\r
173     }\r
174     public static void setMessageLevel(String msglevel) {\r
175         if (msglevel.equalsIgnoreCase("low")) \r
176                         messageLevel = 1;\r
177                 if (msglevel.equalsIgnoreCase("medium")) \r
178                         messageLevel = 2;\r
179                 if (msglevel.equalsIgnoreCase("high")) \r
180                                 messageLevel = 3;\r
181                 if (msglevel.equalsIgnoreCase("extreme")) \r
182                                         messageLevel = 4;\r
183                 settings.beginGroup("Debug");\r
184                 settings.setValue("messageLevel", msglevel);\r
185                 settings.endGroup();            \r
186     }\r
187 \r
188     public static void saveUserInformation(User user) {\r
189         settings.beginGroup("User");\r
190                 settings.setValue("id", user.getId());\r
191                 settings.setValue("username", user.getUsername());\r
192                 settings.setValue("email", user.getEmail());\r
193                 settings.setValue("name", user.getName());\r
194                 settings.setValue("timezone", user.getTimezone());\r
195                 settings.setValue("privilege", user.getPrivilege().getValue());\r
196                 settings.setValue("created", user.getCreated());\r
197                 settings.setValue("updated", user.getUpdated());\r
198                 settings.setValue("deleted", user.getDeleted());\r
199                 settings.endGroup();\r
200                 isPremium();\r
201                 if (user.getAttributes()!=null)\r
202                         saveUserAttributes(user.getAttributes());\r
203                 if (user.getAccounting()!=null)\r
204                         saveUserAccounting(user.getAccounting());\r
205 \r
206     }\r
207     public static void saveUserAttributes(UserAttributes attrib) {\r
208         settings.beginGroup("UserAttributes");\r
209                 settings.setValue("defaultLocationName", attrib.getDefaultLocationName());\r
210                 settings.setValue("defaultLatitude", attrib.getDefaultLocationName());\r
211                 settings.setValue("defaultLongitude", attrib.getDefaultLocationName());\r
212                 settings.setValue("incomingEmailAddress", attrib.getIncomingEmailAddress());\r
213                 settings.endGroup();\r
214     }\r
215     public static UserAttributes getUserAttributes() {\r
216         settings.beginGroup("UserAttributes");\r
217         UserAttributes attrib = new UserAttributes();\r
218                 attrib.setDefaultLocationName((String)settings.value("defaultLocationName",""));\r
219                 attrib.setDefaultLatitudeIsSet(false);\r
220                 attrib.setDefaultLongitudeIsSet(false);\r
221                 attrib.setIncomingEmailAddress((String)settings.value("incomingEmailAddress", ""));\r
222                 settings.endGroup();\r
223                 return attrib;\r
224     }\r
225     public static void saveUserAccounting(Accounting acc) {\r
226         settings.beginGroup("UserAccounting");\r
227                 settings.setValue("uploadLimit", acc.getUploadLimit());\r
228                 settings.setValue("uploadLimitEnd", acc.getUploadLimitEnd());\r
229                 settings.setValue("uploadLimitNextMonth", acc.getUploadLimitNextMonth());\r
230                 settings.setValue("premiumServiceStart", acc.getPremiumServiceStart());\r
231                 settings.setValue("nextPaymentDue", acc.getNextPaymentDue());\r
232                 settings.setValue("uploadAmount", acc.getUpdated());\r
233                 settings.endGroup();\r
234     }\r
235     public static long getUploadLimitEnd() {\r
236         Long limit;\r
237         settings.beginGroup("UserAccounting");\r
238         \r
239         // Upload limit\r
240                 try {\r
241                         String val  = (String)settings.value("uploadLimitEnd", "0");\r
242                         limit = new Long(val.trim());\r
243                 } catch (Exception e) {\r
244                         try {\r
245                                 limit = (Long)settings.value("uploadLimitEnd", 0);\r
246                         } catch (Exception e1) {\r
247                                 limit = new Long(0);\r
248                         }\r
249                 }\r
250         \r
251                 // return value\r
252         settings.endGroup();\r
253         return limit;\r
254     }\r
255     public static void saveUploadAmount(long amount) {\r
256         settings.beginGroup("UserAccounting");\r
257                 settings.setValue("uploadAmount", amount);\r
258                 settings.endGroup();\r
259    }\r
260     public static long getUploadAmount() {\r
261                 long amt=0;\r
262                 settings.beginGroup("UserAccounting");\r
263                 try {\r
264                         String num = (String)settings.value("uploadAmount", "0");\r
265                         amt = new Long(num.trim());\r
266                 } catch (Exception e) {\r
267                         try {\r
268                                 amt = (Integer)settings.value("uploadAmount", 0);\r
269                         } catch (Exception e1) {\r
270                                 amt = 0;\r
271                         }\r
272                 }\r
273                 settings.endGroup();\r
274                 return amt;\r
275     }\r
276     public static void saveEvernoteUpdateCount(long amount) {\r
277         settings.beginGroup("UserAccounting");\r
278                 settings.setValue("updateCount", amount);\r
279                 settings.endGroup();\r
280     }\r
281     public static long getEvernoteUpdateCount() {\r
282                 long amt;\r
283                 settings.beginGroup("UserAccounting");\r
284                 try {\r
285                         String num = (String)settings.value("updateCount", new Long(0).toString());\r
286                         amt = new Long(num.trim());\r
287                 } catch (java.lang.ClassCastException e) {\r
288                         amt = 0;\r
289                 }\r
290                 settings.endGroup();\r
291                 return amt;\r
292     }\r
293     public static boolean isPremium() {\r
294                 int level;\r
295                 settings.beginGroup("User");\r
296                 try {\r
297                         String num = (String)settings.value("privilege", "1");\r
298                         level = new Integer(num.trim());\r
299                 } catch (java.lang.ClassCastException e) {\r
300                         try {\r
301                                 level = (Integer)settings.value("privilege", 1);\r
302                         } catch (Exception e1) {\r
303                                 level = 1;\r
304                         }\r
305                 }\r
306                 settings.endGroup();\r
307                 PrivilegeLevel userLevel = PrivilegeLevel.findByValue(level);\r
308                 if (userLevel == PrivilegeLevel.NORMAL)\r
309                         return false;\r
310                 return true;\r
311                 \r
312    }\r
313     public static long getUploadLimit() {\r
314                 settings.beginGroup("UserAccounting");\r
315                 long limit;\r
316                 try {\r
317                         String num = (String)settings.value("uploadLimit", new Long(0).toString());\r
318                         limit = new Long(num.trim());\r
319                 } catch (java.lang.ClassCastException e) {\r
320                         limit = 0;\r
321                 }\r
322                 settings.endGroup();\r
323                 return limit;\r
324     }\r
325     public static boolean showTrayIcon() {\r
326                 settings.beginGroup("General");\r
327                 String max = (String) settings.value("showTrayIcon", "true");\r
328                 settings.endGroup();\r
329                 if (!max.equalsIgnoreCase("true"))\r
330                         return false;\r
331                 return true;    \r
332     }\r
333     public static void setShowTrayIcon(boolean val) {\r
334                 settings.beginGroup("General");\r
335                 if (val)\r
336                         settings.setValue("showTrayIcon", "true");\r
337                 else\r
338                         settings.setValue("showTrayIcon", "false");\r
339                 settings.endGroup();\r
340     }\r
341     public static boolean wasWindowMaximized() {\r
342                 settings.beginGroup("General");\r
343                 String max = (String) settings.value("isMaximized", "true");\r
344                 settings.endGroup();\r
345                 if (!max.equalsIgnoreCase("true"))\r
346                         return false;\r
347                 return true;    \r
348     }\r
349     public static void saveWindowMaximized(boolean isMax) {\r
350                 settings.beginGroup("General");\r
351                 if (isMax)\r
352                         settings.setValue("isMaximized", "true");\r
353                 else\r
354                         settings.setValue("isMaximized", "false");\r
355                 settings.endGroup();\r
356     }\r
357     public static String getLastViewedNoteGuid() {\r
358                 settings.beginGroup("General");\r
359                 String guid = (String) settings.value("lastViewedNote", "");\r
360                 settings.endGroup();\r
361                 return guid;    \r
362     }\r
363     public static void saveCurrentNoteGuid(String guid) {\r
364                 settings.beginGroup("General");\r
365                 if (guid != null)\r
366                         settings.setValue("lastViewedNote", guid);\r
367                 else\r
368                         settings.setValue("lastViewedNote", "");\r
369                 settings.endGroup();\r
370     }\r
371     public static void setSortColumn(int i) {\r
372                 settings.beginGroup("General");\r
373                 settings.setValue("sortColumn", i);\r
374                 settings.endGroup();\r
375     }\r
376     public static int getSortColumn() {;\r
377         settings.beginGroup("General");\r
378         int order;      \r
379         try {\r
380                 String val  = settings.value("sortColumn", new Integer(0)).toString();\r
381                 order = new Integer(val.trim());\r
382         } catch (Exception e) {\r
383                 try {\r
384                         order = (Integer)settings.value("sortColumn", 0);\r
385                 } catch (Exception e1) {\r
386                     order = 0;\r
387                 }\r
388         }\r
389         \r
390         settings.endGroup();\r
391         return order;\r
392     }\r
393     public static void setSortOrder(int i) {\r
394                 settings.beginGroup("General");\r
395                 settings.setValue("sortOrder", i);\r
396                 settings.endGroup();\r
397     }\r
398     public static int getSortOrder() {\r
399                 settings.beginGroup("General");\r
400                 int order;      \r
401                 try {\r
402                         String val  = settings.value("sortOrder", new Integer(0)).toString();\r
403                         order = new Integer(val.trim());\r
404                 } catch (Exception e) {\r
405                         try {\r
406                                 order = (Integer)settings.value("sortOrder", 0);\r
407                         } catch (Exception e1) {\r
408                             order = 0;\r
409                         }\r
410                 }\r
411                 \r
412                 settings.endGroup();\r
413                 return order;\r
414     }\r
415     public static boolean automaticLogin() {\r
416                 settings.beginGroup("General");\r
417                 String text = (String)settings.value("automaticLogin", "false");\r
418                 settings.endGroup();\r
419                 if (text.equalsIgnoreCase("true"))\r
420                         return true;\r
421                 else\r
422                         return false;           \r
423     }\r
424     public static void setAutomaticLogin(boolean val) {\r
425                 settings.beginGroup("General");\r
426                 if (val)\r
427                         settings.setValue("automaticLogin", "true");\r
428                 else\r
429                         settings.setValue("automaticLogin", "false");\r
430                 settings.endGroup();\r
431     }\r
432     public static boolean rememberPassword() {\r
433                 settings.beginGroup("General");\r
434                 String text = (String)settings.value("rememberPassword", "false");\r
435                 settings.endGroup();\r
436                 if (text.equalsIgnoreCase("true"))\r
437                         return true;\r
438                 else\r
439                         return false;           \r
440     }\r
441     public static void setRememberPassword(boolean val) {\r
442                 settings.beginGroup("General");\r
443                 if (val)\r
444                         settings.setValue("rememberPassword", "true");\r
445                 else\r
446                         settings.setValue("rememberPassword", "false");\r
447                 settings.endGroup();\r
448     }\r
449     public static void setServer(String server) {\r
450                 settings.beginGroup("General");\r
451                 settings.setValue("server", server);\r
452                 settings.endGroup();            \r
453     }\r
454     public static String getServer() {\r
455                 settings.beginGroup("General");\r
456                 String text = (String)settings.value("server", "www.evernote.com");\r
457                 if (text.equals("www.evernote.com")) {\r
458                         userStoreUrl = "https://www.evernote.com/edam/user";\r
459                     noteStoreUrlBase = "www.evernote.com/edam/note/";   \r
460                 } else {\r
461                         userStoreUrl = "https://sandbox.evernote.com/edam/user";\r
462                         noteStoreUrlBase = "sandbox.evernote.com/edam/note/";\r
463                 }\r
464                 settings.endGroup();\r
465                 if (isPremium())\r
466                         noteStoreUrlBase = "https://" + noteStoreUrlBase;\r
467                 else\r
468                         noteStoreUrlBase = "http://" + noteStoreUrlBase;\r
469                 return text;\r
470     }\r
471     public static boolean disableUploads() {\r
472                 settings.beginGroup("General");\r
473                 String text = (String)settings.value("disableUploads", "false");\r
474                 settings.endGroup();\r
475                 if (text.equalsIgnoreCase("true"))\r
476                         return true;\r
477                 else\r
478                         return false;\r
479     }\r
480     public static void setDisableUploads(boolean val) {\r
481                 settings.beginGroup("General");\r
482                 if (val)\r
483                         settings.setValue("disableUploads", "true");\r
484                 else\r
485                         settings.setValue("disableUploads", "false");\r
486                 settings.endGroup();\r
487                 disableUploads = val;\r
488     }\r
489     public static boolean pdfPreview() {\r
490                 settings.beginGroup("General");\r
491                 String text = (String)settings.value("pdfPreview", "true");\r
492                 settings.endGroup();\r
493                 if (text.equalsIgnoreCase("true"))\r
494                         return true;\r
495                 else\r
496                         return false;\r
497     }\r
498     public static void setPdfPreview(boolean val) {\r
499                 settings.beginGroup("General");\r
500                 if (val)\r
501                         settings.setValue("pdfPreview", "true");\r
502                 else\r
503                         settings.setValue("pdfPreview", "false");\r
504                 settings.endGroup();\r
505     }\r
506     public static boolean newNoteWithSelectedTags() {\r
507                 settings.beginGroup("General");\r
508                 String text = (String)settings.value("newNoteWithSelectedTags", "false");\r
509                 settings.endGroup();\r
510                 if (text.equalsIgnoreCase("true"))\r
511                         return true;\r
512                 else\r
513                         return false;\r
514     }\r
515     public static void setNewNoteWithSelectedTags(boolean val) {\r
516                 settings.beginGroup("General");\r
517                 if (val)\r
518                         settings.setValue("newNoteWithSelectedTags", "true");\r
519                 else\r
520                         settings.setValue("newNoteWithSelectedTags", "false");\r
521                 settings.endGroup();\r
522     }\r
523     public static void setMinimumWordLength(int len) {\r
524                 settings.beginGroup("General");\r
525                 settings.setValue("minimumWordLength", len);\r
526                 settings.endGroup();            \r
527     }\r
528     public static int getMinimumWordLength() {\r
529                 settings.beginGroup("General");\r
530                 Integer len = 4;\r
531                 try {\r
532                         String val  = (String)settings.value("minimumWordLength", "4");\r
533                         len = new Integer(val);\r
534                 } catch (Exception e) {\r
535                         try {\r
536                                 len = (Integer)settings.value("minimumWordLength", 4);\r
537                         } catch (Exception e1) {\r
538                                 len = 4;\r
539                         }\r
540                 }\r
541                 settings.endGroup();\r
542                 return len;\r
543                 \r
544     }\r
545     public static void setRecognitionWeight(int len) {\r
546                 settings.beginGroup("General");\r
547                 settings.setValue("recognitionWeight", len);\r
548                 settings.endGroup();            \r
549     }\r
550     public static int getRecognitionWeight() {\r
551                 settings.beginGroup("General");\r
552                 Integer len;\r
553                 try {\r
554                         len = (Integer)settings.value("recognitionWeight", 80);\r
555                 } catch (Exception e) {\r
556                         len = 80;\r
557                 }\r
558                 settings.endGroup();\r
559                 return len;\r
560     }\r
561     public static String getMessageLevel() {\r
562                 settings.beginGroup("Debug");\r
563                 String text = (String)settings.value("messageLevel", "Low");\r
564                 settings.endGroup();\r
565                 return text;\r
566     }\r
567     public static void setDateFormat(String format) {\r
568                 settings.beginGroup("General");\r
569                 settings.setValue("dateFormat", format);\r
570                 settings.endGroup();            \r
571     }\r
572     public static String getDateFormat() {\r
573                 settings.beginGroup("General");\r
574                 String text = (String)settings.value("dateFormat", "MM/dd/yyyy");\r
575                 settings.endGroup();\r
576                 return text;\r
577     }\r
578     public static void setTimeFormat(String format) {\r
579                 settings.beginGroup("General");\r
580                 settings.setValue("timeFormat", format);\r
581                 settings.endGroup();            \r
582     }\r
583     public static String getTimeFormat() {\r
584                 settings.beginGroup("General");\r
585                 String text = (String)settings.value("timeFormat", "HH:mm:ss");\r
586                 settings.endGroup();\r
587                 return text;\r
588     }\r
589     public static String getSyncInterval() {\r
590                 settings.beginGroup("General");\r
591                 String text = (String)settings.value("syncInterval", "15 minutes");\r
592                 settings.endGroup();\r
593                 return text;            \r
594     }\r
595     public static void setSyncInterval(String format) {\r
596                 settings.beginGroup("General");\r
597                 settings.setValue("syncInterval", format);\r
598                 settings.endGroup();            \r
599     }\r
600     public static void setColumnWidth(String col, int width) {\r
601                 settings.beginGroup("ColumnWidths");\r
602                 settings.setValue(col, width);\r
603                 settings.endGroup();\r
604     }\r
605     public static int getColumnWidth(String col) {\r
606                 settings.beginGroup("ColumnWidths");\r
607                 Integer width;\r
608                 try {\r
609                         String val  = (String)settings.value(col, "0");\r
610                         width = new Integer(val.trim());\r
611                 } catch (Exception e) {\r
612                         try {\r
613                                 width = (Integer)settings.value(col, 0);\r
614                         } catch (Exception e1) {\r
615                                 width = 0;\r
616                         }\r
617                 }\r
618                 settings.endGroup();\r
619                 return width;\r
620     }\r
621     public static void setColumnPosition(String col, int width) {\r
622                 settings.beginGroup("ColumnPosition");\r
623                 settings.setValue(col, width);\r
624                 settings.endGroup();\r
625     }\r
626     public static int getColumnPosition(String col) {\r
627                 settings.beginGroup("ColumnPosition");\r
628                 Integer width;\r
629                 try {\r
630                         String val  = (String)settings.value(col, "-1");\r
631                         width = new Integer(val.trim());\r
632                 } catch (Exception e) {\r
633                         try {\r
634                                 width = (Integer)settings.value(col, 0);\r
635                         } catch (Exception e1) {\r
636                                 width = 0;\r
637                         }\r
638                 }\r
639                 settings.endGroup();\r
640                 return width;\r
641     }\r
642     public static boolean verifyDelete() {\r
643                 settings.beginGroup("General");\r
644                 String text = (String)settings.value("verifyDelete", "true");\r
645                 settings.endGroup();\r
646                 if (text.equalsIgnoreCase("true"))\r
647                         return true;\r
648                 else\r
649                         return false;           \r
650     }\r
651     public static void setVerifyDelete(boolean val) {\r
652                 settings.beginGroup("General");\r
653                 if (val)\r
654                         settings.setValue("verifyDelete", "true");\r
655                 else\r
656                         settings.setValue("verifyDelete", "false");\r
657                 settings.endGroup();\r
658     }\r
659     public static boolean synchronizeDeletedContent() {\r
660                 settings.beginGroup("General");\r
661                 String text = (String)settings.value("syncDeletedContent", "false");\r
662                 settings.endGroup();\r
663                 if (text.equalsIgnoreCase("true"))\r
664                         return true;\r
665                 else\r
666                         return false;           \r
667     }\r
668     public static void setSynchronizeDeletedContent(boolean val) {\r
669                 settings.beginGroup("General");\r
670                 if (val)\r
671                         settings.setValue("syncDeletedContent", "true");\r
672                 else\r
673                         settings.setValue("syncDeletedContent", "false");\r
674                 settings.endGroup();\r
675     }\r
676     public static boolean isWindowVisible(String window) {\r
677                 settings.beginGroup("WindowsVisible");\r
678                 String text = (String)settings.value(window, "true");\r
679                 settings.endGroup();\r
680                 if (text.equalsIgnoreCase("true"))\r
681                         return true;\r
682                 else\r
683                         return false;           \r
684     }\r
685     public static void saveWindowVisible(String window, boolean val) {\r
686                 settings.beginGroup("WindowsVisible");\r
687                 if (val)\r
688                         settings.setValue(window, "true");\r
689                 else\r
690                         settings.setValue(window, "false");\r
691                 settings.endGroup();\r
692     }\r
693     public static boolean isColumnVisible(String window) {\r
694                 settings.beginGroup("ColumnsVisible");\r
695                 String text = (String)settings.value(window, "true");\r
696                 settings.endGroup();\r
697                 if (text.equalsIgnoreCase("true"))\r
698                         return true;\r
699                 else\r
700                         return false;   \r
701     }\r
702     public static void saveColumnVisible(String column, boolean val) {\r
703                 settings.beginGroup("ColumnsVisible");\r
704                 if (val)\r
705                         settings.setValue(column, "true");\r
706                 else\r
707                         settings.setValue(column, "false");\r
708                 settings.endGroup();\r
709     }\r
710     public static boolean isEditorButtonVisible(String window) {\r
711                 settings.beginGroup("EditorButtonsVisible");\r
712                 String text = (String)settings.value(window, "true");\r
713                 settings.endGroup();\r
714                 if (text.equalsIgnoreCase("true"))\r
715                         return true;\r
716                 else\r
717                         return false;   \r
718     }\r
719     public static void saveEditorButtonsVisible(String column, boolean val) {\r
720                 settings.beginGroup("EditorButtonsVisible");\r
721                 if (val)\r
722                         settings.setValue(column, "true");\r
723                 else\r
724                         settings.setValue(column, "false");\r
725                 settings.endGroup();\r
726     }\r
727     public static boolean enableCarriageReturnFix() {\r
728                 settings.beginGroup("Debug");\r
729                 String text = (String)settings.value("enableCarriageReturnFix", "false");\r
730                 settings.endGroup();\r
731                 if (text.equalsIgnoreCase("true"))\r
732                         return true;\r
733                 else\r
734                         return false;   \r
735     }\r
736     public static void saveCarriageReturnFix(boolean val) {\r
737                 settings.beginGroup("Debug");\r
738                 if (val)\r
739                         settings.setValue("enableCarriageReturnFix", "true");\r
740                 else\r
741                         settings.setValue("enableCarriageReturnFix", "false");\r
742                 settings.endGroup();\r
743     }\r
744     public static void setIndexThreads(int val) {\r
745                 settings.beginGroup("General");\r
746                 settings.setValue("indexThreads", val);\r
747                 settings.endGroup();\r
748     }\r
749     public static int getIndexThreads() {\r
750                 settings.beginGroup("General");\r
751                 Integer threads;\r
752                 try {\r
753                         String val  = (String)settings.value("indexThreads", "1");\r
754                         threads = new Integer(val.trim());\r
755                 } catch (Exception e) {\r
756                         try {\r
757                                 threads = (Integer)settings.value("indexThreads", 1);\r
758                         } catch (Exception e1) {\r
759                                 threads = 1;\r
760                         }\r
761                 }\r
762                 settings.endGroup();\r
763                 threads = 1;\r
764                 return threads;\r
765     }\r
766     public static void setZoomFactor(double val) {\r
767                 settings.beginGroup("General");\r
768                 settings.setValue("zoomFactor", val);\r
769                 settings.endGroup();\r
770     }\r
771     public static double getZoomFactor() {\r
772                 settings.beginGroup("General");\r
773                 Double threads;\r
774                 try {\r
775                         String val  = (String)settings.value("zoomFactor", "1.0");\r
776                         threads = new Double(val.trim());\r
777                 } catch (Exception e) {\r
778                         try {\r
779                                 threads = (Double)settings.value("zoomFactor", 1.0);\r
780                         } catch (Exception e1) {\r
781                                 threads = new Double(1);\r
782                         }\r
783                 }\r
784                 settings.endGroup();\r
785                 return threads;\r
786     }\r
787     public static void setTextSizeMultiplier(double val) {\r
788                 settings.beginGroup("General");\r
789                 settings.setValue("textMultiplier", val);\r
790                 settings.endGroup();\r
791     }\r
792     public static double getTextSizeMultiplier() {\r
793                 settings.beginGroup("General");\r
794                 Double threads;\r
795                 try {\r
796                         String val  = (String)settings.value("textMultiplier", "1");\r
797                         threads = new Double(val.trim());\r
798                 } catch (Exception e) {\r
799                         try {\r
800                                 threads = (Double)settings.value("textMultiplier", 1);\r
801                         } catch (Exception e1) {\r
802                                 threads = new Double(1);\r
803                         }\r
804                 }\r
805                 settings.endGroup();\r
806                 return threads;\r
807     }\r
808 \r
809     public static boolean getMimicEvernoteInterface() {\r
810                 settings.beginGroup("General");\r
811                 String text = (String)settings.value("mimicEvernoteInterface", "true");\r
812                 settings.endGroup();\r
813                 if (text.equalsIgnoreCase("true"))\r
814                         return true;\r
815                 else\r
816                         return false;\r
817     }\r
818     public static void setMimicEvernoteInterface(boolean value) {\r
819         settings.beginGroup("General");\r
820         if (value)\r
821                 settings.setValue("mimicEvernoteInterface", "true");\r
822         else\r
823                 settings.setValue("mimicEvernoteInterface", "false"); \r
824         settings.endGroup();\r
825     }\r
826     \r
827     public static boolean synchronizeOnClose() {\r
828                 settings.beginGroup("General");\r
829                 String text = (String)settings.value("synchronizeOnClose", "false");\r
830                 settings.endGroup();\r
831                 if (text.equalsIgnoreCase("true"))\r
832                         return true;\r
833                 else\r
834                         return false;\r
835     }\r
836     public static void setSynchronizeOnClose(boolean val) {\r
837                 settings.beginGroup("General");\r
838                 if (val)\r
839                         settings.setValue("synchronizeOnClose", "true");\r
840                 else\r
841                         settings.setValue("synchronizeOnClose", "false");\r
842                 settings.endGroup();\r
843     }\r
844     public static void setDatabaseVersion(String version) {\r
845                 settings.beginGroup("General");\r
846                 settings.setValue("databaseVersion", version);\r
847                 settings.endGroup();\r
848     }\r
849     public static String getDatabaseVersion() {\r
850                 settings.beginGroup("General");\r
851                 String val  = (String)settings.value("databaseVersion", "0.70");\r
852                 settings.endGroup();\r
853                 return val;\r
854     }\r
855     public static String getDatabaseUrl() {\r
856                 settings.beginGroup("General");\r
857                 String val  = (String)settings.value("DatabaseURL", "");\r
858                 settings.endGroup();\r
859                 if (val.equals(""))\r
860                         val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.databaseName);\r
861                 return val;\r
862     }\r
863     public static String getDatabaseUserid() {\r
864                 settings.beginGroup("General");\r
865                 String val  = (String)settings.value("databaseUserid", "");\r
866                 settings.endGroup();\r
867                 return val;\r
868     }\r
869     public static String getDatabaseUserPassword() {\r
870                 settings.beginGroup("General");\r
871                 String val  = (String)settings.value("databaseUserPassword", "");\r
872                 settings.endGroup();\r
873                 return val;\r
874     }\r
875     public static void setStyle(String style) {\r
876                 settings.beginGroup("General");\r
877                 settings.setValue("style", style);\r
878                 settings.endGroup();\r
879     }\r
880     public static String getStyle() {\r
881                 settings.beginGroup("General");\r
882                 String val  = (String)settings.value("style", "");\r
883                 settings.endGroup();\r
884                 return val;\r
885     }\r
886     public static boolean useStandardPalette() {\r
887                 settings.beginGroup("General");\r
888                 String text = (String)settings.value("standardPalette", "true");\r
889                 settings.endGroup();\r
890                 if (text.equalsIgnoreCase("true"))\r
891                         return true;\r
892                 else\r
893                         return false;\r
894     }\r
895     public static void setStandardPalette(boolean val) {\r
896                 settings.beginGroup("General");\r
897                 if (val)\r
898                         settings.setValue("standardPalette", "true");\r
899                 else\r
900                         settings.setValue("standardPalette", "false");\r
901                 settings.endGroup();\r
902     }\r
903     \r
904     public static void saveState(String name, QByteArray state) {\r
905                 settings.beginGroup("SaveState");\r
906                 settings.setValue(name, state);\r
907                 settings.endGroup();\r
908     }\r
909     \r
910     public static QByteArray restoreState(String name) {\r
911                 settings.beginGroup("SaveState");\r
912                 QByteArray state = (QByteArray)settings.value(name);\r
913                 settings.endGroup();\r
914                 return state;\r
915     }\r
916     public static void saveGeometry(String name, QByteArray state) {\r
917                 settings.beginGroup("SaveGeometry");\r
918                 settings.setValue(name, state);\r
919                 settings.endGroup();\r
920     }\r
921     \r
922     public static QByteArray restoreGeometry(String name) {\r
923                 settings.beginGroup("SaveGeometry");\r
924                 QByteArray state = (QByteArray)settings.value(name);\r
925                 settings.endGroup();\r
926                 return state;\r
927     }\r
928     \r
929     public static void setAutoSaveInterval(int interval) {\r
930                 settings.beginGroup("General");\r
931                 settings.setValue("autoSaveInterval", interval);\r
932                 settings.endGroup();\r
933     }\r
934     public static int getAutoSaveInterval() {\r
935                 settings.beginGroup("General");\r
936                 Integer value;\r
937                 try {\r
938                         String val  = (String)settings.value("autoSaveInterval", "5");\r
939                         value = new Integer(val.trim());\r
940                 } catch (Exception e) {\r
941                         try {\r
942                                 value = (Integer)settings.value("autoSaveInterval", 5);\r
943                         } catch (Exception e1) {\r
944                                 value = 0;\r
945                         }\r
946                 }\r
947                 settings.endGroup();\r
948                 return value;\r
949     }\r
950      \r
951     // Add invalid attributes\r
952     public static void addInvalidAttribute(String element, String attribute) {\r
953         \r
954                 List<String> attributes = invalidAttributes.get(element);\r
955                 if (attributes != null) {\r
956                         for (int i=0; i<attributes.size(); i++)\r
957                                 if (attribute.equalsIgnoreCase(attributes.get(i))) {\r
958                                         return;\r
959                         }\r
960         }\r
961         \r
962         ArrayList<String> attributeList;\r
963         if (!invalidAttributes.containsKey(element)) {\r
964                 attributeList = new ArrayList<String>();\r
965                 attributeList.add(attribute);\r
966                 invalidAttributes.put(element, attributeList);\r
967         }\r
968         else {\r
969                 attributeList = invalidAttributes.get(element);\r
970                 attributeList.add(attribute);\r
971                 invalidAttributes.put(element,attributeList);\r
972         }\r
973     }\r
974 \r
975     \r
976     // Add invalid attributes\r
977     public static void addInvalidElement(String element) {\r
978                 for (int i=0; i<invalidElements.size(); i++) {\r
979                         if (element.equalsIgnoreCase(invalidElements.get(i)))\r
980                                 return;\r
981                 }\r
982         invalidElements.add(element);\r
983     }\r
984     \r
985     // Convert a byte array to a hex string\r
986         public static String byteArrayToHexString(byte data[]) {\r
987                 StringBuffer buf = new StringBuffer();\r
988             for (byte element : data) {\r
989                 int halfbyte = (element >>> 4) & 0x0F;\r
990                 int two_halfs = 0;\r
991                 do {\r
992                         if ((0 <= halfbyte) && (halfbyte <= 9))\r
993                                buf.append((char) ('0' + halfbyte));\r
994                            else\r
995                                 buf.append((char) ('a' + (halfbyte - 10)));\r
996                         halfbyte = element & 0x0F;\r
997                 } while(two_halfs++ < 1);\r
998             }\r
999             return buf.toString();              \r
1000         }\r
1001 \r
1002         \r
1003         // What to do with inactive tags?\r
1004         public static String tagBehavior() {\r
1005                 settings.beginGroup("General");\r
1006                 String text = (String)settings.value("tagBehavior", "DoNothing");\r
1007                 settings.endGroup();\r
1008                 return text;\r
1009         }\r
1010         // What to do with inactive tags?\r
1011         public static void setTagBehavior(String value) {\r
1012                 settings.beginGroup("General");\r
1013                 settings.setValue("tagBehavior", value);\r
1014                 settings.endGroup();\r
1015         }\r
1016 \r
1017         \r
1018         // Print date/time.  Used mainly for performance tracing\r
1019         public static void trace(boolean resetInterval) {\r
1020                 String fmt = "MM/dd/yy HH:mm:ss.SSSSSS";\r
1021                 String dateTimeFormat = new String(fmt);\r
1022                 SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);\r
1023                 Calendar cal = Calendar.getInstance();\r
1024                 if (intervalTraceTime == null) \r
1025                         intervalTraceTime = Calendar.getInstance();\r
1026                 if (startTraceTime == null)\r
1027                         startTraceTime = Calendar.getInstance();\r
1028                 \r
1029                 float interval = (cal.getTimeInMillis() - intervalTraceTime.getTimeInMillis());\r
1030                 float total = (cal.getTimeInMillis() - startTraceTime.getTimeInMillis());\r
1031                 \r
1032 //              if (interval > 00.0) {\r
1033                         StackTraceElement[] exceptions = Thread.currentThread().getStackTrace();\r
1034                         System.out.println("------------------------------------------");\r
1035 \r
1036                         System.out.println("Date/Time " +simple.format(cal.getTime()));\r
1037                         System.out.format("Interval Time: %-10.6f%n", interval);\r
1038                         System.out.format("Total Time: %-10.6f%n", total);\r
1039                         for (int i=2; i<5 && i<exceptions.length; i++) {\r
1040                                 System.out.println(exceptions[i]);\r
1041                         }\r
1042 //              }\r
1043                 if (resetInterval)\r
1044                         intervalTraceTime = cal;\r
1045         }\r
1046         public static void traceReset() {\r
1047                 intervalTraceTime = null;\r
1048                 startTraceTime = null;\r
1049         }\r
1050 \r
1051 \r
1052     public static FileManager getFileManager() {\r
1053         return fileManager;\r
1054     }\r
1055     public static boolean getDisableViewing() {\r
1056         return disableViewing;\r
1057     }\r
1058     \r
1059 \r
1060 }\r
1061 \r