import be.nikiroo.jvcard.Card;
import be.nikiroo.jvcard.i18n.Trans;
import be.nikiroo.jvcard.parsers.Format;
+import be.nikiroo.jvcard.remote.Sync;
import be.nikiroo.jvcard.tui.KeyAction;
import be.nikiroo.jvcard.tui.KeyAction.DataType;
import be.nikiroo.jvcard.tui.KeyAction.Mode;
import com.googlecode.lanterna.input.KeyType;
public class FileList extends MainContentList {
- private List<File> files;
+ private List<String> files;
private List<Card> cards;
- public FileList(List<File> files) {
- super(UiColors.Element.CONTACT_LINE,
- UiColors.Element.CONTACT_LINE_SELECTED);
-
+ public FileList(List<String> files) {
setFiles(files);
}
* @param files
* the new files
*/
- public void setFiles(List<File> files) {
+ public void setFiles(List<String> files) {
clearItems();
this.files = files;
cards = new ArrayList<Card>();
- for (File file : files) {
- addItem(file.getName());
+ for (String file : files) {
+ addItem(file); // TODO
cards.add(null);
}
if (cards.get(index) != null)
count += cards.get(index).size();
- String name = files.get(index).getName();
+ String name = files.get(index).replaceAll("\\\\", "/");
+ int indexSl = name.lastIndexOf('/');
+ if (indexSl >= 0) {
+ name = name.substring(indexSl + 1);
+ }
+
+ name = StringUtils.sanitize(name, UiColors.getInstance().isUnicode());
count = " " + StringUtils.padString(count, SIZE_COL_1) + " ";
name = " "
if (cards.get(index) != null)
return cards.get(index);
- File file = files.get(index);
- Format format = Format.Abook;
- String ext = file.getName();
- if (ext.contains(".")) {
- String tab[] = ext.split("\\.");
- if (tab.length > 1
- && tab[tab.length - 1].equalsIgnoreCase("vcf")) {
- format = Format.VCard21;
- }
- }
+ String file = files.get(index);
+
try {
- Card card = new Card(file, format);
+ Card card = FileList.getCard(file);
cards.set(index, card);
invalidate();
return actions;
}
- @Override
- public Mode getMode() {
- return Mode.FILE_LIST;
+ static private Card getCard(String input) throws IOException {
+ boolean remote = false;
+ Format format = Format.Abook;
+ String ext = input;
+ if (ext.contains(".")) {
+ String tab[] = ext.split("\\.");
+ if (tab.length > 1 && tab[tab.length - 1].equalsIgnoreCase("vcf")) {
+ format = Format.VCard21;
+ }
+ }
+
+ if (input.contains("://")) {
+ format = Format.VCard21;
+ remote = true;
+ }
+
+ Card card = null;
+ try {
+ if (remote) {
+ Sync sync = new Sync(input);
+ card = new Card(sync.getCache(), format);
+ card.setRemote(true);
+ sync.sync(card, false);
+ } else {
+ card = new Card(new File(input), format);
+ }
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ throw ioe;
+ }
+
+ return card;
}
}