X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibrary.java;h=5052fa279dd4cdcbe127a61edd8f2a00ca4bf9a6;hb=16a81ef7656c5c692fb831927e75edde25dd77a0;hp=7b52fe3639e9683517b8af88de0f436eb515a451;hpb=edf79e5e06e8dc177cc13b9bad5bf848e6f9741d;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/library/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java index 7b52fe3..5052fa2 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibrary.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibrary.java @@ -1,6 +1,5 @@ package be.nikiroo.fanfix.library; -import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.net.URL; @@ -11,6 +10,7 @@ import java.util.List; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; +import be.nikiroo.utils.Image; import be.nikiroo.utils.Progress; import be.nikiroo.utils.StringUtils; import be.nikiroo.utils.Version; @@ -95,15 +95,15 @@ public class RemoteLibrary extends BasicLibrary { } @Override - public BufferedImage getCover(final String luid) { - final BufferedImage[] result = new BufferedImage[1]; + public Image getCover(final String luid) { + final Image[] result = new Image[1]; try { new ConnectActionClientObject(host, port, true) { @Override public void action(Version serverVersion) throws Exception { Object rep = send(new Object[] { md5, "GET_COVER", luid }); - result[0] = (BufferedImage) rep; + result[0] = (Image) rep; } @Override @@ -119,8 +119,8 @@ public class RemoteLibrary extends BasicLibrary { } @Override - public BufferedImage getSourceCover(final String source) { - final BufferedImage[] result = new BufferedImage[1]; + public Image getSourceCover(final String source) { + final Image[] result = new Image[1]; try { new ConnectActionClientObject(host, port, true) { @@ -128,7 +128,7 @@ public class RemoteLibrary extends BasicLibrary { public void action(Version serverVersion) throws Exception { Object rep = send(new Object[] { md5, "GET_SOURCE_COVER", source }); - result[0] = (BufferedImage) rep; + result[0] = (Image) rep; } @Override @@ -233,8 +233,7 @@ public class RemoteLibrary extends BasicLibrary { }.connect(); // because the meta changed: - clearCache(); - refresh(pgRefresh); + invalidateInfo(luidSaved[0]); MetaData meta = getInfo(luidSaved[0]); meta.setCover(story.getMeta().getCover()); @@ -396,8 +395,57 @@ public class RemoteLibrary extends BasicLibrary { } } + @Override + public synchronized MetaData getInfo(String luid) { + List metas = getMetasList(luid, null); + if (!metas.isEmpty()) { + return metas.get(0); + } + + return null; + } + @Override protected List getMetas(Progress pg) { + return getMetasList("*", pg); + } + + @Override + protected void invalidateInfo(String luid) { + } + + // The following methods are only used by Save and Delete in BasicLibrary: + + @Override + protected int getNextId() { + throw new java.lang.InternalError("Should not have been called"); + } + + @Override + protected void doDelete(String luid) throws IOException { + throw new java.lang.InternalError("Should not have been called"); + } + + @Override + protected Story doSave(Story story, Progress pg) throws IOException { + throw new java.lang.InternalError("Should not have been called"); + } + + // + + /** + * Return the meta of the given story or a list of all known metas if the + * luid is "*". + * + * @param luid + * the luid of the story or * + * @param pg + * the optional progress + * + * + * @return the metas + */ + private List getMetasList(final String luid, Progress pg) { final Progress pgF = pg; final List metas = new ArrayList(); @@ -410,7 +458,7 @@ public class RemoteLibrary extends BasicLibrary { pg = new Progress(); } - Object rep = send(new Object[] { md5, "GET_METADATA", "*" }); + Object rep = send(new Object[] { md5, "GET_METADATA", luid }); while (true) { if (!RemoteLibraryServer.updateProgress(pg, rep)) { @@ -420,8 +468,12 @@ public class RemoteLibrary extends BasicLibrary { rep = send(null); } - for (MetaData meta : (MetaData[]) rep) { - metas.add(meta); + if (rep instanceof MetaData[]) { + for (MetaData meta : (MetaData[]) rep) { + metas.add(meta); + } + } else if (rep != null) { + metas.add((MetaData) rep); } } @@ -436,25 +488,4 @@ public class RemoteLibrary extends BasicLibrary { return metas; } - - @Override - protected void clearCache() { - } - - // The following methods are only used by Save and Delete in BasicLibrary: - - @Override - protected int getNextId() { - throw new java.lang.InternalError("Should not have been called"); - } - - @Override - protected void doDelete(String luid) throws IOException { - throw new java.lang.InternalError("Should not have been called"); - } - - @Override - protected Story doSave(Story story, Progress pg) throws IOException { - throw new java.lang.InternalError("Should not have been called"); - } }