X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FLocalReader.java;fp=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FLocalReader.java;h=26f48f5a21210fe4d6026b44d0e2bdae3cf3e2c1;hp=0000000000000000000000000000000000000000;hb=a6395bef99a8e917f67341ef1906917b87df24a4;hpb=73ce17ef4569e43d24f8413ad6b59bc2906aec07 diff --git a/src/be/nikiroo/fanfix/reader/LocalReader.java b/src/be/nikiroo/fanfix/reader/LocalReader.java new file mode 100644 index 0000000..26f48f5 --- /dev/null +++ b/src/be/nikiroo/fanfix/reader/LocalReader.java @@ -0,0 +1,92 @@ +package be.nikiroo.fanfix.reader; + +import java.awt.EventQueue; +import java.io.File; +import java.io.IOException; + +import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.Library; +import be.nikiroo.fanfix.bundles.Config; +import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.fanfix.data.Story; +import be.nikiroo.fanfix.output.BasicOutput.OutputType; +import be.nikiroo.fanfix.supported.BasicSupport.SupportType; + +class LocalReader extends BasicReader { + private Library lib; + + public LocalReader() throws IOException { + File dir = Instance.getReaderDir(); + dir.mkdirs(); + if (!dir.exists()) { + throw new IOException( + "Cannote create cache directory for local reader: " + dir); + } + + // TODO: can throw an exception, manage that (convert to IOEx ?) + OutputType text = OutputType.valueOfNullOkUC(Instance.getConfig() + .getString(Config.LOCAL_READER_NON_IMAGES_DOCUMENT_TYPE)); + if (text == null) { + text = OutputType.HTML; + } + + OutputType images = OutputType.valueOfNullOkUC(Instance.getConfig() + .getString(Config.LOCAL_READER_IMAGES_DOCUMENT_TYPE)); + if (images == null) { + images = OutputType.CBZ; + } + // + + lib = new Library(dir, text, images); + } + + @Override + public void read() throws IOException { + } + + @Override + public void read(int chapter) { + } + + // return new luid + public String imprt(String luid) { + try { + Story story = Instance.getLibrary().getStory(luid); + story = lib.save(story); + return story.getMeta().getLuid(); + } catch (IOException e) { + Instance.syserr(new IOException( + "Cannot import story from library to LocalReader library: " + + luid, e)); + } + + return null; + } + + public File getTarget(String luid) { + MetaData meta = lib.getInfo(luid); + File file = lib.getFile(luid); + if (file == null) { + luid = imprt(luid); + file = lib.getFile(luid); + meta = lib.getInfo(luid); + } + + return file; + } + + @Override + public void start(SupportType type) { + final SupportType typeFinal = type; + EventQueue.invokeLater(new Runnable() { + public void run() { + new LocalReaderFrame(LocalReader.this, typeFinal) + .setVisible(true); + } + }); + } + + public static void main(String[] args) throws IOException { + new LocalReader().start(null); + } +}