OSDN Git Service

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