search: cleanup
authorNiki Roo <niki@nikiroo.be>
Mon, 15 Apr 2019 16:45:15 +0000 (18:45 +0200)
committerNiki Roo <niki@nikiroo.be>
Mon, 15 Apr 2019 16:45:15 +0000 (18:45 +0200)
src/be/nikiroo/fanfix/Main.java
src/be/nikiroo/fanfix/reader/Reader.java
src/be/nikiroo/fanfix/reader/cli/CliReader.java
src/be/nikiroo/fanfix/reader/tui/TuiReader.java
src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java
src/be/nikiroo/fanfix/reader/ui/GuiReader.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java
src/be/nikiroo/fanfix/searchable/BasicSearchable.java

index 876fe55c853d1a5359be41315b85c48e8ca1c201..faf882006fccfb0b1e9c8a3774c74802d6b8ee78 100644 (file)
@@ -222,13 +222,15 @@ public class Main {
                                        if (searchOn == null) {
                                                Instance.getTraceHandler().error(
                                                                "Website not known: <" + args[i] + ">");
-                                               exitCode = 255;
+                                               exitCode = 41;
+                                               break;
                                        }
 
                                        if (BasicSearchable.getSearchable(searchOn) == null) {
                                                Instance.getTraceHandler().error(
                                                                "Website not supported: " + searchOn);
-                                               exitCode = 255;
+                                               exitCode = 42;
+                                               break;
                                        }
                                } else if (search == null) {
                                        search = args[i];
@@ -399,7 +401,7 @@ public class Main {
                        }
                }
 
