OSDN Git Service

Add logic to display stacks in notebook tree
authorRandy Baumgarte <randy@fbn.cx>
Sun, 7 Nov 2010 12:13:54 +0000 (07:13 -0500)
committerRandy Baumgarte <randy@fbn.cx>
Wed, 15 Dec 2010 15:15:38 +0000 (10:15 -0500)
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/gui/NotebookTreeWidget.java
src/cx/fbn/nevernote/icons/books2.png [new file with mode: 0644]
src/cx/fbn/nevernote/sql/DatabaseConnection.java
src/cx/fbn/nevernote/sql/NotebookTable.java

index 952de30..fe8b947 100644 (file)
@@ -1167,7 +1167,16 @@ public class NeverNote extends QMainWindow{
        if (!Global.mimicEvernoteInterface) {
                for (int i=0; i<selections.size(); i++) {
                        currentSelection = selections.get(i);
-                       selectedNotebookGUIDs.add(currentSelection.text(2));
+                       if (!currentSelection.text(2).equals("STACK"))
+                               selectedNotebookGUIDs.add(currentSelection.text(2));
+                       else {
+                               String stackName = currentSelection.text(0);
+                               for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
+                                       Notebook book = listManager.getNotebookIndex().get(j);
+                                       if (book.getStack()!=null && book.getStack().equalsIgnoreCase(stackName))
+                                               selectedNotebookGUIDs.add(book.getGuid());
+                               }
+                       }
                }
        
                
@@ -1194,14 +1203,22 @@ public class NeverNote extends QMainWindow{
                        previousSelectedNotebook = "";
        } else {
                String guid = "";
-               if (selections.size() > 0)
+               String stackName = "";
+               if (selections.size() > 0) {
                        guid = (selections.get(0).text(2));
-               if (!guid.equals("")) {
+                       stackName = selections.get(0).text(0);
+               }
+               if (!guid.equals("") && !guid.equals("STACK")) {
                        selectedNotebookGUIDs.add(guid);
                        menuBar.notebookIconAction.setEnabled(true);
                }
                else {
                        menuBar.notebookIconAction.setEnabled(false);
+                               for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
+                                       Notebook book = listManager.getNotebookIndex().get(j);
+                                       if (book.getStack() != null && book.getStack().equalsIgnoreCase(stackName))
+                                               selectedNotebookGUIDs.add(book.getGuid());
+                               }
                }
        }
        listManager.setSelectedNotebooks(selectedNotebookGUIDs);
index c0a172f..86a645c 100644 (file)
@@ -40,6 +40,7 @@ import com.trolltech.qt.gui.QIcon;
 import com.trolltech.qt.gui.QMenu;\r
 import com.trolltech.qt.gui.QTreeWidget;\r
 import com.trolltech.qt.gui.QTreeWidgetItem;\r
+import com.trolltech.qt.gui.QTreeWidgetItem.ChildIndicatorPolicy;\r
 \r
 import cx.fbn.nevernote.Global;\r
 import cx.fbn.nevernote.filters.NotebookCounter;\r
@@ -52,6 +53,7 @@ public class NotebookTreeWidget extends QTreeWidget {
        private QAction                                 iconAction;\r
        public NoteSignal                               noteSignal;\r
        private HashMap<String, QIcon>  icons;\r
+       private final HashMap<String, QTreeWidgetItem>  stacks;\r
 //     private final QTreeWidgetItem                   previousMouseOver;\r
 //     private boolean                                 previousMouseOverWasSelected;\r
        \r
@@ -73,7 +75,7 @@ public class NotebookTreeWidget extends QTreeWidget {
        \r
        public NotebookTreeWidget() {\r
                noteSignal = new NoteSignal();\r
-               setProperty("hideTree", true);\r
+//             setProperty("hideTree", true);\r
                List<String> labels = new ArrayList<String>();\r
                labels.add("Notebooks");\r
                labels.add("");\r
@@ -91,6 +93,7 @@ public class NotebookTreeWidget extends QTreeWidget {
                } else\r
                        setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection);\r
 \r
+               stacks = new HashMap<String, QTreeWidgetItem>();\r
 //     int width = Global.getColumnWidth("notebookTreeName");\r
 //             if (width>0)\r
 //                     setColumnWidth(0, width);\r
@@ -161,6 +164,7 @@ public class NotebookTreeWidget extends QTreeWidget {
        for (int i=0; i<books.size(); i++) {\r
                        book = books.get(i);\r
                        child = new QTreeWidgetItem();\r
+                       child.setChildIndicatorPolicy(ChildIndicatorPolicy.DontShowIndicatorWhenChildless);\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
@@ -170,7 +174,26 @@ public class NotebookTreeWidget extends QTreeWidget {
                }\r
                child.setTextAlignment(1, ra.value());\r
                child.setText(2, book.getGuid());\r
-               addTopLevelItem(child);\r
+               if (book.getStack() == null || book.getStack().equalsIgnoreCase(""))\r
+                       addTopLevelItem(child); \r
+               else {\r
+                       String stackName = book.getStack();\r
+                       QTreeWidgetItem parent;\r
+                       if (!stacks.containsKey(stackName)) {\r
+                               String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
+                       QIcon stackIcon = new QIcon(iconPath+"books2.png");\r
+                               parent = new QTreeWidgetItem();\r
+                               stacks.put(stackName, parent);\r
+                               parent.setText(0, stackName);\r
+                               parent.setIcon(0, stackIcon);\r
+                               parent.setText(2, "STACK");\r
+                               parent.setTextAlignment(1, ra.value());\r
+                               addTopLevelItem(parent);\r
+                       } else\r
+                               parent = stacks.get(stackName);\r
+                       parent.addChild(child);\r
+                       \r
+               }\r
        }\r
 \r
        sortItems(0, SortOrder.AscendingOrder); \r
@@ -181,7 +204,6 @@ public class NotebookTreeWidget extends QTreeWidget {
                child = new QTreeWidgetItem();\r
                child.setIcon(0, greenIcon);\r
                child.setText(0, "All Notebooks");\r
-//             child.setText(1, "0");\r
                child.setText(2, "");\r
                child.setTextAlignment(1, ra.value());\r
                insertTopLevelItem(0,child);\r
@@ -189,10 +211,12 @@ public class NotebookTreeWidget extends QTreeWidget {
        resizeColumnToContents(0);\r
        resizeColumnToContents(1);\r
        }\r
+\r
        // update the display with the current number of notes\r
        public void updateCounts(List<Notebook> books, List<NotebookCounter> counts) {\r
                QTreeWidgetItem root = invisibleRootItem();\r
                QTreeWidgetItem child;\r
+               HashMap<String, Integer> stackCounts = new HashMap<String, Integer>();\r
                \r
                QBrush blue = new QBrush();\r
                QBrush black = new QBrush();\r
@@ -203,35 +227,26 @@ public class NotebookTreeWidget extends QTreeWidget {
                        blue.setColor(QColor.black);\r
                int total=0;\r
                \r
-//             for (int i=0; i<counts.size(); i++) {\r
-//                     total=total+counts.get(i).getCount();\r
-//             }\r
                \r
                int size = books.size();\r
                if (Global.mimicEvernoteInterface)\r
                        size++;\r
                \r
                for (int i=0; i<size; i++) {\r
-                       child = root.child(i); \r
-                       if (child != null) {\r
-                               String guid = child.text(2);\r
-                               child.setText(1,"0");\r
-                               child.setForeground(0, black);\r
-                               child.setForeground(1, black);\r
-                               for (int j=0; j<counts.size(); j++) {\r
-                                       if (counts.get(j).getGuid().equals(guid)) {\r
-                                               child.setText(1, new Integer(counts.get(j).getCount()).toString());\r
-                                               total = total+counts.get(j).getCount();\r
-                                               if (counts.get(j).getCount() > 0) {\r
-                                                       child.setForeground(0, blue);\r
-                                                       child.setForeground(1, blue);\r
-                                               }\r
-                                       }\r
-//                                     if (guid.equals("") && Global.mimicEvernoteInterface) {\r
-//                                             child.setText(1, new Integer(total).toString());\r
-//                                     }\r
+                       child = root.child(i);\r
+                       if (child != null && child.childCount() > 0) {\r
+                               int count = child.childCount();\r
+                               QTreeWidgetItem parent = child;\r
+                               int localTotal = 0;\r
+                               for (int j=0; j<count; j++) {\r
+                                       child = parent.child(j);\r
+                                       int childCount = updateCounts(child, books, counts, blue, black);\r
+                                       total = total+childCount;\r
+                                       localTotal = localTotal+childCount;\r
                                }\r
-                       }\r
+                               parent.setText(1, new Integer(localTotal).toString());\r
+                       } else\r
+                               total = total+updateCounts(child, books, counts, blue, black);\r
                }\r
                \r
                for (int i=0; i<size; i++) {\r
@@ -243,6 +258,28 @@ public class NotebookTreeWidget extends QTreeWidget {
                        }\r
                }\r
        }\r
+       \r
+       private int updateCounts(QTreeWidgetItem child, List<Notebook> books, List<NotebookCounter> counts, QBrush blue, QBrush black) {\r
+               int total=0;\r
+               if (child != null) {\r
+                       String guid = child.text(2);\r
+                       child.setText(1,"0");\r
+                       child.setForeground(0, black);\r
+                       child.setForeground(1, black);\r
+                       for (int j=0; j<counts.size(); j++) {\r
+                               if (counts.get(j).getGuid().equals(guid)) {\r
+                                       child.setText(1, new Integer(counts.get(j).getCount()).toString());\r
+                                       total = counts.get(j).getCount();\r
+                                       if (counts.get(j).getCount() > 0) {\r
+                                               child.setForeground(0, blue);\r
+                                               child.setForeground(1, blue);\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               return total;\r
+       }\r
+       \r
        // Return a list of the notebook guids, ordered by the current display order.\r
        public List<String> getNotebookGuids() {\r
                List<String> names = new ArrayList<String>();\r
diff --git a/src/cx/fbn/nevernote/icons/books2.png b/src/cx/fbn/nevernote/icons/books2.png
new file mode 100644 (file)
index 0000000..92cd6af
Binary files /dev/null and b/src/cx/fbn/nevernote/icons/books2.png differ
index 38f0e35..44c0cc6 100644 (file)
@@ -171,6 +171,9 @@ public class DatabaseConnection {
                        executeSql("create index NOTE_DUEDATE_INDEX on note (attributeSubjectDate, guid);");
                        executeSql("create index RESOURCES_GUID_INDEX on noteresources (noteGuid, guid);");
                        executeSql("update note set thumbnailneeded=true, thumbnail=null;");
+                       executeSql("update notebook set publishingUri='', " +
+                                       "publishingAscending='', stack='', publishingOrder=1, " +
+                                       "publishingPublicDescription=''");
                        
                        sharedNotebookTable.createTable();
                        linkedNotebookTable.createTable();
index 7cd6e0e..41379db 100644 (file)
@@ -86,12 +86,12 @@ public class NotebookTable {
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
                check = query.prepare("Insert Into Notebook (guid, sequence, name, defaultNotebook, "\r
                                +"serviceCreated, serviceUpdated, published, "   \r
-                               + "isDirty, autoEncrypt," \r
+                               + "isDirty, autoEncrypt, stack\r
                                + "local, archived) Values("\r
                                +":guid, :sequence, :name, :defaultNotebook,  "\r
                                +":serviceCreated, :serviceUpdated, :published, "\r
                                +":isDirty, :autoEncrypt, "\r
-                               +":local, false)");\r
+                               +":local, false, :stack)");\r
                query.bindValue(":guid", tempNotebook.getGuid());\r
                query.bindValue(":sequence", tempNotebook.getUpdateSequenceNum());\r
                query.bindValue(":name", tempNotebook.getName());\r
@@ -111,6 +111,7 @@ public class NotebookTable {
                        query.bindValue(":isDirty", false);\r
                query.bindValue(":autoEncrypt", false);\r
                query.bindValue(":local", local);\r
+               query.bindValue(":stack", tempNotebook.getStack());\r
 \r
                check = query.exec();\r
                if (!check) {\r
@@ -180,7 +181,7 @@ public class NotebookTable {
                check = query.exec("Select guid, sequence, name, defaultNotebook, " +\r
                                "serviceCreated, "+\r
                                "serviceUpdated, "+\r
-                               "published, defaultNotebook from Notebook order by name");\r
+                               "published, defaultNotebook, stack from Notebook order by name");\r
                if (!check)\r
                        logger.log(logger.EXTREME, "Notebook SQL retrieve has failed.");\r
                while (query.next()) {\r
@@ -202,6 +203,7 @@ public class NotebookTable {
                        }\r
                        tempNotebook.setPublished(new Boolean(query.valueString(6)));\r
                        tempNotebook.setDefaultNotebook(new Boolean(query.valueString(7)));\r
+                       tempNotebook.setStack(query.valueString(8));\r
                        index.add(tempNotebook); \r
                }       \r
                return index;\r
@@ -214,7 +216,7 @@ public class NotebookTable {
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
                                        \r
                check = query.exec("Select guid, sequence, name, defaultNotebook, " +\r
-                               "serviceCreated, serviceUpdated, published from Notebook where local=true order by name");\r
+                               "serviceCreated, serviceUpdated, published, stack from Notebook where local=true order by name");\r
                if (!check)\r
                        logger.log(logger.EXTREME, "Notebook SQL retrieve has failed.");\r
                while (query.next()) {\r
@@ -232,6 +234,7 @@ public class NotebookTable {
                        } catch (ParseException e) {\r
                                e.printStackTrace();\r
                        }\r
+                       tempNotebook.setStack(query.valueString(7));\r
                        index.add(tempNotebook); \r
                }       \r
                return index;\r
@@ -256,7 +259,7 @@ public class NotebookTable {
         NSqlQuery query = new NSqlQuery(db.getConnection());\r
                                        \r
                check = query.exec("Select guid, sequence, name, defaultNotebook, " +\r
-                               "serviceCreated, serviceUpdated, published from Notebook where archived=true order by name");\r
+                               "serviceCreated, serviceUpdated, published, stack from Notebook where archived=true order by name");\r
                if (!check)\r
                        logger.log(logger.EXTREME, "Notebook SQL retrieve has failed.");\r
                while (query.next()) {\r
@@ -275,6 +278,7 @@ public class NotebookTable {
                                e.printStackTrace();\r
                        }\r
                        tempNotebook.setPublished(new Boolean(query.valueString(6)));\r
+                       tempNotebook.setStack(query.valueString(7));\r
                        index.add(tempNotebook); \r
                }       \r
                return index;\r