Skip to content

Commit

Permalink
Rewrite to display remote attributes from transfer status.
Browse files Browse the repository at this point in the history
Former-commit-id: 89516e62098dd3e557a47bc1535f27a29ac4de83
  • Loading branch information
dkocher committed Feb 12, 2014
1 parent 3370fd1 commit d34babc
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 172 deletions.
27 changes: 0 additions & 27 deletions source/ch/cyberduck/ui/cocoa/DownloadPromptModel.java
Expand Up @@ -19,14 +19,8 @@
*/

import ch.cyberduck.core.Cache;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.Session;
import ch.cyberduck.core.formatter.SizeFormatterFactory;
import ch.cyberduck.core.transfer.Transfer;
import ch.cyberduck.ui.cocoa.application.NSImage;
import ch.cyberduck.ui.cocoa.foundation.NSAttributedString;
import ch.cyberduck.ui.cocoa.foundation.NSObject;
import ch.cyberduck.ui.resources.IconCacheFactory;

/**
* @version $Id$
Expand All @@ -36,25 +30,4 @@ public class DownloadPromptModel extends TransferPromptModel {
public DownloadPromptModel(final TransferPromptController c, final Session session, final Transfer transfer, final Cache cache) {
super(c, session, transfer, cache);
}

@Override
protected NSObject objectValueForItem(final Path file, final String identifier) {
if(identifier.equals(Column.size.name())) {
return NSAttributedString.attributedStringWithAttributes(
SizeFormatterFactory.get().format(file.getLocal().attributes().getSize()),
TableCellAttributes.browserFontRightAlignment());
}
if(identifier.equals(Column.warning.name())) {
if(file.attributes().isFile()) {
if(file.attributes().getSize() == 0) {
return IconCacheFactory.<NSImage>get().iconNamed("alert.tiff");
}
if(file.getLocal().attributes().getSize() > file.attributes().getSize()) {
return IconCacheFactory.<NSImage>get().iconNamed("alert.tiff");
}
}
return null;
}
return super.objectValueForItem(file, identifier);
}
}
31 changes: 3 additions & 28 deletions source/ch/cyberduck/ui/cocoa/SyncPromptModel.java
Expand Up @@ -21,11 +21,10 @@
import ch.cyberduck.core.Cache;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.Session;
import ch.cyberduck.core.formatter.SizeFormatterFactory;
import ch.cyberduck.core.synchronization.Comparison;
import ch.cyberduck.core.transfer.SyncTransfer;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.ui.cocoa.application.NSImage;
import ch.cyberduck.ui.cocoa.foundation.NSAttributedString;
import ch.cyberduck.ui.cocoa.foundation.NSObject;
import ch.cyberduck.ui.resources.IconCacheFactory;

Expand Down Expand Up @@ -54,13 +53,6 @@ public enum Column {

@Override
protected NSObject objectValueForItem(final Path file, final String identifier) {
if(identifier.equals(TransferPromptModel.Column.size.name())) {
final Comparison compare = transfer.compare(file);
return NSAttributedString.attributedStringWithAttributes(
SizeFormatterFactory.get().format(
compare.equals(Comparison.remote) ? file.attributes().getSize() : file.getLocal().attributes().getSize()),
TableCellAttributes.browserFontRightAlignment());
}
if(identifier.equals(Column.sync.name())) {
final Comparison compare = transfer.compare(file);
if(compare.equals(Comparison.remote)) {
Expand All @@ -71,28 +63,11 @@ protected NSObject objectValueForItem(final Path file, final String identifier)
}
return null;
}
if(identifier.equals(TransferPromptModel.Column.warning.name())) {
if(file.attributes().isFile()) {
if(file.attributes().getSize() == 0) {
return IconCacheFactory.<NSImage>get().iconNamed("alert.tiff");
}
if(file.getLocal().exists()) {
if(file.getLocal().attributes().getSize() == 0) {
return IconCacheFactory.<NSImage>get().iconNamed("alert.tiff");
}
}
}
return null;
}
if(identifier.equals(Column.create.name())) {
if(!file.getLocal().exists()) {
final TransferStatus status = this.getStatus(file);
if(!status.isExists()) {
return IconCacheFactory.<NSImage>get().iconNamed("plus.tiff", 16);
}
if(status.containsKey(file)) {
if(!status.get(file).isExists()) {
return IconCacheFactory.<NSImage>get().iconNamed("plus.tiff", 16);
}
}
return null;
}
return super.objectValueForItem(file, identifier);
Expand Down
21 changes: 16 additions & 5 deletions source/ch/cyberduck/ui/cocoa/TransferPromptController.java
Expand Up @@ -18,13 +18,23 @@
* dkocher@cyberduck.ch
*/

