OSDN Git Service

リリースノートの日本語が文字化けしていたのを修正。
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / NeverNote.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 package cx.fbn.nevernote;
21 import java.awt.Desktop;
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.io.FileNotFoundException;
25 import java.io.FileOutputStream;
26 import java.net.Authenticator;
27 import java.net.PasswordAuthentication;
28 import java.security.MessageDigest;
29 import java.security.NoSuchAlgorithmException;
30 import java.sql.Connection;
31 import java.sql.DriverManager;
32 import java.sql.SQLException;
33 import java.sql.Statement;
34 import java.text.SimpleDateFormat;
35 import java.util.ArrayList;
36 import java.util.Calendar;
37 import java.util.Collection;
38 import java.util.Collections;
39 import java.util.Comparator;
40 import java.util.Date;
41 import java.util.GregorianCalendar;
42 import java.util.HashMap;
43 import java.util.Iterator;
44 import java.util.List;
45 import java.util.SortedMap;
46 import java.util.Vector;
47
48 import org.apache.log4j.Level;
49 import org.apache.log4j.Logger;
50 import org.apache.thrift.TException;
51 import org.h2.tools.ChangeFileEncryption;
52
53 import com.evernote.edam.error.EDAMNotFoundException;
54 import com.evernote.edam.error.EDAMSystemException;
55 import com.evernote.edam.error.EDAMUserException;
56 import com.evernote.edam.notestore.NoteFilter;
57 import com.evernote.edam.notestore.NoteVersionId;
58 import com.evernote.edam.type.Data;
59 import com.evernote.edam.type.LinkedNotebook;
60 import com.evernote.edam.type.Note;
61 import com.evernote.edam.type.NoteAttributes;
62 import com.evernote.edam.type.Notebook;
63 import com.evernote.edam.type.Publishing;
64 import com.evernote.edam.type.QueryFormat;
65 import com.evernote.edam.type.Resource;
66 import com.evernote.edam.type.SavedSearch;
67 import com.evernote.edam.type.Tag;
68 import com.evernote.edam.type.User;
69 import com.trolltech.qt.QThread;
70 import com.trolltech.qt.core.QByteArray;
71 import com.trolltech.qt.core.QDateTime;
72 import com.trolltech.qt.core.QDir;
73 import com.trolltech.qt.core.QEvent;
74 import com.trolltech.qt.core.QFile;
75 import com.trolltech.qt.core.QFileInfo;
76 import com.trolltech.qt.core.QFileSystemWatcher;
77 import com.trolltech.qt.core.QIODevice;
78 import com.trolltech.qt.core.QIODevice.OpenModeFlag;
79 import com.trolltech.qt.core.QLocale;
80 import com.trolltech.qt.core.QMimeData;
81 import com.trolltech.qt.core.QModelIndex;
82 import com.trolltech.qt.core.QSize;
83 import com.trolltech.qt.core.QTemporaryFile;
84 import com.trolltech.qt.core.QTextCodec;
85 import com.trolltech.qt.core.QTextStream;
86 import com.trolltech.qt.core.QThreadPool;
87 import com.trolltech.qt.core.QTimer;
88 import com.trolltech.qt.core.QTranslator;
89 import com.trolltech.qt.core.QUrl;
90 import com.trolltech.qt.core.Qt;
91 import com.trolltech.qt.core.Qt.BGMode;
92 import com.trolltech.qt.core.Qt.DockWidgetArea;
93 import com.trolltech.qt.core.Qt.ItemDataRole;
94 import com.trolltech.qt.core.Qt.KeyboardModifier;
95 import com.trolltech.qt.core.Qt.MouseButton;
96 import com.trolltech.qt.core.Qt.SortOrder;
97 import com.trolltech.qt.core.Qt.WidgetAttribute;
98 import com.trolltech.qt.gui.QAbstractItemView;
99 import com.trolltech.qt.gui.QAbstractItemView.ScrollHint;
100 import com.trolltech.qt.gui.QAction;
101 import com.trolltech.qt.gui.QApplication;
102 import com.trolltech.qt.gui.QClipboard;
103 import com.trolltech.qt.gui.QCloseEvent;
104 import com.trolltech.qt.gui.QColor;
105 import com.trolltech.qt.gui.QComboBox;
106 import com.trolltech.qt.gui.QCursor;
107 import com.trolltech.qt.gui.QDesktopServices;
108 import com.trolltech.qt.gui.QDialog;
109 import com.trolltech.qt.gui.QDockWidget;
110 import com.trolltech.qt.gui.QFileDialog;
111 import com.trolltech.qt.gui.QFileDialog.AcceptMode;
112 import com.trolltech.qt.gui.QFileDialog.FileMode;
113 import com.trolltech.qt.gui.QGridLayout;
114 import com.trolltech.qt.gui.QHBoxLayout;
115 import com.trolltech.qt.gui.QIcon;
116 import com.trolltech.qt.gui.QImage;
117 import com.trolltech.qt.gui.QKeySequence;
118 import com.trolltech.qt.gui.QLabel;
119 import com.trolltech.qt.gui.QListWidgetItem;
120 import com.trolltech.qt.gui.QMainWindow;
121 import com.trolltech.qt.gui.QMenu;
122 import com.trolltech.qt.gui.QMessageBox;
123 import com.trolltech.qt.gui.QMessageBox.StandardButton;
124 import com.trolltech.qt.gui.QPainter;
125 import com.trolltech.qt.gui.QPalette.ColorRole;
126 import com.trolltech.qt.gui.QPixmap;
127 import com.trolltech.qt.gui.QPrintDialog;
128 import com.trolltech.qt.gui.QPrinter;
129 import com.trolltech.qt.gui.QShortcut;
130 import com.trolltech.qt.gui.QSizePolicy;
131 import com.trolltech.qt.gui.QSizePolicy.Policy;
132 import com.trolltech.qt.gui.QSpinBox;
133 import com.trolltech.qt.gui.QSplashScreen;
134 import com.trolltech.qt.gui.QSplitter;
135 import com.trolltech.qt.gui.QStatusBar;
136 import com.trolltech.qt.gui.QSystemTrayIcon;
137 import com.trolltech.qt.gui.QTableWidgetItem;
138 import com.trolltech.qt.gui.QTextEdit;
139 import com.trolltech.qt.gui.QToolBar;
140 import com.trolltech.qt.gui.QTreeWidgetItem;
141 import com.trolltech.qt.network.QNetworkAccessManager;
142 import com.trolltech.qt.network.QNetworkProxy;
143 import com.trolltech.qt.network.QNetworkProxy.ProxyType;
144 import com.trolltech.qt.network.QNetworkReply;
145 import com.trolltech.qt.network.QNetworkRequest;
146 import com.trolltech.qt.webkit.QWebPage.WebAction;
147 import com.trolltech.qt.webkit.QWebSettings;
148
149 import cx.fbn.nevernote.config.InitializationException;
150 import cx.fbn.nevernote.config.StartupConfig;
151 import cx.fbn.nevernote.dialog.AccountDialog;
152 import cx.fbn.nevernote.dialog.ConfigDialog;
153 import cx.fbn.nevernote.dialog.DBEncryptDialog;
154 import cx.fbn.nevernote.dialog.DatabaseLoginDialog;
155 import cx.fbn.nevernote.dialog.DatabaseStatus;
156 import cx.fbn.nevernote.dialog.FindDialog;
157 import cx.fbn.nevernote.dialog.IgnoreSync;
158 import cx.fbn.nevernote.dialog.LogFileDialog;
159 import cx.fbn.nevernote.dialog.NotebookArchive;
160 import cx.fbn.nevernote.dialog.NotebookEdit;
161 import cx.fbn.nevernote.dialog.OnlineNoteHistory;
162 import cx.fbn.nevernote.dialog.PublishNotebook;
163 import cx.fbn.nevernote.dialog.SavedSearchEdit;
164 import cx.fbn.nevernote.dialog.SetIcon;
165 import cx.fbn.nevernote.dialog.ShareNotebook;
166 import cx.fbn.nevernote.dialog.SharedNotebookSyncError;
167 import cx.fbn.nevernote.dialog.StackNotebook;
168 import cx.fbn.nevernote.dialog.SynchronizationRequiredWarning;
169 import cx.fbn.nevernote.dialog.TagEdit;
170 import cx.fbn.nevernote.dialog.TagMerge;
171 import cx.fbn.nevernote.dialog.ThumbnailViewer;
172 import cx.fbn.nevernote.dialog.UpgradeAvailableDialog;
173 import cx.fbn.nevernote.dialog.WatchFolder;
174 import cx.fbn.nevernote.evernote.NoteMetadata;
175 import cx.fbn.nevernote.filters.FilterEditorNotebooks;
176 import cx.fbn.nevernote.filters.FilterEditorTags;
177 import cx.fbn.nevernote.gui.AttributeTreeWidget;
178 import cx.fbn.nevernote.gui.BrowserWindow;
179 import cx.fbn.nevernote.gui.DateAttributeFilterTable;
180 import cx.fbn.nevernote.gui.ExternalBrowse;
181 import cx.fbn.nevernote.gui.MainMenuBar;
182 import cx.fbn.nevernote.gui.NotebookTreeWidget;
183 import cx.fbn.nevernote.gui.RensoNoteList;
184 import cx.fbn.nevernote.gui.SavedSearchTreeWidget;
185 import cx.fbn.nevernote.gui.SearchPanel;
186 import cx.fbn.nevernote.gui.TabBrowse;
187 import cx.fbn.nevernote.gui.TabBrowserWidget;
188 import cx.fbn.nevernote.gui.TableView;
189 import cx.fbn.nevernote.gui.TagTreeWidget;
190 import cx.fbn.nevernote.gui.Thumbnailer;
191 import cx.fbn.nevernote.gui.TrashTreeWidget;
192 import cx.fbn.nevernote.gui.controls.QuotaProgressBar;
193 import cx.fbn.nevernote.neighbornote.ClipBoardObserver;
194 import cx.fbn.nevernote.oauth.OAuthTokenizer;
195 import cx.fbn.nevernote.oauth.OAuthWindow;
196 import cx.fbn.nevernote.sql.DatabaseConnection;
197 import cx.fbn.nevernote.sql.WatchFolderRecord;
198 import cx.fbn.nevernote.threads.IndexRunner;
199 import cx.fbn.nevernote.threads.SyncRunner;
200 import cx.fbn.nevernote.threads.ThumbnailRunner;
201 import cx.fbn.nevernote.utilities.AESEncrypter;
202 import cx.fbn.nevernote.utilities.ApplicationLogger;
203 import cx.fbn.nevernote.utilities.FileImporter;
204 import cx.fbn.nevernote.utilities.FileUtils;
205 import cx.fbn.nevernote.utilities.ListManager;
206 import cx.fbn.nevernote.utilities.SyncTimes;
207 import cx.fbn.nevernote.xml.ExportData;
208 import cx.fbn.nevernote.xml.ImportData;
209 import cx.fbn.nevernote.xml.ImportEnex;
210 import cx.fbn.nevernote.xml.NoteFormatter;
211
212
213 public class NeverNote extends QMainWindow{
214         
215         QStatusBar                              statusBar;                                      // Application status bar
216         
217         DatabaseConnection              conn;
218         
219         MainMenuBar                             menuBar;                                        // Main menu bar
220         FindDialog                              find;                                           // Text search in note dialog
221         List<String>                    emitLog;                                        // Messages displayed in the status bar;
222         QSystemTrayIcon                 trayIcon;                                       // little tray icon
223         QMenu                                   trayMenu;                                       // System tray menu
224         QAction                                 trayExitAction;                         // Exit the application
225         QAction                                 trayShowAction;                         // toggle the show/hide action          
226         QAction                                 trayAddNoteAction;                      // Add a note from the system tray
227         QNetworkAccessManager   versionChecker;                         // Used when checking for new versions
228         
229     NotebookTreeWidget          notebookTree;                           // List of notebooks
230     AttributeTreeWidget         attributeTree;                          // List of note attributes
231     TagTreeWidget                       tagTree;                                        // list of user created tags
232     SavedSearchTreeWidget       savedSearchTree;                        // list of saved searches
233     TrashTreeWidget                     trashTree;                                      // Trashcan
234     TableView                           noteTableView;                          //      List of notes (the widget).
235
236     public BrowserWindow        browserWindow;                          // Window containing browser & labels
237     public QToolBar             toolBar;                                        // The tool bar under the menu
238     QComboBox                           searchField;                            // search filter bar on the toolbar;
239     QShortcut                           searchShortcut;                         // Shortcut to search bar
240     boolean                                     searchPerformed = false;        // Search was done?
241     QuotaProgressBar            quotaBar;                                       // The current quota usage
242     
243     ApplicationLogger           logger;
244     List<String>                        selectedNotebookGUIDs;          // List of notebook GUIDs
245     List<String>                        selectedTagGUIDs;                       // List of selected tag GUIDs
246     List<String>                        selectedNoteGUIDs;                      // List of selected notes
247     String                                      selectedSavedSearchGUID;        // Currently selected saved searches
248     private final HashMap<String, ExternalBrowse>       externalWindows;        // Notes being edited by an external window;
249     
250     NoteFilter                          filter;                                         // Note filter
251     String                                      currentNoteGuid;                        // GUID of the current note 
252     Note                                        currentNote;                            // The currently viewed note
253     // ICHANGED
254     HashMap<Integer, Boolean>   noteDirty;                              // Has the note been changed?
255     HashMap<Integer, Boolean>   inkNote;                // if this is an ink note, it is read only
256     HashMap<Integer, Boolean>   readOnly;                               // Is this note read-only?
257         
258   
259     ListManager                         listManager;                                    // DB runnable task
260     
261     List<QTemporaryFile>        tempFiles;                                      // Array of temporary files;
262     
263     QTimer                                      indexTimer;                                     // timer to start the index thread
264     IndexRunner                         indexRunner;                            // thread to index notes
265     QThread                                     indexThread;
266     
267     QTimer                                      syncTimer;                                      // Sync on an interval
268     QTimer                                      syncDelayTimer;                         // Sync delay to free up database
269     SyncRunner                          syncRunner;                                     // thread to do a sync.
270     QThread                                     syncThread;                                     // Thread which talks to evernote
271     ThumbnailRunner                     thumbnailRunner;                        // Runner for thumbnail thread
272     QThread                                     thumbnailThread;                        // Thread that generates pretty pictures
273     QTimer                                      saveTimer;                                      // Timer to save note contents
274     
275     QTimer                                      authTimer;                                      // Refresh authentication
276     QTimer                                      externalFileSaveTimer;          // Save files altered externally
277     QTimer                                      thumbnailTimer;                         // Wakeup & scan for thumbnails
278     QTimer                                      debugTimer;
279     List<String>                        externalFiles;                          // External files to save later
280     List<String>                        importFilesKeep;                        // Auto-import files to save later
281     List<String>                        importFilesDelete;                      // Auto-import files to save later
282     
283     int                                         indexTime;                                      // how often to try and index
284     boolean                                     indexRunning;                           // Is indexing running?
285     boolean                                     indexDisabled;                          // Is indexing disabled?
286     
287     int                                         syncThreadsReady;                       // number of sync threads that are free
288     int                                         syncTime;                                       // Sync interval
289     boolean                                     syncRunning;                            // Is sync running?
290     boolean                                     automaticSync;                          // do sync automatically?
291     QTreeWidgetItem                     attributeTreeSelected;
292
293     QAction                             prevButton;                                     // Go to the previous item viewed
294     QAction                             nextButton;                                     // Go to the next item in the history
295     QAction                             downButton;                                     // Go to the next item in the list
296     QAction                             upButton;                                       // Go to the prev. item in the list;
297     QAction                             synchronizeButton;                      // Synchronize with Evernote
298     QAction                             allNotesButton;                         // Reset & view all notes
299     QTimer                              synchronizeAnimationTimer;      // Timer to change animation button
300     int                                 synchronizeIconAngle;           // Used to rotate sync icon
301     QAction                     printButton;                            // Print Button
302     QAction                             tagButton;                                      // Tag edit button
303     QAction                             attributeButton;                        // Attribute information button
304     QAction                     emailButton;                            // Email button
305     QAction                     deleteButton;                           // Delete button
306     QAction                             newButton;                                      // new Note Button;
307     QSpinBox                    zoomSpinner;                            // Zoom zoom
308     QAction                             searchClearButton;                      // Clear the search field
309     
310     SearchPanel                 searchLayout;                           // Widget to hold search field, zoom, & quota
311     
312     QSplitter                   mainLeftRightSplitter;          // main splitter for left/right side
313     QSplitter                   leftSplitter1;                          // first left hand splitter
314     QSplitter                   browserIndexSplitter;           // splitter between note index & note text
315     
316     QFileSystemWatcher  importKeepWatcher;                      // Watch & keep auto-import
317     QFileSystemWatcher  importDeleteWatcher;            // Watch & Delete auto-import
318     List<String>                importedFiles;                          // History of imported files (so we don't import twice)
319     
320     OnlineNoteHistory   historyWindow;                          // online history window 
321     List<NoteVersionId> versions;                                       // history versions
322     
323     QTimer                              threadMonitorTimer;                     // Timer to watch threads.
324     int                                 dbThreadDeadCount=0;            // number of consecutive dead times for the db thread
325     int                                 syncThreadDeadCount=0;          // number of consecutive dead times for the sync thread
326     int                                 indexThreadDeadCount=0;         // number of consecutive dead times for the index thread
327     int                                 notebookThreadDeadCount=0;      // number of consecutive dead times for the notebook thread
328     int                                 tagDeadCount=0;                         // number of consecutive dead times for the tag thread
329     int                                 trashDeadCount=0;                       // number of consecutive dead times for the trash thread
330     int                                 saveThreadDeadCount=0;          // number of consecutive dead times for the save thread
331     boolean                             disableTagThreadCheck=false;
332     boolean                             disableNotebookThreadCheck=false;
333     boolean                             disableTrashThreadCheck=false;
334     boolean                             disableSaveThreadCheck=false;
335     boolean                             disableSyncThreadCheck=false;
336     boolean                             disableIndexThreadCheck=false;
337     
338     HashMap<String, String>             noteCache;                      // Cash of note content 
339     HashMap<String, Boolean>    readOnlyCache;          // List of cashe notes that are read-only
340     HashMap<String, Boolean>    inkNoteCache;           // List of cache notes that are ink notes 
341         // ICHANGED
342         HashMap<Integer, ArrayList<String>> historyGuids;  // タブごとの以前見たノートのGUID
343         HashMap<Integer, Integer> historyPosition; // Position within the viewed items
344         HashMap<Integer, Boolean> fromHistory; // Is this from the history queue?
345         
346     String                              trashNoteGuid;                          // Guid to restore / set into or out of trash to save position
347     List<Thumbnailer>   thumbGenerators;                                // generate preview image
348     ThumbnailViewer             thumbnailViewer;                        // View preview thumbnail; 
349     boolean                             encryptOnShutdown;                      // should I encrypt when I close?
350     boolean                             decryptOnShutdown;                      // should I decrypt on shutdown;
351     String                              encryptCipher;                          // What cipher should I use?
352     //Signal0                   minimizeToTray;
353     boolean                             windowMaximized = false;        // Keep track of the window state for restores
354     List<String>                pdfReadyQueue;                          // Queue of PDFs that are ready to be rendered.
355     List<QPixmap>               syncIcons;                                      // Array of icons used in sync animation
356     private boolean             closeAction = false;            // Used to say when to close or when to minimize
357     private static Logger log = Logger.getLogger(NeverNote.class); 
358     private String              saveLastPath;                           // last path we used
359     private final QTimer                messageTimer;                           // Timer to clear the status message.
360     private QTimer              blockTimer;
361     BrowserWindow               blockingWindow;
362     
363         // ICHANGED
364         private final TabBrowserWidget tabBrowser; // ブラウザウィンドウをタブ化
365         private final HashMap<Integer, TabBrowse> tabWindows; // タブウィンドウ
366         private final RensoNoteList rensoNoteList; // 連想ノートリスト
367         private final QDockWidget rensoNoteListDock; // 連想ノートリストドックウィジェット
368         ClipBoardObserver cbObserver;
369         String rensoNotePressedItemGuid;
370         
371     String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
372         
373         
374     //***************************************************************
375     //***************************************************************
376     //** Constructor & main entry point
377     //***************************************************************
378     //***************************************************************
379     // Application Constructor  
380         @SuppressWarnings("static-access")
381         public NeverNote(DatabaseConnection dbConn)  {
382                 // ICHANGED
383                 cbObserver = new ClipBoardObserver();
384                 
385                 conn = dbConn;          
386                 if (conn.getConnection() == null) {
387                         String msg = new String(tr("Unable to connect to the database.\n\nThe most probable reason is that some other process\n" +
388                                 "is accessing the database or NeighborNote is already running.\n\n" +
389                                 "Please end any other process or shutdown the other NeighborNote before starting.\n\nExiting program."));
390                         
391             QMessageBox.critical(null, tr("Database Connection Error") ,msg);
392                         System.exit(16);
393                 }
394                 setObjectName("mainWindow");
395 //              thread().setPriority(Thread.MAX_PRIORITY);
396                 
397                 logger = new ApplicationLogger("nevernote.log");
398                 logger.log(logger.HIGH, "Starting Application");
399                 
400                 decryptOnShutdown = false;
401                 encryptOnShutdown = false;
402                 conn.checkDatabaseVersion();
403                 
404                 
405                 
406                 // Start building the invalid XML tables
407                 Global.invalidElements = conn.getInvalidXMLTable().getInvalidElements();
408                 List<String> elements = conn.getInvalidXMLTable().getInvalidAttributeElements();
409                 
410                 for (int i=0; i<elements.size(); i++) {
411                         Global.invalidAttributes.put(elements.get(i), conn.getInvalidXMLTable().getInvalidAttributes(elements.get(i)));
412                 }
413                 
414                 logger.log(logger.EXTREME, "Starting GUI build");
415
416                 QTranslator nevernoteTranslator = new QTranslator();
417                 nevernoteTranslator.load(Global.getFileManager().getTranslateFilePath("nevernote_" + QLocale.system().name() + ".qm"));
418                 QApplication.instance().installTranslator(nevernoteTranslator);
419
420                 Global.originalPalette = QApplication.palette();
421                 QApplication.setStyle(Global.getStyle());
422                 if (Global.useStandardPalette())
423                         QApplication.setPalette(QApplication.style().standardPalette());
424         setWindowTitle(tr("NeighborNote"));
425
426         mainLeftRightSplitter = new QSplitter();
427                 // ICHANGED
428                 mainLeftRightSplitter.setOrientation(Qt.Orientation.Horizontal);
429                 
430         setCentralWidget(mainLeftRightSplitter);
431         leftSplitter1 = new QSplitter();
432         leftSplitter1.setOrientation(Qt.Orientation.Vertical);
433                 
434         browserIndexSplitter = new QSplitter();
435         browserIndexSplitter.setOrientation(Qt.Orientation.Vertical);
436         
437         //* Setup threads & thread timers
438 //        int indexRunnerCount = Global.getIndexThreads();
439 //       indexRunnerCount = 1;
440         QThreadPool.globalInstance().setMaxThreadCount(Global.threadCount);     // increase max thread count
441
442                 logger.log(logger.EXTREME, "Building list manager");
443         listManager = new ListManager(conn, logger);
444         
445                 logger.log(logger.EXTREME, "Building index runners & timers");
446                 // ICHANGED Global.getBehaviorDatabaseUrl()を追加
447                 indexRunner = new IndexRunner("indexRunner.log",
448                                 Global.getDatabaseUrl(), Global.getIndexDatabaseUrl(),
449                                 Global.getResourceDatabaseUrl(),
450                                 Global.getBehaviorDatabaseUrl(), Global.getDatabaseUserid(),
451                                 Global.getDatabaseUserPassword(), Global.cipherPassword);
452                 
453                 indexThread = new QThread(indexRunner, "Index Thread");
454         indexRunner.indexAttachmentsLocally = Global.indexAttachmentsLocally();
455         indexRunner.indexImageRecognition = Global.indexImageRecognition();
456         indexRunner.indexNoteBody = Global.indexNoteBody();
457         indexRunner.indexNoteTitle = Global.indexNoteTitle();
458         indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
459                 indexThread.start();
460                 
461         synchronizeAnimationTimer = new QTimer();
462         synchronizeAnimationTimer.timeout.connect(this, "updateSyncButton()");
463         
464                 indexTimer = new QTimer();
465                 indexTime = 1000*Global.getIndexThreadSleepInterval();  
466                 indexTimer.start(indexTime);  // Start indexing timer
467                 indexTimer.timeout.connect(this, "indexTimer()");
468                 indexDisabled = false;
469                 indexRunning = false;
470                                 
471                 logger.log(logger.EXTREME, "Setting sync thread & timers");
472                 syncThreadsReady=1;
473                 // ICHANGED Global.getBehaviorDatabaseUrl()を追加
474                 syncRunner = new SyncRunner("syncRunner.log", Global.getDatabaseUrl(),
475                                 Global.getIndexDatabaseUrl(), Global.getResourceDatabaseUrl(),
476                                 Global.getBehaviorDatabaseUrl(), Global.getDatabaseUserid(),
477                                 Global.getDatabaseUserPassword(), Global.cipherPassword);
478                 
479                 syncTime = new SyncTimes().timeValue(Global.getSyncInterval());
480                 syncTimer = new QTimer();
481                 syncTimer.timeout.connect(this, "syncTimer()");
482         syncRunner.status.message.connect(this, "setMessage(String)");
483         syncRunner.syncSignal.finished.connect(this, "syncThreadComplete(Boolean)");
484         syncRunner.syncSignal.errorDisconnect.connect(this, "remoteErrorDisconnect()");
485         syncRunning = false;    
486                 if (syncTime > 0) {
487                         automaticSync = true;
488                         syncTimer.start(syncTime*60*1000);
489                 } else {
490                         automaticSync = false;
491                         syncTimer.stop();
492                 }
493                 syncRunner.setEvernoteUpdateCount(Global.getEvernoteUpdateCount());
494                 syncThread = new QThread(syncRunner, "Synchronization Thread");
495                 syncThread.start();
496                 
497                 
498                 logger.log(logger.EXTREME, "Starting thumnail thread");
499                 pdfReadyQueue = new ArrayList<String>();
500                 // ICHANGED Global.getBehaviorDatabaseUrl()を追加
501                 thumbnailRunner = new ThumbnailRunner("thumbnailRunner.log",
502                                 Global.getDatabaseUrl(), Global.getIndexDatabaseUrl(),
503                                 Global.getResourceDatabaseUrl(),
504                                 Global.getBehaviorDatabaseUrl(), Global.getDatabaseUserid(),
505                                 Global.getDatabaseUserPassword(), Global.cipherPassword);
506                 
507                 thumbnailThread = new QThread(thumbnailRunner, "Thumbnail Thread");
508                 thumbnailRunner.noteSignal.thumbnailPageReady.connect(this, "thumbnailHTMLReady(String,QByteArray,Integer)");
509                 thumbnailThread.start();
510                 thumbGenerators = new ArrayList<Thumbnailer>();
511                 thumbnailTimer = new QTimer();
512                 thumbnailTimer.timeout.connect(this, "thumbnailTimer()");
513                 thumbnailTimer();
514                 thumbnailTimer.setInterval(500*1000);  // Thumbnail every minute
515                 thumbnailTimer.start();
516                 
517 //              debugTimer = new QTimer();
518 //              debugTimer.timeout.connect(this, "debugDirty()");
519 //              debugTimer.start(1000*60);
520                 
521                 logger.log(logger.EXTREME, "Starting authentication timer");
522                 authTimer = new QTimer();
523                 authTimer.timeout.connect(this, "authTimer()");
524                 authTimer.start(1000*60*15);
525                 syncRunner.syncSignal.authRefreshComplete.connect(this, "authRefreshComplete(boolean)");
526                 
527                 logger.log(logger.EXTREME, "Setting save note timer");
528                 saveTimer = new QTimer();
529                 saveTimer.timeout.connect(this, "saveNote()");
530                 if (Global.getAutoSaveInterval() > 0) {
531                         saveTimer.setInterval(1000*60*Global.getAutoSaveInterval()); 
532                         saveTimer.start();
533                 }
534                 listManager.saveRunner.noteSignals.noteSaveRunnerError.connect(this, "saveRunnerError(String, String)");
535                 
536                 logger.log(logger.EXTREME, "Starting external file monitor timer");
537                 externalFileSaveTimer = new QTimer();
538                 externalFileSaveTimer.timeout.connect(this, "externalFileEditedSaver()");
539                 externalFileSaveTimer.setInterval(1000*5);   // save every 5 seconds;
540                 externalFiles = new ArrayList<String>();
541                 importFilesDelete = new ArrayList<String>();
542                 importFilesKeep = new ArrayList<String>();
543                 externalFileSaveTimer.start();
544                 
545         notebookTree = new NotebookTreeWidget(conn);
546         attributeTree = new AttributeTreeWidget();
547         tagTree = new TagTreeWidget(conn);
548         savedSearchTree = new SavedSearchTreeWidget();
549         trashTree = new TrashTreeWidget();
550                 // ICHANGED
551                 noteTableView = new TableView(logger, listManager, this);     
552         
553         searchField = new QComboBox();
554         searchField.setObjectName("searchField");
555         //setStyleSheet("QComboBox#searchField { background-color: yellow }");
556         searchField.setEditable(true);
557         searchField.activatedIndex.connect(this, "searchFieldChanged()");
558         searchField.setDuplicatesEnabled(false);
559         searchField.editTextChanged.connect(this,"searchFieldTextChanged(String)");
560         searchShortcut = new QShortcut(this);
561         setupShortcut(searchShortcut, "Focus_Search");
562         searchShortcut.activated.connect(this, "focusSearch()");
563         
564         quotaBar = new QuotaProgressBar();
565         // Setup the zoom
566         zoomSpinner = new QSpinBox();
567         zoomSpinner.setMinimum(10);
568         zoomSpinner.setMaximum(1000);
569         zoomSpinner.setAccelerated(true);
570         zoomSpinner.setSingleStep(10);
571         zoomSpinner.setValue(100);
572         zoomSpinner.valueChanged.connect(this, "zoomChanged()");
573         
574         searchLayout = new SearchPanel(searchField, quotaBar, notebookTree, zoomSpinner);
575         
576         
577         QGridLayout leftGrid = new QGridLayout();
578         leftSplitter1.setContentsMargins(5, 0, 0, 7);
579         leftSplitter1.setLayout(leftGrid);
580         leftGrid.addWidget(searchLayout,1,1);
581         leftGrid.addWidget(tagTree,2,1);
582         leftGrid.addWidget(attributeTree,3,1);
583         leftGrid.addWidget(savedSearchTree,4,1);
584         leftGrid.addWidget(trashTree,5, 1);
585         
586         // Setup the browser window
587         noteCache = new HashMap<String,String>();
588         readOnlyCache = new HashMap<String, Boolean>();
589         inkNoteCache = new HashMap<String, Boolean>();
590         // ICHANGED
591         browserWindow = new BrowserWindow(conn, cbObserver);
592
593                 // ICHANGED 下から移動してきた。
594                 historyGuids = new HashMap<Integer, ArrayList<String>>();
595                 historyPosition = new HashMap<Integer, Integer>();
596                 fromHistory = new HashMap<Integer, Boolean>();
597                 
598                 // ICHANGED タブブラウザ作成
599                 tabWindows = new HashMap<Integer, TabBrowse>();
600                 tabBrowser = new TabBrowserWidget(this);
601                 tabBrowser.setStyleSheet("QTabBar::tab{width:150px;}");
602                 tabBrowser.setMovable(true);
603                 TabBrowse tab = new TabBrowse(conn, tabBrowser, cbObserver);
604                 browserWindow = tab.getBrowserWindow();
605                 int index = tabBrowser.addNewTab(tab, "");
606                 tabWindows.put(index, tab);
607                 tabBrowser.setTabsClosable(true);
608                 tabBrowser.currentChanged.connect(this, "tabWindowChanged(int)");
609                 tabBrowser.tabCloseRequested.connect(this, "tabWindowClosing(int)");
610                 
611                 noteDirty = new HashMap<Integer, Boolean>();
612                 noteDirty.put(index, false);
613                 
614                 inkNote = new HashMap<Integer, Boolean>();
615                 readOnly = new HashMap<Integer, Boolean>();
616
617                 // ICHANGED
618                 // 履歴記録のハッシュマップを初期化
619                 historyGuids.put(index, new ArrayList<String>());
620                 historyPosition.put(index, 0);
621                 fromHistory.put(index, false);
622                 
623         mainLeftRightSplitter.addWidget(leftSplitter1);
624         mainLeftRightSplitter.addWidget(browserIndexSplitter);
625         
626                 // ICHANGED
627                 // 連想ノートリストをセットアップ
628                 rensoNoteList = new RensoNoteList(conn, this);
629                 rensoNoteList.itemPressed.connect(this,
630                                 "rensoNoteItemPressed(QListWidgetItem)");
631                 rensoNoteListDock = new QDockWidget(tr("Renso Note List"), this);
632                 rensoNoteListDock.setWidget(rensoNoteList);
633                 addDockWidget(DockWidgetArea.RightDockWidgetArea, rensoNoteListDock);
634
635                 if (Global.getListView() == Global.View_List_Wide) {
636                         browserIndexSplitter.addWidget(noteTableView);
637                         // ICHANGED
638                         browserIndexSplitter.addWidget(tabBrowser);
639                         // browserIndexSplitter.addWidget(browserWindow);
640                 } else {
641                         mainLeftRightSplitter.addWidget(noteTableView);
642                         // ICHANGED
643                         mainLeftRightSplitter.addWidget(tabBrowser);
644                         // mainLeftRightSplitter.addWidget(browserWindow);
645                 }
646         
647         // Setup the thumbnail viewer
648         thumbnailViewer = new ThumbnailViewer();
649         thumbnailViewer.upArrow.connect(this, "upAction()");
650         thumbnailViewer.downArrow.connect(this, "downAction()");
651         thumbnailViewer.leftArrow.connect(this, "nextViewedAction()");
652         thumbnailViewer.rightArrow.connect(this, "previousViewedAction()");
653         
654         //Setup external browser manager
655         externalWindows = new HashMap<String, ExternalBrowse>();
656
657         listManager.loadNotesIndex();
658         initializeNotebookTree();
659         initializeTagTree();
660         initializeSavedSearchTree();
661         attributeTree.itemClicked.connect(this, "attributeTreeClicked(QTreeWidgetItem, Integer)");
662         attributeTreeSelected = null;
663         initializeNoteTable();    
664
665                 selectedNoteGUIDs = new ArrayList<String>();
666                 statusBar = new QStatusBar();
667                 setStatusBar(statusBar);
668                 menuBar = new MainMenuBar(this);
669                 emitLog = new ArrayList<String>();
670                 
671                 tagTree.setDeleteAction(menuBar.tagDeleteAction);
672                 tagTree.setMergeAction(menuBar.tagMergeAction);
673                 tagTree.setEditAction(menuBar.tagEditAction);
674                 tagTree.setAddAction(menuBar.tagAddAction);
675                 tagTree.setIconAction(menuBar.tagIconAction);
676                 tagTree.setVisible(Global.isWindowVisible("tagTree"));
677                 leftSplitter1.setVisible(Global.isWindowVisible("leftPanel"));
678                 tagTree.noteSignal.tagsAdded.connect(this, "tagsAdded(String, String)");
679                 menuBar.hideTags.setChecked(Global.isWindowVisible("tagTree"));
680                 listManager.tagSignal.listChanged.connect(this, "reloadTagTree()");
681                 
682                 if (!Global.isWindowVisible("zoom")) {
683                         searchLayout.hideZoom();
684                         menuBar.hideZoom.setChecked(false);
685                 } 
686         
687                 notebookTree.setDeleteAction(menuBar.notebookDeleteAction);
688                 notebookTree.setEditAction(menuBar.notebookEditAction);
689                 notebookTree.setAddAction(menuBar.notebookAddAction);
690                 notebookTree.setIconAction(menuBar.notebookIconAction);
691                 notebookTree.setStackAction(menuBar.notebookStackAction);
692                 notebookTree.setPublishAction(menuBar.notebookPublishAction);
693                 notebookTree.setShareAction(menuBar.notebookShareAction);
694                 notebookTree.setVisible(Global.isWindowVisible("notebookTree"));
695                 notebookTree.noteSignal.notebookChanged.connect(this, "updateNoteNotebook(String, String)");
696                 notebookTree.noteSignal.tagsChanged.connect(this, "updateNoteTags(String, List)");
697             notebookTree.noteSignal.tagsChanged.connect(this, "updateListTags(String, List)");
698                 menuBar.hideNotebooks.setChecked(Global.isWindowVisible("notebookTree"));
699
700                 savedSearchTree.setAddAction(menuBar.savedSearchAddAction);
701                 savedSearchTree.setEditAction(menuBar.savedSearchEditAction);
702                 savedSearchTree.setDeleteAction(menuBar.savedSearchDeleteAction);
703                 savedSearchTree.setIconAction(menuBar.savedSearchIconAction);
704                 savedSearchTree.itemSelectionChanged.connect(this, "updateSavedSearchSelection()");
705                 savedSearchTree.setVisible(Global.isWindowVisible("savedSearchTree"));
706                 menuBar.hideSavedSearches.setChecked(Global.isWindowVisible("savedSearchTree"));
707                 
708                 // ICHANGED noteTableViewに新しいタブで開くを追加
709                 noteTableView.setOpenNewTabAction(menuBar.noteOpenNewTab);
710                         
711                 noteTableView.setAddAction(menuBar.noteAdd);
712                 
713                 // ICHANGED noteTableViewに新しいタブでノート追加を追加
714                 noteTableView.setAddNoteNewTabAction(menuBar.noteAddNewTab);
715                 
716                 noteTableView.setDeleteAction(menuBar.noteDelete);
717                 noteTableView.setRestoreAction(menuBar.noteRestoreAction);
718                 noteTableView.setNoteDuplicateAction(menuBar.noteDuplicateAction);
719                 noteTableView.setNoteHistoryAction(menuBar.noteOnlineHistoryAction);
720                 noteTableView.noteSignal.titleColorChanged.connect(this, "titleColorChanged(Integer)");
721                 noteTableView.noteSignal.notePinned.connect(this, "notePinned()");
722                 noteTableView.setMergeNotesAction(menuBar.noteMergeAction);
723                 noteTableView.setCopyAsUrlAction(menuBar.noteCopyAsUrlAction);
724                 noteTableView.doubleClicked.connect(this, "listDoubleClick()");
725                 listManager.trashSignal.countChanged.connect(trashTree, "updateCounts(Integer)");
726                 
727                 quotaBar.setMouseClickAction(menuBar.accountAction);
728                 
729                 trashTree.load();
730         trashTree.itemSelectionChanged.connect(this, "trashTreeSelection()");
731                 trashTree.setEmptyAction(menuBar.emptyTrashAction);
732                 trashTree.setVisible(Global.isWindowVisible("trashTree"));
733                 menuBar.hideTrash.setChecked(Global.isWindowVisible("trashTree"));
734                 trashTree.updateCounts(listManager.getTrashCount());
735                 attributeTree.setVisible(Global.isWindowVisible("attributeTree"));
736                 menuBar.hideAttributes.setChecked(Global.isWindowVisible("attributeTree"));
737
738                 noteTableView.setVisible(Global.isWindowVisible("noteList"));
739                 menuBar.hideNoteList.setChecked(Global.isWindowVisible("noteList"));
740                 
741                 if (!Global.isWindowVisible("editorButtonBar"))
742                         toggleEditorButtonBar();
743                 
744                 if (!Global.isWindowVisible("leftPanel"))
745                         menuBar.hideLeftSide.setChecked(true);
746                 if (Global.isWindowVisible("noteInformation"))
747                         toggleNoteInformation();
748                 quotaBar.setVisible(Global.isWindowVisible("quota"));
749                 // IFIXED quotaBar.isVisible() → Global.isWindowVisible("quota")
750                 // なぜかquotaBar.isVisible()が常にfalseを返すようなので修正
751                 if (!Global.isWindowVisible("quota"))
752                         menuBar.hideQuota.setChecked(false);
753                 
754                 searchField.setVisible(Global.isWindowVisible("searchField"));
755                 // IFIXED !searchField.isVisible() → !Global.isWindowVisible("searchField")
756                 // なぜかsearchField.isVisible()が常にfalseを返すようなので修正
757                 if (!Global.isWindowVisible("searchField"))
758                         menuBar.hideSearch.setChecked(false);
759                 
760                 if (searchField.isHidden() && quotaBar.isHidden() && zoomSpinner.isHidden() && notebookTree.isHidden())
761                         searchLayout.hide();
762                 
763                 setMenuBar(menuBar);
764                 setupToolBar();
765                 find = new FindDialog();
766                 find.getOkButton().clicked.connect(this, "doFindText()");
767                 
768                 // Setup the tray icon menu bar
769                 trayShowAction = new QAction(tr("Show/Hide"), this);
770                 trayExitAction = new QAction(tr("Exit"), this);
771                 trayAddNoteAction = new QAction(tr("Add Note"), this);
772                 
773                 trayExitAction.triggered.connect(this, "closeNeverNote()");
774                 trayAddNoteAction.triggered.connect(this, "addNote()");
775                 trayShowAction.triggered.connect(this, "trayToggleVisible()");
776                 
777                 trayMenu = new QMenu(this);
778                 trayMenu.addAction(trayAddNoteAction);
779                 trayMenu.addAction(trayShowAction);
780                 trayMenu.addAction(trayExitAction);
781                 
782                 
783                 trayIcon = new QSystemTrayIcon(this);
784                 trayIcon.setToolTip(tr("NeighborNote"));
785                 trayIcon.setContextMenu(trayMenu);
786                 trayIcon.activated.connect(this, "trayActivated(com.trolltech.qt.gui.QSystemTrayIcon$ActivationReason)");
787
788                 currentNoteGuid="";
789                 currentNoteGuid = Global.getLastViewedNoteGuid();
790                 if (currentNoteGuid.equals(""))
791                         currentNote = new Note();
792                 
793                 // ICHANGED
794                 /* 上に移動したので要らない
795                 historyGuids = new ArrayList<String>();
796                 historyPosition = 0;
797                 fromHistory = false;
798                 */
799                 
800                 if (!currentNoteGuid.trim().equals("")) {
801                         currentNote = conn.getNoteTable().getNote(currentNoteGuid, true,true,false,false,true);
802                 }
803                 
804                 noteIndexUpdated(true);
805                 showColumns();
806                 menuBar.showEditorBar.setChecked(Global.isWindowVisible("editorButtonBar"));
807                 if (menuBar.showEditorBar.isChecked())
808                 showEditorButtons(browserWindow);
809                 tagIndexUpdated(true);
810                 savedSearchIndexUpdated();
811                 notebookIndexUpdated();
812                 updateQuotaBar();
813         setupSyncSignalListeners();        
814         setupBrowserSignalListeners();
815         setupIndexListeners();
816               
817         
818         tagTree.tagSignal.listChanged.connect(this, "tagIndexUpdated()");
819         tagTree.showAllTags(true);
820
821                 QIcon appIcon = new QIcon(iconPath+"nevernote.png");
822                 if (QSystemTrayIcon.isSystemTrayAvailable()) {
823                         setWindowIcon(appIcon);
824                         trayIcon.setIcon(appIcon);
825                         if (Global.showTrayIcon() || Global.minimizeOnClose())
826                                 trayIcon.show();
827                         else
828                                 trayIcon.hide();
829                 }
830         
831         scrollToGuid(currentNoteGuid);
832         if (Global.automaticLogin()) {
833                 remoteConnect();
834                 if (Global.isConnected)
835                         syncTimer();
836         }
837         setupFolderImports();
838         
839         loadStyleSheet();
840         restoreWindowState(true);
841         
842         if (Global.mimicEvernoteInterface) {
843                 notebookTree.selectGuid("");
844         }
845         
846         threadMonitorTimer = new QTimer();
847         threadMonitorTimer.timeout.connect(this, "threadMonitorCheck()");
848         threadMonitorTimer.start(1000*10);  // Check for threads every 10 seconds;              
849         
850                 // ICHANGED たぶんこれはいらない
851                 // IFIXED ?
852                 /*
853                 historyGuids.add(currentNoteGuid);
854                 historyPosition = 1;
855                 */
856         
857         menuBar.blockSignals(true);
858         menuBar.narrowListView.blockSignals(true);
859         menuBar.wideListView.blockSignals(true);
860         if (Global.getListView() == Global.View_List_Narrow) { 
861                 menuBar.narrowListView.setChecked(true);
862         }
863         else{ 
864                 menuBar.wideListView.setChecked(true);
865         }
866         menuBar.blockSignals(false);
867         menuBar.narrowListView.blockSignals(false);
868         menuBar.wideListView.blockSignals(false);
869         
870                 // IFIXED
871                 // 上に同じコードがあるよね? とりあえずコメントアウト
872                 /*
873                  * if (Global.getListView() == Global.View_List_Wide) {
874                  * browserIndexSplitter.addWidget(noteTableView); // ICHANGED //
875                  * browserIndexSplitter.addWidget(tabBrowser);
876                  * browserIndexSplitter.addWidget(browserWindow); } else {
877                  * mainLeftRightSplitter.addWidget(noteTableView); // ICHANGED //
878                  * mainLeftRightSplitter.addWidget(tabBrowser);
879                  * mainLeftRightSplitter.addWidget(browserWindow); }
880                  */
881         
882                 messageTimer = new QTimer();
883                 messageTimer.timeout.connect(this, "clearMessage()");
884                 messageTimer.setInterval(1000*15);
885                 clearMessage();
886         
887         int sortCol = Global.getSortColumn();
888                 int sortOrder = Global.getSortOrder();
889                 noteTableView.proxyModel.blocked = true;
890                 // We sort the table twice to fix a bug.  For some reaosn the table won't sort properly if it is in narrow
891                 // list view and sorted descending on the date  created.  By sorting it twice it forces the proper sort.  Ugly.
892                 if (sortCol == 0 && sortOrder == 1 && Global.getListView() == Global.View_List_Narrow) 
893                         noteTableView.sortByColumn(sortCol, SortOrder.resolve(0));   
894                 noteTableView.sortByColumn(sortCol, SortOrder.resolve(sortOrder));
895                 noteTableView.proxyModel.blocked = false;
896                 noteTableView.proxyModel.sortChanged.connect(this, "tableSortOrderChanged(Integer,Integer)");
897                 
898                 // Set the startup notebook
899         String defaultNotebook = Global.getStartupNotebook();
900         if (!defaultNotebook.equals("AllNotebooks") && !defaultNotebook.equals("")) {
901                 for (int k=0; k<listManager.getNotebookIndex().size(); k++) {
902                         if (listManager.getNotebookIndex().get(k).isDefaultNotebook()) {
903                                 notebookTree.clearSelection();
904                                 notebookTree.selectGuid(listManager.getNotebookIndex().get(k).getGuid());
905                                 notebookTree.selectionSignal.emit();
906                         }
907                 }
908         }
909                 
910                 if (Global.checkVersionUpgrade()) {
911                         // ICHANGED TODO とりあえず封印
912                         // checkForUpdates();
913                 }
914         }
915         
916         
917         public void debugDirty() {
918                 List<Note> dirty = conn.getNoteTable().getDirty();
919                 logger.log(logger.LOW, "------ Dirty Notes List Begin ------");
920                 for (int i=0; i<dirty.size(); i++) {
921                         logger.log(logger.LOW, "GUID: " +dirty.get(i).getGuid() + " Title:" + dirty.get(i).getTitle());
922                 }
923                 logger.log(logger.LOW, "------ Dirty Notes List End ------");
924         }
925                 
926         // Main entry point
927         public static void main(String[] args) {
928                 log.setLevel(Level.FATAL);
929                 QApplication.initialize(args);
930                 QPixmap pixmap = new QPixmap("classpath:cx/fbn/nevernote/icons/splash_logo.png");
931                 QSplashScreen splash = new QSplashScreen(pixmap);
932                 boolean showSplash;
933                 
934                 DatabaseConnection dbConn;
935
936         try {
937             initializeGlobalSettings(args);
938
939             showSplash = Global.isWindowVisible("SplashScreen");
940             if (showSplash)
941                 splash.show();
942
943             dbConn = setupDatabaseConnection();
944
945             // Must be last stage of setup - only safe once DB is open hence we know we are the only instance running
946             Global.getFileManager().purgeResDirectory(true);
947
948         } catch (InitializationException e) {
949             // Fatal
950             e.printStackTrace();
951             QMessageBox.critical(null, "Startup error", "Aborting: " + e.getMessage());
952             return;
953         }
954         
955                 // Setup proxy crap
956                 String proxyUrl = Global.getProxyValue("url");
957                 String proxyPort = Global.getProxyValue("port");
958                 String proxyUserid = Global.getProxyValue("userid");
959                 String proxyPassword = Global.getProxyValue("password");
960                 boolean proxySet = false;
961                 QNetworkProxy proxy = new QNetworkProxy();
962                 proxy.setType(ProxyType.HttpProxy);
963                 if (!proxyUrl.trim().equals("")) {
964                         System.out.println("Proxy URL found: " +proxyUrl);
965                         proxySet = true;
966                         proxy.setHostName(proxyUrl);
967                 }
968                 if (!proxyPort.trim().equals("")) {
969                         System.out.println("Proxy Port found: " +proxyPort);
970                         proxySet = true;
971                         proxy.setPort(Integer.parseInt(proxyPort));
972                 }
973                 if (!proxyUserid.trim().equals("")) {
974                         System.out.println("Proxy Userid found: " +proxyUserid);
975                         proxySet = true;
976                         proxy.setUser(proxyUserid);
977                 }
978                 if (!proxyPassword.trim().equals("")) {
979                         System.out.println("Proxy URL found: " +proxyPassword);
980                         proxySet = true;
981                         proxy.setPassword(proxyPassword);
982                 }
983                 if (proxySet) {
984                         QNetworkProxy.setApplicationProxy(proxy);
985                 }
986                         
987
988         NeverNote application = new NeverNote(dbConn);
989                 if (Global.syncOnly) {
990                         System.out.println("Performing synchronization only.");
991                         application.remoteConnect();
992                         if (Global.isConnected) {
993                                 application.syncRunner.syncNeeded = true;
994                                 application.syncRunner.addWork("SYNC");
995                                 application.syncRunner.addWork("STOP");
996                                 while(!application.syncRunner.isIdle());
997                                 application.closeNeverNote();
998                         }
999                         return;
1000                 }
1001
1002                 application.setAttribute(WidgetAttribute.WA_DeleteOnClose, true);
1003                 if (Global.startMinimized()) 
1004                         application.showMinimized();
1005                 else {
1006                         if (Global.wasWindowMaximized())
1007                                 application.showMaximized();
1008                         else
1009                                 application.show();
1010                 }
1011                 
1012                 if (showSplash)
1013                         splash.finish(application);
1014                 QApplication.exec();
1015                 System.out.println("Goodbye.");
1016                 QApplication.exit();
1017         }
1018
1019     /**
1020      * Open the internal database, or create if not present
1021      *
1022      * @throws InitializationException when opening the database fails, e.g. because another process has it locked
1023      */
1024     private static DatabaseConnection setupDatabaseConnection() throws InitializationException {
1025         ApplicationLogger logger = new ApplicationLogger("nevernote-database.log");
1026         
1027         File f = Global.getFileManager().getDbDirFile(Global.databaseName + ".h2.db");
1028         File fr = Global.getFileManager().getDbDirFile(Global.resourceDatabaseName + ".h2.db");
1029                 // IFIXED resourceDatabaseNameになっていたので修正
1030                 File fi = Global.getFileManager().getDbDirFile(Global.indexDatabaseName + ".h2.db");
1031                 // ICHANGED
1032                 File fb = Global.getFileManager().getDbDirFile(Global.behaviorDatabaseName + ".h2.db");
1033                                 
1034                 if (!f.exists())
1035                         Global.setDatabaseUrl("");
1036                 if (!fr.exists())
1037                         Global.setResourceDatabaseUrl("");              
1038                 if (!fi.exists())
1039                         Global.setIndexDatabaseUrl(""); 
1040                 // ICHANGED
1041                 if (!fb.exists())
1042                         Global.setBehaviorDatabaseUrl("");
1043         
1044         if (Global.getDatabaseUrl().toUpperCase().indexOf("CIPHER=") > -1) {
1045             boolean goodCheck = false;
1046             while (!goodCheck) {
1047                 DatabaseLoginDialog dialog = new DatabaseLoginDialog();
1048                 dialog.exec();
1049                 if (!dialog.okPressed())
1050                     System.exit(0);
1051                 Global.cipherPassword = dialog.getPassword();
1052                 goodCheck = databaseCheck(Global.getDatabaseUrl(), Global.getDatabaseUserid(),
1053                         Global.getDatabaseUserPassword(), Global.cipherPassword);
1054             }
1055         }
1056         // ICHANGED Global.getBehaviorDatabaserUrl()を追加
1057         DatabaseConnection dbConn = new DatabaseConnection(logger,Global.getDatabaseUrl(), 
1058                         Global.getIndexDatabaseUrl(), Global.getResourceDatabaseUrl(), Global.getBehaviorDatabaseUrl(),
1059                         Global.getDatabaseUserid(), Global.getDatabaseUserPassword(), Global.cipherPassword, 0);
1060        return dbConn;
1061     }
1062     
1063     // Encrypt the database upon shutdown
1064     private void encryptOnShutdown() {
1065         String dbPath= Global.getFileManager().getDbDirPath("");
1066         try {
1067                 
1068                 Statement st = conn.getConnection().createStatement();  
1069                 st.execute("shutdown");
1070                 st = conn.getResourceConnection().createStatement();
1071                 st.execute("shutdown");
1072                 st = conn.getIndexConnection().createStatement();
1073                 st.execute("shutdown");
1074                 // ICHANGED
1075                 st = conn.getBehaviorConnection().createStatement();
1076                 st.execute("shutdown");
1077                 
1078                 if (QMessageBox.question(this, tr("Are you sure"), 
1079                                 tr("Are you sure you wish to encrypt the database?"),
1080                                 QMessageBox.StandardButton.Yes, 
1081                                 QMessageBox.StandardButton.No) == StandardButton.Yes.value()) {
1082                         ChangeFileEncryption.execute(dbPath, "NeverNote", encryptCipher, null, Global.cipherPassword.toCharArray(), true);
1083                         ChangeFileEncryption.execute(dbPath, "Resources", encryptCipher, null, Global.cipherPassword.toCharArray(), true);
1084                         ChangeFileEncryption.execute(dbPath, "Index", encryptCipher, null, Global.cipherPassword.toCharArray(), true);
1085                         // ICHANGED
1086                         ChangeFileEncryption.execute(dbPath, "Behavior", encryptCipher, null, Global.cipherPassword.toCharArray(), true);
1087                         
1088                         Global.setDatabaseUrl(Global.getDatabaseUrl() + ";CIPHER="+encryptCipher);
1089                         Global.setResourceDatabaseUrl(Global.getResourceDatabaseUrl() + ";CIPHER="+encryptCipher);
1090                         Global.setIndexDatabaseUrl(Global.getIndexDatabaseUrl() + ";CIPHER="+encryptCipher);
1091                         // ICHANGED
1092                                 Global.setBehaviorDatabaseUrl(Global.getBehaviorDatabaseUrl() + ";CIPHER=" + encryptCipher);
1093
1094                         QMessageBox.information(this, tr("Encryption Complete"), tr("Encryption is complete"));
1095                 }
1096         } catch (SQLException e) {
1097                         e.printStackTrace();
1098                 }       
1099     }
1100     
1101     // Decrypt the database upon shutdown
1102     private void decryptOnShutdown() {
1103         String dbPath= Global.getFileManager().getDbDirPath("");
1104         String dbName = "NeverNote";
1105         try {
1106                 Statement st = conn.getConnection().createStatement();  
1107                 st.execute("shutdown");
1108                 if (Global.getDatabaseUrl().toUpperCase().indexOf(";CIPHER=AES") > -1)
1109                         encryptCipher = "AES";
1110                 else
1111                         encryptCipher = "XTEA";
1112                 if (QMessageBox.question(this, tr("Confirmation"), tr("Are you sure", 
1113                                 "Are you sure you wish to decrypt the database?"),
1114                                 QMessageBox.StandardButton.Yes, 
1115                                 QMessageBox.StandardButton.No) == StandardButton.Yes.value()) {
1116
1117                         ChangeFileEncryption.execute(dbPath, dbName, encryptCipher, Global.cipherPassword.toCharArray(), null, true);
1118                         Global.setDatabaseUrl("");
1119                         Global.setResourceDatabaseUrl("");
1120                         Global.setIndexDatabaseUrl("");
1121                         QMessageBox.information(this, tr("Decryption Complete"), tr("Decryption is complete"));
1122                 }
1123                 } catch (SQLException e) {
1124                         e.printStackTrace();
1125                 }       
1126     }
1127     /**
1128      * Encrypt/Decrypt the local database
1129      **/
1130     public void doDatabaseEncrypt() {
1131         // The database is not currently encrypted
1132         if (Global.getDatabaseUrl().toUpperCase().indexOf("CIPHER=") == -1) {
1133                 if (QMessageBox.question(this, tr("Confirmation"), tr("Encrypting the database is used" +
1134                                 "to enhance security and is performed\nupon shutdown, but please be aware that if"+
1135                                 " you lose the password your\nis lost forever.\n\nIt is highly recommended you " +
1136                                 "perform a backup and/or fully synchronize\n prior to executing this funtction.\n\n" +
1137                                 "Do you wish to proceed?"),
1138                                 QMessageBox.StandardButton.Yes, 
1139                                 QMessageBox.StandardButton.No)==StandardButton.No.value()) {
1140                                 return;
1141                 }
1142                 DBEncryptDialog dialog = new DBEncryptDialog();
1143                 dialog.exec();
1144                 if (dialog.okPressed()) {
1145                         Global.cipherPassword = dialog.getPassword();
1146                         encryptOnShutdown  = true;
1147                         encryptCipher = dialog.getEncryptionMethod();
1148                 }
1149         } else {
1150             DBEncryptDialog dialog = new DBEncryptDialog();
1151             dialog.setWindowTitle(tr("Database Decryption"));
1152             dialog.hideEncryption();
1153             dialog.exec();
1154             if (dialog.okPressed()) {
1155                 if (!dialog.getPassword().equals(Global.cipherPassword)) {
1156                         QMessageBox.critical(null, tr("Incorrect Password"), tr("Incorrect Password"));
1157                         return;
1158                 }
1159                 decryptOnShutdown  = true;
1160                 encryptCipher = "";
1161             }
1162         }
1163         return;
1164     }
1165
1166         private static void initializeGlobalSettings(String[] args) throws InitializationException {
1167                 StartupConfig   startupConfig = new StartupConfig();
1168
1169         for (String arg : args) {
1170             String lower = arg.toLowerCase();
1171             if (lower.startsWith("--name="))
1172                startupConfig.setName(arg.substring(arg.indexOf('=') + 1));
1173             if (lower.startsWith("--home="))
1174                startupConfig.setHomeDirPath(arg.substring(arg.indexOf('=') + 1));
1175             if (lower.startsWith("--disable-viewing"))
1176                startupConfig.setDisableViewing(true);
1177             if (lower.startsWith("--sync-only=true"))
1178                 startupConfig.setSyncOnly(true);
1179         }
1180         Global.setup(startupConfig);
1181         
1182     }
1183
1184     // Exit point
1185         @Override
1186         public void closeEvent(QCloseEvent event) {     
1187                 if (Global.minimizeOnClose() && !closeAction) {
1188                         event.ignore();
1189                         hide();
1190                         return;
1191                 }
1192                 logger.log(logger.HIGH, "Entering NeverNote.closeEvent");
1193                 waitCursor(true);
1194                 
1195                 if (currentNote != null & browserWindow != null) {
1196                         if (currentNote.getTitle() != null && browserWindow != null
1197                                         && !currentNote.getTitle().equals(browserWindow.getTitle()))
1198                                 conn.getNoteTable().updateNoteTitle(currentNote.getGuid(),
1199                                                 browserWindow.getTitle());
1200                 }
1201                 
1202                 saveNote();
1203                 setMessage(tr("Beginning shutdown."));
1204                 
1205                 // Close down external windows
1206                 Collection<ExternalBrowse> windows = externalWindows.values();
1207                 Iterator<ExternalBrowse> iterator = windows.iterator();
1208                 while (iterator.hasNext()) {
1209                         ExternalBrowse browser = iterator.next();
1210                         browser.windowClosing.disconnect();
1211                         browser.close();
1212                 }
1213                 
1214                 // ICHANGED タブブラウザに対してクローズ処理を行う
1215                 Collection<TabBrowse> win = tabWindows.values();
1216                 Iterator<TabBrowse> it = win.iterator();
1217                 tabBrowser.currentChanged.disconnect();
1218                 tabBrowser.tabCloseRequested.disconnect();
1219                 while (it.hasNext()) {
1220                         TabBrowse browser = it.next();
1221                         browser.close();
1222                 }
1223                 
1224                 externalFileEditedSaver();
1225                 if (Global.isConnected && Global.synchronizeOnClose()) {
1226                         setMessage(tr("Performing synchronization before closing."));
1227                         syncRunner.syncNeeded = true;
1228                         syncRunner.addWork("SYNC");
1229                 } else {
1230                         syncRunner.keepRunning = false;
1231                 }
1232                 syncRunner.addWork("STOP");
1233                 setMessage("Closing Program.");
1234                 threadMonitorTimer.stop();
1235
1236                 thumbnailRunner.addWork("STOP");
1237                 indexRunner.addWork("STOP");
1238                 saveNote();
1239                 listManager.stop();
1240                 saveWindowState();
1241
1242                 if (tempFiles != null)
1243                         tempFiles.clear();
1244
1245                 browserWindow.noteSignal.tagsChanged.disconnect();
1246                 browserWindow.noteSignal.titleChanged.disconnect();
1247                 browserWindow.noteSignal.noteChanged.disconnect();
1248                 browserWindow.noteSignal.notebookChanged.disconnect();
1249                 browserWindow.noteSignal.createdDateChanged.disconnect();
1250                 browserWindow.noteSignal.alteredDateChanged.disconnect();
1251                 syncRunner.searchSignal.listChanged.disconnect();
1252                 syncRunner.tagSignal.listChanged.disconnect();
1253         syncRunner.notebookSignal.listChanged.disconnect();
1254         syncRunner.noteIndexSignal.listChanged.disconnect();
1255
1256                 if (isVisible())
1257                         Global.saveWindowVisible("toolBar", toolBar.isVisible());
1258                 saveNoteColumnPositions();
1259                 saveNoteIndexWidth();
1260                 
1261                 int width = notebookTree.columnWidth(0);
1262                 Global.setColumnWidth("notebookTreeName", width);
1263                 width = tagTree.columnWidth(0);
1264                 Global.setColumnWidth("tagTreeName", width);
1265                 
1266                 Global.saveWindowMaximized(isMaximized());
1267                 Global.saveCurrentNoteGuid(currentNoteGuid);
1268                         
1269                 int sortCol = noteTableView.proxyModel.sortColumn();
1270                 int sortOrder = noteTableView.proxyModel.sortOrder().value();
1271                 Global.setSortColumn(sortCol);
1272                 Global.setSortOrder(sortOrder);
1273                 
1274                 hide();
1275                 trayIcon.hide();
1276                 Global.keepRunning = false;
1277                 try {
1278                         logger.log(logger.MEDIUM, "Waiting for indexThread to stop");
1279                         if (indexRunner.thread().isAlive())
1280                                 indexRunner.thread().join(50);
1281                         if (!indexRunner.thread().isAlive())
1282                                 logger.log(logger.MEDIUM, "Index thread has stopped");
1283                         else {
1284                                 logger.log(logger.MEDIUM, "Index thread still running - interrupting");
1285                                 indexRunner.thread().interrupt();
1286                         }
1287                 } catch (InterruptedException e1) {
1288                         e1.printStackTrace();
1289                 }
1290                 
1291                 if (!syncRunner.thread().isAlive()) {
1292                         logger.log(logger.MEDIUM, "Waiting for syncThread to stop");
1293                         if (syncRunner.thread().isAlive()) {
1294                                 System.out.println(tr("Synchronizing.  Please be patient."));
1295                                 for(;syncRunner.thread().isAlive();) {
1296                                         try {
1297                                                 wait(10);
1298                                         } catch (InterruptedException e) {
1299                                                 e.printStackTrace();
1300                                         }
1301                                 }
1302                         }
1303                         logger.log(logger.MEDIUM, "Sync thread has stopped");
1304                 }
1305
1306                 if (encryptOnShutdown) {
1307                         encryptOnShutdown();
1308                 }
1309                 if (decryptOnShutdown) {
1310                         decryptOnShutdown();
1311                 }
1312                 try {
1313                         Global.getFileManager().purgeResDirectory(false);
1314                 } catch (InitializationException e) {
1315                         System.out.println(tr("Empty res directory purge failed"));
1316                         e.printStackTrace();
1317                 }
1318                 logger.log(logger.HIGH, "Leaving NeverNote.closeEvent");
1319         }
1320
1321
1322         private void closeNeverNote() {
1323                 closeAction = true;
1324                 close();
1325         }
1326         public void setMessage(String s) {
1327                 if (logger != null) 
1328                         logger.log(logger.HIGH, "Entering NeverNote.setMessage");
1329                 else
1330                         System.out.println("*** ERROR *** " +s);
1331                 
1332                 if (statusBar != null) {
1333                         statusBar.show();
1334                         if (logger != null) 
1335                                 logger.log(logger.HIGH, "Message: " +s);
1336                         statusBar.showMessage(s);
1337                         if (emitLog != null)
1338                                 emitLog.add(s);
1339                 
1340                         if (messageTimer != null) {
1341                                 messageTimer.stop();
1342                                 messageTimer.setSingleShot(true);
1343                                 messageTimer.start();
1344                         }
1345                 }
1346                         
1347                 if (logger != null) 
1348                         logger.log(logger.HIGH, "Leaving NeverNote.setMessage");
1349         }
1350         
1351         private void clearMessage() {
1352                 statusBar.clearMessage();
1353                 statusBar.hide();
1354         }
1355                 
1356         private void waitCursor(boolean wait) {
1357                 if (wait) {
1358                         if (QApplication.overrideCursor() == null)
1359                                 QApplication.setOverrideCursor(new QCursor(Qt.CursorShape.WaitCursor));
1360                 }
1361                 else {
1362                         if (QApplication.overrideCursor() != null)
1363                                 QApplication.restoreOverrideCursor();
1364                         else
1365                                 QApplication.setOverrideCursor(new QCursor(Qt.CursorShape.ArrowCursor));
1366                 }
1367                 listManager.refreshCounters();
1368         }
1369         
1370         private void setupIndexListeners() {
1371 //              indexRunner.noteSignal.noteIndexed.connect(this, "indexThreadComplete(String)");
1372 //              indexRunner.resourceSignal.resourceIndexed.connect(this, "indexThreadComplete(String)");
1373                 indexRunner.signal.indexStarted.connect(this, "indexStarted()");
1374                 indexRunner.signal.indexFinished.connect(this, "indexComplete()");
1375         }
1376         private void setupSyncSignalListeners() {
1377                 syncRunner.tagSignal.listChanged.connect(this, "tagIndexUpdated()");
1378         syncRunner.searchSignal.listChanged.connect(this, "savedSearchIndexUpdated()");
1379         syncRunner.notebookSignal.listChanged.connect(this, "notebookIndexUpdated()");
1380         syncRunner.noteIndexSignal.listChanged.connect(this, "noteIndexUpdated(boolean)");
1381         syncRunner.noteSignal.quotaChanged.connect(this, "updateQuotaBar()");
1382         
1383                 syncRunner.syncSignal.saveUploadAmount.connect(this,"saveUploadAmount(long)");
1384                 syncRunner.syncSignal.saveUserInformation.connect(this,"saveUserInformation(User)");
1385                 syncRunner.syncSignal.saveEvernoteUpdateCount.connect(this,"saveEvernoteUpdateCount(int)");
1386                 
1387                 syncRunner.noteSignal.guidChanged.connect(this, "noteGuidChanged(String, String)");
1388                 syncRunner.noteSignal.noteChanged.connect(this, "invalidateNoteCache(String, String)");
1389                 syncRunner.resourceSignal.resourceGuidChanged.connect(this, "noteResourceGuidChanged(String,String,String)");
1390                 syncRunner.noteSignal.noteDownloaded.connect(listManager, "noteDownloaded(Note)");
1391                 syncRunner.noteSignal.notebookChanged.connect(this, "updateNoteNotebook(String, String)");
1392                 
1393                 syncRunner.syncSignal.refreshLists.connect(this, "refreshLists()");
1394         }
1395         
1396         private void setupBrowserSignalListeners() {
1397                 setupBrowserWindowListeners(browserWindow, true);
1398         }
1399
1400         private void setupBrowserWindowListeners(BrowserWindow browser, boolean master) {
1401                 browser.fileWatcher.fileChanged.connect(this, "externalFileEdited(String)");
1402                 browser.noteSignal.tagsChanged.connect(this, "updateNoteTags(String, List)");
1403             browser.noteSignal.tagsChanged.connect(this, "updateListTags(String, List)");
1404             if (master) browser.noteSignal.noteChanged.connect(this, "setNoteDirty()");
1405             browser.noteSignal.titleChanged.connect(listManager, "updateNoteTitle(String, String)");
1406             browser.noteSignal.titleChanged.connect(this, "updateNoteTitle(String, String)");
1407             browser.noteSignal.notebookChanged.connect(this, "updateNoteNotebook(String, String)");
1408             browser.noteSignal.createdDateChanged.connect(listManager, "updateNoteCreatedDate(String, QDateTime)");
1409             browser.noteSignal.alteredDateChanged.connect(listManager, "updateNoteAlteredDate(String, QDateTime)");
1410             browser.noteSignal.subjectDateChanged.connect(listManager, "updateNoteSubjectDate(String, QDateTime)");
1411             browser.noteSignal.authorChanged.connect(listManager, "updateNoteAuthor(String, String)");
1412             browser.noteSignal.geoChanged.connect(listManager, "updateNoteGeoTag(String, Double,Double,Double)");
1413             browser.noteSignal.geoChanged.connect(this, "setNoteDirty()");
1414             browser.noteSignal.sourceUrlChanged.connect(listManager, "updateNoteSourceUrl(String, String)");
1415         browser.blockApplication.connect(this, "blockApplication(BrowserWindow)");
1416         browser.unblockApplication.connect(this, "unblockApplication()");
1417             if (master) browser.focusLost.connect(this, "saveNote()");
1418             browser.resourceSignal.contentChanged.connect(this, "externalFileEdited(String)");
1419             browser.evernoteLinkClicked.connect(this, "evernoteLinkClick(String, String)");
1420         }
1421
1422         //**************************************************
1423         //* Setup shortcuts
1424         //**************************************************
1425         private void setupShortcut(QShortcut action, String text) {
1426                 if (!Global.shortcutKeys.containsAction(text))
1427                         return;
1428                 action.setKey(new QKeySequence(Global.shortcutKeys.getShortcut(text)));
1429         }
1430         
1431         //***************************************************************
1432         //***************************************************************
1433         //* Settings and look & feel
1434         //***************************************************************
1435         //***************************************************************
1436         @SuppressWarnings("unused")
1437         private void settings() {
1438                 logger.log(logger.HIGH, "Entering NeverNote.settings");
1439
1440                 saveNoteColumnPositions();
1441                 saveNoteIndexWidth();
1442                 showColumns();
1443         ConfigDialog settings = new ConfigDialog(this);
1444         String dateFormat = Global.getDateFormat();
1445         String timeFormat = Global.getTimeFormat();
1446         
1447                 indexTime = 1000*Global.getIndexThreadSleepInterval();  
1448                 indexTimer.start(indexTime);  // reset indexing timer
1449         
1450         settings.exec();
1451         indexRunner.indexAttachmentsLocally = Global.indexAttachmentsLocally();
1452         indexRunner.indexNoteBody = Global.indexNoteBody();
1453         indexRunner.indexNoteTitle = Global.indexNoteTitle();
1454         indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
1455         indexRunner.indexImageRecognition = Global.indexImageRecognition();
1456         if (Global.showTrayIcon() || Global.minimizeOnClose())
1457                 trayIcon.show();
1458         else
1459                 trayIcon.hide();
1460         showColumns();
1461         if (menuBar.showEditorBar.isChecked()){
1462                 // ICHANGED 
1463                 for(int i = 0; i < tabBrowser.count(); i++){
1464                         BrowserWindow browser = ((TabBrowse) tabBrowser.widget(i)).getBrowserWindow();
1465                         showEditorButtons(browser);
1466                 }
1467                 
1468         }
1469         
1470         // Reset the save timer
1471         if (Global.getAutoSaveInterval() > 0)
1472                         saveTimer.setInterval(1000*60*Global.getAutoSaveInterval());
1473         else
1474                 saveTimer.stop();
1475         
1476         
1477         // Set special reloads
1478         if (settings.getDebugPage().reloadSharedNotebooksClicked()) {
1479                 conn.executeSql("Delete from LinkedNotebook");
1480                 conn.executeSql("delete from SharedNotebook");
1481                 conn.executeSql("Delete from Notebook where linked=true");
1482                 conn.executeSql("Insert into Sync (key, value) values ('FullLinkedNotebookSync', 'true')");
1483                 conn.executeSql("Insert into Sync (key, value) values ('FullSharedNotebookSync', 'true')");
1484         }
1485
1486         // Reload user data
1487         noteCache.clear();
1488         readOnlyCache.clear();
1489         inkNoteCache.clear();
1490         noteIndexUpdated(true);
1491                 
1492         logger.log(logger.HIGH, "Leaving NeverNote.settings");
1493         }
1494         // Restore things to the way they were
1495         private void restoreWindowState(boolean mainWindow) {
1496                 // We need to name things or this doesn't work.
1497                 setObjectName("NeverNote");
1498         restoreState(Global.restoreState(objectName()));
1499                 mainLeftRightSplitter.setObjectName("mainLeftRightSplitter");
1500                 browserIndexSplitter.setObjectName("browserIndexSplitter");
1501                 leftSplitter1.setObjectName("leftSplitter1");
1502                 // ICHANGED
1503                 rensoNoteListDock.setObjectName("rensoNoteListDock");
1504                 
1505                 // Restore the actual positions.
1506                 if (mainWindow)
1507                         restoreGeometry(Global.restoreGeometry(objectName()));
1508         mainLeftRightSplitter.restoreState(Global.restoreState(mainLeftRightSplitter.objectName()));
1509         browserIndexSplitter.restoreState(Global.restoreState(browserIndexSplitter.objectName()));
1510         leftSplitter1.restoreState(Global.restoreState(leftSplitter1.objectName()));
1511         // ICHANGED
1512         rensoNoteListDock.restoreGeometry(Global.restoreGeometry(rensoNoteListDock.objectName()));
1513        
1514         }
1515         // Save window positions for the next start
1516         private void saveWindowState() {
1517                 Global.saveGeometry(objectName(), saveGeometry());
1518                 Global.saveState(mainLeftRightSplitter.objectName(), mainLeftRightSplitter.saveState());
1519                 Global.saveState(browserIndexSplitter.objectName(), browserIndexSplitter.saveState());
1520                 Global.saveState(leftSplitter1.objectName(), leftSplitter1.saveState());
1521                 Global.saveState(objectName(), saveState());
1522                 // ICHANGED
1523                 Global.saveGeometry(rensoNoteListDock.objectName(), rensoNoteListDock.saveGeometry());
1524         }    
1525         // Load the style sheet
1526         private void loadStyleSheet() {
1527                 String styleSheetName = "default.qss";
1528                 if (Global.getStyle().equalsIgnoreCase("cleanlooks"))
1529                                 styleSheetName = "default-cleanlooks.qss";
1530                 String fileName = Global.getFileManager().getQssDirPathUser("default.qss");
1531                 QFile file = new QFile(fileName);
1532                 
1533                 // If a user default.qss doesn't exist, we use the one shipped with NeverNote
1534                 if (!file.exists()) {
1535                         fileName = Global.getFileManager().getQssDirPath(styleSheetName);
1536                         file = new QFile(fileName);
1537                 }
1538                 file.open(OpenModeFlag.ReadOnly);
1539                 String styleSheet = file.readAll().toString();
1540                 file.close();
1541                 setStyleSheet(styleSheet);
1542         }
1543         // Save column positions for the next time
1544         private void saveNoteColumnPositions() {
1545                 int position = noteTableView.header.visualIndex(Global.noteTableCreationPosition);
1546                 Global.setColumnPosition("noteTableCreationPosition", position);
1547                 position = noteTableView.header.visualIndex(Global.noteTableTagPosition);
1548                 Global.setColumnPosition("noteTableTagPosition", position);
1549                 position = noteTableView.header.visualIndex(Global.noteTableNotebookPosition);
1550                 Global.setColumnPosition("noteTableNotebookPosition", position);
1551                 position = noteTableView.header.visualIndex(Global.noteTableChangedPosition);
1552                 Global.setColumnPosition("noteTableChangedPosition", position);
1553                 position = noteTableView.header.visualIndex(Global.noteTableAuthorPosition);
1554                 Global.setColumnPosition("noteTableAuthorPosition", position);
1555                 position = noteTableView.header.visualIndex(Global.noteTableSourceUrlPosition);
1556                 Global.setColumnPosition("noteTableSourceUrlPosition", position);
1557                 position = noteTableView.header.visualIndex(Global.noteTableSubjectDatePosition);
1558                 Global.setColumnPosition("noteTableSubjectDatePosition", position);
1559                 position = noteTableView.header.visualIndex(Global.noteTableTitlePosition);
1560                 Global.setColumnPosition("noteTableTitlePosition", position);
1561                 position = noteTableView.header.visualIndex(Global.noteTableSynchronizedPosition);
1562                 Global.setColumnPosition("noteTableSynchronizedPosition", position);
1563                 position = noteTableView.header.visualIndex(Global.noteTableGuidPosition);
1564                 Global.setColumnPosition("noteTableGuidPosition", position);
1565                 position = noteTableView.header.visualIndex(Global.noteTableThumbnailPosition);
1566                 Global.setColumnPosition("noteTableThumbnailPosition", position);
1567                 position = noteTableView.header.visualIndex(Global.noteTablePinnedPosition);
1568                 Global.setColumnPosition("noteTablePinnedPosition", position);
1569
1570         }
1571         // Save column widths for the next time
1572         private void saveNoteIndexWidth() {
1573                 int width;
1574         width = noteTableView.getColumnWidth(Global.noteTableCreationPosition);
1575         Global.setColumnWidth("noteTableCreationPosition", width);
1576                 width = noteTableView.getColumnWidth(Global.noteTableChangedPosition);
1577                 Global.setColumnWidth("noteTableChangedPosition", width);
1578                 width = noteTableView.getColumnWidth(Global.noteTableGuidPosition);
1579                 Global.setColumnWidth("noteTableGuidPosition", width);
1580                 width = noteTableView.getColumnWidth(Global.noteTableNotebookPosition);
1581                 Global.setColumnWidth("noteTableNotebookPosition", width);
1582                 width = noteTableView.getColumnWidth(Global.noteTableTagPosition);
1583                 Global.setColumnWidth("noteTableTagPosition", width);
1584                 width = noteTableView.getColumnWidth(Global.noteTableTitlePosition);
1585                 Global.setColumnWidth("noteTableTitlePosition", width);
1586                 width = noteTableView.getColumnWidth(Global.noteTableSourceUrlPosition);
1587                 Global.setColumnWidth("noteTableSourceUrlPosition", width);
1588                 width = noteTableView.getColumnWidth(Global.noteTableAuthorPosition);
1589                 Global.setColumnWidth("noteTableAuthorPosition", width);
1590                 width = noteTableView.getColumnWidth(Global.noteTableSubjectDatePosition);
1591                 Global.setColumnWidth("noteTableSubjectDatePosition", width);
1592                 width = noteTableView.getColumnWidth(Global.noteTableSynchronizedPosition);
1593                 Global.setColumnWidth("noteTableSynchronizedPosition", width);
1594                 width = noteTableView.getColumnWidth(Global.noteTableThumbnailPosition);
1595                 Global.setColumnWidth("noteTableThumbnailPosition", width);
1596                 width = noteTableView.getColumnWidth(Global.noteTableGuidPosition);
1597                 Global.setColumnWidth("noteTableGuidPosition", width);
1598                 width = noteTableView.getColumnWidth(Global.noteTablePinnedPosition);
1599                 Global.setColumnWidth("noteTablePinnedPosition", width);
1600         }
1601         
1602         @SuppressWarnings("unused")
1603         private void toggleSearchWindow() {
1604                 logger.log(logger.HIGH, "Entering NeverNote.toggleSearchWindow");
1605         searchLayout.toggleSearchField();
1606         menuBar.hideSearch.setChecked(searchField.isVisible());
1607         Global.saveWindowVisible("searchField", searchField.isVisible());
1608         logger.log(logger.HIGH, "Leaving NeverNote.toggleSearchWindow");
1609     }   
1610         @SuppressWarnings("unused")
1611         private void toggleQuotaWindow() {
1612                 logger.log(logger.HIGH, "Entering NeverNote.toggleQuotaWindow");
1613         searchLayout.toggleQuotaBar();
1614         menuBar.hideQuota.setChecked(quotaBar.isVisible());
1615         Global.saveWindowVisible("quota", quotaBar.isVisible());
1616         logger.log(logger.HIGH, "Leaving NeverNote.toggleQuotaWindow");
1617     }   
1618         @SuppressWarnings("unused")
1619         private void toggleZoomWindow() {
1620                 logger.log(logger.HIGH, "Entering NeverNote.toggleZoomWindow");
1621         searchLayout.toggleZoom();
1622         menuBar.hideZoom.setChecked(zoomSpinner.isVisible());
1623         Global.saveWindowVisible("zoom", zoomSpinner.isVisible());
1624         logger.log(logger.HIGH, "Leaving NeverNote.toggleZoomWindow");
1625     }   
1626         
1627         
1628         
1629     //***************************************************************
1630     //***************************************************************
1631     //** These functions deal with Notebook menu items
1632     //***************************************************************
1633     //***************************************************************
1634     // Setup the tree containing the user's notebooks.
1635     private void initializeNotebookTree() {       
1636         logger.log(logger.HIGH, "Entering NeverNote.initializeNotebookTree");
1637 //      notebookTree.itemClicked.connect(this, "notebookTreeSelection()");
1638         notebookTree.selectionSignal.connect(this, "notebookTreeSelection()");
1639         listManager.notebookSignal.refreshNotebookTreeCounts.connect(notebookTree, "updateCounts(List, List)");
1640         logger.log(logger.HIGH, "Leaving NeverNote.initializeNotebookTree");
1641     }   
1642     // Listener when a notebook is selected
1643         private void notebookTreeSelection() {
1644                 logger.log(logger.HIGH, "Entering NeverNote.notebookTreeSelection");
1645                 noteTableView.proxyModel.blocked = true;
1646                 
1647                 clearTrashFilter();
1648                 clearAttributeFilter();
1649                 clearSavedSearchFilter();
1650                 if (Global.mimicEvernoteInterface) {
1651                         clearTagFilter();
1652                         //searchField.clear();
1653                         searchField.clearEditText();
1654                 }
1655                 menuBar.noteRestoreAction.setVisible(false);            
1656         menuBar.notebookEditAction.setEnabled(true);
1657         menuBar.notebookDeleteAction.setEnabled(true);
1658         menuBar.notebookPublishAction.setEnabled(true);
1659         menuBar.notebookShareAction.setEnabled(true);
1660         menuBar.notebookIconAction.setEnabled(true);
1661         menuBar.notebookStackAction.setEnabled(true);
1662         
1663                 // ICHANGED ゴミ箱から元の画面に戻す。連想ノートリストをONに。
1664                 if (!rensoNoteListDock.isEnabled()) {
1665                         rensoNoteListDock.setEnabled(true);
1666                 }
1667                 
1668         List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1669         selectedNotebookGUIDs.clear();
1670                 String guid = "";
1671                 String stackName = "";
1672                 if (selections.size() > 0) {
1673                 guid = (selections.get(0).text(2));
1674                 stackName = selections.get(0).text(0);
1675         }
1676                 if (!Global.mimicEvernoteInterface) {
1677                         // If no notebooks are selected, we make it look like the "all notebooks" one was selected
1678                         if (selections.size()==0) {
1679                                 selectedNotebookGUIDs.clear();
1680                                 for (int i=0; i < listManager.getNotebookIndex().size(); i++) {
1681                                         selectedNotebookGUIDs.add(listManager.getNotebookIndex().get(i).getGuid());
1682                                 }
1683                                 menuBar.notebookEditAction.setEnabled(false);
1684                                 menuBar.notebookDeleteAction.setEnabled(false);
1685                                 menuBar.notebookStackAction.setEnabled(false);
1686                                 menuBar.notebookIconAction.setEnabled(false);
1687                         }
1688                 }
1689         if (!guid.equals("") && !guid.equals("STACK")) {
1690                 selectedNotebookGUIDs.add(guid);
1691                 menuBar.notebookIconAction.setEnabled(true);
1692         } else {
1693                 menuBar.notebookIconAction.setEnabled(true);
1694                         for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
1695                                 Notebook book = listManager.getNotebookIndex().get(j);
1696                                 if (book.getStack() != null && book.getStack().equalsIgnoreCase(stackName))
1697                                         selectedNotebookGUIDs.add(book.getGuid());
1698                         }
1699         }
1700         listManager.setSelectedNotebooks(selectedNotebookGUIDs);
1701         listManager.loadNotesIndex();
1702         noteIndexUpdated(false);
1703         refreshEvernoteNote(true);
1704         listManager.refreshCounters = true;
1705         listManager.refreshCounters();
1706         if (selectedNotebookGUIDs.size() == 1) {
1707                 int col = conn.getNotebookTable().getSortColumn(selectedNotebookGUIDs.get(0));
1708                 int order = conn.getNotebookTable().getSortOrder(selectedNotebookGUIDs.get(0));
1709                 if (col != -1) {
1710                         noteTableView.proxyModel.blocked = true;
1711                         if (order == 1)
1712                                 noteTableView.sortByColumn(col, Qt.SortOrder.DescendingOrder);
1713                         else
1714                                 noteTableView.sortByColumn(col, Qt.SortOrder.AscendingOrder);
1715                 }
1716         }
1717         noteTableView.proxyModel.blocked = false;
1718                 logger.log(logger.HIGH, "Leaving NeverNote.notebookTreeSelection");
1719
1720     }
1721     private void clearNotebookFilter() {
1722         notebookTree.blockSignals(true);
1723         notebookTree.clearSelection();
1724                 menuBar.noteRestoreAction.setVisible(false);
1725         menuBar.notebookEditAction.setEnabled(false);
1726         menuBar.notebookDeleteAction.setEnabled(false);
1727         selectedNotebookGUIDs.clear();
1728         listManager.setSelectedNotebooks(selectedNotebookGUIDs);
1729         notebookTree.blockSignals(false);
1730     }
1731         // Triggered when the notebook DB has been updated
1732         private void notebookIndexUpdated() {
1733                 logger.log(logger.HIGH, "Entering NeverNote.notebookIndexUpdated");
1734         
1735                 // Get the possible icons
1736                 HashMap<String, QIcon> icons = conn.getNotebookTable().getAllIcons();
1737         notebookTree.setIcons(icons);
1738         
1739         if (selectedNotebookGUIDs == null)
1740                         selectedNotebookGUIDs = new ArrayList<String>();
1741                 List<Notebook> books = conn.getNotebookTable().getAll();
1742                 for (int i=books.size()-1; i>=0; i--) {
1743                         for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1744                                 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(books.get(i).getGuid())) {
1745                                         books.remove(i);
1746                                         j=listManager.getArchiveNotebookIndex().size();
1747                                 }
1748                         }
1749                 }
1750                 
1751                 
1752                 listManager.countNotebookResults(listManager.getNoteIndex());
1753                 notebookTree.blockSignals(true);
1754         notebookTree.load(books, listManager.getLocalNotebooks());
1755         for (int i=selectedNotebookGUIDs.size()-1; i>=0; i--) {
1756                 boolean found = notebookTree.selectGuid(selectedNotebookGUIDs.get(i));
1757                 if (!found)
1758                         selectedNotebookGUIDs.remove(i);
1759         }
1760         listManager.refreshCounters = true;
1761         listManager.refreshCounters();
1762         notebookTree.blockSignals(false);
1763         
1764                 logger.log(logger.HIGH, "Leaving NeverNote.notebookIndexUpdated");
1765     }
1766     // Show/Hide note information
1767         @SuppressWarnings("unused")
1768         private void toggleNotebookWindow() {
1769                 logger.log(logger.HIGH, "Entering NeverNote.toggleNotebookWindow");
1770                 searchLayout.toggleNotebook();
1771         menuBar.hideNotebooks.setChecked(notebookTree.isVisible());
1772         Global.saveWindowVisible("notebookTree", notebookTree.isVisible());
1773         logger.log(logger.HIGH, "Leaving NeverNote.toggleNotebookWindow");
1774     }   
1775         // Add a new notebook
1776         @SuppressWarnings("unused")
1777         private void addNotebook() {
1778                 logger.log(logger.HIGH, "Inside NeverNote.addNotebook");
1779                 NotebookEdit edit = new NotebookEdit();
1780                 edit.setNotebooks(listManager.getNotebookIndex());
1781                 edit.exec();
1782         
1783                 if (!edit.okPressed())
1784                         return;
1785         
1786                 Calendar currentTime = new GregorianCalendar();
1787                 Long l = new Long(currentTime.getTimeInMillis());
1788                 String randint = new String(Long.toString(l));
1789         
1790                 Notebook newBook = new Notebook();
1791                 newBook.setUpdateSequenceNum(0);
1792                 newBook.setGuid(randint);
1793                 newBook.setName(edit.getNotebook());
1794                 newBook.setServiceCreated(new Date().getTime());
1795                 newBook.setServiceUpdated(new Date().getTime());
1796                 newBook.setDefaultNotebook(false);
1797                 newBook.setPublished(false);
1798                 
1799                 listManager.getNotebookIndex().add(newBook);
1800                 if (edit.isLocal())
1801                         listManager.getLocalNotebooks().add(newBook.getGuid());
1802                 conn.getNotebookTable().addNotebook(newBook, true, edit.isLocal());
1803                 notebookIndexUpdated();
1804                 listManager.countNotebookResults(listManager.getNoteIndex());
1805 //              notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
1806                 logger.log(logger.HIGH, "Leaving NeverNote.addNotebook");
1807         }
1808         // Edit an existing notebook
1809         @SuppressWarnings("unused")
1810         private void stackNotebook() {
1811                 logger.log(logger.HIGH, "Entering NeverNote.stackNotebook");
1812                 StackNotebook edit = new StackNotebook();
1813                 
1814                 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1815                 QTreeWidgetItem currentSelection;
1816                 for (int i=0; i<selections.size(); i++) {
1817                         currentSelection = selections.get(0);
1818                         String guid = currentSelection.text(2);
1819                         if (guid.equalsIgnoreCase("")) {
1820                                  QMessageBox.critical(this, tr("Unable To Stack") ,tr("You can't stack the \"All Notebooks\" item."));
1821                                  return;
1822                         }
1823                         if (guid.equalsIgnoreCase("STACK")) {
1824                                  QMessageBox.critical(this, tr("Unable To Stack") ,tr("You can't stack a stack."));
1825                                  return;
1826                         }
1827                 }
1828
1829                 edit.setStackNames(conn.getNotebookTable().getAllStackNames());
1830
1831                 
1832                 edit.exec();
1833         
1834                 if (!edit.okPressed())
1835                         return;
1836         
1837                 String stack = edit.getStackName();
1838                 
1839                 for (int i=0; i<selections.size(); i++) {
1840                         currentSelection = selections.get(i);
1841                         String guid = currentSelection.text(2);
1842                         listManager.updateNotebookStack(guid, stack);
1843                 }
1844                 notebookIndexUpdated();
1845                 logger.log(logger.HIGH, "Leaving NeverNote.stackNotebook");
1846         }
1847         // Edit an existing notebook
1848         @SuppressWarnings("unused")
1849         private void editNotebook() {
1850                 logger.log(logger.HIGH, "Entering NeverNote.editNotebook");
1851                 NotebookEdit edit = new NotebookEdit();
1852                 
1853                 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1854                 QTreeWidgetItem currentSelection;
1855                 currentSelection = selections.get(0);
1856                 edit.setNotebook(currentSelection.text(0));
1857                 
1858                 String guid = currentSelection.text(2);
1859                 if (!guid.equalsIgnoreCase("STACK")) {
1860                         edit.setTitle(tr("Edit Notebook"));
1861                         edit.setNotebooks(listManager.getNotebookIndex());
1862                         edit.setLocalCheckboxEnabled(false);
1863                         for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1864                                 if (listManager.getNotebookIndex().get(i).getGuid().equals(guid)) {
1865                                         edit.setDefaultNotebook(listManager.getNotebookIndex().get(i).isDefaultNotebook());
1866                                         i=listManager.getNotebookIndex().size();
1867                                 }
1868                         }
1869                 } else {
1870                         edit.setTitle(tr("Edit Stack"));
1871                         edit.setStacks(conn.getNotebookTable().getAllStackNames());
1872                         edit.hideLocalCheckbox();
1873                         edit.hideDefaultCheckbox();
1874                 }
1875                 
1876                 edit.exec();
1877         
1878                 if (!edit.okPressed())
1879                         return;
1880         
1881                 
1882                 if (guid.equalsIgnoreCase("STACK")) {
1883                         conn.getNotebookTable().renameStacks(currentSelection.text(0), edit.getNotebook());
1884                         for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
1885                                 if (listManager.getNotebookIndex().get(j).getStack() != null && 
1886                                         listManager.getNotebookIndex().get(j).getStack().equalsIgnoreCase(currentSelection.text(0)))
1887                                                 listManager.getNotebookIndex().get(j).setStack(edit.getNotebook());
1888                         }
1889                         conn.getNotebookTable().renameStacks(currentSelection.text(0), edit.getNotebook());
1890                         currentSelection.setText(0, edit.getNotebook());
1891                         return;
1892                 }
1893                 
1894                 updateListNotebookName(currentSelection.text(0), edit.getNotebook());
1895                 currentSelection.setText(0, edit.getNotebook());
1896                 
1897                 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1898                         if (listManager.getNotebookIndex().get(i).getGuid().equals(guid)) {
1899                                 listManager.getNotebookIndex().get(i).setName(edit.getNotebook());
1900                                 if (!listManager.getNotebookIndex().get(i).isDefaultNotebook() && edit.isDefaultNotebook()) {
1901                                         for (int j=0; j<listManager.getNotebookIndex().size(); j++)
1902                                                 listManager.getNotebookIndex().get(j).setDefaultNotebook(false);
1903                                         listManager.getNotebookIndex().get(i).setDefaultNotebook(true);
1904                                         conn.getNotebookTable().setDefaultNotebook(listManager.getNotebookIndex().get(i).getGuid());
1905                                 }
1906                                 conn.getNotebookTable().updateNotebook(listManager.getNotebookIndex().get(i), true);
1907                                 if (conn.getNotebookTable().isLinked(listManager.getNotebookIndex().get(i).getGuid())) {
1908                                         LinkedNotebook linkedNotebook = conn.getLinkedNotebookTable().getByNotebookGuid(listManager.getNotebookIndex().get(i).getGuid());
1909                                         linkedNotebook.setShareName(edit.getNotebook());
1910                                         conn.getLinkedNotebookTable().updateNotebook(linkedNotebook, true);
1911                                 }
1912                                 i=listManager.getNotebookIndex().size();
1913                         }
1914                 }
1915                 
1916                 // Build a list of non-closed notebooks
1917                 List<Notebook> nbooks = new ArrayList<Notebook>();
1918                 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1919                         boolean found=false;
1920                         for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
1921                                 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
1922                                         found = true;
1923                         }
1924                         if (!found)
1925                                 nbooks.add(listManager.getNotebookIndex().get(i));
1926                 }
1927                 
1928                 
1929                 FilterEditorNotebooks notebookFilter = new FilterEditorNotebooks(conn, logger);
1930                 List<Notebook> filteredBooks = notebookFilter.getValidNotebooks(currentNote, listManager.getNotebookIndex());
1931                 browserWindow.setNotebookList(filteredBooks);
1932                 Iterator<String> set = externalWindows.keySet().iterator();
1933                 while(set.hasNext())
1934                         externalWindows.get(set.next()).getBrowserWindow().setNotebookList(filteredBooks);
1935                 
1936                 // ICHANGED
1937                 Iterator<Integer>it = tabWindows.keySet().iterator();
1938                 while (it.hasNext()) {
1939                         tabWindows.get(it.next()).getBrowserWindow()
1940                                         .setNotebookList(filteredBooks);
1941                 }
1942                 
1943                 logger.log(logger.HIGH, "Leaving NeverNote.editNotebook");
1944         }
1945         // Publish a notebook
1946         @SuppressWarnings("unused")
1947         private void publishNotebook() {
1948                 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1949                 QTreeWidgetItem currentSelection;
1950                 currentSelection = selections.get(0);
1951                 String guid = currentSelection.text(2);
1952
1953                 if (guid.equalsIgnoreCase("STACK") || guid.equalsIgnoreCase(""))
1954                         return;
1955                 
1956                 Notebook n = null;
1957                 int position = 0;
1958                 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1959                         if (guid.equals(listManager.getNotebookIndex().get(i).getGuid())) {
1960                                 n = listManager.getNotebookIndex().get(i);
1961                                 position = i;
1962                                 i = listManager.getNotebookIndex().size();
1963                         }
1964                 }
1965                 if (n == null)
1966                         return;
1967                 
1968                 PublishNotebook publish = new PublishNotebook(Global.username, Global.getServer(), n);
1969                 publish.exec();
1970                 
1971                 if (!publish.okClicked()) 
1972                         return;
1973                 
1974                 Publishing p = publish.getPublishing();
1975                 boolean isPublished = !publish.isStopPressed();
1976                 conn.getNotebookTable().setPublishing(n.getGuid(), isPublished, p);
1977                 n.setPublished(isPublished);
1978                 n.setPublishing(p);
1979                 listManager.getNotebookIndex().set(position, n);
1980                 notebookIndexUpdated();
1981         }
1982         // Publish a notebook
1983         @SuppressWarnings("unused")
1984         private void shareNotebook() {
1985                 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
1986                 QTreeWidgetItem currentSelection;
1987                 currentSelection = selections.get(0);
1988                 String guid = currentSelection.text(2);
1989
1990                 if (guid.equalsIgnoreCase("STACK") || guid.equalsIgnoreCase(""))
1991                         return;
1992                 
1993                 Notebook n = null;;
1994                 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
1995                         if (guid.equals(listManager.getNotebookIndex().get(i).getGuid())) {
1996                                 n = listManager.getNotebookIndex().get(i);
1997                                 i = listManager.getNotebookIndex().size();
1998                         }
1999                 }
2000                                 
2001                 String authToken = null;
2002                 if (syncRunner.isConnected)
2003                         authToken = syncRunner.authToken;
2004                 ShareNotebook share = new ShareNotebook(n.getName(), conn, n, syncRunner);
2005                 share.exec();
2006                 
2007         }
2008
2009         // Delete an existing notebook
2010         @SuppressWarnings("unused")
2011         private void deleteNotebook() {
2012                 logger.log(logger.HIGH, "Entering NeverNote.deleteNotebook");
2013                 boolean stacksFound = false;
2014                 boolean notebooksFound = false;
2015                 boolean assigned = false;
2016                 // Check if any notes have this notebook
2017                 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
2018         for (int i=0; i<selections.size(); i++) {
2019                 QTreeWidgetItem currentSelection;
2020                 currentSelection = selections.get(i);
2021                 String guid = currentSelection.text(2);
2022                 if (!guid.equalsIgnoreCase("STACK")) {
2023                         notebooksFound = true;
2024                         for (int j=0; j<listManager.getNoteIndex().size(); j++) {
2025                                 String noteGuid = listManager.getNoteIndex().get(j).getNotebookGuid();
2026                                 if (noteGuid.equals(guid)) {
2027                                         assigned = true;
2028                                         j=listManager.getNoteIndex().size();
2029                                         i=selections.size();
2030                                 }
2031                         }
2032                 } else {
2033                         stacksFound = true;
2034                 }
2035         }
2036                 if (assigned) {
2037                         QMessageBox.information(this, tr("Unable to Delete"), tr("Some of the selected notebook(s) contain notes.\n"+
2038                                         "Please delete the notes or move them to another notebook before deleting any notebooks."));
2039                         return;
2040                 }
2041                 
2042                 if (conn.getNotebookTable().getAll().size() == 1) {
2043                         QMessageBox.information(this, tr("Unable to Delete"), tr("You must have at least one notebook."));
2044                         return;
2045                 }
2046         
2047         // If all notebooks are clear, verify the delete
2048                 String msg1 = new String(tr("Delete selected notebooks?"));
2049                 String msg2 = new String(tr("Remove selected stacks (notebooks will not be deleted)?"));
2050                 String msg3 = new String(tr("Delete selected notebooks & remove stacks? Notebooks under the stacks are" +
2051                                 " not deleted unless selected?"));
2052                 String msg = "";
2053                 if (stacksFound && notebooksFound)
2054                         msg = msg3;
2055                 if (!stacksFound && notebooksFound)
2056                         msg = msg1;
2057                 if (stacksFound && !notebooksFound)
2058                         msg = msg2;
2059                 if (QMessageBox.question(this, tr("Confirmation"), msg,
2060                         QMessageBox.StandardButton.Yes, 
2061                         QMessageBox.StandardButton.No)==StandardButton.No.value()) {
2062                         return;
2063                 }
2064                 
2065                 // If confirmed, delete the notebook
2066         for (int i=selections.size()-1; i>=0; i--) {
2067                 QTreeWidgetItem currentSelection;
2068                 currentSelection = selections.get(i);
2069                 String guid = currentSelection.text(2);
2070                 if (currentSelection.text(2).equalsIgnoreCase("STACK")) {
2071                         conn.getNotebookTable().renameStacks(currentSelection.text(0), "");
2072                         listManager.renameStack(currentSelection.text(0), "");
2073                 } else {
2074                         conn.getNotebookTable().expungeNotebook(guid, true);
2075                         listManager.deleteNotebook(guid);
2076                 }
2077         }
2078
2079                 notebookIndexUpdated();
2080 //        notebookTreeSelection();
2081 //        notebookTree.load(listManager.getNotebookIndex(), listManager.getLocalNotebooks());
2082 //        listManager.countNotebookResults(listManager.getNoteIndex());
2083         logger.log(logger.HIGH, "Entering NeverNote.deleteNotebook");
2084         }
2085         // A note's notebook has been updated
2086         @SuppressWarnings("unused")
2087         private void updateNoteNotebook(String guid, String notebookGuid) {
2088                 // ICHANGED 同じノートブックに入れられたノート間の履歴を登録
2089                 conn.getHistoryTable().addSameNotebookHistory(guid, notebookGuid);
2090                 
2091                 // Update the list manager
2092                 listManager.updateNoteNotebook(guid, notebookGuid);
2093                 listManager.countNotebookResults(listManager.getNoteIndex());
2094 //              notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());    
2095                 
2096                 // Find the name of the notebook
2097                 String notebookName = null;
2098                 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
2099                         if (listManager.getNotebookIndex().get(i).getGuid().equals(notebookGuid)) {
2100                                 notebookName = listManager.getNotebookIndex().get(i).getName();
2101                                 break;
2102                         }
2103                 }
2104                 
2105                 // If we found the name, update the browser window
2106                 if (notebookName != null) {
2107                         updateListNoteNotebook(guid, notebookName);
2108                         if (guid.equals(currentNoteGuid)) {
2109                                 int pos =  browserWindow.notebookBox.findText(notebookName);
2110                                 if (pos >=0)
2111                                         browserWindow.notebookBox.setCurrentIndex(pos);
2112                         }
2113                 }
2114                 
2115                 // If we're dealing with the current note, then we need to be sure and update the notebook there
2116                 if (guid.equals(currentNoteGuid)) {
2117                         if (currentNote != null) {
2118                                 currentNote.setNotebookGuid(notebookGuid);
2119                         }
2120                 }
2121         }
2122         // Open/close notebooks
2123         @SuppressWarnings("unused")
2124         private void closeNotebooks() {
2125                 NotebookArchive na = new NotebookArchive(listManager.getNotebookIndex(), listManager.getArchiveNotebookIndex());
2126                 na.exec();
2127                 if (!na.okClicked())
2128                         return;
2129                 
2130                 waitCursor(true);
2131                 listManager.getArchiveNotebookIndex().clear();
2132                 
2133                 for (int i=na.getClosedBookList().count()-1; i>=0; i--) {
2134                         String text = na.getClosedBookList().takeItem(i).text();
2135                         for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
2136                                 if (listManager.getNotebookIndex().get(j).getName().equalsIgnoreCase(text)) {
2137                                         Notebook n = listManager.getNotebookIndex().get(j);
2138                                         conn.getNotebookTable().setArchived(n.getGuid(),true);
2139                                         listManager.getArchiveNotebookIndex().add(n);
2140                                         j=listManager.getNotebookIndex().size();
2141                                 }
2142                         }
2143                 }
2144                 
2145                 for (int i=na.getOpenBookList().count()-1; i>=0; i--) {
2146                         String text = na.getOpenBookList().takeItem(i).text();
2147                         for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
2148                                 if (listManager.getNotebookIndex().get(j).getName().equalsIgnoreCase(text)) {
2149                                         Notebook n = listManager.getNotebookIndex().get(j);
2150                                         conn.getNotebookTable().setArchived(n.getGuid(),false);
2151                                         j=listManager.getNotebookIndex().size();
2152                                 }
2153                         }
2154                 }
2155                 notebookTreeSelection();
2156                 listManager.loadNotesIndex();
2157                 notebookIndexUpdated();
2158                 noteIndexUpdated(false);
2159                 reloadTagTree(true);
2160 //              noteIndexUpdated(false);
2161                 
2162                 // Build a list of non-closed notebooks
2163                 List<Notebook> nbooks = new ArrayList<Notebook>();
2164                 for (int i=0; i<listManager.getNotebookIndex().size(); i++) {
2165                         boolean found=false;
2166                         for (int j=0; j<listManager.getArchiveNotebookIndex().size(); j++) {
2167                                 if (listManager.getArchiveNotebookIndex().get(j).getGuid().equals(listManager.getNotebookIndex().get(i).getGuid()))
2168                                         found = true;
2169                         }
2170                         if (!found)
2171                                 nbooks.add(listManager.getNotebookIndex().get(i));
2172                 }
2173                 
2174                 FilterEditorNotebooks notebookFilter = new FilterEditorNotebooks(conn, logger);
2175                 List<Notebook> filteredBooks = notebookFilter.getValidNotebooks(currentNote, listManager.getNotebookIndex());
2176                 browserWindow.setNotebookList(filteredBooks);
2177                 
2178                 // Update any external windows
2179                 Iterator<String> set = externalWindows.keySet().iterator();
2180                 while(set.hasNext())
2181                         externalWindows.get(set.next()).getBrowserWindow().setNotebookList(filteredBooks);
2182                 
2183                 // ICHANGED
2184                 // 全てのタブウィンドウを更新
2185                 Iterator<Integer> it = tabWindows.keySet().iterator();
2186                 while (it.hasNext()) {
2187                         tabWindows.get(it.next()).getBrowserWindow()
2188                                         .setNotebookList(filteredBooks);
2189                 }
2190                 
2191                 waitCursor(false);
2192         }
2193         // Change the notebook's icon
2194         @SuppressWarnings("unused")
2195         private void setNotebookIcon() {
2196                 boolean stackSelected = false;
2197                 boolean allNotebookSelected = false;
2198                 
2199                 QTreeWidgetItem currentSelection;
2200                 List<QTreeWidgetItem> selections = notebookTree.selectedItems();
2201                 if (selections.size() == 0)
2202                         return;
2203                 
2204                 currentSelection = selections.get(0);   
2205                 String guid = currentSelection.text(2);
2206                 if (guid.equalsIgnoreCase(""))
2207                         allNotebookSelected = true;
2208                 if (guid.equalsIgnoreCase("STACK"))
2209                         stackSelected = true;
2210
2211                 QIcon currentIcon = currentSelection.icon(0);
2212                 QIcon icon;
2213                 SetIcon dialog;
2214                 
2215                 if (!stackSelected && !allNotebookSelected) {
2216                         icon = conn.getNotebookTable().getIcon(guid);
2217                         if (icon == null) {
2218                                 dialog = new SetIcon(currentIcon, saveLastPath);
2219                                 dialog.setUseDefaultIcon(true);
2220                         } else {
2221                                 dialog = new SetIcon(icon, saveLastPath);
2222                                 dialog.setUseDefaultIcon(false);
2223                         }
2224                 } else {
2225                         if (stackSelected) {
2226                                 icon = conn.getSystemIconTable().getIcon(currentSelection.text(0), "STACK");
2227                         } else {
2228                                 icon = conn.getSystemIconTable().getIcon(currentSelection.text(0), "ALLNOTEBOOK");                              
2229                         }
2230                         if (icon == null) {
2231                                 dialog = new SetIcon(currentIcon, saveLastPath);
2232                                 dialog.setUseDefaultIcon(true);
2233                         } else {
2234                                 dialog = new SetIcon(icon, saveLastPath);
2235                                 dialog.setUseDefaultIcon(false);
2236                         }
2237                 }
2238                 dialog.exec();
2239                 if (dialog.okPressed()) {
2240                 saveLastPath = dialog.getPath();
2241
2242                         QIcon newIcon = dialog.getIcon();
2243                         if (stackSelected) {
2244                                 conn.getSystemIconTable().setIcon(currentSelection.text(0), "STACK", newIcon, dialog.getFileType());
2245                                 if (newIcon == null) {
2246                                         newIcon = new QIcon(iconPath+"books2.png");
2247                                 }
2248                                 currentSelection.setIcon(0,newIcon);
2249                                 return;
2250                         }
2251                         if (allNotebookSelected) {
2252                                 conn.getSystemIconTable().setIcon(currentSelection.text(0), "ALLNOTEBOOK", newIcon, dialog.getFileType());
2253                                 if (newIcon == null) {
2254                                         newIcon = new QIcon(iconPath+"notebook-green.png");
2255                                 }
2256                                 currentSelection.setIcon(0,newIcon);
2257                                 return;
2258                         }
2259                         conn.getNotebookTable().setIcon(guid, newIcon, dialog.getFileType());
2260                         if (newIcon == null) {
2261                                 boolean isPublished = false;;
2262                                 boolean found = false;
2263                                 for (int i=0; i<listManager.getNotebookIndex().size() && !found; i++) {
2264                                         if (listManager.getNotebookIndex().get(i).getGuid().equals(guid)) {
2265                                                 isPublished = listManager.getNotebookIndex().get(i).isPublished();
2266                                                 found = true;
2267                                         }
2268                                 }
2269                                 newIcon = notebookTree.findDefaultIcon(guid, currentSelection.text(1), listManager.getLocalNotebooks(), isPublished);
2270                         }
2271                         currentSelection.setIcon(0, newIcon);
2272                 }
2273         
2274         }
2275         
2276         
2277     //***************************************************************
2278     //***************************************************************
2279     //** These functions deal with Tag menu items
2280     //***************************************************************
2281     //***************************************************************
2282         // Add a new notebook
2283         @SuppressWarnings("unused")
2284         private void addTag() {
2285                 logger.log(logger.HIGH, "Inside NeverNote.addTag");
2286                 TagEdit edit = new TagEdit();
2287                 edit.setTagList(listManager.getTagIndex());
2288
2289                 List<QTreeWidgetItem> selections = tagTree.selectedItems();
2290                 QTreeWidgetItem currentSelection = null;
2291                 if (selections.size() > 0) {
2292                         currentSelection = selections.get(0);
2293                         edit.setParentTag(currentSelection.text(0));
2294                 }
2295
2296                 edit.exec();
2297         
2298                 if (!edit.okPressed())
2299                         return;
2300         
2301                 Calendar currentTime = new GregorianCalendar();
2302                 Long l = new Long(currentTime.getTimeInMillis());
2303                 String randint = new String(Long.toString(l));
2304         
2305                 Tag newTag = new Tag();
2306                 newTag.setUpdateSequenceNum(0);
2307                 newTag.setGuid(randint);
2308                 newTag.setName(edit.getTag());
2309                 if (edit.getParentTag().isChecked()) {
2310                         newTag.setParentGuid(currentSelection.text(2));
2311                         newTag.setParentGuidIsSet(true);
2312                         currentSelection.setExpanded(true);
2313                 }
2314                 conn.getTagTable().addTag(newTag, true);
2315                 listManager.getTagIndex().add(newTag);
2316                 reloadTagTree(true);
2317                 
2318                 logger.log(logger.HIGH, "Leaving NeverNote.addTag");
2319         }
2320         @SuppressWarnings("unused")
2321         private void reloadTagTree() {
2322                 reloadTagTree(false);
2323         }
2324         private void reloadTagTree(boolean reload) {
2325                 logger.log(logger.HIGH, "Entering NeverNote.reloadTagTree");
2326                 tagIndexUpdated(reload);
2327                 boolean filter = false;
2328                 if (reload)
2329                         listManager.countTagResults(listManager.getNoteIndex());
2330                 if (notebookTree.selectedItems().size() > 0 
2331                                                   && !notebookTree.selectedItems().get(0).text(0).equalsIgnoreCase("All Notebooks"))
2332                                                   filter = true;
2333                 if (tagTree.selectedItems().size() > 0)
2334                         filter = true;
2335                 tagTree.showAllTags(!filter);
2336                 tagIndexUpdated(false);
2337                 logger.log(logger.HIGH, "Leaving NeverNote.reloadTagTree");
2338         }
2339         // Edit an existing tag
2340         @SuppressWarnings("unused")
2341         private void editTag() {
2342                 logger.log(logger.HIGH, "Entering NeverNote.editTag");
2343                 TagEdit edit = new TagEdit();
2344                 edit.setTitle("Edit Tag");
2345                 List<QTreeWidgetItem> selections = tagTree.selectedItems();
2346                 QTreeWidgetItem currentSelection;
2347                 currentSelection = selections.get(0);
2348                 edit.setTag(currentSelection.text(0));
2349                 edit.setTagList(listManager.getTagIndex());
2350                 edit.exec();
2351         
2352                 if (!edit.okPressed())
2353                         return;
2354         
2355                 String guid = currentSelection.text(2);
2356                 currentSelection.setText(0,edit.getTag());
2357                 
2358                 for (int i=0; i<listManager.getTagIndex().size(); i++) {
2359                         if (listManager.getTagIndex().get(i).getGuid().equals(guid)) {
2360                                 listManager.getTagIndex().get(i).setName(edit.getTag());
2361                                 conn.getTagTable().updateTag(listManager.getTagIndex().get(i), true);
2362                                 updateListTagName(guid);
2363                                 if (currentNote != null && currentNote.getTagGuids().contains(guid))
2364                                         browserWindow.setTag(getTagNamesForNote(currentNote));
2365                                 logger.log(logger.HIGH, "Leaving NeverNote.editTag");
2366                                 //return;
2367                         }
2368                 }
2369                 listManager.reloadNoteTagNames(guid, edit.getTag());
2370                 noteIndexUpdated(true);
2371                 refreshEvernoteNote(true);
2372                 browserWindow.setTag(getTagNamesForNote(currentNote));
2373                 logger.log(logger.HIGH, "Leaving NeverNote.editTag...");
2374         }
2375         // Delete an existing tag
2376         @SuppressWarnings("unused")
2377         private void deleteTag() {
2378                 logger.log(logger.HIGH, "Entering NeverNote.deleteTag");
2379                 
2380                 if (QMessageBox.question(this, tr("Confirmation"), tr("Delete the selected tags?"),
2381                         QMessageBox.StandardButton.Yes, 
2382                         QMessageBox.StandardButton.No)==StandardButton.No.value()) {
2383                                                         return;
2384                 }
2385                 
2386                 List<QTreeWidgetItem> selections = tagTree.selectedItems();
2387         for (int i=selections.size()-1; i>=0; i--) {
2388                 QTreeWidgetItem currentSelection;
2389                 currentSelection = selections.get(i);                   
2390                 removeTagItem(currentSelection.text(2));
2391         }
2392         tagIndexUpdated(true);
2393         tagTreeSelection();
2394         listManager.countTagResults(listManager.getNoteIndex());
2395 //              tagTree.updateCounts(listManager.getTagCounter());
2396         logger.log(logger.HIGH, "Leaving NeverNote.deleteTag");
2397         }
2398         // Remove a tag tree item.  Go recursively down & remove the children too
2399         private void removeTagItem(String guid) {
2400         for (int j=listManager.getTagIndex().size()-1; j>=0; j--) {             
2401                 String parent = listManager.getTagIndex().get(j).getParentGuid();
2402                 if (parent != null && parent.equals(guid)) {            
2403                         //Remove this tag's children
2404                         removeTagItem(listManager.getTagIndex().get(j).getGuid());
2405                 }
2406         }
2407         //Now, remove this tag
2408         removeListTagName(guid);
2409         conn.getTagTable().expungeTag(guid, true);                      
2410         for (int a=0; a<listManager.getTagIndex().size(); a++) {
2411                 if (listManager.getTagIndex().get(a).getGuid().equals(guid)) {
2412                         listManager.getTagIndex().remove(a);
2413                         return;
2414                 }
2415         }
2416         }
2417         // Setup the tree containing the user's tags
2418     private void initializeTagTree() {
2419         logger.log(logger.HIGH, "Entering NeverNote.initializeTagTree");
2420 //      tagTree.itemSelectionChanged.connect(this, "tagTreeSelection()");
2421 //      tagTree.itemClicked.connect(this, "tagTreeSelection()");
2422         tagTree.selectionSignal.connect(this, "tagTreeSelection()");
2423         listManager.tagSignal.refreshTagTreeCounts.connect(tagTree, "updateCounts(List)");
2424         logger.log(logger.HIGH, "Leaving NeverNote.initializeTagTree");
2425     }
2426     // Listener when a tag is selected
2427         private void tagTreeSelection() {
2428         logger.log(logger.HIGH, "Entering NeverNote.tagTreeSelection");
2429                 
2430         clearTrashFilter();
2431         clearAttributeFilter();
2432         clearSavedSearchFilter();
2433         
2434                 menuBar.noteRestoreAction.setVisible(false);
2435                 
2436                 // ICHANGED ゴミ箱から元の画面に戻す。連想ノートリストをONに。
2437                 if (!rensoNoteListDock.isEnabled()) {
2438                         rensoNoteListDock.setEnabled(true);
2439                 }
2440                 
2441         List<QTreeWidgetItem> selections = tagTree.selectedItems();
2442         QTreeWidgetItem currentSelection;
2443         selectedTagGUIDs.clear();
2444         for (int i=0; i<selections.size(); i++) {
2445                 currentSelection = selections.get(i);
2446                 selectedTagGUIDs.add(currentSelection.text(2));
2447         }
2448         if (selections.size() > 0) {
2449                 menuBar.tagEditAction.setEnabled(true);
2450                 menuBar.tagDeleteAction.setEnabled(true);
2451                 menuBar.tagIconAction.setEnabled(true);
2452         }
2453         else {
2454                 menuBar.tagEditAction.setEnabled(false);
2455                 menuBar.tagDeleteAction.setEnabled(false);
2456                 menuBar.tagIconAction.setEnabled(true);
2457         }
2458         if (selections.size() > 1)
2459                 menuBar.tagMergeAction.setEnabled(true);
2460         else
2461                 menuBar.tagMergeAction.setEnabled(false);
2462         listManager.setSelectedTags(selectedTagGUIDs);
2463         listManager.loadNotesIndex();
2464         noteIndexUpdated(false);
2465         refreshEvernoteNote(true);
2466         listManager.refreshCounters = true;
2467         listManager.refreshCounters();
2468         logger.log(logger.HIGH, "Leaving NeverNote.tagTreeSelection");
2469     }
2470     // trigger the tag index to be refreshed
2471     @SuppressWarnings("unused")
2472         private void tagIndexUpdated() {
2473         tagIndexUpdated(true);
2474     }
2475     private void tagIndexUpdated(boolean reload) {
2476         logger.log(logger.HIGH, "Entering NeverNote.tagIndexUpdated");
2477                 if (selectedTagGUIDs == null)
2478                         selectedTagGUIDs = new ArrayList<String>();
2479                 if (reload)
2480                         listManager.reloadTagIndex();
2481
2482                 tagTree.blockSignals(true);
2483                 if (reload) {
2484                         tagTree.setIcons(conn.getTagTable().getAllIcons());
2485                         tagTree.load(listManager.getTagIndex());
2486                 }
2487
2488         for (int i=selectedTagGUIDs.size()-1; i>=0; i--) {
2489                 boolean found = tagTree.selectGuid(selectedTagGUIDs.get(i));
2490                 if (!found)
2491                         selectedTagGUIDs.remove(i);
2492         }
2493         tagTree.blockSignals(false);
2494         
2495                 browserWindow.setTag(getTagNamesForNote(currentNote));
2496         logger.log(logger.HIGH, "Leaving NeverNote.tagIndexUpdated");
2497     }   
2498     // Show/Hide note information
2499         @SuppressWarnings("unused")
2500         private void toggleTagWindow() {
2501                 logger.log(logger.HIGH, "Entering NeverNote.toggleTagWindow");
2502         if (tagTree.isVisible())
2503                 tagTree.hide();
2504         else
2505                 tagTree.show();
2506         menuBar.hideTags.setChecked(tagTree.isVisible());
2507         Global.saveWindowVisible("tagTree", tagTree.isVisible());
2508         logger.log(logger.HIGH, "Leaving NeverNote.toggleTagWindow");
2509     }   
2510         // A note's tags have been updated
2511         @SuppressWarnings("unused")
2512         private void updateNoteTags(String guid, List<String> tags) {
2513                 // Save any new tags.  We'll need them later.
2514                 List<String> newTags = new ArrayList<String>();
2515                 for (int i=0; i<tags.size(); i++) {
2516                         if (conn.getTagTable().findTagByName(tags.get(i))==null) 
2517                                 newTags.add(tags.get(i));
2518                 }
2519                 
2520                 listManager.saveNoteTags(guid, tags, true);
2521                 listManager.countTagResults(listManager.getNoteIndex());
2522                 StringBuffer names = new StringBuffer("");
2523                 for (int i=0; i<tags.size(); i++) {
2524                         names = names.append(tags.get(i));
2525                         if (i<tags.size()-1) {
2526                                 names.append(Global.tagDelimeter + " ");
2527                         }
2528                 }
2529                 browserWindow.setTag(names.toString());
2530                 
2531                 // ICHANGED
2532                 for (TabBrowse tab: tabWindows.values()) {
2533                         if (tab.getBrowserWindow().getNote().getGuid().equals(guid)) {
2534                                 int index = tabBrowser.indexOf(tab);
2535                                 noteDirty.put(index, true);
2536                                 break;
2537                         }
2538                 }
2539                 
2540                 // Now, we need to add any new tags to the tag tree
2541                 for (int i=0; i<newTags.size(); i++) 
2542                         tagTree.insertTag(newTags.get(i), conn.getTagTable().findTagByName(newTags.get(i)));
2543         }
2544         // Get a string containing all tag names for a note
2545         private String getTagNamesForNote(Note n) {
2546                 logger.log(logger.HIGH, "Entering NeverNote.getTagNamesForNote");
2547                 if (n==null || n.getGuid() == null || n.getGuid().equals(""))
2548                         return "";
2549                 StringBuffer buffer = new StringBuffer(100);
2550                 Vector<String> v = new Vector<String>();
2551                 List<String> guids = n.getTagGuids();
2552                 
2553                 if (guids == null) 
2554                         return "";
2555                 
2556                 for (int i=0; i<guids.size(); i++) {
2557                         v.add(listManager.getTagNameByGuid(guids.get(i)));
2558                 }
2559                 Comparator<String> comparator = Collections.reverseOrder();
2560                 Collections.sort(v,comparator);
2561                 Collections.reverse(v);
2562                 
2563                 for (int i = 0; i<v.size(); i++) {
2564                         if (i>0) 
2565                                 buffer.append(", ");
2566                         buffer.append(v.get(i));
2567                 }
2568                 
2569                 logger.log(logger.HIGH, "Leaving NeverNote.getTagNamesForNote");
2570                 return buffer.toString();
2571         }       
2572         // Tags were added via dropping notes from the note list
2573         @SuppressWarnings("unused")
2574         private void tagsAdded(String noteGuid, String tagGuid) {
2575                 String tagName = null;
2576                 for (int i=0; i<listManager.getTagIndex().size(); i++) {
2577                         if (listManager.getTagIndex().get(i).getGuid().equals(tagGuid)) {
2578                                 tagName = listManager.getTagIndex().get(i).getName();
2579                                 i=listManager.getTagIndex().size();
2580                         }
2581                 }
2582                 if (tagName == null)
2583                         return;
2584                 
2585                 for (int i=0; i<listManager.getMasterNoteIndex().size(); i++) {
2586                         if (listManager.getMasterNoteIndex().get(i).getGuid().equals(noteGuid)) {
2587                                 List<String> tagNames = new ArrayList<String>();
2588                                 tagNames.add(new String(tagName));
2589                                 Note n = listManager.getMasterNoteIndex().get(i);
2590                                 for (int j=0; j<n.getTagNames().size(); j++) {
2591                                         tagNames.add(new String(n.getTagNames().get(j)));
2592                                 }
2593                                 listManager.getNoteTableModel().updateNoteTags(noteGuid, n.getTagGuids(), tagNames);
2594                                 if (n.getGuid().equals(currentNoteGuid)) {
2595                                         Collections.sort(tagNames);
2596                                         String display = "";
2597                                         for (int j=0; j<tagNames.size(); j++) {
2598                                                 display = display+tagNames.get(j);
2599                                                 if (j+2<tagNames.size()) 
2600                                                         display = display+Global.tagDelimeter+" ";
2601                                         }
2602                                         browserWindow.setTag(display);
2603                                 }
2604                                 i=listManager.getMasterNoteIndex().size();
2605                         }
2606                 }
2607                 
2608                 
2609                 listManager.getNoteTableModel().updateNoteSyncStatus(noteGuid, false);
2610         }
2611         private void clearTagFilter() {
2612                 tagTree.blockSignals(true);
2613                 tagTree.clearSelection();
2614                 menuBar.noteRestoreAction.setVisible(false);
2615                 menuBar.tagEditAction.setEnabled(false);
2616                 menuBar.tagMergeAction.setEnabled(false);
2617                 menuBar.tagDeleteAction.setEnabled(false);
2618                 menuBar.tagIconAction.setEnabled(false);
2619                 selectedTagGUIDs.clear();
2620         listManager.setSelectedTags(selectedTagGUIDs);
2621         tagTree.blockSignals(false);
2622         }
2623         // Change the icon for a tag
2624         @SuppressWarnings("unused")
2625         private void setTagIcon() {
2626                 QTreeWidgetItem currentSelection;
2627                 List<QTreeWidgetItem> selections = tagTree.selectedItems();
2628                 if (selections.size() == 0)
2629                         return;
2630                 
2631                 currentSelection = selections.get(0);   
2632                 String guid = currentSelection.text(2);
2633
2634                 QIcon currentIcon = currentSelection.icon(0);
2635                 QIcon icon = conn.getTagTable().getIcon(guid);
2636                 SetIcon dialog;
2637                 if (icon == null) {
2638                         dialog = new SetIcon(currentIcon, saveLastPath);
2639                         dialog.setUseDefaultIcon(true);
2640                 } else {
2641                         dialog = new SetIcon(icon, saveLastPath);
2642                         dialog.setUseDefaultIcon(false);
2643                 }
2644                 dialog.exec();
2645                 if (dialog.okPressed()) {
2646                 saveLastPath = dialog.getPath();
2647                         QIcon newIcon = dialog.getIcon();
2648                         conn.getTagTable().setIcon(guid, newIcon, dialog.getFileType());
2649                         if (newIcon == null) 
2650                                 newIcon = new QIcon(iconPath+"tag.png");
2651                         currentSelection.setIcon(0, newIcon);
2652                 }
2653         
2654         }
2655         // Merge tags
2656         @SuppressWarnings("unused")
2657         private void mergeTags() {
2658                 List<Tag> tags = new ArrayList<Tag>();
2659                 List<QTreeWidgetItem> selections = tagTree.selectedItems();
2660                 for (int i=0; i<selections.size(); i++) {
2661                         Tag record = new Tag();
2662                         record.setGuid(selections.get(i).text(2));
2663                         record.setName(selections.get(i).text(0));
2664                         tags.add(record);
2665                 }
2666
2667                 TagMerge mergeDialog = new TagMerge(tags);
2668                 mergeDialog.exec();
2669                 if (!mergeDialog.okClicked())
2670                         return;
2671                 String newGuid = mergeDialog.getNewTagGuid();
2672                 
2673                 for (int i=0; i<tags.size(); i++) {
2674                         if (!tags.get(i).getGuid().equals(newGuid)) {
2675                                 List<String> noteGuids = conn.getNoteTable().noteTagsTable.getTagNotes(tags.get(i).getGuid());
2676                                 for (int j=0; j<noteGuids.size(); j++) {
2677                                         String noteGuid = noteGuids.get(j);
2678                                         conn.getNoteTable().noteTagsTable.deleteNoteTag(noteGuid);
2679                                         if (!conn.getNoteTable().noteTagsTable.checkNoteNoteTags(noteGuid, newGuid))
2680                                                 conn.getNoteTable().noteTagsTable.saveNoteTag(noteGuid, newGuid, true);
2681                                 }
2682                         }
2683                 }
2684                 listManager.reloadIndexes();
2685         }
2686         
2687     //***************************************************************
2688     //***************************************************************
2689     //** These functions deal with Saved Search menu items
2690     //***************************************************************
2691     //***************************************************************
2692         // Add a new notebook
2693         @SuppressWarnings("unused")
2694         private void addSavedSearch() {
2695                 logger.log(logger.HIGH, "Inside NeverNote.addSavedSearch");
2696                 SavedSearchEdit edit = new SavedSearchEdit();
2697                 edit.setSearchList(listManager.getSavedSearchIndex());
2698                 edit.exec();
2699         
2700                 if (!edit.okPressed())
2701                         return;
2702         
2703                 Calendar currentTime = new GregorianCalendar();         
2704                 Long l = new Long(currentTime.getTimeInMillis());
2705                 String randint = new String(Long.toString(l));
2706         
2707                 SavedSearch search = new SavedSearch();
2708                 search.setUpdateSequenceNum(0);
2709                 search.setGuid(randint);
2710                 search.setName(edit.getName());
2711                 search.setQuery(edit.getQuery());
2712                 search.setFormat(QueryFormat.USER);
2713                 listManager.getSavedSearchIndex().add(search);
2714                 conn.getSavedSearchTable().addSavedSearch(search, true);
2715                 savedSearchIndexUpdated();
2716                 logger.log(logger.HIGH, "Leaving NeverNote.addSavedSearch");
2717         }
2718         // Edit an existing tag
2719         @SuppressWarnings("unused")
2720         private void editSavedSearch() {
2721                 logger.log(logger.HIGH, "Entering NeverNote.editSavedSearch");
2722                 SavedSearchEdit edit = new SavedSearchEdit();
2723                 edit.setTitle(tr("Edit Search"));
2724                 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
2725                 QTreeWidgetItem currentSelection;
2726                 currentSelection = selections.get(0);
2727                 String guid = currentSelection.text(1);
2728                 SavedSearch s = conn.getSavedSearchTable().getSavedSearch(guid);
2729                 edit.setName(currentSelection.text(0));
2730                 edit.setQuery(s.getQuery());
2731                 edit.setSearchList(listManager.getSavedSearchIndex());
2732                 edit.exec();
2733         
2734                 if (!edit.okPressed())
2735                         return;
2736         
2737                 List<SavedSearch> list = listManager.getSavedSearchIndex();
2738                 SavedSearch search = null;
2739                 boolean found = false;
2740                 for (int i=0; i<list.size(); i++) {
2741                         search = list.get(i);
2742                         if (search.getGuid().equals(guid)) {
2743                                 i=list.size();
2744                                 found = true;
2745                         }
2746                 }
2747                 if (!found)
2748                         return;
2749                 search.setName(edit.getName());
2750                 search.setQuery(edit.getQuery());
2751                 conn.getSavedSearchTable().updateSavedSearch(search, true);
2752                 savedSearchIndexUpdated();
2753                 logger.log(logger.HIGH, "Leaving NeverNote.editSavedSearch");
2754         }
2755         // Delete an existing tag
2756         @SuppressWarnings("unused")
2757         private void deleteSavedSearch() {
2758                 logger.log(logger.HIGH, "Entering NeverNote.deleteSavedSearch");
2759                 
2760                 if (QMessageBox.question(this, tr("Confirmation"), tr("Delete the selected search?"),
2761                         QMessageBox.StandardButton.Yes, 
2762                         QMessageBox.StandardButton.No)==StandardButton.No.value()) {
2763                                                         return;
2764                 }
2765                 
2766                 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
2767         for (int i=selections.size()-1; i>=0; i--) {
2768                 QTreeWidgetItem currentSelection;
2769                 currentSelection = selections.get(i);
2770                 for (int j=0; j<listManager.getSavedSearchIndex().size(); j++) {
2771                         if (listManager.getSavedSearchIndex().get(j).getGuid().equals(currentSelection.text(1))) {
2772                                 conn.getSavedSearchTable().expungeSavedSearch(listManager.getSavedSearchIndex().get(j).getGuid(), true);
2773                                 listManager.getSavedSearchIndex().remove(j);
2774                                 j=listManager.getSavedSearchIndex().size()+1;
2775                         }
2776                 }
2777                 selections.remove(i);
2778         }
2779         savedSearchIndexUpdated();
2780         logger.log(logger.HIGH, "Leaving NeverNote.deleteSavedSearch");
2781         }
2782     // Setup the tree containing the user's tags
2783     private void initializeSavedSearchTree() {
2784         logger.log(logger.HIGH, "Entering NeverNote.initializeSavedSearchTree");
2785         savedSearchTree.itemSelectionChanged.connect(this, "savedSearchTreeSelection()");
2786         logger.log(logger.HIGH, "Leaving NeverNote.initializeSavedSearchTree");
2787     }
2788     // Listener when a tag is selected
2789     @SuppressWarnings("unused")
2790         private void savedSearchTreeSelection() {
2791         logger.log(logger.HIGH, "Entering NeverNote.savedSearchTreeSelection");
2792
2793         clearNotebookFilter();
2794         clearTagFilter();
2795         clearTrashFilter();
2796         clearAttributeFilter();
2797         
2798         String currentGuid = selectedSavedSearchGUID;
2799         menuBar.savedSearchEditAction.setEnabled(true);
2800         menuBar.savedSearchDeleteAction.setEnabled(true);
2801         menuBar.savedSearchIconAction.setEnabled(true);
2802         
2803                 // ICHANGED ゴミ箱から元の画面に戻す。連想ノートリストをONに。
2804                 if (!rensoNoteListDock.isEnabled()) {
2805                         rensoNoteListDock.setEnabled(true);
2806                 }
2807                 
2808         List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
2809         QTreeWidgetItem currentSelection;
2810         selectedSavedSearchGUID = "";
2811         for (int i=0; i<selections.size(); i++) {
2812                 currentSelection = selections.get(i);
2813                 if (currentSelection.text(1).equals(currentGuid)) {
2814                         currentSelection.setSelected(false);
2815                 } else {
2816                         selectedSavedSearchGUID = currentSelection.text(1);
2817                 }
2818 //              i = selections.size() +1;
2819         }
2820         
2821         // There is the potential for no notebooks to be selected if this 
2822         // happens then we make it look like all notebooks were selecetd.
2823         // If that happens, just select the "all notebooks"
2824         if (selections.size()==0) {
2825                 clearSavedSearchFilter();
2826         }
2827         listManager.setSelectedSavedSearch(selectedSavedSearchGUID);
2828         
2829         logger.log(logger.HIGH, "Leaving NeverNote.savedSearchTreeSelection");
2830     }
2831     private void clearSavedSearchFilter() {
2832         menuBar.savedSearchEditAction.setEnabled(false);
2833         menuBar.savedSearchDeleteAction.setEnabled(false);
2834         menuBar.savedSearchIconAction.setEnabled(false);
2835         savedSearchTree.blockSignals(true);
2836         savedSearchTree.clearSelection();
2837         savedSearchTree.blockSignals(false);
2838         selectedSavedSearchGUID = "";
2839         searchField.setEditText("");
2840         searchPerformed = false;
2841         listManager.setSelectedSavedSearch(selectedSavedSearchGUID);
2842     }
2843     // trigger the tag index to be refreshed
2844         private void savedSearchIndexUpdated() { 
2845                 if (selectedSavedSearchGUID == null)
2846                         selectedSavedSearchGUID = new String();
2847                 savedSearchTree.blockSignals(true);
2848                 savedSearchTree.setIcons(conn.getSavedSearchTable().getAllIcons());
2849         savedSearchTree.load(listManager.getSavedSearchIndex());
2850         savedSearchTree.selectGuid(selectedSavedSearchGUID);
2851         savedSearchTree.blockSignals(false);
2852     }
2853     // trigger when the saved search selection changes
2854     @SuppressWarnings("unused")
2855         private void updateSavedSearchSelection() {
2856                 logger.log(logger.HIGH, "Entering NeverNote.updateSavedSearchSelection()");
2857                 
2858         menuBar.savedSearchEditAction.setEnabled(true);
2859         menuBar.savedSearchDeleteAction.setEnabled(true);
2860         menuBar.savedSearchIconAction.setEnabled(true);
2861         List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
2862
2863         if (selections.size() > 0) {
2864                 menuBar.savedSearchEditAction.setEnabled(true);
2865                 menuBar.savedSearchDeleteAction.setEnabled(true);
2866                 menuBar.savedSearchIconAction.setEnabled(true);
2867                 selectedSavedSearchGUID = selections.get(0).text(1);
2868                 SavedSearch s = conn.getSavedSearchTable().getSavedSearch(selectedSavedSearchGUID);
2869                 searchField.setEditText(s.getQuery());
2870         } else { 
2871                 menuBar.savedSearchEditAction.setEnabled(false);
2872                 menuBar.savedSearchDeleteAction.setEnabled(false);
2873                 menuBar.savedSearchIconAction.setEnabled(false);
2874                 selectedSavedSearchGUID = "";
2875                 searchField.setEditText("");
2876         }
2877         searchFieldChanged();
2878         
2879                 logger.log(logger.HIGH, "Leaving NeverNote.updateSavedSearchSelection()");
2880
2881         
2882     }
2883     // Show/Hide note information
2884         @SuppressWarnings("unused")
2885         private void toggleSavedSearchWindow() {
2886                 logger.log(logger.HIGH, "Entering NeverNote.toggleSavedSearchWindow");
2887         if (savedSearchTree.isVisible())
2888                 savedSearchTree.hide();
2889         else
2890                 savedSearchTree.show();
2891         menuBar.hideSavedSearches.setChecked(savedSearchTree.isVisible());
2892                                 
2893                 Global.saveWindowVisible("savedSearchTree", savedSearchTree.isVisible());
2894         logger.log(logger.HIGH, "Leaving NeverNote.toggleSavedSearchWindow");
2895     }
2896         // Change the icon for a saved search
2897         @SuppressWarnings("unused")
2898         private void setSavedSearchIcon() {
2899                 QTreeWidgetItem currentSelection;
2900                 List<QTreeWidgetItem> selections = savedSearchTree.selectedItems();
2901                 if (selections.size() == 0)
2902                         return;
2903                 
2904                 currentSelection = selections.get(0);   
2905                 String guid = currentSelection.text(1);
2906
2907                 QIcon currentIcon = currentSelection.icon(0);
2908                 QIcon icon = conn.getSavedSearchTable().getIcon(guid);
2909                 SetIcon dialog;
2910                 if (icon == null) {
2911                         dialog = new SetIcon(currentIcon, saveLastPath);
2912                         dialog.setUseDefaultIcon(true);
2913                 } else {
2914                         dialog = new SetIcon(icon, saveLastPath);
2915                         dialog.setUseDefaultIcon(false);
2916                 }
2917                 dialog.exec();
2918                 if (dialog.okPressed()) {
2919                 saveLastPath = dialog.getPath();
2920                         QIcon newIcon = dialog.getIcon();
2921                         conn.getSavedSearchTable().setIcon(guid, newIcon, dialog.getFileType());
2922                         if (newIcon == null) 
2923                                 newIcon = new QIcon(iconPath+"search.png");
2924                         currentSelection.setIcon(0, newIcon);
2925                 }
2926         
2927         }
2928         
2929         
2930         
2931         
2932     //***************************************************************
2933     //***************************************************************
2934     //** These functions deal with Help menu & tool menu items
2935     //***************************************************************
2936     //***************************************************************
2937         // Show database status
2938         @SuppressWarnings("unused")
2939         private void databaseStatus() {
2940                 waitCursor(true);
2941                 indexRunner.interrupt = true;
2942                 int dirty = conn.getNoteTable().getDirtyCount();
2943                 int unindexed = conn.getNoteTable().getUnindexedCount();
2944                 DatabaseStatus status = new DatabaseStatus();
2945                 status.setUnsynchronized(dirty);
2946                 status.setUnindexed(unindexed);
2947                 status.setNoteCount(conn.getNoteTable().getNoteCount());
2948                 status.setNotebookCount(listManager.getNotebookIndex().size());
2949                 status.setUnindexedResourceCount(conn.getNoteTable().noteResourceTable.getUnindexedCount());
2950                 status.setSavedSearchCount(listManager.getSavedSearchIndex().size());
2951                 status.setTagCount(listManager.getTagIndex().size());
2952                 status.setResourceCount(conn.getNoteTable().noteResourceTable.getResourceCount());
2953                 status.setWordCount(conn.getWordsTable().getWordCount());
2954                 waitCursor(false);
2955                 status.exec();
2956         }
2957         // Compact the database
2958         @SuppressWarnings("unused")
2959         private void compactDatabase() {
2960         logger.log(logger.HIGH, "Entering NeverNote.compactDatabase");
2961                 if (QMessageBox.question(this, tr("Confirmation"), tr("This will free unused space in the database, "+
2962                                 "but please be aware that depending upon the size of your database this can be time consuming " +
2963                                 "and NeighborNote will be unresponsive until it is complete.  Do you wish to continue?"),
2964                                 QMessageBox.StandardButton.Yes, 
2965                                 QMessageBox.StandardButton.No)==StandardButton.No.value() && Global.verifyDelete() == true) {
2966                                                         return;
2967                 }
2968                 setMessage("Compacting database.");
2969                 waitCursor(true);
2970                 listManager.compactDatabase();
2971                 waitCursor(false);
2972                 setMessage("Database compact is complete.");            
2973         logger.log(logger.HIGH, "Leaving NeverNote.compactDatabase");
2974     }
2975         @SuppressWarnings("unused")
2976         private void accountInformation() {
2977                 logger.log(logger.HIGH, "Entering NeverNote.accountInformation");
2978                 AccountDialog dialog = new AccountDialog();
2979                 dialog.show();
2980                 logger.log(logger.HIGH, "Leaving NeverNote.accountInformation");
2981         }
2982         @SuppressWarnings("unused")
2983         private void releaseNotes() {
2984                 logger.log(logger.HIGH, "Entering NeverNote.releaseNotes");
2985                 QDialog dialog = new QDialog(this);
2986                 QHBoxLayout layout = new QHBoxLayout();
2987                 QTextEdit textBox = new QTextEdit();
2988                 layout.addWidget(textBox);
2989                 textBox.setReadOnly(true);
2990                 QFile file = new QFile(Global.getFileManager().getProgramDirPath("release.txt"));
2991                 if (!file.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly,
2992                 QIODevice.OpenModeFlag.Text)))
2993                         return;
2994                 // ICHANGED 日本語文字化け対策
2995                 QTextCodec codec = QTextCodec.codecForName("UTF-8");
2996                 QTextStream textStream = new QTextStream(file);
2997                 textStream.setCodec(codec);
2998                 textBox.setText(textStream.readAll().toString());
2999                 
3000                 file.close();
3001                 dialog.setWindowTitle(tr("Release Notes"));
3002                 dialog.setLayout(layout);
3003                 dialog.show();
3004                 logger.log(logger.HIGH, "Leaving NeverNote.releaseNotes");
3005         }
3006         // Called when user picks Log from the help menu
3007         @SuppressWarnings("unused")
3008         private void logger() {
3009                 logger.log(logger.HIGH, "Entering NeverNote.logger");
3010                 LogFileDialog dialog = new LogFileDialog(emitLog);
3011                 dialog.exec();
3012                 logger.log(logger.HIGH, "Leaving NeverNote.logger");
3013         }
3014         // Menu option "help/about" was selected
3015         @SuppressWarnings("unused")
3016         private void about() {
3017                 logger.log(logger.HIGH, "Entering NeverNote.about");
3018                 // ICHANGED based on...の記述を付加
3019                 QMessageBox.about(this, 
3020                                                 tr("About NeighborNote"),
3021                                                 tr("<h4><center><b>NeighborNote</b></center></h4><hr><center>Version ")
3022                                                 +Global.version + "(based on NixNote 1.5)"
3023                                                 //+"1.2.120724"
3024                                                 +tr("<hr>"
3025                                               &nbs