From 085a2f9a3a811a910de7c3011eb6f5ef2ab18aa0 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sun, 26 Nov 2017 16:30:04 +0100 Subject: [PATCH] Improve remote, fix bugs, update nikiroo-utils --- changelog.md | 5 ++ ...es.jar => nikiroo-utils-2.2.2-sources.jar} | Bin 259994 -> 260060 bytes src/be/nikiroo/fanfix/DataLoader.java | 12 ++++ .../nikiroo/fanfix/library/BasicLibrary.java | 1 + .../nikiroo/fanfix/library/CacheLibrary.java | 28 +++++---- .../nikiroo/fanfix/library/LocalLibrary.java | 27 +++++++-- .../nikiroo/fanfix/library/RemoteLibrary.java | 33 +++++++---- .../fanfix/library/RemoteLibraryServer.java | 56 ++++++++++++------ .../nikiroo/fanfix/reader/GuiReaderBook.java | 52 +++++++++++----- .../nikiroo/fanfix/reader/GuiReaderFrame.java | 4 ++ 10 files changed, 158 insertions(+), 60 deletions(-) rename libs/{nikiroo-utils-2.2.1-sources.jar => nikiroo-utils-2.2.2-sources.jar} (98%) diff --git a/changelog.md b/changelog.md index 3f5efc29..0154d4e8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Fanfix +# Version WIP + +- Bug fixes +- Remote server/client improvements + ## Version 1.6.2 - Better progress bars diff --git a/libs/nikiroo-utils-2.2.1-sources.jar b/libs/nikiroo-utils-2.2.2-sources.jar similarity index 98% rename from libs/nikiroo-utils-2.2.1-sources.jar rename to libs/nikiroo-utils-2.2.2-sources.jar index 199beb397df2393d81a4d924bcff803426fab7e3..318670fd7d1ef25318a10d5eeddfb1fcc7914f23 100644 GIT binary patch delta 2680 zcmYM0c{tRI7skhYnUQVmd-f^IwTu{JD{&>mwM>>KTgc9E$4=vG4V9&+AxpAdTT=Gy zB$Ta)EJMY$MfRBy@vEo%JimX=IiL4^&-wd2+C#8!#7M-^zWnQF3-g zrv`7u>2}rWg*`_B?zfS$Ml~l2pDZQ33Rx7dSTeBIz^~xnNU0nhBUZ-F$KfTb_3ET^ zhu||cu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k^EvXrk+u3w`qaRv-lJt- zjpfRt5rlW<$MK=1O<2pB?_D-`ioZ3FtNRU`6{g=UJ!N6`y!9gIBVYVbQ_&cY6OtGa zGq|cY3nu~e>Fh+;6JXJzZeC`&6l|d>&JL9M&L46V_=#XOByNy}OlMcp{8s|F%0wdg)9| zd4fB8TLfDIE_7!)vtjQ2epzT!)*RNn^eL*Imk}s@`QEcdt<7s>O%v3JI8FO{JxG^6 zy|uI9RJXd1^Ka2G`?a|fJZN+JMw@>vul7anC&E#$+bCy8$MWLFWnJ!ujtW%?Sw8ek zpR@5x7$_wJ9iC~^Z0*t^TGm4&@^|XugYy}37Rel5exu?UHLJQ!P1`jrL|cEi4Ck-6 zeX>k>AA_mUQ-yLE17C>S_1r?;1Mp#IdGiRT$&iOLkKE9$diUB0s*nEIP!1|H0(K4Y zfjp>lcNO^59ZWFP8&L|{YM*IO`b>^fX6XLR-c3`CsF+siT1CI@jf}Aa8%At@yBxia z*A)AbM2A{!Z~jzRHhDPn^_Ak~I~`MdmGNn$7-g5zJ3Z!f+1Z&vle!_5H=uncVwsz0 z{%t%kmFPew5A9OB zw29TwgePx*Z-~~=tJ`@B89O&jUfBj>0`9hAi@o%3FAz$MK^_C|N&$Mcj15$-=j&;QBMG{6zY6$Ghn0DREhAV3si-2mj6F_6jzU getMetas(Progress pg) { // TODO: progress final List metas = new ArrayList(); - MetaData[] fromNetwork = this - . getRemoteObject("GET_METADATA *"); + MetaData[] fromNetwork = this. getRemoteObject( // + new Object[] { "GET_METADATA", "*" }); if (fromNetwork != null) { for (MetaData meta : fromNetwork) { @@ -60,12 +60,19 @@ public class RemoteLibrary extends BasicLibrary { @Override public BufferedImage getCover(final String luid) { - return this. getRemoteObject("GET_COVER " + luid); + return this. getRemoteObject( // + new Object[] { "GET_COVER", luid }); + } + + @Override + public BufferedImage getSourceCover(final String source) { + return this. getRemoteObject( // + new Object[] { "GET_SOURCE_COVER", source }); } @Override public synchronized Story getStory(final String luid, Progress pg) { - return this. getRemoteObject("GET_STORY " + luid); + return this. getRemoteObject(new Object[] { "GET_STORY", luid }); } @Override @@ -75,20 +82,24 @@ public class RemoteLibrary extends BasicLibrary { @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"); + getRemoteObject(new Object[] { "SAVE_STORY", story, luid }); + + // because the meta changed: + clearCache(); + story.setMeta(getInfo(luid)); + + return story; } @Override public synchronized void delete(String luid) throws IOException { - throw new java.lang.InternalError( - "No write support allowed on remote Libraries"); + getRemoteObject(new Object[] { "DELETE_STORY", luid }); } @Override public void setSourceCover(String source, String luid) { - throw new java.lang.InternalError( - "No write support allowed on remote Libraries"); + this. getRemoteObject( // + new Object[] { "SET_SOURCE_COVER", source, luid }); } @Override @@ -125,7 +136,7 @@ public class RemoteLibrary extends BasicLibrary { * @return the object or NULL */ @SuppressWarnings("unchecked") - private T getRemoteObject(final String command) { + private T getRemoteObject(final Object[] command) { final Object[] result = new Object[1]; try { new ConnectActionClient(host, port, true) { diff --git a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java index 221fbdfc..8c836ed0 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java @@ -1,10 +1,12 @@ package be.nikiroo.fanfix.library; import java.io.IOException; +import java.security.InvalidParameterException; 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.Version; import be.nikiroo.utils.serial.ConnectActionServer; import be.nikiroo.utils.serial.Server; @@ -12,11 +14,19 @@ import be.nikiroo.utils.serial.Server; /** * Create a new remote server that will listen for order on the given port. *

