Search in sources :

Example 1 with VCardManager

use of org.jivesoftware.sparkimpl.profile.VCardManager in project Spark by igniterealtime.

the class UserSearchResults method checkPopup.

private void checkPopup(MouseEvent e) {
    if (!e.isPopupTrigger()) {
        return;
    }
    // Get agent
    final int row = resultsTable.rowAtPoint(e.getPoint());
    final JPopupMenu menu = new JPopupMenu();
    Action addContactAction = new AbstractAction() {

        private static final long serialVersionUID = -6377937878941477145L;

        @Override
        public void actionPerformed(ActionEvent e) {
            RosterDialog dialog = new RosterDialog();
            String jid = (String) resultsTable.getValueAt(row, 0);
            TableColumn column = null;
            try {
                column = resultsTable.getColumn("Name");
            } catch (Exception ex) {
                try {
                    column = resultsTable.getColumn("Username");
                } catch (Exception e1) {
                // Nothing to do
                }
            }
            if (column != null) {
                int col = column.getModelIndex();
                String nickname = (String) resultsTable.getValueAt(row, col);
                if (!ModelUtil.hasLength(nickname)) {
                    nickname = XmppStringUtils.parseLocalpart(jid);
                }
                dialog.setDefaultNickname(nickname);
            }
            dialog.setDefaultJID(jid);
            dialog.showRosterDialog();
        }
    };
    Action chatAction = new AbstractAction() {

        private static final long serialVersionUID = 5651812282020177800L;

        @Override
        public void actionPerformed(ActionEvent e) {
            openChatRoom(row);
        }
    };
    Action profileAction = new AbstractAction() {

        private static final long serialVersionUID = -2014872840628217586L;

        @Override
        public void actionPerformed(ActionEvent e) {
            VCardManager vcardSupport = SparkManager.getVCardManager();
            String jidString = (String) resultsTable.getValueAt(row, 0);
            BareJid jid = JidCreate.bareFromOrThrowUnchecked(jidString);
            vcardSupport.viewProfile(jid, resultsTable);
        }
    };
    if (!Default.getBoolean(Default.ADD_CONTACT_DISABLED) && Enterprise.containsFeature(Enterprise.ADD_CONTACTS_FEATURE)) {
        final JMenuItem addAsContact = new JMenuItem(addContactAction);
        addContactAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_ADD_IMAGE));
        addContactAction.putValue(Action.NAME, Res.getString("menuitem.add.as.contact"));
        menu.add(addAsContact);
    }
    final JMenuItem chatMenu = new JMenuItem(chatAction);
    chatAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_IMAGE));
    chatAction.putValue(Action.NAME, Res.getString("menuitem.chat"));
    menu.add(chatMenu);
    final JMenuItem viewProfileMenu = new JMenuItem(profileAction);
    profileAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_PROFILE_IMAGE));
    profileAction.putValue(Action.NAME, Res.getString("menuitem.view.profile"));
    menu.add(viewProfileMenu);
    menu.show(resultsTable, e.getX(), e.getY());
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) EntityBareJid(org.jxmpp.jid.EntityBareJid) BareJid(org.jxmpp.jid.BareJid) ActionEvent(java.awt.event.ActionEvent) VCardManager(org.jivesoftware.sparkimpl.profile.VCardManager) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) RosterDialog(org.jivesoftware.spark.ui.RosterDialog)

Example 2 with VCardManager

use of org.jivesoftware.sparkimpl.profile.VCardManager in project Spark by igniterealtime.

the class UserManager method getNickname.

public String getNickname() {
    final VCardManager vCardManager = SparkManager.getVCardManager();
    VCard vcard = vCardManager.getVCard();
    if (vcard == null) {
        return SparkManager.getSessionManager().getUsername();
    } else {
        String nickname = vcard.getNickName();
        if (ModelUtil.hasLength(nickname)) {
            return nickname;
        } else {
            String firstName = vcard.getFirstName();
            if (ModelUtil.hasLength(firstName)) {
                return firstName;
            }
        }
    }
    // Default to node if nothing.
    String username = SparkManager.getSessionManager().getUsername();
    username = XmppStringUtils.unescapeLocalpart(username);
    return username;
}
Also used : VCardManager(org.jivesoftware.sparkimpl.profile.VCardManager) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard)

Example 3 with VCardManager

use of org.jivesoftware.sparkimpl.profile.VCardManager in project Spark by igniterealtime.

