- Possibility added to update history records - provided by Damian Minkov.

- File transfer dates fixed.
- File transfer history improved.
- Check for active file transfers before closing the chat window.
cusax-fix
Yana Stamcheva 17 years ago
parent 206ea67e27
commit 71d51b2b03

@ -101,6 +101,7 @@ service.gui.CHAT_ROOMS=Chat rooms
service.gui.CHAT_ROOM_SUBJECT_CHANGED={0} has changed the subject to {1}
service.gui.CLOSE=Cl&ose
service.gui.CLOSE_CHAT_AFTER_NEW_MESSAGE=You have received a new message less than 2 seconds ago. Are you sure you want to close this chat?
service.gui.CLOSE_CHAT_ACTIVE_FILE_TRANSFER=You have active file transfers. Are you sure you want to cancel them?
service.gui.CONNECTING=Connecting...
service.gui.CONNECTION_FAILED_MSG=Connection failed for the following account: User name: {0}, Server name: {1}. Please check your network connection or contact your network administrator for more information.
service.gui.CONNECTION_EXPIRED_MSG=You are currently disconnected from the {0} server.

@ -36,7 +36,9 @@ public class FileHistoryServiceImpl
Logger.getLogger(FileHistoryServiceImpl.class);
private static String[] STRUCTURE_NAMES =
new String[] { "file", "dir", "date", "status"};
new String[] { "file", "dir", "date", "status", "id"};
private static final String FILE_TRANSFER_ACTIVE = "active";
private static HistoryRecordStructure recordStructure =
new HistoryRecordStructure(STRUCTURE_NAMES);
@ -220,6 +222,7 @@ private FileRecord createFileRecordFromHistoryRecord(
String dir = null;
long date = 0;
String status = null;
String id = null;
for (int i = 0; i < hr.getPropertyNames().length; i++)
{
@ -242,9 +245,11 @@ else if (propName.equals(STRUCTURE_NAMES[2]))
}
else if (propName.equals(STRUCTURE_NAMES[3]))
status = hr.getPropertyValues()[i];
else if (propName.equals(STRUCTURE_NAMES[4]))
id = hr.getPropertyValues()[i];
}
return new FileRecord(contact, dir, date, new File(file), status);
return new FileRecord(id, contact, dir, date, new File(file), status);
}
/**
@ -671,7 +676,7 @@ private History getHistory(Contact localContact, Contact remoteContact)
}
/**
* Listens for changes in filetransfers.
* Listens for changes in file transfers.
* @param event
*/
public void statusChanged(FileTransferStatusChangeEvent event)
@ -688,16 +693,14 @@ public void statusChanged(FileTransferStatusChangeEvent event)
History history = getHistory(null, ft.getContact());
HistoryWriter historyWriter = history.getWriter();
historyWriter.addRecord(new String[]{
ft.getFile().getCanonicalPath(),
getDirection(ft.getDirection()),
String.valueOf(new Date().getTime()),
status
});
} catch (IOException e)
historyWriter.updateRecord( STRUCTURE_NAMES[4],
ft.getID(),
STRUCTURE_NAMES[3],
status);
}
catch (IOException e)
{
logger.error("Could not add file transfer log to history", e);
logger.error("Could not update file transfer log to history", e);
}
}
@ -740,15 +743,58 @@ private static String getStatus(int status)
*/
public void fileTransferRequestReceived(FileTransferRequestEvent event)
{
try
{
IncomingFileTransferRequest req = event.getRequest();
History history = getHistory(null, req.getSender());
HistoryWriter historyWriter = history.getWriter();
historyWriter.addRecord(new String[]{
req.getFileName(),
getDirection(FileTransfer.IN),
String.valueOf(event.getTimestamp().getTime()),
FILE_TRANSFER_ACTIVE,
req.getID()
});
}
catch (IOException e)
{
logger.error("Could not add file transfer log to history", e);
}
}
/**
* New filetransfer was created.
* New file transfer was created.
* @param fileTransfer
*/
public void fileTransferCreated(FileTransfer fileTransfer)
public void fileTransferCreated(FileTransferCreatedEvent event)
{
FileTransfer fileTransfer = event.getFileTransfer();
fileTransfer.addStatusListener(this);
if(fileTransfer.getDirection() == FileTransfer.IN)
return;
try
{
History history = getHistory(null, fileTransfer.getContact());
HistoryWriter historyWriter = history.getWriter();
historyWriter.addRecord(new String[]{
fileTransfer.getFile().getCanonicalPath(),
getDirection(FileTransfer.OUT),
String.valueOf(event.getTimestamp().getTime()),
FILE_TRANSFER_ACTIVE,
fileTransfer.getID()
});
}
catch (IOException e)
{
logger.error("Could not add file transfer log to history", e);
}
}
/**

@ -9,6 +9,7 @@
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
@ -45,6 +46,8 @@ public abstract class ChatConversationComponent
protected static final ResourceManagementService resources
= GuiActivator.getResources();
private Date date;
/**
* Creates a <tt>ChatConversationComponent</tt>.
*/
@ -221,6 +224,27 @@ protected void openFile(File downloadFile)
}
}
/**
* Returns the date string to be used in order to show date and time in the
* chat conversation component.
* @param date the date to format
* @return the date string to be used in order to show date and time in the
* chat conversation component
*/
public String getDateString(Date date)
{
return ChatConversationPanel.getDateString(date.getTime())
+ GuiUtils.formatTime(date)
+ " ";
}
/**
* Returns the date of the component event.
*
* @return the date of the component event
*/
public abstract Date getDate();
/**
* Shows the given error message to the user. This method is made abstract
* in order to allow extension classes to provide custom implementations

@ -203,7 +203,7 @@ public String processMessage(ChatMessage chatMessage)
String msgHeaderID = "messageHeader";
String chatString = "";
String endHeaderTag = "";
String timeString = "";
String dateString = getDateString(date);
String startDivTag = "<DIV identifier=\"" + msgID + "\">";
String startHistoryDivTag
@ -226,14 +226,6 @@ public String processMessage(ChatMessage chatMessage)
endPlainTextTag = "</PLAINTEXT>";
}
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(date);
if (GuiUtils.compareDates(date, System.currentTimeMillis()) < 0)
{
timeString = GuiUtils.formatDate(date) + " ";
}
if (messageType.equals(Constants.INCOMING_MESSAGE))
{
this.lastIncomingMsgTimestamp = System.currentTimeMillis();
@ -245,7 +237,7 @@ public String processMessage(ChatMessage chatMessage)
endHeaderTag = "</h2>";
chatString += timeString + contactName + " at "
chatString += dateString + contactName + " at "
+ GuiUtils.formatTime(date) + endHeaderTag + startDivTag
+ startPlainTextTag + formatMessage(message, contentType)
+ endPlainTextTag + endDivTag;
@ -259,7 +251,7 @@ else if (messageType.equals(Constants.SMS_MESSAGE))
endHeaderTag = "</h2>";
chatString += "SMS: " + timeString + contactName + " at "
chatString += "SMS: " + dateString + contactName + " at "
+ GuiUtils.formatTime(date) + endHeaderTag + startDivTag
+ startPlainTextTag + formatMessage(message, contentType)
+ endPlainTextTag + endDivTag;
@ -273,7 +265,7 @@ else if (messageType.equals(Constants.OUTGOING_MESSAGE))
endHeaderTag = "</h3>";
chatString += timeString
chatString += dateString
+ GuiActivator.getResources()
.getI18NString("service.gui.ME")
+ " at " + GuiUtils.formatTime(date) + endHeaderTag
@ -338,7 +330,7 @@ else if (messageType.equals(Constants.HISTORY_INCOMING_MESSAGE))
endHeaderTag = "</h2>";
chatString += timeString + contactName + " at "
chatString += dateString + contactName + " at "
+ GuiUtils.formatTime(date) + endHeaderTag + startHistoryDivTag
+ startPlainTextTag + formatMessage(message, contentType)
+ endPlainTextTag + endDivTag;
@ -352,7 +344,7 @@ else if (messageType.equals(Constants.HISTORY_OUTGOING_MESSAGE))
endHeaderTag = "</h3>";
chatString += timeString
chatString += dateString
+ GuiActivator.getResources()
.getI18NString("service.gui.ME")
+ " at " + GuiUtils.formatTime(date) + endHeaderTag
@ -963,8 +955,8 @@ public Date getPageFirstMsgTimestamp()
if(firstMessageElement == null)
return new Date(Long.MAX_VALUE);
String dateString = (String)firstMessageElement
.getAttributes().getAttribute("date");
String dateString = firstMessageElement
.getAttributes().getAttribute("date").toString();
return new Date(Long.parseLong(dateString));
}
@ -1132,7 +1124,7 @@ public String getToolTipText(MouseEvent event)
*
* @param component the component to add at the end of the conversation.
*/
public void addComponent(Component component)
public void addComponent(ChatConversationComponent component)
{
Style style = document.getStyleSheet().addStyle(
StyleConstants.ComponentElementName,
@ -1147,6 +1139,22 @@ public void addComponent(Component component)
StyleConstants.ComponentAttribute,
component);
style.addAttribute(
"identifier",
"messageHeader");
style.addAttribute(
"date",
component.getDate().getTime());
style.addAttribute(
"identifier",
"messageHeader");
style.addAttribute(
"date",
component.getDate().getTime());
// Insert the component style at the end of the text
try
{
@ -1160,4 +1168,20 @@ public void addComponent(Component component)
this.setCarretToEnd();
}
/**
* Returns the date string to show for the given date.
*
* @param date the date to format
* @return the date string to show for the given date
*/
public static String getDateString(long date)
{
if (GuiUtils.compareDates(date, System.currentTimeMillis()) < 0)
{
return GuiUtils.formatDate(date) + " ";
}
return "";
}
}

