X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibraryServer.java;h=c150a01b6f8a14f68279fc4bb7358f3374a85e10;hb=f433d15308b70e23280a65cef8c54002a7a971ce;hp=4ee3f74d221c3497978cc57d70fc935fd466579f;hpb=3177622aa63d2e126ce9426b440a3443a2ea8bab;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java index 4ee3f74..c150a01 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java @@ -70,16 +70,16 @@ public class RemoteLibraryServer extends ServerObject { * Note: the key we use here is the encryption key (it must not contain a * subkey). * - * @param key - * the key that will restrict access to this server - * @param port - * the port to listen on - * * @throws IOException * in case of I/O error */ - public RemoteLibraryServer(String key, int port) throws IOException { - super("Fanfix remote library", port, key); + public RemoteLibraryServer() throws IOException { + super("Fanfix remote library", + Instance.getInstance().getConfig() + .getInteger(Config.SERVER_PORT), + Instance.getInstance().getConfig() + .getString(Config.SERVER_KEY)); + setTraceHandler(Instance.getInstance().getTraceHandler()); } @@ -405,22 +405,45 @@ public class RemoteLibraryServer extends ServerObject { * @return TRUE if it was a progress event, FALSE if not */ static boolean updateProgress(Progress pg, Object rep) { - if (rep instanceof Object[]) { + boolean updateProgress = false; + if (rep instanceof Integer[] && ((Integer[]) rep).length == 3) + updateProgress = true; + if (rep instanceof Object[] && ((Object[]) rep).length >= 5 + && "UPDATE".equals(((Object[]) rep)[0])) + updateProgress = true; + + if (updateProgress) { Object[] a = (Object[]) rep; - if (a.length >= 3) { - int min = (Integer)a[0]; - int max = (Integer)a[1]; - int progress = (Integer)a[2]; - - if (min >= 0 && min <= max) { - pg.setMinMax(min, max); - pg.setProgress(progress); - if (a.length >= 4) { - pg.put("meta", a[3]); - } - return true; + int offset = 0; + if (a[0] instanceof String) { + offset = 1; + } + + int min = (Integer) a[0 + offset]; + int max = (Integer) a[1 + offset]; + int progress = (Integer) a[2 + offset]; + + Object meta = null; + if (a.length > (3 + offset)) { + meta = a[3 + offset]; + } + + String name = null; + if (a.length > (4 + offset)) { + name = a[4 + offset] == null ? "" : a[4 + offset].toString(); + } + + + if (min >= 0 && min <= max) { + pg.setName(name); + pg.setMinMax(min, max); + pg.setProgress(progress); + if (meta != null) { + pg.put("meta", meta); } + + return true; } } @@ -447,6 +470,7 @@ public class RemoteLibraryServer extends ServerObject { final Integer[] p = new Integer[] { -1, -1, -1 }; final Object[] pMeta = new MetaData[1]; + final String[] pName = new String[1]; final Long[] lastTime = new Long[] { new Date().getTime() }; pg.addProgressListener(new ProgressListener() { @Override @@ -467,15 +491,18 @@ public class RemoteLibraryServer extends ServerObject { // Do not re-send the same value twice over the wire, // unless more than 2 seconds have elapsed (to maintain the // connection) - if (!samePg || !same(pMeta[0], meta) // + if (!samePg || !same(pMeta[0], meta) + || !same(pName[0], name) // || (new Date().getTime() - lastTime[0] > 2000)) { p[0] = min; p[1] = max; p[2] = rel; pMeta[0] = meta; + pName[0] = name; try { - action.send(new Object[] { min, max, rel, meta }); + action.send(new Object[] { "UPDATE", min, max, rel, + meta, name }); action.rec(); } catch (Exception e) { getTraceHandler().error(e); @@ -512,12 +539,14 @@ public class RemoteLibraryServer extends ServerObject { } private MetaData removeCover(MetaData meta) { - MetaData light; - if (meta.getCover() == null) { - light = meta; - } else { - light = meta.clone(); - light.setCover(null); + MetaData light = null; + if (meta != null) { + if (meta.getCover() == null) { + light = meta; + } else { + light = meta.clone(); + light.setCover(null); + } } return light;