aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/service/protocol/AbstractFileTransfer.java
diff options
context:
space:
mode:
authorYana Stamcheva <yana@jitsi.org>2009-06-15 15:18:29 +0000
committerYana Stamcheva <yana@jitsi.org>2009-06-15 15:18:29 +0000
commit2f0db4d2d1ad77f058b352829a6494c7af5a16b3 (patch)
tree32ecf5f800417777fa473b8814dead041f6515c3 /src/net/java/sip/communicator/service/protocol/AbstractFileTransfer.java
parent3563fa97f679c2f8b29f2d2eb74fc0bbcaa698ab (diff)
downloadjitsi-2f0db4d2d1ad77f058b352829a6494c7af5a16b3.zip
jitsi-2f0db4d2d1ad77f058b352829a6494c7af5a16b3.tar.gz
jitsi-2f0db4d2d1ad77f058b352829a6494c7af5a16b3.tar.bz2
Adding support for file transfer for XMPP and graphical User Interface for file transfer (ongoing work). This first commit adds the needed gui that enables users to send and receive files, to
drag and drop files into chat windows. It displays incoming file notifications, file icons or previews (where possible, e.g. images). This work package also contains a first file transfer implementation over the XMPP protocol (using the smack implementation of xep-0096: http://xmpp.org/extensions/xep-0096.html). Unfortunately this implementation won't work very well with GoogleTalk accounts for now, as Google servers seem to block every file bigger than 60K. This commit contains also some improvements in the way we load the history and we manage error messages in the gui.
Diffstat (limited to 'src/net/java/sip/communicator/service/protocol/AbstractFileTransfer.java')
-rw-r--r--src/net/java/sip/communicator/service/protocol/AbstractFileTransfer.java180
1 files changed, 180 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/service/protocol/AbstractFileTransfer.java b/src/net/java/sip/communicator/service/protocol/AbstractFileTransfer.java
new file mode 100644
index 0000000..18a85f9
--- /dev/null
+++ b/src/net/java/sip/communicator/service/protocol/AbstractFileTransfer.java
@@ -0,0 +1,180 @@
+/*
+ * 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;
+
+import java.util.*;
+
+import net.java.sip.communicator.service.protocol.event.*;
+
+/**
+ * An abstract implementation of the <tt>FileTransfer</tt> interface providing
+ * implementation of status and progress events related methods and leaving all
+ * protocol specific methods abstract. A protocol specific implementation could
+ * extend this class and implement only <tt>cancel()</tt> and
+ * <tt>getTransferredBytes()</tt>.
+ *
+ * @author Yana Stamcheva
+ */
+public abstract class AbstractFileTransfer
+ implements FileTransfer
+{
+ /**
+ * A list of listeners registered for file transfer status events.
+ */
+ private Vector<FileTransferStatusListener> statusListeners
+ = new Vector<FileTransferStatusListener>();
+
+ /**
+ * A list of listeners registered for file transfer status events.
+ */
+ private Vector<FileTransferProgressListener> progressListeners
+ = new Vector<FileTransferProgressListener>();
+
+ private int status;
+
+ /**
+ * Cancels this file transfer. When this method is called transfer should
+ * be interrupted.
+ */
+ abstract public void cancel();
+
+ /**
+ * Returns the number of bytes already transfered through this file transfer.
+ *
+ * @return the number of bytes already transfered through this file transfer
+ */
+ abstract public long getTransferedBytes();
+
+ /**
+ * 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)
+ {
+ synchronized(progressListeners)
+ {
+ if(!progressListeners.contains(listener))
+ {
+ this.progressListeners.add(listener);
+ }
+ }
+ }
+
+ /**
+ * 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)
+ {
+ synchronized(statusListeners)
+ {
+ if(!statusListeners.contains(listener))
+ {
+ this.statusListeners.add(listener);
+ }
+ }
+ }
+
+ /**
+ * Removes the given <tt>FileTransferProgressListener</tt>.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeProgressListener(FileTransferProgressListener listener)
+ {
+ synchronized(progressListeners)
+ {
+ this.progressListeners.remove(listener);
+ }
+ }
+
+ /**
+ * Removes the given <tt>FileTransferStatusListener</tt>.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeStatusListener(FileTransferStatusListener listener)
+ {
+ synchronized(statusListeners)
+ {
+ this.statusListeners.remove(listener);
+ }
+ }
+
+ /**
+ * Returns the current status of the transfer. This information could be
+ * used from the user interface to show a progress bar indicating the
+ * file transfer status.
+ *
+ * @return the current status of the transfer
+ */
+ public int getStatus()
+ {
+ return status;
+ }
+
+ /**
+ * Notifies all status listeners that a new
+ * <tt>FileTransferStatusChangeEvent</tt> occured.
+ */
+ public void fireStatusChangeEvent(int newStatus)
+ {
+ Collection<FileTransferStatusListener> listeners = null;
+ synchronized (statusListeners)
+ {
+ listeners
+ = new ArrayList<FileTransferStatusListener>(statusListeners);
+ }
+
+ FileTransferStatusChangeEvent statusEvent
+ = new FileTransferStatusChangeEvent(this, status, newStatus);
+
+ // Updates the status.
+ this.status = newStatus;
+
+ Iterator<FileTransferStatusListener> listenersIter
+ = listeners.iterator();
+
+ while (listenersIter.hasNext())
+ {
+ FileTransferStatusListener statusListener = listenersIter.next();
+
+ statusListener.statusChanged(statusEvent);
+ }
+ }
+
+ /**
+ * Notifies all status listeners that a new
+ * <tt>FileTransferProgressEvent</tt> occured.
+ */
+ public void fireProgressChangeEvent(int progress)
+ {
+ Collection<FileTransferProgressListener> listeners = null;
+ synchronized (progressListeners)
+ {
+ listeners
+ = new ArrayList<FileTransferProgressListener>(progressListeners);
+ }
+
+ FileTransferProgressEvent progressEvent
+ = new FileTransferProgressEvent(this, progress);
+
+ Iterator<FileTransferProgressListener> listenersIter
+ = listeners.iterator();
+
+ while (listenersIter.hasNext())
+ {
+ FileTransferProgressListener statusListener = listenersIter.next();
+
+ statusListener.progressChanged(progressEvent);
+ }
+ }
+}