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'
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());
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.");
- }
- }
}
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;
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.
*
* @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;
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);
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);
}
/**
*
* @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);
}
}
- private void init(Reader reader) {
+ private void init(TuiReader reader) {
this.reader = reader;
// TODO: traces/errors?
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"
+ story + "\"", Type.OKCANCEL);
if (mbox.getResult() == Result.OK) {
try {
- reader.getLibrary().delete(luid);
+ getLibrary().delete(luid);
if (main != null) {
main.refreshStories();
}
*/
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) {
}
}
- @Override
public void openExternal(BasicLibrary lib, String luid, boolean sync)
throws IOException {
reader.openExternal(lib, luid, sync);