OSDN Git Service

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