Small fixes, including better external launcher
[fanfix.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 *
133 * @throws IOException
134 * in case of I/O error or if the {@link Story} was not
135 * previously set
136 */
137 public void read() throws IOException;
138
139 /**
bc2ea776
NR
140 * The selected chapter to start reading at (starting at 1, 0 = description,
141 * -1 = none).
142 *
143 * @return the chapter, or -1 for "no chapter"
144 */
145 public int getChapter();
146
147 /**
148 * The selected chapter to start reading at (starting at 1, 0 = description,
149 * -1 = none).
e42573a0
NR
150 *
151 * @param chapter
6322ab64 152 * the chapter, or -1 for "no chapter"
e42573a0 153 */
bc2ea776 154 public void setChapter(int chapter);
e42573a0
NR
155
156 /**
157 * Start the reader in browse mode for the given source (or pass NULL for
158 * all sources).
159 *
160 * @param source
161 * the type of {@link Story} to take into account, or NULL for
162 * all
163 */
164 public void browse(String source);
16a81ef7
NR
165
166 /**
167 * Open the {@link Story} with an external reader (the program will be
168 * passed the main file associated with this {@link Story}).
169 *
170 * @param lib
171 * the {@link BasicLibrary} to select the {@link Story} from
172 * @param luid
173 * the {@link Story} LUID
174 *
175 * @throws IOException
176 * in case of I/O error
177 */
178 public void openExternal(BasicLibrary lib, String luid) throws IOException;
e42573a0 179}