*/
public File export(String luid, OutputType type, String target, Progress pg)
throws IOException {
+ Progress pgGetStory = new Progress();
+ Progress pgOut = new Progress();
+ if (pg != null) {
+ pg.setMax(2);
+ pg.addProgress(pgGetStory, 1);
+ pg.addProgress(pgOut, 1);
+ }
+
BasicOutput out = BasicOutput.getOutput(type, true);
if (out == null) {
throw new IOException("Output type not supported: " + type);
}
- Story story = getStory(luid, pg);
+ Story story = getStory(luid, pgGetStory);
if (story == null) {
throw new IOException("Cannot find story to export: " + luid);
}
- return out.process(story, target);
+ return out.process(story, target, pgOut);
}
/**
*
* @param story
* the {@link Story} to save
+ * @param pg
+ * the optional progress reporter
*
* @return the same {@link Story}, whose LUID may have changed
*
* @throws IOException
* in case of I/O error
*/
- public Story save(Story story) throws IOException {
- return save(story, null);
+ public Story save(Story story, Progress pg) throws IOException {
+ return save(story, null, pg);
}
/**
* the {@link Story} to save
* @param luid
* the <b>correct</b> LUID or NULL to get the next free one
+ * @param pg
+ * the optional progress reporter
*
* @return the same {@link Story}, whose LUID may have changed
*
* @throws IOException
* in case of I/O error
*/
- public Story save(Story story, String luid) throws IOException {
+ public Story save(Story story, String luid, Progress pg) throws IOException {
// Do not change the original metadata, but change the original story
MetaData key = story.getMeta().clone();
story.setMeta(key);
}
BasicOutput it = BasicOutput.getOutput(out, true);
- File file = it.process(story, getFile(key).getPath());
+ File file = it.process(story, getFile(key).getPath(), pg);
getStories().put(story.getMeta(), file);
return story;
BasicSupport support = BasicSupport.getSupport(source);
if (support != null) {
- Story story = support.process(source, pg);
+ Progress pgIn = new Progress();
+ Progress pgOut = new Progress();
+ if (pg != null) {
+ pg.setMax(2);
+ pg.addProgress(pgIn, 1);
+ pg.addProgress(pgOut, 1);
+ }
+ Story story = support.process(source, pgIn);
try {
target = new File(target).getAbsolutePath();
BasicOutput.getOutput(type, infoCover).process(
- story, target);
+ story, target, pgOut);
} catch (IOException e) {
Instance.syserr(new IOException(trans(
StringId.ERR_SAVING, target), e));
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.StringId;
import be.nikiroo.fanfix.data.Chapter;
import be.nikiroo.fanfix.data.Paragraph;
-import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
+import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.utils.ui.Progress;
/**
* This class is the base class used by the other output classes. It can be used
private OutputType type;
private boolean writeCover;
private boolean writeInfo;
+ private Progress storyPg;
+ private Progress chapPg;
/**
* Process the {@link Story} into the given target.
* @param target
* the target where to save to (will not necessary be taken as is
* by the processor, for instance an extension can be added)
+ * @param pg
+ * the optional progress reporter
*
* @return the actual main target saved, which can be slightly different
* that the input one
* @throws IOException
* in case of I/O error
*/
- public File process(Story story, String target) throws IOException {
+ public File process(Story story, String target, Progress pg)
+ throws IOException {
+ storyPg = pg;
+
target = new File(target).getAbsolutePath();
File targetDir = new File(target).getParentFile();
String targetName = new File(target).getName();
* the target filename (will not necessary be taken as is by the
* processor, for instance an extension can be added)
*
+ *
* @return the actual main target saved, which can be slightly different
* that the input one
*
}
protected void writeStory(Story story) throws IOException {
+ if (storyPg == null) {
+ storyPg = new Progress(0, story.getChapters().size() + 2);
+ } else {
+ storyPg.setMinMax(0, story.getChapters().size() + 2);
+ }
+
String chapterNameNum = String.format("%03d", 0);
String paragraphNumber = String.format("%04d", 0);
imageName = paragraphNumber + "_" + chapterNameNum + ".png";
InfoCover.writeInfo(targetDir, targetName, story.getMeta());
}
- writeStoryHeader(story);
+ storyPg.setProgress(1);
+
+ List<Progress> chapPgs = new ArrayList<Progress>(story.getChapters()
+ .size());
for (Chapter chap : story) {
- writeChapter(chap);
+ chapPg = new Progress(0, chap.getParagraphs().size());
+ storyPg.addProgress(chapPg, 1);
+ chapPgs.add(chapPg);
+ chapPg = null;
+ }
+
+ writeStoryHeader(story);
+ for (int i = 0; i < story.getChapters().size(); i++) {
+ chapPg = chapPgs.get(i);
+ writeChapter(story.getChapters().get(i));
+ chapPg.setProgress(chapPg.getMax());
+ chapPg = null;
}
writeStoryFooter(story);
+
+ storyPg.setProgress(storyPg.getMax());
+ storyPg = null;
}
protected void writeChapter(Chapter chap) throws IOException {
imageName = chapterNameNum + "_" + paragraphNumber + ".png";
writeChapterHeader(chap);
+ int i = 1;
for (Paragraph para : chap) {
paragraphNumber = String.format("%04d", num++);
imageName = chapterNameNum + "_" + paragraphNumber + ".png";
writeParagraph(para);
+ if (chapPg != null) {
+ chapPg.setProgress(i++);
+ }
}
writeChapterFooter(chap);
}
* in case of I/O error
*/
public void imprt(String luid, Progress pg) throws IOException {
+ Progress pgGetStory = new Progress();
+ Progress pgSave = new Progress();
+ if (pg != null) {
+ pg.setMax(2);
+ pg.addProgress(pgGetStory, 1);
+ pg.addProgress(pgSave, 1);
+ }
+
try {
- Story story = Instance.getLibrary().getStory(luid, pg);
+ Story story = Instance.getLibrary().getStory(luid, pgGetStory);
if (story != null) {
- story = lib.save(story, luid);
+ story = lib.save(story, luid, pgSave);
} else {
throw new IOException("Cannot find story in Library: " + luid);
}