+
+ @Override
+ public MetaData getMeta() {
+ return reader.getMeta();
+ }
+
+ @Override
+ public Story getStory(Progress pg) {
+ return reader.getStory(pg);
+ }
+
+ @Override
+ public BasicLibrary getLibrary() {
+ return reader.getLibrary();
+ }
+
+ @Override
+ public void setLibrary(BasicLibrary lib) {
+ reader.setLibrary(lib);
+ }
+
+ @Override
+ public void setMeta(MetaData meta) throws IOException {
+ reader.setMeta(meta);
+ }
+
+ @Override
+ public void setMeta(String luid) throws IOException {
+ reader.setMeta(luid);
+ }
+
+ @Override
+ public void setMeta(URL source, Progress pg) throws IOException {
+ reader.setMeta(source, pg);
+ }
+
+ @Override
+ public void browse(String source) {
+ reader.browse(source);
+ }
+
+ @Override
+ public int getChapter() {
+ return reader.getChapter();
+ }
+
+ @Override
+ public void setChapter(int chapter) {
+ reader.setChapter(chapter);
+ }
+
+ private void init(Reader reader) {
+ this.reader = reader;
+
+ // TODO: traces/errors?
+ Instance.setTraceHandler(null);
+
+ // Add the menus TODO: i18n
+ TMenu fileMenu = addMenu("&File");
+ fileMenu.addItem(MENU_OPEN, "&Open");
+ fileMenu.addItem(MENU_EXPORT, "&Save as...");
+ // TODO: Move to...
+ fileMenu.addSeparator();
+ fileMenu.addItem(MENU_IMPORT_URL, "Import &URL...");
+ fileMenu.addItem(MENU_IMPORT_FILE, "Import &file...");
+ fileMenu.addSeparator();
+ fileMenu.addItem(MENU_EXIT, "E&xit");
+
+ TStatusBar statusBar = fileMenu.newStatusBar("File-management "
+ + "commands (Open, Save, Print, etc.)");
+ // TODO: doesn't actually work:
+ statusBar.addShortcutKeypress(TKeypress.kbF10, TCommand.cmExit, "Exit");
+
+ // TODO: Edit: re-download, delete
+
+ //
+
+ addWindowMenu();
+
+ getBackend().setTitle("Fanfix");
+ }
+
+ @Override
+ protected boolean onMenu(TMenuEvent menu) {
+ // TODO: i18n
+ switch (menu.getId()) {
+ case MENU_EXIT:
+ if (messageBox("Confirmation", "(TODO: i18n) Exit application?",
+ TMessageBox.Type.YESNO).getResult() == TMessageBox.Result.YES) {
+ // exit(false);
+ }
+
+ return true;
+ case MENU_IMPORT_URL:
+ String clipboard = "";
+ try {
+ clipboard = ("" + Toolkit.getDefaultToolkit()
+ .getSystemClipboard().getData(DataFlavor.stringFlavor))
+ .trim();
+ } catch (Exception e) {
+ // No data will be handled
+ }
+
+ if (clipboard == null || !clipboard.startsWith("http")) {
+ clipboard = "";
+ }
+
+ String url = inputBox("Import story", "URL to import", clipboard)
+ .getText();
+
+ if (!imprt(url)) {
+ // TODO: bad import
+ }
+
+ return true;
+ case MENU_IMPORT_FILE:
+ try {
+ String filename = fileOpenBox(".");
+ if (!imprt(filename)) {
+ // TODO: bad import
+ }
+ } catch (IOException e) {
+ // TODO: bad file
+ e.printStackTrace();
+ }
+
+ return true;
+ }
+
+ return super.onMenu(menu);
+ }
+
+ private boolean imprt(String url) {
+ try {
+ reader.getLibrary().imprt(BasicReader.getUrl(url), null);
+ main.refreshStories();
+ return true;
+ } catch (IOException e) {
+ return false;
+ }
+ }