CLI search, step 1
[fanfix.git] / src / be / nikiroo / fanfix / reader / Reader.java
index d7285785b6513dc76badadb96ad8ce49a620e9be..59ed024f42380a8a50f2b3e5fa199146d9092459 100644 (file)
@@ -3,11 +3,18 @@ package be.nikiroo.fanfix.reader;
 import java.io.IOException;
 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.library.LocalLibrary;
+import be.nikiroo.fanfix.supported.SupportType;
 import be.nikiroo.utils.Progress;
 
+/**
+ * A {@link Reader} is a class that will handle {@link Story} reading and
+ * browsing.
+ * 
+ * @author niki
+ */
 public interface Reader {
        /**
         * A type of {@link BasicReader}.
@@ -21,6 +28,8 @@ public interface Reader {
                GUI,
                /** A text (UTF-8) reader with menu and text windows */
                TUI,
+               /** A GUI reader implemented with the Android framework */
+               ANDROID,
 
                ;
 
@@ -34,57 +43,80 @@ public interface Reader {
                        String pkg = "be.nikiroo.fanfix.reader.";
                        switch (this) {
                        case CLI:
-                               return pkg + "CliReader";
+                               return pkg + "cli.CliReader";
                        case TUI:
-                               return pkg + "TuiReader";
+                               return pkg + "tui.TuiReader";
                        case GUI:
-                               return pkg + "GuiReader";
+                               return pkg + "ui.GuiReader";
+                       case ANDROID:
+                               return pkg + "android.AndroidReader";
                        }
 
                        return null;
                }
-       };
+       }
 
        /**
-        * Return the current {@link Story}.
+        * Return the current target {@link MetaData}.
+        * 
+        * @return the meta
+        */
+       public MetaData getMeta();
+
+       /**
+        * Return the current {@link Story} as described by the current
+        * {@link MetaData}.
+        * 
+        * @param pg
+        *            the optional progress
         * 
         * @return the {@link Story}
         */
-       public Story getStory();
+       public Story getStory(Progress pg);
 
        /**
-        * The {@link LocalLibrary} to load the stories from (by default, takes the
-        * default {@link LocalLibrary}).
+        * The {@link BasicLibrary} to load the stories from (by default, takes the
+        * default {@link BasicLibrary}).
         * 
-        * @return the {@link LocalLibrary}
+        * @return the {@link BasicLibrary}
         */
        public BasicLibrary getLibrary();
 
        /**
-        * Change the {@link LocalLibrary} that will be managed by this
+        * Change the {@link BasicLibrary} that will be managed by this
         * {@link BasicReader}.
         * 
         * @param lib
-        *            the new {@link LocalLibrary}
+        *            the new {@link BasicLibrary}
         */
-       public void setLibrary(LocalLibrary lib);
+       public void setLibrary(BasicLibrary lib);
 
        /**
-        * Create a new {@link BasicReader} for a {@link Story} in the
-        * {@link LocalLibrary}.
+        * Set a {@link Story} from the current {@link BasicLibrary} into the
+        * {@link Reader}.
         * 
         * @param luid
         *            the {@link Story} ID
-        * @param pg
-        *            the optional progress reporter
         * 
         * @throws IOException
         *             in case of I/O error
         */
-       public void setStory(String luid, Progress pg) throws IOException;
+       public void setMeta(String luid) throws IOException;
 
        /**
-        * Create a new {@link BasicReader} for an external {@link Story}.
+        * Set a {@link Story} from the current {@link BasicLibrary} into the
+        * {@link Reader}.
+        * 
+        * @param meta
+        *            the meta
+        * 
+        * @throws IOException
+        *             in case of I/O error
+        */
+       public void setMeta(MetaData meta) throws IOException;
+
+       /**
+        * Set an external {@link Story} into this {@link Reader}.
         * 
         * @param source
         *            the {@link Story} {@link URL}
@@ -94,32 +126,43 @@ public interface Reader {
         * @throws IOException
         *             in case of I/O error
         */
-       public void setStory(URL source, Progress pg) throws IOException;
+       public void setMeta(URL source, Progress pg) throws IOException;
 
        /**
         * Start the {@link Story} Reading.
         * 
+        * @param sync
+        *            execute the process synchronously (wait until it is terminated
+        *            before returning)
+        * 
         * @throws IOException
         *             in case of I/O error or if the {@link Story} was not
         *             previously set
         */
-       public void read() throws IOException;
+       public void read(boolean sync) throws IOException;
 
        /**
-        * Read the selected chapter (starting at 1).
+        * The selected chapter to start reading at (starting at 1, 0 = description,
+        * -1 = none).
         * 
-        * @param chapter
-        *            the chapter
+        * @return the chapter, or -1 for "no chapter"
+        */
+       public int getChapter();
+
+       /**
+        * The selected chapter to start reading at (starting at 1, 0 = description,
+        * -1 = none).
         * 
-        * @throws IOException
-        *             in case of I/O error or if the {@link Story} was not
-        *             previously set
+        * @param chapter
+        *            the chapter, or -1 for "no chapter"
         */
-       public void read(int chapter) throws IOException;
+       public void setChapter(int chapter);
 
        /**
         * Start the reader in browse mode for the given source (or pass NULL for
         * all sources).
+        * <p>
+        * Note that this must be a <b>synchronous</b> action.
         * 
         * @param source
         *            the type of {@link Story} to take into account, or NULL for
@@ -127,4 +170,73 @@ 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 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)
+        * @param tags
+        *            the tags display names 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,
+                       String... tags) throws IOException;
+
+       /**
+        * Open the {@link Story} with an external reader (the program should be
+        * passed the main file associated with this {@link Story}).
+        * 
+        * @param lib
+        *            the {@link BasicLibrary} to select the {@link Story} from
+        * @param luid
+        *            the {@link Story} LUID
+        * @param sync
+        *            execute the process synchronously (wait until it is terminated
+        *            before returning)
+        * 
+        * @throws IOException
+        *             in case of I/O error
+        */
+       public void openExternal(BasicLibrary lib, String luid, boolean sync)
+                       throws IOException;
 }