@ -31,7 +31,6 @@
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.swing.*;
import net.java.sip.communicator.util.swing.SwingWorker;
/**
* The <tt>ChatPanel</tt> is the panel, where users can write and send messages,
@ -49,7 +48,8 @@ public class ChatPanel
extends TransparentPanel
implements ChatSessionRenderer,
Chat,
ChatConversationContainer
ChatConversationContainer,
FileTransferStatusListener
{
private static final Logger logger = Logger.getLogger(ChatPanel.class);
@ -106,6 +106,9 @@ public class ChatPanel
private boolean isHistoryLoaded;
private final ArrayList<String> activeFileTransfers
= new ArrayList<String>();
/**
* Creates a <tt>ChatPanel</tt> which is added to the given chat window.
*
@ -886,6 +889,13 @@ public Object construct()
final FileTransfer fileTransfer
= sendFileTransport.sendFile(file);
addActiveFileTransfer(fileTransfer.getID());
// Add the status listener that would notify us when the file
// transfer has been completed and should be removed from
// active components.
fileTransfer.addStatusListener(ChatPanel.this);
SwingUtilities.invokeLater(new Runnable()
{
public void run()
@ -1597,12 +1607,16 @@ public void setChatSubject(String subject)
* panel in order to notify the user of the incoming file.
*
* @param request the request to display in the conversation panel
* @param date the date on which the request has been received
*/
public void addIncomingFileTransferRequest(
IncomingFileTransferRequest request)
IncomingFileTransferRequest request,
Date date)
{
this.addActiveFileTransfer(request.getID());
ReceiveFileConversationComponent component
= new ReceiveFileConversationComponent(request);
= new ReceiveFileConversationComponent(this, request, date);
if (ConfigurationManager.isHistoryShown() && !isHistoryLoaded)
{
@ -1791,6 +1805,36 @@ public void fireChatFocusEvent(int eventID)
}
}
/**
* Handles file transfer status changed in order to remove completed file
* transfers from the list of active transfers.
*/
public void statusChanged(FileTransferStatusChangeEvent event)
{
FileTransfer fileTransfer = event.getFileTransfer();
int newStatus = event.getNewStatus();
if (newStatus == FileTransferStatusChangeEvent.COMPLETED
|| newStatus == FileTransferStatusChangeEvent.CANCELED
|| newStatus == FileTransferStatusChangeEvent.FAILED
|| newStatus == FileTransferStatusChangeEvent.REFUSED)
{
removeActiveFileTransfer(fileTransfer.getID());
}
}
/**
* Returns <code>true</code> if there are active file transfers, otherwise
* returns <code>false</code>.
* @return <code>true</code> if there are active file transfers, otherwise
* returns <code>false</code>
*/
public boolean containsActiveFileTransfers()
{
return !activeFileTransfers.isEmpty();
}
/**
* Returns the number of messages received but not yet read from the user.
*
@ -1839,13 +1883,39 @@ private void addIncomingEvents()
{
this.appendChatMessage((ChatMessage) incomingEvent);
}
else if (incomingEvent instanceof Component)
else if (incomingEvent instanceof ChatConversationComponent)
{
this.getChatConversationPanel()
.addComponent((Component) incomingEvent);
.addComponent((ChatConversationComponent)incomingEvent);
}
}
}
}
/**
* Adds the given file transfer <tt>id</tt> to the list of active file
* transfers.
*
* @param id the identifier of the file transfer to add
*/
private void addActiveFileTransfer(String id)
{
synchronized (activeFileTransfers)
{
activeFileTransfers.add(id);
}
}
/**
* Removes the given file transfer <tt>id</tt> from the list of active
* file transfers.
* @param id the identifier of the file transfer to remove
*/
private void removeActiveFileTransfer(String id)
{
synchronized (activeFileTransfers)
{
activeFileTransfers.remove(id);
}
}
}

