Search in sources :

Example 16 with ContactList

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

the class FrequentContactsPlugin method showPopup.

/**
 * Displays your favorite contacts.
 */
private void showPopup() {
    // Get Transcript Directory
    if (!transcriptDir.exists()) {
        return;
    }
    jidMap.clear();
    model.clear();
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    for (final String user : getFavoriteContacts()) {
        ContactItem contactItem = contactList.getContactItemByJID(user);
        Icon icon;
        if (contactItem != null) {
            icon = contactItem.getIcon();
            if (icon == null) {
                icon = SparkRes.getImageIcon(SparkRes.CLEAR_BALL_ICON);
            }
            JLabel label = new JLabel();
            label.setText(contactItem.getDisplayName());
            label.setIcon(icon);
            model.addElement(label);
            jidMap.put(label, user);
        }
    }
    window.setSize(200, 200);
    GraphicUtils.centerWindowOnComponent(window, SparkManager.getMainWindow());
    if (model.size() > 0) {
        contacts.setSelectedIndex(0);
    }
    window.setVisible(true);
}
Also used : ContactItem(org.jivesoftware.spark.ui.ContactItem) JLabel(javax.swing.JLabel) ContactList(org.jivesoftware.spark.ui.ContactList) Icon(javax.swing.Icon)

Example 17 with ContactList

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

the class PhoneManager method addListeners.

private void addListeners() {
    // Handle ChatRooms.
    final ChatManager chatManager = SparkManager.getChatManager();
    chatManager.addChatRoomListener(this);
    // Handle ContextMenus.
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    contactList.addContextMenuListener(this);
}
Also used : ContactList(org.jivesoftware.spark.ui.ContactList) ChatManager(org.jivesoftware.spark.ChatManager)

Example 18 with ContactList

use of org.jivesoftware.spark.ui.ContactList 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 19 with ContactList

use of org.jivesoftware.spark.ui.ContactList 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 20 with ContactList

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

the class SparkTransferManager method sendFile.

/**
 * Send a file to a user.
 *
 * @param file the file to send.
 * @param jid  the jid of the user to send the file to.
 * @return the ChatRoom of the user.
 */
