OSDN Git Service

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