1 package be
.nikiroo
.fanfix
.reader
;
3 import java
.awt
.EventQueue
;
5 import java
.io
.IOException
;
7 import be
.nikiroo
.fanfix
.Instance
;
8 import be
.nikiroo
.fanfix
.Library
;
9 import be
.nikiroo
.fanfix
.bundles
.UiConfig
;
10 import be
.nikiroo
.fanfix
.data
.Story
;
11 import be
.nikiroo
.fanfix
.output
.BasicOutput
.OutputType
;
12 import be
.nikiroo
.utils
.Progress
;
14 class LocalReader
extends BasicReader
{
17 public LocalReader() throws IOException
{
18 File dir
= Instance
.getReaderDir();
21 throw new IOException(
22 "Cannote create cache directory for local reader: " + dir
);
25 // TODO: can throw an exception, manage that (convert to IOEx ?)
26 OutputType text
= OutputType
.valueOfNullOkUC(Instance
.getUiConfig()
27 .getString(UiConfig
.LOCAL_READER_NON_IMAGES_DOCUMENT_TYPE
));
29 text
= OutputType
.HTML
;
32 OutputType images
= OutputType
.valueOfNullOkUC(Instance
.getUiConfig()
33 .getString(UiConfig
.LOCAL_READER_IMAGES_DOCUMENT_TYPE
));
35 images
= OutputType
.CBZ
;
39 lib
= new Library(dir
, text
, images
);
43 public void read() throws IOException
{
47 public void read(int chapter
) {
51 * Import the story into the local reader library, and keep the same LUID.
56 * the optional progress reporter
59 * in case of I/O error
61 public void imprt(String luid
, Progress pg
) throws IOException
{
62 Progress pgGetStory
= new Progress();
63 Progress pgSave
= new Progress();
66 pg
.addProgress(pgGetStory
, 1);
67 pg
.addProgress(pgSave
, 1);
71 Story story
= Instance
.getLibrary().getStory(luid
, pgGetStory
);
73 story
= lib
.save(story
, luid
, pgSave
);
75 throw new IOException("Cannot find story in Library: " + luid
);
77 } catch (IOException e
) {
78 throw new IOException(
79 "Cannot import story from library to LocalReader library: "
85 * Get the target file related to this {@link Story}.
88 * the LUID of the {@link Story}
90 * the optional progress reporter
92 * @return the target file
95 * in case of I/O error
97 public File
getTarget(String luid
, Progress pg
) throws IOException
{
98 File file
= lib
.getFile(luid
);
101 file
= lib
.getFile(luid
);
108 * Check if the {@link Story} denoted by this Library UID is present in the
109 * {@link LocalReader} cache.
114 * @return TRUE if it is
116 public boolean isCached(String luid
) {
117 return lib
.getInfo(luid
) != null;
121 public void start(String type
) {
122 final String typeFinal
= type
;
123 EventQueue
.invokeLater(new Runnable() {
125 new LocalReaderFrame(LocalReader
.this, typeFinal
)
131 void refresh(String luid
) {
135 void delete(String luid
) {
137 Instance
.getLibrary().delete(luid
);