OSDN Git Service

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