OSDN Git Service

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