Merge branch 'master' into search
authorNiki Roo <niki@nikiroo.be>
Sat, 13 Apr 2019 11:33:46 +0000 (13:33 +0200)
committerNiki Roo <niki@nikiroo.be>
Sat, 13 Apr 2019 11:33:46 +0000 (13:33 +0200)
14 files changed:
README-fr.md
README.md
src/be/nikiroo/fanfix/Main.java
src/be/nikiroo/fanfix/bundles/resources_core.properties
src/be/nikiroo/fanfix/bundles/resources_core_fr.properties
src/be/nikiroo/fanfix/reader/BasicReader.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/GuiReaderFrame.java
src/be/nikiroo/fanfix/searchable/BasicSearchable.java
src/be/nikiroo/fanfix/searchable/Fanfiction.java

index cb76040b15f8c20c58677486cb288407c1673811..1021769f48cbf0c8e3c16e9f82d4842b42472bf2 100644 (file)
@@ -10,6 +10,10 @@ Fanfix est un petit programme Java qui peut télécharger des histoires sur inte
 - ```fanfix``` --convert [*URL*] [*output_type*] [*target*] (+info)
 - ```fanfix``` --read [*id*] ([*chapter number*])
 - ```fanfix``` --read-url [*URL*] ([*chapter number*])
+- ```fanfix``` --search
+- ```fanfix``` --search [*where*] [*keywords*] (page [*page*]) (item [*item*])
+- ```fanfix``` --tag
+- ```fanfix``` --tag [*index 1*]... (page [*page*]) (item [*item*])
 - ```fanfix``` --list
 - ```fanfix``` --set-reader [*GUI* | *TUI* | *CLI*]
 - ```fanfix``` --server [*key*] [*port*]
@@ -85,6 +89,10 @@ Les arguments suivants sont aussi supportés :
 - ```--convert [URL] [output_type] [target] (+info)```: convertir l'histoire vers le fichier donné, et forcer l'ajout d'un fichier .info si +info est utilisé
 - ```--read [id] ([chapter number])```: afficher l'histoire "id"
 - ```--read-url [URL] ([chapter number])```: convertir l'histoire et la lire à la volée, sans la sauver
+- ```--search```: liste les sites supportés (```where```)
+- ```--search [where] [keywords] (page [page]) (item [item])```: lance une recherche et affiche les résultats de la page ```page``` (page 1 par défaut), et de l'item ```item``` spécifique si demandé
+- ```--tag [where]```: liste tous les tags supportés par ce site web
+- ```--tag [index 1]... (page [page]) (item [item])```: affine la recherche, tag par tag, et affiche si besoin les sous-tags, les histoires ou les infos précises de l'histoire demandée
 - ```--list```: lister les histoires presentes dans la librairie et leurs IDs
 - ```--set-reader [reader type]```: changer le type de lecteur pour la commande en cours sur CLI, TUI ou GUI
 - ```--server [key] [port]```: démarrer un serveur d'histoires sur ce port
index 22e0b60f40342ab5f2b472c4df324ad6a550aa20..bc003c73634e203d234cf8c5aba4e6daf7699c6b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -10,6 +10,10 @@ Fanfix is a small Java program that can download stories from some supported web
 - ```fanfix``` --convert [*URL*] [*output_type*] [*target*] (+info)
 - ```fanfix``` --read [*id*] ([*chapter number*])
 - ```fanfix``` --read-url [*URL*] ([*chapter number*])
+- ```fanfix``` --search
+- ```fanfix``` --search [*where*] [*keywords*] (page [*page*]) (item [*item*])
+- ```fanfix``` --tag
+- ```fanfix``` --tag [*index 1*]... (page [*page*]) (item [*item*])
 - ```fanfix``` --list
 - ```fanfix``` --set-reader [*GUI* | *TUI* | *CLI*]
 - ```fanfix``` --server [*key*] [*port*]
@@ -85,6 +89,10 @@ The following arguments are also allowed:
 - ```--convert [URL] [output_type] [target] (+info)```: convert the story at URL into target, and force-add the .info and cover if +info is passed
 - ```--read [id] ([chapter number])```: read the given story denoted by ID from the library
 - ```--read-url [URL] ([chapter number])```: convert on the fly and read the story at URL, without saving it
