X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FBasicLibrary.java;h=b3b49fdbce50ec5aa6b4877af9c42b2a949e39df;hb=c1b93db3213970c86b766c92a0b0d546c9d1c2ae;hp=f6daed620f86347a5ec84a44ee3e8e80b600eb09;hpb=5f42f329b6d1dd0d61f49dd9947fe487c39160ee;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/library/BasicLibrary.java b/src/be/nikiroo/fanfix/library/BasicLibrary.java index f6daed6..b3b49fd 100644 --- a/src/be/nikiroo/fanfix/library/BasicLibrary.java +++ b/src/be/nikiroo/fanfix/library/BasicLibrary.java @@ -8,7 +8,9 @@ import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.TreeMap; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; @@ -158,8 +160,8 @@ abstract public class BasicLibrary { * Invalidate the {@link Story} cache (when the content should be re-read * because it was changed). */ - protected void deleteInfo() { - deleteInfo(null); + protected void invalidateInfo() { + invalidateInfo(null); } /** @@ -171,7 +173,7 @@ abstract public class BasicLibrary { * the LUID of the {@link Story} to clear from the cache, or NULL * for all stories */ - protected abstract void deleteInfo(String luid); + protected abstract void invalidateInfo(String luid); /** * Invalidate the {@link Story} cache (when the content has changed, but we @@ -246,6 +248,47 @@ abstract public class BasicLibrary { return list; } + /** + * List all the known types (sources) of stories, grouped by directory + * ("Source_1/a" and "Source_1/b" will be grouped into "Source_1"). + *

+ * Note that an empty item in the list means a non-grouped source (type) -- + * e.g., you could have for Source_1: + *

+ * + * @return the grouped list + */ + public synchronized Map> getSourcesGrouped() { + Map> map = new TreeMap>(); + for (String source : getSources()) { + String name; + String subname; + + int pos = source.indexOf('/'); + if (pos > 0 && pos < source.length() - 1) { + name = source.substring(0, pos); + subname = source.substring(pos + 1); + + } else { + name = source; + subname = ""; + } + + List list = map.get(name); + if (list == null) { + list = new ArrayList(); + map.put(name, list); + } + list.add(subname); + } + + return map; + } + /** * List all the known authors of stories. * @@ -375,7 +418,7 @@ abstract public class BasicLibrary { /** * List all the stories in the {@link BasicLibrary}. *

- * Cover images not included. + * Cover images MAYBE not included. * * @return the stories */ @@ -705,7 +748,7 @@ abstract public class BasicLibrary { this.getClass().getSimpleName() + ": deleting story " + luid); doDelete(luid); - deleteInfo(luid); + invalidateInfo(luid); Instance.getTraceHandler().trace( this.getClass().getSimpleName() + ": story deleted (" + luid @@ -732,7 +775,83 @@ abstract public class BasicLibrary { throw new IOException("Story not found: " + luid); } + changeSTA(luid, newSource, meta.getTitle(), meta.getAuthor(), pg); + } + + /** + * Change the title (name) of the given {@link Story}. + * + * @param luid + * the {@link Story} LUID + * @param newTitle + * the new title + * @param pg + * the optional progress reporter + * + * @throws IOException + * in case of I/O error or if the {@link Story} was not found + */ + public synchronized void changeTitle(String luid, String newTitle, + Progress pg) throws IOException { + MetaData meta = getInfo(luid); + if (meta == null) { + throw new IOException("Story not found: " + luid); + } + + changeSTA(luid, meta.getSource(), newTitle, meta.getAuthor(), pg); + } + + /** + * Change the author of the given {@link Story}. + * + * @param luid + * the {@link Story} LUID + * @param newAuthor + * the new author + * @param pg + * the optional progress reporter + * + * @throws IOException + * in case of I/O error or if the {@link Story} was not found + */ + public synchronized void changeAuthor(String luid, String newAuthor, + Progress pg) throws IOException { + MetaData meta = getInfo(luid); + if (meta == null) { + throw new IOException("Story not found: " + luid); + } + + changeSTA(luid, meta.getSource(), meta.getTitle(), newAuthor, pg); + } + + /** + * Change the Source, Title and Author of the {@link Story} in one single + * go. + * + * @param luid + * the {@link Story} LUID + * @param newSource + * the new source + * @param newTitle + * the new title + * @param newAuthor + * the new author + * @param pg + * the optional progress reporter + * + * @throws IOException + * in case of I/O error or if the {@link Story} was not found + */ + protected synchronized void changeSTA(String luid, String newSource, + String newTitle, String newAuthor, Progress pg) throws IOException { + MetaData meta = getInfo(luid); + if (meta == null) { + throw new IOException("Story not found: " + luid); + } + meta.setSource(newSource); + meta.setTitle(newTitle); + meta.setAuthor(newAuthor); saveMeta(meta, pg); } @@ -743,7 +862,7 @@ abstract public class BasicLibrary { * By default, delete the old {@link Story} then recreate a new * {@link Story}. *

- * Note that this behaviour can lead to data loss. + * Note that this behaviour can lead to data loss in case of problems! * * @param meta * the new {@link MetaData} (LUID MUST NOT change) @@ -769,8 +888,8 @@ abstract public class BasicLibrary { throw new IOException("Story not found: " + meta.getLuid()); } + // TODO: this is not safe! delete(meta.getLuid()); - story.setMeta(meta); save(story, meta.getLuid(), pgSet);