Search in sources :

Example 1 with ContactItem

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

the class ContactListAssistantPlugin method moveItems.

/**
 * Moves a collection of <code>ContactItem</code>s to the specified group.
 *
 * @param contactItems the contact items to move.
 * @param groupName    the name of the group to move to.
 */
private void moveItems(Collection<ContactItem> contactItems, String groupName) {
    final ContactGroup contactGroup = getContactGroup(groupName);
    ContactGroup oldGroup;
    for (ContactItem contactItem : contactItems) {
        oldGroup = getContactGroup(contactItem.getGroupName());
        if (oldGroup.isSharedGroup()) {
            continue;
        }
        addContactItem(contactGroup, contactItem, true);
    }
}
Also used : ContactItem(org.jivesoftware.spark.ui.ContactItem) ContactGroup(org.jivesoftware.spark.ui.ContactGroup)

Example 2 with ContactItem

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

the class ContactListAssistantPlugin method addContactItem.

/**
 * Copies or moves a new <code>ContactItem</code> into the <code>ContactGroup</code>.
 *
 * @param contactGroup the ContactGroup.
 * @param item         the ContactItem to move.
 * @param move         true if the ContactItem should be moved, otherwise false.
 */
private void addContactItem(final ContactGroup contactGroup, final ContactItem item, final boolean move) {
    ContactItem newContact = UIComponentRegistry.createContactItem(item.getAlias(), item.getNickname(), item.getJID());
    newContact.setPresence(item.getPresence());
    newContact.setIcon(item.getIcon());
    newContact.getNicknameLabel().setFont(item.getNicknameLabel().getFont());
    boolean groupHadAvailableContacts = false;
    // Do not copy/move a contact item only if it is not already in the Group.
    if (contactGroup.getContactItemByJID(item.getJID(), true) != null) {
        return;
    }
    if (!PresenceManager.isOnline(item.getJID())) {
        contactGroup.addOfflineContactItem(item.getAlias(), item.getNickname(), item.getJID(), null);
    } else {
        groupHadAvailableContacts = contactGroup.hasAvailableContacts();
        contactGroup.addContactItem(newContact);
    }
    contactGroup.clearSelection();
    // Updating group title
    contactGroup.fireContactGroupUpdated();
    final ContactGroup oldGroup = getContactGroup(item.getGroupName());
    final boolean groupAvailableContacts = groupHadAvailableContacts;
    SwingWorker worker = new SwingWorker() {

        @Override
        public Object construct() {
            Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
            RosterEntry entry = roster.getEntry(item.getJID());
            RosterGroup groupFound = null;
            for (RosterGroup group : roster.getGroups()) {
                if (group.getName().equals(contactGroup.getGroupName())) {
                    try {
                        groupFound = group;
                        if (!groupAvailableContacts) {
                            SparkManager.getContactList().toggleGroupVisibility(groupFound.getName(), true);
                        }
                        group.addEntry(entry);
                    } catch (XMPPException | SmackException e1) {
                        Log.error(e1);
                        return false;
                    }
                }
            }
            // This is a new group
            if (groupFound == null) {
                groupFound = roster.createGroup(contactGroup.getGroupName());
                try {
                    groupFound.addEntry(entry);
                    if (!groupAvailableContacts) {
                        SparkManager.getContactList().toggleGroupVisibility(groupFound.getName(), true);
                    }
                } catch (XMPPException | SmackException e) {
                    Log.error(e);
                }
            }
            return true;
        }

        @Override
        public void finished() {
            if ((Boolean) get()) {
                // Now try and remove the group from the old one.
                if (move) {
                    removeContactItem(oldGroup, item);
                    if (!localPreferences.isEmptyGroupsShown() && !oldGroup.hasAvailableContacts()) {
                        SparkManager.getContactList().toggleGroupVisibility(oldGroup.getGroupName(), false);
                    }
                }
            }
        }
    };
    worker.start();
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) ContactItem(org.jivesoftware.spark.ui.ContactItem) SmackException(org.jivesoftware.smack.SmackException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) ContactGroup(org.jivesoftware.spark.ui.ContactGroup) XMPPException(org.jivesoftware.smack.XMPPException) RosterGroup(org.jivesoftware.smack.roster.RosterGroup)

Example 3 with ContactItem

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

the class ReceiveFileTransfer method acceptFileTransfer.

