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);
}
}
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();
}
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);
}
});
}
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();
}
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;
}
Aggregations