X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fui%2FGuiReaderMainPanel.java;fp=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fui%2FGuiReaderMainPanel.java;h=476e130b01bc6acd7eb4804ddd7d19ddc15db4c4;hb=ca7d4e2fe5a5ae4df2c6b07e6dedf5640d5b8650;hp=bae2742733b474c1f81e3c734a3cebb1e503d84d;hpb=c747c1f2b4225bc600d25d8ebef7b45e3cf6e7c7;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java index bae2742..476e130 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java @@ -17,6 +17,7 @@ import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -42,6 +43,7 @@ import be.nikiroo.fanfix.library.BasicLibrary.Status; import be.nikiroo.fanfix.library.LocalLibrary; import be.nikiroo.fanfix.reader.BasicReader; import be.nikiroo.fanfix.reader.ui.GuiReaderBook.BookActionListener; +import be.nikiroo.fanfix.reader.ui.GuiReaderBookInfo.Type; import be.nikiroo.utils.Progress; import be.nikiroo.utils.ui.ProgressBar; @@ -414,6 +416,70 @@ class GuiReaderMainPanel extends JPanel { } }); } + + /** + * Prefetch a {@link GuiReaderBook} item (which can be a group, in which + * case we prefetch all its members). + * + * @param book + * the {@link GuiReaderBook} to open + */ + public void prefetchBook(final GuiReaderBook book) { + final List luids = new LinkedList(); + try { + switch (book.getInfo().getType()) { + case STORY: + luids.add(book.getInfo().getMeta().getLuid()); + break; + case SOURCE: + for (MetaData meta : helper.getReader().getLibrary() + .getListBySource(book.getInfo().getMainInfo())) { + luids.add(meta.getLuid()); + } + break; + case AUTHOR: + for (MetaData meta : helper.getReader().getLibrary() + .getListByAuthor(book.getInfo().getMainInfo())) { + luids.add(meta.getLuid()); + } + break; + } + } catch (IOException e) { + Instance.getTraceHandler().error(e); + } + + final Progress pg = new Progress(); + pg.setMax(luids.size()); + + outOfUi(pg, false, new Runnable() { + @Override + public void run() { + try { + for (String luid : luids) { + Progress pgStep = new Progress(); + pg.addProgress(pgStep, 1); + + helper.getReader().prefetch(luid, pgStep); + } + + // TODO: also set the green button on sources/authors? + // requires to do the same when all stories inside are green + if (book.getInfo().getType() == Type.STORY) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + book.setCached(true); + } + }); + } + } catch (IOException e) { + Instance.getTraceHandler().error(e); + error(GuiReader.trans(StringIdGui.ERROR_CANNOT_OPEN), + GuiReader.trans(StringIdGui.TITLE_ERROR), e); + } + } + }); + } /** * Process the given action out of the Swing UI thread and link the given