OSDN Git Service

Add user qss directory.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / IgnoreSync.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.dialog;\r
21 \r
22 import java.util.List;\r
23 \r
24 import com.evernote.edam.type.Notebook;\r
25 import com.evernote.edam.type.Tag;\r
26 import com.trolltech.qt.gui.QAbstractItemView;\r
27 import com.trolltech.qt.gui.QDialog;\r
28 import com.trolltech.qt.gui.QHBoxLayout;\r
29 import com.trolltech.qt.gui.QIcon;\r
30 import com.trolltech.qt.gui.QLabel;\r
31 import com.trolltech.qt.gui.QListWidget;\r
32 import com.trolltech.qt.gui.QListWidgetItem;\r
33 import com.trolltech.qt.gui.QPushButton;\r
34 import com.trolltech.qt.gui.QSpacerItem;\r
35 import com.trolltech.qt.gui.QVBoxLayout;\r
36 \r
37 public class IgnoreSync extends QDialog {\r
38         private final QListWidget               syncBookList;\r
39         private final QListWidget               ignoreBookList;\r
40         private final QListWidget               syncTagList;\r
41         private final QListWidget               ignoreTagList;\r
42         private final QPushButton               okButton;\r
43         private final QPushButton               cancelButton;\r
44         private boolean                                 okClicked;\r
45         private final QPushButton               leftButton;\r
46         private final QPushButton               rightButton;\r
47         private final QPushButton               leftTagButton;\r
48         private final QPushButton               rightTagButton;\r
49         \r
50         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
51         \r
52         public IgnoreSync(List<Notebook> allBooks, List<Notebook> archive, List<Tag> allTags, List<Tag> ignoreTags) {\r
53                 setWindowIcon(new QIcon(iconPath+"synchronize.png"));\r
54                 okClicked = false;\r
55                 syncBookList = new QListWidget();\r
56                 syncBookList.setSortingEnabled(true);\r
57                 syncBookList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
58                 \r
59                 syncTagList = new QListWidget();\r
60                 syncTagList.setSortingEnabled(true);\r
61                 syncTagList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
62                 \r
63                 okButton = new QPushButton();\r
64                 okButton.setText(tr("OK"));\r
65                 okButton.pressed.connect(this, "onClicked()");\r
66                 \r
67                 cancelButton = new QPushButton();\r
68                 cancelButton.setText(tr("Cancel"));\r
69                 cancelButton.pressed.connect(this, "onCancel()");\r
70                 \r
71                 QVBoxLayout openLayout = new QVBoxLayout();\r
72                 openLayout.addWidget(new QLabel(tr("Synchronized Notebooks")));\r
73                 openLayout.addWidget(syncBookList);\r
74                 \r
75                 QVBoxLayout openTagLayout = new QVBoxLayout();\r
76                 openTagLayout.addWidget(new QLabel(tr("Synchronized Tags")));\r
77                 openTagLayout.addWidget(syncTagList);\r
78                 \r
79                 rightButton = new QPushButton(this);\r
80                 rightButton.setIcon(new QIcon(iconPath+"forward.png"));\r
81                 leftButton = new QPushButton(this);\r
82                 leftButton.setIcon(new QIcon(iconPath+"back.png"));\r
83                 leftButton.setEnabled(false);\r
84                 rightButton.setEnabled(false);\r
85                 \r
86                 rightTagButton = new QPushButton(this);\r
87                 rightTagButton.setIcon(new QIcon(iconPath+"forward.png"));\r
88                 leftTagButton = new QPushButton(this);\r
89                 leftTagButton.setIcon(new QIcon(iconPath+"back.png"));\r
90                 leftTagButton.setEnabled(false);\r
91                 rightTagButton.setEnabled(false);\r
92                 \r
93                 QVBoxLayout middleLayout = new QVBoxLayout();\r
94                 middleLayout.addSpacerItem(new QSpacerItem(1,1));\r
95                 middleLayout.addWidget(rightButton);\r
96                 middleLayout.addWidget(leftButton);\r
97                 middleLayout.addSpacerItem(new QSpacerItem(1,1));\r
98                 \r
99                 QVBoxLayout middleTagLayout = new QVBoxLayout();\r
100                 middleTagLayout.addSpacerItem(new QSpacerItem(1,1));\r
101                 middleTagLayout.addWidget(rightTagButton);\r
102                 middleTagLayout.addWidget(leftTagButton);\r
103                 middleTagLayout.addSpacerItem(new QSpacerItem(1,1));\r
104 \r
105                 QVBoxLayout closeLayout = new QVBoxLayout();\r
106                 closeLayout.addWidget(new QLabel(tr("Non-Synchronized Notebooks")));\r
107                 ignoreBookList = new QListWidget();\r
108                 ignoreBookList.setSortingEnabled(true);\r
109                 ignoreBookList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
110                 closeLayout.addWidget(ignoreBookList);\r
111 \r
112                 QVBoxLayout closeTagLayout = new QVBoxLayout();\r
113                 closeTagLayout.addWidget(new QLabel(tr("Non-Synchronized Tags")));\r
114                 ignoreTagList = new QListWidget();\r
115                 ignoreTagList.setSortingEnabled(true);\r
116                 ignoreTagList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
117                 closeTagLayout.addWidget(ignoreTagList);\r
118                 \r
119                 syncBookList.itemSelectionChanged.connect(this, "syncBookSelected()");\r
120                 ignoreBookList.itemSelectionChanged.connect(this, "ignoreBookSelected()");\r
121                 leftButton.clicked.connect(this, "toOpenList()");\r
122                 rightButton.clicked.connect(this, "toClosedList()");\r
123                 \r
124                 syncTagList.itemSelectionChanged.connect(this, "syncTagSelected()");\r
125                 ignoreTagList.itemSelectionChanged.connect(this, "ignoreTagSelected()");\r
126                 leftTagButton.clicked.connect(this, "toOpenTagList()");\r
127                 rightTagButton.clicked.connect(this, "toClosedTagList()");\r
128                 \r
129                 QHBoxLayout buttonLayout = new QHBoxLayout();\r
130                 buttonLayout.addStretch(1);\r
131                 buttonLayout.addWidget(okButton);\r
132                 buttonLayout.addWidget(cancelButton);\r
133                 setWindowTitle(tr("Open/Close Notebooks"));\r
134                 \r
135                 QHBoxLayout upperLayout = new QHBoxLayout();\r
136                 upperLayout.addLayout(openLayout);\r
137                 upperLayout.addLayout(middleLayout);\r
138                 upperLayout.addLayout(closeLayout);\r
139                 \r
140                 QHBoxLayout tagLayout = new QHBoxLayout();\r
141                 tagLayout.addLayout(openTagLayout);\r
142                 tagLayout.addLayout(middleTagLayout);\r
143                 tagLayout.addLayout(closeTagLayout);\r
144                 \r
145                 QVBoxLayout mainLayout = new QVBoxLayout();\r
146                 mainLayout.addLayout(upperLayout);\r
147                 mainLayout.addLayout(tagLayout);\r
148                 mainLayout.addSpacing(1);\r
149                 mainLayout.addLayout(buttonLayout);\r
150                 setLayout(mainLayout);\r
151 \r
152                 for (int i=0; i<allBooks.size(); i++) {\r
153                         boolean found = false;\r
154                         for (int j=0; j<archive.size(); j++) {\r
155                                 if (archive.get(j).getName().equalsIgnoreCase(allBooks.get(i).getName())) {\r
156                                         found = true;\r
157                                         j=archive.size();\r
158                                 }\r
159                         }\r
160                         if (!found) {\r
161                                 QListWidgetItem item = new QListWidgetItem(allBooks.get(i).getName());\r
162                                 item.setSelected(false);\r
163                                 syncBookList.addItem(item);\r
164                         }\r
165                 }\r
166                 \r
167                 setWindowTitle(tr("Open Notebooks"));\r
168                 for (int i=0; i<archive.size(); i++) {\r
169                         QListWidgetItem item = new QListWidgetItem(archive.get(i).getName());\r
170                         item.setSelected(false);\r
171                         ignoreBookList.addItem(item);\r
172                 }\r
173                 \r
174                 for (int i=0; i<allTags.size(); i++) {\r
175                         boolean found = false;\r
176                         for (int j=0; j<ignoreTags.size(); j++) {\r
177                                 if (ignoreTags.get(j).getName().equalsIgnoreCase(allTags.get(i).getName())) {\r
178                                         found = true;\r
179                                         j=ignoreTags.size();\r
180                                 }\r
181                         }\r
182                         if (!found) {\r
183                                 QListWidgetItem item = new QListWidgetItem(allTags.get(i).getName());\r
184                                 item.setSelected(false);\r
185                                 syncTagList.addItem(item);\r
186                         }\r
187                 }\r
188                 \r
189                 setWindowTitle(tr("Ignore Synchronized Notes"));\r
190                 for (int i=0; i<ignoreTags.size(); i++) {\r
191                         QListWidgetItem item = new QListWidgetItem(ignoreTags.get(i).getName());\r
192                         item.setSelected(false);\r
193                         ignoreTagList.addItem(item);\r
194                 }\r
195                 syncBookList.itemSelectionChanged.connect(this, "itemSelected()");\r
196         }\r
197         \r
198         @SuppressWarnings("unused")\r
199         private void toClosedList() {\r
200                 List<QListWidgetItem> items = syncBookList.selectedItems();\r
201                 for (int i=items.size()-1; i>=0; i--) {\r
202                         int row = syncBookList.row(items.get(i));\r
203                         syncBookList.takeItem(row);\r
204                         ignoreBookList.addItem(items.get(i).text());\r
205                 }\r
206                 if (syncBookList.count() == 0)\r
207                         okButton.setEnabled(false);\r
208                 rightButton.setEnabled(false);\r
209         }\r
210         \r
211         \r
212         @SuppressWarnings("unused")\r
213         private void toOpenList() {\r
214                 List<QListWidgetItem> items = ignoreBookList.selectedItems();\r
215                 for (int i=items.size()-1; i>=0; i--) {\r
216                         int row = ignoreBookList.row(items.get(i));\r
217                         ignoreBookList.takeItem(row);\r
218                         syncBookList.addItem(items.get(i).text());\r
219                 }\r
220                 okButton.setEnabled(true);\r
221                 leftButton.setEnabled(false);\r
222         }\r
223         \r
224         \r
225         @SuppressWarnings("unused")\r
226         private void toClosedTagList() {\r
227                 List<QListWidgetItem> items = syncTagList.selectedItems();\r
228                 for (int i=items.size()-1; i>=0; i--) {\r
229                         int row = syncTagList.row(items.get(i));\r
230                         syncTagList.takeItem(row);\r
231                         ignoreTagList.addItem(items.get(i).text());\r
232                 }\r
233                 if (syncTagList.count() == 0)\r
234                         okButton.setEnabled(false);\r
235                 rightTagButton.setEnabled(false);\r
236         }\r
237         \r
238         \r
239         @SuppressWarnings("unused")\r
240         private void toOpenTagList() {\r
241                 List<QListWidgetItem> items = ignoreTagList.selectedItems();\r
242                 for (int i=items.size()-1; i>=0; i--) {\r
243                         int row = ignoreTagList.row(items.get(i));\r
244                         ignoreTagList.takeItem(row);\r
245                         syncTagList.addItem(items.get(i).text());\r
246                 }\r
247                 okButton.setEnabled(true);\r
248                 leftTagButton.setEnabled(false);\r
249         }\r
250         \r
251         \r
252         @SuppressWarnings("unused")\r
253         private void ignoreBookSelected() {\r
254                 if (ignoreBookList.selectedItems().size() > 0)\r
255                         leftButton.setEnabled(true);\r
256                 else\r
257                         leftButton.setEnabled(false);\r
258         }\r
259         \r
260         @SuppressWarnings("unused")\r
261         private void syncBookSelected() {\r
262                 if (syncBookList.selectedItems().size() > 0)\r
263                         rightButton.setEnabled(true);\r
264                 else\r
265                         rightButton.setEnabled(false);\r
266         }\r
267         \r
268         @SuppressWarnings("unused")\r
269         private void ignoreTagSelected() {\r
270                 if (ignoreTagList.selectedItems().size() > 0)\r
271                         leftTagButton.setEnabled(true);\r
272                 else\r
273                         leftTagButton.setEnabled(false);\r
274         }\r
275         \r
276         @SuppressWarnings("unused")\r
277         private void syncTagSelected() {\r
278                 if (syncTagList.selectedItems().size() > 0)\r
279                         rightTagButton.setEnabled(true);\r
280                 else\r
281                         rightTagButton.setEnabled(false);\r
282         }\r
283         \r
284         @SuppressWarnings("unused")\r
285         private void onClicked() {\r
286                 okClicked = true;\r
287                 close();\r
288         }\r
289         \r
290         @SuppressWarnings("unused")\r
291         private void onCancel() {\r
292                 okClicked = false;\r
293                 close();\r
294         }\r
295         \r
296         public boolean okClicked() {\r
297                 return okClicked;\r
298         }\r
299         \r
300         public QListWidget getSyncBookList() {\r
301                 return syncBookList;\r
302         }\r
303         \r
304         public QListWidget getIgnoredBookList() {\r
305                 return ignoreBookList;\r
306         }\r
307         \r
308         public QListWidget getSyncTagList() {\r
309                 return syncTagList;\r
310         }\r
311         \r
312         public QListWidget getIgnoredTagList() {\r
313                 return ignoreTagList;\r
314         }\r
315         \r
316         @SuppressWarnings("unused")\r
317         private void itemSelected() {\r
318                 if (syncBookList.selectedItems().size() == syncBookList.count()) {\r
319                         okButton.setEnabled(false);\r
320                         rightButton.setEnabled(false);\r
321                         return;\r
322                 }\r
323                 rightButton.setEnabled(true);\r
324                 okButton.setEnabled(true);\r
325         }\r
326 }\r