FileHistory Service impl.

cusax-fix
Damian Minkov 17 years ago
parent 8a7cd18b2b
commit ab6e04cdcf

@ -808,7 +808,7 @@
bundle-dict,bundle-plugin-dictaccregwizz,
bundle-plugin-simpleaccreg,bundle-plugin-generalconfig,
bundle-plugin-googletalkaccregwizz,bundle-argdelegation-service,
bundle-argdelegation,bundle-zrtp4j"/>
bundle-argdelegation,bundle-zrtp4j,bundle-filehistory"/>
<!--BUNDLE-SC-LAUNCHER-->
<target name="bundle-sc-launcher">
@ -1964,4 +1964,17 @@ javax.swing.event, javax.swing.border"/>
</manifest>
</jar>
</target>
<!--BUNDLE-FILEHISTORY-->
<target name="bundle-filehistory">
<jar compress="false" destfile="${bundles.dest}/filehistory.jar"
manifest="${src}/net/java/sip/communicator/impl/filehistory/filehistory.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/service/filehistory"
prefix="net/java/sip/communicator/service/filehistory"/>
<zipfileset dir="${dest}/net/java/sip/communicator/impl/filehistory"
prefix="net/java/sip/communicator/impl/filehistory" />
</jar>
</target>
</project>

@ -117,6 +117,7 @@ felix.auto.start.60= \
reference:file:sc-bundles/history.jar \
reference:file:sc-bundles/msghistory.jar \
reference:file:sc-bundles/callhistory.jar \
reference:file:sc-bundles/filehistory.jar \
reference:file:sc-bundles/audionotifier.jar \
reference:file:sc-bundles/keybindings.jar \
reference:file:sc-bundles/notification.jar

@ -0,0 +1,69 @@
/*
* 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.impl.filehistory;
import org.osgi.framework.*;
import net.java.sip.communicator.service.history.*;
import net.java.sip.communicator.service.filehistory.*;
import net.java.sip.communicator.util.*;
/**
*
* @author Damian Minkov
*/
public class FileHistoryActivator
implements BundleActivator
{
private static Logger logger =
Logger.getLogger(FileHistoryActivator.class);
private FileHistoryServiceImpl fileHistoryService = null;
/**
* Initialize and start file history
*
* @param bundleContext BundleContext
* @throws Exception
*/
public void start(BundleContext bundleContext) throws Exception
{
try{
logger.logEntry();
ServiceReference refHistory = bundleContext.getServiceReference(
HistoryService.class.getName());
HistoryService historyService = (HistoryService)
bundleContext.getService(refHistory);
//Create and start the file history service.
fileHistoryService =
new FileHistoryServiceImpl();
// set the history service
fileHistoryService.setHistoryService(historyService);
fileHistoryService.start(bundleContext);
bundleContext.registerService(
FileHistoryService.class.getName(), fileHistoryService, null);
logger.info("File History Service ...[REGISTERED]");
}
finally
{
logger.logExit();
}
}
public void stop(BundleContext bundleContext) throws Exception
{
if(fileHistoryService != null)
fileHistoryService.stop(bundleContext);
}
}