+- ```--search```: list the supported websites (```where```)
+- ```--search [where] [keywords] (page [page]) (item [item])```: search on the supported website and display the given results page of stories it found, or the story details if asked
+- ```--tag [where]```: list all the tags supported by this website
+- ```--tag [index 1]... (page [page]) (item [item])```: search for the given stories or subtags, tag by tag, and display information about a specific page of results or about a specific item if requested
 - ```--list```: list the stories present in the library and their associated IDs
 - ```--set-reader [reader type]```: set the reader type to CLI, TUI or GUI for this command
 - ```--server [key] [port]```: start a story server on this port
index 953bc45a50b776a99b533fab67bbd9dc5dafa7d9..6fc49c549764cbba0a7439086c49e79e981af3ad 100644 (file)
@@ -4,6 +4,7 @@ import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.List;
 
 import be.nikiroo.fanfix.bundles.StringId;
@@ -20,6 +21,7 @@ import be.nikiroo.fanfix.output.BasicOutput.OutputType;
 import be.nikiroo.fanfix.reader.BasicReader;
 import be.nikiroo.fanfix.reader.Reader;
 import be.nikiroo.fanfix.reader.Reader.ReaderType;
+import be.nikiroo.fanfix.searchable.BasicSearchable;
 import be.nikiroo.fanfix.supported.BasicSupport;
 import be.nikiroo.fanfix.supported.SupportType;
 import be.nikiroo.utils.Progress;
