use of org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport in project Spark by igniterealtime.
the class RosterDialog method addEntry.
private void addEntry() {
Transport transport = null;
AccountItem item;
if (publicBox.isSelected()) {
item = (AccountItem) accounts.getSelectedItem();
transport = item.getTransport();
}
if (transport == null) {
String jid = getJID();
if (!jid.contains("@")) {
jid = jid + "@" + SparkManager.getConnection().getServiceName();
}
String nickname = nicknameField.getText();
String group = (String) groupBox.getSelectedItem();
jid = UserManager.escapeJID(jid);
// Add as a new entry
addRosterEntry(jid, nickname, group);
} else {
String jid = getJID();
try {
jid = Gateway.getJID(transport.getServiceName(), jid);
} catch (SmackException e) {
Log.error(e);
}
String nickname = nicknameField.getText();
String group = (String) groupBox.getSelectedItem();
addRosterEntry(jid, nickname, group);
}
}
use of org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport in project Spark by igniterealtime.
the class RosterDialog method addContactButton.
/**
* Method to handle the Add-Button
*/
private void addContactButton() {
String errorMessage = Res.getString("title.error");
String jid = getJID();
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
if (jid.length() == 0) {
JOptionPane.showMessageDialog(dialog, Res.getString("message.invalid.jid.error"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
return;
}
String contact = UserManager.escapeJID(jid);
String nickname = nicknameField.getText();
String group = (String) groupBox.getSelectedItem();
Transport transport = null;
if (publicBox.isSelected()) {
AccountItem item = (AccountItem) accounts.getSelectedItem();
transport = item.getTransport();
}
if (transport == null) {
if (!contact.contains("@")) {
contact = contact + "@" + SparkManager.getConnection().getServiceName();
}
} else {
if (!contact.contains("@")) {
contact = contact + "@" + transport.getServiceName();
}
}
if (!ModelUtil.hasLength(nickname) && ModelUtil.hasLength(contact)) {
// Try to load nickname from VCard
VCard vcard = new VCard();
try {
vcard.load(SparkManager.getConnection(), contact);
nickname = vcard.getNickName();
} catch (XMPPException | SmackException e1) {
Log.error(e1);
}
// If no nickname, use first name.
if (!ModelUtil.hasLength(nickname)) {
nickname = XmppStringUtils.parseLocalpart(contact);
}
nicknameField.setText(nickname);
}
ContactGroup contactGroup = contactList.getContactGroup(group);
boolean isSharedGroup = contactGroup != null && contactGroup.isSharedGroup();
if (isSharedGroup) {
errorMessage = Res.getString("message.cannot.add.contact.to.shared.group");
} else if (!ModelUtil.hasLength(contact)) {
errorMessage = Res.getString("message.specify.contact.jid");
} else if (!XmppStringUtils.parseBareJid(contact).contains("@")) {
errorMessage = Res.getString("message.invalid.jid.error");
} else if (!ModelUtil.hasLength(group)) {
errorMessage = Res.getString("message.specify.group");
} else if (ModelUtil.hasLength(contact) && ModelUtil.hasLength(group) && !isSharedGroup) {
addEntry();
dialog.setVisible(false);
} else {
JOptionPane.showMessageDialog(dialog, errorMessage, Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
}
}
use of org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport in project Spark by igniterealtime.
the class GatewayTabItem method createTransportMenu.
private void createTransportMenu() {
_signInOut.addActionListener(e -> {
if (signedIn) {
final Presence offlinePresence = new Presence(Presence.Type.unavailable);
offlinePresence.setTo(_transport.getServiceName());
try {
SparkManager.getConnection().sendStanza(offlinePresence);
_statusIcon.setIcon(SparkRes.getImageIcon(SparkRes.YELLOW_BALL));
} catch (SmackException.NotConnectedException e1) {
Log.error("Unable to send presence.", e1);
}
} else {
final Presence onlinePresence = new Presence(Presence.Type.available);
onlinePresence.setTo(_transport.getServiceName());
try {
SparkManager.getConnection().sendStanza(onlinePresence);
_statusIcon.setIcon(SparkRes.getImageIcon(SparkRes.YELLOW_BALL));
} catch (SmackException.NotConnectedException e1) {
Log.error("Unable to send presence.", e1);
}
}
});
// If transport is registered, we can check if the autojoin is enabled
if (_transportRegistered) {
_autoJoin.setSelected(TransportUtils.autoJoinService(_transport.getServiceName()));
_registerButton.setText(Res.getString("menuitem.delete.login.information"));
_signInOut.setEnabled(true);
} else {
setNotRegistered();
}
_autoJoinButton.addActionListener(e -> {
_autoJoin.setSelected(!_autoJoin.isSelected());
TransportUtils.setAutoJoin(_transport.getServiceName(), _autoJoin.isSelected());
});
_registerButton.addActionListener(e -> {
// If transport is registered we should show the
// "delete information" gui
UIManager.put("OptionPane.yesButtonText", Res.getString("yes"));
UIManager.put("OptionPane.noButtonText", Res.getString("no"));
UIManager.put("OptionPane.cancelButtonText", Res.getString("cancel"));
if (TransportUtils.isRegistered(SparkManager.getConnection(), _transport)) {
int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport", _transport.getName()), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
try {
TransportUtils.unregister(SparkManager.getConnection(), _transport.getServiceName());
setNotRegistered();
} catch (SmackException e1) {
Log.error(e1);
}
}
} else {
// If transport is not registered we should show the
// register gui
TransportRegistrationDialog registrationDialog = new TransportRegistrationDialog(_transport.getServiceName());
registrationDialog.invoke();
// Set user as offline while he fills in the login
// information
setOffline();
ActionListener al = e1 -> {
// If user canceled the register window, he is sill
// not registrated
setNotRegistered();
};
registrationDialog.addCancelActionListener(al);
}
});
_autoJoinButton.setText(Res.getString("menuitem.sign.in.at.login"));
_autoJoinButton.setHorizontalAlignment(SwingConstants.LEFT);
// JPanel signPanel = new JPanel(new BorderLayout());
// signPanel.setBackground(Color.lightGray);
// signPanel.add(_statusIcon, BorderLayout.WEST);
// signPanel.add(_signInOut, BorderLayout.CENTER);
_registerButton.setHorizontalAlignment(SwingConstants.LEFT);
_signInOut.setHorizontalAlignment(SwingConstants.LEFT);
_listPanel.add(new JLabel(), new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0, GridBagConstraints.PAGE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
_listPanel.add(_statusIcon, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 3, 0, 0), 0, 0));
_listPanel.add(_signInOut, new GridBagConstraints(2, 0, 1, 1, 0.9, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
_listPanel.add(_autoJoin, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
_listPanel.add(_autoJoinButton, new GridBagConstraints(2, 1, 1, 1, 0.9, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
_listPanel.add(_registerButton, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
// _listPanel.add(_autoJoin);
// _listPanel.add(_registerButton);
}
use of org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport in project Spark by igniterealtime.
the class RosterDialog method getAccounts.
public List<AccountItem> getAccounts() {
List<AccountItem> list = new ArrayList<>();
for (Transport transport : TransportUtils.getTransports()) {
if (TransportUtils.isRegistered(SparkManager.getConnection(), transport)) {
AccountItem item = new AccountItem(transport.getIcon(), transport.getName(), transport);
list.add(item);
}
}
return list;
}
use of org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport in project Spark by igniterealtime.
the class ContactInfoWindow method customizeUI.
public void customizeUI(ContactItem contactItem) {
if (contactItem == null) {
return;
}
nicknameLabel.setText(contactItem.getDisplayName());
String status = contactItem.getStatus();
if (!ModelUtil.hasLength(status)) {
if (contactItem.getPresence() == null || contactItem.getPresence().getType() == Presence.Type.unavailable) {
status = Res.getString("offline");
} else {
status = Res.getString("online");
}
}
if (status.equals(Res.getString("offline")) || contactItem.getPresence().isAway()) {
try {
String client = "";
if (!status.equals(Res.getString("offline"))) {
// If user is away (not offline), last activity request is sent to client
client = contactItem.getPresence().getFrom();
if ((client != null) && (client.lastIndexOf("/") != -1)) {
client = client.substring(client.lastIndexOf("/"));
} else
client = "/";
}
LastActivity activity = LastActivityManager.getInstanceFor(SparkManager.getConnection()).getLastActivity(contactItem.getJID() + client);
long idleTime = (activity.getIdleTime() * 1000);
if (idleTime > 0) {
if (status.equals(Res.getString("offline"))) {
SimpleDateFormat format = new SimpleDateFormat("M/d/yy");
Date l = new Date();
String curDay = format.format(l);
l.setTime(l.getTime() - idleTime);
// If idleTime is within today show the time, otherwise, show the day, date, and time
if (curDay.equals(format.format(l))) {
format = new SimpleDateFormat("h:mm a");
} else {
format = new SimpleDateFormat("EEE M/d/yy h:mm a");
}
status += (" since " + format.format(l));
} else if (contactItem.getPresence().isAway()) {
status += "\n";
String time = ModelUtil.getTimeFromLong(idleTime);
status += Res.getString("message.idle.for", time);
}
}
} catch (Exception e1) {
Log.warning("Unable to get Last Activity from: " + contactItem.toString(), e1);
}
}
statusLabel.setText(status);
Transport transport = TransportUtils.getTransport(XmppStringUtils.parseDomain(contactItem.getJID()));
if (transport != null) {
fullJIDLabel.setIcon(transport.getIcon());
String name = XmppStringUtils.parseLocalpart(contactItem.getJID());
name = XmppStringUtils.unescapeLocalpart(name);
fullJIDLabel.setText(transport.getName() + " - " + name);
} else {
String name = XmppStringUtils.unescapeLocalpart(contactItem.getJID());
fullJIDLabel.setText(name);
fullJIDLabel.setIcon(null);
}
avatarLabel.setBorder(null);
try {
URL avatarURL = contactItem.getAvatarURL();
ImageIcon icon = null;
if (avatarURL != null) {
icon = new ImageIcon(avatarURL);
}
if (icon != null && icon.getIconHeight() > 1) {
icon = GraphicUtils.scaleImageIcon(icon, 96, 96);
avatarLabel.setIcon(icon);
} else {
icon = SparkRes.getImageIcon(SparkRes.DEFAULT_AVATAR_64x64_IMAGE);
avatarLabel.setIcon(icon);
}
avatarLabel.setBorder(BorderFactory.createBevelBorder(0, Color.white, Color.lightGray));
} catch (MalformedURLException e) {
Log.error(e);
}
// Get VCard from memory (if available)
String title = "";
String phone = "";
VCard vcard = SparkManager.getVCardManager().getVCardFromMemory(XmppStringUtils.parseBareJid(contactItem.getJID()));
if (vcard != null) {
title = vcard.getField("TITLE");
phone = vcard.getPhoneWork("VOICE");
if (!ModelUtil.hasLength(title)) {
title = "";
}
if (!ModelUtil.hasLength(phone)) {
phone = "";
}
}
titleLabel.setText(title);
phoneLabel.setText(phone);
}
Aggregations