OSDN Git Service

7805e7be9aaba447b2a7e8908b53021b16f824ac
[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.LinkedNotebook;\r
25 import com.evernote.edam.type.Notebook;\r
26 import com.evernote.edam.type.Tag;\r
27 import com.trolltech.qt.gui.QAbstractItemView;\r
28 import com.trolltech.qt.gui.QDialog;\r
29 import com.trolltech.qt.gui.QHBoxLayout;\r
30 import com.trolltech.qt.gui.QIcon;\r
31 import com.trolltech.qt.gui.QLabel;\r
32 import com.trolltech.qt.gui.QListWidget;\r
33 import com.trolltech.qt.gui.QListWidgetItem;\r
34 import com.trolltech.qt.gui.QPushButton;\r
35 import com.trolltech.qt.gui.QSpacerItem;\r
36 import com.trolltech.qt.gui.QVBoxLayout;\r
37 \r
38 public class IgnoreSync extends QDialog {\r
39         private final QListWidget               syncBookList;\r
40         private final QListWidget               ignoreBookList;\r
41         private final QListWidget               syncTagList;\r
42         private final QListWidget               ignoreTagList;\r
43         private final QListWidget               syncLinkedNotebookList;\r
44         private final QListWidget               ignoreLinkedNotebookList;\r
45         private final QPushButton               okButton;\r
46         private final QPushButton               cancelButton;\r
47         private boolean                                 okClicked;\r
48         private final QPushButton               leftButton;\r
49         private final QPushButton               rightButton;\r
50         private final QPushButton               leftTagButton;\r
51         private final QPushButton               rightTagButton;\r
52         private final QPushButton               leftLinkedNotebookButton;\r
53         private final QPushButton               rightLinkedNotebookButton;\r
54         private final QLabel                    linkedLabelLeft;\r
55         private final QLabel                    linkedLabelRight;\r
56         \r
57         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
58         \r
59         public IgnoreSync(List<Notebook> allBooks, List<Notebook> archive, List<Tag> allTags, List<Tag> ignoreTags, \r
60                         List<LinkedNotebook> allLinkedNotebooks, List<LinkedNotebook> ignoreLinkedNotebooks) {\r
61                 setWindowIcon(new QIcon(iconPath+"synchronize.png"));\r
62                 okClicked = false;\r
63                 syncBookList = new QListWidget();\r
64                 syncBookList.setSortingEnabled(true);\r
65                 syncBookList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
66                 \r
67                 syncTagList = new QListWidget();\r
68                 syncTagList.setSortingEnabled(true);\r
69                 syncTagList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
70                 \r
71                 syncLinkedNotebookList = new QListWidget();\r
72                 syncLinkedNotebookList.setSortingEnabled(true);\r
73                 syncLinkedNotebookList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
74                 \r
75                 okButton = new QPushButton();\r
76                 okButton.setText(tr("OK"));\r
77                 okButton.pressed.connect(this, "onClicked()");\r
78                 \r
79                 cancelButton = new QPushButton();\r
80                 cancelButton.setText(tr("Cancel"));\r
81                 cancelButton.pressed.connect(this, "onCancel()");\r
82                 \r
83                 QVBoxLayout openLayout = new QVBoxLayout();\r
84                 openLayout.addWidget(new QLabel(tr("Synchronized Notebooks")));\r
85                 openLayout.addWidget(syncBookList);\r
86                 \r
87                 QVBoxLayout openTagLayout = new QVBoxLayout();\r
88                 openTagLayout.addWidget(new QLabel(tr("Synchronized Tags")));\r
89                 openTagLayout.addWidget(syncTagList);\r
90                 \r
91                 QVBoxLayout openLinkedNotebookLayout = new QVBoxLayout();\r
92                 linkedLabelLeft = new QLabel(tr("Synchronized Linked Notebooks"));\r
93                 openLinkedNotebookLayout.addWidget(linkedLabelLeft);\r
94                 openLinkedNotebookLayout.addWidget(syncLinkedNotebookList);\r
95                 \r
96                 rightButton = new QPushButton(this);\r
97                 rightButton.setIcon(new QIcon(iconPath+"forward.png"));\r
98                 leftButton = new QPushButton(this);\r
99                 leftButton.setIcon(new QIcon(iconPath+"back.png"));\r
100                 leftButton.setEnabled(false);\r
101                 rightButton.setEnabled(false);\r
102                 \r
103                 rightTagButton = new QPushButton(this);\r
104                 rightTagButton.setIcon(new QIcon(iconPath+"forward.png"));\r
105                 leftTagButton = new QPushButton(this);\r
106                 leftTagButton.setIcon(new QIcon(iconPath+"back.png"));\r
107                 leftTagButton.setEnabled(false);\r
108                 rightTagButton.setEnabled(false);\r
109                 \r
110                 rightLinkedNotebookButton = new QPushButton(this);\r
111                 rightLinkedNotebookButton.setIcon(new QIcon(iconPath+"forward.png"));\r
112                 leftLinkedNotebookButton = new QPushButton(this);\r
113                 leftLinkedNotebookButton.setIcon(new QIcon(iconPath+"back.png"));\r
114                 leftLinkedNotebookButton.setEnabled(false);\r
115                 rightLinkedNotebookButton.setEnabled(false);\r
116                 \r
117                 QVBoxLayout middleLayout = new QVBoxLayout();\r
118                 middleLayout.addSpacerItem(new QSpacerItem(1,1));\r
119                 middleLayout.addWidget(rightButton);\r
120                 middleLayout.addWidget(leftButton);\r
121                 middleLayout.addSpacerItem(new QSpacerItem(1,1));\r
122                 \r
123                 QVBoxLayout middleTagLayout = new QVBoxLayout();\r
124                 middleTagLayout.addSpacerItem(new QSpacerItem(1,1));\r
125                 middleTagLayout.addWidget(rightTagButton);\r
126                 middleTagLayout.addWidget(leftTagButton);\r
127                 middleTagLayout.addSpacerItem(new QSpacerItem(1,1));\r
128                 \r
129                 QVBoxLayout middleLinkedNotebookLayout = new QVBoxLayout();\r
130                 middleLinkedNotebookLayout.addSpacerItem(new QSpacerItem(1,1));\r
131                 middleLinkedNotebookLayout.addWidget(rightLinkedNotebookButton);\r
132                 middleLinkedNotebookLayout.addWidget(leftLinkedNotebookButton);\r
133                 middleLinkedNotebookLayout.addSpacerItem(new QSpacerItem(1,1));\r
134 \r
135                 QVBoxLayout closeLayout = new QVBoxLayout();\r
136                 closeLayout.addWidget(new QLabel(tr("Non-Synchronized Notebooks")));\r
137                 ignoreBookList = new QListWidget();\r
138                 ignoreBookList.setSortingEnabled(true);\r
139                 ignoreBookList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
140                 closeLayout.addWidget(ignoreBookList);\r
141 \r
142                 QVBoxLayout closeTagLayout = new QVBoxLayout();\r
143                 closeTagLayout.addWidget(new QLabel(tr("Non-Synchronized Tags")));\r
144                 ignoreTagList = new QListWidget();\r
145                 ignoreTagList.setSortingEnabled(true);\r
146                 ignoreTagList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
147                 closeTagLayout.addWidget(ignoreTagList);\r
148                 \r
149                 QVBoxLayout closeLinkedNotebookLayout = new QVBoxLayout();\r
150                 linkedLabelRight = new QLabel(tr("Non-Synchronized Linked Notebooks"));\r
151                 closeLinkedNotebookLayout.addWidget(linkedLabelRight);\r
152                 ignoreLinkedNotebookList = new QListWidget();\r
153                 ignoreLinkedNotebookList.setSortingEnabled(true);\r
154                 ignoreLinkedNotebookList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
155                 closeLinkedNotebookLayout.addWidget(ignoreLinkedNotebookList);\r
156                 \r
157                 syncBookList.itemSelectionChanged.connect(this, "syncBookSelected()");\r
158                 ignoreBookList.itemSelectionChanged.connect(this, "ignoreBookSelected()");\r
159                 leftButton.clicked.connect(this, "toOpenList()");\r
160                 rightButton.clicked.connect(this, "toClosedList()");\r
161                 \r
162                 syncTagList.itemSelectionChanged.connect(this, "syncTagSelected()");\r
163                 ignoreTagList.itemSelectionChanged.connect(this, "ignoreTagSelected()");\r
164                 leftTagButton.clicked.connect(this, "toOpenTagList()");\r
165                 rightTagButton.clicked.connect(this, "toClosedTagList()");\r
166                 \r
167                 syncLinkedNotebookList.itemSelectionChanged.connect(this, "syncLinkedNotebookSelected()");\r
168                 ignoreLinkedNotebookList.itemSelectionChanged.connect(this, "ignoreLinkedNotebookSelected()");\r
169                 leftLinkedNotebookButton.clicked.connect(this, "toOpenLinkedNotebookList()");\r
170                 rightLinkedNotebookButton.clicked.connect(this, "toClosedLinkedNotebookList()");\r
171                 \r
172                 QHBoxLayout buttonLayout = new QHBoxLayout();\r
173                 buttonLayout.addStretch(1);\r
174                 buttonLayout.addWidget(okButton);\r
175                 buttonLayout.addWidget(cancelButton);\r
176                 setWindowTitle(tr("Open/Close Notebooks"));\r
177                 \r
178                 QHBoxLayout upperLayout = new QHBoxLayout();\r
179                 upperLayout.addLayout(openLayout);\r
180                 upperLayout.addLayout(middleLayout);\r
181                 upperLayout.addLayout(closeLayout);\r
182                 \r
183                 QHBoxLayout tagLayout = new QHBoxLayout();\r
184                 tagLayout.addLayout(openTagLayout);\r
185                 tagLayout.addLayout(middleTagLayout);\r
186                 tagLayout.addLayout(closeTagLayout);\r
187                 \r
188                 QHBoxLayout linkedNotebookLayout = new QHBoxLayout();\r
189                 linkedNotebookLayout.addLayout(openLinkedNotebookLayout);\r
190                 linkedNotebookLayout.addLayout(middleLinkedNotebookLayout);\r
191                 linkedNotebookLayout.addLayout(closeLinkedNotebookLayout);\r
192                 \r
193                 QVBoxLayout mainLayout = new QVBoxLayout();\r
194                 mainLayout.addLayout(upperLayout);\r
195                 mainLayout.addLayout(tagLayout);\r
196                 mainLayout.addLayout(linkedNotebookLayout);\r
197                 mainLayout.addSpacing(1);\r
198                 mainLayout.addLayout(buttonLayout);\r
199                 setLayout(mainLayout);\r
200 \r
201                 for (int i=0; i<allBooks.size(); i++) {\r
202                         boolean found = false;\r
203                         for (int j=0; j<archive.size(); j++) {\r
204                                 if (archive.get(j).getName().equalsIgnoreCase(allBooks.get(i).getName())) {\r
205                                         found = true;\r
206                                         j=archive.size();\r
207                                 }\r
208                         }\r
209                         if (!found) {\r
210                                 QListWidgetItem item = new QListWidgetItem(allBooks.get(i).getName());\r
211                                 item.setSelected(false);\r
212                                 syncBookList.addItem(item);\r
213                         }\r
214                 }\r
215                 \r
216                 setWindowTitle(tr("Open Notebooks"));\r
217                 for (int i=0; i<archive.size(); i++) {\r
218                         QListWidgetItem item = new QListWidgetItem(archive.get(i).getName());\r
219                         item.setSelected(false);\r
220                         ignoreBookList.addItem(item);\r
221                 }\r
222                 \r
223                 for (int i=0; i<allTags.size(); i++) {\r
224                         boolean found = false;\r
225                         for (int j=0; j<ignoreTags.size(); j++) {\r
226                                 if (ignoreTags.get(j).getName().equalsIgnoreCase(allTags.get(i).getName())) {\r
227                                         found = true;\r
228                                         j=ignoreTags.size();\r
229                                 }\r
230                         }\r
231                         if (!found) {\r
232                                 QListWidgetItem item = new QListWidgetItem(allTags.get(i).getName());\r
233                                 item.setSelected(false);\r
234                                 syncTagList.addItem(item);\r
235                         }\r
236                 }\r
237                 for (int i=0; i<ignoreTags.size(); i++) {\r
238                         QListWidgetItem item = new QListWidgetItem(ignoreTags.get(i).getName());\r
239                         item.setSelected(false);\r
240                         ignoreTagList.addItem(item);\r
241                 }\r
242                 \r
243                 for (int i=0; i<allLinkedNotebooks.size(); i++) {\r
244                         boolean found = false;\r
245                         for (int j=0; j<ignoreLinkedNotebooks.size(); j++) {\r
246                                 if (ignoreLinkedNotebooks.get(j).getShareName().equalsIgnoreCase(allLinkedNotebooks.get(i).getShareName())) {\r
247                                         found = true;\r
248                                         j=ignoreLinkedNotebooks.size();\r
249                                 }\r
250                         }\r
251                         if (!found) {\r
252                                 QListWidgetItem item = new QListWidgetItem(allLinkedNotebooks.get(i).getShareName());\r
253                                 item.setSelected(false);\r
254                                 syncLinkedNotebookList.addItem(item);\r
255                         }\r
256                 }\r
257                 for (int i=0; i<ignoreLinkedNotebooks.size(); i++) {\r
258                         QListWidgetItem item = new QListWidgetItem(ignoreLinkedNotebooks.get(i).getShareName());\r
259                         item.setSelected(false);\r
260                         ignoreLinkedNotebookList.addItem(item);\r
261                 }\r
262 \r
263 \r
264                 syncBookList.itemSelectionChanged.connect(this, "itemSelected()");\r
265                 setWindowTitle(tr("Ignore Synchronized Notes"));\r
266 \r
267                 if (allLinkedNotebooks.size() == 0) {\r
268                         linkedLabelLeft.setVisible(false);\r
269                         linkedLabelRight.setVisible(false);\r
270                         rightLinkedNotebookButton.setVisible(false);\r
271                         leftLinkedNotebookButton.setVisible(false);\r
272                         ignoreLinkedNotebookList.setVisible(false);\r
273                         syncLinkedNotebookList.setVisible(false);\r
274                 }\r
275         }\r
276         \r
277         @SuppressWarnings("unused")\r
278         private void toClosedList() {\r
279                 List<QListWidgetItem> items = syncBookList.selectedItems();\r
280                 for (int i=items.size()-1; i>=0; i--) {\r
281                         int row = syncBookList.row(items.get(i));\r
282                         syncBookList.takeItem(row);\r
283                         ignoreBookList.addItem(items.get(i).text());\r
284                 }\r
285                 if (syncBookList.count() == 0)\r
286                         okButton.setEnabled(false);\r
287                 rightButton.setEnabled(false);\r
288         }\r
289         \r
290         \r
291         @SuppressWarnings("unused")\r
292         private void toOpenList() {\r
293                 List<QListWidgetItem> items = ignoreBookList.selectedItems();\r
294                 for (int i=items.size()-1; i>=0; i--) {\r
295                         int row = ignoreBookList.row(items.get(i));\r
296                         ignoreBookList.takeItem(row);\r
297                         syncBookList.addItem(items.get(i).text());\r
298                 }\r
299                 okButton.setEnabled(true);\r
300                 leftButton.setEnabled(false);\r
301         }\r
302         \r
303         \r
304         @SuppressWarnings("unused")\r
305         private void toClosedTagList() {\r
306                 List<QListWidgetItem> items = syncTagList.selectedItems();\r
307                 for (int i=items.size()-1; i>=0; i--) {\r
308                         int row = syncTagList.row(items.get(i));\r
309                         syncTagList.takeItem(row);\r
310                         ignoreTagList.addItem(items.get(i).text());\r
311                 }\r
312                 rightTagButton.setEnabled(false);\r
313         }\r
314         \r
315         \r
316         @SuppressWarnings("unused")\r
317         private void toOpenTagList() {\r
318                 List<QListWidgetItem> items = ignoreTagList.selectedItems();\r
319                 for (int i=items.size()-1; i>=0; i--) {\r
320                         int row = ignoreTagList.row(items.get(i));\r
321                         ignoreTagList.takeItem(row);\r
322                         syncTagList.addItem(items.get(i).text());\r
323                 }\r
324                 leftTagButton.setEnabled(false);\r
325         }\r
326         \r
327         @SuppressWarnings("unused")\r
328         private void toClosedLinkedNotebookList() {\r
329                 List<QListWidgetItem> items = syncLinkedNotebookList.selectedItems();\r
330                 for (int i=items.size()-1; i>=0; i--) {\r
331                         int row = syncLinkedNotebookList.row(items.get(i));\r
332                         syncLinkedNotebookList.takeItem(row);\r
333                         ignoreLinkedNotebookList.addItem(items.get(i).text());\r
334                 }\r
335                 rightLinkedNotebookButton.setEnabled(false);\r
336         }\r
337         \r
338         \r
339         @SuppressWarnings("unused")\r
340         private void toOpenLinkedNotebookList() {\r
341                 List<QListWidgetItem> items = ignoreLinkedNotebookList.selectedItems();\r
342                 for (int i=items.size()-1; i>=0; i--) {\r
343                         int row = ignoreLinkedNotebookList.row(items.get(i));\r
344                         ignoreLinkedNotebookList.takeItem(row);\r
345                         syncLinkedNotebookList.addItem(items.get(i).text());\r
346                 }\r
347                 leftLinkedNotebookButton.setEnabled(false);\r
348         }\r
349         \r
350         \r
351         @SuppressWarnings("unused")\r
352         private void ignoreBookSelected() {\r
353                 if (ignoreBookList.selectedItems().size() > 0)\r
354                         leftButton.setEnabled(true);\r
355                 else\r
356                         leftButton.setEnabled(false);\r
357         }\r
358         \r
359         @SuppressWarnings("unused")\r
360         private void syncBookSelected() {\r
361                 if (syncBookList.selectedItems().size() > 0)\r
362                         rightButton.setEnabled(true);\r
363                 else\r
364                         rightButton.setEnabled(false);\r
365         }\r
366         \r
367         @SuppressWarnings("unused")\r
368         private void ignoreTagSelected() {\r
369                 if (ignoreTagList.selectedItems().size() > 0)\r
370                         leftTagButton.setEnabled(true);\r
371                 else\r
372                         leftTagButton.setEnabled(false);\r
373         }\r
374         \r
375         @SuppressWarnings("unused")\r
376         private void syncTagSelected() {\r
377                 if (syncTagList.selectedItems().size() > 0)\r
378                         rightTagButton.setEnabled(true);\r
379                 else\r
380                         rightTagButton.setEnabled(false);\r
381         }\r
382         \r
383         @SuppressWarnings("unused")\r
384         private void ignoreLinkedNotebookSelected() {\r
385                 if (ignoreLinkedNotebookList.selectedItems().size() > 0)\r
386                         leftLinkedNotebookButton.setEnabled(true);\r
387                 else\r
388                         leftLinkedNotebookButton.setEnabled(false);\r
389         }\r
390         \r
391         @SuppressWarnings("unused")\r
392         private void syncLinkedNotebookSelected() {\r
393                 if (syncLinkedNotebookList.selectedItems().size() > 0)\r
394                         rightLinkedNotebookButton.setEnabled(true);\r
395                 else\r
396                         rightLinkedNotebookButton.setEnabled(false);\r
397         }\r
398         \r
399         @SuppressWarnings("unused")\r
400         private void onClicked() {\r
401                 okClicked = true;\r
402                 close();\r
403         }\r
404         \r
405         @SuppressWarnings("unused")\r
406         private void onCancel() {\r
407                 okClicked = false;\r
408                 close();\r
409         }\r
410         \r
411         public boolean okClicked() {\r
412                 return okClicked;\r
413         }\r
414         \r
415         public QListWidget getSyncBookList() {\r
416                 return syncBookList;\r
417         }\r
418         \r
419         public QListWidget getIgnoredBookList() {\r
420                 return ignoreBookList;\r
421         }\r
422         \r
423         public QListWidget getSyncTagList() {\r
424                 return syncTagList;\r
425         }\r
426         \r
427         public QListWidget getIgnoredTagList() {\r
428                 return ignoreTagList;\r
429         }\r
430         \r
431         public QListWidget getSyncLinkedNotebookList() {\r
432                 return syncLinkedNotebookList;\r
433         }\r
434         \r
435         public QListWidget getIgnoredLinkedNotebookList() {\r
436                 return ignoreLinkedNotebookList;\r
437         }\r
438         \r
439         @SuppressWarnings("unused")\r
440         private void itemSelected() {\r
441                 if (syncBookList.selectedItems().size() == syncBookList.count()) {\r
442                         okButton.setEnabled(false);\r
443                         rightButton.setEnabled(false);\r
444                         return;\r
445                 }\r
446                 rightButton.setEnabled(true);\r
447                 okButton.setEnabled(true);\r
448         }\r
449 }\r