X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibrary.java;h=63082ce94fd0a954790865d4a4ddc19fbf6c5ebb;hb=e604986c4208da0091d26bc0e1c4feb4ff3c588f;hp=337e13fe7394c36f4d089f0e25700e487ed6c4d6;hpb=99ccbdf63b539f1f40e070f5833f2d15fcf79830;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/library/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java index 337e13f..63082ce 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibrary.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibrary.java @@ -9,7 +9,6 @@ import java.util.List; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; -import be.nikiroo.fanfix.output.BasicOutput.OutputType; import be.nikiroo.utils.Progress; import be.nikiroo.utils.Version; import be.nikiroo.utils.serial.ConnectActionClient; @@ -44,8 +43,7 @@ public class RemoteLibrary extends BasicLibrary { this.baseDir = Instance.getRemoteDir(host); this.baseDir.mkdirs(); - this.lib = new LocalLibrary(baseDir, OutputType.INFO_TEXT, - OutputType.CBZ); + this.lib = new LocalLibrary(baseDir); } @Override @@ -61,7 +59,7 @@ public class RemoteLibrary extends BasicLibrary { metas = new ArrayList(); try { - new ConnectActionClient(host, port, true, null) { + new ConnectActionClient(host, port, true) { @Override public void action(Version serverVersion) throws Exception { try { @@ -77,6 +75,14 @@ public class RemoteLibrary extends BasicLibrary { } catch (IOException e) { Instance.syserr(e); } + + List test = new ArrayList(); + for (MetaData meta : metas) { + if (test.contains(meta.getLuid())) { + throw new RuntimeException("wwops"); + } + test.add(meta.getLuid()); + } } return metas; @@ -88,7 +94,7 @@ public class RemoteLibrary extends BasicLibrary { if (file == null) { final File[] tmp = new File[1]; try { - new ConnectActionClient(host, port, true, null) { + new ConnectActionClient(host, port, true) { @Override public void action(Version serverVersion) throws Exception { try { @@ -119,13 +125,30 @@ public class RemoteLibrary extends BasicLibrary { } @Override - public BufferedImage getCover(String luid) { - // Retrieve it from the network if needed: - if (lib.getInfo(luid) == null) { - getFile(luid); + public BufferedImage getCover(final String luid) { + // Retrieve it from the cache if possible: + if (lib.getInfo(luid) != null) { + return lib.getCover(luid); + } + + final BufferedImage[] result = new BufferedImage[1]; + try { + new ConnectActionClient(host, port, true) { + @Override + public void action(Version serverVersion) throws Exception { + try { + Object rep = send("GET_COVER " + luid); + result[0] = (BufferedImage) rep; + } catch (Exception e) { + Instance.syserr(e); + } + } + }.connect(); + } catch (IOException e) { + Instance.syserr(e); } - return lib.getCover(luid); + return result[0]; } @Override @@ -170,4 +193,13 @@ public class RemoteLibrary extends BasicLibrary { protected Story doSave(Story story, Progress pg) throws IOException { throw new java.lang.InternalError("Should not have been called"); } + + /** + * Return the backing local library. + * + * @return the library + */ + LocalLibrary getLocalLibrary() { + return lib; + } }