import java.util.ArrayList;
import java.util.List;
+import javax.net.ssl.SSLException;
+
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.bundles.StringId;
import be.nikiroo.fanfix.data.Chapter;
-import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.library.BasicLibrary;
import be.nikiroo.fanfix.library.CacheLibrary;
exitCode = 10;
break;
}
- BasicReader.getReader().browse(null);
+ try {
+ BasicReader.getReader().browse(null);
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ exitCode = 66;
+ }
break;
case SERVER:
key = Instance.getConfig().getString(Config.SERVER_KEY);
exitCode = 15;
break;
}
+ try {
+ new RemoteLibrary(key, host, port).exit();
+ } catch (SSLException e) {
+ Instance.getTraceHandler().error(
+ "Bad access key for remote library");
+ exitCode = 43;
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ exitCode = 44;
+ }
- new RemoteLibrary(key, host, port).exit();
break;
case REMOTE:
exitCode = 255; // should not be reachable (REMOTE -> START)
* @return the exit return code (0 = success)
*/
private static int list(String source) {
- List<MetaData> stories;
- stories = BasicReader.getReader().getLibrary().getListBySource(source);
-
- for (MetaData story : stories) {
- String author = "";
- if (story.getAuthor() != null && !story.getAuthor().isEmpty()) {
- author = " (" + story.getAuthor() + ")";
- }
-
- System.out.println(story.getLuid() + ": " + story.getTitle()
- + author);
+ BasicReader.setDefaultReaderType(ReaderType.CLI);
+ try {
+ BasicReader.getReader().browse(source);
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ return 66;
}
+
return 0;
}
* @author niki
*/
public enum Status {
- /** The library is ready. */
- READY,
+ /** The library is ready and r/w. */
+ READ_WRITE,
+ /** The library is ready, but read-only. */
+ READ_ONLY,
/** The library is invalid (not correctly set up). */
INVALID,
/** You are not allowed to access this library. */
UNAUTHORIZED,
/** The library is currently out of commission. */
- UNAVAILABLE,
+ UNAVAILABLE;
+
+ /**
+ * The library is available (you can query it).
+ * <p>
+ * It does <b>not</b> specify if it is read-only or not.
+ *
+ * @return TRUE if it is
+ */
+ public boolean isReady() {
+ return (this == READ_WRITE || this == READ_ONLY);
+ }
+
+ /**
+ * This library can be modified (= you are allowed to modify it).
+ *
+ * @return TRUE if it is
+ */
+ public boolean isWritable() {
+ return (this == READ_WRITE);
+ }
}
/**
* @return the current status
*/
public Status getStatus() {
- return Status.READY;
+ return Status.READ_WRITE;
}
/**
* the optional {@link Progress}
*
* @return the corresponding {@link Story}
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public abstract File getFile(String luid, Progress pg);
+ public abstract File getFile(String luid, Progress pg) throws IOException;
/**
* Return the cover image associated to this story.
* the Library UID of the story
*
* @return the cover image
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public abstract Image getCover(String luid);
+ public abstract Image getCover(String luid) throws IOException;
/**
* Return the cover image associated to this source.
* the source
*
* @return the cover image or NULL
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public Image getSourceCover(String source) {
+ public Image getSourceCover(String source) throws IOException {
Image custom = getCustomSourceCover(source);
if (custom != null) {
return custom;
* the author
*
* @return the cover image or NULL
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public Image getAuthorCover(String author) {
+ public Image getAuthorCover(String author) throws IOException {
Image custom = getCustomAuthorCover(author);
if (custom != null) {
return custom;
* the source to look for
*
* @return the custom cover or NULL if none
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public Image getCustomSourceCover(@SuppressWarnings("unused") String source) {
+ public Image getCustomSourceCover(@SuppressWarnings("unused") String source)
+ throws IOException {
return null;
}
* the author to look for
*
* @return the custom cover or NULL if none
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public Image getCustomAuthorCover(@SuppressWarnings("unused") String author) {
+ public Image getCustomAuthorCover(@SuppressWarnings("unused") String author)
+ throws IOException {
return null;
}
* the source to change
* @param luid
* the story LUID
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public abstract void setSourceCover(String source, String luid);
+ public abstract void setSourceCover(String source, String luid)
+ throws IOException;
/**
* Set the author cover to the given story cover.
* the author to change
* @param luid
* the story LUID
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public abstract void setAuthorCover(String author, String luid);
+ public abstract void setAuthorCover(String author, String luid)
+ throws IOException;
/**
* Return the list of stories (represented by their {@link MetaData}, which
* the optional {@link Progress}
*
* @return the list (can be empty but not NULL)
+ *
+ * @throws IOException
+ * in case of IOException
*/
- protected abstract List<MetaData> getMetas(Progress pg);
+ protected abstract List<MetaData> getMetas(Progress pg) throws IOException;
/**
* Invalidate the {@link Story} cache (when the content should be re-read
*
* @param meta
* the {@link Story} to clear from the cache
+ *
+ * @throws IOException
+ * in case of IOException
*/
- protected abstract void updateInfo(MetaData meta);
+ protected abstract void updateInfo(MetaData meta) throws IOException;
/**
* Return the next LUID that can be used.
*
* @param pg
* the optional progress reporter
+ *
+ * @throws IOException
+ * in case of IOException
*/
public void refresh(Progress pg) {
- getMetas(pg);
+ try {
+ getMetas(pg);
+ } catch (IOException e) {
+ // We will let it fail later
+ }
}
/**
* List all the known types (sources) of stories.
*
* @return the sources
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public synchronized List<String> getSources() {
+ public synchronized List<String> getSources() throws IOException {
List<String> list = new ArrayList<String>();
for (MetaData meta : getMetas(null)) {
String storySource = meta.getSource();
* </ul>
*
* @return the grouped list
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public synchronized Map<String, List<String>> getSourcesGrouped() {
+ public synchronized Map<String, List<String>> getSourcesGrouped()
+ throws IOException {
Map<String, List<String>> map = new TreeMap<String, List<String>>();
for (String source : getSources()) {
String name;
* List all the known authors of stories.
*
* @return the authors
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public synchronized List<String> getAuthors() {
+ public synchronized List<String> getAuthors() throws IOException {
List<String> list = new ArrayList<String>();
for (MetaData meta : getMetas(null)) {
String storyAuthor = meta.getAuthor();
* <tt>0-9</tt>, which may only be present or not).
*
* @return the authors' names, grouped by letter(s)
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public Map<String, List<String>> getAuthorsGrouped() {
+ public Map<String, List<String>> getAuthorsGrouped() throws IOException {
int MAX = 20;
Map<String, List<String>> groups = new TreeMap<String, List<String>>();
* @param car
* the starting character, <tt>*</tt>, <tt>0</tt> or a capital
* letter
+ *
* @return the authors that fulfill the starting letter
+ *
+ * @throws IOException
+ * in case of IOException
*/
- private List<String> getAuthorsGroup(List<String> authors, char car) {
+ private List<String> getAuthorsGroup(List<String> authors, char car)
+ throws IOException {
List<String> accepted = new ArrayList<String>();
for (String author : authors) {
char first = '*';
* Cover images <b>MAYBE</b> not included.
*
* @return the stories
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public synchronized List<MetaData> getList() {
+ public synchronized List<MetaData> getList() throws IOException {
return getMetas(null);
}
* the type of story to retrieve, or NULL for all
*
* @return the stories
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public synchronized List<MetaData> getListBySource(String type) {
+ public synchronized List<MetaData> getListBySource(String type)
+ throws IOException {
List<MetaData> list = new ArrayList<MetaData>();
for (MetaData meta : getMetas(null)) {
String storyType = meta.getSource();
* the author of the stories to retrieve, or NULL for all
*
* @return the stories
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public synchronized List<MetaData> getListByAuthor(String author) {
+ public synchronized List<MetaData> getListByAuthor(String author)
+ throws IOException {
List<MetaData> list = new ArrayList<MetaData>();
for (MetaData meta : getMetas(null)) {
String storyAuthor = meta.getAuthor();
* the Library UID of the story
*
* @return the corresponding {@link Story}
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public synchronized MetaData getInfo(String luid) {
+ public synchronized MetaData getInfo(String luid) throws IOException {
if (luid != null) {
for (MetaData meta : getMetas(null)) {
if (luid.equals(meta.getLuid())) {
* the optional progress reporter
*
* @return the corresponding {@link Story} or NULL if not found
+ *
+ * @throws IOException
+ * in case of IOException
*/
- public synchronized Story getStory(String luid, Progress pg) {
+ public synchronized Story getStory(String luid, Progress pg)
+ throws IOException {
Progress pgMetas = new Progress();
Progress pgStory = new Progress();
if (pg != null) {
* the optional progress reporter
*
* @return the corresponding {@link Story} or NULL if not found
+ *
+ * @throws IOException
+ * in case of IOException
*/
public synchronized Story getStory(String luid,
- @SuppressWarnings("javadoc") MetaData meta, Progress pg) {
+ @SuppressWarnings("javadoc") MetaData meta, Progress pg)
+ throws IOException {
if (pg == null) {
pg = new Progress();
}
@Override
- protected List<MetaData> getMetas(Progress pg) {
+ protected List<MetaData> getMetas(Progress pg) throws IOException {
if (pg == null) {
pg = new Progress();
}
}
@Override
- public synchronized MetaData getInfo(String luid) {
+ public synchronized MetaData getInfo(String luid) throws IOException {
MetaData info = cacheLib.getInfo(luid);
if (info == null) {
info = lib.getInfo(luid);
}
@Override
- public synchronized Story getStory(String luid, MetaData meta, Progress pg) {
+ public synchronized Story getStory(String luid, MetaData meta, Progress pg)
+ throws IOException {
if (pg == null) {
pg = new Progress();
}
}
@Override
- public synchronized File getFile(final String luid, Progress pg) {
+ public synchronized File getFile(final String luid, Progress pg)
+ throws IOException {
if (pg == null) {
pg = new Progress();
}
}
@Override
- public Image getCover(final String luid) {
+ public Image getCover(final String luid) throws IOException {
if (isCached(luid)) {
return cacheLib.getCover(luid);
}
}
@Override
- public Image getSourceCover(String source) {
+ public Image getSourceCover(String source) throws IOException {
Image custom = getCustomSourceCover(source);
if (custom != null) {
return custom;
}
@Override
- public Image getAuthorCover(String author) {
+ public Image getAuthorCover(String author) throws IOException {
Image custom = getCustomAuthorCover(author);
if (custom != null) {
return custom;
}
@Override
- public Image getCustomSourceCover(String source) {
+ public Image getCustomSourceCover(String source) throws IOException {
Image custom = cacheLib.getCustomSourceCover(source);
if (custom == null) {
custom = lib.getCustomSourceCover(source);
}
@Override
- public Image getCustomAuthorCover(String author) {
+ public Image getCustomAuthorCover(String author) throws IOException {
Image custom = cacheLib.getCustomAuthorCover(author);
if (custom == null) {
custom = lib.getCustomAuthorCover(author);
}
@Override
- public void setSourceCover(String source, String luid) {
+ public void setSourceCover(String source, String luid) throws IOException {
lib.setSourceCover(source, luid);
cacheLib.setSourceCover(source, getCover(luid));
}
@Override
- public void setAuthorCover(String author, String luid) {
+ public void setAuthorCover(String author, String luid) throws IOException {
lib.setAuthorCover(author, luid);
cacheLib.setAuthorCover(author, getCover(luid));
}
@Override
- protected void updateInfo(MetaData meta) {
+ protected void updateInfo(MetaData meta) throws IOException {
if (meta != null && metas != null) {
for (int i = 0; i < metas.size(); i++) {
if (metas.get(i).getLuid().equals(meta.getLuid())) {
* @return TRUE if it is
*/
public boolean isCached(String luid) {
- return cacheLib.getInfo(luid) != null;
+ try {
+ return cacheLib.getInfo(luid) != null;
+ } catch (IOException e) {
+ return false;
+ }
}
/**
}
@Override
- public File getFile(String luid, Progress pg) {
+ public File getFile(String luid, Progress pg) throws IOException {
Instance.getTraceHandler().trace(
this.getClass().getSimpleName() + ": get file for " + luid);
}
@Override
- public Image getCover(String luid) {
+ public Image getCover(String luid) throws IOException {
MetaData meta = getInfo(luid);
if (meta != null) {
if (meta.getCover() != null) {
}
@Override
- public void setSourceCover(String source, String luid) {
+ public void setSourceCover(String source, String luid) throws IOException {
setSourceCover(source, getCover(luid));
}
@Override
- public void setAuthorCover(String author, String luid) {
+ public void setAuthorCover(String author, String luid) throws IOException {
setAuthorCover(author, getCover(luid));
}
// informative only (server will make the actual checks)
private boolean rw;
- // TODO: error handling is not up to par!
-
/**
* Create a {@link RemoteLibrary} linked to the given server.
* <p>
@Override
public String getLibraryName() {
- return host + ":" + port;
+ return (rw ? "[READ-ONLY] " : "") + host + ":" + port;
}
@Override
if ("r/w".equals(rep)) {
rw = true;
- result[0] = Status.READY;
+ result[0] = Status.READ_WRITE;
} else if ("r/o".equals(rep)) {
rw = false;
- result[0] = Status.READY;
+ result[0] = Status.READ_ONLY;
} else {
result[0] = Status.UNAUTHORIZED;
}
}
@Override
- public Image getCover(final String luid) {
+ public Image getCover(final String luid) throws IOException {
final Image[] result = new Image[1];
connectRemoteAction(new RemoteAction() {
}
@Override
- public Image getCustomSourceCover(final String source) {
+ public Image getCustomSourceCover(final String source) throws IOException {
return getCustomCover(source, "SOURCE");
}
@Override
- public Image getCustomAuthorCover(final String author) {
+ public Image getCustomAuthorCover(final String author) throws IOException {
return getCustomCover(author, "AUTHOR");
}
// type: "SOURCE" or "AUTHOR"
- private Image getCustomCover(final String source, final String type) {
+ private Image getCustomCover(final String source, final String type)
+ throws IOException {
final Image[] result = new Image[1];
connectRemoteAction(new RemoteAction() {
}
@Override
- public synchronized Story getStory(final String luid, Progress pg) {
+ public synchronized Story getStory(final String luid, Progress pg)
+ throws IOException {
final Progress pgF = pg;
final Story[] result = new Story[1];
}
@Override
- public void setSourceCover(final String source, final String luid) {
+ public void setSourceCover(final String source, final String luid)
+ throws IOException {
setCover(source, luid, "SOURCE");
}
@Override
- public void setAuthorCover(final String author, final String luid) {
+ public void setAuthorCover(final String author, final String luid)
+ throws IOException {
setCover(author, luid, "AUTHOR");
}
// type = "SOURCE" | "AUTHOR"
private void setCover(final String value, final String luid,
- final String type) {
+ final String type) throws IOException {
connectRemoteAction(new RemoteAction() {
@Override
public void action(ConnectActionClientObject action)
/**
* Stop the server.
*/
- public void exit() {
+ public void exit() throws IOException {
connectRemoteAction(new RemoteAction() {
@Override
public void action(ConnectActionClientObject action)
}
@Override
- public synchronized MetaData getInfo(String luid) {
+ public synchronized MetaData getInfo(String luid) throws IOException {
List<MetaData> metas = getMetasList(luid, null);
if (!metas.isEmpty()) {
return metas.get(0);
}
@Override
- protected List<MetaData> getMetas(Progress pg) {
+ protected List<MetaData> getMetas(Progress pg) throws IOException {
return getMetasList("*", pg);
}
* @param pg
* the optional progress
*
- *
* @return the metas
+ *
+ * @throws IOException
+ * in case of I/O error or bad key (SSLException)
*/
- private List<MetaData> getMetasList(final String luid, Progress pg) {
+ private List<MetaData> getMetasList(final String luid, Progress pg)
+ throws IOException {
final Progress pgF = pg;
final List<MetaData> metas = new ArrayList<MetaData>();
return metas;
}
- private void connectRemoteAction(final RemoteAction runAction) {
+ private void connectRemoteAction(final RemoteAction runAction)
+ throws IOException {
+ final IOException[] err = new IOException[1];
try {
final RemoteConnectAction[] array = new RemoteConnectAction[1];
RemoteConnectAction ra = new RemoteConnectAction() {
@Override
protected void onError(Exception e) {
- if (e instanceof SSLException) {
- Instance.getTraceHandler().error(
- "Connection refused (bad key)");
- } else {
+ if (!(e instanceof IOException)) {
Instance.getTraceHandler().error(e);
+ return;
}
+
+ err[0] = (IOException) e;
}
};
array[0] = ra;
ra.connect();
} catch (Exception e) {
- Instance.getTraceHandler().error(e);
+ err[0] = (IOException) e;
+ }
+
+ if (err[0] != null) {
+ throw err[0];
}
}
}
}
@Override
- public synchronized Story getStory(Progress pg) {
+ public synchronized Story getStory(Progress pg) throws IOException {
if (story == null) {
story = getLibrary().getStory(meta.getLuid(), pg);
}
* the optional progress
*
* @return the {@link Story}
+ *
+ * @throws IOException
+ * in case of I/O error
+ *
*/
- public Story getStory(Progress pg);
+ public Story getStory(Progress pg) throws IOException;
/**
* The {@link BasicLibrary} to load the stories from (by default, takes the
* @param source
* the type of {@link Story} to take into account, or NULL for
* all
+ *
+ * @throws IOException
+ * in case of I/O error
*/
- public void browse(String source);
+ public void browse(String source) throws IOException;
/**
* Display all supports that allow search operations.
}
@Override
- public void browse(String source) {
- List<MetaData> stories;
- stories = getLibrary().getListBySource(source);
+ public void browse(String source) throws IOException {
+ List<MetaData> stories = getLibrary().getListBySource(source);
for (MetaData story : stories) {
String author = "";
}
@Override
- public Story getStory(Progress pg) {
+ public Story getStory(Progress pg) throws IOException {
return reader.getStory(pg);
}
@Override
public void browse(String source) {
- reader.browse(source);
+ try {
+ reader.browse(source);
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ }
}
@Override
} else if (smode.equals("Sources")) {
selectTargets.clear();
selectTargets.add("(show all)");
- for (String source : reader.getLibrary().getSources()) {
- selectTargets.add(source);
+ try {
+ for (String source : reader.getLibrary().getSources()) {
+ selectTargets.add(source);
+ }
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
}
+
showTarget = true;
} else {
selectTargets.clear();
selectTargets.add("(show all)");
- for (String author : reader.getLibrary().getAuthors()) {
- selectTargets.add(author);
+ try {
+ for (String author : reader.getLibrary().getAuthors()) {
+ selectTargets.add(author);
+ }
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
}
showTarget = true;
*/
public void refreshStories() {
List<MetaData> metas;
- if (mode == Mode.SOURCE) {
- metas = reader.getLibrary().getListBySource(target);
- } else if (mode == Mode.AUTHOR) {
- metas = reader.getLibrary().getListByAuthor(target);
- } else {
- metas = reader.getLibrary().getList();
+
+ try {
+ if (mode == Mode.SOURCE) {
+ metas = reader.getLibrary().getListBySource(target);
+ } else if (mode == Mode.AUTHOR) {
+ metas = reader.getLibrary().getListByAuthor(target);
+ } else {
+ metas = reader.getLibrary().getList();
+ }
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ metas = new ArrayList<MetaData>();
}
setMetas(metas);
package be.nikiroo.fanfix.reader.ui;
+import java.io.IOException;
+
import be.nikiroo.fanfix.bundles.StringIdGui;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
* the {@link BasicLibrary} to use to fetch the image
*
* @return the base image
+ *
+ * @throws IOException
+ * in case of I/O error
*/
- public Image getBaseImage(BasicLibrary lib) {
+ public Image getBaseImage(BasicLibrary lib) throws IOException {
switch (type) {
case STORY:
if (meta.getCover() != null) {
GuiReaderBookInfo info = new GuiReaderBookInfo(Type.SOURCE, "source_"
+ source, source);
- info.count = StringUtils.formatNumber(lib.getListBySource(source)
- .size());
+ int size = 0;
+ try {
+ size = lib.getListBySource(source).size();
+ } catch (IOException e) {
+ }
+
+ info.count = StringUtils.formatNumber(size);
if (!info.count.isEmpty()) {
info.count = GuiReader.trans(StringIdGui.BOOK_COUNT_STORIES,
info.count);
GuiReaderBookInfo info = new GuiReaderBookInfo(Type.AUTHOR, "author_"
+ author, author);
- info.count = StringUtils.formatNumber(lib.getListByAuthor(author)
- .size());
+ int size = 0;
+ try {
+ size = lib.getListByAuthor(author).size();
+ } catch (IOException e) {
+ }
+
+ info.count = StringUtils.formatNumber(size);
if (!info.count.isEmpty()) {
info.count = GuiReader.trans(StringIdGui.BOOK_COUNT_STORIES,
info.count);
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.library.BasicLibrary;
+import be.nikiroo.fanfix.library.BasicLibrary.Status;
import be.nikiroo.fanfix.library.LocalLibrary;
import be.nikiroo.fanfix.output.BasicOutput.OutputType;
import be.nikiroo.fanfix.reader.BasicReader;
@Override
public JPopupMenu createBookPopup() {
+ Status status = reader.getLibrary().getStatus();
JPopupMenu popup = new JPopupMenu();
popup.add(createMenuItemOpenBook());
popup.addSeparator();
popup.add(createMenuItemExport());
- popup.add(createMenuItemMoveTo(true));
- popup.add(createMenuItemSetCoverForSource());
- popup.add(createMenuItemSetCoverForAuthor());
+ if (status.isWritable()) {
+ popup.add(createMenuItemMoveTo());
+ popup.add(createMenuItemSetCoverForSource());
+ popup.add(createMenuItemSetCoverForAuthor());
+ }
popup.add(createMenuItemClearCache());
- popup.add(createMenuItemRedownload());
- popup.addSeparator();
- popup.add(createMenuItemRename(true));
- popup.add(createMenuItemSetAuthor(true));
- popup.addSeparator();
- popup.add(createMenuItemDelete());
+ if (status.isWritable()) {
+ popup.add(createMenuItemRedownload());
+ popup.addSeparator();
+ popup.add(createMenuItemRename());
+ popup.add(createMenuItemSetAuthor());
+ popup.addSeparator();
+ popup.add(createMenuItemDelete());
+ }
popup.addSeparator();
popup.add(createMenuItemProperties());
return popup;
}
@Override
- public void createMenu(boolean libOk) {
+ public void createMenu(Status status) {
invalidate();
JMenuBar bar = new JMenuBar();
file.add(createMenuItemOpenBook());
file.add(createMenuItemExport());
- file.add(createMenuItemMoveTo(libOk));
- file.addSeparator();
- file.add(imprt);
- file.add(imprtF);
- file.addSeparator();
- file.add(createMenuItemRename(libOk));
- file.add(createMenuItemSetAuthor(libOk));
+ if (status.isWritable()) {
+ file.add(createMenuItemMoveTo());
+ file.addSeparator();
+ file.add(imprt);
+ file.add(imprtF);
+ file.addSeparator();
+ file.add(createMenuItemRename());
+ file.add(createMenuItemSetAuthor());
+ }
file.addSeparator();
file.add(createMenuItemProperties());
file.addSeparator();
bar.add(view);
Map<String, List<String>> groupedSources = new HashMap<String, List<String>>();
- if (libOk) {
- groupedSources = reader.getLibrary().getSourcesGrouped();
+ if (status.isReady()) {
+ try {
+ groupedSources = reader.getLibrary().getSourcesGrouped();
+ } catch (IOException e) {
+ error(e.getLocalizedMessage(), "IOException", e);
+ }
}
JMenu sources = new JMenu(GuiReader.trans(StringIdGui.MENU_SOURCES));
sources.setMnemonic(KeyEvent.VK_S);
bar.add(sources);
Map<String, List<String>> goupedAuthors = new HashMap<String, List<String>>();
- if (libOk) {
- goupedAuthors = reader.getLibrary().getAuthorsGrouped();
+ if (status.isReady()) {
+ try {
+ goupedAuthors = reader.getLibrary().getAuthorsGrouped();
+ } catch (IOException e) {
+ error(e.getLocalizedMessage(), "IOException", e);
+ }
}
JMenu authors = new JMenu(GuiReader.trans(StringIdGui.MENU_AUTHORS));
authors.setMnemonic(KeyEvent.VK_A);
final boolean listMode) {
return new ActionListener() {
@Override
- public void actionPerformed(ActionEvent e) {
+ public void actionPerformed(ActionEvent ae) {
mainPanel.removeBookPanes();
- mainPanel.addBookPane(type, listMode);
+ try {
+ mainPanel.addBookPane(type, listMode);
+ } catch (IOException e) {
+ error(e.getLocalizedMessage(), "IOException", e);
+ }
mainPanel.refreshBooks();
}
};
/**
* Create the "move to" menu item.
*
- * @param libOk
- * the library can be queried
- *
* @return the item
*/
- private JMenuItem createMenuItemMoveTo(boolean libOk) {
+ private JMenuItem createMenuItemMoveTo() {
JMenu changeTo = new JMenu(
GuiReader.trans(StringIdGui.MENU_FILE_MOVE_TO));
changeTo.setMnemonic(KeyEvent.VK_M);
Map<String, List<String>> groupedSources = new HashMap<String, List<String>>();
- if (libOk) {
+ try {
groupedSources = reader.getLibrary().getSourcesGrouped();
+ } catch (IOException e) {
+ error(e.getLocalizedMessage(), "IOException", e);
}
JMenuItem item = new JMenuItem(
/**
* Create the "set author" menu item.
*
- * @param libOk
- * the library can be queried
- *
* @return the item
*/
- private JMenuItem createMenuItemSetAuthor(boolean libOk) {
+ private JMenuItem createMenuItemSetAuthor() {
JMenu changeTo = new JMenu(
GuiReader.trans(StringIdGui.MENU_FILE_SET_AUTHOR));
changeTo.setMnemonic(KeyEvent.VK_A);
newItem.addActionListener(createMoveAction(ChangeAction.AUTHOR, null));
// Existing authors
- if (libOk) {
- Map<String, List<String>> groupedAuthors = reader.getLibrary()
- .getAuthorsGrouped();
-
- if (groupedAuthors.size() > 1) {
- for (String key : groupedAuthors.keySet()) {
- JMenu group = new JMenu(key);
- for (String value : groupedAuthors.get(key)) {
- JMenuItem item = new JMenuItem(
- value.isEmpty() ? GuiReader
- .trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
- : value);
- item.addActionListener(createMoveAction(
- ChangeAction.AUTHOR, value));
- group.add(item);
- }
- changeTo.add(group);
- }
- } else if (groupedAuthors.size() == 1) {
- for (String value : groupedAuthors.values().iterator().next()) {
+ Map<String, List<String>> groupedAuthors;
+
+ try {
+ groupedAuthors = reader.getLibrary().getAuthorsGrouped();
+ } catch (IOException e) {
+ error(e.getLocalizedMessage(), "IOException", e);
+ groupedAuthors = new HashMap<String, List<String>>();
+
+ }
+
+ if (groupedAuthors.size() > 1) {
+ for (String key : groupedAuthors.keySet()) {
+ JMenu group = new JMenu(key);
+ for (String value : groupedAuthors.get(key)) {
JMenuItem item = new JMenuItem(
value.isEmpty() ? GuiReader
.trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
: value);
item.addActionListener(createMoveAction(
ChangeAction.AUTHOR, value));
- changeTo.add(item);
+ group.add(item);
}
+ changeTo.add(group);
+ }
+ } else if (groupedAuthors.size() == 1) {
+ for (String value : groupedAuthors.values().iterator().next()) {
+ JMenuItem item = new JMenuItem(
+ value.isEmpty() ? GuiReader
+ .trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+ : value);
+ item.addActionListener(createMoveAction(ChangeAction.AUTHOR,
+ value));
+ changeTo.add(item);
}
}
/**
* Create the "rename" menu item.
*
- * @param libOk
- * the library can be queried
- *
* @return the item
*/
- private JMenuItem createMenuItemRename(
- @SuppressWarnings("unused") boolean libOk) {
+ private JMenuItem createMenuItemRename() {
JMenuItem changeTo = new JMenuItem(
GuiReader.trans(StringIdGui.MENU_FILE_RENAME));
changeTo.setMnemonic(KeyEvent.VK_R);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
- createMenu(true);
+ createMenu(reader.getLibrary().getStatus());
}
});
}
KeyEvent.VK_C);
open.addActionListener(new ActionListener() {
@Override
- public void actionPerformed(ActionEvent e) {
+ public void actionPerformed(ActionEvent ae) {
final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
if (selectedBook != null) {
BasicLibrary lib = reader.getLibrary();
String source = selectedBook.getInfo().getMeta()
.getSource();
- lib.setSourceCover(source, luid);
+ try {
+ lib.setSourceCover(source, luid);
+ } catch (IOException e) {
+ error(e.getLocalizedMessage(), "IOException", e);
+ }
GuiReaderBookInfo sourceInfo = GuiReaderBookInfo
.fromSource(lib, source);
KeyEvent.VK_A);
open.addActionListener(new ActionListener() {
@Override
- public void actionPerformed(ActionEvent e) {
+ public void actionPerformed(ActionEvent ae) {
final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
if (selectedBook != null) {
BasicLibrary lib = reader.getLibrary();
String author = selectedBook.getInfo().getMeta()
.getAuthor();
- lib.setAuthorCover(author, luid);
+ try {
+ lib.setAuthorCover(author, luid);
+ } catch (IOException e) {
+ error(e.getLocalizedMessage(), "IOException", e);
+ }
GuiReaderBookInfo authorInfo = GuiReaderBookInfo
.fromAuthor(lib, author);
* <p>
* Will invalidate the layout.
*
- * @param libOk
- * the library can be queried
+ * @param status
+ * the library status, <b>must not</b> be NULL
*/
- public void createMenu(boolean libOk);
+ public void createMenu(Status status);
/**
* Create a popup menu for a {@link GuiReaderBook} that represents a
final BasicLibrary lib = helper.getReader().getLibrary();
final Status status = lib.getStatus();
- if (status == Status.READY) {
+ if (status == Status.READ_WRITE) {
lib.refresh(pg);
}
inUi(new Runnable() {
@Override
public void run() {
- if (status == Status.READY) {
- helper.createMenu(true);
+ if (status.isReady()) {
+ helper.createMenu(status);
pane.setVisible(true);
if (typeF == null) {
- addBookPane(true, false);
+ try {
+ addBookPane(true, false);
+ } catch (IOException e) {
+ error(e.getLocalizedMessage(),
+ "IOException", e);
+ }
} else {
addBookPane(typeF, true);
}
} else {
- helper.createMenu(false);
+ helper.createMenu(status);
validate();
String desc = Instance.getTransGui().getStringX(
* @param listMode
* TRUE to get a listing of all the sources or authors, FALSE to
* get one icon per source or author
+ *
+ * @throws IOException
+ * in case of I/O error
*/
- public void addBookPane(boolean type, boolean listMode) {
+ public void addBookPane(boolean type, boolean listMode) throws IOException {
this.currentType = type;
BasicLibrary lib = helper.getReader().getLibrary();
if (type) {
List<GuiReaderBookInfo> infos = new ArrayList<GuiReaderBookInfo>();
List<MetaData> metas;
- if (currentType) {
- metas = lib.getListBySource(value);
- } else {
- metas = lib.getListByAuthor(value);
+ try {
+ if (currentType) {
+ metas = lib.getListBySource(value);
+ } else {
+ metas = lib.getListByAuthor(value);
+ }
+ } catch (IOException e) {
+ error(e.getLocalizedMessage(), "IOException", e);
+ metas = new ArrayList<MetaData>();
}
+
for (MetaData meta : metas) {
infos.add(GuiReaderBookInfo.fromMeta(meta));
}