OSDN Git Service

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