aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYana Stamcheva <yana@jitsi.org>2009-06-18 13:47:22 +0000
committerYana Stamcheva <yana@jitsi.org>2009-06-18 13:47:22 +0000
commit5d124a30bfdabf6bcd1a6c12635715257fbd8d13 (patch)
tree63f91dceb13db8178d6587646414ea520c036753
parentee16a8ad66c7e933c194fc124916f3de999c68b8 (diff)
downloadjitsi-5d124a30bfdabf6bcd1a6c12635715257fbd8d13.zip
jitsi-5d124a30bfdabf6bcd1a6c12635715257fbd8d13.tar.gz
jitsi-5d124a30bfdabf6bcd1a6c12635715257fbd8d13.tar.bz2
- Return the appropriate default download directory depending on the operating system.
- When receiving a file check if a file with the given name already exist and add an index to the name.
-rw-r--r--src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java35
-rw-r--r--src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf1
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java49
3 files changed, 61 insertions, 24 deletions
diff --git a/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java b/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java
index c7a8342..051f21a 100644
--- a/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java
@@ -8,6 +8,8 @@ package net.java.sip.communicator.impl.fileaccess;
import java.io.*;
+import javax.swing.filechooser.*;
+
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.fileaccess.*;
import net.java.sip.communicator.util.*;
@@ -363,23 +365,30 @@ public class FileAccessServiceImpl implements FileAccessService {
public File getDefaultDownloadDirectory()
throws IOException
{
- String defaultLocation = getSystemProperty("user.home")
- + File.separatorChar + "Downloads";
+ File downloadDir;
+
+ String osName = System.getProperty("os.name");
+ String osVersion = System.getProperty("os.version");
- File downloadDir = new File(defaultLocation);
+ String majorVersionString
+ = osVersion.substring(0, osVersion.indexOf("."));
- if (!downloadDir.exists())
+ // For Windows versions previous to Vista, the default download location
+ // would be the home directory (i.e. the Desktop folder).
+ if (osName.startsWith("Windows")
+ && Integer.parseInt(majorVersionString) <= 5)
{
- if (!downloadDir.mkdirs())
- {
- String message = "Could not create the download directory : "
- + downloadDir.getAbsolutePath();
+ FileSystemView fsv = FileSystemView.getFileSystemView();
- logger.debug(message);
- throw new IOException(message);
- }
- logger.debug("Download directory created : "
- + downloadDir.getAbsolutePath());
+ downloadDir = fsv.getHomeDirectory();
+ }
+ // For all other operating systems we return the Downloads folder.
+ else
+ {
+ String defaultLocation = getSystemProperty("user.home")
+ + File.separatorChar + "Downloads";
+
+ downloadDir = new File(defaultLocation);
}
return downloadDir;
diff --git a/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf b/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf
index a9d82f6..268bf1c 100644
--- a/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf
+++ b/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf
@@ -11,6 +11,7 @@ Import-Package: org.osgi.framework,
javax.xml.transform.dom,
javax.xml.transform.stream,
javax.xml.parsers,
+ javax.swing.filechooser,
net.java.sip.communicator.util,
net.java.sip.communicator.util.xml,
net.java.sip.communicator.service.fileaccess,
diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java b/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java
index ed51210..2069978 100644
--- a/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java
+++ b/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java
@@ -21,7 +21,6 @@ import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.swing.*;
-import net.java.sip.communicator.util.swing.SwingWorker;
/**
* The <tt>ReceiveFileConversationComponent</tt> is the component shown in the
@@ -325,19 +324,45 @@ public class ReceiveFileConversationComponent
{
File downloadFile = null;
File downloadDir = null;
+
+ String incomingFileName = fileTransferRequest.getFileName();
try
{
downloadDir = GuiActivator.getFileAccessService()
.getDefaultDownloadDirectory();
+
+ if (!downloadDir.exists())
+ {
+ if (!downloadDir.mkdirs())
+ {
+ logger.error("Could not create the download directory : "
+ + downloadDir.getAbsolutePath());
+ }
+ logger.debug("Download directory created : "
+ + downloadDir.getAbsolutePath());
+ }
}
catch (IOException e)
{
- logger.debug("Unable to find download directory.");
+ logger.debug("Unable to find download directory.", e);
+ }
+
+ downloadFile = new File(downloadDir, incomingFileName);
+
+ // If a file with the given name already exists, add an index to the
+ // file name.
+ int index = 0;
+ while (downloadFile.exists())
+ {
+ String newFileName
+ = incomingFileName.substring(0, incomingFileName.lastIndexOf("."))
+ + "-" + ++index
+ + incomingFileName.substring(incomingFileName.lastIndexOf("."));
+
+ downloadFile = new File(downloadDir, newFileName);
}
-
- if (downloadDir != null)
- downloadFile = new File(downloadDir,
- fileTransferRequest.getFileName());
+
+ fileLabel.setText(downloadFile.getName());
return downloadFile;
}
@@ -395,7 +420,6 @@ public class ReceiveFileConversationComponent
titleLabel.setText(resources.getI18NString(
"service.gui.FILE_RECEIVE_COMPLETED",
new String[]{fromContactName}));
- fileLabel.setText(fileTransferRequest.getFileName());
imageLabel.setToolTipText(
resources.getI18NString("service.gui.OPEN_FILE_FROM_IMAGE"));
@@ -494,10 +518,13 @@ public class ReceiveFileConversationComponent
public void finished()
{
- fileTransfer.addStatusListener(
- ReceiveFileConversationComponent.this);
- fileTransfer.addProgressListener(
- ReceiveFileConversationComponent.this);
+ if (fileTransfer != null)
+ {
+ fileTransfer.addStatusListener(
+ ReceiveFileConversationComponent.this);
+ fileTransfer.addProgressListener(
+ ReceiveFileConversationComponent.this);
+ }
}
}