@ -0,0 +1,760 @@
/*
* 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.impl.filehistory;
import java.io.*;
import java.util.*;
import org.osgi.framework.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.filehistory.*;
import net.java.sip.communicator.service.history.*;
import net.java.sip.communicator.service.history.records.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
/**
* File History Service stores info for file transfers from various protocols.
* Uses History Service.
*
* @author Damian Minkov
*/
public class FileHistoryServiceImpl
implements FileHistoryService,
ServiceListener,
FileTransferStatusListener,
FileTransferListener
{
/**
* The logger for this class.
*/
private static final Logger logger =
Logger.getLogger(FileHistoryServiceImpl.class);
private static String[] STRUCTURE_NAMES =
new String[] { "file", "dir", "date", "status"};
private static HistoryRecordStructure recordStructure =
new HistoryRecordStructure(STRUCTURE_NAMES);
// the field used to search by keywords
private static final String SEARCH_FIELD = "file";
/**
* The BundleContext that we got from the OSGI bus.
*/
private BundleContext bundleContext = null;
private HistoryService historyService = null;
/**
* Starts the service. Check the current registerd protocol providers
* which supports FileTransfer and adds a listener to them.
*
* @param bc BundleContext
*/
public void start(BundleContext bc)
{
logger.debug("Starting the file history implementation.");
this.bundleContext = bc;
// start listening for newly register or removed protocol providers
bc.addServiceListener(this);
ServiceReference[] protocolProviderRefs = null;
try
{
protocolProviderRefs = bc.getServiceReferences(
ProtocolProviderService.class.getName(),
null);
}
catch (InvalidSyntaxException ex)
{
// this shouldn't happen since we're providing no parameter string
// but let's log just in case.
logger.error(
"Error while retrieving service refs", ex);
return;
}
// in case we found any
if (protocolProviderRefs != null)
{
logger.debug("Found "
+ protocolProviderRefs.length
+ " already installed providers.");
for (int i = 0; i < protocolProviderRefs.length; i++)
{
ProtocolProviderService provider = (ProtocolProviderService) bc
.getService(protocolProviderRefs[i]);
this.handleProviderAdded(provider);
}
}
}
/**
* Stops the service.
*
* @param bc BundleContext
*/
public void stop(BundleContext bc)
{
bc.removeServiceListener(this);
ServiceReference[] protocolProviderRefs = null;
try
{
protocolProviderRefs = bc.getServiceReferences(
ProtocolProviderService.class.getName(),
null);
}
catch (InvalidSyntaxException ex)
{
// this shouldn't happen since we're providing no parameter string
// but let's log just in case.
logger.error("Error while retrieving service refs", ex);
return;
}
// in case we found any
if (protocolProviderRefs != null)
{
for (int i = 0; i < protocolProviderRefs.length; i++)
{
ProtocolProviderService provider = (ProtocolProviderService) bc
.getService(protocolProviderRefs[i]);
this.handleProviderRemoved(provider);
}
}
}
/**
* Used to attach the File History Service to existing or
* just registered protocol provider. Checks if the provider has implementation
* of OperationSetFileTransfer
*
* @param provider ProtocolProviderService
*/
private void handleProviderAdded(ProtocolProviderService provider)
{
logger.debug("Adding protocol provider " + provider.getProtocolName());
// check whether the provider has a file transfer operation set
OperationSetFileTransfer opSetFileTransfer =
(OperationSetFileTransfer) provider
.getOperationSet(OperationSetFileTransfer.class);
if (opSetFileTransfer != null)
{
opSetFileTransfer.addFileTransferListener(this);
}
else
{
logger.trace("Service did not have a file transfer op. set.");
}
}
/**
* Removes the specified provider from the list of currently known providers
*
* @param provider the ProtocolProviderService that has been unregistered.
*/
private void handleProviderRemoved(ProtocolProviderService provider)
{
OperationSetFileTransfer opSetFileTransfer =
(OperationSetFileTransfer) provider
.getOperationSet(OperationSetFileTransfer.class);
if (opSetFileTransfer != null)
{
opSetFileTransfer.addFileTransferListener(this);
}
}
/**
* Set the history service.
*
* @param historyService HistoryService
*/
public void setHistoryService(HistoryService historyService)
{
this.historyService = historyService;
}
/**
* Gets all the history readers for the contacts in the given MetaContact
* @param contact MetaContact
* @return Hashtable
*/
private Map<Contact, HistoryReader> getHistoryReaders(MetaContact contact)
{
Map<Contact, HistoryReader> readers = new Hashtable<Contact, HistoryReader>();
Iterator<Contact> iter = contact.getContacts();
while (iter.hasNext())
{
Contact item = iter.next();
try
{
History history = this.getHistory(null, item);
readers.put(item, history.getReader());
}
catch (IOException e)
{
logger.error("Could not read history", e);
}
}
return readers;
}
private FileRecord createFileRecordFromHistoryRecord(HistoryRecord hr)
{
String file = null;
String dir = null;
long date = 0;
String status = null;
for (int i = 0; i < hr.getPropertyNames().length; i++)
{
String propName = hr.getPropertyNames()[i];
if (propName.equals(STRUCTURE_NAMES[0]))
file = hr.getPropertyValues()[i];
else if (propName.equals(STRUCTURE_NAMES[1]))
dir = hr.getPropertyValues()[i];
else if (propName.equals(STRUCTURE_NAMES[2]))
{
try
{
date = Long.valueOf(hr.getPropertyValues()[i]);
}
catch (NumberFormatException e)
{
logger.error("Wrong date : " + hr.getPropertyValues()[i]);
}
}
else if (propName.equals(STRUCTURE_NAMES[3]))
status = hr.getPropertyValues()[i];
}
return new FileRecord(dir, date, new File(file), status);
}
/**
* Returns all the file transfers made after the given date
*
* @param contact MetaContact the receiver or sender of the file
* @param startDate Date the start date of the transfers
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByStartDate(
MetaContact contact, Date startDate)
throws RuntimeException
{
TreeSet<FileRecord> result =
new TreeSet<FileRecord>(new FileRecordComparator());
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
for (Map.Entry<Contact, HistoryReader> readerEntry : readers.entrySet())
{
HistoryReader reader = readerEntry.getValue();
// add the progress listeners
Iterator<HistoryRecord> recs = reader.findByStartDate(startDate);
while (recs.hasNext())
{
result.add(createFileRecordFromHistoryRecord(recs.next()));
}
}
return result;
}
/**
* Returns all the file transfers made before the given date
*
* @param contact MetaContact the receiver or sender of the file
* @param endDate Date the end date of the transfers
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByEndDate(MetaContact contact, Date endDate)
throws RuntimeException
{
TreeSet<FileRecord> result =
new TreeSet<FileRecord>(new FileRecordComparator());
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
for (Map.Entry<Contact, HistoryReader> readerEntry : readers.entrySet())
{
HistoryReader reader = readerEntry.getValue();
// add the progress listeners
Iterator<HistoryRecord> recs = reader.findByEndDate(endDate);
while (recs.hasNext())
{
result.add(createFileRecordFromHistoryRecord(recs.next()));
}
}
return result;
}
/**
* Returns all the file transfers made between the given dates and
* having the given keywords in the filename
*
* @param contact MetaContact the receiver or sender of the file
* @param startDate Date the start date of the transfers
* @param endDate Date the end date of the transfers
* @param keywords array of keywords
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByPeriod(MetaContact contact,
Date startDate, Date endDate, String[] keywords)
throws RuntimeException
{
return findByPeriod(contact, startDate, endDate, keywords, false);
}
/**
* Returns all the file transfers made between the given dates
* and having the given keywords in the filename
*
* @param contact MetaContact the receiver or sender of the file
* @param startDate Date the start date of the transfers
* @param endDate Date the end date of the transfers
* @param keywords array of keywords
* @param caseSensitive is keywords search case sensitive
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByPeriod(MetaContact contact, Date startDate, Date endDate,
String[] keywords, boolean caseSensitive)
throws RuntimeException
{
TreeSet<FileRecord> result =
new TreeSet<FileRecord>(new FileRecordComparator());
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
for (Map.Entry<Contact, HistoryReader> readerEntry : readers.entrySet())
{
HistoryReader reader = readerEntry.getValue();
// add the progress listeners
Iterator<HistoryRecord> recs = reader.findByPeriod(
startDate, endDate, keywords, SEARCH_FIELD, caseSensitive);
while (recs.hasNext())
{
result.add(createFileRecordFromHistoryRecord(recs.next()));
}
}
return result;
}
/**
* Returns all the file transfers made between the given dates
*
* @param contact MetaContact the receiver or sender of the file
* @param startDate Date the start date of the transfers
* @param endDate Date the end date of the transfers
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByPeriod(
MetaContact contact, Date startDate, Date endDate)
throws RuntimeException
{
TreeSet<FileRecord> result =
new TreeSet<FileRecord>(new FileRecordComparator());
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
for (Map.Entry<Contact, HistoryReader> readerEntry : readers.entrySet())
{
HistoryReader reader = readerEntry.getValue();
// add the progress listeners
Iterator<HistoryRecord> recs = reader.findByPeriod(startDate, endDate);
while (recs.hasNext())
{
result.add(createFileRecordFromHistoryRecord(recs.next()));
}
}
return result;
}
/**
* Returns the supplied number of file transfers
*
* @param contact MetaContact the receiver or sender of the file
* @param count filetransfer count
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findLast(MetaContact contact, int count)
throws RuntimeException
{
TreeSet<FileRecord> result =
new TreeSet<FileRecord>(new FileRecordComparator());
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
for (Map.Entry<Contact, HistoryReader> readerEntry : readers.entrySet())
{
HistoryReader reader = readerEntry.getValue();
// add the progress listeners
Iterator<HistoryRecord> recs = reader.findLast(count);
while (recs.hasNext())
{
result.add(createFileRecordFromHistoryRecord(recs.next()));
}
}
return result;
}
/**
* Returns all the file transfers having the given keyword in the filename
*
* @param contact MetaContact the receiver or sender of the file
* @param keyword keyword
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByKeyword(
MetaContact contact, String keyword)
throws RuntimeException
{
return findByKeyword(contact, keyword, false);
}
/**
* Returns all the file transfers having the given keyword in the filename
*
* @param contact MetaContact the receiver or sender of the file
* @param keyword keyword
* @param caseSensitive is keywords search case sensitive
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByKeyword(
MetaContact contact, String keyword, boolean caseSensitive)
throws RuntimeException
{
return findByKeywords(contact, new String[]{keyword}, caseSensitive);
}
/**
* Returns all the file transfers having the given keywords in the filename
*
* @param contact MetaContact the receiver or sender of the file
* @param keywords keyword
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByKeywords(
MetaContact contact, String[] keywords)
throws RuntimeException
{
return findByKeywords(contact, keywords, false);
}
/**
* Returns all the file transfershaving the given keywords in the filename
*
* @param contact MetaContact the receiver or sender of the file
* @param keywords keyword
* @param caseSensitive is keywords search case sensitive
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByKeywords(
MetaContact contact, String[] keywords, boolean caseSensitive)
throws RuntimeException
{
TreeSet<FileRecord> result =
new TreeSet<FileRecord>(new FileRecordComparator());
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
for (Map.Entry<Contact, HistoryReader> readerEntry : readers.entrySet())
{
HistoryReader reader = readerEntry.getValue();
// add the progress listeners
Iterator<HistoryRecord> recs =
reader.findByKeywords(keywords, SEARCH_FIELD, caseSensitive);
while (recs.hasNext())
{
result.add(createFileRecordFromHistoryRecord(recs.next()));
}
}
return result;
}
/**
* Returns the supplied number of recent file transfers after the given date
*
* @param contact MetaContact the receiver or sender of the file
* @param date transfers after date
* @param count transfers count
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findFirstRecordsAfter(
MetaContact contact, Date date, int count)
throws RuntimeException
{
TreeSet<FileRecord> result =
new TreeSet<FileRecord>(new FileRecordComparator());
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
for (Map.Entry<Contact, HistoryReader> readerEntry : readers.entrySet())
{
HistoryReader reader = readerEntry.getValue();
// add the progress listeners
Iterator<HistoryRecord> recs =
reader.findFirstRecordsAfter(date, count);
while (recs.hasNext())
{
result.add(createFileRecordFromHistoryRecord(recs.next()));
}
}
LinkedList<FileRecord> resultAsList = new LinkedList<FileRecord>(result);
int toIndex = count;
if(toIndex > resultAsList.size())
toIndex = resultAsList.size();
return resultAsList.subList(0, toIndex);
}
/**
* Returns the supplied number of recent file transfers before the given date
*
* @param contact MetaContact the receiver or sender of the file
* @param date transfers before date
* @param count transfers count
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findLastRecordsBefore(
MetaContact contact, Date date, int count)
throws RuntimeException
{
TreeSet<FileRecord> result =
new TreeSet<FileRecord>(new FileRecordComparator());
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
for (Map.Entry<Contact, HistoryReader> readerEntry : readers.entrySet())
{
HistoryReader reader = readerEntry.getValue();
// add the progress listeners
Iterator<HistoryRecord> recs =
reader.findLastRecordsBefore(date, count);
while (recs.hasNext())
{
result.add(createFileRecordFromHistoryRecord(recs.next()));
}
}
LinkedList<FileRecord> resultAsList = new LinkedList<FileRecord>(result);
int startIndex = resultAsList.size() - count;
if(startIndex < 0)
startIndex = 0;
return resultAsList.subList(startIndex, resultAsList.size());
}
/**
* When new protocol provider is registered we check
* does it supports FileTransfer and if so add a listener to it
*
* @param serviceEvent ServiceEvent
*/
public void serviceChanged(ServiceEvent serviceEvent)
{
Object sService = bundleContext.getService(serviceEvent.getServiceReference());
logger.trace("Received a service event for: " + sService.getClass().getName());
// we don't care if the source service is not a protocol provider
if (! (sService instanceof ProtocolProviderService))
{
return;
}
logger.debug("Service is a protocol provider.");
if (serviceEvent.getType() == ServiceEvent.REGISTERED)
{
logger.debug("Handling registration of a new Protocol Provider.");
this.handleProviderAdded((ProtocolProviderService)sService);
}
else if (serviceEvent.getType() == ServiceEvent.UNREGISTERING)
{
this.handleProviderRemoved( (ProtocolProviderService) sService);
}
}
/**
* Returns the history by specified local and remote contact
* if one of them is null the default is used
*
* @param localContact Contact
* @param remoteContact Contact
* @return History
* @throws IOException
*/
private History getHistory(Contact localContact, Contact remoteContact)
throws IOException
{
History retVal = null;
String localId = localContact == null ? "default" : localContact
.getAddress();
String remoteId = remoteContact == null ? "default" : remoteContact
.getAddress();
String account = "unkown";
if (remoteContact != null)
account = remoteContact.getProtocolProvider().getAccountID().
getAccountUniqueID();
HistoryID historyId = HistoryID.createFromRawID(
new String[] { "filehistory",
localId,
account,
remoteId });
if (this.historyService.isHistoryExisting(historyId))
{
retVal = this.historyService.getHistory(historyId);
} else
{
retVal = this.historyService.createHistory(historyId,
recordStructure);
}
return retVal;
}
/**
* Listens for changes in filetransfers.
* @param event
*/
public void statusChanged(FileTransferStatusChangeEvent event)
{
try
{
FileTransfer ft = event.getFileTransfer();
String status = getStatus(ft.getStatus());
// ignore events we don't need
if(status == null)
return;
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)
{
logger.error("Could not add file transfer log to history", e);
}
}
private static String getDirection(int direction)
{
switch(direction)
{
case FileTransfer.IN :
return FileRecord.IN;
case FileTransfer.OUT :
return FileRecord.OUT;
default: return null;
}
}
/**
* Maps only the statuses we are interested in, otherwise returns null.
* @param status the status as receive from FileTransfer
* @return the corresponding status of FileRecord.
*/
private static String getStatus(int status)
{
switch(status)
{
case FileTransferStatusChangeEvent.CANCELED :
return FileRecord.CANCELED;
case FileTransferStatusChangeEvent.COMPLETED :
return FileRecord.COMPLETED;
case FileTransferStatusChangeEvent.FAILED :
return FileRecord.FAILED;
case FileTransferStatusChangeEvent.REFUSED :
return FileRecord.REFUSED;
default: return null;
}
}
/**
* We ignore filetransfer requests.
* @param event
*/
public void fileTransferRequestReceived(FileTransferRequestEvent event)
{
}
/**
* New filetransfer was created.
* @param fileTransfer
*/
public void fileTransferCreated(FileTransfer fileTransfer)
{
fileTransfer.addStatusListener(this);
}
/**
* Used to compare FileRecords
* and to be ordered in TreeSet according their timestamp
*/
private static class FileRecordComparator
implements Comparator
{
public int compare(Object o1, Object o2)
{
long date1 = ((FileRecord)o1).getDate();
long date2 = ((FileRecord)o2).getDate();
return (date1 < date2) ? -1 : ((date1 == date2) ? 0 : 1);
}
}
}

