/**
* Return the cover image associated to this source.
* <p>
- * By default, return the cover of the first story with this source.
+ * By default, return the custom cover if any, and if not, return the cover
+ * of the first story with this source.
*
* @param source
* the source
* @return the cover image or NULL
*/
public Image getSourceCover(String source) {
+ Image custom = getCustomSourceCover(source);
+ if (custom != null) {
+ return custom;
+ }
+
List<MetaData> metas = getListBySource(source);
if (metas.size() > 0) {
return getCover(metas.get(0).getLuid());
return null;
}
+ /**
+ * Return the custom cover image associated to this source.
+ * <p>
+ * By default, return NULL.
+ *
+ * @param source
+ * the source to look for
+ *
+ * @return the custom cover or NULL if none
+ */
+ public Image getCustomSourceCover(@SuppressWarnings("unused") String source) {
+ return null;
+ }
+
/**
* Fix the source cover to the given story cover.
*
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
}
@Override
- public Image getSourceCover(String source) {
+ public synchronized Image getCustomSourceCover(String source) {
if (sourceCovers == null) {
- getStories(null);
+ sourceCovers = new HashMap<String, Image>();
+ }
+
+ Image img = sourceCovers.get(source);
+ if (img != null) {
+ return img;
}
- if (!sourceCovers.containsKey(source)) {
- sourceCovers.put(source, super.getSourceCover(source));
+ File coverDir = new File(baseDir, source);
+ if (coverDir.isDirectory()) {
+ File cover = new File(coverDir, ".cover.png");
+ InputStream in;
+ try {
+ in = new FileInputStream(cover);
+ try {
+ sourceCovers.put(source, new Image(in));
+ } finally {
+ in.close();
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
return sourceCovers.get(source);
@Override
public void setSourceCover(String source, String luid) {
- if (sourceCovers == null) {
- getStories(null);
- }
+ setSourceCover(source, getCover(luid));
+ }
- sourceCovers.put(source, getCover(luid));
+ /**
+ * Fix the source cover to the given story cover.
+ *
+ * @param source
+ * the source to change
+ * @param coverImage
+ * the cover image
+ */
+ synchronized void setSourceCover(String source, Image coverImage) {
File cover = new File(getExpectedDir(source), ".cover");
try {
- Instance.getCache().saveAsImage(sourceCovers.get(source), cover,
- true);
+ Instance.getCache().saveAsImage(coverImage, cover, true);
+ if (sourceCovers != null) {
+ sourceCovers.put(source, coverImage);
+ }
} catch (IOException e) {
Instance.getTraceHandler().error(e);
- sourceCovers.remove(source);
}
}
if (stories == null) {
stories = new HashMap<MetaData, File[]>();
- sourceCovers = new HashMap<String, Image>();
lastId = 0;
pgDirs.addProgress(pgFiles, 100);
pgDirs.setName("Loading from: " + dir.getName());
- String source = null;
for (File infoFile : infoFiles) {
pgFiles.setName(infoFile.getName());
try {
MetaData meta = InfoReader
.readMeta(infoFile, false);
- source = meta.getSource();
try {
int id = Integer.parseInt(meta.getLuid());
if (id > lastId) {
pgFiles.add(1);
}
- File cover = new File(dir, ".cover.png");
- if (cover.exists()) {
- try {
- InputStream in = new FileInputStream(cover);
- try {
- sourceCovers.put(source, new Image(in));
- } finally {
- in.close();
- }
- } catch (IOException e) {
- Instance.getTraceHandler().error(e);
- }
- }
-
pgFiles.setName(null);
}
pg.done();
return stories;
}
-
- /**
- * Fix the source cover to the given story cover.
- *
- * @param source
- * the source to change
- * @param coverImage
- * the cover image
- */
- void setSourceCover(String source, Image coverImage) {
- if (sourceCovers == null) {
- getStories(null);
- }
-
- sourceCovers.put(source, coverImage);
- File cover = new File(getExpectedDir(source), ".cover");
- try {
- Instance.getCache().saveAsImage(sourceCovers.get(source), cover,
- true);
- } catch (IOException e) {
- Instance.getTraceHandler().error(e);
- sourceCovers.remove(source);
- }
- }
}
* the LUID</li>
* <li>[md5] DELETE_STORY [luid]: delete the story of LUID luid</li>
* <li>[md5] GET_COVER [luid]: return the cover of the story</li>
- * <li>[md5] GET_SOURCE_COVER [source]: return the cover for this source</li>
+ * <li>[md5] GET_CUSTOM_SOURCE_COVER [source]: return the cover for this source</li>
* <li>[md5] SET_SOURCE_COVER [source], [luid]: set the default cover for the
* given source to the cover of the story denoted by luid</li>
* <li>[md5] CHANGE_SOURCE [luid] [new source]: change the source of the story
Instance.getLibrary().delete((String) args[0]);
} else if ("GET_COVER".equals(command)) {
return Instance.getLibrary().getCover((String) args[0]);
- } else if ("GET_SOURCE_COVER".equals(command)) {
- return Instance.getLibrary().getSourceCover((String) args[0]);
+ } else if ("GET_CUSTOM_SOURCE_COVER".equals(command)) {
+ return Instance.getLibrary().getCustomSourceCover((String) args[0]);
} else if ("SET_SOURCE_COVER".equals(command)) {
Instance.getLibrary().setSourceCover((String) args[0],
(String) args[1]);