public void acceptFileTransfer(final FileTransferRequest request) {
    String fileName = request.getFileName();
    long fileSize = request.getFileSize();
    String requestor = request.getRequestor();
    String bareJID = XmppStringUtils.parseBareJid(requestor);
    // SPARK-1869
    FileTransferNegotiator.getInstanceFor(SparkManager.getConnection());
    FileTransferNegotiator.IBB_ONLY = SettingsManager.getLocalPreferences().isFileTransferIbbOnly();
    ByteFormat format = new ByteFormat();
    String text = format.format(fileSize);
    fileLabel.setText(fileName + " (" + text + ")");
    ContactList contactList = SparkManager.getWorkspace().getContactList();
    ContactItem contactItem = contactList.getContactItemByJID(bareJID);
    titleLabel.setText(Res.getString("message.user.is.sending.you.a.file", contactItem.getDisplayName()));
    File tempFile = new File(Spark.getSparkUserHome(), "/tmp");
    try {
        tempFile.mkdirs();
        File file = new File(tempFile, fileName);
        file.delete();
        BufferedWriter out = new BufferedWriter(new FileWriter(file));
        out.write("a");
        out.close();
        imageLabel.setIcon(GraphicUtils.getIcon(file));
        // Delete temp file when program exits.
        file.delete();
    } catch (IOException e) {
        imageLabel.setIcon(SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32));
        Log.error(e);
    }
    acceptButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            try {
                Downloads.checkDownloadDirectory();
                acceptRequest(request);
            } catch (Exception ex) {
                // this means there is a problem with the download directory
                try {
                    request.reject();
                } catch (SmackException.NotConnectedException e1) {
                    Log.warning("Unable to reject the request.", ex);
                }
                setBackground(new Color(239, 245, 250));
                acceptButton.setVisible(false);
                declineButton.setVisible(false);
                if (Downloads.getDownloadDirectory() == null) {
                    fileLabel.setText("");
                } else {
                    ResourceUtils.resLabel(fileLabel, null, Res.getString("label.transfer.download.directory") + " " + Downloads.getDownloadDirectory().getAbsolutePath());
                }
                // option to set a new path for the file-download
                pathButton.setVisible(true);
                pathButton.addMouseListener(new MouseAdapter() {

                    public void mousePressed(MouseEvent e) {
                        Preference p = SparkManager.getPreferenceManager().getPreference(new FileTransferPreference().getNamespace());
                        // retrieve the filetransfer preferences and show the preference menu
                        // to the user
                        SparkManager.getPreferenceManager().showPreferences(p);
                    }
                });
                titleLabel.setText(ex.getMessage());
                titleLabel.setForeground(new Color(65, 139, 179));
                invalidate();
                validate();
                repaint();
            }
        }
    });
    declineButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            rejectRequest(request);
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) ContactItem(org.jivesoftware.spark.ui.ContactItem) FileWriter(java.io.FileWriter) SmackException(org.jivesoftware.smack.SmackException) Color(java.awt.Color) MouseAdapter(java.awt.event.MouseAdapter) ContactList(org.jivesoftware.spark.ui.ContactList) IOException(java.io.IOException) FileTransferPreference(org.jivesoftware.spark.filetransfer.preferences.FileTransferPreference) SmackException(org.jivesoftware.smack.SmackException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) ByteFormat(org.jivesoftware.spark.util.ByteFormat) FileTransferPreference(org.jivesoftware.spark.filetransfer.preferences.FileTransferPreference) Preference(org.jivesoftware.spark.preference.Preference) File(java.io.File)

Example 4 with ContactItem

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

the class OutgoingCall method handleOutgoingCall.

/**
 * Handles a new outgoing call.
 *
 * @param session  the JingleSession for the outgoing call.
 * @param chatRoom the room the session is associated with.
 * @param jid      the users jid.
 */
public void handleOutgoingCall(final JingleSession session, ChatRoom chatRoom, final String jid) throws SmackException {
    this.chatRoom = chatRoom;
    JingleStateManager.getInstance().addJingleSession(chatRoom, JingleStateManager.JingleRoomState.ringing);
    chatRoom.addClosingListener(this);
    session.addListener(this);
    cancelButton.setVisible(true);
    this.session = session;
    // Start the call
    this.session.startOutgoing();
    fileLabel.setText(jid);
    ContactList contactList = SparkManager.getWorkspace().getContactList();
    ContactItem contactItem = contactList.getContactItemByJID(jid);
    titleLabel.setText(JingleResources.getString("label.outgoing.voicechat", contactItem.getNickname()));
    cancelButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            cancel();
        }

        public void mouseEntered(MouseEvent e) {
            cancelButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        }

        public void mouseExited(MouseEvent e) {
            cancelButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
    });
    makeClickable(imageLabel);
    makeClickable(titleLabel);
    // Notify state change
    SparkManager.getChatManager().notifySparkTabHandlers(chatRoom);
    updateOutgoingCallPanel();
}
Also used : MouseEvent(java.awt.event.MouseEvent) ContactItem(org.jivesoftware.spark.ui.ContactItem) MouseAdapter(java.awt.event.MouseAdapter) ContactList(org.jivesoftware.spark.ui.ContactList) Cursor(java.awt.Cursor)

Example 5 with ContactItem

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

the class VCardManager method getAvatar.

/**
 * Returns the URL of the avatar image associated with the users JID.
 *
 * @param jid the jid of the user.
 * @return the URL of the image. If not image is found, a default avatar is returned.
 */
public URL getAvatar(String jid) {
    // Handle own avatar file.
    if (jid != null && XmppStringUtils.parseBareJid(SparkManager.getSessionManager().getJID()).equals(XmppStringUtils.parseBareJid(jid))) {
        if (imageFile.exists()) {
            try {
                return imageFile.toURI().toURL();
            } catch (MalformedURLException e) {
                Log.error(e);
            }
        } else {
            return SparkRes.getURL(SparkRes.DUMMY_CONTACT_IMAGE);
        }
    }
    // Handle other users JID
    ContactItem item = SparkManager.getWorkspace().getContactList().getContactItemByJID(jid);
    URL avatarURL = null;
    if (item != null) {
        try {
            avatarURL = item.getAvatarURL();
        } catch (MalformedURLException e) {
            Log.error(e);
        }
    }
    if (avatarURL == null) {
        return SparkRes.getURL(SparkRes.DUMMY_CONTACT_IMAGE);
    }
    return avatarURL;
}
Also used : MalformedURLException(java.net.MalformedURLException) ContactItem(org.jivesoftware.spark.ui.ContactItem) URL(java.net.URL)

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