update to master
authorNiki Roo <niki@nikiroo.be>
Tue, 26 May 2020 19:03:01 +0000 (21:03 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 26 May 2020 19:03:01 +0000 (21:03 +0200)
14 files changed:
data/MetaData.java
library/WebLibrary.java
library/WebLibraryServer.java
library/WebLibraryServerHtml.java
library/web/fit_to_width_limited-32x32.png [new file with mode: 0644]
library/web/fit_to_width_limited-64x64.png [new file with mode: 0644]
library/web/index.pre.html [deleted file]
library/web/style.css
library/web/templates/WebLibraryServerTemplates.java
library/web/templates/index.html
library/web/templates/index.post.html [deleted file]
library/web/templates/viewer.image.nolink.html [new file with mode: 0644]
supported/BasicSupport.java
supported/BasicSupport_Deprecated.java

index 1c6ad42838d5541dbd69533b9fb1e2d21d52dd60..5989604ce92f51edef0b631a45dcec1ff0200ab6 100644 (file)
@@ -320,7 +320,7 @@ public class MetaData implements Cloneable, Comparable<MetaData>, Serializable {
         * output type this {@link Story} is in (see {@link SupportType}).
         * <p>
         * It allows you to know where the {@link Story} comes from, and is not
-        * supposed to change.
+        * supposed to change, even when re-imported.
         * <p>
         * It's the user representation of the enum
         * ({@link SupportType#getSourceName()}, not
@@ -337,7 +337,7 @@ public class MetaData implements Cloneable, Comparable<MetaData>, Serializable {
         * output type this {@link Story} is in (see {@link SupportType}).
         * <p>
         * It allows you to know where the {@link Story} comes from, and is not
-        * supposed to change.
+        * supposed to change, even when re-imported.
         * <p>
         * It's the user representation of the enum
         * ({@link SupportType#getSourceName()}, not
@@ -353,8 +353,8 @@ public class MetaData implements Cloneable, Comparable<MetaData>, Serializable {
        /**
         * The output type this {@link Story} is in (see {@link SupportType}).
         * <p>
-        * It allows you to know where the {@link Story} comes from, and is not
-        * supposed to change.
+        * It allows you to know where the {@link Story} comes from, and is supposed
+        * to only change when it is imported anew.
         * <p>
         * It's the direct representation of the enum
         * ({@link SupportType#toString()}, not
@@ -369,8 +369,8 @@ public class MetaData implements Cloneable, Comparable<MetaData>, Serializable {
        /**
         * The output type this {@link Story} is in (see {@link SupportType}).
         * <p>
-        * It allows you to know where the {@link Story} comes from, and is not
-        * supposed to change.
+        * It allows you to know where the {@link Story} comes from, and is supposed
+        * to only change when it is imported anew.
         * <p>
         * It's the direct representation of the enum
         * ({@link SupportType#toString()}, not
index 9af38e2b6bd1c7ccb565ca6f244e31ef42f40746..7381ae368661023aa3ac2a23c643d6f4461ac658 100644 (file)
@@ -173,12 +173,12 @@ public class WebLibrary extends BasicLibrary {
                InputStream in = post(WebLibraryUrls.getStoryUrlCover(luid));
                try {
                        Image img = new Image(in);
-                       if (img.getSize() > 0) {
+                       if (img.getSize() == 0) {
                                img.close();
-                               return img;
+                               img = null;
                        }
 
-                       return null;
+                       return img;
                } finally {
                        in.close();
                }
@@ -189,12 +189,12 @@ public class WebLibrary extends BasicLibrary {
                InputStream in = post(WebLibraryUrls.getCoverUrlSource(source));
                try {
                        Image img = new Image(in);
-                       if (img.getSize() > 0) {
+                       if (img.getSize() == 0) {
                                img.close();
-                               return img;
+                               img = null;
                        }
 
-                       return null;
+                       return img;
                } finally {
                        in.close();
                }
@@ -205,12 +205,12 @@ public class WebLibrary extends BasicLibrary {
                InputStream in = post(WebLibraryUrls.getCoverUrlAuthor(author));
                try {
                        Image img = new Image(in);
-                       if (img.getSize() > 0) {
+                       if (img.getSize() == 0) {
                                img.close();
-                               return img;
+                               img = null;
                        }
 
-                       return null;
+                       return img;
                } finally {
                        in.close();
                }
index 22f36e91f5729a7bfef72fe9c98d2a7fa157a6ec..56d78ed4de20b5a52583af21105043a07cc8e89f 100644 (file)
@@ -217,9 +217,8 @@ public class WebLibraryServer extends WebLibraryServerHtml {
                                jsons.add(JsonIO.toJson(meta));
                        }
 
-                       return newInputStreamResponse("application/json",
-                                       new ByteArrayInputStream(
-                                                       new JSONArray(jsons).toString().getBytes()));
+                       return NanoHTTPD.newFixedLengthResponse(Status.OK,
+                                       "application/json", new JSONArray(jsons).toString());
                }
 
                return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST,
index d5ba533f27b5ac746c631ccb2457ea3c3aa3649f..63c50c54df64c4ad5ed5810d030a5783e30ad12e 100644 (file)
@@ -247,6 +247,12 @@ abstract class WebLibraryServerHtml implements Runnable {
                                                                        mimeType = "text/html";
                                                                } else if (uri.endsWith(".js")) {
                                                                        mimeType = "text/javascript";
+                                                               } else if (uri.endsWith(".png")) {
+                                                                       mimeType = "image/png";
+                                                               } else if (uri.endsWith(".ico")) {
+                                                                       mimeType = "image/x-icon";
+                                                               } else if (uri.endsWith(".java")) {
+                                                                       mimeType = "text/plain";
                                                                }
                                                                rep = newChunkedResponse(Status.OK, mimeType,
                                                                                in);
@@ -326,7 +332,8 @@ abstract class WebLibraryServerHtml implements Runnable {
                content.add(templates.login(uri));
 
                return NanoHTTPD.newChunkedResponse(Status.FORBIDDEN,
-                               NanoHTTPD.MIME_HTML, templates.index(true, content).read());
+                               NanoHTTPD.MIME_HTML,
+                               templates.index(true, false, content).read());
        }
 
        private Response root(IHTTPSession session, Map<String, String> cookies,
@@ -469,7 +476,7 @@ abstract class WebLibraryServerHtml implements Runnable {
                booklines.add(0, templates.browser(browser, filter, selects));
 
                return newInputStreamResponse(NanoHTTPD.MIME_HTML,
-                               templates.index(true, booklines).read());
+                               templates.index(true, false, booklines).read());
        }
 
        private Response getViewer(Map<String, String> cookies, String uri,
@@ -546,6 +553,7 @@ abstract class WebLibraryServerHtml implements Runnable {
                        boolean disabledRight = false;
                        boolean disabledZoomReal = false;
                        boolean disabledZoomWidth = false;
+                       boolean disabledZoomWidthLimited = false;
                        boolean disabledZoomHeight = false;
 
                        Template viewerItem = null;
@@ -623,27 +631,36 @@ abstract class WebLibraryServerHtml implements Runnable {
                                }
 
                                if (para.getType() == ParagraphType.IMAGE) {
-                                       String zoomStyle = "max-width: 100%;";
-                                       disabledZoomWidth = true;
+                                       // default values:
+                                       String zoomStyle = "max-width: 800px;";
+                                       disabledZoomWidthLimited = true;
+
                                        String zoomOption = cookies.get("zoom");
                                        if (zoomOption != null && !zoomOption.isEmpty()) {
                                                if (zoomOption.equals("real")) {
                                                        zoomStyle = "";
-                                                       disabledZoomWidth = false;
+                                                       disabledZoomWidthLimited = false;
                                                        disabledZoomReal = true;
+                                               } else if (zoomOption.equals("widthlimited")) {
+                                                       // default
                                                } else if (zoomOption.equals("width")) {
                                                        zoomStyle = "max-width: 100%;";
+                                                       disabledZoomWidthLimited = false;
+                                                       disabledZoomWidth = true;
                                                } else if (zoomOption.equals("height")) {
                                                        // see height of navbar + optionbar
                                                        zoomStyle = "max-height: calc(100% - 128px);";
-                                                       disabledZoomWidth = false;
+                                                       disabledZoomWidthLimited = false;
                                                        disabledZoomHeight = true;
                                                }
                                        }
 
-                                       viewerItem = templates.viewerImage(WebLibraryUrls
-                                                       .getStoryUrl(luid, chapter, paragraph), next,
-                                                       zoomStyle);
+                                       viewerItem = templates.viewerImage(
+                                                       WebLibraryUrls.getStoryUrl(luid, chapter,
+                                                                       paragraph), //
+                                                       disabledRight ? null : next, //
+                                                       zoomStyle //
+                                       );
                                } else {
                                        viewerItem = templates.viewerText(null,
                                                        new TextOutput(false).convert(para));
@@ -708,25 +725,29 @@ abstract class WebLibraryServerHtml implements Runnable {
                                buttons.add(templates.viewerOptionbarButton( //
                                                "1:1", uri + "?optionName=zoom&optionValue=real",
                                                "zoomreal", disabledZoomReal));
+                               buttons.add(templates.viewerOptionbarButton( //
+                                               "]width[",
+                                               uri + "?optionName=zoom&optionValue=widthlimited",
+                                               "zoomwidthlimited", disabledZoomWidthLimited));
                                buttons.add(templates.viewerOptionbarButton( //
                                                "Width", uri + "?optionName=zoom&optionValue=width",
                                                "zoomwidth", disabledZoomWidth));
                                buttons.add(templates.viewerOptionbarButton( //
                                                "Height", uri + "?optionName=zoom&optionValue=height",
-                                               "zoomHeight", disabledZoomHeight));
+                                               "zoomheight", disabledZoomHeight));
                        }
 
                        // Optionbar
 
                        Template optionbar = templates.viewerOptionbar( //
-                                       (paragraph > 0) ? 4 : 1, //
+                                       (paragraph > 0) ? 5 : 1, //
                                        buttons //
                        );
 
                        // Full content
 
                        return newInputStreamResponse(NanoHTTPD.MIME_HTML, //
-                                       templates.index(false, Arrays.asList( //
+                                       templates.index(false, (paragraph > 0), Arrays.asList( //
                                                        navbar, //
                                                        viewerItem, //
                                                        optionbar //
@@ -738,7 +759,7 @@ abstract class WebLibraryServerHtml implements Runnable {
                                        NanoHTTPD.MIME_PLAINTEXT, "Error when processing request");
                }
        }
-
+       
        protected Response newInputStreamResponse(String mimeType, InputStream in) {
                if (in == null) {
                        return NanoHTTPD.newFixedLengthResponse(Status.NO_CONTENT, "",
diff --git a/library/web/fit_to_width_limited-32x32.png b/library/web/fit_to_width_limited-32x32.png
new file mode 100644 (file)
index 0000000..4971046
Binary files /dev/null and b/library/web/fit_to_width_limited-32x32.png differ
diff --git a/library/web/fit_to_width_limited-64x64.png b/library/web/fit_to_width_limited-64x64.png
new file mode 100644 (file)
index 0000000..bd97942
Binary files /dev/null and b/library/web/fit_to_width_limited-64x64.png differ
diff --git a/library/web/index.pre.html b/library/web/index.pre.html
deleted file mode 100644 (file)
index 1e626ab..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<!--
-       Copyright 2020 David ROULET
-       
-       This file is part of fanfix.
-       
-       fanfix is free software: you can redistribute it and/or modify
-       it under the terms of the GNU Affero General Public License as published by
-       the Free Software Foundation, either version 3 of the License, or
-       (at your option) any later version.
-       
-       fanfix is distributed in the hope that it will be useful,
-       but WITHOUT ANY WARRANTY; without even the implied warranty of
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-       GNU Affero General Public License for more details.
-       
-       You should have received a copy of the GNU Affero General Public License
-       along with fanfix.  If not, see <https://www.gnu.org/licenses/>.
-       ___________________________________________________________________________
-
-       This website was coded by:
-                       A kangaroo.
-                                                  _  _
-                                                 (\\( \
-                                                  `.\-.)
-                              _...._            _,-"   `-.
-\                           ,"      `-._.- -.,-"       .  \
- \`.                      ,"                               `.
-  \ `-...__              /                           .   .:  y
-   `._     ``-...__     /                           ,"```-._/
-      `-._         ```-"                      |    /_          //
-          `.._                   _            ;   <_ \        //
-              ``-.___             `.           `-._ \ \      //
-                     `- <           `.     (\ _/)/ `.\/     //
-                         \            \     `       ^^^^^^^^^
-       ___________________________________________________________________________
-       
-       -->
-       <meta http-equiv="content-type" content="text/html; charset=utf-8">
-       <meta name="viewport" content="width=device-width, initial-scale=1.0">
-       <title>${title}</title>
-       <link rel="stylesheet" type="text/css" href="/style.css" />
-       <link rel="icon" type="image/x-icon" href="/${favicon}" />
-</head>
-<body>
-       <div class='main'>
index bb91002920e94bd593d125ff8abe26c714f4c5db..5a4c51ff9d150109e261ec7e55be23f11367fc04 100644 (file)
@@ -227,6 +227,7 @@ h3 {
 
 .bar.optionbar.s1 { padding-left: calc(50% - (1 * (64px + 5px) / 2)); }
 .bar.optionbar.s4 { padding-left: calc(50% - (4 * (64px + 5px) / 2)); }
+.bar.optionbar.s5 { padding-left: calc(50% - (5 * (64px + 5px) / 2)); }
 
 .bar.optionbar {
        bottom: 0;
@@ -258,10 +259,11 @@ h3 {
 .bar .button.next     { color: transparent; background-image: url('/arrow_right-32x32.png');        }
 .bar .button.last     { color: transparent; background-image: url('/arrow_double_right-32x32.png'); }
 
-.bar .button.back       { color: transparent; background-image: url('/back-32x32.png');          }
-.bar .button.zoomreal   { color: transparent; background-image: url('/actual_size-32x32.png');   }
-.bar .button.zoomwidth  { color: transparent; background-image: url('/fit_to_width-32x32.png');  }
-.bar .button.zoomheight { color: transparent; background-image: url('/fit_to_height-32x32.png'); }
+.bar .button.back             { color: transparent; background-image: url('/back-32x32.png');                 }
+.bar .button.zoomreal         { color: transparent; background-image: url('/actual_size-32x32.png');          }
+.bar .button.zoomwidth        { color: transparent; background-image: url('/fit_to_width-32x32.png');         }
+.bar .button.zoomwidthlimited { color: transparent; background-image: url('/fit_to_width_limited-32x32.png'); }
+.bar .button.zoomheight       { color: transparent; background-image: url('/fit_to_height-32x32.png');        }
 
 .viewer {
        padding-top: 64px;
@@ -316,18 +318,19 @@ a.viewer.link:hover {
        color: #AAA391;
 }
 
-@media(min-width: 800px) {
-        .main {
+@media(min-width: 800px) { 
+        .main:not(.fullscreen) {
                max-width: 800px;
         }
         
-       .bar.navbar       { padding-left: calc(400px - (5 * (64px + 5px) / 2)); }
+       .main:not(.fullscreen) .bar.navbar       { padding-left: calc(400px - (5 * (64px + 5px) / 2)); }
        
-       .bar.optionbar.s1 { padding-left: calc(400px - (1 * (64px + 5px) / 2)); }
-       .bar.optionbar.s4 { padding-left: calc(400px - (4 * (64px + 5px) / 2)); }
+       .main:not(.fullscreen) .bar.optionbar.s1 { padding-left: calc(400px - (1 * (64px + 5px) / 2)); }
+       .main:not(.fullscreen) .bar.optionbar.s4 { padding-left: calc(400px - (4 * (64px + 5px) / 2)); }
+       .main:not(.fullscreen) .bar.optionbar.s5 { padding-left: calc(400px - (5 * (64px + 5px) / 2)); }
        
-       .desc { flex-direction: row; }
-       .desc .cover img {
+       .main:not(.fullscreen) .desc { flex-direction: row; }
+       .main:not(.fullscreen) .desc .cover img {
                width: 200px;
                padding-right: 10px;
        }
index 59e7020c62fa6254ff3c20da3e0a4aa939031b22..25644446db3bdc5ada11122d07e3295bd3efc663 100644 (file)
@@ -44,7 +44,8 @@ public class WebLibraryServerTemplates {
                ;
        }
 
-       public Template index(boolean banner, List<Template> content) {
+       public Template index(boolean banner, boolean fullscreen,
+                       List<Template> content) {
                String favicon = "favicon.ico";
                String icon = Instance.getInstance().getUiConfig()
                                .getString(UiConfig.PROGRAM_ICON);
@@ -55,6 +56,7 @@ public class WebLibraryServerTemplates {
                Template index = new Template(getClass(), "index.html") //
                                .set("title", "Fanfix") //
                                .set("favicon", favicon) //
+                               .set("mainClass", fullscreen ? "fullscreen" : "") //
                                .set("content", content) //
                ;
 
@@ -137,11 +139,13 @@ public class WebLibraryServerTemplates {
                ;
        }
 
+       // href NULL means no forward link
        public Template viewerImage(String src, String href, String zoomStyle) {
-               return new Template(getClass(), "viewer.image.html") //
-                               .set("src", src) //
-                               .set("href", href) //
-                               .set("zoomStyle", zoomStyle) //
+               return new Template(getClass(),
+                               href == null ? "viewer.image.nolink.html" : "viewer.image.html") //
+                                               .set("src", src) //
+                                               .set("href", href) //
+                                               .set("zoomStyle", zoomStyle) //
                ;
        }
 
@@ -180,7 +184,7 @@ public class WebLibraryServerTemplates {
                ;
        }
 
-       // supported numberOfButtons = 4 or 1 or the moment
+       // supported numberOfButtons = 5 or 4 or 1 or the moment
        public Template viewerOptionbar(int numberOfButtons,
                        List<Template> buttons) {
                return new Template(getClass(), "viewer.optionbar.html") //
index 6f3934e285f2d092d5054e6b013078b4ab6f41a0..4edc0b0afbc31e9dad4f7367248f7cd6b2daba34 100644 (file)
@@ -45,6 +45,6 @@
        <link rel='icon' type='image/x-icon' href='/${favicon}' />
 </head>
 <body>
-       <div class='main'>
+       <div class='main ${mainClass}'>
 ${banner}${content}    </div>
 </body>
diff --git a/library/web/templates/index.post.html b/library/web/templates/index.post.html
deleted file mode 100644 (file)
index 52ba19e..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-       </div>
-</body>
\ No newline at end of file
diff --git a/library/web/templates/viewer.image.nolink.html b/library/web/templates/viewer.image.nolink.html
new file mode 100644 (file)
index 0000000..64483c9
--- /dev/null
@@ -0,0 +1,5 @@
+               <div 
+                 class='viewer' 
+                 oncontextmenu='document.getElementById("previous").click(); return false;'>
+                       <img class='viewer img' style='${zoomStyle}' src='${src}'/>
+               </div>
index bcfcca1bdbb16cfd3bd8849e8fdb2bfb55a22de0..ff9ecaf9be3cc80666d964ee48da375d1307bae6 100644 (file)
@@ -276,8 +276,10 @@ public abstract class BasicSupport {
                MetaData meta = getMeta();
                meta.setType(getType().toString());
                meta.setSource(getType().getSourceName());
-               meta.setPublisher(getType().getSourceName());
-               
+               if (meta.getPublisher() == null) {
+                       meta.setPublisher(getType().getSourceName());
+               }
+
                if (meta.getCreationDate() == null
                                || meta.getCreationDate().trim().isEmpty()) {
                        meta.setCreationDate(bsHelper
index 9aac6d5c61b713a4641fc251796b981e48d3a2ec..512aabf390d8cf9a9aa07fcf692a491249510d2e 100644 (file)
@@ -207,7 +207,9 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                        MetaData meta = getMeta(url, getInput());
                        meta.setType(getType().toString());
                        meta.setSource(getType().getSourceName());
-                       meta.setPublisher(getType().getSourceName());
+                       if (meta.getPublisher() == null) {
+                               meta.setPublisher(getType().getSourceName());
+                       }
                        
                        if (meta.getCreationDate() == null
                                        || meta.getCreationDate().trim().isEmpty()) {