import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.library.BasicLibrary;
import be.nikiroo.fanfix.output.BasicOutput.OutputType;
-import be.nikiroo.fanfix.reader.Reader;
+import be.nikiroo.jexer.TSizeConstraint;
/**
* The library window, that will list all the (filtered) stories available in
public static final TCommand CMD_SEARCH = new TCommand(MENU_SEARCH) {
};
+ public enum Mode {
+ SOURCE, AUTHOR,
+ }
+
private TList list;
private List<MetaData> listKeys;
private List<String> listItems;
- private Reader reader;
- private String source;
+ private TuiReaderApplication reader;
+
+ private Mode mode = Mode.SOURCE;
+ private String target = null;
private String filter = "";
+
private List<TSizeConstraint> sizeConstraints = new ArrayList<TSizeConstraint>();
- // TODO: because no way to find out the current index!!
- private TComboBox select;
+ // The 2 comboboxes used to select by source/author
+ private TComboBox selectTargetBox;
+ private TComboBox selectBox;
/**
* Create a new {@link TuiReaderMainWindow} without any stories in the list.
listKeys = new ArrayList<MetaData>();
listItems = new ArrayList<String>();
- addSearch();
addList();
- addSelect(); // TODO: last so it can draw over the rest
+ addSearch();
+ addSelect();
TStatusBar statusBar = reader.setStatusBar(this, "Library");
statusBar.addShortcutKeypress(TKeypress.kbCtrlF, CMD_SEARCH, "Search");
}
private void addSelect() {
- // TODO: make a full list
- final List<String> options = new ArrayList<String>();
- options.add("(all opt)");
- options.add("Sources");
- options.add("Author");
-
- // TODO
- final List<String> sources = new ArrayList<String>();
- sources.add("(show all)");
- for (String source : reader.getLibrary().getSources()) {
- sources.add(source);
- }
+ // TODO: i18n
+ final List<String> selects = new ArrayList<String>();
+ selects.add("(show all)");
+ selects.add("Sources");
+ selects.add("Author");
+
+ final List<String> selectTargets = new ArrayList<String>();
+ selectTargets.add("");
TLabel lblSelect = addLabel("Select: ", 0, 0);
- // TODO: why must be last so to be able to draw over the rest
- // TODO: make it so we cannot add manual entries
- // TODO: how to select the item via keyboard? why double-click via
- // mouse?
- // TODO: how to change the values size on resize?
- // TODO: setWidth() does not impact the display width, only the control
- // and the down arrow on the right
- // TODO: width 1 +resize + click on down arrow = bad format exception
- select = addComboBox(0, 0, 10, sources, 0,
- Math.min(sources.size() + 1, getHeight() - 1 - 1),
- new TAction() {
- @Override
- public void DO() {
- // TODO: wut?
- if (select.getText().equals("(show all)")) {
- setSource(null);
- } else {
- setSource(select.getText());
+ TAction onSelect = new TAction() {
+ @Override
+ public void DO() {
+ String smode = selectBox.getText();
+ boolean showTarget;
+ if (smode == null || smode.equals("(show all)")) {
+ showTarget = false;
+ } else if (smode.equals("Sources")) {
+ selectTargets.clear();
+ selectTargets.add("(show all)");
+ try {
+ for (String source : reader.getLibrary().getSources()) {
+ selectTargets.add(source);
}
- refreshStories();
+ } catch (IOException e) {
+ Instance.getInstance().getTraceHandler().error(e);
+ }
+
+ showTarget = true;
+ } else {
+ selectTargets.clear();
+ selectTargets.add("(show all)");
+ try {
+ for (String author : reader.getLibrary().getAuthors()) {
+ selectTargets.add(author);
+ }
+ } catch (IOException e) {
+ Instance.getInstance().getTraceHandler().error(e);
}
- });
- final TComboBox option = addComboBox(0, 0, 10, options, 0,
- Math.min(sources.size() + 1, getHeight() - 1 - 1),
+ showTarget = true;
+ }
+
+ selectTargetBox.setVisible(showTarget);
+ selectTargetBox.setEnabled(showTarget);
+ if (showTarget) {
+ selectTargetBox.reflowData();
+ }
+
+ selectTargetBox.setText(selectTargets.get(0));
+ if (showTarget) {
+ TuiReaderMainWindow.this.activate(selectTargetBox);
+ } else {
+ TuiReaderMainWindow.this.activate(list);
+ }
+ }
+ };
+
+ selectBox = addComboBox(0, 0, 10, selects, 0, -1, onSelect);
+
+ selectTargetBox = addComboBox(0, 0, 0, selectTargets, 0, -1,
new TAction() {
@Override
public void DO() {
- // TODO Not working:
- sources.clear();
- sources.add("(show all)");
- for (String source : reader.getLibrary().getSources()) {
- sources.add(source);
+ if (selectTargetBox.getText().equals(
+ selectTargets.get(0))) {
+ setMode(mode, null);
+ } else {
+ setMode(mode, selectTargetBox.getText());
}
}
});
+ // Set defaults
+ onSelect.DO();
+
TSizeConstraint.setSize(sizeConstraints, lblSelect, 5, 3, null, null);
- TSizeConstraint.setSize(sizeConstraints, option, 15, 3, -5, null);
- TSizeConstraint.setSize(sizeConstraints, select, 15, 4, -5, null);
+ TSizeConstraint.setSize(sizeConstraints, selectBox, 15, 3, -5, null);
+ TSizeConstraint.setSize(sizeConstraints, selectTargetBox, 15, 4, -5,
+ null);
}
@Override
* Will take the current settings into account (filter, source...).
*/
public void refreshStories() {
- List<MetaData> metas = reader.getLibrary().getListBySource(source);
+ List<MetaData> metas;
+
+ try {
+ if (mode == Mode.SOURCE) {
+ metas = reader.getLibrary().getList().filter(target, null, null);
+ } else if (mode == Mode.AUTHOR) {
+ metas = reader.getLibrary().getList().filter(null, target, null);
+ } else {
+ metas = reader.getLibrary().getList().getMetas();
+ }
+ } catch (IOException e) {
+ Instance.getInstance().getTraceHandler().error(e);
+ metas = new ArrayList<MetaData>();
+ }
+
setMetas(metas);
}
/**
- * Change the source filter and display all stories matching this source.
+ * Change the author/source filter and display all stories matching this
+ * target.
*
- * @param source
- * the new source or NULL for all sources
+ * @param mode
+ * the new mode or NULL for no sorting
+ * @param target
+ * the actual target for the given mode, or NULL for all of them
*/
- public void setSource(String source) {
- this.source = source;
+ public void setMode(Mode mode, String target) {
+ this.mode = mode;
+ this.target = target;
refreshStories();
}
}
list.setList(listItems);
+ if (listItems.size() > 0) {
+ list.setSelectedIndex(0);
+ }
}
public MetaData getSelectedMeta() {
try {
reader.setChapter(-1);
reader.setMeta(meta);
- reader.read();
+ reader.read(false);
} catch (IOException e) {
- Instance.getTraceHandler().error(e);
+ Instance.getInstance().getTraceHandler().error(e);
}
}
MetaData meta = getSelectedMeta();
if (meta != null) {
switch (menu.getId()) {
- case TuiReaderApplication.MENU_OPEN:
+ case TuiReaderApplication.MENU_FILE_OPEN:
readStory(meta);
return;
- case TuiReaderApplication.MENU_EXPORT:
+ case TuiReaderApplication.MENU_FILE_EXPORT:
try {
// TODO: choose type, pg, error