@ -6,6 +6,10 @@
*/
package net.java.sip.communicator.impl.gui.main.chat;
import java.util.*;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
/**
@ -81,7 +85,9 @@ public void updateChatContactStatus(ChatContact chatContact,
* panel in order to notify the user of the incoming file.
*
* @param request the request to display in the conversation panel
* @param date the date on which the request has been received
*/
public void addIncomingFileTransferRequest(
IncomingFileTransferRequest request);
IncomingFileTransferRequest request,
Date date);
}

@ -166,7 +166,8 @@ public boolean isChatOpenedForChatRoom(ChatRoom chatRoom)
ChatRoomWrapper chatRoomWrapper
= (ChatRoomWrapper) descriptor;
if(chatRoomWrapper.getChatRoomID().equals(chatRoom.getIdentifier())
if(chatRoomWrapper.getChatRoomID()
.equals(chatRoom.getIdentifier())
&& getChat(chatSession).isShown())
{
return true;
@ -229,7 +230,26 @@ else if (System.currentTimeMillis() - chatWindow
if (answer == JOptionPane.OK_OPTION)
closeChatPanel(chatPanel);
}
else {
else if (chatPanel.containsActiveFileTransfers())
{
SIPCommMsgTextArea msgText
= new SIPCommMsgTextArea(GuiActivator.getResources()
.getI18NString(
"service.gui.CLOSE_CHAT_ACTIVE_FILE_TRANSFER"));
int answer = JOptionPane.showConfirmDialog(
chatWindow,
msgText,
GuiActivator.getResources()
.getI18NString("service.gui.WARNING"),
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if (answer == JOptionPane.OK_OPTION)
closeChatPanel(chatPanel);
}
else
{
closeChatPanel(chatPanel);
}
}
@ -244,9 +264,27 @@ public void closeWindow(ChatWindow chatWindow)
{
synchronized (syncChat)
{
ChatPanel chatPanel = chatWindow.getCurrentChatPanel();
ChatPanel activePanel = null;
for (ChatPanel chatPanel : chatPanels)
{
if (!chatPanel.isWriteAreaEmpty()
|| chatPanel.containsActiveFileTransfers()
|| System.currentTimeMillis() - chatWindow
.getLastIncomingMsgTimestamp(chatPanel) < 2 * 1000)
{
activePanel = chatPanel;
break;
}
}
if (!chatPanel.isWriteAreaEmpty())
if (activePanel == null)
{
this.disposeChatWindow(chatWindow);
return;
}
if (!activePanel.isWriteAreaEmpty())
{
SIPCommMsgTextArea msgText = new SIPCommMsgTextArea(
GuiActivator.getResources().getI18NString(
@ -265,7 +303,7 @@ public void closeWindow(ChatWindow chatWindow)
}
}
else if (System.currentTimeMillis() - chatWindow
.getLastIncomingMsgTimestamp(chatPanel) < 2 * 1000)
.getLastIncomingMsgTimestamp(activePanel) < 2 * 1000)
{
SIPCommMsgTextArea msgText = new SIPCommMsgTextArea(
GuiActivator.getResources()
@ -283,9 +321,23 @@ else if (System.currentTimeMillis() - chatWindow
this.disposeChatWindow(chatWindow);
}
}
else
else if (activePanel.containsActiveFileTransfers())
{
this.disposeChatWindow(chatWindow);
SIPCommMsgTextArea msgText
= new SIPCommMsgTextArea(GuiActivator.getResources()
.getI18NString(
"service.gui.CLOSE_CHAT_ACTIVE_FILE_TRANSFER"));
int answer = JOptionPane.showConfirmDialog(
chatWindow,
msgText,
GuiActivator.getResources()
.getI18NString("service.gui.WARNING"),
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if (answer == JOptionPane.OK_OPTION)
this.disposeChatWindow(chatWindow);
}
}
}

@ -15,6 +15,7 @@
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.contactlist.event.*;
import net.java.sip.communicator.service.filehistory.*;
import net.java.sip.communicator.service.metahistory.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
@ -218,16 +219,22 @@ public long getHistoryStartDate()
if(o instanceof MessageDeliveredEvent)
{
MessageDeliveredEvent evt
= (MessageDeliveredEvent)o;
= (MessageDeliveredEvent) o;
startHistoryDate = evt.getTimestamp();
}
else if(o instanceof MessageReceivedEvent)
{
MessageReceivedEvent evt = (MessageReceivedEvent)o;
MessageReceivedEvent evt = (MessageReceivedEvent) o;
startHistoryDate = evt.getTimestamp();
}
else if (o instanceof FileRecord)
{
FileRecord fileRecord = (FileRecord) o;
startHistoryDate = fileRecord.getDate();
}
}
return startHistoryDate;
@ -264,16 +271,22 @@ public long getHistoryEndDate()
if(o1 instanceof MessageDeliveredEvent)
{
MessageDeliveredEvent evt
= (MessageDeliveredEvent)o1;
= (MessageDeliveredEvent) o1;
endHistoryDate = evt.getTimestamp();
}
else if(o1 instanceof MessageReceivedEvent)
{
MessageReceivedEvent evt = (MessageReceivedEvent)o1;
MessageReceivedEvent evt = (MessageReceivedEvent) o1;
endHistoryDate = evt.getTimestamp();
}
else if (o1 instanceof FileRecord)
{
FileRecord fileRecord = (FileRecord) o1;
endHistoryDate = fileRecord.getDate();
}
}
return endHistoryDate;

@ -6,6 +6,8 @@
*/
package net.java.sip.communicator.impl.gui.main.chat.filetransfer;
import java.util.*;
import net.java.sip.communicator.service.filehistory.*;
/**
@ -17,8 +19,12 @@
public class FileHistoryConversationComponent
extends FileTransferConversationComponent
{
private final FileRecord fileRecord;
public FileHistoryConversationComponent(FileRecord fileRecord)
{
this.fileRecord = fileRecord;
String contactName = fileRecord.getContact().getDisplayName();
String titleString = "";
@ -92,9 +98,22 @@ else if (fileRecord.getStatus().equals(FileRecord.REFUSED))
this.setCompletedDownloadFile(fileRecord.getFile());
titleLabel.setText(titleString);
long date = fileRecord.getDate();
titleLabel.setText(
getDateString(new Date(date)) + titleString);
fileLabel.setText(getFileName(fileRecord.getFile()));
openFileButton.setVisible(true);
openFolderButton.setVisible(true);
}
/**
* Returns the date of the component event.
*
* @return the date of the component event
*/
public Date getDate()
{
return new Date(fileRecord.getDate());
}
}

@ -8,8 +8,10 @@
import java.awt.event.*;
import java.io.*;
import java.util.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@ -32,6 +34,12 @@ public class ReceiveFileConversationComponent
private final IncomingFileTransferRequest fileTransferRequest;
private final ChatPanel chatPanel;
private final Date date;
private final String dateString;
/**
* Creates a <tt>ReceiveFileConversationComponent</tt>.
*
@ -39,11 +47,18 @@ public class ReceiveFileConversationComponent
* associated with this component
*/
public ReceiveFileConversationComponent(
final IncomingFileTransferRequest request)
ChatPanel chatPanel,
final IncomingFileTransferRequest request,
final Date date)
{
this.chatPanel = chatPanel;
this.fileTransferRequest = request;
this.date = date;
this.dateString = getDateString(date);
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_TRANSFER_REQUEST_RECIEVED",
new String[]{fileTransferRequest.getSender().getDisplayName()}));
@ -54,7 +69,9 @@ public ReceiveFileConversationComponent(
{
public void actionPerformed(ActionEvent e)
{
titleLabel.setText(resources
titleLabel.setText(
dateString
+ resources
.getI18NString("service.gui.FILE_TRANSFER_PREPARING",
new String[]{fileTransferRequest.getSender()
.getDisplayName()}));
@ -80,7 +97,8 @@ public void actionPerformed(ActionEvent e)
rejectButton.setVisible(false);
fileLabel.setText("");
titleLabel.setText(
resources.getI18NString(
dateString
+ resources.getI18NString(
"service.gui.FILE_TRANSFER_CANCELED"));
}
});
@ -154,14 +172,18 @@ public void statusChanged(FileTransferStatusChangeEvent event)
if (status == FileTransferStatusChangeEvent.PREPARING)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_TRANSFER_PREPARING",
new String[]{fromContactName}));
}
else if (status == FileTransferStatusChangeEvent.FAILED)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_RECEIVE_FAILED",
new String[]{fromContactName}));
@ -169,7 +191,9 @@ else if (status == FileTransferStatusChangeEvent.FAILED)
}
else if (status == FileTransferStatusChangeEvent.IN_PROGRESS)
{
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_RECEIVING_FROM",
new String[]{fromContactName}));
setWarningStyle(false);
@ -188,7 +212,9 @@ else if (status == FileTransferStatusChangeEvent.COMPLETED)
openFileButton.setVisible(true);
openFolderButton.setVisible(true);
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_RECEIVE_COMPLETED",
new String[]{fromContactName}));
}
@ -197,14 +223,18 @@ else if (status == FileTransferStatusChangeEvent.CANCELED)
progressBar.setVisible(false);
cancelButton.setVisible(false);
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_TRANSFER_CANCELED"));
setWarningStyle(true);
}
else if (status == FileTransferStatusChangeEvent.REFUSED)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_TRANSFER_REFUSED",
new String[]{fromContactName}));
cancelButton.setVisible(false);
@ -212,6 +242,16 @@ else if (status == FileTransferStatusChangeEvent.REFUSED)
}
}
/**
* Returns the date of the component event.
*
* @return the date of the component event
*/
public Date getDate()
{
return date;
}
/**
* Accepts the file in a new thread.
*/
@ -230,6 +270,14 @@ public Object construct()
{
fileTransfer = fileTransferRequest.acceptFile(downloadFile);
// Add the status listener that would notify us when the file
// transfer has been completed and should be removed from
// active components.
fileTransfer.addStatusListener(chatPanel);
fileTransfer.addStatusListener(
ReceiveFileConversationComponent.this);
return "";
}
@ -238,9 +286,6 @@ public void finished()
if (fileTransfer != null)
{
setFileTransfer(fileTransfer);
fileTransfer.addStatusListener(
ReceiveFileConversationComponent.this);
}
}
}