@@ -33,7 +35,7 @@ import be.nikiroo.utils.serial.server.ServerObject;
  */
 public class Main {
        private enum MainAction {
-               IMPORT, EXPORT, CONVERT, READ, READ_URL, LIST, HELP, SET_READER, START, VERSION, SERVER, STOP_SERVER, REMOTE, SET_SOURCE, SET_TITLE, SET_AUTHOR
+               IMPORT, EXPORT, CONVERT, READ, READ_URL, LIST, HELP, SET_READER, START, VERSION, SERVER, STOP_SERVER, REMOTE, SET_SOURCE, SET_TITLE, SET_AUTHOR, SEARCH, TAG
        }
 
        /**
@@ -59,6 +61,14 @@ public class Main {
         * </li>
         * <li>--read-url [URL] ([chapter number]): convert on the fly and read the
         * story, without saving it</li>
+        * <li>--search: list the supported websites (where)</li>
+        * <li>--search [where] [keywords] (page [page]) (item [item]): search on
+        * the supported website and display the given results page of stories it
+        * found, or the story details if asked</li>
+        * <li>--tag [where]: list all the tags supported by this website</li>
+        * <li>--tag [index 1]... (page [page]) (item [item]): search for the given
+        * stories or subtags, tag by tag, and display information about a specific
+        * page of results or about a specific item if requested</li>
         * <li>--list ([type]): list the stories present in the library</li>
         * <li>--set-source [id] [new source]: change the source of the given story</li>
         * <li>--set-title [id] [new title]: change the title of the given story</li>
@@ -88,6 +98,11 @@ public class Main {
                Boolean plusInfo = null;
                String host = null;
                Integer port = null;
+               SupportType searchOn = null;
+               String search = null;
+               List<Integer> tags = new ArrayList<Integer>();
+               Integer page = null;
+               Integer item = null;
 
                boolean noMoreActions = false;
 
@@ -200,6 +215,101 @@ public class Main {
                                        exitCode = 255;
                                }
                                break;
+                       case SEARCH:
+                               if (searchOn == null) {
+                                       searchOn = SupportType.valueOfAllOkUC(args[i]);
+
+                                       if (searchOn == null) {
+                                               Instance.getTraceHandler().error(
+                                                               "Website not known: <" + args[i] + ">");
+                                               exitCode = 255;
+                                       }
+
+                                       if (BasicSearchable.getSearchable(searchOn) == null) {
+                                               Instance.getTraceHandler().error(
+                                                               "Website not supported: " + searchOn);
+                                               exitCode = 255;
+                                       }
+                               } else if (search == null) {
+                                       search = args[i];
+                               } else if (page != null && page == -1) {
+                                       try {
+                                               page = Integer.parseInt(args[i]);
+                                       } catch (Exception e) {
+                                               page = -2;
+                                       }
+                               } else if (item != null && item == -1) {
+                                       try {
+                                               item = Integer.parseInt(args[i]);
+                                       } catch (Exception e) {
+                                               item = -2;
+                                       }
+                               } else if (page == null || item == null) {
+                                       if (page == null && "page".equals(args[i])) {
+                                               page = -1;
+                                       } else if (item == null && "item".equals(args[i])) {
+                                               item = -1;
+                                       } else {
+                                               exitCode = 255;
+                                       }
+                               } else {
+                                       exitCode = 255;
+                               }
+                               break;
+                       case TAG:
+                               if (searchOn == null) {
+                                       searchOn = SupportType.valueOfAllOkUC(args[i]);
+
+                                       if (searchOn == null) {
+                                               Instance.getTraceHandler().error(
+                                                               "Website not known: <" + args[i] + ">");
+                                               exitCode = 255;
+                                       }
+
+                                       if (BasicSearchable.getSearchable(searchOn) == null) {
+                                               Instance.getTraceHandler().error(
+                                                               "Website not supported: " + searchOn);
+                                               exitCode = 255;
+                                       }
+                               } else if (page == null && item == null) {
+                                       if ("page".equals(args[i])) {
+                                               page = -1;
+                                       } else if ("item".equals(args[i])) {
+                                               item = -1;
+                                       } else {
+                                               try {
+                                                       int index = Integer.parseInt(args[i]);
+                                                       tags.add(index);
+                                               } catch (NumberFormatException e) {
+                                                       Instance.getTraceHandler().error(
+                                                                       "Invalid tag index: " + args[i]);
+                                                       exitCode = 255;
+                                               }
+                                       }
+                               } else if (page != null && page == -1) {
+                                       try {
+                                               page = Integer.parseInt(args[i]);
+                                       } catch (Exception e) {
+                                               page = -2;
+                                       }
+                               } else if (item != null && item == -1) {
+                                       try {
+                                               item = Integer.parseInt(args[i]);
+                                       } catch (Exception e) {
+                                               item = -2;
+                                       }
+                               } else if (page == null || item == null) {
+                                       if (page == null && "page".equals(args[i])) {
+                                               page = -1;
+                                       } else if (item == null && "item".equals(args[i])) {
+                                               item = -1;
+                                       } else {
+                                               exitCode = 255;
+                                       }
+                               } else {
+                                       exitCode = 255;
+                               }
+                               break;
                        case HELP:
                                exitCode = 255;
                                break;
@@ -282,8 +392,8 @@ public class Main {
                                System.err.println("\tVersion " + v);
                                System.err.println("\t-------------");
                                System.err.println("");
-                               for (String item : updates.getChanges().get(v)) {
-                                       System.err.println("\t- " + item);
+                               for (String it : updates.getChanges().get(v)) {
+                                       System.err.println("\t- " + it);
                                }
                                System.err.println("");
                        }
@@ -357,6 +467,82 @@ public class Main {
                                        break;
                                }
                                exitCode = read(urlString, chapString, false);
+                               break;
+                       case SEARCH:
+                               page = page == null ? 1 : page;
+                               if (page < 0) {
+                                       Instance.getTraceHandler().error("Incorrect page number");
+                                       exitCode = 255;
+                                       break;
+                               }
+
+                               item = item == null ? 0 : item;
+                               if (item < 0) {
+                                       Instance.getTraceHandler().error("Incorrect item number");
+                                       exitCode = 255;
+                                       break;
+                               }
+
+                               if (BasicReader.getReader() == null) {
+                                       Instance.getTraceHandler()
+                                                       .error(new Exception(
+                                                                       "No reader type has been configured"));
+                                       exitCode = 10;
+                                       break;
+                               }
+
+                               if (searchOn == null || search == null) {
+                                       // TODO: do on reader!!!
+                                       for (SupportType type : SupportType.values()) {
+                                               if (BasicSearchable.getSearchable(type) != null) {
+                                                       System.out.println(type);
+                                               }
+                                       }
+                               } else {
+                                       try {
+                                               BasicReader.getReader().search(searchOn, search, page,
+                                                               item);
+                                       } catch (IOException e1) {
+                                               Instance.getTraceHandler().error(e1);
+                                       }
+                               }
+
+                               break;
+                       case TAG:
+                               if (searchOn == null) {
+                                       exitCode = 255;
+                                       break;
+                               }
+
+                               page = page == null ? 1 : page;
+                               if (page < 0) {
+                                       Instance.getTraceHandler().error("Incorrect page number");
+                                       exitCode = 255;
+                                       break;
+                               }
+
+                               item = item == null ? 0 : item;
+                               if (item < 0) {
+                                       Instance.getTraceHandler().error("Incorrect item number");
+                                       exitCode = 255;
+                                       break;
+                               }
+
+                               if (BasicReader.getReader() == null) {
+                                       Instance.getTraceHandler()
+                                                       .error(new Exception(
+                                                                       "No reader type has been configured"));
+                                       exitCode = 10;
+                                       break;
+                               }
+
+                               try {
+                                       BasicReader.getReader().searchTag(searchOn, page, item,
+                                                       tags.toArray(new Integer[] {}));
+                               } catch (IOException e1) {
+                                       Instance.getTraceHandler().error(e1);
+                               }
+
                                break;
                        case HELP:
                                syntax(true);
index 62fd158ecddf0288ddc1b7e684b0aa420e4665ce..e244122258e1dc656404e29c35a48603d09c648b 100644 (file)
@@ -16,6 +16,18 @@ HELP_SYNTAX = Valid options:\n\
 \t--read [id] ([chapter number]): read the given story from the library\n\
 \t--read-url [URL] ([chapter number]): convert on the fly and read the \n\
 \t\tstory, without saving it\n\
+\t--search WEBSITE [free text] ([page] ([item])): search for the given terms, show the\n\
+\t\tgiven page (page 0 means "how many page do we have", starts at page 1)\n\
+\t--search-tag WEBSITE ([tag 1] [tag2...] ([page] ([item]))): list the known tags or \n\
+\t\tsearch the stories for the given tag(s), show the given page of results\n\
+\t--search: list the supported websites (where)\n\
+\t--search [where] [keywords] (page [page]) (item [item]): search on the supported \n\
+\t\twebsite and display the given results page of stories it found, or the story \n\
+\t\tdetails if asked\n\
+\t--tag [where]: list all the tags supported by this website\n\
+\t--tag [index 1]... (page [page]) (item [item]): search for the given stories or \n\
+\t\tsubtags, tag by tag, and display information about a specific page of results or \n\
+\t\tabout a specific item if requested\n\
 \t--list ([type]) : list the stories present in the library\n\
 \t--set-source [id] [new source]: change the source of the given story\n\
 \t--set-title [id] [new title]: change the title of the given story\n\
index 092bd336248e211b2c4d573b0136597355c5a026..71c0411b26b7b62e7c571839eb71b20a17703d31 100644 (file)
@@ -15,6 +15,14 @@ HELP_SYNTAX = Options reconnues :\n\
 \t--convert [URL] [output_type] [target] (+info): convertir l'histoire vers le fichier donné, et forcer l'ajout d'un fichier .info si +info est utilisé\n\
 \t--read [id] ([chapter number]): afficher l'histoire "id"\n\
 \t--read-url [URL] ([chapter number]): convertir l'histoire et la lire à la volée, sans la sauver\n\
+\t--search: liste les sites supportés (where)\n\
+\t--search [where] [keywords] (page [page]) (item [item]): lance une recherche et \n\
+\t\taffiche les résultats de la page page (page 1 par défaut), et de l'item item \n\
+\t\tspécifique si demandé\n\
+\t--tag [where]: liste tous les tags supportés par ce site web\n\
+\t--tag [index 1]... (page [page]) (item [item]): affine la recherche, tag par tag,\n\
+\t\tet affiche si besoin les sous-tags, les histoires ou les infos précises de \n\
+\t\tl'histoire demandée\n\
 \t--list ([type]): lister les histoires presentes dans la librairie et leurs IDs\n\
 \t--set-source [id] [nouvelle source]: change la source de l'histoire\n\
 \t--set-title [id] [nouveau titre]: change le titre de l'histoire\n\
index c2a650cf73af2d809d3c609f3bf957c246dbc312..e0970e3ef09621e9f8c582d65fb7e4a2c2afba13 100644 (file)
@@ -232,9 +232,11 @@ public abstract class BasicReader implements Reader {
                metaDesc.put("Published on", meta.getPublisher());
                metaDesc.put("URL", meta.getUrl());
                if (meta.isImageDocument()) {
-                       metaDesc.put("Number of images", format(meta.getWords()));
+                       metaDesc.put("Number of images",
+                                       StringUtils.formatNumber(meta.getWords()));
                } else {
-                       metaDesc.put("Number of words", format(meta.getWords()));
+                       metaDesc.put("Number of words",
+                                       StringUtils.formatNumber(meta.getWords()));
                }
                metaDesc.put("Source", meta.getSource());
                metaDesc.put("Subject", meta.getSubject());
@@ -351,26 +353,6 @@ public abstract class BasicReader implements Reader {
                }
        }
 
-       static private String format(long value) {
-               String display = "";
-               String suffix = "";
-
-               if (value > 4000) {
-                       value = value / 1000;
-                       suffix = "k";
-               }
-
-               while (value > 0) {
-                       if (!display.isEmpty()) {
-                               display = "." + display;
-                       }
-                       display = (value % 1000) + display;
-                       value = value / 1000;
-               }
-
-               return display + suffix;
-       }
-
        static private String formatDate(String date) {
                long ms = 0;
 
index b001e304842f4956095050160d5bf65b8795d3f3..fa170e44fcc64a3233ec2c09cba93fb31e84cb07 100644 (file)
@@ -6,6 +6,7 @@ import java.net.URL;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.library.BasicLibrary;
+import be.nikiroo.fanfix.supported.SupportType;
 import be.nikiroo.utils.Progress;
 
 /**
@@ -169,6 +170,58 @@ public interface Reader {
         */
        public void browse(String source);
 
+       /**
+        * Search for the given terms and find stories that correspond if possible.
+        * 
+        * @param searchOn
+        *            the website to search on
+        * @param keywords
+        *            the words to search for (cannot be NULL)
+        * @param page
+        *            the page of results to show (0 = request the maximum number of
+        *            pages, pages start at 1)
+        * @param item
+        *            the item to select (0 = do not select a specific item but show
+        *            all the page, items start at 1)
+        * 
+        * @throws IOException
+        *             in case of I/O error
+        */
+       public void search(SupportType searchOn, String keywords, int page, int item)
+                       throws IOException;
+
+       /**
+        * Search based upon a hierarchy of tags, or search for (sub)tags.
+        * <p>
+        * We use the tags <tt>DisplayName</tt>.
+        * <p>
+        * If no tag is given, the main tags will be shown.
+        * <p>
+        * If a non-leaf tag is given, the subtags will be shown.
+        * <p>
+        * If a leaf tag is given (or a full hierarchy ending with a leaf tag),
+        * stories will be shown.
+        * <p>
+        * You can select the story you want with the <tt>item</tt> number.
+        * 
+        * @param searchOn
+        *            the website to search on
+        * @param page
+        *            the page of results to show (0 = request the maximum number of
+        *            pages, pages <b>start at 1</b>)
+        * @param item
+        *            the item to select (0 = do not select a specific item but show
+        *            all the page, items <b>start at 1</b>)
+        * @param tags
+        *            the tags indices to search for (this is a tag
+        *            <b>hierarchy</b>, <b>NOT</b> a multiple tags choice)
+        * 
+        * @throws IOException
+        *             in case of I/O error
+        */
+       public void searchTag(SupportType searchOn, int page, int item,
+                       Integer... tags) throws IOException;
+
        /**
         * Open the {@link Story} with an external reader (the program should be
         * passed the main file associated with this {@link Story}).
index 9ec37a583d983cee46333f32f793ea1dc04dc3b1..6d9841830982533247e20dfcc8c5f2b9461a61af 100644 (file)
@@ -1,6 +1,7 @@
 package be.nikiroo.fanfix.reader.cli;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import be.nikiroo.fanfix.Instance;
@@ -10,6 +11,10 @@ import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Paragraph;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.reader.BasicReader;
+import be.nikiroo.fanfix.searchable.BasicSearchable;
+import be.nikiroo.fanfix.searchable.SearchableTag;
+import be.nikiroo.fanfix.supported.SupportType;
+import be.nikiroo.utils.StringUtils;
 
 /**
  * Command line {@link Story} reader.
@@ -95,4 +100,134 @@ class CliReader extends BasicReader {
                                        + author);
                }
        }
+
+       @Override
+       public void search(SupportType searchOn, String keywords, int page, int item)
+                       throws IOException {
+
+       }
+
+       @Override
+       public void searchTag(SupportType searchOn, int page, int item,
+                       Integer... tags) throws IOException {
+               BasicSearchable search = BasicSearchable.getSearchable(searchOn);
+               List<SearchableTag> stags = search.getTags();
+               String fqnTag = "";
+
+               SearchableTag stag = null;
+               for (Integer tagIndex : tags) {
+                       // ! 1-based index !
+                       if (tagIndex == null || tagIndex <= 0 | tagIndex > stags.size()) {
+                               throw new IOException("Index out of bounds: " + tagIndex);
+                       }
+
+                       stag = stags.get(tagIndex - 1);
+                       if (stag != null) {
+                               search.fillTag(stag);
+                               stags = stag.getChildren();
+                               if (!fqnTag.isEmpty()) {
+                                       fqnTag += " / ";
+                               }
+                               fqnTag += stag.getName();
+                       } else {
+                               stags = new ArrayList<SearchableTag>();
+                               break;
+                       }
+               }
+
+               if (stag != null) {
+                       if (page <= 0) {
+                               if (stag.isLeaf()) {
+                                       search.search(stag, 1);
+                                       System.out.println(stag.getPages());
+                               } else {
+                                       System.out.println(stag.getCount());
+                               }
+                       } else {
+                               List<MetaData> metas = null;
+                               List<SearchableTag> subtags = null;
+                               int count;
+
+                               if (stag.isLeaf()) {
+                                       metas = search.search(stag, page);
+                                       count = metas.size();
+                               } else {
+                                       subtags = stag.getChildren();
+                                       count = subtags.size();
+                               }
+
+                               if (item > 0) {
+                                       if (item <= count) {
+                                               if (metas != null) {
+                                                       MetaData meta = metas.get(item - 1);
+                                                       System.out.println(page + "/" + item + ": "
+                                                                       + meta.getTitle());
+                                                       System.out.println();
+                                                       System.out.println(meta.getUrl());
+                                                       System.out.println();
+                                                       System.out.println("Tags: " + meta.getTags());
+                                                       System.out.println();
+                                                       for (Paragraph para : meta.getResume()) {
+                                                               System.out.println(para.getContent());
+                                                               System.out.println("");
+                                                       }
+                                               } else {
+                                                       SearchableTag subtag = subtags.get(item - 1);
+
+                                                       // TODO: i18n
+                                                       String stories = "stories";
+                                                       String num = StringUtils.formatNumber(subtag
+                                                                       .getCount());
+                                                       System.out.println(String.format("%s (%s), %s %s",
+                                                                       subtag.getName(), fqnTag, num, stories));
+                                               }
+                                       } else {
+                                               System.out.println("Invalid item: only " + count
+                                                               + " items found");
+                                       }
+                               } else {
+                                       if (metas != null) {
+                                               // TODO i18n
+                                               System.out.println(String.format("Content of %s: ",
+                                                               fqnTag));
+                                               int i = 1;
+                                               for (MetaData meta : metas) {
+                                                       System.out.println(i + ": " + meta.getTitle());
+                                                       i++;
+                                               }
+                                       } else {
+                                               // TODO i18n
+                                               System.out.println(String.format("Subtags of %s: ",
+                                                               fqnTag));
+                                               int i = 1;
+                                               for (SearchableTag subtag : subtags) {
+                                                       String total = "";
+                                                       if (subtag.getCount() > 0) {
+                                                               total = StringUtils.formatNumber(subtag
+                                                                               .getCount());
+                                                       }
+
+                                                       if (total.isEmpty()) {
+                                                               System.out.println(String.format("%d: %s", i,
+                                                                               subtag.getName()));
+                                                       } else {
+                                                               System.out.println(String.format("%d: %s (%s)",
+                                                                               i, subtag.getName(), total));
+                                                       }
+
+                                                       i++;
+                                               }
+                                       }
+                               }
+                       }
+               } else {
+                       // TODO i18n
+                       System.out.println("Known tags: ");
+                       int i = 1;
+                       for (SearchableTag s : stags) {
+                               System.out.println(String.format("%d: %s", i, s.getName()));
+                               i++;
+                       }
+               }
+       }
 }
index f94f7838c2552e41d7061cd59e3c5bb3328ca7a9..cc39dcde77e7173229c5cd597942e36721e6462b 100644 (file)
@@ -7,6 +7,7 @@ import jexer.TApplication.BackendType;
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.reader.BasicReader;
 import be.nikiroo.fanfix.reader.Reader;
+import be.nikiroo.fanfix.supported.SupportType;
 
 /**
  * This {@link Reader}is based upon the TUI widget library 'jexer'
@@ -70,4 +71,16 @@ class TuiReader extends BasicReader {
                        Instance.getTraceHandler().error(e);
                }
        }
+       
+       @Override
+       public void search(SupportType searchOn, String keywords, int page, int item) {
+               // TODO: !!!
+               throw new java.lang.IllegalStateException("Not implemented yet.");      
+       }
+       
+       @Override
+       public void searchTag(SupportType searchOn, int page, int item, String... tags) {
+               // TODO: !!!
+               throw new java.lang.IllegalStateException("Not implemented yet.");
+       }
 }
index f08b84ccbbf17328283b059fae0ec960fe29cee1..85b1abcfb44f7af7419b757f21865b3f4ed8c3d2 100644 (file)
@@ -25,6 +25,7 @@ import be.nikiroo.fanfix.library.BasicLibrary;
 import be.nikiroo.fanfix.reader.BasicReader;
 import be.nikiroo.fanfix.reader.Reader;
 import be.nikiroo.fanfix.reader.tui.TuiReaderMainWindow.Mode;
+import be.nikiroo.fanfix.supported.SupportType;
 import be.nikiroo.utils.Progress;
 
 /**
@@ -125,6 +126,17 @@ class TuiReaderApplication extends TApplication implements Reader {
                reader.setChapter(chapter);
        }
 
+       @Override
+       public void search(SupportType searchOn, String keywords, int page, int item) throws IOException {
+               reader.search(searchOn, keywords, page, item);
+       }
+
+       @Override
+       public void searchTag(SupportType searchOn, int page, int item,
+                       Integer... tags) throws IOException {
+               reader.searchTag(searchOn, page, item, tags);
+       }
+
        /**
         * Open the given {@link Story} for reading. This may or may not start an
         * external program to read said {@link Story}.
index f4a932b3b899ef3fc48826bbe0b3aaa913a68d90..2ca61919cc5adb1aa714f3618e38e7b7f3f85bfb 100644 (file)
@@ -25,6 +25,7 @@ import be.nikiroo.fanfix.library.BasicLibrary;
 import be.nikiroo.fanfix.library.CacheLibrary;
 import be.nikiroo.fanfix.reader.BasicReader;
 import be.nikiroo.fanfix.reader.Reader;
+import be.nikiroo.fanfix.supported.SupportType;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.Version;
 import be.nikiroo.utils.ui.UIUtils;
@@ -217,6 +218,18 @@ class GuiReader extends BasicReader {
                        super.start(target, program, sync);
                }
        }
+       
+       @Override
+       public void search(SupportType searchOn, String keywords, int page, int item) {
+               // TODO: !!!
+               throw new java.lang.IllegalStateException("Not implemented yet.");
+       }
+       
+       @Override
+       public void searchTag(SupportType searchOn, int page, int item, String... tags) {
+               // TODO: !!!
+               throw new java.lang.IllegalStateException("Not implemented yet.");
+       }
 
        /**
         * Delete the {@link Story} from the cache if it is present, but <b>NOT</b>
index bbd34ab38a54a18cb9886c170b2dca4ce15e6d8c..7afaacc4e3747b37fe1b3684abb19b6248b42818 100644 (file)
@@ -199,10 +199,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                        }
                }
                
-               // TODO: enable when ready
-               if (false) {
-                       bar.add(search);
-               }
+               bar.add(search);
                
                JMenu view = new JMenu(GuiReader.trans(StringIdGui.MENU_VIEW));
                view.setMnemonic(KeyEvent.VK_V);
index c6394430e6e08c8b34ff49e2a0d2b819f6da47bc..ebc509611856b0a6f6d699a64c7a96592a68428a 100644 (file)
@@ -83,7 +83,7 @@ public abstract class BasicSearchable {
         * @throws IOException
         *             in case of I/O error
         */
-       abstract protected void fillTag(SearchableTag tag) throws IOException;
+       abstract public void fillTag(SearchableTag tag) throws IOException;
 
        /**
         * Search for the given term and return a list of stories satisfying this
index bcc4759d1390f4f765963136eeb23b890fd07559..28c0d1be02613d8840f67ce55426ea7c71c98ad8 100644 (file)
@@ -77,7 +77,7 @@ class Fanfiction extends BasicSearchable {
                if (storiesName != null) {
                        SearchableTag tag = new SearchableTag(null, storiesName, false);
                        for (String id : stories.keySet()) {
-                               tag.add(new SearchableTag(id, stories.get(id), true, false));
+                               tag.add(new SearchableTag(id, stories.get(id), false, false));
                        }
                        tags.add(tag);
                }
@@ -94,7 +94,7 @@ class Fanfiction extends BasicSearchable {
        }
 
        @Override
-       protected void fillTag(SearchableTag tag) throws IOException {
+       public void fillTag(SearchableTag tag) throws IOException {
                if (tag.getId() == null || tag.isComplete()) {
                        return;
                }
@@ -126,7 +126,11 @@ class Fanfiction extends BasicSearchable {
                                                                nr = nr.substring(0, nr.length() - 1);
                                                        }
                                                        nr = nr.trim();
-                                                       subtag.setCount(toNumber(nr));
+
+                                                       // TODO: fix toNumber/fromNumber
+                                                       nr = nr.replaceAll("\\.[0-9]*", "");
+
+                                                       subtag.setCount(StringUtils.toNumber(nr));
                                                }
                                        }
                                }
@@ -136,33 +140,6 @@ class Fanfiction extends BasicSearchable {
                tag.setComplete(true);
        }
 
-       /**
-        * @deprecated use {@link StringUtils} when updated
-        */
-       @Deprecated
-       private static long toNumber(String value) {
-               // TODO: use StringUtils instead after update
-               long count = 0l;
-               if (value != null) {
-                       try {
-                               if (value.toLowerCase().endsWith("m")) {
-                                       count = Long.parseLong(value.substring(0,
-                                                       value.length() - 1).trim());
-                                       count *= 1000000;
-                               } else if (value.toLowerCase().endsWith("k")) {
-                                       count = Long.parseLong(value.substring(0,
-                                                       value.length() - 1).trim());
-                                       count *= 1000;
-                               } else {
-                                       count = Long.parseLong(value);
-                               }
-                       } catch (NumberFormatException pe) {
-                       }
-               }
-
-               return count;
-       }
-
        @Override
        public List<MetaData> search(String search) throws IOException {
                String encoded = URLEncoder.encode(search.toLowerCase(), "utf-8");
@@ -190,7 +167,7 @@ class Fanfiction extends BasicSearchable {
                        Document doc = load(url, false);
 
                        // Update the pages number if needed
-                       if (tag.getPages() < 0) {
+                       if (tag.getPages() < 0 && tag.isLeaf()) {
                                tag.setPages(getPages(doc));
                        }