X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FBasicLibrary.java;h=b8b8185cd50f75b915d732901ce8a79814bb9727;hp=8ec4e5620655ad148fb6b4b47b2c16d0f4284ee8;hb=60f723111f3f7f5bd60760afa7d0b645406b48d7;hpb=97b36d32a43b7fbbd4938c95c4b40db0c68daa71 diff --git a/src/be/nikiroo/fanfix/library/BasicLibrary.java b/src/be/nikiroo/fanfix/library/BasicLibrary.java index 8ec4e56..b8b8185 100644 --- a/src/be/nikiroo/fanfix/library/BasicLibrary.java +++ b/src/be/nikiroo/fanfix/library/BasicLibrary.java @@ -119,6 +119,31 @@ abstract public class BasicLibrary { return null; } + /** + * Return the cover image associated to this author. + *

+ * By default, return the custom cover if any, and if not, return the cover + * of the first story with this author. + * + * @param author + * the author + * + * @return the cover image or NULL + */ + public Image getAuthorCover(String author) { + Image custom = getCustomAuthorCover(author); + if (custom != null) { + return custom; + } + + List metas = getListByAuthor(author); + if (metas.size() > 0) { + return getCover(metas.get(0).getLuid()); + } + + return null; + } + /** * Return the custom cover image associated to this source. *

@@ -134,7 +159,21 @@ abstract public class BasicLibrary { } /** - * Fix the source cover to the given story cover. + * Return the custom cover image associated to this author. + *

+ * By default, return NULL. + * + * @param author + * the author to look for + * + * @return the custom cover or NULL if none + */ + public Image getCustomAuthorCover(@SuppressWarnings("unused") String author) { + return null; + } + + /** + * Set the source cover to the given story cover. * * @param source * the source to change @@ -143,6 +182,16 @@ abstract public class BasicLibrary { */ public abstract void setSourceCover(String source, String luid); + /** + * Set the author cover to the given story cover. + * + * @param source + * the author to change + * @param luid + * the story LUID + */ + public abstract void setAuthorCover(String author, String luid); + /** * Return the list of stories (represented by their {@link MetaData}, which * MAY not have the cover included). @@ -516,6 +565,42 @@ abstract public class BasicLibrary { * @return the corresponding {@link Story} or NULL if not found */ public synchronized Story getStory(String luid, Progress pg) { + Progress pgMetas = new Progress(); + Progress pgStory = new Progress(); + if (pg != null) { + pg.setMinMax(0, 100); + pg.addProgress(pgMetas, 10); + pg.addProgress(pgStory, 90); + } + + MetaData meta = null; + for (MetaData oneMeta : getMetas(pgMetas)) { + if (oneMeta.getLuid().equals(luid)) { + meta = oneMeta; + break; + } + } + + pgMetas.done(); + + Story story = getStory(luid, meta, pgStory); + pgStory.done(); + + return story; + } + + /** + * Retrieve a specific {@link Story}. + * + * @param luid + * the meta of the story + * @param pg + * the optional progress reporter + * + * @return the corresponding {@link Story} or NULL if not found + */ + public synchronized Story getStory(String luid, MetaData meta, Progress pg) { + if (pg == null) { pg = new Progress(); } @@ -528,39 +613,32 @@ abstract public class BasicLibrary { pg.addProgress(pgProcess, 1); Story story = null; - for (MetaData meta : getMetas(null)) { - if (meta.getLuid().equals(luid)) { - File file = getFile(luid, pgGet); - pgGet.done(); - try { - SupportType type = SupportType.valueOfAllOkUC(meta - .getType()); - URL url = file.toURI().toURL(); - if (type != null) { - story = BasicSupport.getSupport(type, url) // - .process(pgProcess); - - // Because we do not want to clear the meta cache: - meta.setCover(story.getMeta().getCover()); - meta.setResume(story.getMeta().getResume()); - story.setMeta(meta); - // - } else { - throw new IOException("Unknown type: " + meta.getType()); - } - } catch (IOException e) { - // We should not have not-supported files in the - // library - Instance.getTraceHandler().error( - new IOException("Cannot load file from library: " - + file, e)); - } finally { - pgProcess.done(); - pg.done(); - } - - break; + File file = getFile(luid, pgGet); + pgGet.done(); + try { + SupportType type = SupportType.valueOfAllOkUC(meta.getType()); + URL url = file.toURI().toURL(); + if (type != null) { + story = BasicSupport.getSupport(type, url) // + .process(pgProcess); + + // Because we do not want to clear the meta cache: + meta.setCover(story.getMeta().getCover()); + meta.setResume(story.getMeta().getResume()); + story.setMeta(meta); + // + } else { + throw new IOException("Unknown type: " + meta.getType()); } + } catch (IOException e) { + // We should not have not-supported files in the + // library + Instance.getTraceHandler() + .error(new IOException("Cannot load file from library: " + + file, e)); + } finally { + pgProcess.done(); + pg.done(); } return story;