OSDN Git Service

Add Linked notebooks to the ignore sync process.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / IgnoreSync.java
index 466a779..7805e7b 100644 (file)
@@ -21,6 +21,7 @@ package cx.fbn.nevernote.dialog;
 \r
 import java.util.List;\r
 \r
 \r
 import java.util.List;\r
 \r
+import com.evernote.edam.type.LinkedNotebook;\r
 import com.evernote.edam.type.Notebook;\r
 import com.evernote.edam.type.Tag;\r
 import com.trolltech.qt.gui.QAbstractItemView;\r
 import com.evernote.edam.type.Notebook;\r
 import com.evernote.edam.type.Tag;\r
 import com.trolltech.qt.gui.QAbstractItemView;\r
@@ -39,6 +40,8 @@ public class IgnoreSync extends QDialog {
        private final QListWidget               ignoreBookList;\r
        private final QListWidget               syncTagList;\r
        private final QListWidget               ignoreTagList;\r
        private final QListWidget               ignoreBookList;\r
        private final QListWidget               syncTagList;\r
        private final QListWidget               ignoreTagList;\r
+       private final QListWidget               syncLinkedNotebookList;\r
+       private final QListWidget               ignoreLinkedNotebookList;\r
        private final QPushButton               okButton;\r
        private final QPushButton               cancelButton;\r
        private boolean                                 okClicked;\r
        private final QPushButton               okButton;\r
        private final QPushButton               cancelButton;\r
        private boolean                                 okClicked;\r
@@ -46,10 +49,15 @@ public class IgnoreSync extends QDialog {
        private final QPushButton               rightButton;\r
        private final QPushButton               leftTagButton;\r
        private final QPushButton               rightTagButton;\r
        private final QPushButton               rightButton;\r
        private final QPushButton               leftTagButton;\r
        private final QPushButton               rightTagButton;\r
+       private final QPushButton               leftLinkedNotebookButton;\r
+       private final QPushButton               rightLinkedNotebookButton;\r
+       private final QLabel                    linkedLabelLeft;\r
+       private final QLabel                    linkedLabelRight;\r
        \r
        private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
        \r
        \r
        private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
        \r
-       public IgnoreSync(List<Notebook> allBooks, List<Notebook> archive, List<Tag> allTags, List<Tag> ignoreTags) {\r
+       public IgnoreSync(List<Notebook> allBooks, List<Notebook> archive, List<Tag> allTags, List<Tag> ignoreTags, \r
+                       List<LinkedNotebook> allLinkedNotebooks, List<LinkedNotebook> ignoreLinkedNotebooks) {\r
                setWindowIcon(new QIcon(iconPath+"synchronize.png"));\r
                okClicked = false;\r
                syncBookList = new QListWidget();\r
                setWindowIcon(new QIcon(iconPath+"synchronize.png"));\r
                okClicked = false;\r
                syncBookList = new QListWidget();\r
@@ -60,6 +68,10 @@ public class IgnoreSync extends QDialog {
                syncTagList.setSortingEnabled(true);\r
                syncTagList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
                \r
                syncTagList.setSortingEnabled(true);\r
                syncTagList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
                \r
+               syncLinkedNotebookList = new QListWidget();\r
+               syncLinkedNotebookList.setSortingEnabled(true);\r
+               syncLinkedNotebookList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
+               \r
                okButton = new QPushButton();\r
                okButton.setText(tr("OK"));\r
                okButton.pressed.connect(this, "onClicked()");\r
                okButton = new QPushButton();\r
                okButton.setText(tr("OK"));\r
                okButton.pressed.connect(this, "onClicked()");\r
@@ -76,6 +88,11 @@ public class IgnoreSync extends QDialog {
                openTagLayout.addWidget(new QLabel(tr("Synchronized Tags")));\r
                openTagLayout.addWidget(syncTagList);\r
                \r
                openTagLayout.addWidget(new QLabel(tr("Synchronized Tags")));\r
                openTagLayout.addWidget(syncTagList);\r
                \r
+               QVBoxLayout openLinkedNotebookLayout = new QVBoxLayout();\r
+               linkedLabelLeft = new QLabel(tr("Synchronized Linked Notebooks"));\r
+               openLinkedNotebookLayout.addWidget(linkedLabelLeft);\r
+               openLinkedNotebookLayout.addWidget(syncLinkedNotebookList);\r
+               \r
                rightButton = new QPushButton(this);\r
                rightButton.setIcon(new QIcon(iconPath+"forward.png"));\r
                leftButton = new QPushButton(this);\r
                rightButton = new QPushButton(this);\r
                rightButton.setIcon(new QIcon(iconPath+"forward.png"));\r
                leftButton = new QPushButton(this);\r
@@ -90,6 +107,13 @@ public class IgnoreSync extends QDialog {
                leftTagButton.setEnabled(false);\r
                rightTagButton.setEnabled(false);\r
                \r
                leftTagButton.setEnabled(false);\r
                rightTagButton.setEnabled(false);\r
                \r
+               rightLinkedNotebookButton = new QPushButton(this);\r
+               rightLinkedNotebookButton.setIcon(new QIcon(iconPath+"forward.png"));\r
+               leftLinkedNotebookButton = new QPushButton(this);\r
+               leftLinkedNotebookButton.setIcon(new QIcon(iconPath+"back.png"));\r
+               leftLinkedNotebookButton.setEnabled(false);\r
+               rightLinkedNotebookButton.setEnabled(false);\r
+               \r
                QVBoxLayout middleLayout = new QVBoxLayout();\r
                middleLayout.addSpacerItem(new QSpacerItem(1,1));\r
                middleLayout.addWidget(rightButton);\r
                QVBoxLayout middleLayout = new QVBoxLayout();\r
                middleLayout.addSpacerItem(new QSpacerItem(1,1));\r
                middleLayout.addWidget(rightButton);\r
@@ -101,6 +125,12 @@ public class IgnoreSync extends QDialog {
                middleTagLayout.addWidget(rightTagButton);\r
                middleTagLayout.addWidget(leftTagButton);\r
                middleTagLayout.addSpacerItem(new QSpacerItem(1,1));\r
                middleTagLayout.addWidget(rightTagButton);\r
                middleTagLayout.addWidget(leftTagButton);\r
                middleTagLayout.addSpacerItem(new QSpacerItem(1,1));\r
+               \r
+               QVBoxLayout middleLinkedNotebookLayout = new QVBoxLayout();\r
+               middleLinkedNotebookLayout.addSpacerItem(new QSpacerItem(1,1));\r
+               middleLinkedNotebookLayout.addWidget(rightLinkedNotebookButton);\r
+               middleLinkedNotebookLayout.addWidget(leftLinkedNotebookButton);\r
+               middleLinkedNotebookLayout.addSpacerItem(new QSpacerItem(1,1));\r
 \r
                QVBoxLayout closeLayout = new QVBoxLayout();\r
                closeLayout.addWidget(new QLabel(tr("Non-Synchronized Notebooks")));\r
 \r
                QVBoxLayout closeLayout = new QVBoxLayout();\r
                closeLayout.addWidget(new QLabel(tr("Non-Synchronized Notebooks")));\r
@@ -116,6 +146,14 @@ public class IgnoreSync extends QDialog {
                ignoreTagList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
                closeTagLayout.addWidget(ignoreTagList);\r
                \r
                ignoreTagList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
                closeTagLayout.addWidget(ignoreTagList);\r
                \r
+               QVBoxLayout closeLinkedNotebookLayout = new QVBoxLayout();\r
+               linkedLabelRight = new QLabel(tr("Non-Synchronized Linked Notebooks"));\r
+               closeLinkedNotebookLayout.addWidget(linkedLabelRight);\r
+               ignoreLinkedNotebookList = new QListWidget();\r
+               ignoreLinkedNotebookList.setSortingEnabled(true);\r
+               ignoreLinkedNotebookList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
+               closeLinkedNotebookLayout.addWidget(ignoreLinkedNotebookList);\r
+               \r
                syncBookList.itemSelectionChanged.connect(this, "syncBookSelected()");\r
                ignoreBookList.itemSelectionChanged.connect(this, "ignoreBookSelected()");\r
                leftButton.clicked.connect(this, "toOpenList()");\r
                syncBookList.itemSelectionChanged.connect(this, "syncBookSelected()");\r
                ignoreBookList.itemSelectionChanged.connect(this, "ignoreBookSelected()");\r
                leftButton.clicked.connect(this, "toOpenList()");\r
@@ -126,6 +164,11 @@ public class IgnoreSync extends QDialog {
                leftTagButton.clicked.connect(this, "toOpenTagList()");\r
                rightTagButton.clicked.connect(this, "toClosedTagList()");\r
                \r
                leftTagButton.clicked.connect(this, "toOpenTagList()");\r
                rightTagButton.clicked.connect(this, "toClosedTagList()");\r
                \r
+               syncLinkedNotebookList.itemSelectionChanged.connect(this, "syncLinkedNotebookSelected()");\r
+               ignoreLinkedNotebookList.itemSelectionChanged.connect(this, "ignoreLinkedNotebookSelected()");\r
+               leftLinkedNotebookButton.clicked.connect(this, "toOpenLinkedNotebookList()");\r
+               rightLinkedNotebookButton.clicked.connect(this, "toClosedLinkedNotebookList()");\r
+               \r
                QHBoxLayout buttonLayout = new QHBoxLayout();\r
                buttonLayout.addStretch(1);\r
                buttonLayout.addWidget(okButton);\r
                QHBoxLayout buttonLayout = new QHBoxLayout();\r
                buttonLayout.addStretch(1);\r
                buttonLayout.addWidget(okButton);\r
@@ -142,9 +185,15 @@ public class IgnoreSync extends QDialog {
                tagLayout.addLayout(middleTagLayout);\r
                tagLayout.addLayout(closeTagLayout);\r
                \r
                tagLayout.addLayout(middleTagLayout);\r
                tagLayout.addLayout(closeTagLayout);\r
                \r
+               QHBoxLayout linkedNotebookLayout = new QHBoxLayout();\r
+               linkedNotebookLayout.addLayout(openLinkedNotebookLayout);\r
+               linkedNotebookLayout.addLayout(middleLinkedNotebookLayout);\r
+               linkedNotebookLayout.addLayout(closeLinkedNotebookLayout);\r
+               \r
                QVBoxLayout mainLayout = new QVBoxLayout();\r
                mainLayout.addLayout(upperLayout);\r
                mainLayout.addLayout(tagLayout);\r
                QVBoxLayout mainLayout = new QVBoxLayout();\r
                mainLayout.addLayout(upperLayout);\r
                mainLayout.addLayout(tagLayout);\r
+               mainLayout.addLayout(linkedNotebookLayout);\r
                mainLayout.addSpacing(1);\r
                mainLayout.addLayout(buttonLayout);\r
                setLayout(mainLayout);\r
                mainLayout.addSpacing(1);\r
                mainLayout.addLayout(buttonLayout);\r
                setLayout(mainLayout);\r
@@ -185,14 +234,44 @@ public class IgnoreSync extends QDialog {
                                syncTagList.addItem(item);\r
                        }\r
                }\r
                                syncTagList.addItem(item);\r
                        }\r
                }\r
-               \r
-               setWindowTitle(tr("Ignore Synchronized Notes"));\r
                for (int i=0; i<ignoreTags.size(); i++) {\r
                        QListWidgetItem item = new QListWidgetItem(ignoreTags.get(i).getName());\r
                        item.setSelected(false);\r
                        ignoreTagList.addItem(item);\r
                }\r
                for (int i=0; i<ignoreTags.size(); i++) {\r
                        QListWidgetItem item = new QListWidgetItem(ignoreTags.get(i).getName());\r
                        item.setSelected(false);\r
                        ignoreTagList.addItem(item);\r
                }\r
+               \r
+               for (int i=0; i<allLinkedNotebooks.size(); i++) {\r
+                       boolean found = false;\r
+                       for (int j=0; j<ignoreLinkedNotebooks.size(); j++) {\r
+                               if (ignoreLinkedNotebooks.get(j).getShareName().equalsIgnoreCase(allLinkedNotebooks.get(i).getShareName())) {\r
+                                       found = true;\r
+                                       j=ignoreLinkedNotebooks.size();\r
+                               }\r
+                       }\r
+                       if (!found) {\r
+                               QListWidgetItem item = new QListWidgetItem(allLinkedNotebooks.get(i).getShareName());\r
+                               item.setSelected(false);\r
+                               syncLinkedNotebookList.addItem(item);\r
+                       }\r
+               }\r
+               for (int i=0; i<ignoreLinkedNotebooks.size(); i++) {\r
+                       QListWidgetItem item = new QListWidgetItem(ignoreLinkedNotebooks.get(i).getShareName());\r
+                       item.setSelected(false);\r
+                       ignoreLinkedNotebookList.addItem(item);\r
+               }\r
+\r
+\r
                syncBookList.itemSelectionChanged.connect(this, "itemSelected()");\r
                syncBookList.itemSelectionChanged.connect(this, "itemSelected()");\r
+               setWindowTitle(tr("Ignore Synchronized Notes"));\r
+\r
+               if (allLinkedNotebooks.size() == 0) {\r
+                       linkedLabelLeft.setVisible(false);\r
+                       linkedLabelRight.setVisible(false);\r
+                       rightLinkedNotebookButton.setVisible(false);\r
+                       leftLinkedNotebookButton.setVisible(false);\r
+                       ignoreLinkedNotebookList.setVisible(false);\r
+                       syncLinkedNotebookList.setVisible(false);\r
+               }\r
        }\r
        \r
        @SuppressWarnings("unused")\r
        }\r
        \r
        @SuppressWarnings("unused")\r
@@ -230,8 +309,6 @@ public class IgnoreSync extends QDialog {
                        syncTagList.takeItem(row);\r
                        ignoreTagList.addItem(items.get(i).text());\r
                }\r
                        syncTagList.takeItem(row);\r
                        ignoreTagList.addItem(items.get(i).text());\r
                }\r
-               if (syncTagList.count() == 0)\r
-                       okButton.setEnabled(false);\r
                rightTagButton.setEnabled(false);\r
        }\r
        \r
                rightTagButton.setEnabled(false);\r
        }\r
        \r
@@ -244,10 +321,32 @@ public class IgnoreSync extends QDialog {
                        ignoreTagList.takeItem(row);\r
                        syncTagList.addItem(items.get(i).text());\r
                }\r
                        ignoreTagList.takeItem(row);\r
                        syncTagList.addItem(items.get(i).text());\r
                }\r
-               okButton.setEnabled(true);\r
                leftTagButton.setEnabled(false);\r
        }\r
        \r
                leftTagButton.setEnabled(false);\r
        }\r
        \r
