From: Niki Roo Date: Sun, 26 Apr 2020 19:40:21 +0000 (+0200) Subject: allow setSourceAuthorCover X-Git-Tag: fanfix-swing-1.0.0~17 X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=79c9e0b7077d44480c407f2d31dc3b2ff548bafd;p=fanfix-swing.git allow setSourceAuthorCover --- diff --git a/src/be/nikiroo/fanfix_swing/gui/BooksPanelActions.java b/src/be/nikiroo/fanfix_swing/gui/BooksPanelActions.java index 86667c6e..bf4e1285 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BooksPanelActions.java +++ b/src/be/nikiroo/fanfix_swing/gui/BooksPanelActions.java @@ -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() { + @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) {