OSDN Git Service

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