- * The available commands are: + * The available commands are given as String arrays (first item is the command, + * the rest are the arguments): *

    - *
  • GET_METADATA *: will get the metadata of all the stories in the library
  • + *
  • GET_METADATA *: will return the metadata of all the stories in the + * library
  • *
  • GET_STORY [luid]: will return the given story if it exists (or NULL if * not)
  • + *
  • SAVE_STORY [story] [luid]: save the story with the given LUID
  • + *
  • DELETE_STORY [luid]: delete the story of LUID luid
  • + *
  • GET_COVER [luid]: return the cover of the story
  • + *
  • GET_SOURCE_COVER [source]: return the cover for this source
  • + *
  • SET_SOURCE_COVER [source], [luid]: set the default cover for the given + * source to the cover of the story denoted by luid
  • *
* * @author niki @@ -40,35 +50,43 @@ public class RemoteLibraryServer extends Server { @Override protected Object onRequest(ConnectActionServer action, Version clientVersion, Object data) throws Exception { - String command = null; - String args = null; - if (data instanceof String) { - command = (String) data; - int pos = command.indexOf(" "); - if (pos >= 0) { - args = command.substring(pos + 1); - command = command.substring(0, pos); + + String command = ""; + Object[] args = new Object[0]; + if (data instanceof Object[]) { + args = (Object[]) data; + if (args.length > 0) { + command = "" + args[0]; } } - System.out.println(String.format("COMMAND: [%s], ARGS: [%s]", command, - args)); + System.out.print("COMMAND: "); + for (Object arg : args) { + System.out.print(arg + " "); + } + System.out.println(""); // TODO: progress (+send name + %age info back to client) if ("GET_METADATA".equals(command)) { - if (args != null && args.equals("*")) { + if (args[1].equals("*")) { List metas = Instance.getLibrary().getMetas(null); return metas.toArray(new MetaData[] {}); } + throw new InvalidParameterException( + "only * is valid here, but you passed: " + args[1]); } else if ("GET_STORY".equals(command)) { - if (args != null) { - return Instance.getLibrary().getStory(args, null); - } + return Instance.getLibrary().getStory("" + args[1], null); + } else if ("SAVE_STORY".equals(command)) { + Instance.getLibrary().save((Story) args[1], "" + args[2], null); + } else if ("DELETE_STORY".equals(command)) { + Instance.getLibrary().delete("" + args[1]); } else if ("GET_COVER".equals(command)) { - if (args != null) { - return Instance.getLibrary().getCover(args); - } + return Instance.getLibrary().getCover("" + args[1]); + } else if ("GET_SOURCE_COVER".equals(command)) { + return Instance.getLibrary().getSourceCover("" + args[1]); + } else if ("SET_SOURCE_COVER".equals(command)) { + Instance.getLibrary().setSourceCover("" + args[1], "" + args[2]); } return null; diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java index 2ae04b46..bf2b5ed9 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java +++ b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java @@ -140,7 +140,7 @@ class GuiReaderBook extends JPanel { optSecondary = ""; } - icon = new JLabel(generateCoverIcon(meta)); + icon = new JLabel(generateCoverIcon()); title = new JLabel( String.format( "" @@ -371,24 +371,12 @@ class GuiReaderBook extends JPanel { /** * Generate a cover icon based upon the given {@link MetaData}. * - * @param meta - * the {@link MetaData} about the target {@link Story} or source - * (if no LUID) - * * @return the icon */ - private ImageIcon generateCoverIcon(MetaData meta) { + private ImageIcon generateCoverIcon() { BufferedImage resizedImage = null; - String id = null; - - String key = meta.getUuid(); - if (key == null) { - // a fake meta (a source) - key = "source_" + meta.getSource(); - } + String id = getIconId(meta); - id = key + ".thumb_" + SPINE_WIDTH + "x" + COVER_WIDTH + "+" - + SPINE_HEIGHT + "+" + COVER_HEIGHT + "@" + HOFFSET; InputStream in = Instance.getCache().getFromCache(id); if (in != null) { try { @@ -444,4 +432,38 @@ class GuiReaderBook extends JPanel { return new ImageIcon(resizedImage); } + + /** + * Manually clear the icon set for this item. + * + * @param meta + * the meta of the story or source (if luid is null) + */ + public static void clearIcon(MetaData meta) { + String id = getIconId(meta); + Instance.getCache().removeFromCache(id); + } + + /** + * Get a unique ID from this meta (note that if the luid is null, it is + * considered a source and not a {@link Story}). + * + * @param meta + * the meta + * @return the unique ID + */ + private static String getIconId(MetaData meta) { + String id = null; + + String key = meta.getUuid(); + if (meta.getLuid() == null) { + // a fake meta (== a source) + key = "source_" + meta.getSource(); + } + + id = key + ".thumb_" + SPINE_WIDTH + "x" + COVER_WIDTH + "+" + + SPINE_HEIGHT + "+" + COVER_HEIGHT + "@" + HOFFSET; + + return id; + } } diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java index 39db588b..1b4cb66e 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java @@ -608,6 +608,7 @@ class GuiReaderFrame extends JFrame { reader.clearLocalReaderCache(selectedBook.getMeta() .getLuid()); selectedBook.setCached(false); + GuiReaderBook.clearIcon(selectedBook.getMeta()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -785,6 +786,9 @@ class GuiReaderFrame extends JFrame { reader.getLibrary().setSourceCover( selectedBook.getMeta().getSource(), selectedBook.getMeta().getLuid()); + MetaData source = selectedBook.getMeta().clone(); + source.setLuid(null); + GuiReaderBook.clearIcon(source); } } }); -- 2.27.0