summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cocoa/DownloadWindowController.m60
-rw-r--r--cocoa/gui.h1
-rw-r--r--cocoa/gui.m1
-rw-r--r--cocoa/res/DownloadWindow.xib43
4 files changed, 99 insertions, 6 deletions
diff --git a/cocoa/DownloadWindowController.m b/cocoa/DownloadWindowController.m
index 701b8817a..adce55f5d 100644
--- a/cocoa/DownloadWindowController.m
+++ b/cocoa/DownloadWindowController.m
@@ -20,6 +20,7 @@
#import "desktop/download.h"
#import "desktop/gui.h"
+#import "cocoa/gui.h"
@interface DownloadWindowController ()
@@ -29,6 +30,7 @@
- (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
+- (void)askCancelDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
- (BOOL) receivedData: (NSData *)data;
@@ -164,6 +166,33 @@ static void cocoa_register_download( DownloadWindowController *download );
[self removeIfPossible];
}
+- (BOOL) windowShouldClose: (id)sender;
+{
+ if ([[NSUserDefaults standardUserDefaults] boolForKey: kAlwaysCancelDownload]) return YES;
+
+ NSAlert *ask = [NSAlert alertWithMessageText: @"Cancel download?" defaultButton: @"Yes"
+ alternateButton: @"No" otherButton: nil
+ informativeTextWithFormat: @"Should the download of '%@' really be cancelled?", [self fileName]];
+ [ask setShowsSuppressionButton: YES];
+ [ask beginSheetModalForWindow: [self window] modalDelegate: self
+ didEndSelector: @selector(askCancelDidEnd:returnCode:contextInfo:) contextInfo: NULL];
+ return NO;
+}
+
+- (void) windowWillClose: (NSNotification *)notification;
+{
+ [self abort];
+}
+
+- (void)askCancelDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
+{
+ if (returnCode == NSOKButton) {
+ [[NSUserDefaults standardUserDefaults] setBool: [[alert suppressionButton] state] == NSOnState
+ forKey: kAlwaysCancelDownload];
+ [self close];
+ }
+}
+
#pragma mark -
#pragma mark Properties
@@ -211,23 +240,46 @@ static NSString *cocoa_file_size_string( float size )
return [NSString stringWithFormat:@"%1.1f TB", size];
}
+static NSString *cocoa_time_string( unsigned seconds )
+{
+ if (seconds <= 10) return @"less than 10 seconds";
+
+ if (seconds < 60) return [NSString stringWithFormat: @"%u seconds", seconds];
+
+ unsigned minutes = seconds / 60;
+ seconds = seconds % 60;
+
+ if (minutes < 60) return [NSString stringWithFormat: @"%u:%02u minutes", minutes, seconds];
+
+ unsigned hours = minutes / 60;
+ minutes = minutes % 60;
+
+ return [NSString stringWithFormat: @"%2:%02u hours", hours, minutes];
+}
+
- (NSString *) statusText;
{
NSString *speedString = @"";
- float elapsedTime = [[NSDate date] timeIntervalSinceDate: startDate];
+ float speed = 0.0;
+ NSTimeInterval elapsedTime = [[NSDate date] timeIntervalSinceDate: startDate];
if (elapsedTime >= 0.1) {
- float speed = (float)receivedSize / elapsedTime;
+ speed = (float)receivedSize / elapsedTime;
speedString = [NSString stringWithFormat: @" (%@/s)", cocoa_file_size_string( speed )];
}
+ NSString *timeRemainingString = @"";
NSString *totalSizeString = @"";
if (totalSize != 0) {
+ if (speed > 0.0) {
+ float timeRemaining = (float)(totalSize - receivedSize) / speed;
+ timeRemainingString = [NSString stringWithFormat: @": %@", cocoa_time_string( timeRemaining )];
+ }
totalSizeString = [NSString stringWithFormat: @" of %@", cocoa_file_size_string( totalSize )];
}
- return [NSString stringWithFormat: @"%@%@%@", cocoa_file_size_string( receivedSize ),
- totalSizeString, speedString];
+ return [NSString stringWithFormat: @"%@%@%@%@", cocoa_file_size_string( receivedSize ),
+ totalSizeString, speedString, timeRemainingString];
}
+ (NSSet *) keyPathsForValuesAffectingFileName;
diff --git a/cocoa/gui.h b/cocoa/gui.h
index df2c23fde..b4b78466e 100644
--- a/cocoa/gui.h
+++ b/cocoa/gui.h
@@ -23,5 +23,6 @@ extern NSString * const kURLsFileOption;
extern NSString * const kHotlistFileOption;
extern NSString * const kHomepageURLOption;
extern NSString * const kOptionsFileOption;
+extern NSString * const kAlwaysCancelDownload;
void cocoa_autorelease( void );
diff --git a/cocoa/gui.m b/cocoa/gui.m
index 33ab922d3..9bb1bab36 100644
--- a/cocoa/gui.m
+++ b/cocoa/gui.m
@@ -45,6 +45,7 @@ NSString * const kURLsFileOption = @"URLsFile";
NSString * const kHotlistFileOption = @"Hotlist";
NSString * const kHomepageURLOption = @"HomepageURL";
NSString * const kOptionsFileOption = @"ClassicOptionsFile";
+NSString * const kAlwaysCancelDownload = @"AlwaysCancelDownload";
#define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ )
diff --git a/cocoa/res/DownloadWindow.xib b/cocoa/res/DownloadWindow.xib
index 9d960d019..039ff1914 100644
--- a/cocoa/res/DownloadWindow.xib
+++ b/cocoa/res/DownloadWindow.xib
@@ -12,7 +12,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="2"/>
+ <integer value="1"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -247,6 +247,14 @@
</object>
<int key="connectionID">24</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">delegate</string>
+ <reference key="source" ref="1005"/>
+ <reference key="destination" ref="1001"/>
+ </object>
+ <int key="connectionID">25</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -422,7 +430,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">24</int>
+ <int key="maxID">25</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -435,6 +443,37 @@
<string key="minorKey">DownloadWindowController.h</string>
</object>
</object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSApplication</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">PSMTabBarControl/PSMTabDragAssistant.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">PSMTabBarControl/PSMTabBarCell.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">PSMTabBarControl/PSMTabBarControl.h</string>
+ </object>
+ </object>
+ </object>
+ <object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.2+">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">Print.framework/Headers/PDEPluginInterface.h</string>
+ </object>
+ </object>
</object>
</object>
<int key="IBDocument.localizationMode">0</int>