Search in sources :

Example 26 with ContactItem

use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.

the class PrivacyAddDialogUI method createList.

private void createList() {
    _userList.clear();
    final Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
    if (_showGroups) {
        for (RosterGroup group : roster.getGroups()) {
            _showOffCheckbox.setVisible(false);
            ContactItem item = new ContactItem(group.getName(), null, group.getName());
            _userList.add(item);
        }
    } else {
        for (RosterEntry entry : roster.getEntries()) {
            Presence presence = PresenceManager.getPresence(entry.getUser());
            if (presence.isAvailable()) {
                ContactItem item = new ContactItem(entry.getName(), null, entry.getUser());
                item.setPresence(presence);
                _userList.add(item);
            } else if (_showOffCheckbox.isSelected()) {
                ContactItem item = new ContactItem(entry.getName(), null, entry.getUser());
                item.setPresence(presence);
                _userList.add(item);
            }
        }
    }
    Collections.sort(_userList, itemComparator);
    model.clear();
    for (ContactItem item : _userList) {
        model.addElement(item);
    }
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) ContactItem(org.jivesoftware.spark.ui.ContactItem) Presence(org.jivesoftware.smack.packet.Presence) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) RosterGroup(org.jivesoftware.smack.roster.RosterGroup)

Example 27 with ContactItem

use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.

the class PhoneManager method poppingUp.

public void poppingUp(Object object, final JPopupMenu popup) {
    if (!phones.isEmpty()) {
        if (object instanceof ContactItem) {
            final ContactItem contactItem = (ContactItem) object;
            final List<Action> actions = new ArrayList<>();
            SwingWorker worker = new SwingWorker() {

                public Object construct() {
                    for (Phone phone : phones) {
                        final Collection<Action> itemActions = phone.getPhoneActions(contactItem.getJID());
                        for (Action action : itemActions) {
                            actions.add(action);
                        }
                    }
                    return null;
                }

                public void finished() {
                    if (actions.size() > 0) {
                        final JMenu dialMenu = new JMenu(Res.getString("title.dial.phone"));
                        dialMenu.setIcon(SparkRes.getImageIcon(SparkRes.DIAL_PHONE_IMAGE_16x16));
                        for (Action action : actions) {
                            dialMenu.add(action);
                        }
                        int count = popup.getComponentCount();
                        if (count > 2) {
                            popup.insert(dialMenu, 2);
                        }
                        popup.invalidate();
                        popup.validate();
                        popup.repaint();
                    }
                }
            };
            worker.start();
        }
    }
}
Also used : Action(javax.swing.Action) ContactItem(org.jivesoftware.spark.ui.ContactItem) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) SwingWorker(org.jivesoftware.spark.util.SwingWorker) JMenu(javax.swing.JMenu)

Example 28 with ContactItem

use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.

the class UserManager method getUserNicknameFromJID.

public String getUserNicknameFromJID(String jid) {
    ContactList contactList = SparkManager.getWorkspace().getContactList();
    ContactItem item = contactList.getContactItemByJID(jid);
    if (item != null) {
        return item.getDisplayName();
    }
    return unescapeJID(jid);
}
Also used : ContactItem(org.jivesoftware.spark.ui.ContactItem) ContactList(org.jivesoftware.spark.ui.ContactList)

Example 29 with ContactItem

use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.

the class UserManager method getJIDFromDisplayName.

/**
 * Returns the full jid w/ resource of a user by their display name
 * in the ContactList.
 *
 * @param displayName the displayed name of the user.
 * @return the full jid w/ resource of the user.
 */
public String getJIDFromDisplayName(String displayName) {
    ContactList contactList = SparkManager.getWorkspace().getContactList();
    ContactItem item = contactList.getContactItemByDisplayName(displayName);
    if (item != null) {
        return getFullJID(item.getJID());
    }
    return null;
}
Also used : ContactItem(org.jivesoftware.spark.ui.ContactItem) ContactList(org.jivesoftware.spark.ui.ContactList)

Example 30 with ContactItem

use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.

the class Workspace method createOneToOneRoom.

/**
 * Creates a new room based on an anonymous user.
 *
 * @param bareJID the bareJID of the anonymous user.
 * @param message the message from the anonymous user.
 */
private void createOneToOneRoom(String bareJID, Message message) {
    ContactItem contact = contactList.getContactItemByJID(bareJID);
    String nickname = XmppStringUtils.parseLocalpart(bareJID);
    if (contact != null) {
        nickname = contact.getDisplayName();
    } else {
        // Attempt to load VCard from users who we are not subscribed to.
        VCard vCard = SparkManager.getVCardManager().getVCard(bareJID);
        if (vCard != null && vCard.getError() == null) {
            String firstName = vCard.getFirstName();
            String lastName = vCard.getLastName();
            String userNickname = vCard.getNickName();
            if (ModelUtil.hasLength(userNickname)) {
                nickname = userNickname;
            } else if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
                nickname = firstName + " " + lastName;
            } else if (ModelUtil.hasLength(firstName)) {
                nickname = firstName;
            }
        }
    }
    SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
    try {
        insertMessage(bareJID, message);
    } catch (ChatRoomNotFoundException e) {
        Log.error("Could not find chat room.", e);
    }
}
Also used : ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) ContactItem(org.jivesoftware.spark.ui.ContactItem) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard)

Aggregations

ContactItem (org.jivesoftware.spark.ui.ContactItem)34 ContactList (org.jivesoftware.spark.ui.ContactList)16 MouseEvent (java.awt.event.MouseEvent)10 Presence (org.jivesoftware.smack.packet.Presence)8 MouseAdapter (java.awt.event.MouseAdapter)7 ArrayList (java.util.ArrayList)7 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)7 File (java.io.File)6 SmackException (org.jivesoftware.smack.SmackException)6 SwingWorker (org.jivesoftware.spark.util.SwingWorker)6 GridBagConstraints (java.awt.GridBagConstraints)5 Insets (java.awt.Insets)5 MalformedURLException (java.net.MalformedURLException)5 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)5 ContactGroup (org.jivesoftware.spark.ui.ContactGroup)5 Color (java.awt.Color)4 Cursor (java.awt.Cursor)4 ActionEvent (java.awt.event.ActionEvent)4 Action (javax.swing.Action)4 IOException (java.io.IOException)3