Search in sources :

Example 36 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry in project Spark by igniterealtime.

the class ContactList method switchAllUserOfflineNoGroupEntry.

/**
 * Switches all Users to Offline and Creates an Icon in the CommandBar
 */
private synchronized void switchAllUserOfflineNoGroupEntry(final boolean onError) {
    SwingWorker worker = new SwingWorker() {

        @Override
        public Object construct() {
            _reconnectpanelicon.getPanel().add(_reconnectpanelicon.getButton(), 0);
            _reconnectpanelicon.getPanel().revalidate();
            _reconnectpanelicon.setClosedOnError(onError);
            final Collection<RosterEntry> roster = Roster.getInstanceFor(SparkManager.getConnection()).getEntries();
            for (RosterEntry r : roster) {
                Presence p = new Presence(Presence.Type.unavailable);
                moveToOfflineGroup(p, r.getUser());
            }
            return true;
        }
    };
    worker.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) Presence(org.jivesoftware.smack.packet.Presence) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Example 37 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry 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);
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) UserManager(org.jivesoftware.spark.UserManager) UIManager(javax.swing.UIManager) Insets(java.awt.Insets) ActionListener(java.awt.event.ActionListener) RosterPacket(org.jivesoftware.smack.roster.packet.RosterPacket) JTextField(javax.swing.JTextField) Res(org.jivesoftware.resource.Res) Transport(org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport) Log(org.jivesoftware.spark.util.log.Log) ResourceUtils(org.jivesoftware.spark.util.ResourceUtils) RosterGroup(org.jivesoftware.smack.roster.RosterGroup) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) RolloverButton(org.jivesoftware.spark.component.RolloverButton) JComponent(javax.swing.JComponent) KeyStroke(javax.swing.KeyStroke) Presence(org.jivesoftware.smack.packet.Presence) ModelUtil(org.jivesoftware.spark.util.ModelUtil) Frame(java.awt.Frame) BorderFactory(javax.swing.BorderFactory) Icon(javax.swing.Icon) JOptionPane(javax.swing.JOptionPane) GridBagConstraints(java.awt.GridBagConstraints) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) TitlePanel(org.jivesoftware.spark.component.TitlePanel) XmppStringUtils(org.jxmpp.util.XmppStringUtils) WindowEvent(java.awt.event.WindowEvent) Spark(org.jivesoftware.Spark) TransportUtils(org.jivesoftware.sparkimpl.plugin.gateways.transports.TransportUtils) Dimension(java.awt.Dimension) Roster(org.jivesoftware.smack.roster.Roster) SparkManager(org.jivesoftware.spark.SparkManager) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) GridBagLayout(java.awt.GridBagLayout) JPanel(javax.swing.JPanel) XMPPException(org.jivesoftware.smack.XMPPException) ComponentTitledBorder(org.jivesoftware.spark.component.borders.ComponentTitledBorder) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) SmackException(org.jivesoftware.smack.SmackException) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) TitlePanel(org.jivesoftware.spark.component.TitlePanel) Roster(org.jivesoftware.smack.roster.Roster) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) UserManager(org.jivesoftware.spark.UserManager) WindowEvent(java.awt.event.WindowEvent) KeyStroke(javax.swing.KeyStroke) Presence(org.jivesoftware.smack.packet.Presence) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) Icon(javax.swing.Icon) Transport(org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport)

Example 38 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry in project Spark by igniterealtime.

the class WorkgroupRosterTree method buildFromRoster.

