OSDN Git Service

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