Lot of fixes + first (bad, ugly) working GUI
[fanfix.git] / src / be / nikiroo / fanfix / reader / LocalReader.java
CommitLineData
a6395bef
NR
1package be.nikiroo.fanfix.reader;
2
3import java.awt.EventQueue;
4import java.io.File;
5import java.io.IOException;
6
7import be.nikiroo.fanfix.Instance;
8import be.nikiroo.fanfix.Library;
9import be.nikiroo.fanfix.bundles.Config;
10import be.nikiroo.fanfix.data.MetaData;
11import be.nikiroo.fanfix.data.Story;
12import be.nikiroo.fanfix.output.BasicOutput.OutputType;
a6395bef
NR
13
14class LocalReader extends BasicReader {
15 private Library lib;
16
17 public LocalReader() throws IOException {
18 File dir = Instance.getReaderDir();
19 dir.mkdirs();
20 if (!dir.exists()) {
21 throw new IOException(
22 "Cannote create cache directory for local reader: " + dir);
23 }
24
25 // TODO: can throw an exception, manage that (convert to IOEx ?)
26 OutputType text = OutputType.valueOfNullOkUC(Instance.getConfig()
27 .getString(Config.LOCAL_READER_NON_IMAGES_DOCUMENT_TYPE));
28 if (text == null) {
29 text = OutputType.HTML;
30 }
31
32 OutputType images = OutputType.valueOfNullOkUC(Instance.getConfig()
33 .getString(Config.LOCAL_READER_IMAGES_DOCUMENT_TYPE));
34 if (images == null) {
35 images = OutputType.CBZ;
36 }
37 //
38
39 lib = new Library(dir, text, images);
40 }
41
42 @Override
43 public void read() throws IOException {
44 }
45
46 @Override
47 public void read(int chapter) {
48 }
49
50 // return new luid
51 public String imprt(String luid) {
52 try {
53 Story story = Instance.getLibrary().getStory(luid);
54 story = lib.save(story);
55 return story.getMeta().getLuid();
56 } catch (IOException e) {
57 Instance.syserr(new IOException(
58 "Cannot import story from library to LocalReader library: "
59 + luid, e));
60 }
61
62 return null;
63 }
64
65 public File getTarget(String luid) {
66 MetaData meta = lib.getInfo(luid);
67 File file = lib.getFile(luid);
68 if (file == null) {
69 luid = imprt(luid);
70 file = lib.getFile(luid);
71 meta = lib.getInfo(luid);
72 }
73
74 return file;
75 }
76
77 @Override
333f0e7b
NR
78 public void start(String type) {
79 final String typeFinal = type;
a6395bef
NR
80 EventQueue.invokeLater(new Runnable() {
81 public void run() {
82 new LocalReaderFrame(LocalReader.this, typeFinal)
83 .setVisible(true);
84 }
85 });
86 }
a6395bef 87}