GUI: detect remote connection failures
[nikiroo-utils.git] / src / be / nikiroo / fanfix / library / CacheLibrary.java
index 38fb7b3193e1b13da59e2abc285d2a6bd0461dfa..62ac9fa77bb4f3f7efd4a463863896961ce7abce 100644 (file)
@@ -45,6 +45,11 @@ public class CacheLibrary extends BasicLibrary {
                return lib.getLibraryName();
        }
 
+       @Override
+       public Status getStatus() {
+               return lib.getStatus();
+       }
+
        @Override
        protected List<MetaData> getMetas(Progress pg) {
                if (pg == null) {
@@ -80,7 +85,7 @@ public class CacheLibrary extends BasicLibrary {
                                pgImport.done();
                                clearCache();
                        } catch (IOException e) {
-                               Instance.syserr(e);
+                               Instance.getTraceHandler().error(e);
                        }
 
                        pgImport.done();
@@ -126,8 +131,22 @@ public class CacheLibrary extends BasicLibrary {
        @Override
        public synchronized Story save(Story story, String luid, Progress pg)
                        throws IOException {
-               story = lib.save(story, luid, pg);
+               Progress pgLib = new Progress();
+               Progress pgCacheLib = new Progress();
+
+               if (pg == null) {
+                       pg = new Progress();
+               }
+
+               pg.setMinMax(0, 2);
+               pg.addProgress(pgLib, 1);
+               pg.addProgress(pgCacheLib, 1);
+
+               story = lib.save(story, luid, pgLib);
+               story = cacheLib.save(story, luid, pgCacheLib);
+
                clearCache();
+
                return story;
        }
 
@@ -153,7 +172,9 @@ public class CacheLibrary extends BasicLibrary {
                pg.addProgress(pgCache, 1);
                pg.addProgress(pgOrig, 1);
 
-               cacheLib.changeSource(luid, newSource, pgCache);
+               if (isCached(luid)) {
+                       cacheLib.changeSource(luid, newSource, pgCache);
+               }
                pgCache.done();
                lib.changeSource(luid, newSource, pgOrig);
                pgOrig.done();
@@ -184,8 +205,10 @@ public class CacheLibrary extends BasicLibrary {
         *             in case of I/O error
         */
        public void clearFromCache(String luid) throws IOException {
-               cacheLib.delete(luid);
-               clearCache();
+               if (isCached(luid)) {
+                       cacheLib.delete(luid);
+                       clearCache();
+               }
        }
 
        // All the following methods are only used by Save and Delete in