1 package be
.nikiroo
.jvcard
.tui
.panes
;
4 import java
.io
.IOException
;
5 import java
.util
.ArrayList
;
6 import java
.util
.LinkedList
;
9 import be
.nikiroo
.jvcard
.Card
;
10 import be
.nikiroo
.jvcard
.i18n
.Trans
;
11 import be
.nikiroo
.jvcard
.parsers
.Format
;
12 import be
.nikiroo
.jvcard
.remote
.Sync
;
13 import be
.nikiroo
.jvcard
.tui
.KeyAction
;
14 import be
.nikiroo
.jvcard
.tui
.KeyAction
.DataType
;
15 import be
.nikiroo
.jvcard
.tui
.KeyAction
.Mode
;
16 import be
.nikiroo
.jvcard
.tui
.StringUtils
;
17 import be
.nikiroo
.jvcard
.tui
.UiColors
;
18 import be
.nikiroo
.jvcard
.tui
.UiColors
.Element
;
20 import com
.googlecode
.lanterna
.input
.KeyType
;
22 public class FileList
extends MainContentList
{
23 private List
<String
> files
;
24 private List
<Card
> cards
;
26 public FileList(List
<String
> files
) {
31 * Change the list of currently selected files.
36 public void setFiles(List
<String
> files
) {
39 cards
= new ArrayList
<Card
>();
41 for (String file
: files
) {
42 addItem(file
); // TODO
50 public DataType
getDataType() {
51 return DataType
.CARD_FILES
;
55 protected List
<TextPart
> getLabel(int index
, int width
, boolean selected
,
57 // TODO: from ini file?
60 Element el
= (focused
&& selected
) ? Element
.CONTACT_LINE_SELECTED
61 : Element
.CONTACT_LINE
;
62 Element elSep
= (focused
&& selected
) ? Element
.CONTACT_LINE_SEPARATOR_SELECTED
63 : Element
.CONTACT_LINE_SEPARATOR
;
65 List
<TextPart
> parts
= new LinkedList
<TextPart
>();
68 if (cards
.get(index
) != null)
69 count
+= cards
.get(index
).size();
71 String name
= files
.get(index
).replaceAll("\\\\", "/");
72 int indexSl
= name
.lastIndexOf('/');
74 name
= name
.substring(indexSl
+ 1);
77 name
= StringUtils
.sanitize(name
, UiColors
.getInstance().isUnicode());
79 count
= " " + StringUtils
.padString(count
, SIZE_COL_1
) + " ";
81 + StringUtils
.padString(name
, width
- SIZE_COL_1
82 - getSeparator().length()) + " ";
84 parts
.add(new TextPart(count
, el
));
85 parts
.add(new TextPart(getSeparator(), elSep
));
86 parts
.add(new TextPart(name
, el
));
92 public List
<KeyAction
> getKeyBindings() {
93 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
96 actions
.add(new KeyAction(Mode
.CONTACT_LIST
, KeyType
.Enter
,
97 Trans
.StringId
.KEY_ACTION_VIEW_CARD
) {
99 public Object
getObject() {
100 int index
= getSelectedIndex();
102 if (index
< 0 || index
>= cards
.size())
105 if (cards
.get(index
) != null)
106 return cards
.get(index
);
108 String file
= files
.get(index
);
111 Card card
= FileList
.getCard(file
);
112 cards
.set(index
, card
);
117 } catch (IOException ioe
) {
118 ioe
.printStackTrace();
127 static private Card
getCard(String input
) throws IOException
{
128 boolean remote
= false;
129 Format format
= Format
.Abook
;
131 if (ext
.contains(".")) {
132 String tab
[] = ext
.split("\\.");
133 if (tab
.length
> 1 && tab
[tab
.length
- 1].equalsIgnoreCase("vcf")) {
134 format
= Format
.VCard21
;
138 if (input
.contains("://")) {
139 format
= Format
.VCard21
;
146 Sync sync
= new Sync(input
);
147 card
= new Card(sync
.getCache(), format
);
148 card
.setRemote(true);
149 sync
.sync(card
, false);
151 card
= new Card(new File(input
), format
);
153 } catch (IOException ioe
) {
154 ioe
.printStackTrace();