+ Instance.getInstance().getTraceHandler().error(e);
+ error(GuiReader.trans(StringIdGui.ERROR_CANNOT_OPEN),
+ GuiReader.trans(StringIdGui.TITLE_ERROR), e);
+ }
+ }
+ });
+ }
+
+ /**
+ * 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<String> luids = new LinkedList<String>();
+ try {
+ switch (book.getInfo().getType()) {
+ case STORY:
+ luids.add(book.getInfo().getMeta().getLuid());
+ break;
+ case SOURCE:
+ for (MetaData meta : helper.getReader().getLibrary()
+ .getList().filter(book.getInfo().getMainInfo(), null, null)) {
+ luids.add(meta.getLuid());
+ }
+ break;
+ case AUTHOR:
+ for (MetaData meta : helper.getReader().getLibrary()
+ .getList().filter(null, book.getInfo().getMainInfo(), null)) {
+ luids.add(meta.getLuid());
+ }
+ break;
+ }
+ } catch (IOException e) {
+ Instance.getInstance().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.getInstance().getTraceHandler().error(e);