OSDN Git Service

loggerを修正した
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / RensoNoteList.java
index c3f829b..6a1f2fe 100644 (file)
@@ -23,10 +23,13 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import com.evernote.edam.type.Note;
 import com.trolltech.qt.QThread;
+import com.trolltech.qt.core.QByteArray;
+import com.trolltech.qt.core.QFile;
 import com.trolltech.qt.core.QSize;
 import com.trolltech.qt.core.Qt.MouseButton;
 import com.trolltech.qt.gui.QAction;
@@ -39,7 +42,9 @@ import com.trolltech.qt.gui.QMenu;
 import cx.fbn.nevernote.Global;
 import cx.fbn.nevernote.NeverNote;
 import cx.fbn.nevernote.sql.DatabaseConnection;
+import cx.fbn.nevernote.threads.CounterRunner;
 import cx.fbn.nevernote.threads.ENRelatedNotesRunner;
+import cx.fbn.nevernote.threads.ENThumbnailRunner;
 import cx.fbn.nevernote.threads.SyncRunner;
 import cx.fbn.nevernote.utilities.ApplicationLogger;
 import cx.fbn.nevernote.utilities.Pair;
@@ -48,7 +53,7 @@ public class RensoNoteList extends QListWidget {
        private final DatabaseConnection conn;
        private final ApplicationLogger logger;
        private final HashMap<QListWidgetItem, String> rensoNoteListItems;
-       private final List<RensoNoteListItem> rensoNoteListTrueItems;
+       private final HashMap<String, RensoNoteListItem> rensoNoteListTrueItems;
        private String rensoNotePressedItemGuid;
        private final QAction openNewTabAction;
        private final QAction starAction;
@@ -61,6 +66,8 @@ public class RensoNoteList extends QListWidget {
        private final ENRelatedNotesRunner enRelatedNotesRunner;
        private final QThread enRelatedNotesThread;
        private final HashMap<String, List<String>> enRelatedNotesCache;        // Evernote関連ノートのキャッシュ<guid, 関連ノートリスト>
+       private final ENThumbnailRunner enThumbnailRunner;
+       private final QThread enThumbnailThread;
        private String guid;
        private int allPointSum;
 
@@ -76,14 +83,22 @@ public class RensoNoteList extends QListWidget {
                this.guid = new String();
                mergedHistory = new HashMap<String, Integer>();
                enRelatedNotesCache = new HashMap<String, List<String>>();
-               this.enRelatedNotesRunner = new ENRelatedNotesRunner(this.syncRunner, this.logger);
+               this.enRelatedNotesRunner = new ENRelatedNotesRunner(this.syncRunner, "enRelatedNotesRunner.log");
                this.enRelatedNotesRunner.enRelatedNotesSignal.getENRelatedNotesFinished.connect(this, "enRelatedNotesComplete()");
                this.enRelatedNotesRunner.limitSignal.rateLimitReached.connect(parent, "informRateLimit(Integer)");
                this.enRelatedNotesThread = new QThread(enRelatedNotesRunner, "ENRelatedNotes Thread");
                this.getEnRelatedNotesThread().start();
                
+               this.enThumbnailRunner = new ENThumbnailRunner("enThumbnailRunner.log", CounterRunner.NOTEBOOK, 
+                                       Global.getDatabaseUrl(), Global.getIndexDatabaseUrl(), Global.getResourceDatabaseUrl(), Global.getBehaviorDatabaseUrl(),
+                                       Global.getDatabaseUserid(), Global.getDatabaseUserPassword(), Global.cipherPassword);
+               this.enThumbnailRunner.enThumbnailSignal.getENThumbnailFinished.connect(this, "enThumbnailComplete(String)");
+               this.enThumbnailRunner.limitSignal.rateLimitReached.connect(parent, "informRateLimit(Integer)");
+               this.enThumbnailThread = new QThread(enThumbnailRunner, "ENThumbnail Thread");
+               this.enThumbnailThread.start();
+               
                rensoNoteListItems = new HashMap<QListWidgetItem, String>();
-               rensoNoteListTrueItems = new ArrayList<RensoNoteListItem>();
+               rensoNoteListTrueItems = new HashMap<String, RensoNoteListItem>();
                
                this.itemPressed.connect(this, "rensoNoteItemPressed(QListWidgetItem)");
                
@@ -255,6 +270,9 @@ public class RensoNoteList extends QListWidget {
        private void addRensoNoteList(HashMap<String, Integer> History){
                logger.log(logger.EXTREME, "Entering RensoNoteList.addRensoNoteList");
                
+               enThumbnailRunner.setUser(Global.getUserInformation());
+               enThumbnailRunner.setServerUrl(Global.getServer());
+               
                String currentNoteGuid = new String(parent.getCurrentNoteGuid());
                
                // スター付きノートとスター無しノートを分ける
@@ -307,6 +325,18 @@ public class RensoNoteList extends QListWidget {
                                
                                // 存在していて、かつ関連度0でなければノート情報を取得して連想ノートリストに追加
                                if (isNoteActive && maxNum > 0) {
+                                       // Evernoteサムネイルが取得済みか確認。未取得ならサムネイル取得スレッドにキュー
+                                       if (Global.isConnected) {
+                                               String thumbnailName = Global.getFileManager().getResDirPath("enThumbnail-" + maxGuid + ".png");
+                                               QFile thumbnail = new QFile(thumbnailName);
+                                               if (!thumbnail.exists()) {      // Evernoteサムネイルがファイルとして存在しない
+                                                       QByteArray data = conn.getNoteTable().getENThumbnail(maxGuid);
+                                                       if (data == null) {     // Evernoteサムネイル未取得
+                                                               enThumbnailRunner.addGuid(maxGuid);
+                                                       }
+                                               }
+                                       }
+                                       
                                        // スター付きか確認
                                        boolean isStared;
                                        isStared = conn.getStaredTable().existNote(currentNoteGuid, maxGuid);
@@ -317,7 +347,7 @@ public class RensoNoteList extends QListWidget {
                                        this.addItem(item);
                                        this.setItemWidget(item, myItem);
                                        rensoNoteListItems.put(item, maxGuid);
-                                       rensoNoteListTrueItems.add(myItem);
+                                       rensoNoteListTrueItems.put(maxGuid, myItem);
                                } else {
                                        break;
                                }
@@ -374,8 +404,7 @@ public class RensoNoteList extends QListWidget {
        // コンテキストメニューが閉じられた時
        @SuppressWarnings("unused")
        private void contextMenuHidden() {
-               for (int i = 0; i < rensoNoteListTrueItems.size(); i++) {
-                       RensoNoteListItem item = rensoNoteListTrueItems.get(i);
+               for (RensoNoteListItem item : rensoNoteListTrueItems.values()) {
                        item.setDefaultBackground();
                }
        }
@@ -445,12 +474,17 @@ public class RensoNoteList extends QListWidget {
        public boolean stopThread() {
                logger.log(logger.HIGH, "Entering RensoNoteList.stopThread");
                
-               if (enRelatedNotesRunner.addStop()) {
-                       logger.log(logger.HIGH, "RensoNoteList.stopThread succeeded");
-                       return true;
+               if (!enRelatedNotesRunner.addStop()) {
+                       logger.log(logger.HIGH, "RensoNoteList.stopThread failed(enRelatedNotesRunner)");
+                       return false;
                }
-               logger.log(logger.HIGH, "RensoNoteList.stopThread failed");
-               return false;
+               if (!enThumbnailRunner.addStop()) {
+                       logger.log(logger.HIGH, "RensoNoteList.stopThread failed(enThumbnailRunner)");
+                       return false;
+               }
+               
+               logger.log(logger.HIGH, "RensoNoteList.stopThread succeeded");
+               return true;
        }
 
        public QThread getEnRelatedNotesThread() {
@@ -475,4 +509,23 @@ public class RensoNoteList extends QListWidget {
                
                return dstHistory;
        }
+       
+       /**
+        * Evernoteサムネイルの取得が完了
+        * 
+        * @param guid 現在開いているノートのguid
+        */
+       @SuppressWarnings("unused")
+       private void enThumbnailComplete(String guid) {
+               logger.log(logger.HIGH, "Entering RensoNoteList.enThumbnailComplete");
+               
+               for (Map.Entry<String, RensoNoteListItem> e : rensoNoteListTrueItems.entrySet()) {
+                       // サムネイル取得が完了したノートが現在の連想ノートリストに表示されていたら再描画
+                       if (guid.equals(e.getKey())) {
+                               e.getValue().repaint();
+                       }
+               }
+               
+               logger.log(logger.HIGH, "Leaving RensoNoteList.enThumbnailComplete");
+       }
 }