From: Niki Roo Date: Tue, 5 May 2020 16:48:18 +0000 (+0200) Subject: update to follow fanfix X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=83484ac184bf7941e1ac6abd1a993b093f90f0a4;p=fanfix-jexer.git update to follow fanfix --- diff --git a/src/be/nikiroo/fanfix_jexer/Main.java b/src/be/nikiroo/fanfix_jexer/Main.java index f5c53a3..d540b47 100644 --- a/src/be/nikiroo/fanfix_jexer/Main.java +++ b/src/be/nikiroo/fanfix_jexer/Main.java @@ -1,9 +1,6 @@ package be.nikiroo.fanfix_jexer; -import java.io.IOException; - import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.reader.Reader.ReaderType; import be.nikiroo.fanfix_jexer.reader.TuiReader; /** @@ -32,8 +29,6 @@ public class Main { } Instance.init(); - - TuiReader.setDefaultReaderType(ReaderType.TUI); - new TuiReader().browse(null); + new TuiReader().start(null); } } diff --git a/src/be/nikiroo/fanfix_jexer/reader/TuiReader.java b/src/be/nikiroo/fanfix_jexer/reader/TuiReader.java index 7eb0f25..beee855 100644 --- a/src/be/nikiroo/fanfix_jexer/reader/TuiReader.java +++ b/src/be/nikiroo/fanfix_jexer/reader/TuiReader.java @@ -1,13 +1,11 @@ package be.nikiroo.fanfix_jexer.reader; -import java.io.IOException; +import java.io.Reader; -import jexer.TApplication; -import jexer.TApplication.BackendType; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.reader.BasicReader; -import be.nikiroo.fanfix.reader.Reader; -import be.nikiroo.fanfix.supported.SupportType; +import jexer.TApplication; +import jexer.TApplication.BackendType; /** * This {@link Reader}is based upon the TUI widget library 'jexer' @@ -50,26 +48,7 @@ public class TuiReader extends BasicReader { return backendType; } - @Override - public void read(boolean sync) throws IOException { - // TODO - if (!sync) { - // How could you do a not-sync in TUI mode? - throw new java.lang.IllegalStateException( - "Async mode not implemented yet."); - } - - try { - TuiReaderApplication app = new TuiReaderApplication(this, - guessBackendType()); - app.run(); - } catch (Exception e) { - Instance.getInstance().getTraceHandler().error(e); - } - } - - @Override - public void browse(String source) { + public void start(String source) { try { TuiReaderApplication app = new TuiReaderApplication(this, source, guessBackendType()); @@ -78,30 +57,4 @@ public class TuiReader extends BasicReader { Instance.getInstance().getTraceHandler().error(e); } } - - @Override - public void search(boolean sync) throws IOException { - // TODO - if (sync) { - throw new java.lang.IllegalStateException("Not implemented yet."); - } - } - - @Override - public void search(SupportType searchOn, String keywords, int page, - int item, boolean sync) { - // TODO - if (sync) { - throw new java.lang.IllegalStateException("Not implemented yet."); - } - } - - @Override - public void searchTag(SupportType searchOn, int page, int item, - boolean sync, Integer... tags) { - // TODO - if (sync) { - throw new java.lang.IllegalStateException("Not implemented yet."); - } - } } diff --git a/src/be/nikiroo/fanfix_jexer/reader/TuiReaderApplication.java b/src/be/nikiroo/fanfix_jexer/reader/TuiReaderApplication.java index f621309..3f8b4e3 100644 --- a/src/be/nikiroo/fanfix_jexer/reader/TuiReaderApplication.java +++ b/src/be/nikiroo/fanfix_jexer/reader/TuiReaderApplication.java @@ -3,9 +3,17 @@ package be.nikiroo.fanfix_jexer.reader; import java.awt.Toolkit; import java.awt.datatransfer.DataFlavor; import java.io.IOException; +import java.io.Reader; import java.net.URL; import java.net.UnknownHostException; +import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.fanfix.data.Story; +import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.fanfix.reader.BasicReader; +import be.nikiroo.fanfix.supported.BasicSupport; +import be.nikiroo.fanfix_jexer.reader.TuiReaderMainWindow.Mode; import jexer.TApplication; import jexer.TCommand; import jexer.TKeypress; @@ -18,15 +26,6 @@ import jexer.TWindow; import jexer.event.TCommandEvent; import jexer.event.TMenuEvent; import jexer.menu.TMenu; -import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.data.MetaData; -import be.nikiroo.fanfix.data.Story; -import be.nikiroo.fanfix.library.BasicLibrary; -import be.nikiroo.fanfix.reader.BasicReader; -import be.nikiroo.fanfix.reader.Reader; -import be.nikiroo.fanfix.supported.SupportType; -import be.nikiroo.fanfix_jexer.reader.TuiReaderMainWindow.Mode; -import be.nikiroo.utils.Progress; /** * Manages the TUI general mode and links and manages the {@link TWindow}s. @@ -36,7 +35,7 @@ import be.nikiroo.utils.Progress; * * @author niki */ -class TuiReaderApplication extends TApplication implements Reader { +class TuiReaderApplication extends TApplication { public static final int MENU_FILE_OPEN = 1025; public static final int MENU_FILE_IMPORT_URL = 1026; public static final int MENU_FILE_IMPORT_FILE = 1027; @@ -52,21 +51,10 @@ class TuiReaderApplication extends TApplication implements Reader { public static final TCommand CMD_EXIT = new TCommand(MENU_FILE_EXIT) { }; - private Reader reader; + private TuiReader reader; private TuiReaderMainWindow main; - // start reading if meta present - public TuiReaderApplication(Reader reader, BackendType backend) - throws Exception { - super(backend); - init(reader); - - if (getMeta() != null) { - read(false); - } - } - - public TuiReaderApplication(Reader reader, String source, + public TuiReaderApplication(TuiReader reader, String source, TApplication.BackendType backend) throws Exception { super(backend); init(reader); @@ -75,80 +63,17 @@ class TuiReaderApplication extends TApplication implements Reader { main.setMode(Mode.SOURCE, source); } - @Override - public void read(boolean sync) throws IOException { - read(getStory(null), sync); - } - - @Override - public MetaData getMeta() { - return reader.getMeta(); - } - - @Override - public Story getStory(Progress pg) throws IOException { - return reader.getStory(pg); - } - - @Override + /** + * @deprecated use {@link Instance} instead + */ + @Deprecated public BasicLibrary getLibrary() { - return reader.getLibrary(); - } - - @Override - public void setLibrary(BasicLibrary lib) { - reader.setLibrary(lib); + return Instance.getInstance().getLibrary(); } - - @Override - public void setMeta(MetaData meta) throws IOException { - reader.setMeta(meta); - } - - @Override - public void setMeta(String luid) throws IOException { - reader.setMeta(luid); - } - - @Override - public void setMeta(URL source, Progress pg) throws IOException { - reader.setMeta(source, pg); - } - - @Override - public void browse(String source) { - try { - reader.browse(source); - } catch (IOException e) { - Instance.getInstance().getTraceHandler().error(e); - } - } - - @Override - public int getChapter() { - return reader.getChapter(); - } - - @Override - public void setChapter(int chapter) { - reader.setChapter(chapter); - } - - @Override - public void search(boolean sync) throws IOException { - reader.search(sync); - } - - @Override - public void search(SupportType searchOn, String keywords, int page, - int item, boolean sync) throws IOException { - reader.search(searchOn, keywords, page, item, sync); - } - - @Override - public void searchTag(SupportType searchOn, int page, int item, - boolean sync, Integer... tags) throws IOException { - reader.searchTag(searchOn, page, item, sync, tags); + + public void read(MetaData meta, int chap) throws IOException { + Story story = getLibrary().getStory(meta.getLuid(), null); + read(story, chap); } /** @@ -157,25 +82,22 @@ class TuiReaderApplication extends TApplication implements Reader { * * @param story * the {@link Story} to read - * @param sync - * execute the process synchronously (wait until it is terminated - * before returning) * * @throws IOException * in case of I/O errors */ - public void read(Story story, boolean sync) throws IOException { + public void read(Story story, int chap) throws IOException { if (story == null) { throw new IOException("No story to read"); } // TODO: open in editor + external option if (!story.getMeta().isImageDocument()) { - TWindow window = new TuiReaderStoryWindow(this, story, getChapter()); + TWindow window = new TuiReaderStoryWindow(this, story, chap); window.maximize(); } else { try { - openExternal(getLibrary(), story.getMeta().getLuid(), sync); + openExternal(getLibrary(), story.getMeta().getLuid(), false); } catch (IOException e) { messageBox("Error when trying to open the story", e.getMessage(), TMessageBox.Type.OK); @@ -215,7 +137,7 @@ class TuiReaderApplication extends TApplication implements Reader { } } - private void init(Reader reader) { + private void init(TuiReader reader) { this.reader = reader; // TODO: traces/errors? @@ -272,8 +194,21 @@ class TuiReaderApplication extends TApplication implements Reader { String openfile = null; try { openfile = fileOpenBox("."); - reader.setMeta(BasicReader.getUrl(openfile), null); - read(false); + URL url = BasicReader.getUrl(openfile); + + try { + BasicSupport support = BasicSupport + .getSupport(BasicReader.getUrl(openfile)); + if (support == null) { + Instance.getInstance().getTraceHandler() + .error("URL not supported: " + openfile); + } + + read(support.process(null), -1); + } catch (IOException e) { + Instance.getInstance().getTraceHandler() + .error(new IOException("Failed to read book", e)); + } } catch (IOException e) { // TODO: i18n error("Fail to open file" @@ -299,7 +234,7 @@ class TuiReaderApplication extends TApplication implements Reader { + story + "\"", Type.OKCANCEL); if (mbox.getResult() == Result.OK) { try { - reader.getLibrary().delete(luid); + getLibrary().delete(luid); if (main != null) { main.refreshStories(); } @@ -385,7 +320,7 @@ class TuiReaderApplication extends TApplication implements Reader { */ private boolean imprt(String url) throws IOException { try { - reader.getLibrary().imprt(BasicReader.getUrl(url), null); + getLibrary().imprt(BasicReader.getUrl(url), null); main.refreshStories(); return true; } catch (UnknownHostException e) { @@ -393,7 +328,6 @@ class TuiReaderApplication extends TApplication implements Reader { } } - @Override public void openExternal(BasicLibrary lib, String luid, boolean sync) throws IOException { reader.openExternal(lib, luid, sync); diff --git a/src/be/nikiroo/fanfix_jexer/reader/TuiReaderMainWindow.java b/src/be/nikiroo/fanfix_jexer/reader/TuiReaderMainWindow.java index 2429583..b8edb5a 100644 --- a/src/be/nikiroo/fanfix_jexer/reader/TuiReaderMainWindow.java +++ b/src/be/nikiroo/fanfix_jexer/reader/TuiReaderMainWindow.java @@ -312,9 +312,7 @@ class TuiReaderMainWindow extends TWindow { public void readStory(MetaData meta) { try { - reader.setChapter(-1); - reader.setMeta(meta); - reader.read(false); + reader.read(meta, -1); } catch (IOException e) { Instance.getInstance().getTraceHandler().error(e); }