the class ChatRoomImpl method actionPerformed.

// I would normally use the command pattern, but
// have no real use when dealing with just a couple options.
@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == infoButton) {
        VCardManager vcard = SparkManager.getVCardManager();
        vcard.viewProfile(participantJID.asBareJid(), SparkManager.getChatManager().getChatContainer());
    } else if (e.getSource() == addToRosterButton) {
        RosterDialog rosterDialog = new RosterDialog();
        rosterDialog.setDefaultJID(participantJID.asBareJid().toString());
        rosterDialog.setDefaultNickname(getParticipantNickname().toString());
        rosterDialog.showRosterDialog(SparkManager.getChatManager().getChatContainer().getChatFrame());
    } else {
        super.actionPerformed(e);
    }
}
Also used : VCardManager(org.jivesoftware.sparkimpl.profile.VCardManager)

Example 4 with VCardManager

use of org.jivesoftware.sparkimpl.profile.VCardManager in project Spark by igniterealtime.

the class ContactList method showPopup.

/**
 * Shows popup for right-clicking of ContactItem.
 *
 * @param e    the MouseEvent
 * @param item the ContactItem
 * @param component the owning component
 */
public void showPopup(Component component, MouseEvent e, final ContactItem item) {
    if (item.getJid() == null) {
        return;
    }
    activeItem = item;
    final JPopupMenu popup = new JPopupMenu();
    // Add Start Chat Menu
    popup.add(chatMenu);
    // Add Send File Action
    Action sendAction = new AbstractAction() {

        private static final long serialVersionUID = -7519717310558205566L;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            SparkManager.getTransferManager().sendFileTo(item);
        }
    };
    // See if we should disable the option to transfer files and images
    if (!Default.getBoolean(Default.DISABLE_FILE_TRANSFER) && Enterprise.containsFeature(Enterprise.FILE_TRANSFER_FEATURE)) {
        sendAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.DOCUMENT_16x16));
        sendAction.putValue(Action.NAME, Res.getString("menuitem.send.a.file"));
        if (item.getPresence() != null)
            popup.add(sendAction);
    }
    popup.addSeparator();
    String groupName = item.getGroupName();
    ContactGroup contactGroup = getContactGroup(groupName);
    // Only show "Remove Contact From Group" if the user belongs to more than one group.
    if (!contactGroup.isSharedGroup() && !contactGroup.isOfflineGroup() && contactGroup != getUnfiledGroup()) {
        Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
        RosterEntry entry = roster.getEntry(item.getJid().asBareJid());
        if (entry != null) {
            int groupCount = entry.getGroups().size();
            // which would put them into the unfiled group.
            if (groupCount > 1) {
                popup.add(removeContactFromGroupMenu);
            }
        }
    }
    // Define remove entry action
    Action removeAction = new AbstractAction() {

        private static final long serialVersionUID = -2565914214685979320L;

        @Override
        public void actionPerformed(ActionEvent e) {
            removeContactFromRoster(item);
        }
    };
    removeAction.putValue(Action.NAME, Res.getString("menuitem.remove.from.roster"));
    removeAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_CIRCLE_DELETE));
    // Check if user is in shared group.
    boolean isInSharedGroup = false;
    for (ContactGroup cGroup : new ArrayList<>(getContactGroups())) {
        if (cGroup.isSharedGroup()) {
            ContactItem it = cGroup.getContactItemByJID(item.getJid().asBareJid());
            if (it != null) {
                isInSharedGroup = true;
            }
        }
    }
    // See if we should disable the option to remove a contact
    if (!Default.getBoolean(Default.DISABLE_REMOVALS) && Enterprise.containsFeature(Enterprise.REMOVALS_FEATURE)) {
        if (!contactGroup.isSharedGroup() && !isInSharedGroup)
            popup.add(removeAction);
    }
    // See if we should disable the option to rename a contact
    if (!Default.getBoolean(Default.DISABLE_RENAMES) && Enterprise.containsFeature(Enterprise.RENAMES_FEATURE))
        popup.add(renameMenu);
    Action viewProfile = new AbstractAction() {

        private static final long serialVersionUID = -2562731455090634805L;

        @Override
        public void actionPerformed(ActionEvent e) {
            VCardManager vcardSupport = SparkManager.getVCardManager();
            BareJid jid = item.getJid().asBareJid();
            vcardSupport.viewProfile(jid, SparkManager.getWorkspace());
        }
    };
    viewProfile.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_16x16));
    viewProfile.putValue(Action.NAME, Res.getString("menuitem.view.profile"));
    popup.add(viewProfile);
    popup.addSeparator();
    Action lastActivityAction = new AbstractAction() {

        private static final long serialVersionUID = -4884230635430933060L;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                String client = "";
                if (item.getPresence().getType() != Presence.Type.unavailable) {
                    client = item.getPresence().getFrom().toString();
                    if ((client != null) && (client.lastIndexOf("/") != -1)) {
                        client = client.substring(client.lastIndexOf("/"));
                    } else
                        client = "/";
                }
                Jid jid = JidCreate.from(item.getJid().toString() + client);
                LastActivity activity = LastActivityManager.getInstanceFor(SparkManager.getConnection()).getLastActivity(jid);
                long idleTime = (activity.getIdleTime() * 1000);
                String time = ModelUtil.getTimeFromLong(idleTime);
                UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                JOptionPane.showMessageDialog(getGUI(), Res.getString("message.idle.for", time), Res.getString("title.last.activity"), JOptionPane.INFORMATION_MESSAGE);
            } catch (Exception e1) {
                UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                JOptionPane.showMessageDialog(getGUI(), Res.getString("message.unable.to.retrieve.last.activity", item.getJid()), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
            }
        }
    };
    lastActivityAction.putValue(Action.NAME, Res.getString("menuitem.view.last.activity"));
    lastActivityAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.HISTORY_16x16));
    if (contactGroup == offlineGroup || item.getPresence().isAway() || (item.getPresence().getType() == Presence.Type.unavailable) || (item.getPresence().getType() == null)) {
        popup.add(lastActivityAction);
    }
    Action subscribeAction = new AbstractAction() {

        private static final long serialVersionUID = -7754905015338902300L;

        @Override
        public void actionPerformed(ActionEvent e) {
            BareJid jid = item.getJid();
            Presence response = new Presence(Presence.Type.subscribe);
            response.setTo(jid);
            try {
                SparkManager.getConnection().sendStanza(response);
            } catch (SmackException.NotConnectedException | InterruptedException e1) {
                Log.warning("Unable to send subscribe to " + jid, e1);
            }
        }
    };
    subscribeAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_USER1_INFORMATION));
    subscribeAction.putValue(Action.NAME, Res.getString("menuitem.subscribe.to"));
    Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
    RosterEntry entry = roster.getEntry(item.getJid().asBareJid());
    if (entry != null && entry.getType() == RosterPacket.ItemType.from) {
        popup.add(subscribeAction);
    } else if (entry != null && entry.getType() != RosterPacket.ItemType.both && entry.isSubscriptionPending()) {
        popup.add(subscribeAction);
    }
    // Fire Context Menu Listener
    fireContextMenuListenerPopup(popup, item);
    ContactGroup group = getContactGroup(item.getGroupName());
    if (component == null) {
        popup.show(group.getList(), e.getX(), e.getY());
    } else {
        popup.show(component, e.getX(), e.getY());
        popup.requestFocus();
    }
}
Also used : Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) BareJid(org.jxmpp.jid.BareJid) ActionEvent(java.awt.event.ActionEvent) VCardManager(org.jivesoftware.sparkimpl.profile.VCardManager) LastActivity(org.jivesoftware.smackx.iqlast.packet.LastActivity) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) IOException(java.io.IOException) Roster(org.jivesoftware.smack.roster.Roster) Presence(org.jivesoftware.smack.packet.Presence) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Aggregations

VCardManager (org.jivesoftware.sparkimpl.profile.VCardManager)4 ActionEvent (java.awt.event.ActionEvent)2 BareJid (org.jxmpp.jid.BareJid)2 IOException (java.io.IOException)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 TableColumn (javax.swing.table.TableColumn)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 Presence (org.jivesoftware.smack.packet.Presence)1 Roster (org.jivesoftware.smack.roster.Roster)1 RosterEntry (org.jivesoftware.smack.roster.RosterEntry)1 LastActivity (org.jivesoftware.smackx.iqlast.packet.LastActivity)1 VCard (org.jivesoftware.smackx.vcardtemp.packet.VCard)1 RosterDialog (org.jivesoftware.spark.ui.RosterDialog)1 EntityBareJid (org.jxmpp.jid.EntityBareJid)1 Jid (org.jxmpp.jid.Jid)1