use of org.jivesoftware.smack.filter.IQReplyFilter in project Spark by igniterealtime.
the class VersionViewer method viewVersion.
public static void viewVersion(String jid) {
final JPanel loadingCard = new JPanel();
final ImageIcon icon = new ImageIcon(VersionViewer.class.getClassLoader().getResource("images/ajax-loader.gif"));
loadingCard.add(new JLabel("loading... ", icon, JLabel.CENTER));
loadingCard.setVisible(true);
final JPanel dataCard = new JPanel();
dataCard.setVisible(false);
dataCard.setLayout(new GridBagLayout());
JLabel timeLabel = new JLabel();
JLabel softwareLabel = new JLabel();
JLabel versionLabel = new JLabel();
JLabel osLabel = new JLabel();
final JTextField timeField = new JTextField();
final JTextField softwareField = new JTextField();
final JTextField versionField = new JTextField();
final JTextField osField = new JTextField();
// Add resources
ResourceUtils.resLabel(timeLabel, timeField, Res.getString("label.local.time") + ":");
ResourceUtils.resLabel(softwareLabel, softwareField, Res.getString("label.software") + ":");
ResourceUtils.resLabel(versionLabel, versionField, Res.getString("label.version") + ":");
ResourceUtils.resLabel(osLabel, osField, Res.getString("label.os") + ":");
// Add Time Label
dataCard.add(timeLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
dataCard.add(timeField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
dataCard.add(softwareLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
dataCard.add(softwareField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
dataCard.add(versionLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
dataCard.add(versionField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
dataCard.add(osLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
dataCard.add(osField, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
osField.setEditable(false);
versionField.setEditable(false);
softwareField.setEditable(false);
timeField.setEditable(false);
final JPanel cards = new JPanel(new CardLayout());
cards.add(loadingCard);
cards.add(dataCard);
final XMPPConnection connection = SparkManager.getConnection();
try {
// Load Version
final Version versionRequest = new Version();
versionRequest.setType(IQ.Type.get);
versionRequest.setTo(jid);
connection.sendStanzaWithResponseCallback(versionRequest, new IQReplyFilter(versionRequest, connection), stanza -> {
final Version versionResult = (Version) stanza;
softwareField.setText(versionResult.getName());
versionField.setText(versionResult.getVersion());
osField.setText(versionResult.getOs());
((CardLayout) (cards.getLayout())).last(cards);
});
// Time
final Time time = new Time();
time.setType(IQ.Type.get);
time.setTo(jid);
connection.sendStanzaWithResponseCallback(time, new IQReplyFilter(time, connection), stanza -> {
;
timeField.setText(new SimpleDateFormat().format(((Time) stanza).getTime()));
((CardLayout) (cards.getLayout())).last(cards);
});
} catch (SmackException.NotConnectedException e) {
Log.warning("Unable to query for version.", e);
((CardLayout) (cards.getLayout())).last(cards);
}
MessageDialog.showComponent(Res.getString("title.version.and.time"), Res.getString("message.client.information", UserManager.unescapeJID(jid)), SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_24x24), cards, SparkManager.getMainWindow(), 400, 300, false);
}
use of org.jivesoftware.smack.filter.IQReplyFilter in project Spark by igniterealtime.
the class TransportUtils method unregister.
/**
* @param con the XMPPConnection.
* @param gatewayDomain the domain of the gateway (service name)
* @throws XMPPException thrown if there was an issue unregistering with the gateway.
*/
public static void unregister(XMPPConnection con, String gatewayDomain) throws SmackException.NotConnectedException {
Map<String, String> map = new HashMap<>();
map.put("remove", "");
Registration registration = new Registration(map);
registration.setType(IQ.Type.set);
registration.setTo(gatewayDomain);
con.sendStanzaWithResponseCallback(registration, new IQReplyFilter(registration, con), stanza -> {
IQ response = (IQ) stanza;
if (response.getType() == IQ.Type.error) {
Log.warning("Unable to unregister from gateway: " + stanza);
}
});
}
use of org.jivesoftware.smack.filter.IQReplyFilter in project Spark by igniterealtime.
the class TransportUtils method registerUser.
/**
* Registers a user with a gateway.
*
* @param con the XMPPConnection.
* @param gatewayDomain the domain of the gateway (service name)
* @param username the username.
* @param password the password.
* @param nickname the nickname.
* @throws XMPPException thrown if there was an issue registering with the gateway.
*/
public static void registerUser(XMPPConnection con, String gatewayDomain, String username, String password, String nickname, StanzaListener callback) throws SmackException.NotConnectedException {
Map<String, String> attributes = new HashMap<>();
if (username != null) {
attributes.put("username", username);
}
if (password != null) {
attributes.put("password", password);
}
if (nickname != null) {
attributes.put("nick", nickname);
}
Registration registration = new Registration(attributes);
registration.setType(IQ.Type.set);
registration.setTo(gatewayDomain);
registration.addExtension(new GatewayRegisterExtension());
con.sendStanzaWithResponseCallback(registration, new IQReplyFilter(registration, con), callback);
}
use of org.jivesoftware.smack.filter.IQReplyFilter in project Spark by igniterealtime.
the class CheckUpdates method getLatestVersion.
/**
* Returns the latest version of Spark available via Spark Manager or Jive Software.
*
* @param connection the XMPPConnection to use.
* @return the information for about the latest Spark Client.
* @throws XMPPException If unable to retrieve latest version.
*/
public static SparkVersion getLatestVersion(XMPPConnection connection) throws SmackException, XMPPException.XMPPErrorException {
SparkVersion request = new SparkVersion();
request.setType(IQ.Type.get);
request.setTo("updater." + connection.getServiceName());
PacketCollector collector = connection.createPacketCollector(new IQReplyFilter(request, connection));
connection.sendStanza(request);
SparkVersion response = collector.nextResult(SmackConfiguration.getDefaultPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw SmackException.NoResponseException.newWith(connection, collector);
}
XMPPException.XMPPErrorException.ifHasErrorThenThrow(response);
return response;
}
Aggregations