allow setSourceAuthorCover
authorNiki Roo <niki@nikiroo.be>
Sun, 26 Apr 2020 19:40:21 +0000 (21:40 +0200)
committerNiki Roo <niki@nikiroo.be>
Sun, 26 Apr 2020 19:40:21 +0000 (21:40 +0200)
src/be/nikiroo/fanfix_swing/gui/BooksPanelActions.java

index 86667c6e93d149d478aaca7cd43fe7a960c942b4..bf4e12856037332ed2bbb37a40e1bb945e0e5db2 100644 (file)
@@ -402,45 +402,44 @@ public class BooksPanelActions {
                }
        }
        
-       public void setCoverFor(ChangeAction what) {
-               // SOURCE:
-               
-               // final GuiReaderBook selectedBook =
-               // mainPanel.getSelectedBook();
-               // if (selectedBook != null) {
-               // BasicLibrary lib = lib;
-               // String luid = selectedBook.getInfo().getMeta().getLuid();
-               // String source = selectedBook.getInfo().getMeta().getSource();
-               //
-               // try {
-               // lib.setSourceCover(source, luid);
-               // } catch (IOException e) {
-               // error(e.getLocalizedMessage(), "IOException", e);
-               // }
-               //
-               // GuiReaderBookInfo sourceInfo =
-               // GuiReaderBookInfo.fromSource(lib, source);
-               // GuiReaderCoverImager.clearIcon(sourceInfo);
-               // }
-               
-               // AUTHOR:
-               
-               // final GuiReaderBook selectedBook =
-               // mainPanel.getSelectedBook();
-               // if (selectedBook != null) {
-               // String luid = selectedBook.getInfo().getMeta().getLuid();
-               // String author = selectedBook.getInfo().getMeta().getAuthor();
-               //
-               // try {
-               // lib.setAuthorCover(author, luid);
-               // } catch (IOException e) {
-               // error(e.getLocalizedMessage(), "IOException", e);
-               // }
-               //
-               // GuiReaderBookInfo authorInfo =
-               // GuiReaderBookInfo.fromAuthor(lib, author);
-               // GuiReaderCoverImager.clearIcon(authorInfo);
-               // }
+       public void setCoverFor(final ChangeAction what) {
+               final BookInfo book = informer.getUniqueSelected();
+               if (book != null) {
+                       final BasicLibrary lib = Instance.getInstance().getLibrary();
+                       final String luid = book.getMeta().getLuid();
+
+                       new SwingWorker<Void, Void>() {
+                               @Override
+                               protected Void doInBackground() throws Exception {
+                                       switch (what) {
+                                       case SOURCE:
+                                               lib.setSourceCover(book.getMeta().getSource(), luid);
+                                               break;
+                                       case AUTHOR:
+                                               lib.setAuthorCover(book.getMeta().getAuthor(), luid);
+                                               break;
+                                       case TITLE:
+                                               throw new IllegalArgumentException(
+                                                               "Cannot change TITLE cover");
+                                       }
+
+                                       return null;
+                               }
+
+                               @Override
+                               protected void done() {
+                                       try {
+                                               get();
+                                               // TODO: informer.what? (notify cover for source/author
+                                               // changed -> browser)
+                                               informer.invalidateCache();
+                                       } catch (Exception e) {
+                                               UiHelper.error(owner, e.getLocalizedMessage(),
+                                                               "IOException", e);
+                                       }
+                               }
+                       }.execute();
+               }
        }
        
        static private String trans(StringIdGui id, Object... values) {