import ch.cyberduck.core.*;
import ch.cyberduck.core.Cache;
import ch.cyberduck.core.DescriptiveUrl;
import ch.cyberduck.core.LocaleFactory;
import ch.cyberduck.core.NSObjectPathReference;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.Preferences;
import ch.cyberduck.core.ProgressListener;
import ch.cyberduck.core.Session;
import ch.cyberduck.core.TranscriptListener;
import ch.cyberduck.core.UserDateFormatterFactory;
import ch.cyberduck.core.formatter.SizeFormatterFactory;
import ch.cyberduck.core.shared.DefaultUrlProvider;
import ch.cyberduck.core.threading.BackgroundAction;
import ch.cyberduck.core.transfer.Transfer;
import ch.cyberduck.core.transfer.TransferAction;
import ch.cyberduck.core.transfer.TransferPrompt;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.ui.cocoa.application.*;
import ch.cyberduck.ui.cocoa.foundation.NSAttributedString;
import ch.cyberduck.ui.cocoa.foundation.NSNotification;
Expand Down Expand Up @@ -278,20 +288,21 @@ public void selectionDidChange(NSNotification notification) {
remoteURLField.setAttributedStringValue(NSAttributedString.attributedStringWithAttributes(
new DefaultUrlProvider(transfer.getHost()).toUrl(file).find(DescriptiveUrl.Type.provider).getUrl(),
TRUNCATE_MIDDLE_ATTRIBUTES));
if(file.attributes().getSize() == -1) {
final TransferStatus status = browserModel.getStatus(file);
if(status.getRemote().getSize() == -1) {
remoteSizeField.setAttributedStringValue(UNKNOWN_STRING);
}
else {
remoteSizeField.setAttributedStringValue(NSAttributedString.attributedStringWithAttributes(
SizeFormatterFactory.get().format(file.attributes().getSize()),
SizeFormatterFactory.get().format(status.getRemote().getSize()),
TRUNCATE_MIDDLE_ATTRIBUTES));
}
if(file.attributes().getModificationDate() == -1) {
if(status.getRemote().getModificationDate() == -1) {
remoteModificationField.setAttributedStringValue(UNKNOWN_STRING);
}
else {
remoteModificationField.setAttributedStringValue(NSAttributedString.attributedStringWithAttributes(
UserDateFormatterFactory.get().getLongFormat(file.attributes().getModificationDate()),
UserDateFormatterFactory.get().getLongFormat(status.getRemote().getModificationDate()),
TRUNCATE_MIDDLE_ATTRIBUTES));
}
}
Expand Down
30 changes: 29 additions & 1 deletion source/ch/cyberduck/ui/cocoa/TransferPromptModel.java
Expand Up @@ -24,17 +24,20 @@
import ch.cyberduck.core.Path;
import ch.cyberduck.core.Preferences;
import ch.cyberduck.core.Session;
import ch.cyberduck.core.formatter.SizeFormatterFactory;
import ch.cyberduck.core.transfer.Transfer;
import ch.cyberduck.core.transfer.TransferAction;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.ui.action.TransferPromptFilterWorker;
import ch.cyberduck.ui.action.TransferPromptListWorker;
import ch.cyberduck.ui.cocoa.application.NSCell;
import ch.cyberduck.ui.cocoa.application.NSImage;
import ch.cyberduck.ui.cocoa.application.NSOutlineView;
import ch.cyberduck.ui.cocoa.application.NSTableColumn;
import ch.cyberduck.ui.cocoa.foundation.NSAttributedString;
import ch.cyberduck.ui.cocoa.foundation.NSNumber;
import ch.cyberduck.ui.cocoa.foundation.NSObject;
import ch.cyberduck.ui.resources.IconCacheFactory;
import ch.cyberduck.ui.threading.WorkerBackgroundAction;

import org.apache.log4j.Logger;
Expand Down Expand Up @@ -116,6 +119,10 @@ public void setSelected(final Path file, boolean state) {
selected.put(file, state);
}

/**
* @param file File
* @return False if transfer filter rejected file
*/
public boolean isFiltered(final Path file) {
return !status.containsKey(file);
}
Expand All @@ -125,6 +132,15 @@ protected AttributedList<Path> get(final Path directory) {
return cache.get(null == directory ? null : directory.getReference());
}

public TransferStatus getStatus(final Path file) {
if(!status.containsKey(file)) {
// Transfer filter background task has not yet finished
log.warn(String.format("Unknown transfer status for %s", file));
return new TransferStatus();
}
return status.get(file);
}

protected AttributedList<Path> children(final Path directory) {
if(null == directory) {
// Root
Expand Down Expand Up @@ -158,7 +174,6 @@ public void cleanup(final Map<Path, TransferStatus> accepted) {
);
}


protected NSObject objectValueForItem(final Path file, final String identifier) {
if(identifier.equals(Column.include.name())) {
if(this.isFiltered(file)) {
Expand All @@ -170,6 +185,19 @@ protected NSObject objectValueForItem(final Path file, final String identifier)
return NSAttributedString.attributedStringWithAttributes(file.getName(),
TableCellAttributes.browserFontLeftAlignment());
}
if(identifier.equals(Column.size.name())) {
return NSAttributedString.attributedStringWithAttributes(
SizeFormatterFactory.get().format(this.getStatus(file).getLength()),
TableCellAttributes.browserFontRightAlignment());
}
if(identifier.equals(Column.warning.name())) {
if(file.attributes().isFile()) {
if(this.getStatus(file).getLength() == 0) {
return IconCacheFactory.<NSImage>get().iconNamed("alert.tiff");
}
}
return null;
}
throw new IllegalArgumentException(String.format("Unknown identifier %s", identifier));
}

Expand Down
27 changes: 0 additions & 27 deletions source/ch/cyberduck/ui/cocoa/UploadPromptModel.java
Expand Up @@ -19,14 +19,8 @@
*/

import ch.cyberduck.core.Cache;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.Session;
import ch.cyberduck.core.formatter.SizeFormatterFactory;
import ch.cyberduck.core.transfer.Transfer;
import ch.cyberduck.ui.cocoa.application.NSImage;
import ch.cyberduck.ui.cocoa.foundation.NSAttributedString;
import ch.cyberduck.ui.cocoa.foundation.NSObject;
import ch.cyberduck.ui.resources.IconCacheFactory;

/**
* @version $Id$
Expand All @@ -36,25 +30,4 @@ public class UploadPromptModel extends TransferPromptModel {
public UploadPromptModel(final TransferPromptController c, final Session session, final Transfer transfer, final Cache cache) {
super(c, session, transfer, cache);
}

@Override
protected NSObject objectValueForItem(final Path file, final String identifier) {
if(identifier.equals(Column.size.name())) {
return NSAttributedString.attributedStringWithAttributes(
SizeFormatterFactory.get().format(file.attributes().getSize()),
TableCellAttributes.browserFontRightAlignment());
}
if(identifier.equals(Column.warning.name())) {
if(file.attributes().isFile()) {
if(file.getLocal().attributes().getSize() == 0) {
return IconCacheFactory.<NSImage>get().iconNamed("alert.tiff");
}
if(file.attributes().getSize() > file.getLocal().attributes().getSize()) {
return IconCacheFactory.<NSImage>get().iconNamed("alert.tiff");
}
}
return null;
}
return super.objectValueForItem(file, identifier);
}
}
21 changes: 0 additions & 21 deletions source/ch/cyberduck/ui/controller/DownloadPromptModel.cs
Expand Up @@ -31,26 +31,5 @@ public DownloadPromptModel(TransferPromptController controller, Session session,
{
;
}

public override object GetSize(Path path)
{
return path.getLocal().attributes().getSize();
}

public override object GetWarningImage(Path path)
{
if (path.attributes().isFile())
{
if (path.attributes().getSize() == 0)
{
return AlertIcon;
}
if (path.getLocal().attributes().getSize() > path.attributes().getSize())
{
return AlertIcon;
}
}
return null;
}
}
}
38 changes: 2 additions & 36 deletions source/ch/cyberduck/ui/controller/SyncPromptModel.cs
Expand Up @@ -29,46 +29,12 @@ public SyncPromptModel(TransferPromptController controller, Session session, Tra
{
}

public override object GetSize(Path path)
public virtual object GetCreateImage(Path path)
{
Comparison compare = ((SyncTransfer) Transfer).compare(path);
return compare.equals(Comparison.remote)
? path.attributes().getSize()
: path.getLocal().attributes().getSize();
}

public override object GetWarningImage(Path path)
{
if (path.attributes().isFile())
{
if (path.attributes().getSize() == 0)
{
return AlertIcon;
}
if (path.getLocal().exists())
{
if (path.getLocal().attributes().getSize() == 0)
{
return AlertIcon;
}
}
}
return null;
}

public override object GetCreateImage(Path path)
{
if (!path.getLocal().exists())
if (!GetStatus(path).isExists())
{
return IconCache.Instance.IconForName("plus");
}
if (_status.ContainsKey(path))
{
if (!_status[path].isExists())
{
return IconCache.Instance.IconForName("plus");
}
}
return null;
}

Expand Down
9 changes: 5 additions & 4 deletions source/ch/cyberduck/ui/controller/TransferPromptController.cs
Expand Up @@ -183,22 +183,23 @@ private void View_ChangedSelectionEvent()
new DefaultUrlProvider(Transfer.getHost()).toUrl(selected)
.find(DescriptiveUrl.Type.provider)
.getUrl();
if (selected.attributes().getSize() == -1)
TransferStatus status = TransferPromptModel.GetStatus(selected);
if (status.getRemote().getSize() == -1)
{
View.RemoteFileSize = UnknownString;
}
else
{
View.RemoteFileSize = SizeFormatterFactory.get().format(selected.attributes().getSize());
View.RemoteFileSize = SizeFormatterFactory.get().format(status.getRemote());
}
if (selected.attributes().getModificationDate() == -1)
if (status.getRemote().getModificationDate() == -1)
{
View.RemoteFileModificationDate = UnknownString;
}
else
{
View.RemoteFileModificationDate =
UserDateFormatterFactory.get().getLongFormat(selected.attributes().getModificationDate());
UserDateFormatterFactory.get().getLongFormat(status.getRemote().getModificationDate());
}
}
else
Expand Down

0 comments on commit d34babc

Please sign in to comment.