2014-10-22 12:38:44 -04:00
|
|
|
package eu.siacs.conversations.entities;
|
|
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.xml.Element;
|
2014-11-05 15:55:47 -05:00
|
|
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
|
|
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
2014-10-22 12:38:44 -04:00
|
|
|
|
|
|
|
public class Bookmark extends Element implements ListItem {
|
|
|
|
|
|
|
|
private Account account;
|
|
|
|
private Conversation mJoinedConversation;
|
|
|
|
|
2014-11-05 15:55:47 -05:00
|
|
|
public Bookmark(final Account account, final Jid jid) {
|
2014-10-22 12:38:44 -04:00
|
|
|
super("conference");
|
2014-11-05 15:55:47 -05:00
|
|
|
this.setAttribute("jid", jid.toString());
|
2014-10-22 12:38:44 -04:00
|
|
|
this.account = account;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Bookmark(Account account) {
|
|
|
|
super("conference");
|
|
|
|
this.account = account;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Bookmark parse(Element element, Account account) {
|
|
|
|
Bookmark bookmark = new Bookmark(account);
|
|
|
|
bookmark.setAttributes(element.getAttributes());
|
|
|
|
bookmark.setChildren(element.getChildren());
|
|
|
|
return bookmark;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAutojoin(boolean autojoin) {
|
|
|
|
if (autojoin) {
|
|
|
|
this.setAttribute("autojoin", "true");
|
|
|
|
} else {
|
|
|
|
this.setAttribute("autojoin", "false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setName(String name) {
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setNick(String nick) {
|
|
|
|
Element element = this.findChild("nick");
|
|
|
|
if (element == null) {
|
|
|
|
element = this.addChild("nick");
|
|
|
|
}
|
|
|
|
element.setContent(nick);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPassword(String password) {
|
|
|
|
Element element = this.findChild("password");
|
|
|
|
if (element != null) {
|
|
|
|
element.setContent(password);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-05 15:55:47 -05:00
|
|
|
public int compareTo(final ListItem another) {
|
|
|
|
return this.getDisplayName().compareToIgnoreCase(
|
|
|
|
another.getDisplayName());
|
|
|
|
}
|
2014-10-22 12:38:44 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDisplayName() {
|
|
|
|
if (this.mJoinedConversation != null
|
|
|
|
&& (this.mJoinedConversation.getMucOptions().getSubject() != null)) {
|
|
|
|
return this.mJoinedConversation.getMucOptions().getSubject();
|
|
|
|
} else if (getName() != null) {
|
|
|
|
return getName();
|
|
|
|
} else {
|
2014-11-05 15:55:47 -05:00
|
|
|
return this.getJid().getLocalpart();
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-05 15:55:47 -05:00
|
|
|
public Jid getJid() {
|
|
|
|
final String jid = this.getAttribute("jid");
|
2014-10-22 12:38:44 -04:00
|
|
|
if (jid != null) {
|
2014-11-05 15:55:47 -05:00
|
|
|
try {
|
|
|
|
return Jid.fromString(jid);
|
|
|
|
} catch (final InvalidJidException e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else {
|
2014-10-22 12:38:44 -04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getNick() {
|
|
|
|
Element nick = this.findChild("nick");
|
|
|
|
if (nick != null) {
|
|
|
|
return nick.getContent();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean autojoin() {
|
|
|
|
String autojoin = this.getAttribute("autojoin");
|
|
|
|
return (autojoin != null && (autojoin.equalsIgnoreCase("true") || autojoin
|
|
|
|
.equalsIgnoreCase("1")));
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPassword() {
|
|
|
|
Element password = this.findChild("password");
|
|
|
|
if (password != null) {
|
|
|
|
return password.getContent();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean match(String needle) {
|
|
|
|
return needle == null
|
2014-11-05 15:55:47 -05:00
|
|
|
|| getJid().toString().toLowerCase(Locale.US).contains(needle.toLowerCase(Locale.US))
|
2014-10-22 12:38:44 -04:00
|
|
|
|| getDisplayName().toLowerCase(Locale.US).contains(
|
|
|
|
needle.toLowerCase(Locale.US));
|
|
|
|
}
|
|
|
|
|
|
|
|
public Account getAccount() {
|
|
|
|
return this.account;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setConversation(Conversation conversation) {
|
|
|
|
this.mJoinedConversation = conversation;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Conversation getConversation() {
|
|
|
|
return this.mJoinedConversation;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return this.getAttribute("name");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unregisterConversation() {
|
|
|
|
if (this.mJoinedConversation != null) {
|
|
|
|
this.mJoinedConversation.deregisterWithBookmark();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|