[sip-comm-dev] Re: svn commit: r5402 - trunk/src/net/java/sip/communicator/impl: fileaccess gui/main/chat/filetransfer


#1

Hey Yana,

I see that you've deleted the explicit import of SwingWorker which I
added. Please note though that SwingWorker is also available in Java 6
and the imports of both javax.swing.* and
net.java.sip.communicator.util.swing.* cause a compile-type error on
Java 6 because the type SwingWorker is ambiguous.

Thank you,
Lubo

···

2009/6/18 <yanas@dev.java.net>:

Author: yanas
Date: 2009-06-18 13:47:22+0000
New Revision: 5402

Modified:
trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java
trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf
trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java

Log:
- 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.

Modified: trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java?view=diff&rev=5402&p1=trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java&p2=trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java&r1=5401&r2=5402

--- trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java (original)
+++ trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java 2009-06-18 13:47:22+0000
@@ -8,6 +8,8 @@

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 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;

Modified: trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf?view=diff&rev=5402&p1=trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf&p2=trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf&r1=5401&r2=5402

--- trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf (original)
+++ trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf 2009-06-18 13:47:22+0000
@@ -11,6 +11,7 @@
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,

Modified: trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java?view=diff&rev=5402&p1=trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java&p2=trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java&r1=5401&r2=5402

--- trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java (original)
+++ trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java 2009-06-18 13:47:22+0000
@@ -21,7 +21,6 @@
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 @@
{
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 @@
titleLabel.setText(resources.getI18NString(
"service.gui.FILE_RECEIVE_COMPLETED",
new String[]{fromContactName}));
- fileLabel.setText(fileTransferRequest.getFileName());

        imageLabel\.setToolTipText\(
            resources\.getI18NString\(&quot;service\.gui\.OPEN\_FILE\_FROM\_IMAGE&quot;\)\);

@@ -494,10 +518,13 @@

    public void finished\(\)
    \{

- fileTransfer.addStatusListener(
- ReceiveFileConversationComponent.this);
- fileTransfer.addProgressListener(
- ReceiveFileConversationComponent.this);
+ if (fileTransfer != null)
+ {
+ fileTransfer.addStatusListener(
+ ReceiveFileConversationComponent.this);
+ fileTransfer.addProgressListener(
+ ReceiveFileConversationComponent.this);
+ }
}
}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: commits-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net


#2

Hi Lubo,

I know and thanks for the fix on first place!

Actually I didn't remove it on purpose, it's just the "Organize imports" option in Eclipse that does that automatically. I'll be more careful next time!

Thanks again!
Yana

Lubomir Marinov wrote:

···

Hey Yana,

I see that you've deleted the explicit import of SwingWorker which I
added. Please note though that SwingWorker is also available in Java 6
and the imports of both javax.swing.* and
net.java.sip.communicator.util.swing.* cause a compile-type error on
Java 6 because the type SwingWorker is ambiguous.

Thank you,
Lubo

2009/6/18 <yanas@dev.java.net>:

Author: yanas
Date: 2009-06-18 13:47:22+0000
New Revision: 5402

Modified:
  trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java
  trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf
  trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java

Log:
- 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.

Modified: trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java?view=diff&rev=5402&p1=trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java&p2=trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java&r1=5401&r2=5402

--- trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java (original)
+++ trunk/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java 2009-06-18 13:47:22+0000
@@ -8,6 +8,8 @@

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 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;

Modified: trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf?view=diff&rev=5402&p1=trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf&p2=trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf&r1=5401&r2=5402

--- trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf (original)
+++ trunk/src/net/java/sip/communicator/impl/fileaccess/fileaccess.manifest.mf 2009-06-18 13:47:22+0000
@@ -11,6 +11,7 @@
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,

Modified: trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java?view=diff&rev=5402&p1=trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java&p2=trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java&r1=5401&r2=5402

--- trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java (original)
+++ trunk/src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java 2009-06-18 13:47:22+0000
@@ -21,7 +21,6 @@
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 @@
    {
        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 @@
            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 void finished()
        {
- fileTransfer.addStatusListener(
- ReceiveFileConversationComponent.this);
- fileTransfer.addProgressListener(
- ReceiveFileConversationComponent.this);
+ if (fileTransfer != null)
+ {
+ fileTransfer.addStatusListener(
+ ReceiveFileConversationComponent.this);
+ fileTransfer.addProgressListener(
+ ReceiveFileConversationComponent.this);
+ }
        }
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: commits-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net