@ -0,0 +1,15 @@
Bundle-Activator: net.java.sip.communicator.impl.filehistory.FileHistoryActivator
Bundle-Name: File History Service Provider
Bundle-Description: A bundle that implements the file history package.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1
System-Bundle: yes
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.history,
net.java.sip.communicator.service.history.records,
net.java.sip.communicator.service.history.event,
net.java.sip.communicator.service.contactlist,
net.java.sip.communicator.util,
net.java.sip.communicator.service.protocol,
net.java.sip.communicator.service.protocol.event
Export-Package: net.java.sip.communicator.service.filehistory

@ -373,14 +373,14 @@ public void statusChanged(FileTransferStatusChangeEvent event)
String fromContactName
= fileTransferRequest.getSender().getDisplayName();
if (status == FileTransfer.PREPARING)
if (status == FileTransferStatusChangeEvent.PREPARING)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
"service.gui.FILE_TRANSFER_PREPARING",
new String[]{fromContactName}));
}
else if (status == FileTransfer.FAILED)
else if (status == FileTransferStatusChangeEvent.FAILED)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
@ -389,7 +389,7 @@ else if (status == FileTransfer.FAILED)
setWarningStyle(true);
}
else if (status == FileTransfer.IN_PROGRESS)
else if (status == FileTransferStatusChangeEvent.IN_PROGRESS)
{
titleLabel.setText(resources.getI18NString(
"service.gui.FILE_RECEIVING_FROM",
@ -401,7 +401,7 @@ else if (status == FileTransfer.IN_PROGRESS)
progressBar.setVisible(true);
}
}
else if (status == FileTransfer.COMPLETED)
else if (status == FileTransferStatusChangeEvent.COMPLETED)
{
if (downloadFile != null)
{
@ -432,7 +432,7 @@ public void mouseClicked(MouseEvent e)
}
});
}
else if (status == FileTransfer.CANCELED)
else if (status == FileTransferStatusChangeEvent.CANCELED)
{
progressBar.setVisible(false);
cancelButton.setVisible(false);
@ -441,7 +441,7 @@ else if (status == FileTransfer.CANCELED)
"service.gui.FILE_TRANSFER_CANCELED"));
setWarningStyle(true);
}
else if (status == FileTransfer.REFUSED)
else if (status == FileTransferStatusChangeEvent.REFUSED)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(

@ -249,7 +249,7 @@ public void statusChanged(FileTransferStatusChangeEvent event)
{
int status = event.getNewStatus();
if (status == FileTransfer.PREPARING)
if (status == FileTransferStatusChangeEvent.PREPARING)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
@ -258,7 +258,7 @@ public void statusChanged(FileTransferStatusChangeEvent event)
cancelButton.setVisible(true);
retryButton.setVisible(false);
}
else if (status == FileTransfer.FAILED)
else if (status == FileTransferStatusChangeEvent.FAILED)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
@ -268,7 +268,7 @@ else if (status == FileTransfer.FAILED)
retryButton.setVisible(true);
setWarningStyle(true);
}
else if (status == FileTransfer.IN_PROGRESS)
else if (status == FileTransferStatusChangeEvent.IN_PROGRESS)
{
titleLabel.setText(resources.getI18NString(
"service.gui.FILE_SENDING_TO",
@ -280,7 +280,7 @@ else if (status == FileTransfer.IN_PROGRESS)
progressBar.setVisible(true);
}
}
else if (status == FileTransfer.COMPLETED)
else if (status == FileTransferStatusChangeEvent.COMPLETED)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
@ -289,7 +289,7 @@ else if (status == FileTransfer.COMPLETED)
cancelButton.setVisible(false);
retryButton.setVisible(false);
}
else if (status == FileTransfer.CANCELED)
else if (status == FileTransferStatusChangeEvent.CANCELED)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(
@ -298,7 +298,7 @@ else if (status == FileTransfer.CANCELED)
retryButton.setVisible(true);
setWarningStyle(true);
}
else if (status == FileTransfer.REFUSED)
else if (status == FileTransferStatusChangeEvent.REFUSED)
{
progressBar.setVisible(false);
titleLabel.setText(resources.getI18NString(

@ -6,6 +6,8 @@
*/
package net.java.sip.communicator.impl.protocol.jabber;
import java.io.*;
import org.jivesoftware.smackx.filetransfer.*;
import net.java.sip.communicator.service.protocol.*;
@ -18,14 +20,21 @@
public class IncomingFileTransferJabberImpl
extends AbstractFileTransfer
{
private Contact sender = null;
private File file = null;
/**
* The jabber incoming file transfer.
*/
private IncomingFileTransfer jabberTransfer;
public IncomingFileTransferJabberImpl(IncomingFileTransfer jabberTransfer)
public IncomingFileTransferJabberImpl(Contact sender,
File file,
IncomingFileTransfer jabberTransfer)
{
this.jabberTransfer = jabberTransfer;
this.sender = sender;
this.file = file;
}
/**
@ -45,4 +54,27 @@ public long getTransferedBytes()
{
return jabberTransfer.getAmountWritten();
}
/**
* The direction is incoming.
* @return IN.
*/
public int getDirection()
{
return IN;
}
/**
* The file we are receiving.
* @return the file.
*/
public File getFile()
{
return file;
}
public Contact getContact()
{
return sender;
}
}

@ -121,7 +121,8 @@ public FileTransfer acceptFile(File file)
try
{
incomingTransfer
= new IncomingFileTransferJabberImpl(jabberTransfer);
= new IncomingFileTransferJabberImpl(
sender, file, jabberTransfer);
fileTransferOpSet.fireFileTransferCreated(incomingTransfer);

@ -102,7 +102,7 @@ public FileTransfer sendFile( Contact toContact,
= manager.createOutgoingFileTransfer(presence.getFrom());
outgoingTransfer
= new OutgoingFileTransferJabberImpl(transfer);
= new OutgoingFileTransferJabberImpl(toContact, file, transfer);
// Notify all interested listeners that a file transfer has been
// created.
@ -363,10 +363,10 @@ public void run()
status = parseJabberStatus(jabberTransfer.getStatus());
progress = fileTransfer.getTransferedBytes();
if (status == FileTransfer.FAILED
|| status == FileTransfer.COMPLETED
|| status == FileTransfer.CANCELED
|| status == FileTransfer.REFUSED)
if (status == FileTransferStatusChangeEvent.FAILED
|| status == FileTransferStatusChangeEvent.COMPLETED
|| status == FileTransferStatusChangeEvent.CANCELED
|| status == FileTransferStatusChangeEvent.REFUSED)
{
break;
}
@ -381,10 +381,10 @@ public void run()
}
if (initialFileSize > 0
&& status == FileTransfer.COMPLETED
&& status == FileTransferStatusChangeEvent.COMPLETED
&& fileTransfer.getTransferedBytes() < initialFileSize)
{
status = FileTransfer.CANCELED;
status = FileTransferStatusChangeEvent.CANCELED;
}
fileTransfer.fireStatusChangeEvent(status);
@ -402,21 +402,21 @@ public void run()
private static int parseJabberStatus(Status jabberStatus)
{
if (jabberStatus.equals(Status.complete))
return FileTransfer.COMPLETED;
return FileTransferStatusChangeEvent.COMPLETED;
else if (jabberStatus.equals(Status.cancelled))
return FileTransfer.CANCELED;
return FileTransferStatusChangeEvent.CANCELED;
else if (jabberStatus.equals(Status.in_progress)
|| jabberStatus.equals(Status.negotiated))
return FileTransfer.IN_PROGRESS;
return FileTransferStatusChangeEvent.IN_PROGRESS;
else if (jabberStatus.equals(Status.error))
return FileTransfer.FAILED;
return FileTransferStatusChangeEvent.FAILED;
else if (jabberStatus.equals(Status.refused))
return FileTransfer.REFUSED;
return FileTransferStatusChangeEvent.REFUSED;
else if (jabberStatus.equals(Status.negotiating_transfer)
|| jabberStatus.equals(Status.negotiating_stream))
return FileTransfer.PREPARING;
return FileTransferStatusChangeEvent.PREPARING;
else
// FileTransfer.Status.initial
return FileTransfer.WAITING;
return FileTransferStatusChangeEvent.WAITING;
}
}

@ -6,6 +6,8 @@
*/
package net.java.sip.communicator.impl.protocol.jabber;
import java.io.*;
import net.java.sip.communicator.service.protocol.*;
import org.jivesoftware.smackx.filetransfer.*;
@ -18,6 +20,9 @@
public class OutgoingFileTransferJabberImpl
extends AbstractFileTransfer
{
private Contact receiver;
private File file;
/**
* The jabber outgoing file transfer.
*/
@ -30,9 +35,13 @@ public class OutgoingFileTransferJabberImpl
* @param jabberTransfer the Jabber transfer object, containing all transfer
* information
*/
public OutgoingFileTransferJabberImpl(OutgoingFileTransfer jabberTransfer)
public OutgoingFileTransferJabberImpl(Contact receiver,
File file,
OutgoingFileTransfer jabberTransfer)
{
this.jabberTransfer = jabberTransfer;
this.receiver = receiver;
this.file = file;
}
/**
@ -52,4 +61,31 @@ public long getTransferedBytes()
{
return jabberTransfer.getBytesSent();
}
}
/**
* The direction is outgoing.
* @return OUT.
*/
public int getDirection()
{
return OUT;
}
/**
* The file we are sending.
* @return the file.
*/
public File getFile()
{
return file;
}
/**
* The contact we are sending the file.
* @return the receiver.
*/
public Contact getContact()
{
return receiver;
}
}

@ -6,6 +6,7 @@
*/
package net.java.sip.communicator.impl.protocol.ssh;
import java.io.*;
import net.java.sip.communicator.service.protocol.*;
/**
@ -47,4 +48,19 @@ public long getTransferedBytes()
// TODO: Implement getTransferedBytes() for SSH file transfer.
return 0;
}
public int getDirection()
{
return IN;
}
public File getFile()
{
throw new UnsupportedOperationException("Not supported yet.");
}
public Contact getContact()
{
throw new UnsupportedOperationException("Not supported yet.");
}
}

@ -25,7 +25,8 @@ public interface FileHistoryService
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByStartDate(MetaContact contact, Date startDate)
public Collection<FileRecord> findByStartDate(
MetaContact contact, Date startDate)
throws RuntimeException;
/**
@ -36,7 +37,8 @@ public Collection<FileRecord> findByStartDate(MetaContact contact, Date startDat
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByEndDate(MetaContact contact, Date endDate)
public Collection<FileRecord> findByEndDate(
MetaContact contact, Date endDate)
throws RuntimeException;
/**
@ -48,7 +50,8 @@ public Collection<FileRecord> findByEndDate(MetaContact contact, Date endDate)
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByPeriod(MetaContact contact, Date startDate, Date endDate)
public Collection<FileRecord> findByPeriod(
MetaContact contact, Date startDate, Date endDate)
throws RuntimeException;
/**
@ -103,7 +106,8 @@ public Collection<FileRecord> findLast(MetaContact contact, int count)
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByKeyword(MetaContact contact, String keyword)
public Collection<FileRecord> findByKeyword(
MetaContact contact, String keyword)
throws RuntimeException;
/**
@ -127,7 +131,8 @@ Collection<FileRecord> findByKeyword(
* @return Collection of FileRecords
* @throws RuntimeException
*/
public Collection<FileRecord> findByKeywords(MetaContact contact, String[] keywords)
public Collection<FileRecord> findByKeywords(
MetaContact contact, String[] keywords)
throws RuntimeException;
/**

@ -7,7 +7,6 @@
package net.java.sip.communicator.service.filehistory;
import java.io.*;
import java.util.*;
/**
* Structure used for encapsulating data when writing or reading
@ -45,7 +44,7 @@ public class FileRecord
private String direction = null;
private Date date = null;
private long date;
private File file = null;
private String status;
@ -60,7 +59,7 @@ public class FileRecord
*/
public FileRecord(
String direction,
Date date,
long date,
File file,
String status)
{
@ -83,7 +82,7 @@ public String getDirection()
* The date of the record.
* @return the date
*/
public Date getDate()
public long getDate()
{
return date;
}

@ -127,6 +127,10 @@ public int getStatus()
*/
public void fireStatusChangeEvent(int newStatus)
{
// ignore if status is the same
if(this.status == newStatus)
return;
Collection<FileTransferStatusListener> listeners = null;
synchronized (statusListeners)
{

@ -6,6 +6,8 @@
*/
package net.java.sip.communicator.service.protocol;
import java.io.*;
import net.java.sip.communicator.service.protocol.event.*;
/**
@ -18,46 +20,39 @@
public interface FileTransfer
{
/**
* Indicates that the file transfer has been completed.
* File transfer is incoming.
*/
public static final int COMPLETED = 0;
public static final int IN = 1;
/**
* Indicates that the file transfer has been canceled.
* File transfer is outgoing.
*/
public static final int CANCELED = 1;
public static final int OUT = 2;
/**
* Indicates that the file transfer has failed.
*/
public static final int FAILED = 2;
/**
* Indicates that the file transfer has been refused.
*/
public static final int REFUSED = 3;
/**
* Indicates that the file transfer is in progress.
* Cancels this file transfer. When this method is called transfer should
* be interrupted.
*/
public static final int IN_PROGRESS = 4;
public void cancel();
/**
* Indicates that the file transfer waits for the recipient to accept the
* file.
* The file transfer direction.
* @return returns the direction of the file transfer : IN or OUT.
*/
public static final int WAITING = 5;
public int getDirection();
/**
* Indicates that the file transfer is in negotiation.
* Returns the file that is transfered.
*
* @return the file
*/
public static final int PREPARING = 6;
public File getFile();
/**
* Cancels this file transfer. When this method is called transfer should
* be interrupted.
* Returns the contact that we are transfering files with.
* @return the contact.
*/
public void cancel();
public Contact getContact();
/**
* Returns the current status of the transfer. This information could be
@ -72,7 +67,7 @@ public interface FileTransfer
/**
* Returns the number of bytes already transfered through this file transfer.
*
*
* @return the number of bytes already transfered through this file transfer
*/
public long getTransferedBytes();
@ -80,14 +75,14 @@ public interface FileTransfer
/**
* Adds the given <tt>FileTransferStatusListener</tt> to listen for
* status changes on this file transfer.
*
*
* @param listener the listener to add
*/
public void addStatusListener(FileTransferStatusListener listener);
/**
* Removes the given <tt>FileTransferStatusListener</tt>.
*
*
* @param listener the listener to remove
*/
public void removeStatusListener(FileTransferStatusListener listener);
@ -95,14 +90,14 @@ public interface FileTransfer
/**
* Adds the given <tt>FileTransferProgressListener</tt> to listen for
* status changes on this file transfer.
*
*
* @param listener the listener to add
*/
public void addProgressListener(FileTransferProgressListener listener);
/**
* Removes the given <tt>FileTransferProgressListener</tt>.
*
*
* @param listener the listener to remove
*/
public void removeProgressListener(FileTransferProgressListener listener);

@ -19,6 +19,42 @@
public class FileTransferStatusChangeEvent
extends EventObject
{
/**
* Indicates that the file transfer has been completed.
*/
public static final int COMPLETED = 0;
/**
* Indicates that the file transfer has been canceled.
*/
public static final int CANCELED = 1;
/**
* Indicates that the file transfer has failed.
*/
public static final int FAILED = 2;
/**
* Indicates that the file transfer has been refused.
*/
public static final int REFUSED = 3;
/**
* Indicates that the file transfer is in progress.
*/
public static final int IN_PROGRESS = 4;
/**
* Indicates that the file transfer waits for the recipient to accept the
* file.
*/
public static final int WAITING = 5;
/**
* Indicates that the file transfer is in negotiation.
*/
public static final int PREPARING = 6;
/**
* The state of the file transfer before this event occured.
*/

Loading…
Cancel
Save