@ -8,6 +8,7 @@
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
@ -29,6 +30,10 @@ public class SendFileConversationComponent
private final ChatPanel parentChatPanel;
private final Date date;
private final String dateString;
/**
* Creates a <tt>SendFileConversationComponent</tt> by specifying the parent
* chat panel, where this component is added, the destination contact of
@ -45,11 +50,17 @@ public SendFileConversationComponent( ChatPanel chatPanel,
this.parentChatPanel = chatPanel;
this.toContactName = toContactName;
// Create the date that would be shown in the component.
this.date = new Date();
this.dateString = getDateString(date);
this.setCompletedDownloadFile(file);
titleLabel.setText(resources.getI18NString(
"service.gui.FILE_WAITING_TO_ACCEPT",
new String[]{toContactName}));
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_WAITING_TO_ACCEPT",
new String[]{toContactName}));
fileLabel.setText(getFileName(file));
@ -98,7 +109,9 @@ public void statusChanged(FileTransferStatusChangeEvent event)
if (status == FileTransferStatusChangeEvent.PREPARING)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_TRANSFER_PREPARING",
new String[]{toContactName}));
cancelButton.setVisible(true);
@ -107,7 +120,9 @@ public void statusChanged(FileTransferStatusChangeEvent event)
else if (status == FileTransferStatusChangeEvent.FAILED)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_UNABLE_TO_SEND",
new String[]{toContactName}));
cancelButton.setVisible(false);
@ -116,7 +131,9 @@ else if (status == FileTransferStatusChangeEvent.FAILED)
}
else if (status == FileTransferStatusChangeEvent.IN_PROGRESS)
{
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_SENDING_TO",
new String[]{toContactName}));
setWarningStyle(false);
@ -129,7 +146,9 @@ else if (status == FileTransferStatusChangeEvent.IN_PROGRESS)
else if (status == FileTransferStatusChangeEvent.COMPLETED)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_SEND_COMPLETED",
new String[]{toContactName}));
cancelButton.setVisible(false);
@ -138,7 +157,9 @@ else if (status == FileTransferStatusChangeEvent.COMPLETED)
else if (status == FileTransferStatusChangeEvent.CANCELED)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_TRANSFER_CANCELED"));
cancelButton.setVisible(false);
retryButton.setVisible(true);
@ -147,7 +168,9 @@ else if (status == FileTransferStatusChangeEvent.CANCELED)
else if (status == FileTransferStatusChangeEvent.REFUSED)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_SEND_REFUSED",
new String[]{toContactName}));
cancelButton.setVisible(false);
@ -155,4 +178,14 @@ else if (status == FileTransferStatusChangeEvent.REFUSED)
setWarningStyle(true);
}
}
/**
* Returns the date of the component event.
*
* @return the date of the component event
*/
public Date getDate()
{
return date;
}
}

