X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibrary.java;h=a4f00ceff53546eaf1849e526c656add37fa6d17;hb=98b95fb81566ca8b04c8d891a02c8019d8bed63d;hp=511d1c1580cbf607069ab4c1b6fb34b6a1602843;hpb=211f7ddb50f68aa8a999023ef6d63d5756bdace6;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/library/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java deleted file mode 100644 index 511d1c1..0000000 --- a/src/be/nikiroo/fanfix/library/RemoteLibrary.java +++ /dev/null @@ -1,156 +0,0 @@ -package be.nikiroo.fanfix.library; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -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; - -/** - * This {@link BasicLibrary} will access a remote server to list the available - * stories, and download the one you try to load to the local directory - * specified in the configuration. - * - * @author niki - */ -public class RemoteLibrary extends BasicLibrary { - private String host; - private int port; - private File baseDir; - - private LocalLibrary lib; - private List metas; - - /** - * Create a {@link RemoteLibrary} linked to the given server. - * - * @param host - * the host to contact or NULL for localhost - * @param port - * the port to contact it on - */ - public RemoteLibrary(String host, int port) { - this.host = host; - this.port = port; - - this.baseDir = Instance.getRemoteDir(host); - this.baseDir.mkdirs(); - - this.lib = new LocalLibrary(baseDir, OutputType.INFO_TEXT, - OutputType.CBZ); - } - - @Override - protected List getMetas(Progress pg) { - // TODO: progress - - if (metas == null) { - metas = new ArrayList(); - - try { - new ConnectActionClient(host, port, true, null) { - @Override - public void action(Version serverVersion) throws Exception { - try { - Object rep = send("GET_METADATA *"); - for (MetaData meta : (MetaData[]) rep) { - metas.add(meta); - } - } catch (Exception e) { - Instance.syserr(e); - } - } - }.connect(); - } catch (IOException e) { - Instance.syserr(e); - } - } - - return metas; - } - - @Override - public synchronized File getFile(final String luid) { - File file = lib.getFile(luid); - if (file == null) { - final File[] tmp = new File[1]; - try { - new ConnectActionClient(host, port, true, null) { - @Override - public void action(Version serverVersion) throws Exception { - try { - Object rep = send("GET_STORY " + luid); - Story story = (Story) rep; - if (story != null) { - lib.save(story, luid, null); - tmp[0] = lib.getFile(luid); - } - } catch (Exception e) { - Instance.syserr(e); - } - } - }.connect(); - } catch (IOException e) { - Instance.syserr(e); - } - - file = tmp[0]; - } - - if (file != null) { - MetaData meta = getInfo(luid); - metas.add(meta); - } - - return file; - } - - @Override - public BufferedImage getCover(String luid) { - // Retrieve it from the network if needed: - if (lib.getInfo(luid) == null) { - getFile(luid); - } - - return lib.getCover(luid); - } - - @Override - protected void clearCache() { - metas = null; - lib.clearCache(); - } - - @Override - public synchronized Story save(Story story, String luid, Progress pg) - throws IOException { - throw new java.lang.InternalError( - "No write support allowed on remote Libraries"); - } - - @Override - protected int getNextId() { - throw new java.lang.InternalError( - "No write support allowed on remote Libraries"); - } - - @Override - protected void doDelete(String luid) throws IOException { - throw new java.lang.InternalError( - "No write support allowed on remote Libraries"); - } - - @Override - protected Story doSave(Story story, Progress pg) throws IOException { - throw new java.lang.InternalError( - "No write support allowed on remote Libraries"); - } -}