remote/general: import should not retrieve story from server
authorNiki Roo <niki@nikiroo.be>
Thu, 19 Sep 2019 11:15:30 +0000 (13:15 +0200)
committerNiki Roo <niki@nikiroo.be>
Thu, 19 Sep 2019 11:15:30 +0000 (13:15 +0200)
src/be/nikiroo/fanfix/Main.java
src/be/nikiroo/fanfix/library/BasicLibrary.java
src/be/nikiroo/fanfix/library/CacheLibrary.java
src/be/nikiroo/fanfix/library/RemoteLibrary.java
src/be/nikiroo/fanfix/library/RemoteLibraryServer.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java

index b3633612713996f8651bffda5f480fc2607b54be..3d69cad31358f794d874b0645a9e124e36bf7caa 100644 (file)
@@ -12,6 +12,7 @@ import javax.net.ssl.SSLException;
 import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.bundles.StringId;
 import be.nikiroo.fanfix.data.Chapter;
+import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.library.BasicLibrary;
 import be.nikiroo.fanfix.library.CacheLibrary;
@@ -644,10 +645,10 @@ public class Main {
         */
        public static int imprt(String urlString, Progress pg) {
                try {
-                       Story story = Instance.getLibrary().imprt(
+                       MetaData meta = Instance.getLibrary().imprt(
                                        BasicReader.getUrl(urlString), pg);
-                       System.out.println(story.getMeta().getLuid() + ": \""
-                                       + story.getMeta().getTitle() + "\" imported.");
+                       System.out.println(meta.getLuid() + ": \"" + meta.getTitle()
+                                       + "\" imported.");
                } catch (IOException e) {
                        Instance.getTraceHandler().error(e);
                        return 1;
index 380c5c988ca43dad853f7e4edb25e657a55ed1ba..099859dcfaffed075f30b3d716b790f644a43a09 100644 (file)
@@ -751,14 +751,14 @@ abstract public class BasicLibrary {
         * @param pg
         *            the optional progress reporter
         * 
-        * @return the imported {@link Story}
+        * @return the imported Story {@link MetaData}
         * 
         * @throws UnknownHostException
         *             if the host is not supported
         * @throws IOException
         *             in case of I/O error
         */
-       public Story imprt(URL url, Progress pg) throws IOException {
+       public MetaData imprt(URL url, Progress pg) throws IOException {
                if (pg == null)
                        pg = new Progress();
 
@@ -776,7 +776,7 @@ abstract public class BasicLibrary {
                Story story = save(support.process(pgProcess), pgSave);
                pg.done();
 
-               return story;
+               return story.getMeta();
        }
 
        /**
index 019acd210d1fb3b2263db468e2c21e6e6bfd1d69..e128da525b6616befc61a5917119a3e70f1e2b26 100644 (file)
@@ -345,7 +345,7 @@ public class CacheLibrary extends BasicLibrary {
        }
 
        @Override
-       public Story imprt(URL url, Progress pg) throws IOException {
+       public MetaData imprt(URL url, Progress pg) throws IOException {
                if (pg == null) {
                        pg = new Progress();
                }
@@ -356,13 +356,13 @@ public class CacheLibrary extends BasicLibrary {
                pg.addProgress(pgImprt, 7);
                pg.addProgress(pgCache, 3);
 
-               Story story = lib.imprt(url, pgImprt);
-               cacheLib.save(story, story.getMeta().getLuid(), pgCache);
-
-               updateInfo(story.getMeta());
+               MetaData meta = lib.imprt(url, pgImprt);
+               updateInfo(meta);
+               
+               clearFromCache(meta.getLuid());
 
                pg.done();
-               return story;
+               return meta;
        }
 
        // All the following methods are only used by Save and Delete in
index a6c68546882c0cdd64bda6c7592976d228bdfb4d..ce4305aadad96bfe9446817d467234545ccfce7a 100644 (file)
@@ -78,7 +78,7 @@ public class RemoteLibrary extends BasicLibrary {
         * <li><b>wl</b>: flag to allow access to all the stories (bypassing the
         * whitelist if it exists)</li>
         * </ul>
-        * 
+        * <p>
         * Some examples:
         * <ul>
         * <li><b>my_key</b>: normal connection, will take the default server
@@ -352,8 +352,9 @@ public class RemoteLibrary extends BasicLibrary {
 
        @Override
        // Could work (more slowly) without it
-       public Story imprt(final URL url, Progress pg) throws IOException {
+       public MetaData imprt(final URL url, Progress pg) throws IOException {
                // Import the file locally if it is actually a file
+               
                if (url == null || url.getProtocol().equalsIgnoreCase("file")) {
                        return super.imprt(url, pg);
                }
@@ -364,13 +365,7 @@ public class RemoteLibrary extends BasicLibrary {
                        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 Progress pgF = pg;
                final String[] luid = new String[1];
 
                connectRemoteAction(new RemoteAction() {
@@ -399,11 +394,8 @@ public class RemoteLibrary extends BasicLibrary {
                        throw new IOException("Remote failure");
                }
 
-               Story story = getStory(luid[0], pgGet);
-               pgGet.done();
-
                pg.done();
-               return story;
+               return getInfo(luid[0]);
        }
 
        @Override
index 43f61b096cbb6e8d452a47b13853a1a2fc15af7c..dc9688c4de69c0348a1ee7dbac4665ec581d905a 100644 (file)
@@ -289,10 +289,10 @@ public class RemoteLibraryServer extends ServerObject {
                        }
 
                        Progress pg = createPgForwarder(action);
-                       Story story = Instance.getLibrary().imprt(
+                       MetaData meta = Instance.getLibrary().imprt(
                                        new URL((String) args[0]), pg);
                        forcePgDoneSent(pg);
-                       return story.getMeta().getLuid();
+                       return meta.getLuid();
                } else if ("DELETE_STORY".equals(command)) {
                        if (!rw) {
                                throw new RemoteLibraryException("Read-Only remote library: "
index a28dc8a0d275bda522b46f2a96d860907ba40f37..fe11c810edf76b8e4a79d066460dfd123c8a71e9 100644 (file)
@@ -36,7 +36,7 @@ import be.nikiroo.fanfix.library.LocalLibrary;
 import be.nikiroo.fanfix.output.BasicOutput.OutputType;
 import be.nikiroo.fanfix.reader.BasicReader;
 import be.nikiroo.fanfix.reader.ui.GuiReaderMainPanel.FrameHelper;
-import be.nikiroo.fanfix.reader.ui.GuiReaderMainPanel.StoryRunnable;
+import be.nikiroo.fanfix.reader.ui.GuiReaderMainPanel.MetaDataRunnable;
 import be.nikiroo.fanfix.searchable.BasicSearchable;
 import be.nikiroo.fanfix.supported.SupportType;
 import be.nikiroo.utils.Progress;
@@ -756,10 +756,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                                final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
                                if (selectedBook != null) {
                                        final MetaData meta = selectedBook.getInfo().getMeta();
-                                       mainPanel.imprt(meta.getUrl(), new StoryRunnable() {
+                                       mainPanel.imprt(meta.getUrl(), new MetaDataRunnable() {
                                                @Override
-                                               public void run(Story story) {
-                                                       MetaData newMeta = story.getMeta();
+                                               public void run(MetaData newMeta) {
                                                        if (!newMeta.getSource().equals(meta.getSource())) {
                                                                reader.changeSource(newMeta.getLuid(),
                                                                                meta.getSource());
index 8593fe6471c816812220defeedf5775fe1757642..7caa243c411ca4bba0f4bf2c0dbbedd7368f8e07 100644 (file)
@@ -108,18 +108,18 @@ class GuiReaderMainPanel extends JPanel {
        }
 
        /**
-        * A {@link Runnable} with a {@link Story} parameter.
+        * A {@link Runnable} with a {@link MetaData} parameter.
         * 
         * @author niki
         */
-       public interface StoryRunnable {
+       public interface MetaDataRunnable {
                /**
                 * Run the action.
                 * 
-                * @param story
-                *            the story
+                * @param meta
+                *            the meta of the story
                 */
-               public void run(Story story);
+               public void run(MetaData meta);
        }
 
        /**
@@ -548,7 +548,7 @@ class GuiReaderMainPanel extends JPanel {
         * @param onSuccessPgName
         *            the name to use for the onSuccess progress bar
         */
-       public void imprt(final String url, final StoryRunnable onSuccess,
+       public void imprt(final String url, final MetaDataRunnable onSuccess,
                        String onSuccessPgName) {
                final Progress pg = new Progress();
                final Progress pgImprt = new Progress();
@@ -560,9 +560,9 @@ class GuiReaderMainPanel extends JPanel {
                        @Override
                        public void run() {
                                Exception ex = null;
-                               Story story = null;
+                               MetaData meta = null;
                                try {
-                                       story = helper.getReader().getLibrary()
+                                       meta = helper.getReader().getLibrary()
                                                        .imprt(BasicReader.getUrl(url), pgImprt);
                                } catch (IOException e) {
                                        ex = e;
@@ -586,7 +586,7 @@ class GuiReaderMainPanel extends JPanel {
                                        }
                                } else {
                                        if (onSuccess != null) {
-                                               onSuccess.run(story);
+                                               onSuccess.run(meta);
                                        }
                                }
                                pgOnSuccess.done();