From b31a0db030e164bc1d9a8620e71b595dad31adb6 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Mon, 15 Apr 2019 18:45:15 +0200 Subject: [PATCH] search: cleanup --- src/be/nikiroo/fanfix/Main.java | 31 +++++----- src/be/nikiroo/fanfix/reader/Reader.java | 12 ++++ .../nikiroo/fanfix/reader/cli/CliReader.java | 9 +++ .../nikiroo/fanfix/reader/tui/TuiReader.java | 8 +++ .../reader/tui/TuiReaderApplication.java | 5 ++ .../nikiroo/fanfix/reader/ui/GuiReader.java | 15 ++++- .../fanfix/reader/ui/GuiReaderGroup.java | 2 +- .../fanfix/searchable/BasicSearchable.java | 61 ++++++++++--------- 8 files changed, 95 insertions(+), 48 deletions(-) diff --git a/src/be/nikiroo/fanfix/Main.java b/src/be/nikiroo/fanfix/Main.java index 876fe55c..faf88200 100644 --- a/src/be/nikiroo/fanfix/Main.java +++ b/src/be/nikiroo/fanfix/Main.java @@ -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; diff --git a/src/be/nikiroo/fanfix/reader/Reader.java b/src/be/nikiroo/fanfix/reader/Reader.java index bd13e5cb..a0a8e806 100644 --- a/src/be/nikiroo/fanfix/reader/Reader.java +++ b/src/be/nikiroo/fanfix/reader/Reader.java @@ -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. * diff --git a/src/be/nikiroo/fanfix/reader/cli/CliReader.java b/src/be/nikiroo/fanfix/reader/cli/CliReader.java index a9dcfeeb..33578be6 100644 --- a/src/be/nikiroo/fanfix/reader/cli/CliReader.java +++ b/src/be/nikiroo/fanfix/reader/cli/CliReader.java @@ -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 { diff --git a/src/be/nikiroo/fanfix/reader/tui/TuiReader.java b/src/be/nikiroo/fanfix/reader/tui/TuiReader.java index 640d628b..bef84eae 100644 --- a/src/be/nikiroo/fanfix/reader/tui/TuiReader.java +++ b/src/be/nikiroo/fanfix/reader/tui/TuiReader.java @@ -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) { diff --git a/src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java b/src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java index 6b8ce2b0..6f7ed3cb 100644 --- a/src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java +++ b/src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java @@ -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 { diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReader.java b/src/be/nikiroo/fanfix/reader/ui/GuiReader.java index 6c3a35e5..62de6cee 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReader.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReader.java @@ -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) { diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java index 2d466294..3e86fba9 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java @@ -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()); } diff --git a/src/be/nikiroo/fanfix/searchable/BasicSearchable.java b/src/be/nikiroo/fanfix/searchable/BasicSearchable.java index d8076fa7..a67d2f60 100644 --- a/src/be/nikiroo/fanfix/searchable/BasicSearchable.java +++ b/src/be/nikiroo/fanfix/searchable/BasicSearchable.java @@ -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; -- 2.27.0