OSDN Git Service

Allow customizing of notebook icons.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / NotebookTreeWidget.java
index 896b1a8..c0a172f 100644 (file)
@@ -20,6 +20,7 @@
 package cx.fbn.nevernote.gui;\r
 \r
 import java.util.ArrayList;\r
+import java.util.HashMap;\r
 import java.util.List;\r
 \r
 import com.evernote.edam.type.Notebook;\r
@@ -48,7 +49,9 @@ public class NotebookTreeWidget extends QTreeWidget {
        private QAction                                 deleteAction;\r
        private QAction                                 addAction;\r
        private QAction                                 editAction;\r
+       private QAction                                 iconAction;\r
        public NoteSignal                               noteSignal;\r
+       private HashMap<String, QIcon>  icons;\r
 //     private final QTreeWidgetItem                   previousMouseOver;\r
 //     private boolean                                 previousMouseOverWasSelected;\r
        \r
@@ -64,6 +67,10 @@ public class NotebookTreeWidget extends QTreeWidget {
                editAction = e;\r
        }\r
        \r
+       public void setIconAction(QAction e) {\r
+               iconAction = e;\r
+       }\r
+       \r
        public NotebookTreeWidget() {\r
                noteSignal = new NoteSignal();\r
                setProperty("hideTree", true);\r
@@ -118,33 +125,49 @@ public class NotebookTreeWidget extends QTreeWidget {
                return false;\r
        }\r
        \r
+       public void setIcons(HashMap<String, QIcon> i) {\r
+               icons = i;\r
+       }\r
        \r
-       public void load(List<Notebook> books, List<String> localBooks) {\r
-       Notebook book;\r
-       QTreeWidgetItem child;\r
-       clear();\r
+       public QIcon findDefaultIcon(String guid, String name, List<String> localBooks, boolean isPublished) {\r
        String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
        QIcon blueIcon = new QIcon(iconPath+"notebook-blue.png");\r
        QIcon greenIcon = new QIcon(iconPath+"notebook-green.png");\r
        QIcon redIcon = new QIcon(iconPath+"notebook-red.png");\r
        QIcon yellowIcon = new QIcon(iconPath+"notebook-yellow.png");\r
+\r
+               if (localBooks.contains(guid)) {\r
+                       return yellowIcon;\r
+               }\r
+               \r
+               if (localBooks.contains(guid) && \r
+                       (name.equalsIgnoreCase("Conflicting Changes") ||\r
+                        name.equalsIgnoreCase("Conflicting Changes (Local)")))\r
+                               return redIcon;\r
+               if (isPublished)\r
+                       return blueIcon;\r
+\r
+               return greenIcon;\r
+       }\r
+       \r
+       public void load(List<Notebook> books, List<String> localBooks) {\r
+       Notebook book;\r
+       QTreeWidgetItem child;\r
+       clear();\r
        \r
        if (books == null)\r
                return;\r
        Qt.Alignment ra = new Qt.Alignment(Qt.AlignmentFlag.AlignRight);\r
        for (int i=0; i<books.size(); i++) {\r
-               book = books.get(i);\r
-               child = new QTreeWidgetItem();\r
-               child.setText(0, book.getName());\r
-               child.setIcon(0, greenIcon);\r
-               if (localBooks.contains(book.getGuid()))\r
-                       child.setIcon(0, yellowIcon);\r
-               if (localBooks.contains(book.getGuid()) && \r
-                               (book.getName().equalsIgnoreCase("Conflicting Changes") ||\r
-                                book.getName().equalsIgnoreCase("Conflicting Changes (Local)")))\r
-                                       child.setIcon(0, redIcon);\r
-               if (book.isPublished())\r
-                       child.setIcon(0, blueIcon);\r
+                       book = books.get(i);\r
+                       child = new QTreeWidgetItem();\r
+                       child.setText(0, book.getName());\r
+               if (icons != null && !icons.containsKey(book.getGuid())) {\r
+                       QIcon icon = findDefaultIcon(book.getGuid(), book.getName(), localBooks, book.isPublished());\r
+                       child.setIcon(0, icon);\r
+               } else {\r
+                       child.setIcon(0, icons.get(book.getGuid()));\r
+               }\r
                child.setTextAlignment(1, ra.value());\r
                child.setText(2, book.getGuid());\r
                addTopLevelItem(child);\r
@@ -152,6 +175,9 @@ public class NotebookTreeWidget extends QTreeWidget {
 \r
        sortItems(0, SortOrder.AscendingOrder); \r
        if (Global.mimicEvernoteInterface) {\r
+               String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
+               QIcon greenIcon = new QIcon(iconPath+"notebook-green.png");\r
+               \r
                child = new QTreeWidgetItem();\r
                child.setIcon(0, greenIcon);\r
                child.setText(0, "All Notebooks");\r
@@ -236,6 +262,8 @@ public class NotebookTreeWidget extends QTreeWidget {
                menu.addAction(addAction);\r
                menu.addAction(editAction);\r
                menu.addAction(deleteAction);\r
+               menu.addSeparator();\r
+               menu.addAction(iconAction);\r
                menu.exec(event.globalPos());\r
        }\r
        \r