-               if (exitCode != 255) {
+               if (exitCode == 0) {
                        switch (action) {
                        case IMPORT:
                                exitCode = imprt(urlString, pg);
@@ -491,22 +493,19 @@ public class Main {
                                        break;
                                }
 
-                               if (searchOn == null) {
-                                       // TODO: do on reader!!!
-                                       for (SupportType type : SupportType.values()) {
-                                               if (BasicSearchable.getSearchable(type) != null) {
-                                                       System.out.println(type);
-                                               }
-                                       }
-                               } else if (search != null) {
-                                       try {
+                               try {
+                                       if (searchOn == null) {
+                                               BasicReader.getReader().search(true);
+                                       } else if (search != null) {
+
                                                BasicReader.getReader().search(searchOn, search, page,
                                                                item, true);
-                                       } catch (IOException e1) {
-                                               Instance.getTraceHandler().error(e1);
+                                       } else {
+                                               exitCode = 255;
                                        }
-                               } else {
-                                       exitCode = 255;
+                               } catch (IOException e1) {
+                                       Instance.getTraceHandler().error(e1);
+                                       exitCode = 20;
                                }
 
                                break;
index bd13e5cb8c032e6866b72c30693d625eae0815e1..a0a8e806656711ca098664bdec7c9a77bda6f9fb 100644 (file)
@@ -170,6 +170,18 @@ public interface Reader {
         */
        public void browse(String source);
 
+       /**
+        * Display all supports that allow search operations.
+        * 
+        * @param sync
+        *            execute the process synchronously (wait until it is terminated
+        *            before returning)
+        * 
+        * @throws IOException
+        *             in case of I/O error
+        */
+       public void search(boolean sync) throws IOException;
+
        /**
         * Search for the given terms and find stories that correspond if possible.
         * 
index a9dcfeeb5b51b3578369f04fe588973524b833c0..33578be668818e9974d26db122e29cbe1904cafe 100644 (file)
@@ -100,6 +100,15 @@ class CliReader extends BasicReader {
                }
        }
 
+       @Override
+       public void search(boolean sync) throws IOException {
+               for (SupportType type : SupportType.values()) {
+                       if (BasicSearchable.getSearchable(type) != null) {
+                               System.out.println(type);
+                       }
+               }
+       }
+
        @Override
        public void search(SupportType searchOn, String keywords, int page,
                        int item, boolean sync) throws IOException {
index 640d628b3e32305a36089f6cfa25ed236dc7d83a..bef84eae46c92ae9f41ea14f0c69f75d99e5927d 100644 (file)
@@ -72,6 +72,14 @@ class TuiReader extends BasicReader {
                }
        }
 
+       @Override
+       public void search(boolean sync) throws IOException {
+               // TODO
+               if (sync) {
+                       throw new java.lang.IllegalStateException("Not implemented yet.");
+               }
+       }
+
        @Override
        public void search(SupportType searchOn, String keywords, int page,
                        int item, boolean sync) {
index 6b8ce2b077b88eddfbb6c513343bfabad98508d7..6f7ed3cbddc61f003d286ce231c0b4d0daeb41d0 100644 (file)
@@ -126,6 +126,11 @@ class TuiReaderApplication extends TApplication implements Reader {
                reader.setChapter(chapter);
        }
 
+       @Override
+       public void search(boolean sync) throws IOException {
+               reader.search(sync);
+       }
+
        @Override
        public void search(SupportType searchOn, String keywords, int page,
                        int item, boolean sync) throws IOException {
index 6c3a35e5198827c603393f4c5c77d5bea9f3b6d9..62de6ceebde36142656697ac5bdb7bc720927f25 100644 (file)
@@ -220,14 +220,25 @@ class GuiReader extends BasicReader {
        }
 
        @Override
-       public void search(SupportType searchOn, String keywords, int page,
-                       int item, boolean sync) {
+       public void search(boolean sync) throws IOException {
                // TODO
                if (sync) {
                        throw new java.lang.IllegalStateException("Not implemented yet.");
                }
        }
 
+       @Override
+       public void search(SupportType searchOn, String keywords, int page,
+                       int item, boolean sync) {
+               // TODO: add parameters!
+               GuiReaderSearch search = new GuiReaderSearch(this);
+               if (sync) {
+                       sync(search);
+               } else {
+                       search.setVisible(true);
+               }
+       }
+
        @Override
        public void searchTag(SupportType searchOn, int page, int item,
                        boolean sync, Integer... tags) {
index 2d466294a1483781d3a64148bc4aa5955c3d568d..3e86fba9d0a7a3677a73323ea9d44c4e35a86629 100644 (file)
@@ -188,7 +188,7 @@ public class GuiReaderGroup extends JPanel {
                if (infos != null) {
                        for (GuiReaderBookInfo info : infos) {
                                boolean isCached = false;
-                               if (info.getMeta() != null) {
+                               if (info.getMeta() != null && info.getMeta().getLuid() != null) {
                                        isCached = reader.isCached(info.getMeta().getLuid());
                                }
 
index d8076fa7a1b87f99e452cddcef30100305884c7b..a67d2f6022e47088824d7f61cbaaa341b6ce8a0c 100644 (file)
@@ -217,41 +217,44 @@ public abstract class BasicSearchable {
         * type, or NULL if it does not exist.
         * 
         * @param type
-        *            the type, must not be NULL
+        *            the type, can be NULL (will just return NULL, since we do not
+        *            support it)
         * 
         * @return an implementation that supports it, or NULL
         */
        static public BasicSearchable getSearchable(SupportType type) {
                BasicSearchable support = null;
 
-               switch (type) {
-               case FIMFICTION:
-                       // TODO
-                       break;
-               case FANFICTION:
-                       support = new Fanfiction(type);
-                       break;
-               case MANGAFOX:
-                       // TODO
-                       break;
-               case E621:
-                       // TODO
-                       break;
-               case YIFFSTAR:
-                       // TODO
-                       break;
-               case E_HENTAI:
-                       // TODO
-                       break;
-               case MANGA_LEL:
-                       support = new MangaLel();
-                       break;
-               case CBZ:
-               case HTML:
-               case INFO_TEXT:
-               case TEXT:
-               case EPUB:
-                       break;
+               if (type != null) {
+                       switch (type) {
+                       case FIMFICTION:
+                               // TODO
+                               break;
+                       case FANFICTION:
+                               support = new Fanfiction(type);
+                               break;
+                       case MANGAFOX:
+                               // TODO
+                               break;
+                       case E621:
+                               // TODO
+                               break;
+                       case YIFFSTAR:
+                               // TODO
+                               break;
+                       case E_HENTAI:
+                               // TODO
+                               break;
+                       case MANGA_LEL:
+                               support = new MangaLel();
+                               break;
+                       case CBZ:
+                       case HTML:
+                       case INFO_TEXT:
+                       case TEXT:
+                       case EPUB:
+                               break;
+                       }
                }
 
                return support;