X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FLocalReader.java;h=6c6150318b38917958579a4fbaf87a5f1489ff05;hb=6cac0e45756735a3567822f45a7cc3e6bef61fd5;hp=b43473707796f819259df4bf320198d09e749dbd;hpb=9843a5e5c44825ac404f45ddccd6f63e554567a4;p=fanfix.git
diff --git a/src/be/nikiroo/fanfix/reader/LocalReader.java b/src/be/nikiroo/fanfix/reader/LocalReader.java
index b434737..6c61503 100644
--- a/src/be/nikiroo/fanfix/reader/LocalReader.java
+++ b/src/be/nikiroo/fanfix/reader/LocalReader.java
@@ -1,20 +1,38 @@
package be.nikiroo.fanfix.reader;
+import java.awt.Desktop;
import java.awt.EventQueue;
import java.io.File;
import java.io.IOException;
+import java.net.URISyntaxException;
+
+import javax.swing.JEditorPane;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.Library;
+import be.nikiroo.fanfix.VersionCheck;
import be.nikiroo.fanfix.bundles.UiConfig;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.output.BasicOutput.OutputType;
import be.nikiroo.utils.Progress;
+import be.nikiroo.utils.Version;
+import be.nikiroo.utils.ui.UIUtils;
class LocalReader extends BasicReader {
- private Library lib;
+ static private boolean nativeLookLoaded;
+
+ private Library localLibrary;
public LocalReader() throws IOException {
+ if (!nativeLookLoaded) {
+ UIUtils.setLookAndFeel();
+ nativeLookLoaded = true;
+ }
+
File dir = Instance.getReaderDir();
dir.mkdirs();
if (!dir.exists()) {
@@ -22,29 +40,48 @@ class LocalReader extends BasicReader {
"Cannote create cache directory for local reader: " + dir);
}
- // TODO: can throw an exception, manage that (convert to IOEx ?)
- OutputType text = OutputType.valueOfNullOkUC(Instance.getUiConfig()
- .getString(UiConfig.LOCAL_READER_NON_IMAGES_DOCUMENT_TYPE));
- if (text == null) {
- text = OutputType.HTML;
- }
+ OutputType text = null;
+ OutputType images = null;
- OutputType images = OutputType.valueOfNullOkUC(Instance.getUiConfig()
- .getString(UiConfig.LOCAL_READER_IMAGES_DOCUMENT_TYPE));
- if (images == null) {
- images = OutputType.CBZ;
+ try {
+ text = OutputType.valueOfNullOkUC(Instance.getUiConfig().getString(
+ UiConfig.NON_IMAGES_DOCUMENT_TYPE));
+ if (text == null) {
+ text = OutputType.HTML;
+ }
+
+ images = OutputType.valueOfNullOkUC(Instance.getUiConfig()
+ .getString(UiConfig.IMAGES_DOCUMENT_TYPE));
+ if (images == null) {
+ images = OutputType.CBZ;
+ }
+ } catch (Exception e) {
+ UiConfig key = (text == null) ? UiConfig.NON_IMAGES_DOCUMENT_TYPE
+ : UiConfig.IMAGES_DOCUMENT_TYPE;
+ String value = Instance.getUiConfig().getString(key);
+
+ throw new IOException(
+ String.format(
+ "The configuration option %s is not valid: %s",
+ key, value), e);
}
- //
- lib = new Library(dir, text, images);
+ localLibrary = new Library(dir, text, images);
}
@Override
public void read() throws IOException {
+ if (getStory() == null) {
+ throw new IOException("No story to read");
+ }
+
+ open(getStory().getMeta().getLuid(), null);
}
@Override
- public void read(int chapter) {
+ public void read(int chapter) throws IOException {
+ // TODO: show a special page?
+ read();
}
/**
@@ -70,7 +107,7 @@ class LocalReader extends BasicReader {
try {
Story story = Instance.getLibrary().getStory(luid, pgGetStory);
if (story != null) {
- story = lib.save(story, luid, pgSave);
+ story = localLibrary.save(story, luid, pgSave);
} else {
throw new IOException("Cannot find story in Library: " + luid);
}
@@ -81,29 +118,6 @@ class LocalReader extends BasicReader {
}
}
- /**
- * Get the target file related to this {@link Story}.
- *
- * @param luid
- * the LUID of the {@link Story}
- * @param pg
- * the optional progress reporter
- *
- * @return the target file
- *
- * @throws IOException
- * in case of I/O error
- */
- public File getTarget(String luid, Progress pg) throws IOException {
- File file = lib.getFile(luid);
- if (file == null) {
- imprt(luid, pg);
- file = lib.getFile(luid);
- }
-
- return file;
- }
-
/**
* Check if the {@link Story} denoted by this Library UID is present in the
* {@link LocalReader} cache.
@@ -114,26 +128,97 @@ class LocalReader extends BasicReader {
* @return TRUE if it is
*/
public boolean isCached(String luid) {
- return lib.getInfo(luid) != null;
+ return localLibrary.getInfo(luid) != null;
}
@Override
- public void start(String type) {
+ public void browse(String type) {
+ // TODO: improve presentation of update message
+ final VersionCheck updates = VersionCheck.check();
+ StringBuilder builder = new StringBuilder();
+
+ final JEditorPane updateMessage = new JEditorPane("text/html", "");
+ if (updates.isNewVersionAvailable()) {
+ builder.append("A new version of the program is available at https://github.com/nikiroo/fanfix/releases");
+ builder.append("
");
+ builder.append("
");
+ for (Version v : updates.getNewer()) {
+ builder.append("\tVersion " + v + "");
+ builder.append("
");
+ builder.append("