X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FGuiReader.java;h=8559cf112eb34b47dd923cf14b0011c2c4ae561b;hb=b89dfb6ece936486563734818ed62488a59e5897;hp=2c30ab6740ad49a46a070585fbe581326b75fc1f;hpb=6322ab64949f9f4ae2b04b9504d58a301039d670;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/GuiReader.java b/src/be/nikiroo/fanfix/reader/GuiReader.java index 2c30ab6..8559cf1 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReader.java +++ b/src/be/nikiroo/fanfix/reader/GuiReader.java @@ -15,6 +15,7 @@ import javax.swing.event.HyperlinkListener; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.VersionCheck; import be.nikiroo.fanfix.bundles.UiConfig; +import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.library.LocalLibrary; import be.nikiroo.fanfix.output.BasicOutput.OutputType; @@ -69,17 +70,15 @@ class GuiReader extends BasicReader { localLibrary = new LocalLibrary(dir, text, images); } + @Override public void read() throws IOException { - if (getStory() == null) { + MetaData meta = getMeta(); + + if (meta == null) { throw new IOException("No story to read"); } - open(getStory().getMeta().getLuid(), null); - } - - public void read(int chapter) throws IOException { - // TODO: show a special page? - read(); + read(meta.getLuid(), null); } /** @@ -94,21 +93,8 @@ class GuiReader extends BasicReader { * in case of I/O error */ public void imprt(String luid, Progress pg) throws IOException { - Progress pgGetStory = new Progress(); - Progress pgSave = new Progress(); - if (pg != null) { - pg.setMax(2); - pg.addProgress(pgGetStory, 1); - pg.addProgress(pgSave, 1); - } - try { - Story story = getLibrary().getStory(luid, pgGetStory); - if (story != null) { - story = localLibrary.save(story, luid, pgSave); - } else { - throw new IOException("Cannot find story in Library: " + luid); - } + localLibrary.imprt(getLibrary(), luid, pg); } catch (IOException e) { throw new IOException( "Cannot import story from library to LocalReader library: " @@ -129,6 +115,7 @@ class GuiReader extends BasicReader { return localLibrary.getInfo(luid) != null; } + @Override public void browse(String type) { // TODO: improve presentation of update message final VersionCheck updates = VersionCheck.check(); @@ -156,6 +143,7 @@ class GuiReader extends BasicReader { // handle link events updateMessage.addHyperlinkListener(new HyperlinkListener() { + @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType().equals( HyperlinkEvent.EventType.ACTIVATED)) @@ -174,6 +162,7 @@ class GuiReader extends BasicReader { final String typeFinal = type; EventQueue.invokeLater(new Runnable() { + @Override public void run() { if (updates.isNewVersionAvailable()) { int rep = JOptionPane.showConfirmDialog(null, @@ -203,7 +192,9 @@ class GuiReader extends BasicReader { // delete from main library void delete(String luid) { try { - localLibrary.delete(luid); + if (localLibrary.getInfo(luid) != null) { + localLibrary.delete(luid); + } getLibrary().delete(luid); } catch (IOException e) { Instance.syserr(e); @@ -211,20 +202,23 @@ class GuiReader extends BasicReader { } // open the given book - void open(String luid, Progress pg) throws IOException { + void read(String luid, Progress pg) throws IOException { File file = localLibrary.getFile(luid); if (file == null) { imprt(luid, pg); file = localLibrary.getFile(luid); } + // TODO: show a special page for the chapter? openExternal(getLibrary().getInfo(luid), file); } - void changeType(String luid, String newType) { + void changeType(String luid, String newSource) { try { - localLibrary.changeSource(luid, newType, null); - getLibrary().changeSource(luid, newType, null); + if (localLibrary.getInfo(luid) != null) { + localLibrary.changeSource(luid, newSource, null); + } + getLibrary().changeSource(luid, newSource, null); } catch (IOException e) { Instance.syserr(e); }