private void buildFromRoster() {
    final Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
    roster.addRosterListener(new RosterListener() {

        public void rosterModified() {
        }

        public void entriesAdded(Collection collection) {
        }

        public void entriesUpdated(Collection collection) {
        }

        public void entriesDeleted(Collection collection) {
        }

        public void presenceChanged(Presence presence) {
            changePresence(presence.getFrom(), presence);
        }
    });
    for (RosterGroup group : roster.getGroups()) {
        if (workgroupList.contains(group.getName())) {
            continue;
        }
        final JiveTreeNode groupNode = new JiveTreeNode(group.getName(), true);
        groupNode.setAllowsChildren(true);
        if (group.getEntryCount() > 0) {
            rootNode.add(groupNode);
        }
        for (RosterEntry entry : group.getEntries()) {
            String name = entry.getName();
            if (name == null) {
                name = entry.getUser();
            }
            if (exclusionList.contains(entry.getUser())) {
                continue;
            }
            final JiveTreeNode entryNode = new JiveTreeNode(name, false);
            final Presence usersPresence = roster.getPresence(entry.getUser());
            addressMap.put(entryNode, entry.getUser());
            if (PresenceManager.isAvailable(usersPresence)) {
                groupNode.add(entryNode);
            } else if (showUnavailableAgents) {
                groupNode.add(entryNode);
            }
            changePresence(entry.getUser(), usersPresence);
            final DefaultTreeModel model = (DefaultTreeModel) rosterTree.getModel();
            model.nodeStructureChanged(groupNode);
        }
    }
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) JiveTreeNode(org.jivesoftware.spark.component.JiveTreeNode) Collection(java.util.Collection) Presence(org.jivesoftware.smack.packet.Presence) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) RosterListener(org.jivesoftware.smack.roster.RosterListener) RosterGroup(org.jivesoftware.smack.roster.RosterGroup)

Example 39 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry in project Zom-Android by zom.

the class XmppConnection method makeContact.

private Contact makeContact(String address) {
    Contact contact = null;
    // load from roster if we don't have the contact
    RosterEntry rEntry = null;
    try {
        if (mConnection != null)
            rEntry = mRoster.getEntry(JidCreate.bareFrom(address));
        if (rEntry != null) {
            XmppAddress xAddress = new XmppAddress(address);
            String name = rEntry.getName();
            if (name == null)
                name = xAddress.getUser();
            // TODO we should check the type from here
            contact = new Contact(xAddress, name, Imps.Contacts.TYPE_NORMAL);
        } else {
            XmppAddress xAddress = new XmppAddress(address);
            contact = new Contact(xAddress, xAddress.getUser(), Imps.Contacts.TYPE_NORMAL);
        }
    } catch (XmppStringprepException xe) {
    // nothing return null;
    }
    return contact;
}
Also used : RosterEntry(org.jivesoftware.smack.roster.RosterEntry) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Contact(org.awesomeapp.messenger.model.Contact)

Example 40 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry in project xabber-android by redsolution.

the class RosterManager method removeGroup.

/**
 * Requests to remove group from all contacts in account.
 */
public void removeGroup(AccountJid account, String groupName) throws NetworkException {
    final Roster roster = getRoster(account);
    if (roster == null) {
        return;
    }
    final org.jivesoftware.smack.roster.RosterGroup group = roster.getGroup(groupName);
    if (group == null) {
        return;
    }
    Application.getInstance().runInBackgroundUserRequest(new Runnable() {

        @Override
        public void run() {
            for (RosterEntry entry : group.getEntries()) {
                try {
                    group.removeEntry(entry);
                } catch (SmackException.NoResponseException e) {
                    Application.getInstance().onError(R.string.CONNECTION_FAILED);
                } catch (SmackException.NotConnectedException e) {
                    Application.getInstance().onError(R.string.NOT_CONNECTED);
                } catch (XMPPException.XMPPErrorException e) {
                    Application.getInstance().onError(R.string.XMPP_EXCEPTION);
                } catch (InterruptedException e) {
                    LogManager.exception(LOG_TAG, e);
                }
            }
        }
    });
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Aggregations

RosterEntry (org.jivesoftware.smack.roster.RosterEntry)45 Roster (org.jivesoftware.smack.roster.Roster)35 RosterGroup (org.jivesoftware.smack.roster.RosterGroup)17 SmackException (org.jivesoftware.smack.SmackException)14 Presence (org.jivesoftware.smack.packet.Presence)13 XMPPException (org.jivesoftware.smack.XMPPException)12 IOException (java.io.IOException)6 SwingWorker (org.jivesoftware.spark.util.SwingWorker)4 RosterPacket (org.jivesoftware.smack.roster.packet.RosterPacket)3 AccountItem (com.xabber.android.data.account.AccountItem)2 ConnectionItem (com.xabber.android.data.connection.ConnectionItem)2 java.awt (java.awt)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 KeyEvent (java.awt.event.KeyEvent)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 javax.swing (javax.swing)2 Icon (javax.swing.Icon)2