X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2FDataLoader.java;h=901e8da4c13d8a338cccf2945be17a52adef5abd;hb=d11fb35b34e44744c8b1f9226321f133af4eb151;hp=51855c418d6ea8b7f5973a3dd1c16b6684515e8f;hpb=12443642377be74159578c99af7a9883571e38bf;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/DataLoader.java b/src/be/nikiroo/fanfix/DataLoader.java index 51855c4..901e8da 100644 --- a/src/be/nikiroo/fanfix/DataLoader.java +++ b/src/be/nikiroo/fanfix/DataLoader.java @@ -28,6 +28,7 @@ public class DataLoader { private Downloader downloader; private Downloader downloaderNoCache; private Cache cache; + private boolean offline; /** * Create a new {@link DataLoader} object. @@ -69,6 +70,41 @@ public class DataLoader { downloaderNoCache = downloader; cache = new CacheMemory(); } + + /** + * This {@link Downloader} is forbidden to try and connect to the network. + *

+ * If TRUE, it will only check the cache (even in no-cache mode!). + *

+ * Default is FALSE. + * + * @return TRUE if offline + */ + public boolean isOffline() { + return offline; + } + + /** + * This {@link Downloader} is forbidden to try and connect to the network. + *

+ * If TRUE, it will only check the cache (even in no-cache mode!). + *

+ * Default is FALSE. + * + * @param offline TRUE for offline, FALSE for online + */ + public void setOffline(boolean offline) { + this.offline = offline; + downloader.setOffline(offline); + downloaderNoCache.setOffline(offline); + + // If we don't, we cannot support no-cache using code in OFFLINE mode + if (offline) { + downloaderNoCache.setCache(cache); + } else { + downloaderNoCache.setCache(null); + } + } /** * The traces handler for this {@link Cache}. @@ -95,7 +131,7 @@ public class DataLoader { * @param url * the resource to open * @param support - * the support to use to download the resource + * the support to use to download the resource (can be NULL) * @param stable * TRUE for more stable resources, FALSE when they often change * @@ -149,7 +185,7 @@ public class DataLoader { * is also used for the cache ID if needed (so we can retrieve * the content with this URL if needed) * @param support - * the support to use to download the resource + * the support to use to download the resource (can be NULL) * @param stable * TRUE for more stable resources, FALSE when they often change * @param postParams @@ -229,7 +265,7 @@ public class DataLoader { * @param url * the resource to open * @param support - * the support to use to download the resource + * the support to use to download the resource (can be NULL) * @param stable * TRUE for more stable resources, FALSE when they often change * @@ -238,7 +274,7 @@ public class DataLoader { */ public void refresh(URL url, BasicSupport support, boolean stable) throws IOException { - if (check(url, stable)) { + if (!check(url, stable)) { open(url, url, support, stable, null, null, null).close(); } } @@ -278,11 +314,10 @@ public class DataLoader { throws IOException { String format; if (cover) { - format = Instance.getConfig().getString(Config.IMAGE_FORMAT_COVER) - .toLowerCase(); + format = Instance.getInstance().getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER).toLowerCase(); } else { - format = Instance.getConfig() - .getString(Config.IMAGE_FORMAT_CONTENT).toLowerCase(); + format = Instance.getInstance().getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_CONTENT) + .toLowerCase(); } saveAsImage(img, new File(target.toString() + "." + format), format); }