+       @SuppressWarnings("unused")\r
+       private void toClosedLinkedNotebookList() {\r
+               List<QListWidgetItem> items = syncLinkedNotebookList.selectedItems();\r
+               for (int i=items.size()-1; i>=0; i--) {\r
+                       int row = syncLinkedNotebookList.row(items.get(i));\r
+                       syncLinkedNotebookList.takeItem(row);\r
+                       ignoreLinkedNotebookList.addItem(items.get(i).text());\r
+               }\r
+               rightLinkedNotebookButton.setEnabled(false);\r
+       }\r
+       \r
+       \r
+       @SuppressWarnings("unused")\r
+       private void toOpenLinkedNotebookList() {\r
+               List<QListWidgetItem> items = ignoreLinkedNotebookList.selectedItems();\r
+               for (int i=items.size()-1; i>=0; i--) {\r
+                       int row = ignoreLinkedNotebookList.row(items.get(i));\r
+                       ignoreLinkedNotebookList.takeItem(row);\r
+                       syncLinkedNotebookList.addItem(items.get(i).text());\r
+               }\r
+               leftLinkedNotebookButton.setEnabled(false);\r
+       }\r
+       \r
        \r
        @SuppressWarnings("unused")\r
        private void ignoreBookSelected() {\r
        \r
        @SuppressWarnings("unused")\r
        private void ignoreBookSelected() {\r
@@ -282,6 +381,22 @@ public class IgnoreSync extends QDialog {
        }\r
        \r
        @SuppressWarnings("unused")\r
        }\r
        \r
        @SuppressWarnings("unused")\r
+       private void ignoreLinkedNotebookSelected() {\r
+               if (ignoreLinkedNotebookList.selectedItems().size() > 0)\r
+                       leftLinkedNotebookButton.setEnabled(true);\r
+               else\r
+                       leftLinkedNotebookButton.setEnabled(false);\r
+       }\r
+       \r
+       @SuppressWarnings("unused")\r
+       private void syncLinkedNotebookSelected() {\r
+               if (syncLinkedNotebookList.selectedItems().size() > 0)\r
+                       rightLinkedNotebookButton.setEnabled(true);\r
+               else\r
+                       rightLinkedNotebookButton.setEnabled(false);\r
+       }\r
+       \r
+       @SuppressWarnings("unused")\r
        private void onClicked() {\r
                okClicked = true;\r
                close();\r
        private void onClicked() {\r
                okClicked = true;\r
                close();\r
@@ -313,6 +428,14 @@ public class IgnoreSync extends QDialog {
                return ignoreTagList;\r
        }\r
        \r
                return ignoreTagList;\r
        }\r
        \r
+       public QListWidget getSyncLinkedNotebookList() {\r
+               return syncLinkedNotebookList;\r
+       }\r
+       \r
+       public QListWidget getIgnoredLinkedNotebookList() {\r
+               return ignoreLinkedNotebookList;\r
+       }\r
+       \r
        @SuppressWarnings("unused")\r
        private void itemSelected() {\r
                if (syncBookList.selectedItems().size() == syncBookList.count()) {\r
        @SuppressWarnings("unused")\r
        private void itemSelected() {\r
                if (syncBookList.selectedItems().size() == syncBookList.count()) {\r