reader: sync/async work
[fanfix.git] / src / be / nikiroo / fanfix / reader / Reader.java
1 package be.nikiroo.fanfix.reader;
2
3 import java.io.IOException;
4 import java.net.URL;
5
6 import be.nikiroo.fanfix.data.MetaData;
7 import be.nikiroo.fanfix.data.Story;
8 import be.nikiroo.fanfix.library.BasicLibrary;
9 import be.nikiroo.utils.Progress;
10
11 /**
12 * A {@link Reader} is a class that will handle {@link Story} reading and
13 * browsing.
14 *
15 * @author niki
16 */
17 public interface Reader {
18 /**
19 * A type of {@link BasicReader}.
20 *
21 * @author niki
22 */
23 public enum ReaderType {
24 /** Simple reader that outputs everything on the console */
25 CLI,
26 /** Reader that starts local programs to handle the stories */
27 GUI,
28 /** A text (UTF-8) reader with menu and text windows */
29 TUI,
30 /** A GUI reader implemented with the Android framework */
31 ANDROID,
32
33 ;
34
35 /**
36 * Return the full class name of a type that implements said
37 * {@link ReaderType}.
38 *
39 * @return the class name
40 */
41 public String getTypeName() {
42 String pkg = "be.nikiroo.fanfix.reader.";
43 switch (this) {
44 case CLI:
45 return pkg + "cli.CliReader";
46 case TUI:
47 return pkg + "tui.TuiReader";
48 case GUI:
49 return pkg + "ui.GuiReader";
50 case ANDROID:
51 return pkg + "android.AndroidReader";
52 }
53
54 return null;
55 }
56 }
57
58 /**
59 * Return the current target {@link MetaData}.
60 *
61 * @return the meta
62 */
63 public MetaData getMeta();
64
65 /**
66 * Return the current {@link Story} as described by the current
67 * {@link MetaData}.
68 *
69 * @param pg
70 * the optional progress
71 *
72 * @return the {@link Story}
73 */
74 public Story getStory(Progress pg);
75
76 /**
77 * The {@link BasicLibrary} to load the stories from (by default, takes the
78 * default {@link BasicLibrary}).
79 *
80 * @return the {@link BasicLibrary}
81 */
82 public BasicLibrary getLibrary();
83
84 /**
85 * Change the {@link BasicLibrary} that will be managed by this
86 * {@link BasicReader}.
87 *
88 * @param lib
89 * the new {@link BasicLibrary}
90 */
91 public void setLibrary(BasicLibrary lib);
92
93 /**
94 * Set a {@link Story} from the current {@link BasicLibrary} into the
95 * {@link Reader}.
96 *
97 * @param luid
98 * the {@link Story} ID
99 *
100 * @throws IOException
101 * in case of I/O error
102 */
103 public void setMeta(String luid) throws IOException;
104
105 /**
106 * Set a {@link Story} from the current {@link BasicLibrary} into the
107 * {@link Reader}.
108 *
109 * @param meta
110 * the meta
111 *
112 * @throws IOException
113 * in case of I/O error
114 */
115 public void setMeta(MetaData meta) throws IOException;
116
117 /**
118 * Set an external {@link Story} into this {@link Reader}.
119 *
120 * @param source
121 * the {@link Story} {@link URL}
122 * @param pg
123 * the optional progress reporter
124 *
125 * @throws IOException
126 * in case of I/O error
127 */
128 public void setMeta(URL source, Progress pg) throws IOException;
129
130 /**
131 * Start the {@link Story} Reading.
132 *
133 * @param sync
134 * execute the process synchronously (wait until it is terminated
135 * before returning)
136 *
137 * @throws IOException
138 * in case of I/O error or if the {@link Story} was not
139 * previously set
140 */
141 public void read(boolean sync) throws IOException;
142
143 /**
144 * The selected chapter to start reading at (starting at 1, 0 = description,
145 * -1 = none).
146 *
147 * @return the chapter, or -1 for "no chapter"
148 */
149 public int getChapter();
150
151 /**
152 * The selected chapter to start reading at (starting at 1, 0 = description,
153 * -1 = none).
154 *
155 * @param chapter
156 * the chapter, or -1 for "no chapter"
157 */
158 public void setChapter(int chapter);
159
160 /**
161 * Start the reader in browse mode for the given source (or pass NULL for
162 * all sources).
163 * <p>
164 * Note that this must be a <b>synchronous</b> action.
165 *
166 * @param source
167 * the type of {@link Story} to take into account, or NULL for
168 * all
169 */
170 public void browse(String source);
171
172 /**
173 * Open the {@link Story} with an external reader (the program should be
174 * passed the main file associated with this {@link Story}).
175 *
176 * @param lib
177 * the {@link BasicLibrary} to select the {@link Story} from
178 * @param luid
179 * the {@link Story} LUID
180 * @param sync
181 * execute the process synchronously (wait until it is terminated
182 * before returning)
183 *
184 * @throws IOException
185 * in case of I/O error
186 */
187 public void openExternal(BasicLibrary lib, String luid, boolean sync)
188 throws IOException;
189 }