use of org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport in project Spark by igniterealtime.
the class SubscriptionDialog method invoke.
public void invoke(final String jid) throws SmackException.NotConnectedException {
this.jid = jid;
final Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
// If User is already in roster, do not show.
RosterEntry entry = roster.getEntry(jid);
if (entry != null && entry.getType() == RosterPacket.ItemType.to) {
Presence response = new Presence(Presence.Type.subscribed);
response.setTo(jid);
SparkManager.getConnection().sendStanza(response);
return;
}
String message = Res.getString("message.approve.subscription", UserManager.unescapeJID(jid));
Transport transport = TransportUtils.getTransport(XmppStringUtils.parseDomain(jid));
Icon icon = null;
if (transport != null) {
icon = transport.getIcon();
}
TitlePanel messageLabel = new TitlePanel("", message, icon, true);
// Add Message Label
mainPanel.add(messageLabel, new GridBagConstraints(0, 0, 6, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
UserManager userManager = SparkManager.getUserManager();
String username = userManager.getNickname(userManager.getFullJID(jid));
username = username == null ? XmppStringUtils.parseLocalpart(UserManager.unescapeJID(jid)) : username;
usernameLabelValue.setText(UserManager.unescapeJID(jid));
nicknameField.setText(username);
acceptButton.addActionListener(e -> {
if (!rosterBox.isSelected()) {
Presence response = new Presence(Presence.Type.subscribed);
response.setTo(jid);
try {
SparkManager.getConnection().sendStanza(response);
} catch (SmackException.NotConnectedException e1) {
Log.warning("Unable to send stanza accepting subscription from " + jid, e1);
}
dialog.dispose();
return;
}
boolean addEntry = addEntry();
if (addEntry) {
Presence response = new Presence(Presence.Type.subscribed);
response.setTo(jid);
try {
SparkManager.getConnection().sendStanza(response);
} catch (SmackException.NotConnectedException e1) {
Log.warning("Unable to send stanza accepting subscription from " + jid, e1);
}
} else {
dialog.dispose();
}
});
denyButton.addActionListener(e -> {
// Send subscribed
unsubscribeAndClose();
});
viewInfoButton.addActionListener(e -> SparkManager.getVCardManager().viewProfile(jid, mainPanel));
dialog = new JFrame(Res.getString("title.subscription.request")) {
private static final long serialVersionUID = 5713933518069623228L;
public Dimension getPreferredSize() {
final Dimension dim = super.getPreferredSize();
dim.width = 400;
return dim;
}
};
dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
unsubscribeAndClose();
}
});
KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
ActionListener action = e -> unsubscribeAndClose();
dialog.getRootPane().registerKeyboardAction(action, key, JComponent.WHEN_FOCUSED);
dialog.setIconImage(SparkManager.getApplicationImage().getImage());
dialog.getContentPane().add(mainPanel);
dialog.pack();
dialog.setLocationRelativeTo(SparkManager.getMainWindow());
if (SparkManager.getMainWindow().isFocused()) {
dialog.setState(Frame.NORMAL);
dialog.setVisible(true);
} else if (!SparkManager.getMainWindow().isVisible() || !SparkManager.getMainWindow().isFocused()) {
if (Spark.isWindows()) {
dialog.setFocusable(false);
dialog.setState(Frame.ICONIFIED);
}
SparkManager.getNativeManager().flashWindowStopOnFocus(dialog);
dialog.setVisible(true);
}
}
Aggregations