Search in sources :

Example 31 with ContactItem

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

the class JContactItemRenderer method getListCellRendererComponent.

@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    basicPanelRenderer.getListCellRendererComponent(list, this, index, isSelected, cellHasFocus);
    ContactItem renderItem = (ContactItem) value;
    setFocusable(false);
    setNickname(renderItem.getNickname());
    setAlias(renderItem.getAlias());
    if (this.getDisplayName().trim().isEmpty()) {
        // Fallback hack to show something other than empty string.
        // JID can't be set after object creation, so alias is reset.
        setAlias(renderItem.getDisplayName());
    }
    setIcon(renderItem.getIcon());
    setStatus(renderItem.getStatus());
    getNicknameLabel().setFont(renderItem.getNicknameLabel().getFont());
    getNicknameLabel().setForeground(renderItem.getNicknameLabel().getForeground());
    getDescriptionLabel().setFont(renderItem.getDescriptionLabel().getFont());
    getDescriptionLabel().setText(renderItem.getDescriptionLabel().getText());
    getSpecialImageLabel().setIcon(renderItem.getSpecialImageLabel().getIcon());
    getSideIcon().setIcon(renderItem.getSideIcon().getIcon());
    return this;
}
Also used : ContactItem(org.jivesoftware.spark.ui.ContactItem)

Example 32 with ContactItem

use of org.jivesoftware.spark.ui.ContactItem 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)

Example 33 with ContactItem

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

the class ContactInfoWindow method display.

public void display(ContactGroup group, MouseEvent e) {
    int loc = group.getList().locationToIndex(e.getPoint());
    ContactItem item = (ContactItem) group.getList().getModel().getElementAt(loc);
    if (item == null || item.getJID() == null) {
        return;
    }
    if (getContactItem() != null && getContactItem() == item) {
        return;
    }
    iconLabel.setIcon(item.getIcon());
    Point point = group.getList().indexToLocation(loc);
    window.setFocusableWindowState(false);
    setContactItem(item);
    window.pack();
    Point mainWindowLocation = SparkManager.getMainWindow().getLocationOnScreen();
    Point listLocation = group.getList().getLocationOnScreen();
    int x = (int) mainWindowLocation.getX() + SparkManager.getMainWindow().getWidth();
    int y = (int) listLocation.getY() + (int) point.getY();
    setWindowLocation(x, y);
    if (!window.isVisible()) {
        window.setVisible(true);
    }
}
Also used : ContactItem(org.jivesoftware.spark.ui.ContactItem) Point(java.awt.Point) Point(java.awt.Point)

Example 34 with ContactItem

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

the class VCardManager method reloadVCard.

/**
 * Forces a reload of a <code>VCard</code>. To load a VCard you should use
 * getVCard(String jid) instead. This method will perform a network lookup
 * which could take some time. If you're having problems with request
 * timeout you should also use getVCard(String jid). Use addToQueue(String
 * jid) if you want VCardManager to update the VCard by the given jid. The
 * method will block until the result is available or a timeout occurs.
 *
 * @param jid
 *            the jid of the user.
 *
 * @return the new network vCard or a vCard with an error
 */
public VCard reloadVCard(String jid) {
    jid = XmppStringUtils.parseBareJid(jid);
    VCard vcard = new VCard();
    try {
        vcard.setJabberId(jid);
        vcard.load(SparkManager.getConnection(), jid);
        if (vcard.getNickName() != null && vcard.getNickName().length() > 0) {
            // update nickname.
            ContactItem item = SparkManager.getWorkspace().getContactList().getContactItemByJID(jid);
            item.setNickname(vcard.getNickName());
        // TODO: this doesn't work if someone removes his nickname. If we remove it in that case, it will cause problems with people using another way to manage their nicknames.
        }
        addVCard(jid, vcard);
        persistVCard(jid, vcard);
    } catch (XMPPException | SmackException e) {
        // //System.out.println(jid+" Fehler in reloadVCard ----> null");
        vcard.setError(new XMPPError(XMPPError.Condition.resource_constraint));
        vcard.setJabberId(jid);
        delayedContacts.add(jid);
        return vcard;
    // We dont want cards with error
    // vcard.setError(new XMPPError(XMPPError.Condition.request_timeout));
    // addVCard(jid, vcard);
    }
    return vcard;
}
Also used : ContactItem(org.jivesoftware.spark.ui.ContactItem) SmackException(org.jivesoftware.smack.SmackException) XMPPError(org.jivesoftware.smack.packet.XMPPError) XMPPException(org.jivesoftware.smack.XMPPException) 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