@ -586,7 +586,7 @@ public void fileTransferRequestReceived(FileTransferRequestEvent event)
final ChatPanel chatPanel = chatWindowManager
.getContactChat(metaContact, sourceContact);
chatPanel.addIncomingFileTransferRequest(request);
chatPanel.addIncomingFileTransferRequest(request, event.getTimestamp());
ChatTransport chatTransport
= chatPanel.getChatSession()
@ -619,7 +619,7 @@ public void run()
* Nothing to do here, because we already know when a file transfer is
* created.
*/
public void fileTransferCreated(FileTransfer fileTransfer)
public void fileTransferCreated(FileTransferCreatedEvent event)
{}
/**

@ -11,14 +11,17 @@
import java.util.*;
import org.w3c.dom.*;
import net.java.sip.communicator.service.history.*;
import net.java.sip.communicator.service.history.records.*;
import net.java.sip.communicator.util.xml.*;
/**
* @author Alexander Pelov
*/
public class HistoryWriterImpl implements HistoryWriter {
public class HistoryWriterImpl
implements HistoryWriter
{
public static final int MAX_RECORDS_PER_FILE = 150;
private static final String CDATA_SUFFIX = "_CDATA";
@ -204,4 +207,91 @@ private void createNewDoc(Date date, boolean loadLastFile)
.getChildNodes().getLength();
}
/**
* Updates a record by searching for record with idProperty which have idValue
* and updating/creating the property with newValue.
*
* @param idProperty name of the id property
* @param idValue value of the id property
* @param property the property to change
* @param newValue the value of the changed property.
*/
public void updateRecord(String idProperty, String idValue,
String property, String newValue)
throws IOException
{
Iterator<String> fileIterator = this.historyImpl.getFileList();
while (fileIterator.hasNext())
{
String filename = fileIterator.next();
Document doc = this.historyImpl.getDocumentForFile(filename);
if(doc == null)
continue;
NodeList nodes = doc.getElementsByTagName("record");
boolean changed = false;
Node node;
for (int i = 0; i < nodes.getLength(); i++)
{
node = nodes.item(i);
Element idNode = XMLUtils.findChild((Element)node, idProperty);
if(idNode == null)
continue;
Node nestedNode = idNode.getFirstChild();
if(nestedNode == null)
continue;
// Get nested TEXT node's value
String nodeValue = nestedNode.getNodeValue();
if(!nodeValue.equals(idValue))
continue;
Element changedNode =
XMLUtils.findChild((Element)node, property);
if(changedNode != null)
{
Node changedNestedNode = changedNode.getFirstChild();
changedNestedNode.setNodeValue(newValue);
}
else
{
Element propertyElement = this.currentDoc
.createElement(property);
Text value = this.currentDoc
.createTextNode(newValue.replaceAll("\0", " "));
propertyElement.appendChild(value);
node.appendChild(propertyElement);
}
changed = true;
break;
}
if(changed)
{
// write changes
synchronized (this.docWriteLock)
{
if(historyImpl.getHistoryServiceImpl().isCacheEnabled())
this.historyImpl.writeFile(filename);
else
this.historyImpl.writeFile(filename, doc);
}
break;
}
}
}
}

