OSDN Git Service

バージョン記述を更新
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / Global.java
1 /*
2  * This file is part of NixNote/NeighborNote 
3  * Copyright 2009 Randy Baumgarte
4  * Copyright 2013 Yuki Takahashi
5  * 
6  * This file may be licensed under the terms of of the
7  * GNU General Public License Version 2 (the ``GPL'').
8  *
9  * Software distributed under the License is distributed
10  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
11  * express or implied. See the GPL for the specific language
12  * governing rights and limitations.
13  *
14  * You should have received a copy of the GPL along with this
15  * program. If not, go to http://www.gnu.org/licenses/gpl.html
16  * or write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19 */
20
21 package cx.fbn.nevernote;
22
23
24 import java.io.ByteArrayInputStream;
25 import java.io.ByteArrayOutputStream;
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.ObjectInputStream;
29 import java.io.ObjectOutputStream;
30 import java.text.SimpleDateFormat;
31 import java.util.ArrayList;
32 import java.util.Calendar;
33 import java.util.HashMap;
34 import java.util.List;
35
36 import org.apache.commons.lang3.StringEscapeUtils;
37
38 import com.evernote.edam.type.Accounting;
39 import com.evernote.edam.type.PrivilegeLevel;
40 import com.evernote.edam.type.User;
41 import com.evernote.edam.type.UserAttributes;
42 import com.swabunga.spell.engine.Configuration;
43 import com.trolltech.qt.core.QByteArray;
44 import com.trolltech.qt.core.QFile;
45 import com.trolltech.qt.core.QSettings;
46 import com.trolltech.qt.core.QSize;
47 import com.trolltech.qt.gui.QPalette;
48 import com.trolltech.qt.gui.QSystemTrayIcon;
49
50 import cx.fbn.nevernote.config.FileManager;
51 import cx.fbn.nevernote.config.InitializationException;
52 import cx.fbn.nevernote.config.StartupConfig;
53 import cx.fbn.nevernote.gui.ContainsAttributeFilterTable;
54 import cx.fbn.nevernote.gui.DateAttributeFilterTable;
55 import cx.fbn.nevernote.gui.SearchEdit.SearchTarget;
56 import cx.fbn.nevernote.gui.ShortcutKeys;
57 import cx.fbn.nevernote.sql.DatabaseConnection;
58 import cx.fbn.nevernote.sql.driver.NSqlQuery;
59 import cx.fbn.nevernote.utilities.ApplicationLogger;
60 import cx.fbn.nevernote.utilities.Pair;
61
62
63 //*****************************************************
64 //*****************************************************
65 //* Global constants & static functions used by 
66 //* multiple threads.
67 //*****************************************************
68 //*****************************************************
69
70 public class Global {
71         // Set current version and the known versions.
72         public static String version = "0.5";
73         public static String[] validVersions = {"0.5", "0.4.1", "0.4", "0.3", "0.2", "0.1.3", "0.1.2", "0.1.1", "0.1"};
74         
75     public static String username = ""; 
76     //public static String password = "";     
77     
78
79     // Each thread has an ID.  This is used primarily to check the status
80     // of running threads.
81     public static final int mainThreadId=0;
82     public static final int syncThreadId=1;
83     public static final int tagCounterThreadId=2;
84     public static final int trashCounterThreadId=3;   // This should always be the highest thread ID
85     public static final int indexThreadId=4;    // Thread for indexing words
86     public static final int saveThreadId=5;     // Thread used for processing data to saving content
87     public static final int notebookCounterThreadId=6;   // Notebook Thread
88     public static final int indexThread03Id=7;   // unused
89     public static final int indexThread04Id=8;   // unused
90     public static final int dbThreadId=9;   // This should always be the highest thread ID
91     public static final int threadCount = 10;
92     
93     
94     // These variables deal with where the list of notes appears
95     // They will either be vertical (View_List_Narrow) or will be
96     // on top of the note (View_List_Wide).  It also has the size of
97     // thumbnails displayed in each view
98     public static int View_List_Wide = 1;
99     public static int View_List_Narrow = 2;
100     public static QSize smallThumbnailSize = new QSize(100,75);
101     public static QSize largeThumbnailSize = new QSize(300,225);
102
103     // This is used to keep a running list of passwords that the user
104     // wants us to remember.
105     public static HashMap<String,Pair<String,String>> passwordSafe = new HashMap<String, Pair<String,String>>();
106     public static List<Pair<String,String>> passwordRemember = new ArrayList<Pair<String,String>>();
107     
108     
109     //public static String currentNotebookGuid;
110     
111     // These deal with Evernote user settings
112     public static User user; 
113     public static long authTimeRemaining;
114     public static long authRefreshTime;
115     public static long failedRefreshes = 0; 
116     public static String userStoreUrl;
117     public static String noteStoreUrl;
118     public static String noteStoreUrlBase;
119
120     // When we want to shut down we set this to true to short
121     // circut other threads
122     public static boolean keepRunning;
123         
124     // In the note list, these are the column numbers
125     // so I don't need to hard code numbers.
126     public static int noteTableCreationPosition = 0;
127     public static int noteTableTitlePosition = 1;
128     public static int noteTableTagPosition = 2;
129     public static int noteTableNotebookPosition = 3;
130     public static int noteTableChangedPosition = 4;
131     public static int noteTableGuidPosition = 5;
132     public static int noteTableAuthorPosition = 6;
133     public static int noteTableSourceUrlPosition = 7;
134     public static int noteTableSubjectDatePosition = 8;
135     public static int noteTableSynchronizedPosition = 9;
136     public static int noteTableThumbnailPosition = 10;
137     public static int noteTablePinnedPosition = 11;
138     public static int noteTableColumnCount = 12;
139     public static Integer cryptCounter = 0;
140     
141     //public static int minimumWordCount = 2;
142     
143     // Regular expression to parse text with when indexing
144 //    private static String wordRegex;
145     
146     // Experimental fixes.  Set via Edit/Preferences/Debugging
147     public static boolean enableCarriageReturnFix = false;
148     public static boolean enableHTMLEntitiesFix = false;
149     
150     // Used to set & retrieve ini & Windows registry settings
151     public static QSettings     settings;     // Set & get ini settings
152     public static boolean isConnected;    // Are we connected to Evernote
153     public static boolean showDeleted = false;   // Show deleted notes?
154     public static boolean disableUploads = false;  // Should we disable uploads (used in testing features)
155         public static int messageLevel;   // The level of messages to write to the log files
156         public static String tagDelimeter = ",";   // This is used to separate out tag names when entering above note
157         public static String attachmentNameDelimeter = "------";  // Used to separate out attachment names in the res directory
158         
159         
160         //* Database fields
161         public static String    databaseName = new String("NeverNote");  // database name.  used for multiple databases to separate settings.
162         public static String    indexDatabaseName = new String("Index"); // searchable words database
163         public static String    resourceDatabaseName = new String("Resources");  // attachments database
164         public static String behaviorDatabaseName = new String("Behavior"); // 操作履歴データベース   
165         
166         public static DateAttributeFilterTable createdSinceFilter;
167         public static DateAttributeFilterTable createdBeforeFilter;
168         public static DateAttributeFilterTable changedSinceFilter;
169         public static DateAttributeFilterTable changedBeforeFilter;
170         public static ContainsAttributeFilterTable containsFilter;
171         
172         // Log file used for debugging
173         public static ApplicationLogger    logger;
174         //PrintStream stdoutStream;
175         
176         // Application key shortcuts & appearance
177         public static QPalette                          originalPalette;
178         public static ShortcutKeys                      shortcutKeys;
179         
180         public static boolean                           disableViewing;  // used to disable the editor
181         
182         // When saving a note, this is a list of things we strip out because Evernote hates them
183         public static List<String>                              invalidElements = new ArrayList<String>();
184         public static HashMap<String, ArrayList<String>>        invalidAttributes = new HashMap<String, ArrayList<String>>();
185         
186         public static boolean mimicEvernoteInterface; // Try to mimic Evernote or allow multiple notebook selection
187         public static HashMap<String,String> resourceMap;   // List of attachments for a note.
188         public static String cipherPassword = "";    // If the database is encrypted, this stores the password
189         public static String databaseCache = "16384";  // Default DB cache size
190         
191         // These are used for performance testing
192         static Calendar startTraceTime;   
193         static Calendar intervalTraceTime;
194         
195         static boolean syncOnly;
196         
197         private static FileManager fileManager;  // Used to access files & directories
198         
199     // Do initial setup 
200     public static void setup(StartupConfig startupConfig) throws InitializationException  {
201         String settingFileName = new String("NeighborNote.ini");
202         
203         // バージョン0.1.2以下で作成された古い設定ファイルを見つけたら、ホームディレクトリに移動させる。
204         String oldSettingPath = new QSettings(settingFileName, QSettings.Format.IniFormat).fileName();
205         File homeDir = new File(FileManager.toPlatformPathSeparator(startupConfig.getHomeDirPath()));
206         String homePath = FileManager.slashTerminatePath(homeDir.getPath());
207         if (QFile.exists(oldSettingPath)) {
208                 QFile file = new QFile(oldSettingPath);
209                 file.copy(homePath + settingFileName);
210                 file.remove();
211         }
212         
213         settings = new QSettings(homePath + settingFileName, QSettings.Format.IniFormat);
214         
215         disableViewing = startupConfig.getDisableViewing();
216         syncOnly = startupConfig.isSyncOnly();
217
218         fileManager = new FileManager(startupConfig.getHomeDirPath(), startupConfig.getProgramDirPath());
219
220
221                 getServer();  // Setup URL to connect to
222                 
223                 // Get regular expressions used to parse out words
224 //              settings.beginGroup("General");
225 //              String regex = (String) settings.value("regex", "[,\\s]+");
226 //              setWordRegex(regex);
227 //              settings.endGroup();
228                 
229                 //Setup debugging information
230                 settings.beginGroup("Debug");
231                 String msglevel = (String) settings.value("messageLevel", "Low");
232                 settings.endGroup();
233                 
234                 
235                 //messageLevel = 1;
236                 setMessageLevel(msglevel);
237                 keepRunning = true;  // Make sure child threads stay running
238                 disableUploads = disableUploads();  // Should we upload anything?  Normally false.
239                 //disableUploads = true;  //***** DELETE THIS LINE *******
240                 enableCarriageReturnFix = enableCarriageReturnFix();  // Enable test fix?
241                 enableHTMLEntitiesFix = enableHtmlEntitiesFix();  // Enable test fix?
242                 
243                 logger = new ApplicationLogger("global.log");  // Setup log for this class 
244                 shortcutKeys = new ShortcutKeys();  // Setup keyboard shortcuts.
245                 mimicEvernoteInterface = getMimicEvernoteInterface();  // Should we mimic Evernote's notebook behavior
246                 resourceMap = new HashMap<String,String>();  // Setup resource map used to store attachments when editing
247                         
248                 databaseCache = getDatabaseCacheSize();  // Set database cache size     
249                 
250                 Global.username = getUserInformation().getUsername();
251     }
252
253     // Get/Set word parsing regular expression
254 //    public static String getWordRegex() {
255 //      return wordRegex;
256 //    }
257 //    public static void setWordRegex(String r) {
258 //      wordRegex = r;
259 //    }
260
261    // Set the debug message level
262    public static void setMessageLevel(String msglevel) {
263         if (msglevel.equalsIgnoreCase("low")) 
264                         messageLevel = 1;
265                 if (msglevel.equalsIgnoreCase("medium")) 
266                         messageLevel = 2;
267                 if (msglevel.equalsIgnoreCase("high")) 
268                                 messageLevel = 3;
269                 if (msglevel.equalsIgnoreCase("extreme")) 
270                                         messageLevel = 4;
271                 settings.beginGroup("Debug");
272                 settings.setValue("messageLevel", msglevel);
273                 settings.endGroup();            
274     }
275
276    //****************************************************
277    //****************************************************
278    //** Save user account information from Evernote
279    //****************************************************
280    //****************************************************
281     public static void saveUserInformation(User user) {
282         settings.beginGroup("User");
283                 settings.setValue("id", user.getId());
284                 settings.setValue("username", user.getUsername());
285                 settings.setValue("email", user.getEmail());
286                 settings.setValue("name", user.getName());
287                 settings.setValue("timezone", user.getTimezone());
288                 settings.setValue("privilege", user.getPrivilege().getValue());
289                 settings.setValue("created", user.getCreated());
290                 settings.setValue("updated", user.getUpdated());
291                 settings.setValue("deleted", user.getDeleted());
292                 settings.setValue("shard", user.getShardId());
293                 settings.endGroup();
294                 isPremium();
295                 if (user.getAttributes()!=null)
296                         saveUserAttributes(user.getAttributes());
297                 if (user.getAccounting()!=null)
298                         saveUserAccounting(user.getAccounting());
299
300     }
301     public static User getUserInformation() {
302         User user = new User();
303         settings.beginGroup("User");
304         try {   
305                 user.setId((Integer)settings.value("id", 0));                   
306         } catch  (java.lang.ClassCastException e) {
307                 user.setId(new Integer((String)settings.value("id", "0")));
308         }
309                 String username = (String)settings.value("username", "");
310                 String email = (String)settings.value("email", "");
311                 String name = (String)settings.value("name", "");
312                 String timezone = (String)settings.value("timezone", "");
313                 Integer privilege = 0;
314                 try {   
315                         privilege = new Integer((String)settings.value("privilege", "0"));                      
316                 } catch (java.lang.ClassCastException e) {
317                         privilege = (Integer)settings.value("privilege", 0);
318                 }
319
320                 try {   
321                         String date = (String)settings.value("created", "0");
322                         user.setCreated(new Long(date));
323                         date = (String)settings.value("updated", "0");
324                         user.setUpdated(new Long(date));
325                         date = (String)settings.value("deleted", "0");
326                         user.setDeleted(new Long(date));
327                 } catch (java.lang.ClassCastException e) {
328                         Long date = (Long)settings.value("created", 0);
329                         user.setCreated(date);
330                         date = (Long)settings.value("updated", 0);
331                         user.setUpdated(date);
332                         date = (Long)settings.value("deleted", 0);
333                         user.setDeleted(date);
334                 }
335
336                 String shard = (String)settings.value("shard", "");
337         settings.endGroup();
338         
339         user.setUsername(username);
340         user.setEmail(email);
341         user.setName(name);
342         user.setTimezone(timezone);
343         PrivilegeLevel userLevel = PrivilegeLevel.findByValue(privilege);
344         user.setPrivilege(userLevel);
345         user.setShardId(shard);
346         return user;
347     }
348     
349     public static void saveUserAttributes(UserAttributes attrib) {
350         settings.beginGroup("UserAttributes");
351                 settings.setValue("defaultLocationName", attrib.getDefaultLocationName());
352                 settings.setValue("defaultLatitude", attrib.getDefaultLocationName());
353                 settings.setValue("defaultLongitude", attrib.getDefaultLocationName());
354                 settings.setValue("incomingEmailAddress", attrib.getIncomingEmailAddress());
355                 settings.endGroup();
356     }
357     public static UserAttributes getUserAttributes() {
358         settings.beginGroup("UserAttributes");
359         UserAttributes attrib = new UserAttributes();
360                 attrib.setDefaultLocationName((String)settings.value("defaultLocationName",""));
361                 attrib.setDefaultLatitudeIsSet(false);
362                 attrib.setDefaultLongitudeIsSet(false);
363                 attrib.setIncomingEmailAddress((String)settings.value("incomingEmailAddress", ""));
364                 settings.endGroup();
365                 return attrib;
366     }
367     public static void saveUserAccounting(Accounting acc) {
368         settings.beginGroup("UserAccounting");
369                 settings.setValue("uploadLimit", acc.getUploadLimit());
370                 settings.setValue("uploadLimitEnd", acc.getUploadLimitEnd());
371                 settings.setValue("uploadLimitNextMonth", acc.getUploadLimitNextMonth());
372                 settings.setValue("premiumServiceStart", acc.getPremiumServiceStart());
373                 settings.setValue("nextPaymentDue", acc.getNextPaymentDue());
374                 settings.setValue("uploadAmount", acc.getUpdated());
375                 settings.endGroup();
376     }
377     public static long getUploadLimitEnd() {
378         Long limit;
379         settings.beginGroup("UserAccounting");
380         
381         // Upload limit
382                 try {
383                         String val  = (String)settings.value("uploadLimitEnd", "0");
384                         limit = new Long(val.trim());
385                 } catch (Exception e) {
386                         try {
387                                 limit = (Long)settings.value("uploadLimitEnd", 0);
388                         } catch (Exception e1) {
389                                 limit = new Long(0);
390                         }
391                 }
392         
393                 // return value
394         settings.endGroup();
395         return limit;
396     }
397     public static void saveUploadAmount(long amount) {
398         settings.beginGroup("UserAccounting");
399                 settings.setValue("uploadAmount", amount);
400                 settings.endGroup();
401    }
402     public static long getUploadAmount() {
403                 long amt=0;
404                 settings.beginGroup("UserAccounting");
405                 try {
406                         String num = (String)settings.value("uploadAmount", "0");
407                         amt = new Long(num.trim());
408                 } catch (Exception e) {
409                         try {
410                                 amt = (Integer)settings.value("uploadAmount", 0);
411                         } catch (Exception e1) {
412                                 amt = 0;
413                         }
414                 }
415                 settings.endGroup();
416                 return amt;
417     }
418     public static void saveEvernoteUpdateCount(long amount) {
419         settings.beginGroup("UserAccounting");
420                 settings.setValue("updateCount", amount);
421                 settings.endGroup();
422     }
423     public static long getEvernoteUpdateCount() {
424                 long amt;
425                 settings.beginGroup("UserAccounting");
426                 try {
427                         String num = (String)settings.value("updateCount", new Long(0).toString());
428                         amt = new Long(num.trim());
429                 } catch (java.lang.ClassCastException e) {
430                         amt = 0;
431                 }
432                 settings.endGroup();
433                 return amt;
434     }
435     public static boolean isPremium() {
436                 int level;
437                 settings.beginGroup("User");
438                 try {
439                         String num = (String)settings.value("privilege", "1");
440                         level = new Integer(num.trim());
441                 } catch (java.lang.ClassCastException e) {
442                         try {
443                                 level = (Integer)settings.value("privilege", 1);
444                         } catch (Exception e1) {
445                                 level = 1;
446                         }
447                 }
448                 settings.endGroup();
449                 PrivilegeLevel userLevel = PrivilegeLevel.findByValue(level);
450                 if (userLevel == PrivilegeLevel.NORMAL)
451                         return false;
452                 return true;
453                 
454    }
455     public static long getUploadLimit() {
456                 settings.beginGroup("UserAccounting");
457                 long limit;
458                 try {
459                         String num = (String)settings.value("uploadLimit", new Long(0).toString());
460                         limit = new Long(num.trim());
461                 } catch (java.lang.ClassCastException e) {
462                         limit = 0;
463                 }
464                 settings.endGroup();
465                 return limit;
466     }
467
468     
469     
470     //****************************************************
471     //****************************************************
472     //** View settings.  Used to restore settings 
473     //** when starting and to control how the program
474     //** behaves.
475     //****************************************************
476     //****************************************************
477     
478     //* Get/Set if we should show a tray icon
479     public static boolean showTrayIcon() {
480                 settings.beginGroup("General");
481                 try {
482                         String max = (String) settings.value("showTrayIcon", "false");
483                         settings.endGroup();
484                         if (!max.equalsIgnoreCase("true") || !QSystemTrayIcon.isSystemTrayAvailable())
485                                 return false;
486                         else
487                                 return true;    
488                 } catch (java.lang.ClassCastException e) {
489                         Boolean value = (Boolean) settings.value("showTrayIcon", false);
490                         settings.endGroup();
491                         return value;
492                 }
493     }
494     public static void setShowTrayIcon(boolean val) {
495                 settings.beginGroup("General");
496                 if (val)
497                         settings.setValue("showTrayIcon", "true");
498                 else
499                         settings.setValue("showTrayIcon", "false");
500                 settings.endGroup();
501     }
502     
503     // Get/Set window maximized when closed last
504     public static boolean wasWindowMaximized() {
505         try {
506                         settings.beginGroup("General");
507                         String max = (String) settings.value("isMaximized", "true");
508                         settings.endGroup();
509                         if (!max.equalsIgnoreCase("true"))
510                                 return false;
511                         return true;    
512                 } catch (java.lang.ClassCastException e) {
513                         Boolean value = (Boolean) settings.value("isMaximized", true);
514                         settings.endGroup();
515                         return value;
516                 }
517     }
518     public static void saveWindowMaximized(boolean isMax) {
519                 settings.beginGroup("General");
520                 if (isMax)
521                         settings.setValue("isMaximized", "true");
522                 else
523                         settings.setValue("isMaximized", "false");
524                 settings.endGroup();
525     }
526     
527     // Get/set currently viewed note Guid
528     public static String getLastViewedNoteGuid() {
529                 settings.beginGroup("General");
530                 String guid = (String) settings.value("lastViewedNote", "");
531                 settings.endGroup();
532                 return guid;    
533     }
534     public static void saveCurrentNoteGuid(String guid) {
535                 settings.beginGroup("General");
536                 if (guid != null)
537                         settings.setValue("lastViewedNote", guid);
538                 else
539                         settings.setValue("lastViewedNote", "");
540                 settings.endGroup();
541     }
542     
543     // Get/Set the note column we are sorted on and the order
544     public static void setSortColumn(int i) {
545         int view = Global.getListView();
546                 settings.beginGroup("General");
547         if (view == Global.View_List_Wide)
548                 settings.setValue("sortColumn", i);
549         else
550                 settings.setValue("sortColumn-Narrow", i);
551                 settings.endGroup();
552     }
553     public static int getSortColumn() {;
554     String key;
555         if (Global.getListView() == Global.View_List_Wide)
556                 key = "sortColumn";
557         else
558                 key = "sortColumn-Narrow";
559
560         settings.beginGroup("General");
561         int order;      
562         try {
563                 String val  = settings.value(key, new Integer(0)).toString();
564                 order = new Integer(val.trim());
565         } catch (Exception e) {
566                 try {
567                         order = (Integer)settings.value(key, 0);
568                 } catch (Exception e1) {
569                     order = 0;
570                 }
571         }
572         
573         settings.endGroup();
574         return order;
575     }
576     public static void setSortOrder(int i) {
577         int view = Global.getListView();
578                 settings.beginGroup("General");
579         if (view == Global.View_List_Wide)
580                 settings.setValue("sortOrder", i);
581         else
582                 settings.setValue("sortOrder-Narrow", i);
583                 settings.endGroup();
584     }
585     public static int getSortOrder() {
586         int view = Global.getListView();
587                 settings.beginGroup("General");
588                 String key;
589         if (view == Global.View_List_Wide)
590                 key = "sortOrder";
591                 else
592                         key = "sortOrder-Narrow";
593
594                 int order;      
595                 try {
596                         String val  = settings.value(key, new Integer(0)).toString();
597                         order = new Integer(val.trim());
598                 } catch (Exception e) {
599                         try {
600                                 order = (Integer)settings.value(key, 0);
601                         } catch (Exception e1) {
602                             order = 0;
603                         }
604                 }
605                 
606                 settings.endGroup();
607                 return order;
608     }
609     
610     // Should we automatically log in to Evernote when starting?
611     public static boolean automaticLogin() {
612         try {
613                 settings.beginGroup("General");
614                 String text = (String)settings.value("automaticLogin", "false");
615                 settings.endGroup();
616                 if (text.equalsIgnoreCase("true"))
617                         return true;
618                 else
619                         return false;           
620         } catch (java.lang.ClassCastException e) {
621                 Boolean value = (Boolean) settings.value("automaticLogin", false);
622                 settings.endGroup();
623                 return value;
624         }
625     }
626     public static void setAutomaticLogin(boolean val) {
627                 settings.beginGroup("General");
628                 if (val)
629                         settings.setValue("automaticLogin", "true");
630                 else
631                         settings.setValue("automaticLogin", "false");
632                 settings.endGroup();
633     }
634
635     // Get/set the Evernote server Url.  
636     public static void setServer(String server) {
637                 settings.beginGroup("General");
638                 settings.setValue("server", server);
639                 settings.endGroup();            
640     }
641     public static String getServer() {
642                 settings.beginGroup("General");
643                 String text = (String)settings.value("server", "www.evernote.com");
644                 if (text.equals("www.evernote.com")) {
645                         userStoreUrl = "https://www.evernote.com/edam/user";
646                     noteStoreUrlBase = "www.evernote.com/edam/note/";   
647                 } else {
648                         userStoreUrl = "https://sandbox.evernote.com/edam/user";
649                         noteStoreUrlBase = "sandbox.evernote.com/edam/note/";
650                 }
651                 settings.endGroup();
652 //              if (isPremium())
653                         noteStoreUrlBase = "https://" + noteStoreUrlBase;
654 //              else
655 //                      noteStoreUrlBase = "http://" + noteStoreUrlBase;
656                 return text;
657     }
658
659     // Get/Set if we should disable uploads to Evernote
660     public static boolean disableUploads() {
661         settings.beginGroup("General");
662         try {
663                 String text = (String)settings.value("disableUploads", "false");
664                 settings.endGroup();
665                 if (text.equalsIgnoreCase("true"))
666                         return true;
667                 else
668                         return false;
669                 } catch (java.lang.ClassCastException e) {
670                         Boolean value = (Boolean) settings.value("disableUploads", false);
671                         settings.endGroup();
672                         return value;
673                 }
674     }
675     public static void setDisableUploads(boolean val) {
676                 settings.beginGroup("General");
677                 if (val)
678                         settings.setValue("disableUploads", "true");
679                 else
680                         settings.setValue("disableUploads", "false");
681                 settings.endGroup();
682                 disableUploads = val;
683     }
684  
685     // Should we view PDF documents inline?
686     public static boolean pdfPreview() {
687                 settings.beginGroup("General");
688                 try {
689                         String text = (String)settings.value("pdfPreview", "true");
690                         settings.endGroup();
691                         if (text.equalsIgnoreCase("true"))
692                                 return true;
693                         else
694                                 return false;
695                 } catch (java.lang.ClassCastException e) {
696                         Boolean value = (Boolean) settings.value("pdfPreview", true);
697                         settings.endGroup();
698                         return value;
699                 }
700     }
701     public static void setPdfPreview(boolean val) {
702                 settings.beginGroup("General");
703                 if (val)
704                         settings.setValue("pdfPreview", "true");
705                 else
706                         settings.setValue("pdfPreview", "false");
707                 settings.endGroup();
708     }
709     
710     // When creating a new note, should it inherit tags that are currently selected?
711     public static boolean newNoteWithSelectedTags() {
712                 settings.beginGroup("General");
713                 try {
714                         String text = (String)settings.value("newNoteWithSelectedTags", "false");
715                         settings.endGroup();
716                         if (text.equalsIgnoreCase("true"))
717                                 return true;
718                         else
719                                 return false;
720                 } catch (java.lang.ClassCastException e) {
721                         Boolean value = (Boolean) settings.value("newNoteWithSelectedTags", false);
722                         settings.endGroup();
723                         return value;
724                 }
725     }
726     public static void setNewNoteWithSelectedTags(boolean val) {
727                 settings.beginGroup("General");
728                 if (val)
729                         settings.setValue("newNoteWithSelectedTags", "true");
730                 else
731                         settings.setValue("newNoteWithSelectedTags", "false");
732                 settings.endGroup();
733     }
734     
735     // Minimum weight for text OCRed from Evernote. Anything below this
736     // Won't be shown to the user when they search
737     public static void setRecognitionWeight(int len) {
738                 settings.beginGroup("General");
739                 settings.setValue("recognitionWeight", len);
740                 settings.endGroup();            
741     }
742     public static int getRecognitionWeight() {
743                 settings.beginGroup("General");
744                 Integer len;
745                 try {
746                         len = (Integer)settings.value("recognitionWeight", 30);
747                 } catch (Exception e) {
748                         len = 80;
749                 }
750                 settings.endGroup();
751                 return len;
752     }
753     
754     // get/set current debug message level
755     public static String getMessageLevel() {
756                 settings.beginGroup("Debug");
757                 String text = (String)settings.value("messageLevel", "Low");
758                 settings.endGroup();
759                 setMessageLevel(text);
760                 return text;
761     }
762     public static void setDateFormat(String format) {
763                 settings.beginGroup("General");
764                 settings.setValue("dateFormat", format);
765                 settings.endGroup();            
766     }
767     
768     // Get/Set user date/time formats
769     public static String getDateFormat() {
770                 settings.beginGroup("General");
771                 String text = (String)settings.value("dateFormat", "MM/dd/yyyy");
772                 settings.endGroup();
773                 return text;
774     }
775     public static void setTimeFormat(String format) {
776                 settings.beginGroup("General");
777                 settings.setValue("timeFormat", format);
778                 settings.endGroup();            
779     }
780     public static String getTimeFormat() {
781                 settings.beginGroup("General");
782                 String text = (String)settings.value("timeFormat", "HH:mm:ss");
783                 settings.endGroup();
784                 return text;
785     }
786     
787     // How often should we sync with Evernote?
788     public static String getSyncInterval() {
789                 settings.beginGroup("General");
790                 String text = (String)settings.value("syncInterval", "15 minutes");
791                 settings.endGroup();
792                 return text;            
793     }
794     public static void setSyncInterval(String format) {
795                 settings.beginGroup("General");
796                 settings.setValue("syncInterval", format);
797                 settings.endGroup();            
798     }
799     
800     // Get/Set the width of columns and their position for the 
801     // next start.
802     public static void setColumnWidth(String col, int width) {
803         if (Global.getListView() == Global.View_List_Wide)
804                 settings.beginGroup("ColumnWidths");
805         else 
806                 settings.beginGroup("ColumnWidths-Narrow");
807                 settings.setValue(col, width);
808                 settings.endGroup();
809         }
810     public static int getColumnWidth(String col) {
811         int view = Global.getListView();
812         if (view == Global.View_List_Wide)
813                 settings.beginGroup("ColumnWidths");
814         else
815                 settings.beginGroup("ColumnWidths-Narrow");
816                 Integer width;
817                 try {
818                         String val  = (String)settings.value(col, "0");
819                         width = new Integer(val.trim());
820                 } catch (Exception e) {
821                         try {
822                                 width = (Integer)settings.value(col, 0);
823                         } catch (Exception e1) {
824                                 width = 0;
825                         }
826                 }
827                 settings.endGroup();
828                 return width;
829     }
830     public static void setColumnPosition(String col, int width) {
831         if (Global.getListView() == Global.View_List_Wide)
832                 settings.beginGroup("ColumnPosition");
833         else
834                 settings.beginGroup("ColumnPosition-Narrow");
835                 settings.setValue(col, width);
836                 settings.endGroup();
837     }
838     public static int getColumnPosition(String col) {
839         if (Global.getListView() == Global.View_List_Wide)
840                 settings.beginGroup("ColumnPosition");
841         else
842                 settings.beginGroup("ColumnPosition-Narrow");
843                 Integer width;
844                 try {
845                         String val  = (String)settings.value(col, "-1");
846                         width = new Integer(val.trim());
847                 } catch (Exception e) {
848                         try {
849                                 width = (Integer)settings.value(col, 0);
850                         } catch (Exception e1) {
851                                 width = 0;
852                         }
853                 }
854                 settings.endGroup();
855                 return width;
856     }
857     
858     // Ping the user when they try to delete or just do it.
859     public static boolean verifyDelete() {
860                 settings.beginGroup("General");
861                 try {
862                         String text = (String)settings.value("verifyDelete", "true");
863                         settings.endGroup();
864                         if (text.equalsIgnoreCase("true"))
865                                 return true;
866                         else
867                                 return false;
868                 } catch (java.lang.ClassCastException e) {
869                         Boolean value = (Boolean) settings.value("verifyDelete", true);
870                         settings.endGroup();
871                         return value;
872                 }
873     }
874     public static void setVerifyDelete(boolean val) {
875                 settings.beginGroup("General");
876                 if (val)
877                         settings.setValue("verifyDelete", "true");
878                 else
879                         settings.setValue("verifyDelete", "false");
880                 settings.endGroup();
881     }
882     
883     // Should it start minimized?
884     public static boolean startMinimized() {
885                 settings.beginGroup("General");
886                 try {
887                         String text = (String)settings.value("startMinimized", "false");
888                         settings.endGroup();
889                         if (text.equalsIgnoreCase("true"))
890                                 return true;
891                         else
892                                 return false;
893                 } catch (java.lang.ClassCastException e) {
894                         Boolean value = (Boolean) settings.value("startMinimized", false);
895                         settings.endGroup();
896                         return value;
897                 }
898     }
899     public static void setStartMinimized(boolean val) {
900                 settings.beginGroup("General");
901                 if (val)
902                         settings.setValue("startMinimized", "true");
903                 else
904                         settings.setValue("startMinimized", "false");
905                 settings.endGroup();
906     }
907     
908     // Should we upload the content of any deleted notes
909     public static boolean synchronizeDeletedContent() {
910                 settings.beginGroup("General");
911                 try {
912                         String text = (String)settings.value("syncDeletedContent", "false");
913                         settings.endGroup();
914                         if (text.equalsIgnoreCase("true"))
915                                 return true;
916                         else
917                                 return false;
918                 } catch (java.lang.ClassCastException e) {
919                         Boolean value = (Boolean) settings.value("syncDeletedContent", false);
920                         settings.endGroup();
921                         return value;
922                 }
923     }   
924     public static void setSynchronizeDeletedContent(boolean val) {
925                 settings.beginGroup("General");
926                 if (val)
927                         settings.setValue("syncDeletedContent", "true");
928                 else
929                         settings.setValue("syncDeletedContent", "false");
930                 settings.endGroup();
931     }
932     
933     // Is a section of the window visible?  Used to hide things people don't
934     // want to see.
935     public static boolean isWindowVisible(String window) {
936                 settings.beginGroup("WindowsVisible");
937                 try {
938                         String defaultValue = "true";
939                         if (window.equalsIgnoreCase("noteInformation"))
940                                 defaultValue = "false";
941                         String text = (String)settings.value(window, defaultValue);
942                         settings.endGroup();
943                         if (text.equalsIgnoreCase("true"))
944                                 return true;
945                 else
946                         return false;           
947                 } catch (java.lang.ClassCastException e) {
948                         boolean defaultValue = true;
949                         if (window.equalsIgnoreCase("noteInformation"))
950                                 defaultValue = false;
951                         Boolean value = (Boolean) settings.value("showTrayIcon", defaultValue);
952                         settings.endGroup();
953                         return value;
954                 }
955     }
956     public static void saveWindowVisible(String window, boolean val) {
957                 settings.beginGroup("WindowsVisible");
958                 if (val)
959                         settings.setValue(window, "true");
960                 else
961                         settings.setValue(window, "false");
962                 settings.endGroup();
963     }
964     
965     // Is a list in the column in the note list visible?  
966     public static boolean isColumnVisible(String window) {
967         String defaultValue = "true";
968         int view = Global.getListView();
969         if (Global.getListView() == Global.View_List_Wide)
970                 settings.beginGroup("ColumnsVisible");
971         else
972                 settings.beginGroup("ColumnsVisible-Narrow"); 
973                 if (window.equalsIgnoreCase("thumbnail") && view == Global.View_List_Wide)
974                         defaultValue = "false";
975                 if (window.equalsIgnoreCase("thumbnail"))
976                         defaultValue = "false";
977                 if (window.equalsIgnoreCase("Guid"))
978                         defaultValue = "false";
979                 try {
980                         String text = (String)settings.value(window, defaultValue);
981                         settings.endGroup();
982                         if (text.equalsIgnoreCase("true"))
983                                 return true;
984                         else
985                                 return false;
986                 } catch (java.lang.ClassCastException e) {
987                         boolean defBool = false;
988                         if (window.equalsIgnoreCase("true"))
989                                 defBool = true;
990                         else
991                                 defBool = false;
992                         Boolean value = (Boolean) settings.value(window, defBool);
993                         settings.endGroup();
994                         return value;
995                 }
996     }
997     public static void saveColumnVisible(String column, boolean val) {
998         if (Global.getListView() == Global.View_List_Wide)
999                 settings.beginGroup("ColumnsVisible");
1000         else
1001                 settings.beginGroup("ColumnsVisible-Narrow");                   
1002                 if (val)
1003                         settings.setValue(column, "true");
1004                 else
1005                         settings.setValue(column, "false");
1006                 settings.endGroup();
1007     }
1008     
1009     // Is a particular editor button visible?
1010     public static boolean isEditorButtonVisible(String window) {
1011                 settings.beginGroup("EditorButtonsVisible");
1012                 try {
1013                         String text = (String)settings.value(window, "true");
1014                         settings.endGroup();
1015                         if (text.equalsIgnoreCase("true"))
1016                                 return true;
1017                         else
1018                                 return false;
1019                 } catch (java.lang.ClassCastException e) {
1020                         Boolean value = (Boolean) settings.value(window, true);
1021                         settings.endGroup();
1022                         return value;
1023                 }
1024     }
1025     public static void saveEditorButtonsVisible(String column, boolean val) {
1026                 settings.beginGroup("EditorButtonsVisible");
1027                 if (val)
1028                         settings.setValue(column, "true");
1029                 else
1030                         settings.setValue(column, "false");
1031                 settings.endGroup();
1032     }
1033     
1034     // Should the test fixes be enabled
1035     public static boolean enableCarriageReturnFix() {
1036         try {
1037                 settings.beginGroup("Debug");
1038                 String text = (String)settings.value("enableCarriageReturnFix", "false");
1039                 settings.endGroup();
1040                 if (text.equalsIgnoreCase("true"))
1041                         return true;
1042                 else
1043                         return false;
1044                 } catch (java.lang.ClassCastException e) {
1045                         Boolean value = (Boolean) settings.value("enableCarriageReturnFix", false);
1046                         settings.endGroup();
1047                         return value;
1048                 }
1049     }
1050     public static void saveCarriageReturnFix(boolean val) {
1051                 settings.beginGroup("Debug");
1052                 if (val)
1053                         settings.setValue("enableCarriageReturnFix", "true");
1054                 else
1055                         settings.setValue("enableCarriageReturnFix", "false");
1056                 settings.endGroup();
1057     }
1058     public static boolean enableHtmlEntitiesFix() {
1059         try {
1060                 settings.beginGroup("Debug");
1061                 String text = (String)settings.value("enableHtmlEntitiesFix", "false");
1062                 settings.endGroup();
1063                 if (text.equalsIgnoreCase("true"))
1064                         return true;
1065                 else
1066                         return false;
1067                 } catch (java.lang.ClassCastException e) {
1068                         Boolean value = (Boolean) settings.value("enableHtmlEntitiesFix", false);
1069                         settings.endGroup();
1070                         return value;
1071                 }
1072     }
1073     public static void saveHtmlEntitiesFix(boolean val) {
1074                 settings.beginGroup("Debug");
1075                 if (val)
1076                         settings.setValue("enableHtmlEntitiesFix", "true");
1077                 else
1078                         settings.setValue("enableHtmlEntitiesFix", "false");
1079                 settings.endGroup();
1080     }
1081
1082 //    public static void setIndexThreads(int val) {
1083 //              settings.beginGroup("General");
1084 //              settings.setValue("indexThreads", val);
1085 //              settings.endGroup();
1086 //   }
1087 //    public static int getIndexThreads() {
1088 //              settings.beginGroup("General");
1089 //              Integer threads;
1090 //              try {
1091 //                      String val  = (String)settings.value("indexThreads", "1");
1092 //                      threads = new Integer(val.trim());
1093 //              } catch (Exception e) {
1094 //                      try {
1095 //                              threads = (Integer)settings.value("indexThreads", 1);
1096 //                      } catch (Exception e1) {
1097 //                              threads = 1;
1098 //                      }
1099 //              }
1100 //              settings.endGroup();
1101 //              threads = 1;
1102 //              return threads;
1103     
1104     // Get/Set text zoom factor
1105 //   }
1106     public static void setZoomFactor(double val) {
1107                 settings.beginGroup("General");
1108                 settings.setValue("zoomFactor", val);
1109                 settings.endGroup();
1110     }
1111     public static double getZoomFactor() {
1112                 settings.beginGroup("General");
1113                 Double threads;
1114                 try {
1115                         String val  = (String)settings.value("zoomFactor", "1.0");
1116                         threads = new Double(val.trim());
1117                 } catch (Exception e) {
1118                         try {
1119                                 threads = (Double)settings.value("zoomFactor", 1.0);
1120                         } catch (Exception e1) {
1121                                 threads = new Double(1);
1122                         }
1123                 }
1124                 settings.endGroup();
1125                 return threads;
1126     }
1127     public static void setTextSizeMultiplier(double val) {
1128                 settings.beginGroup("General");
1129                 settings.setValue("textMultiplier", val);
1130                 settings.endGroup();
1131     }
1132     public static double getTextSizeMultiplier() {
1133                 settings.beginGroup("General");
1134                 Double threads;
1135                 try {
1136                         String val  = (String)settings.value("textMultiplier", "1");
1137                         threads = new Double(val.trim());
1138                 } catch (Exception e) {
1139                         try {
1140                                 threads = (Double)settings.value("textMultiplier", 1);
1141                         } catch (Exception e1) {
1142                                 threads = new Double(1);
1143                         }
1144                 }
1145                 settings.endGroup();
1146                 return threads;
1147     }
1148     
1149     
1150     // Should we mimic Evernote and restrict the notebooks selected?
1151     public static boolean getMimicEvernoteInterface() {
1152                 settings.beginGroup("General");
1153                 try {
1154                         String text = (String)settings.value("mimicEvernoteInterface", "true");
1155                         settings.endGroup();
1156                         if (text.equalsIgnoreCase("true"))
1157                                 return true;
1158                         else
1159                                 return false;
1160                 } catch (java.lang.ClassCastException e) {
1161                         Boolean value = (Boolean) settings.value("mimicEvernoteInterface", true);
1162                         settings.endGroup();
1163                         return value;
1164                 }
1165     }
1166     public static void setMimicEvernoteInterface(boolean value) {
1167         settings.beginGroup("General");
1168         if (value)
1169                 settings.setValue("mimicEvernoteInterface", "true");
1170         else
1171                 settings.setValue("mimicEvernoteInterface", "false"); 
1172         settings.endGroup();
1173     }
1174     
1175     
1176     // Synchronize with Evernote when closing?
1177     public static boolean synchronizeOnClose() {
1178                 settings.beginGroup("General");
1179                 try {
1180                         String text = (String)settings.value("synchronizeOnClose", "false");
1181                         settings.endGroup();
1182                         if (text.equalsIgnoreCase("true"))
1183                                 return true;
1184                         else
1185                                 return false;
1186                 } catch (java.lang.ClassCastException e) {
1187                         Boolean value = (Boolean) settings.value("synchronizeOnClose", false);
1188                         settings.endGroup();
1189                         return value;
1190                 }
1191     }
1192     public static void setSynchronizeOnClose(boolean val) {
1193                 settings.beginGroup("General");
1194                 if (val)
1195                         settings.setValue("synchronizeOnClose", "true");
1196                 else
1197                         settings.setValue("synchronizeOnClose", "false");
1198                 settings.endGroup();
1199     }
1200
1201     // Get/set the database version.  Not really used any more, but kept
1202     // for compatibility.
1203     public static void setDatabaseVersion(String version) {
1204                 settings.beginGroup("General");
1205                 settings.setValue("databaseVersion", version);
1206                 settings.endGroup();
1207     }
1208     public static String getDatabaseVersion() {
1209                 settings.beginGroup("General");
1210                 String val  = (String)settings.value("databaseVersion", "0.70");
1211                 settings.endGroup();
1212                 return val;
1213     }
1214
1215     // Get the URL (full path) of the main database
1216     public static String getDatabaseUrl() {
1217                 settings.beginGroup("General");
1218                 String val  = (String)settings.value("DatabaseURL", "");
1219                 settings.endGroup();
1220                 if (val.equals(""))
1221                         val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.databaseName);
1222                 return val;
1223     }
1224     
1225     // get the url (full path) of the searchable word database
1226     public static String getIndexDatabaseUrl() {
1227                 settings.beginGroup("General");
1228                 String val  = (String)settings.value("IndexDatabaseURL", "");
1229                 settings.endGroup();
1230                 if (val.equals(""))
1231                         val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.indexDatabaseName);
1232                 return val;
1233     }
1234     
1235     // Get the url (full path) of the attachment database
1236     public static String getResourceDatabaseUrl() {
1237                 settings.beginGroup("General");
1238                 String val  = (String)settings.value("ResourceDatabaseURL", "");
1239                 settings.endGroup();
1240                 if (val.equals(""))
1241                         val = "jdbc:h2:"+Global.getFileManager().getDbDirPath(Global.resourceDatabaseName);
1242                 return val;
1243     }
1244     
1245         // 操作履歴データベースのURL(フルパス)をゲット
1246         public static String getBehaviorDatabaseUrl() {
1247                 settings.beginGroup("General");
1248                 String val = (String) settings.value("BehaviorDatabaseURL", "");
1249                 settings.endGroup();
1250                 if (val.equals(""))
1251                         val = "jdbc:h2:"
1252                                         + Global.getFileManager().getDbDirPath(
1253                                                         Global.behaviorDatabaseName);
1254                 return val;
1255         }
1256         
1257     public static void setDatabaseUrl(String value) {
1258                 settings.beginGroup("General");
1259                 settings.setValue("DatabaseURL", value);
1260                 settings.endGroup();
1261     }
1262     public static void setIndexDatabaseUrl(String value) {
1263                 settings.beginGroup("General");
1264                 settings.setValue("IndexDatabaseURL", value);
1265                 settings.endGroup();
1266     }
1267     public static void setResourceDatabaseUrl(String value) {
1268                 settings.beginGroup("General");
1269                 settings.setValue("ResourceDatabaseURL", value);
1270                 settings.endGroup();
1271     }
1272     
1273         public static void setBehaviorDatabaseUrl(String value) {
1274                 settings.beginGroup("General");
1275                 settings.setValue("BehaviorDatabaseURL", value);
1276                 settings.endGroup();
1277         }
1278         
1279     public static String getDatabaseUserid() {
1280                 settings.beginGroup("General");
1281                 String val  = (String)settings.value("databaseUserid", "");
1282                 settings.endGroup();
1283                 return val;
1284     }
1285     public static String getDatabaseUserPassword() {
1286                 settings.beginGroup("General");
1287                 String val  = (String)settings.value("databaseUserPassword", "");
1288                 settings.endGroup();
1289                 return val;
1290     }
1291     
1292     // get/Set the style sheet and the palette to control the look & feel
1293     public static void setStyle(String style) {
1294                 settings.beginGroup("General");
1295                 settings.setValue("style", style);
1296                 settings.endGroup();
1297     }
1298     public static String getStyle() {
1299                 settings.beginGroup("General");
1300                 String val  = (String)settings.value("style", "Cleanlooks");
1301                 settings.endGroup();
1302                 return val;
1303     }
1304     public static boolean useStandardPalette() {
1305                 settings.beginGroup("General");
1306                 try {
1307                         String text = (String)settings.value("standardPalette", "true");
1308                         settings.endGroup();
1309                         if (text.equalsIgnoreCase("true"))
1310                                 return true;
1311                         else
1312                                 return false;
1313                 } catch (java.lang.ClassCastException e) {
1314                         Boolean value = (Boolean) settings.value("standardPalette", true);
1315                         settings.endGroup();
1316                         return value;
1317                 }
1318     }
1319     public static void setStandardPalette(boolean val) {
1320                 settings.beginGroup("General");
1321                 if (val)
1322                         settings.setValue("standardPalette", "true");
1323                 else
1324                         settings.setValue("standardPalette", "false");
1325                 settings.endGroup();
1326     }
1327     
1328     // Set the amount of time to wait between indexing
1329     // Get/Set interval when the index thread wakes up.
1330     public static void setIndexThreadSleepInterval(int sleep) {
1331                 settings.beginGroup("General");
1332                 settings.setValue("IndexThreadSleepInterval", sleep);
1333                 settings.endGroup();
1334     }
1335     public static int getIndexThreadSleepInterval() {
1336                 settings.beginGroup("General");
1337                 Integer sleep;
1338                 try {
1339                         String val  = (String)settings.value("IndexThreadSleepInterval", "300");
1340                         sleep = new Integer(val.trim());
1341                 } catch (Exception e) {
1342                         try {
1343                                 sleep = (Integer)settings.value("IndexThreadSleepInterval", 0);
1344                         } catch (Exception e1) {
1345                                 sleep = 300;
1346                         }
1347                 }
1348                 settings.endGroup();
1349                 return sleep;
1350     }
1351     
1352     
1353     // Get/Set a window state for later restoring
1354     public static void saveState(String name, QByteArray state) {
1355         int view = Global.getListView();
1356         if (view == Global.View_List_Narrow)
1357                 name = name +"Narrow";
1358                 settings.beginGroup("SaveState");
1359                 settings.setValue(name, state);
1360                 settings.endGroup();
1361     }
1362     
1363     public static QByteArray restoreState(String name) {
1364         int view = Global.getListView();
1365         if (view == Global.View_List_Narrow)
1366                 name = name +"Narrow";
1367                 settings.beginGroup("SaveState");
1368                 QByteArray state = (QByteArray)settings.value(name);
1369                 settings.endGroup();
1370                 return state;
1371     }
1372     public static void saveGeometry(String name, QByteArray state) {
1373         int view = Global.getListView();
1374         if (view == Global.View_List_Narrow)
1375                 settings.beginGroup("SaveGeometryNarrow");
1376         else
1377                 settings.beginGroup("SaveGeometry");
1378                 settings.setValue(name, state);
1379                 settings.endGroup();
1380     }
1381     
1382     public static QByteArray restoreGeometry(String name) {
1383         int view = Global.getListView();
1384         if (view == Global.View_List_Narrow)
1385                 settings.beginGroup("SaveGeometryNarrow");
1386         else
1387                 settings.beginGroup("SaveGeometry");
1388                 QByteArray state = (QByteArray)settings.value(name);
1389                 settings.endGroup();
1390                 return state;
1391     }
1392     
1393     
1394     // Set how often to do an automatic save
1395     public static void setAutoSaveInterval(int interval) {
1396                 settings.beginGroup("General");
1397                 settings.setValue("autoSaveInterval", interval);
1398                 settings.endGroup();
1399     }
1400     public static int getAutoSaveInterval() {
1401                 settings.beginGroup("General");
1402                 Integer value;
1403                 try {
1404                         String val  = (String)settings.value("autoSaveInterval", "5");
1405                         value = new Integer(val.trim());
1406                 } catch (Exception e) {
1407                         try {
1408                                 value = (Integer)settings.value("autoSaveInterval", 5);
1409                         } catch (Exception e1) {
1410                                 value = 5;
1411                         }
1412                 }
1413                 settings.endGroup();
1414                 return value;
1415     }
1416      
1417     // Add an invalid attribute & element to the database so we don't bother parsing it in the future
1418     // These values we automatically remove from any note.
1419     // Add invalid attributes
1420     public static void addInvalidAttribute(String element, String attribute) {
1421         
1422                 List<String> attributes = invalidAttributes.get(element);
1423                 if (attributes != null) {
1424                         for (int i=0; i<attributes.size(); i++)
1425                                 if (attribute.equalsIgnoreCase(attributes.get(i))) {
1426                                         return;
1427                         }
1428         }
1429         
1430         ArrayList<String> attributeList;
1431         if (!invalidAttributes.containsKey(element)) {
1432                 attributeList = new ArrayList<String>();
1433                 attributeList.add(attribute);
1434                 invalidAttributes.put(element, attributeList);
1435         }
1436         else {
1437                 attributeList = invalidAttributes.get(element);
1438                 attributeList.add(attribute);
1439                 invalidAttributes.put(element,attributeList);
1440         }
1441     }
1442    
1443     // Add invalid attributes
1444     public static void addInvalidElement(String element) {
1445                 for (int i=0; i<invalidElements.size(); i++) {
1446                         if (element.equalsIgnoreCase(invalidElements.get(i)))
1447                                 return;
1448                 }
1449         invalidElements.add(element);
1450     }
1451     
1452     // Get/Set proxy information
1453     // Proxy settings
1454     public static String getProxyValue(String key) {
1455                 settings.beginGroup("Proxy");
1456                 String val  = (String)settings.value(key, "");
1457                 settings.endGroup();
1458                 return val;
1459     }
1460     public static void setProxyValue(String key, String value) {
1461                 settings.beginGroup("Proxy");
1462                 settings.setValue(key, value);
1463                 settings.endGroup();
1464     }
1465     
1466     // Change a byte array to a hex string
1467     // Convert a byte array to a hex string
1468         public static String byteArrayToHexString(byte data[]) {
1469                 StringBuffer buf = new StringBuffer();
1470             for (byte element : data) {
1471                 int halfbyte = (element >>> 4) & 0x0F;
1472                 int two_halfs = 0;
1473                 do {
1474                         if ((0 <= halfbyte) && (halfbyte <= 9))
1475                                buf.append((char) ('0' + halfbyte));
1476                            else
1477                                 buf.append((char) ('a' + (halfbyte - 10)));
1478                         halfbyte = element & 0x0F;
1479                 } while(two_halfs++ < 1);
1480             }
1481             return buf.toString();              
1482         }
1483
1484     
1485         // Get/Set spelling settings
1486         public static boolean getSpellSetting(String value) {
1487                 settings.beginGroup("Spell");
1488                 String text = (String)settings.value(value, "");
1489                 settings.endGroup();
1490                 if (text.equalsIgnoreCase("true"))
1491                         return true;
1492                 if (text.equalsIgnoreCase("false"))
1493                         return false;
1494                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREDIGITWORDS))
1495                         return true;
1496                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREINTERNETADDRESSES))
1497                         return true;
1498                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREUPPERCASE))
1499                         return true;
1500                 if (value.equalsIgnoreCase(Configuration.SPELL_IGNORESENTENCECAPITALIZATION))
1501                         return true;
1502                 return false;
1503     }
1504     public static void setSpellSetting(String setting, boolean val) {
1505                 settings.beginGroup("Spell");
1506                 if (val)
1507                         settings.setValue(setting, "true");
1508                 else
1509                         settings.setValue(setting, "false");
1510                 settings.endGroup();
1511     }
1512         
1513         // Get/Set how we should display tags (color them, hide unused, or do nothing)
1514         // What to do with inactive tags?
1515         public static String tagBehavior() {
1516                 settings.beginGroup("General");
1517                 String text = (String)settings.value("tagBehavior", "DoNothing");
1518                 settings.endGroup();
1519                 return text;
1520         }
1521         // What to do with inactive tags?
1522         public static void setTagBehavior(String value) {
1523                 settings.beginGroup("General");
1524                 settings.setValue("tagBehavior", value);
1525                 settings.endGroup();
1526         }
1527
1528     
1529         // Should the toolbar be visible?
1530         public static boolean isToolbarButtonVisible(String window, Boolean val) {
1531                 settings.beginGroup("ToolbarButtonsVisible");
1532                 try {
1533                         String text = (String)settings.value(window, val.toString());
1534                         settings.endGroup();
1535                         if (text.equalsIgnoreCase("true"))
1536                                 return true;
1537                         else
1538                                 return false;   
1539                 } catch (java.lang.ClassCastException e) {
1540                         Boolean value = (Boolean) settings.value(window, val);
1541                         settings.endGroup();
1542                         return value;
1543                 }
1544     }
1545     public static void saveToolbarButtonsVisible(String column, boolean val) {
1546                 settings.beginGroup("ToolbarButtonsVisible");
1547                 if (val)
1548                         settings.setValue(column, "true");
1549                 else
1550                         settings.setValue(column, "false");
1551                 settings.endGroup();
1552     }
1553         
1554     // Are thumbnails enabled?
1555     
1556     public static boolean enableThumbnails() {
1557                 settings.beginGroup("Debug");
1558                 try {
1559                         String text = (String)settings.value("thumbnails", "true");
1560                         settings.endGroup();
1561                         if (text.equalsIgnoreCase("true"))
1562                                 return true;
1563                         else
1564                                 return false;
1565                 } catch (java.lang.ClassCastException e) {
1566                         Boolean value = (Boolean) settings.value("thumbnails", true);
1567                         settings.endGroup();
1568                         return value;
1569                 }
1570     }
1571     public static void setEnableThumbnails(boolean val) {
1572                 settings.beginGroup("Debug");
1573                 if (val)
1574                         settings.setValue("thumbnails", "true");
1575                 else
1576                         settings.setValue("thumbnails", "false");
1577                 settings.endGroup();
1578     }
1579         
1580     // Trace used for performance tuning.  Not normally used in production.
1581         // Print date/time.  Used mainly for performance tracing
1582         public static void trace(boolean resetInterval) {
1583                 String fmt = "MM/dd/yy HH:mm:ss.SSSSSS";
1584                 String dateTimeFormat = new String(fmt);
1585                 SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);
1586                 Calendar cal = Calendar.getInstance();
1587                 if (intervalTraceTime == null) 
1588                         intervalTraceTime = Calendar.getInstance();
1589                 if (startTraceTime == null)
1590                         startTraceTime = Calendar.getInstance();
1591                 
1592                 float interval = (cal.getTimeInMillis() - intervalTraceTime.getTimeInMillis());
1593                 float total = (cal.getTimeInMillis() - startTraceTime.getTimeInMillis());
1594                 
1595 //              if (interval > 00.0) {
1596                         StackTraceElement[] exceptions = Thread.currentThread().getStackTrace();
1597                         System.out.println("------------------------------------------");
1598
1599                         System.out.println("Date/Time " +simple.format(cal.getTime()));
1600                         System.out.format("Interval Time: %-10.6f%n", interval);
1601                         System.out.format("Total Time: %-10.6f%n", total);
1602                         for (int i=2; i<5 && i<exceptions.length; i++) {
1603                                 System.out.println(exceptions[i]);
1604                         }
1605 //              }
1606                 if (resetInterval)
1607                         intervalTraceTime = cal;
1608         }
1609         public static void traceReset() {
1610                 intervalTraceTime = null;
1611                 startTraceTime = null;
1612         }
1613
1614     
1615         // Get the FileManager class to manage local files & directories
1616         public static FileManager getFileManager() {
1617         return fileManager;
1618     }
1619         
1620         // Should the note editor be disabled?
1621     public static boolean getDisableViewing() {
1622         return disableViewing;
1623     }
1624
1625     //**********************
1626     //* Thumbnail zoom level
1627     //**********************
1628     public static int calculateThumbnailZoom(String content) {
1629         int zoom = 1;
1630                 if (content.indexOf("application/pdf") == -1) {
1631                         if (content.indexOf("image/") == -1) {
1632                                 String text =  StringEscapeUtils.unescapeHtml4(content.replaceAll("\\<.*?\\>", ""));
1633                                 zoom = 2;
1634                                 if (text.length() < 500) 
1635                                         zoom = 2;
1636                                 if (text.length() < 250)
1637                                         zoom = 3;
1638                                 if (text.length() < 100)
1639                                         zoom = 4;
1640                                 if (text.length() < 50)
1641                                         zoom = 5;
1642                                 if (text.length() < 10)
1643                                         zoom = 6;
1644                         }
1645                 }
1646                 return zoom;
1647     }
1648     
1649     //**********************
1650     //* List View settings 
1651     //**********************
1652     public static void setListView(int view) {
1653                 settings.beginGroup("General");
1654                 settings.setValue("listView", view);
1655                 settings.endGroup();
1656     }
1657     public static int getListView() {
1658                 settings.beginGroup("General");
1659                 Integer value;
1660                 try {
1661                         String val  = (String)settings.value("listView", View_List_Wide);
1662                         value = new Integer(val.trim());
1663                 } catch (Exception e) {
1664                         try {
1665                                 value = (Integer)settings.value("listView", View_List_Wide);
1666                         } catch (Exception e1) {
1667                                 value = View_List_Wide;
1668                         }
1669                 }
1670                 settings.endGroup();
1671                 return value;
1672     }
1673
1674     
1675     
1676     //*******************
1677     // Font Settings
1678     //*******************
1679     public static boolean overrideDefaultFont() {
1680                 settings.beginGroup("Font");
1681                 try {
1682                         String text = (String)settings.value("overrideFont", "false");
1683                         settings.endGroup();
1684                         if (text.equalsIgnoreCase("true"))
1685                                 return true;
1686                         else
1687                                 return false;   
1688                 } catch (java.lang.ClassCastException e) {
1689                         Boolean value = (Boolean) settings.value("overrideFont", false);
1690                         settings.endGroup();
1691                         return value;
1692                 }
1693
1694     }
1695     
1696     //****************************************************
1697     // Get/Set the default font settings for a new note
1698     //****************************************************
1699     public static void setOverrideDefaultFont(boolean value) {
1700                 settings.beginGroup("Font");
1701                 settings.setValue("overrideFont", value);
1702                 settings.endGroup();    
1703     }
1704     public static String getDefaultFont() {
1705                 settings.beginGroup("Font");
1706                 String val  = (String)settings.value("font", "");
1707                 settings.endGroup();
1708                 return val;
1709     }
1710     public static void setDefaultFont(String value) {
1711                 settings.beginGroup("Font");
1712                 settings.setValue("font", value);
1713                 settings.endGroup();
1714     }
1715     public static String getDefaultFontSize() {
1716                 settings.beginGroup("Font");
1717                 String val  = (String)settings.value("fontSize", "");
1718                 settings.endGroup();
1719                 return val;
1720     }
1721     public static void setDefaultFontSize(String value) {
1722                 settings.beginGroup("Font");
1723                 settings.setValue("fontSize", value);
1724                 settings.endGroup();
1725     }
1726     
1727     
1728     //*******************************************
1729     // Override the close & minimize instead.
1730     //*******************************************
1731     public static boolean minimizeOnClose() {
1732                 settings.beginGroup("General");
1733                 try {
1734                         String text = (String)settings.value("minimizeOnClose", "false");
1735                         settings.endGroup();
1736                         if (text.equalsIgnoreCase("true") && QSystemTrayIcon.isSystemTrayAvailable())
1737                                 return true;
1738                         else
1739                                 return false;
1740                 } catch (java.lang.ClassCastException e) {
1741                         Boolean value = (Boolean) settings.value("minimizeOnClose", false);
1742                         settings.endGroup();
1743                         return value;
1744                 }
1745     }
1746     public static void setMinimizeOnClose(boolean value) {
1747                 settings.beginGroup("General");
1748                 settings.setValue("minimizeOnClose", value);
1749                 settings.endGroup();    
1750     }
1751
1752     //*********************************
1753     // Check version information
1754     //*********************************
1755     public static boolean checkVersionUpgrade() {
1756                 settings.beginGroup("Upgrade");
1757                 try {
1758                         String text = (String)settings.value("checkForUpdates", "true");
1759                         settings.endGroup();
1760                         if (text.equalsIgnoreCase("true"))
1761                                 return true;
1762                         else
1763                                 return false;
1764                 } catch (java.lang.ClassCastException e) {
1765                         Boolean value = (Boolean) settings.value("checkForUpdates", true);
1766                         settings.endGroup();
1767                         return value;
1768                 }
1769     }
1770     public static void setCheckVersionUpgrade(boolean value) {
1771                 settings.beginGroup("Upgrade");
1772                 settings.setValue("checkForUpdates", value);
1773                 settings.endGroup();    
1774     }
1775     public static String getUpdatesAvailableUrl() {
1776                 settings.beginGroup("Upgrade");
1777                 String text = (String)settings.value("avialableUrl", "http://puma.cis.ibaraki.ac.jp/products/neighbornote/develop/versions.txt");
1778                 settings.endGroup();    
1779                 return text;
1780     }
1781     public static String getUpdateAnnounceUrl() {
1782                 settings.beginGroup("Upgrade");
1783                 String text = (String)settings.value("announceUrl", "http://puma.cis.ibaraki.ac.jp/products/neighbornote/develop/upgrade.html");
1784                 settings.endGroup();    
1785                 return text;
1786     }
1787     public static String getUpdateDownloadUrl() {
1788                 settings.beginGroup("Upgrade");
1789                 String text = (String)settings.value("downloadUrl", "http://puma.cis.ibaraki.ac.jp/products/neighbornote/download.html");
1790                 settings.endGroup();    
1791                 return text;
1792     }
1793     
1794     //*******************
1795     // Index settings
1796     //*******************
1797     // Set/Get if we should index the text of a note
1798     public static boolean indexNoteBody() {
1799                 settings.beginGroup("Index");
1800                 try {
1801                         String value = (String)settings.value("indexNoteBody", "true");
1802                         settings.endGroup();
1803                         if (value.equals("true"))
1804                                 return true;
1805                         else
1806                                 return false;
1807                 } catch (java.lang.ClassCastException e) {
1808                         Boolean value = (Boolean) settings.value("indexNoteBody", true);
1809                         settings.endGroup();
1810                         return value;
1811                 }
1812     }
1813     public static void setIndexNoteTitle(boolean value) {
1814                 settings.beginGroup("Index");
1815                 settings.setValue("indexNoteTitle", value);
1816                 settings.endGroup();    
1817     }
1818     // Set/Get if we should index the title of a note
1819     public static boolean indexNoteTitle() {
1820                 settings.beginGroup("Index");
1821                 try {
1822                         String value = (String)settings.value("indexNoteTitle", "true");
1823                         settings.endGroup();
1824                         if (value.equals("true"))
1825                                 return true;
1826                         else
1827                                 return false;
1828                 } catch (java.lang.ClassCastException e) {
1829                         Boolean value = (Boolean) settings.value("indexNoteTitle", true);
1830                         settings.endGroup();
1831                         return value;
1832                 }
1833     }
1834     public static void setIndexNoteBody(boolean value) {
1835                 settings.beginGroup("Index");
1836                 settings.setValue("indexNoteBody", value);
1837                 settings.endGroup();    
1838     }
1839     // Set/Get if we should index any attachments
1840     public static boolean indexAttachmentsLocally() {
1841                 settings.beginGroup("Index");
1842                 try {
1843                         String value = (String)settings.value("indexAttachmentsLocally", "true");
1844                         settings.endGroup();
1845                         if (value.equals("true"))
1846                                 return true;
1847                         else
1848                                 return false;
1849                 } catch (java.lang.ClassCastException e) {
1850                         Boolean value = (Boolean) settings.value("indexAttachmentsLocally", true);
1851                         settings.endGroup();
1852                         return value;
1853                 }
1854     }
1855     public static void setIndexImageRecognition(boolean value) {
1856                 settings.beginGroup("Index");
1857                 settings.setValue("indexImageRecognition", value);
1858                 settings.endGroup();    
1859     }
1860     public static boolean indexImageRecognition() {
1861                 settings.beginGroup("Index");
1862                 try {
1863                         String value = (String)settings.value("indexImageRecognition", "true");
1864                         settings.endGroup();
1865                         if (value.equals("true"))
1866                                 return true;
1867                         else
1868                                 return false;
1869                 } catch (java.lang.ClassCastException e) {
1870                         Boolean value = (Boolean) settings.value("indexImageRecognition", true);
1871                         settings.endGroup();
1872                         return value;
1873                 }
1874     }
1875     public static void setIndexAttachmentsLocally(boolean value) {
1876                 settings.beginGroup("Index");
1877                 settings.setValue("indexAttachmentsLocally", value);
1878                 settings.endGroup();    
1879     }
1880     // Get/Set characters that shouldn't be removed from a word
1881 //    public static String getSpecialIndexCharacters() {
1882 //              settings.beginGroup("Index");
1883 //              String text = (String)settings.value("specialCharacters", "");
1884 //              settings.endGroup();    
1885 //              return text;
1886 //    }
1887 //    public static void setSpecialIndexCharacters(String value) {
1888 //              settings.beginGroup("Index");
1889 //              settings.setValue("specialCharacters", value);
1890 //              settings.endGroup();    
1891 //              databaseCache = value;
1892 //    }
1893     
1894     //*****************************************************************************
1895     // Control how tag selection behaves (should they be "and" or "or" selections
1896     //*****************************************************************************
1897     public static boolean anyTagSelectionMatch() {
1898                 settings.beginGroup("General");
1899                 try {
1900                         String value = (String)settings.value("anyTagSelectionMatch", "false");
1901                         settings.endGroup();
1902                         if (value.equals("true"))
1903                                 return true;
1904                         else
1905                                 return false;
1906                 } catch (java.lang.ClassCastException e) {
1907                         Boolean value = (Boolean) settings.value("anyTagSelectionMatch", false);
1908                         settings.endGroup();
1909                         return value;
1910                 }
1911     }
1912     public static void setAnyTagSelectionMatch(boolean value) {
1913                 settings.beginGroup("General");
1914                 settings.setValue("anyTagSelectionMatch", value);
1915                 settings.endGroup();    
1916     }
1917
1918     //*****************************************************************************
1919     // Control if a user receives a warning when trying to create a note-to-note link
1920     // when the DB is not synchronized.
1921     //*****************************************************************************
1922     public static boolean bypassSynchronizationWarning() {
1923                 settings.beginGroup("User");
1924                 try {
1925                         String value = (String)settings.value("bypassSynchronizationWarning", "false");
1926                         settings.endGroup();
1927                         if (value.equals("true"))
1928                                 return true;
1929                         else
1930                                 return false;
1931                 } catch (java.lang.ClassCastException e) {
1932                         Boolean value = (Boolean) settings.value("bypassSynchronizationWarning", false);
1933                         settings.endGroup();
1934                         return value;
1935                 }
1936     }
1937     public static void setBypassSynchronizationWarning(boolean value) {
1938                 settings.beginGroup("User");
1939                 settings.setValue("bypassSynchronizationWarning", value);
1940                 settings.endGroup();    
1941     }
1942
1943     
1944     //***********************
1945     //* Database cache size
1946     //***********************
1947     public static String getDatabaseCacheSize() {
1948                 settings.beginGroup("Debug");
1949                 String text = (String)settings.value("databaseCache", "16384");
1950                 settings.endGroup();    
1951                 return text;
1952     }
1953     public static void setDatabaseCache(String value) {
1954                 settings.beginGroup("Debug");
1955                 settings.setValue("databaseCache", value);
1956                 settings.endGroup();    
1957                 databaseCache = value;
1958     }
1959
1960     
1961     // This is used to copy a class since Java's normal deep copy is wacked
1962     public static Object deepCopy(Object oldObj) 
1963     {
1964        ObjectOutputStream oos = null;
1965        ObjectInputStream ois = null;
1966        try
1967        {
1968           ByteArrayOutputStream bos = 
1969                 new ByteArrayOutputStream(); // A
1970           oos = new ObjectOutputStream(bos); // B
1971           // serialize and pass the object
1972           oos.writeObject(oldObj);   // C
1973           oos.flush();               // D
1974           ByteArrayInputStream bin = 
1975                 new ByteArrayInputStream(bos.toByteArray()); // E
1976           ois = new ObjectInputStream(bin);                  // F
1977           // return the new object
1978           return ois.readObject(); // G
1979        }
1980        catch(Exception e)
1981        {
1982           Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e);
1983        }
1984           try {
1985                         oos.close();
1986                 ois.close();
1987                 } catch (IOException e) {
1988                         Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e);
1989                         e.printStackTrace();
1990                 }
1991
1992                 return null;
1993     }
1994
1995     // If we should automatically select the children of any tag
1996     public static boolean includeTagChildren() {
1997                 settings.beginGroup("General");
1998                 try {
1999                         String value = (String)settings.value("includeTagChildren", "false");
2000                         settings.endGroup();
2001                         if (value.equals("true"))
2002                                 return true;
2003                         else
2004                                 return false;
2005                 } catch (java.lang.ClassCastException e) {
2006                         Boolean value = (Boolean) settings.value("includeTagChildren", false);
2007                         settings.endGroup();
2008                         return value;
2009                 }
2010
2011     }
2012     public static void setIncludeTagChildren(boolean value) {
2013                 settings.beginGroup("General");
2014                 settings.setValue("includeTagChildren", value);
2015                 settings.endGroup();    
2016     }
2017     
2018     // If we should automatically wildcard searches
2019 //    public static boolean automaticWildcardSearches() {
2020 //              settings.beginGroup("General");
2021 //              try {
2022 //                      String value = (String)settings.value("automaticWildcard", "false");
2023 //                      settings.endGroup();
2024 //                      if (value.equals("true"))
2025 //                              return true;
2026 //                      else
2027 //                              return false;
2028 //              } catch (java.lang.ClassCastException e) {
2029 //                      Boolean value = (Boolean) settings.value("automaticWildcard", false);
2030 //                      settings.endGroup();
2031 //                      return value;
2032 //              }
2033 //
2034 //    }
2035 //    public static void setAutomaticWildcardSearches(boolean value) {
2036 //              settings.beginGroup("General");
2037 //              settings.setValue("automaticWildcard", value);
2038 //              settings.endGroup();    
2039 //    }
2040
2041     // If we should automatically select the children of any tag
2042     public static boolean displayRightToLeft() {
2043                 settings.beginGroup("General");
2044                 try {
2045                         String value = (String)settings.value("displayRightToLeft", "false");
2046                         settings.endGroup();
2047                         if (value.equals("true"))
2048                                 return true;
2049                         else
2050                                 return false;
2051                 } catch (java.lang.ClassCastException e) {
2052                         Boolean value = (Boolean) settings.value("displayRightToLeft", false);
2053                         settings.endGroup();
2054                         return value;
2055                 }
2056
2057     }
2058     public static void setDisplayRightToLeft(boolean value) {
2059                 settings.beginGroup("General");
2060                 settings.setValue("displayRightToLeft", value);
2061                 settings.endGroup();    
2062     }
2063
2064
2065     //***********************
2066     //* Startup Notebook
2067     //***********************
2068     public static String getStartupNotebook() {
2069                 settings.beginGroup("General");
2070                 String text = (String)settings.value("startupNotebook", "");
2071                 settings.endGroup();    
2072                 return text;
2073     }
2074     public static void setStartupNotebook(String value) {
2075                 settings.beginGroup("General");
2076                 settings.setValue("startupNotebook", value);
2077                 settings.endGroup();    
2078                 databaseCache = value;
2079     }
2080     
2081     // 複数ノート同時閲覧操作に対する重み付け
2082     public static void setBrowseWeight(int weight) {
2083                 settings.beginGroup("RensoNoteList");
2084                 settings.setValue("browseWeight", weight);
2085                 settings.endGroup();            
2086     }
2087     public static int getBrowseWeight() {
2088                 settings.beginGroup("RensoNoteList");
2089                 Integer value;
2090                 try {
2091                         String val  = (String)settings.value("browseWeight", 1);
2092                         value = new Integer(val.trim());
2093                 } catch (Exception e) {
2094                         try {
2095                                 value = (Integer)settings.value("browseWeight", 1);
2096                         } catch (Exception e1) {
2097                                 value = 1;
2098                         }
2099                 }
2100                 settings.endGroup();
2101                 return value;
2102     }
2103     
2104     // ノート内容のコピー&ペースト操作に対する重み付け
2105     public static void setCopyPasteWeight(int weight) {
2106                 settings.beginGroup("RensoNoteList");
2107                 settings.setValue("copyPasteWeight", weight);
2108                 settings.endGroup();            
2109     }
2110     public static int getCopyPasteWeight() {
2111                 settings.beginGroup("RensoNoteList");
2112                 Integer value;
2113                 try {
2114                         String val  = (String)settings.value("copyPasteWeight", 3);
2115                         value = new Integer(val.trim());
2116                 } catch (Exception e) {
2117                         try {
2118                                 value = (Integer)settings.value("copyPasteWeight", 3);
2119                         } catch (Exception e1) {
2120                                 value = 3;
2121                         }
2122                 }
2123                 settings.endGroup();
2124                 return value;
2125     }
2126     
2127     // 新規ノート追加操作に対する重み付け
2128     public static void setAddNewNoteWeight(int weight) {
2129                 settings.beginGroup("RensoNoteList");
2130                 settings.setValue("addNewNoteWeight", weight);
2131                 settings.endGroup();            
2132     }
2133         public static int getAddNewNoteWeight() {
2134                 settings.beginGroup("RensoNoteList");
2135                 Integer value;
2136                 try {
2137                         String val  = (String)settings.value("addNewNoteWeight", 3);
2138                         value = new Integer(val.trim());
2139                 } catch (Exception e) {
2140                         try {
2141                                 value = (Integer)settings.value("addNewNoteWeight", 3);
2142                         } catch (Exception e1) {
2143                                 value = 1;
2144                         }
2145                 }
2146                 settings.endGroup();
2147                 return value;
2148         }
2149         
2150         // 連想ノートクリック操作に対する重み付け
2151     public static void setRensoItemClickWeight(int weight) {
2152                 settings.beginGroup("RensoNoteList");
2153                 settings.setValue("rensoItemClickWeight", weight);
2154                 settings.endGroup();            
2155     }
2156         public static int getRensoItemClickWeight() {
2157                 settings.beginGroup("RensoNoteList");
2158                 Integer value;
2159                 try {
2160                         String val  = (String)settings.value("rensoItemClickWeight", 10);
2161                         value = new Integer(val.trim());
2162                 } catch (Exception e) {
2163                         try {
2164                                 value = (Integer)settings.value("rensoItemClickWeight", 10);
2165                         } catch (Exception e1) {
2166                                 value = 10;
2167                         }
2168                 }
2169                 settings.endGroup();
2170                 return value;
2171         }
2172         
2173         // タグ付け操作に対する重み付け
2174     public static void setSameTagWeight(int weight) {
2175                 settings.beginGroup("RensoNoteList");
2176                 settings.setValue("sameTagWeight", weight);
2177                 settings.endGroup();            
2178     }
2179         public static int getSameTagWeight() {
2180                 settings.beginGroup("RensoNoteList");
2181                 Integer value;
2182                 try {
2183                         String val  = (String)settings.value("sameTagWeight", 2);
2184                         value = new Integer(val.trim());
2185                 } catch (Exception e) {
2186                         try {
2187                                 value = (Integer)settings.value("sameTagWeight", 2);
2188                         } catch (Exception e1) {
2189                                 value = 2;
2190                         }
2191                 }
2192                 settings.endGroup();
2193                 return value;
2194         }
2195         
2196         // ノートブック変更操作に対する重み付け
2197     public static void setSameNotebookWeight(int weight) {
2198                 settings.beginGroup("RensoNoteList");
2199                 settings.setValue("sameNotebookWeight", weight);
2200                 settings.endGroup();            
2201     }
2202         public static int getSameNotebookWeight() {
2203                 settings.beginGroup("RensoNoteList");
2204                 Integer value;
2205                 try {
2206                         String val  = (String)settings.value("sameNotebookWeight", 2);
2207                         value = new Integer(val.trim());
2208                 } catch (Exception e) {
2209                         try {
2210                                 value = (Integer)settings.value("sameNotebookWeight", 2);
2211                         } catch (Exception e1) {
2212                                 value = 2;
2213                         }
2214                 }
2215                 settings.endGroup();
2216                 return value;
2217         }
2218         
2219         // Evernote関連ノート機能統合に対する重み付け
2220         public static void setENRelatedNotesWeight(int weight) {
2221                 settings.beginGroup("RensoNoteList");
2222                 settings.setValue("enRelatedNotesWeight", weight);
2223                 settings.endGroup();
2224         }
2225         public static int getENRelatedNotesWeight() {
2226                 settings.beginGroup("RensoNoteList");
2227                 Integer value;
2228                 try {
2229                         String val = (String)settings.value("enRelatedNotesWeight", 5);
2230                         value = new Integer(val.trim());
2231                 } catch (Exception e) {
2232                         try {
2233                                 value = (Integer)settings.value("enRelatedNotesWeight", 5);
2234                         } catch (Exception e1) {
2235                                 value = 10;
2236                         }
2237                 }
2238                 settings.endGroup();
2239                 return value;
2240         }
2241     
2242     //*******************
2243     // ノートのマージ・複製の関連ノートリストへの適用
2244     //*******************
2245     public static void setMergeRensoNote(boolean value) {
2246                 settings.beginGroup("RensoNoteList");
2247                 settings.setValue("mergeRensoNoteList", value);
2248                 settings.endGroup();    
2249     }
2250     
2251     public static boolean getMergeRensoNote() {
2252                 settings.beginGroup("RensoNoteList");
2253                 try {
2254                         String value = (String)settings.value("mergeRensoNoteList", "true");
2255                         settings.endGroup();
2256                         if (value.equals("true"))
2257                                 return true;
2258                         else
2259                                 return false;
2260                 } catch (java.lang.ClassCastException e) {
2261                         Boolean value = (Boolean) settings.value("mergeRensoNoteList", true);
2262                         settings.endGroup();
2263                         return value;
2264                 }
2265     }
2266     
2267     public static void setDuplicateRensoNote(boolean value) {
2268                 settings.beginGroup("RensoNoteList");
2269                 settings.setValue("duplicateRensoNoteList", value);
2270                 settings.endGroup();    
2271     }
2272     
2273     public static boolean getDuplicateRensoNote() {
2274                 settings.beginGroup("RensoNoteList");
2275                 try {
2276                         String value = (String)settings.value("duplicateRensoNoteList", "true");
2277                         settings.endGroup();
2278                         if (value.equals("true"))
2279                                 return true;
2280                         else
2281                                 return false;
2282                 } catch (java.lang.ClassCastException e) {
2283                         Boolean value = (Boolean) settings.value("duplicateRensoNoteList", true);
2284                         settings.endGroup();
2285                         return value;
2286                 }
2287     }
2288     
2289     // 連想ノートリストからノートを除外するときに確認メッセージを表示するかどうか
2290     public static boolean verifyExclude() {
2291                 settings.beginGroup("RensoNoteList");
2292                 try {
2293                         String text = (String)settings.value("verifyExclude", "true");
2294                         settings.endGroup();
2295                         if (text.equalsIgnoreCase("true"))
2296                                 return true;
2297                         else
2298                                 return false;
2299                 } catch (java.lang.ClassCastException e) {
2300                         Boolean value = (Boolean) settings.value("verifyExclude", true);
2301                         settings.endGroup();
2302                         return value;
2303                 }
2304     }
2305     
2306     public static void setVerifyExclude(boolean val) {
2307                 settings.beginGroup("RensoNoteList");
2308                 if (val)
2309                         settings.setValue("verifyExclude", "true");
2310                 else
2311                         settings.setValue("verifyExclude", "false");
2312                 settings.endGroup();
2313     }
2314     
2315         // 連想ノートリスト最大表示アイテム数
2316     public static void setRensoListItemMaximum(int maximum) {
2317                 settings.beginGroup("RensoNoteList");
2318                 settings.setValue("rensoListMaximum", maximum);
2319                 settings.endGroup();            
2320     }
2321         public static int getRensoListItemMaximum() {
2322                 settings.beginGroup("RensoNoteList");
2323                 Integer value;
2324                 try {
2325                         String val  = (String)settings.value("rensoListMaximum", 10);
2326                         value = new Integer(val.trim());
2327                 } catch (Exception e) {
2328                         try {
2329                                 value = (Integer)settings.value("rensoListMaximum", 10);
2330                         } catch (Exception e1) {
2331                                 value = 10;
2332                         }
2333                 }
2334                 settings.endGroup();
2335                 return value;
2336         }
2337         
2338         // タグを排除してプレーンテキストを抽出
2339         public static String extractPlainText(String sourceText) {
2340                 String plainText = sourceText.replaceAll("<.+?>", "");  // タグを除去
2341                 plainText = plainText.replaceAll("\\s{2,}", " ");               // 2個以上の空白文字を1文字の空白に変換
2342                 String kaigyo = System.getProperty("line.separator");
2343                 plainText = plainText.replaceAll(kaigyo, "");                   // 改行を除去
2344 //              plainText = plainText.replaceAll("&lt;.+?&gt;", "");    // &lt;で始まり&gt;で終わる文字列を除去
2345                 
2346                 // HTML特殊文字のサニタイジングを解除
2347                 plainText = plainText.replaceAll("&#39;", "'");
2348                 plainText = plainText.replaceAll("&quot;", "\"");
2349                 plainText = plainText.replaceAll("&gt;", ">");
2350                 plainText = plainText.replaceAll("&lt;", "<");
2351                 plainText = plainText.replaceAll("&amp;", "&");
2352                 
2353                 plainText = plainText.replaceAll("&.+?;", "");                  // その他HTML特殊文字があれば除去
2354                 
2355                 return plainText;
2356         }
2357         
2358         // 全文検索機能の対象となるテーブルとカラムを再構築
2359         public static boolean rebuildFullTextNoteTarget(DatabaseConnection dbConn) {
2360                 NSqlQuery nQuery = new NSqlQuery(dbConn.getConnection());
2361                 StringBuilder noteTableTarget = new StringBuilder();
2362                 boolean success = true;
2363                 
2364                 if (Global.indexNoteBody()) {
2365                         noteTableTarget.append("CONTENTTEXT");
2366                 }
2367                 if (Global.indexNoteTitle()) {
2368                         if (noteTableTarget.length() > 0) {
2369                                 noteTableTarget.append(", ");
2370                         }
2371                         noteTableTarget.append("TITLE");
2372                 }
2373                 
2374                 if (noteTableTarget.length() > 0) {
2375                         nQuery.prepare("CALL FTL_CREATE_INDEX('PUBLIC', 'NOTE', :column);");
2376                         nQuery.bindValue(":column", noteTableTarget.toString());
2377                         if (!nQuery.exec()) {
2378                                 success = false;
2379                         }
2380                 }
2381                 
2382                 return success;
2383         }
2384         
2385         public static boolean rebuildFullTextResourceTarget(DatabaseConnection dbConn) {
2386                 NSqlQuery rQuery = new NSqlQuery(dbConn.getResourceConnection());
2387                 StringBuilder resourceTableTarget = new StringBuilder();
2388                 boolean success = true;
2389                 
2390                 if (Global.indexAttachmentsLocally()) {
2391                         resourceTableTarget.append("RESOURCETEXT");
2392                 }
2393                 
2394                 if (resourceTableTarget.length() > 0) {
2395                         rQuery.prepare("CALL FTL_CREATE_INDEX('PUBLIC', 'NOTERESOURCES', :column);");
2396                         rQuery.bindValue(":column", resourceTableTarget.toString());
2397                         if (!rQuery.exec()) {
2398                                 success = false;
2399                         }
2400                 }
2401                 
2402                 return success;
2403         }
2404         
2405     // 操作ログを取らないモードのボタン状態
2406     public static boolean isHaltLogButton() {
2407                 settings.beginGroup("RensoNoteList");
2408                 try {
2409                         String text = (String)settings.value("haltOperationLog", "false");
2410                         settings.endGroup();
2411                         if (text.equalsIgnoreCase("true"))
2412                                 return true;
2413                         else
2414                                 return false;
2415                 } catch (java.lang.ClassCastException e) {
2416                         Boolean value = (Boolean) settings.value("haltOperationLog", true);
2417                         settings.endGroup();
2418                         return value;
2419                 }
2420     }
2421     public static void saveHaltLogButton(boolean val) {
2422                 settings.beginGroup("RensoNoteList");
2423                 if (val)
2424                         settings.setValue("haltOperationLog", "true");
2425                 else
2426                         settings.setValue("haltOperationLog", "false");
2427                 settings.endGroup();
2428     }
2429     
2430     // 連想ノートリストの重み付けモードの状態
2431     public static String rensoWeightingSelect() {
2432                 settings.beginGroup("RensoNoteList");
2433                 String text = (String)settings.value("rensoWeightingSelect", "Standard");
2434                 settings.endGroup();
2435                 return text;
2436     }
2437     public static void saveRensoWeightingSelect(String val) {
2438                 settings.beginGroup("RensoNoteList");
2439                 settings.setValue("rensoWeightingSelect", val);
2440                 settings.endGroup();
2441     }
2442     
2443     // ordinal から指定した Enum の要素に変換する汎用関数
2444         public static <E extends Enum<E>> E fromOrdinal(Class<E> enumClass, int ordinal) {
2445             E[] enumArray = enumClass.getEnumConstants();
2446             return enumArray[ordinal];
2447         }
2448         
2449         // 連想ノートリスト重み付けモード:カスタムの設定値(同時閲覧)
2450     public static int customBrowseWeight() {
2451                 settings.beginGroup("RensoNoteList");
2452                 Integer value;
2453                 try {
2454                         String val  = (String)settings.value("customBrowseWeight", 1);
2455                         value = new Integer(val.trim());
2456                 } catch (Exception e) {
2457                         try {
2458                                 value = (Integer)settings.value("customBrowseWeight", 1);
2459                         } catch (Exception e1) {
2460                                 value = 1;
2461                         }
2462                 }
2463                 settings.endGroup();
2464                 return value;
2465     }
2466         public static void saveCustomBrowseWeight(int weight) {
2467                 settings.beginGroup("RensoNoteList");
2468                 settings.setValue("customBrowseWeight", weight);
2469                 settings.endGroup();
2470         }
2471         // 連想ノートリスト重み付けモード:カスタムの設定値(コピー&ペースト)
2472     public static int customCopyPasteWeight() {
2473                 settings.beginGroup("RensoNoteList");
2474                 Integer value;
2475                 try {
2476                         String val  = (String)settings.value("customCopyPasteWeight", 3);
2477                         value = new Integer(val.trim());
2478                 } catch (Exception e) {
2479                         try {
2480                                 value = (Integer)settings.value("customCopyPasteWeight", 3);
2481                         } catch (Exception e1) {
2482                                 value = 3;
2483                         }
2484                 }
2485                 settings.endGroup();
2486                 return value;
2487     }
2488         public static void saveCustomCopyPasteWeight(int weight) {
2489                 settings.beginGroup("RensoNoteList");
2490                 settings.setValue("customCopyPasteWeight", weight);
2491                 settings.endGroup();
2492         }
2493         // 連想ノートリスト重み付けモード:カスタムの設定値(新規ノート追加)
2494     public static int customAddNewNoteWeight() {
2495                 settings.beginGroup("RensoNoteList");
2496                 Integer value;
2497                 try {
2498                         String val  = (String)settings.value("customAddNewNoteWeight", 3);
2499                         value = new Integer(val.trim());
2500                 } catch (Exception e) {
2501                         try {
2502                                 value = (Integer)settings.value("customAddNewNoteWeight", 3);
2503                         } catch (Exception e1) {
2504                                 value = 3;
2505                         }
2506                 }
2507                 settings.endGroup();
2508                 return value;
2509     }
2510         public static void saveCustomAddNewNoteWeight(int weight) {
2511                 settings.beginGroup("RensoNoteList");
2512                 settings.setValue("customAddNewNoteWeight", weight);
2513                 settings.endGroup();
2514         }
2515         // 連想ノートリスト重み付けモード:カスタムの設定値(連想ノートクリック)
2516     public static int customRensoItemClickWeight() {
2517                 settings.beginGroup("RensoNoteList");
2518                 Integer value;
2519                 try {
2520                         String val  = (String)settings.value("customRensoItemClickWeight", 10);
2521                         value = new Integer(val.trim());
2522                 } catch (Exception e) {
2523                         try {
2524                                 value = (Integer)settings.value("customRensoItemClickWeight", 10);
2525                         } catch (Exception e1) {
2526                                 value = 10;
2527                         }
2528                 }
2529                 settings.endGroup();
2530                 return value;
2531     }
2532         public static void saveCustomRensoItemClickWeight(int weight) {
2533                 settings.beginGroup("RensoNoteList");
2534                 settings.setValue("customRensoItemClickWeight", weight);
2535                 settings.endGroup();
2536         }
2537         // 連想ノートリスト重み付けモード:カスタムの設定値(同じタグ)
2538     public static int customSameTagWeight() {
2539                 settings.beginGroup("RensoNoteList");
2540                 Integer value;
2541                 try {
2542                         String val  = (String)settings.value("customSameTagWeight", 2);
2543                         value = new Integer(val.trim());
2544                 } catch (Exception e) {
2545                         try {
2546                                 value = (Integer)settings.value("customSameTagWeight", 2);
2547                         } catch (Exception e1) {
2548                                 value = 2;
2549                         }
2550                 }
2551                 settings.endGroup();
2552                 return value;
2553     }
2554         public static void saveCustomSameTagWeight(int weight) {
2555                 settings.beginGroup("RensoNoteList");
2556                 settings.setValue("customSameTagWeight", weight);
2557                 settings.endGroup();
2558         }
2559         // 連想ノートリスト重み付けモード:カスタムの設定値(同じノートブック)
2560     public static int customSameNotebookWeight() {
2561                 settings.beginGroup("RensoNoteList");
2562                 Integer value;
2563                 try {
2564                         String val  = (String)settings.value("customSameNotebookWeight", 2);
2565                         value = new Integer(val.trim());
2566                 } catch (Exception e) {
2567                         try {
2568                                 value = (Integer)settings.value("customSameNotebookWeight", 2);
2569                         } catch (Exception e1) {
2570                                 value = 2;
2571                         }
2572                 }
2573                 settings.endGroup();
2574                 return value;
2575     }
2576         public static void saveCustomSameNotebookWeight(int weight) {
2577                 settings.beginGroup("RensoNoteList");
2578                 settings.setValue("customSameNotebookWeight", weight);
2579                 settings.endGroup();
2580         }
2581         // 連想ノートリスト重み付けモード:カスタムの設定値(Evernote関連ノート)
2582     public static int customENRelatedNotesWeight() {
2583                 settings.beginGroup("RensoNoteList");
2584                 Integer value;
2585                 try {
2586                         String val  = (String)settings.value("customENRelatedNotesWeight", 5);
2587                         value = new Integer(val.trim());
2588                 } catch (Exception e) {
2589                         try {
2590                                 value = (Integer)settings.value("customENRelatedNotesWeight", 5);
2591                         } catch (Exception e1) {
2592                                 value = 5;
2593                         }
2594                 }
2595                 settings.endGroup();
2596                 return value;
2597     }
2598         public static void saveCustomENRelatedNotesWeight(int weight) {
2599                 settings.beginGroup("RensoNoteList");
2600                 settings.setValue("customENRelatedNotesWeight", weight);
2601                 settings.endGroup();
2602         }
2603
2604         // ツールバーの「新規」ボタンを押した時、新規ノートをタブで開くかどうか
2605         public static boolean toolBarNewAction() {
2606                 settings.beginGroup("General");
2607                 try {
2608                         String text = (String)settings.value("toolBarNewAction", "true");
2609                         settings.endGroup();
2610                         if (text.equalsIgnoreCase("true"))
2611                                 return true;
2612                         else
2613                                 return false;
2614                 } catch (java.lang.ClassCastException e) {
2615                         Boolean value = (Boolean) settings.value("toolBarNewAction", true);
2616                         settings.endGroup();
2617                         return value;
2618                 }
2619         }
2620         public static void setToolBarNewAction(boolean value) {
2621                 settings.beginGroup("General");
2622                 settings.setValue("toolBarNewAction", value);
2623                 settings.endGroup();    
2624         }
2625         
2626         // 全文検索の範囲
2627         public static SearchTarget searchTarget() {
2628                 settings.beginGroup("General");
2629                 try {
2630                         String text = (String)settings.value("searchTarget", "0");
2631                         settings.endGroup();
2632                         int ordinal = Integer.parseInt(text);
2633                         SearchTarget target = fromOrdinal(SearchTarget.class, ordinal);
2634                         return target;
2635                 } catch (java.lang.ClassCastException e) {
2636                         int value = (Integer) settings.value("searchTarget", 0);
2637                         settings.endGroup();;
2638                         SearchTarget target = fromOrdinal(SearchTarget.class, value);
2639                         return target;
2640                 }
2641         }
2642         
2643         public static void setSearchTarget(SearchTarget target) {
2644                 settings.beginGroup("General");
2645                 settings.setValue("searchTarget", target.ordinal());
2646                 settings.endGroup();
2647         }
2648 }
2649