X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibrary.java;h=7b52fe3639e9683517b8af88de0f436eb515a451;hb=edf79e5e06e8dc177cc13b9bad5bf848e6f9741d;hp=f3104135f2977b689a222ea68242c8bc5be75d27;hpb=0fa0fe9552e57bf05d8dd295a9d96d2364730c4e;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/library/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java index f310413..7b52fe3 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibrary.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibrary.java @@ -3,6 +3,7 @@ package be.nikiroo.fanfix.library; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.net.URL; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; @@ -220,8 +221,7 @@ public class RemoteLibrary extends BasicLibrary { pg.add(1); } - send(null); // done sending the story - luidSaved[0] = (String) send(null); // get LUID + luidSaved[0] = (String) send(null); pg.done(); } @@ -235,7 +235,10 @@ public class RemoteLibrary extends BasicLibrary { // because the meta changed: clearCache(); refresh(pgRefresh); - story.setMeta(getInfo(luidSaved[0])); + + MetaData meta = getInfo(luidSaved[0]); + meta.setCover(story.getMeta().getCover()); + story.setMeta(meta); pg.done(); @@ -276,6 +279,96 @@ public class RemoteLibrary extends BasicLibrary { } } + @Override + // Could work (more slowly) without it + public Story imprt(final URL url, Progress pg) throws IOException { + if (pg == null) { + pg = new Progress(); + } + + pg.setMinMax(0, 2); + Progress pgImprt = new Progress(); + Progress pgGet = new Progress(); + pg.addProgress(pgImprt, 1); + pg.addProgress(pgGet, 1); + + final Progress pgF = pgImprt; + final String[] luid = new String[1]; + + try { + new ConnectActionClientObject(host, port, true) { + @Override + public void action(Version serverVersion) throws Exception { + Progress pg = pgF; + + Object rep = send(new Object[] { md5, "IMPORT", + url.toString() }); + + while (true) { + if (!RemoteLibraryServer.updateProgress(pg, rep)) { + break; + } + + rep = send(null); + } + + pg.done(); + luid[0] = (String) rep; + } + + @Override + protected void onError(Exception e) { + Instance.getTraceHandler().error(e); + } + }.connect(); + } catch (IOException e) { + Instance.getTraceHandler().error(e); + } + + if (luid[0] == null) { + throw new IOException("Remote failure"); + } + + Story story = getStory(luid[0], pgGet); + pgGet.done(); + + pg.done(); + return story; + } + + @Override + // Could work (more slowly) without it + public synchronized void changeSource(final String luid, + final String newSource, Progress pg) throws IOException { + final Progress pgF = pg == null ? new Progress() : pg; + + try { + new ConnectActionClientObject(host, port, true) { + @Override + public void action(Version serverVersion) throws Exception { + Progress pg = pgF; + + Object rep = send(new Object[] { md5, "CHANGE_SOURCE", + luid, newSource }); + while (true) { + if (!RemoteLibraryServer.updateProgress(pg, rep)) { + break; + } + + rep = send(null); + } + } + + @Override + protected void onError(Exception e) { + Instance.getTraceHandler().error(e); + } + }.connect(); + } catch (IOException e) { + Instance.getTraceHandler().error(e); + } + } + @Override public synchronized File getFile(final String luid, Progress pg) { throw new java.lang.InternalError(