@ -20,19 +20,31 @@
public class IncomingFileTransferJabberImpl
extends AbstractFileTransfer
{
private String id = null;
private Contact sender = null;
private File file = null;
/**
* The jabber incoming file transfer.
* The Jabber incoming file transfer.
*/
private IncomingFileTransfer jabberTransfer;
public IncomingFileTransferJabberImpl(Contact sender,
File file,
IncomingFileTransfer jabberTransfer)
/**
* Creates an <tt>IncomingFileTransferJabberImpl</tt>.
*
* @param sender the sender of the file
* @param file the file
* @param date the date on which the request was received
* @param jabberTransfer the Jabber file transfer object
*/
public IncomingFileTransferJabberImpl( String id,
Contact sender,
File file,
IncomingFileTransfer jabberTransfer)
{
this.jabberTransfer = jabberTransfer;
this.id = id;
this.sender = sender;
this.file = file;
}
@ -48,7 +60,7 @@ public void cancel()
/**
* Returns the number of bytes already received from the recipient.
*
* @return the number of bytes already received from the recipient.
* @return the number of bytes already received from the recipient
*/
public long getTransferedBytes()
{
@ -57,7 +69,8 @@ public long getTransferedBytes()
/**
* The direction is incoming.
* @return IN.
*
* @return IN
*/
public int getDirection()
{
@ -66,15 +79,31 @@ public int getDirection()
/**
* The file we are receiving.
* @return the file.
*
* @return file we are receiving
*/
public File getFile()
{
return file;
}
/**
* Returns the sender of the file.
*
* @return the sender of the file
*/
public Contact getContact()
{
return sender;
}
/**
* Returns the identifier of this file transfer.
*
* @return the identifier of this file transfer
*/
public String getID()
{
return id;
}
}

@ -7,6 +7,7 @@
package net.java.sip.communicator.impl.protocol.jabber;
import java.io.File;
import java.util.*;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.util.*;
@ -14,6 +15,7 @@
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.FileTransfer;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.Logger;
/**
@ -31,6 +33,8 @@ public class IncomingFileTransferRequestJabberImpl
private static final Logger logger =
Logger.getLogger(IncomingFileTransferRequestJabberImpl.class);
private String id;
/**
* The Jabber file transfer request.
*/
@ -47,11 +51,13 @@ public class IncomingFileTransferRequestJabberImpl
* @param jabberProvider the protocol provider
* @param fileTransferOpSet file transfer operation set
* @param fileTransferRequest the request coming from the Jabber protocol
* @param date the date on which this request was received
*/
public IncomingFileTransferRequestJabberImpl(
ProtocolProviderServiceJabberImpl jabberProvider,
OperationSetFileTransferJabberImpl fileTransferOpSet,
FileTransferRequest fileTransferRequest)
FileTransferRequest fileTransferRequest,
Date date)
{
this.fileTransferOpSet = fileTransferOpSet;
this.fileTransferRequest = fileTransferRequest;
@ -65,6 +71,9 @@ public IncomingFileTransferRequestJabberImpl(
OperationSetPersistentPresence.class);
sender = opSetPersPresence.findContactByID(fromUserID);
this.id = String.valueOf( System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
@ -122,9 +131,12 @@ public FileTransfer acceptFile(File file)
{
incomingTransfer
= new IncomingFileTransferJabberImpl(
sender, file, jabberTransfer);
id, sender, file, jabberTransfer);
fileTransferOpSet.fireFileTransferCreated(incomingTransfer);
FileTransferCreatedEvent event
= new FileTransferCreatedEvent(incomingTransfer, new Date());
fileTransferOpSet.fireFileTransferCreated(event);
jabberTransfer.recieveFile(file);
@ -147,4 +159,13 @@ public void rejectFile()
{
fileTransferRequest.reject();
}
/**
* The unique id.
* @return the id.
*/
public String getID()
{
return id;
}
}

@ -102,11 +102,15 @@ public FileTransfer sendFile( Contact toContact,
= manager.createOutgoingFileTransfer(presence.getFrom());
outgoingTransfer
= new OutgoingFileTransferJabberImpl(toContact, file, transfer);
= new OutgoingFileTransferJabberImpl(
toContact, file, transfer);
// Notify all interested listeners that a file transfer has been
// created.
fireFileTransferCreated(outgoingTransfer);
FileTransferCreatedEvent event
= new FileTransferCreatedEvent(outgoingTransfer, new Date());
fireFileTransferCreated(event);
// Send the file through the Jabber file transfer.
transfer.sendFile(file, "Sending file.");
@ -256,17 +260,21 @@ public void fileTransferRequest(FileTransferRequest request)
{
logger.debug("Incoming Jabber file transfer request.");
// Create the date on which the request was received.
Date requestDate = new Date();
// Create a global incoming file transfer request.
IncomingFileTransferRequest incomingFileTransferRequest
= new IncomingFileTransferRequestJabberImpl(
jabberProvider,
OperationSetFileTransferJabberImpl.this,
request);
request,
requestDate);
// Create an event associated to this global request.
FileTransferRequestEvent fileTransferRequestEvent
= new FileTransferRequestEvent( incomingFileTransferRequest,
new Date());
requestDate);
// Notify the global listener that a request has arrived.
fireFileTransferRequest(fileTransferRequestEvent);
@ -302,7 +310,7 @@ private void fireFileTransferRequest(FileTransferRequestEvent event)
* @param fileTransfer the <tt>FileTransfer</tt> that we'd like delivered to
* all registered file transfer listeners.
*/
void fireFileTransferCreated(FileTransfer fileTransfer)
void fireFileTransferCreated(FileTransferCreatedEvent event)
{
Iterator<FileTransferListener> listeners = null;
synchronized (fileTransferListeners)
@ -315,7 +323,7 @@ void fireFileTransferCreated(FileTransfer fileTransfer)
{
FileTransferListener listener = listeners.next();
listener.fileTransferCreated(fileTransfer);
listener.fileTransferCreated(event);
}
}

@ -20,9 +20,12 @@
public class OutgoingFileTransferJabberImpl
extends AbstractFileTransfer
{
private String id;
private Contact receiver;
private File file;
/**
* The jabber outgoing file transfer.
*/
@ -35,13 +38,16 @@ public class OutgoingFileTransferJabberImpl
* @param jabberTransfer the Jabber transfer object, containing all transfer
* information
*/
public OutgoingFileTransferJabberImpl(Contact receiver,
File file,
OutgoingFileTransfer jabberTransfer)
public OutgoingFileTransferJabberImpl( Contact receiver,
File file,
OutgoingFileTransfer jabberTransfer)
{
this.jabberTransfer = jabberTransfer;
this.receiver = receiver;
this.file = file;
this.id = String.valueOf( System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
@ -88,4 +94,13 @@ public Contact getContact()
{
return receiver;
}
/**
* The unique id.
* @return the id.
*/
public String getID()
{
return id;
}
}

@ -7,6 +7,8 @@
package net.java.sip.communicator.impl.protocol.ssh;
import java.io.*;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
/**
@ -19,14 +21,19 @@ public class FileTransferSSHImpl
{
private final SSHFileTransferDaemon fileTransfer;
private final Date initialDate;
/**
* Creates an SSH implementation of the file transfer interface.
*
* @param fileTransfer the SSH file transfer
* @param date the initial date of the transfer
*/
public FileTransferSSHImpl(SSHFileTransferDaemon fileTransfer)
public FileTransferSSHImpl( SSHFileTransferDaemon fileTransfer,
Date date)
{
this.fileTransfer = fileTransfer;
this.initialDate = date;
}
/**
@ -56,11 +63,21 @@ public int getDirection()
public File getFile()
{
throw new UnsupportedOperationException("Not supported yet.");
return null;
}
public Contact getContact()
{
throw new UnsupportedOperationException("Not supported yet.");
return null;
}
public String getID()
{
return null;
}
public Date getInitialDate()
{
return initialDate;
}
}

@ -122,7 +122,7 @@ public FileTransfer sendFile(
remotePath,
localPath);
return new FileTransferSSHImpl(fileTransferDaemon);
return new FileTransferSSHImpl(fileTransferDaemon, new Date());
}
else if(fromContact == null)
{
@ -135,7 +135,7 @@ else if(fromContact == null)
remotePath,
localPath);
return new FileTransferSSHImpl(fileTransferDaemon);
return new FileTransferSSHImpl(fileTransferDaemon, new Date());
}
// code should not reach here

@ -52,6 +52,8 @@ public class FileRecord
private Contact contact;
private String id = null;
/**
* Constructs new FileRecord
*
@ -61,6 +63,7 @@ public class FileRecord
* @param status
*/
public FileRecord(
String id,
Contact contact,
String direction,
long date,
@ -72,6 +75,7 @@ public FileRecord(
this.date = date;
this.file = file;
this.status = status;
this.id = id;
}
/**
@ -118,4 +122,13 @@ public Contact getContact()
{
return contact;
}
/**
* The id.
* @return id.
*/
public String getID()
{
return id;
}
}

@ -50,4 +50,15 @@ public interface HistoryWriter {
*/
void addRecord(String[] propertyValues, Date timestamp) throws IOException;
/**
* Updates a record by searching for record with idProperty which have idValue
* and updating/creating the property with newValue.
*
* @param idProperty name of the id property
* @param idValue value of the id property
* @param property the property to change
* @param newValue the value of the changed property.
*/
public void updateRecord(String idProperty, String idValue,
String property, String newValue) throws IOException;
}

@ -7,6 +7,7 @@
package net.java.sip.communicator.service.protocol;
import java.io.*;
import java.util.*;
import net.java.sip.communicator.service.protocol.event.*;
@ -29,6 +30,14 @@ public interface FileTransfer
*/
public static final int OUT = 2;
/**
* Uniquie ID that is identifying the FileTransfer
* if the request has been accepted.
*
* @return the id.
*/
public String getID();
/**
* Cancels this file transfer. When this method is called transfer should
* be interrupted.
@ -60,7 +69,7 @@ public interface FileTransfer
* The status is returned as an <tt>int</tt> and could be equal to one of
* the static constants declared in this interface (i.e. COMPLETED,
* CANCELED, FAILED, etc.).
*
*
* @return the current status of the transfer
*/
public int getStatus();

@ -17,6 +17,14 @@
*/
public interface IncomingFileTransferRequest
{
/**
* Uniquie ID that is identifying the request and then the FileTransfer
* if the request has been accepted.
*
* @return the id.
*/
public String getID();
/**
* Returns a String that represents the name of the file that is being
* received.

@ -0,0 +1,64 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.protocol.event;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
/**
* The <tt>FileTransferCreatedEvent</tt> indicates the creation of a file
* transfer.
*
* @author Yana Stamcheva
*/
public class FileTransferCreatedEvent
extends EventObject
{
/**
* The timestamp indicating the exact date when the event occurred.
*/
private final Date timestamp;
/**
* Creates a <tt>FileTransferCreatedEvent</tt> representing creation of a
* file transfer.
*
* @param request the <tt>FileTransfer</tt> whose creation this event
* represents.
* @param timestamp the timestamp indicating the exact date when the event
* occurred
*/
public FileTransferCreatedEvent(FileTransfer fileTransfer,
Date timestamp)
{
super(fileTransfer);
this.timestamp = timestamp;
}
/**
* Returns the file transfer that triggered this event.
*
* @return the <tt>FileTransfer</tt> that triggered this
* event.
*/
public FileTransfer getFileTransfer()
{
return (FileTransfer) getSource();
}
/**
* A timestamp indicating the exact date when the event occurred.
*
* @return a Date indicating when the event occurred.
*/
public Date getTimestamp()
{
return timestamp;
}
}

@ -8,8 +8,6 @@
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
/**
* A listener that would gather events notifying of incoming file transfer
* requests.
@ -29,9 +27,10 @@ public interface FileTransferListener
public void fileTransferRequestReceived(FileTransferRequestEvent event);
/**
* Called when an incoming or outgoing <tt>FileTransfer</tt> has been
* created.
* @param fileTransfer the file transfer object that has been created
* Called when a <tt>FileTransferCreatedEvent</tt> has been received.
*
* @param event the <tt>FileTransferCreatedEvent</tt> containing the newly
* received file transfer and other details.
*/
public void fileTransferCreated(FileTransfer fileTransfer);
public void fileTransferCreated(FileTransferCreatedEvent event);
}

@ -109,7 +109,12 @@ public static Image getScaledRoundedImage(Image image, int width, int height)
public static ImageIcon getScaledRoundedIcon(Image image, int width,
int height)
{
return new ImageIcon(getScaledRoundedImage(image, width, height));
Image scaledImage = getScaledRoundedImage(image, width, height);
if (scaledImage != null)
return new ImageIcon(scaledImage);
return null;
}
/**

@ -8,14 +8,11 @@
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.util.*;
/**

Loading…
Cancel
Save