gui: fix sync() method usage
[nikiroo-utils.git] / src / be / nikiroo / fanfix / reader / Reader.java
CommitLineData
e42573a0
NR
1package be.nikiroo.fanfix.reader;
2
3import java.io.IOException;
4import java.net.URL;
5
bc2ea776 6import be.nikiroo.fanfix.data.MetaData;
e42573a0
NR
7import be.nikiroo.fanfix.data.Story;
8import be.nikiroo.fanfix.library.BasicLibrary;
e42573a0
NR
9import be.nikiroo.utils.Progress;
10
bc2ea776
NR
11/**
12 * A {@link Reader} is a class that will handle {@link Story} reading and
13 * browsing.
14 *
15 * @author niki
16 */
e42573a0
NR
17public 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,
b4f9071c
NR
30 /** A GUI reader implemented with the Android framework */
31 ANDROID,
e42573a0
NR
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:
16a81ef7 45 return pkg + "cli.CliReader";
e42573a0 46 case TUI:
16a81ef7 47 return pkg + "tui.TuiReader";
e42573a0 48 case GUI:
16a81ef7 49 return pkg + "ui.GuiReader";
b4f9071c
NR
50 case ANDROID:
51 return pkg + "android.AndroidReader";
e42573a0
NR
52 }
53
54 return null;
55 }
211f7ddb 56 }
e42573a0
NR
57
58 /**
bc2ea776
NR
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
e42573a0
NR
71 *
72 * @return the {@link Story}
73 */
bc2ea776 74 public Story getStory(Progress pg);
e42573a0
NR
75
76 /**
bc2ea776
NR
77 * The {@link BasicLibrary} to load the stories from (by default, takes the
78 * default {@link BasicLibrary}).
e42573a0 79 *
bc2ea776 80 * @return the {@link BasicLibrary}
e42573a0
NR
81 */
82 public BasicLibrary getLibrary();
83
84 /**
bc2ea776 85 * Change the {@link BasicLibrary} that will be managed by this
e42573a0
NR
86 * {@link BasicReader}.
87 *
88 * @param lib
bc2ea776 89 * the new {@link BasicLibrary}
e42573a0 90 */
bc2ea776 91 public void setLibrary(BasicLibrary lib);
e42573a0
NR
92
93 /**
bc2ea776 94 * Set a {@link Story} from the current {@link BasicLibrary} into the
6322ab64 95 * {@link Reader}.
e42573a0
NR
96 *
97 * @param luid
98 * the {@link Story} ID
e42573a0
NR
99 *
100 * @throws IOException
101 * in case of I/O error
102 */
bc2ea776
NR
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;
e42573a0
NR
116
117 /**
6322ab64 118 * Set an external {@link Story} into this {@link Reader}.
e42573a0
NR
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 */
bc2ea776 128 public void setMeta(URL source, Progress pg) throws IOException;
e42573a0
NR
129
130 /**
131 * Start the {@link Story} Reading.
132 *
350bc060
NR
133 * @param sync
134 * execute the process synchronously (wait until it is terminated
135 * before returning)
136 *
e42573a0
NR
137 * @throws IOException
138 * in case of I/O error or if the {@link Story} was not
139 * previously set
140 */
350bc060 141 public void read(boolean sync) throws IOException;
e42573a0
NR
142
143 /**
bc2ea776
NR
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).
e42573a0
NR
154 *
155 * @param chapter
6322ab64 156 * the chapter, or -1 for "no chapter"
e42573a0 157 */
bc2ea776 158 public void setChapter(int chapter);
e42573a0
NR
159
160 /**
161 * Start the reader in browse mode for the given source (or pass NULL for
162 * all sources).
350bc060
NR
163 * <p>
164 * Note that this must be a <b>synchronous</b> action.
e42573a0
NR
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);
16a81ef7
NR
171
172 /**
350bc060 173 * Open the {@link Story} with an external reader (the program should be
16a81ef7
NR
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
350bc060
NR
180 * @param sync
181 * execute the process synchronously (wait until it is terminated
182 * before returning)
16a81ef7
NR
183 *
184 * @throws IOException
185 * in case of I/O error
186 */
350bc060
NR
187 public void openExternal(BasicLibrary lib, String luid, boolean sync)
188 throws IOException;
e42573a0 189}