From: Niki Roo Date: Mon, 15 Apr 2019 16:46:12 +0000 (+0200) Subject: Merge branch 'master' of github.com:nikiroo/fanfix X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=71e4b26c25cfa0bcabe69d11a7de8a142be3ddf8;hp=48dfdfae65132782413f63b6c1b9df793dc56d11;p=fanfix.git Merge branch 'master' of github.com:nikiroo/fanfix --- diff --git a/TODO.md b/TODO.md index 434dc5c..f9f7692 100644 --- a/TODO.md +++ b/TODO.md @@ -9,6 +9,7 @@ My current planning for Fanfix (but not everything appears on this list): - [x] [e-Hentai](https://e-hentai.org/) requested - [x] Find some FR comics/manga websites - [ ] Find more FR thingies +- [ ] Support videos (anime)? - [x] A GUI library - [x] Make one - [x] Make it run when no args passed diff --git a/src/be/nikiroo/fanfix/Main.java b/src/be/nikiroo/fanfix/Main.java index 876fe55..faf8820 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 bd13e5c..a0a8e80 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 3795cd8..33578be 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 { @@ -116,7 +125,7 @@ class CliReader extends BasicReader { displayStories(metas); } else { // ! 1-based index ! - if (item <= 0 | item > metas.size()) { + if (item <= 0 || item > metas.size()) { throw new IOException("Index out of bounds: " + item); } diff --git a/src/be/nikiroo/fanfix/reader/tui/TuiReader.java b/src/be/nikiroo/fanfix/reader/tui/TuiReader.java index 640d628..bef84ea 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 6b8ce2b..6f7ed3c 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 6c3a35e..62de6ce 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/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java index dd192fb..723ea09 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java @@ -192,7 +192,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { searchItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - reader.search(type, "", 1, 0, false); + reader.search(type, null, 1, 0, false); } }); search.add(searchItem); diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java index cd98fac..3e86fba 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java @@ -33,6 +33,7 @@ public class GuiReaderGroup extends JPanel { private List infos; private List books; private JPanel pane; + private JLabel titleLabel; private boolean words; // words or authors (secondary info on books) private int itemsPerLine; @@ -43,7 +44,8 @@ public class GuiReaderGroup extends JPanel { * the {@link GuiReaderBook} used to probe some information about * the stories * @param title - * the title of this group + * the title of this group (can be NULL for "no title", an empty + * {@link String} will trigger a default title for empty groups) * @param backgroundColor * the background colour to use (or NULL for default) */ @@ -68,18 +70,10 @@ public class GuiReaderGroup extends JPanel { add(pane, BorderLayout.CENTER); - if (title != null) { - if (title.isEmpty()) { - title = GuiReader.trans(StringIdGui.MENU_AUTHORS_UNKNOWN); - } - - JLabel label = new JLabel(); - label.setText(String.format("" - + "
" - + "%s" + "" + "", title)); - label.setHorizontalAlignment(JLabel.CENTER); - add(label, BorderLayout.NORTH); - } + titleLabel = new JLabel(); + titleLabel.setHorizontalAlignment(JLabel.CENTER); + add(titleLabel, BorderLayout.NORTH); + setTitle(title); // Compute the number of items per line at each resize addComponentListener(new ComponentAdapter() { @@ -119,6 +113,28 @@ public class GuiReaderGroup extends JPanel { }); } + /** + * The title of this group (can be NULL for "no title", an empty + * {@link String} will trigger a default title for empty groups) + * + * @param title + * the title or NULL + */ + public void setTitle(String title) { + if (title != null) { + if (title.isEmpty()) { + title = GuiReader.trans(StringIdGui.MENU_AUTHORS_UNKNOWN); + } + + titleLabel.setText(String.format("" + + "
" + + "%s" + "" + "", title)); + titleLabel.setVisible(true); + } else { + titleLabel.setVisible(false); + } + } + /** * Compute how many items can fit in a line so UP and DOWN can be used to go * up/down one line at a time. @@ -172,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()); } @@ -242,12 +258,21 @@ public class GuiReaderGroup extends JPanel { repaint(); } + /** + * The number of books in this group. + * + * @return the count + */ + public int getBooksCount() { + return books.size(); + } + /** * Return the index of the currently selected book if any, -1 if none. * * @return the index or -1 */ - private int getSelectedBookIndex() { + public int getSelectedBookIndex() { int index = -1; for (int i = 0; i < books.size(); i++) { if (books.get(i).isSelected()) { @@ -269,7 +294,7 @@ public class GuiReaderGroup extends JPanel { * TRUE to constraint the index to the first/last element, FALSE * to unselect when outside the range */ - private void setSelectedBook(int index, boolean forceRange) { + public void setSelectedBook(int index, boolean forceRange) { int previousIndex = getSelectedBookIndex(); if (index >= books.size()) { diff --git a/src/be/nikiroo/fanfix/searchable/BasicSearchable.java b/src/be/nikiroo/fanfix/searchable/BasicSearchable.java index d8076fa..a67d2f6 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;