OSDN Git Service

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