OSDN Git Service

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