public ChatRoom sendFile(File file, String jid) {
    long maxsize = Long.parseLong(Default.getString(Default.FILE_TRANSFER_MAXIMUM_SIZE));
    long warningsize = Long.parseLong(Default.getString(Default.FILE_TRANSFER_WARNING_SIZE));
    if (file.length() >= maxsize && maxsize != -1) {
        String maxsizeString = TransferUtils.getAppropriateByteWithSuffix(maxsize);
        String yoursizeString = TransferUtils.getAppropriateByteWithSuffix(file.length());
        String output = Res.getString("message.file.transfer.file.too.big.error", maxsizeString, yoursizeString);
        UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
        JOptionPane.showMessageDialog(null, output, Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
        return null;
    }
    if (file.length() >= warningsize && warningsize != -1) {
        int result = JOptionPane.showConfirmDialog(null, Res.getString("message.file.transfer.file.too.big.warning"), Res.getString("title.error"), JOptionPane.YES_NO_OPTION);
        if (result != 0) {
            return null;
        }
    }
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    String bareJID = XmppStringUtils.parseBareJid(jid);
    String fullJID = PresenceManager.getFullyQualifiedJID(jid);
    if (!PresenceManager.isOnline(jid)) {
        ArrayList<File> list = waitMap.get(jid);
        if (list == null) {
            list = new ArrayList<>();
        }
        list.add(file);
        waitMap.put(jid, list);
        ChatRoom chatRoom;
        ContactItem contactItem = contactList.getContactItemByJID(jid);
        if (contactItem != null) {
            chatRoom = SparkManager.getChatManager().createChatRoom(jid, contactItem.getDisplayName(), contactItem.getDisplayName());
        } else {
            chatRoom = SparkManager.getChatManager().createChatRoom(jid, jid, jid);
        }
        chatRoom.getTranscriptWindow().insertNotificationMessage("The user is offline. Will auto-send \"" + file.getName() + "\" when user comes back online.", ChatManager.ERROR_COLOR);
        return null;
    }
    // Create the outgoing file transfer
    final OutgoingFileTransfer transfer = transferManager.createOutgoingFileTransfer(fullJID);
    ContactItem contactItem = contactList.getContactItemByJID(bareJID);
    ChatRoom chatRoom;
    if (contactItem != null) {
        chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, contactItem.getDisplayName(), contactItem.getDisplayName());
    } else {
        chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, bareJID, bareJID);
    }
    TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow();
    SendFileTransfer sendingUI = new SendFileTransfer();
    try {
        transfer.sendFile(file, "Sending file");
    } catch (SmackException e) {
        Log.error(e);
    }
    // Add listener to cancel transfer is sending file to user who just went offline.
    AndFilter presenceFilter = new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.createBare(bareJID));
    final StanzaListener packetListener = stanza -> {
        Presence presence = (Presence) stanza;
        if (!presence.isAvailable()) {
            if (transfer != null) {
                transfer.cancel();
            }
        }
    };
    // Add presence listener to check if user is offline and cancel sending.
    SparkManager.getConnection().addAsyncStanzaListener(packetListener, presenceFilter);
    chatRoom.addClosingListener(() -> {
        SparkManager.getConnection().removeAsyncStanzaListener(packetListener);
        if (!transfer.isDone()) {
            transfer.cancel();
        }
    });
    try {
        sendingUI.sendFile(transfer, transferManager, fullJID, contactItem.getDisplayName());
    } catch (NullPointerException e) {
        Log.error(e);
    }
    transcriptWindow.addComponent(sendingUI);
    chatRoom.scrollToBottom();
    return chatRoom;
}
Also used : OutgoingFileTransfer(org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer) Color(java.awt.Color) UIManager(javax.swing.UIManager) URL(java.net.URL) Cursor(java.awt.Cursor) URISyntaxException(java.net.URISyntaxException) StringUtils(org.jivesoftware.smack.util.StringUtils) Res(org.jivesoftware.resource.Res) Log(org.jivesoftware.spark.util.log.Log) TransferUtils(org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui.TransferUtils) ContactItem(org.jivesoftware.spark.ui.ContactItem) ResourceUtils(org.jivesoftware.spark.util.ResourceUtils) GraphicsEnvironment(java.awt.GraphicsEnvironment) FileDialog(java.awt.FileDialog) TranscriptWindow(org.jivesoftware.spark.ui.TranscriptWindow) Map(java.util.Map) MouseAdapter(java.awt.event.MouseAdapter) ImageIO(javax.imageio.ImageIO) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) MainWindow(org.jivesoftware.MainWindow) PreferenceManager(org.jivesoftware.spark.preference.PreferenceManager) URI(java.net.URI) FileTransferPreference(org.jivesoftware.spark.filetransfer.preferences.FileTransferPreference) Enterprise(org.jivesoftware.sparkimpl.plugin.manager.Enterprise) AndFilter(org.jivesoftware.smack.filter.AndFilter) FromMatchesFilter(org.jivesoftware.smack.filter.FromMatchesFilter) org.jivesoftware.smack(org.jivesoftware.smack) Frame(java.awt.Frame) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) ChatManager(org.jivesoftware.spark.ChatManager) FileTransferManager(org.jivesoftware.smackx.filetransfer.FileTransferManager) BufferedImage(java.awt.image.BufferedImage) SparkRes(org.jivesoftware.resource.SparkRes) SendFileTransfer(org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui.SendFileTransfer) JMenu(javax.swing.JMenu) ChatRoomListenerAdapter(org.jivesoftware.spark.ui.ChatRoomListenerAdapter) KeyEvent(java.awt.event.KeyEvent) ImageSelectionPanel(org.jivesoftware.spark.ui.ImageSelectionPanel) Spark(org.jivesoftware.Spark) List(java.util.List) AWTException(java.awt.AWTException) Toolkit(java.awt.Toolkit) Downloads(org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.Downloads) FileTransferRequest(org.jivesoftware.smackx.filetransfer.FileTransferRequest) Rectangle(java.awt.Rectangle) DataFlavor(java.awt.datatransfer.DataFlavor) ChatRoomButton(org.jivesoftware.spark.ui.ChatRoomButton) GraphicsDevice(java.awt.GraphicsDevice) Transferable(java.awt.datatransfer.Transferable) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) HashMap(java.util.HashMap) ReceiveFileTransfer(org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui.ReceiveFileTransfer) KeyAdapter(java.awt.event.KeyAdapter) ArrayList(java.util.ArrayList) SwingUtilities(javax.swing.SwingUtilities) Robot(java.awt.Robot) JMenuItem(javax.swing.JMenuItem) Default(org.jivesoftware.resource.Default) PresenceManager(org.jivesoftware.spark.PresenceManager) OutgoingFileTransfer(org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer) Desktop(java.awt.Desktop) Presence(org.jivesoftware.smack.packet.Presence) Iterator(java.util.Iterator) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) JOptionPane(javax.swing.JOptionPane) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) XmppStringUtils(org.jxmpp.util.XmppStringUtils) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) ContactList(org.jivesoftware.spark.ui.ContactList) SparkManager(org.jivesoftware.spark.SparkManager) InBandBytestreamManager(org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager) Message(org.jivesoftware.smack.packet.Message) ChatFrame(org.jivesoftware.spark.ui.ChatFrame) ContactItem(org.jivesoftware.spark.ui.ContactItem) SendFileTransfer(org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui.SendFileTransfer) ContactList(org.jivesoftware.spark.ui.ContactList) AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) TranscriptWindow(org.jivesoftware.spark.ui.TranscriptWindow) Presence(org.jivesoftware.smack.packet.Presence) File(java.io.File)

Aggregations

ContactList (org.jivesoftware.spark.ui.ContactList)20 ContactItem (org.jivesoftware.spark.ui.ContactItem)16 MouseEvent (java.awt.event.MouseEvent)10 MouseAdapter (java.awt.event.MouseAdapter)6 File (java.io.File)5 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)5 Color (java.awt.Color)4 Cursor (java.awt.Cursor)4 GridBagConstraints (java.awt.GridBagConstraints)4 Insets (java.awt.Insets)4 ActionEvent (java.awt.event.ActionEvent)4 MalformedURLException (java.net.MalformedURLException)4 AbstractAction (javax.swing.AbstractAction)4 Action (javax.swing.Action)4 JPopupMenu (javax.swing.JPopupMenu)4 Presence (org.jivesoftware.smack.packet.Presence)4 ContextMenuListener (org.jivesoftware.spark.plugin.ContextMenuListener)4 ContactGroup (org.jivesoftware.spark.ui.ContactGroup)4 IOException (java.io.IOException)3 URL (java.net.URL)3