add pause/resume to download manager (bug 187483)

This commit is contained in:
pinkerton%aol.net 2005-08-02 22:53:43 +00:00
Родитель fc97cdf23e
Коммит f8e5d82100
13 изменённых файлов: 283 добавлений и 67 удалений

Просмотреть файл

@ -3236,6 +3236,8 @@
0F5187C408858E620091F3FB, 0F5187C408858E620091F3FB,
0FB6D99B089B276100414498, 0FB6D99B089B276100414498,
3FEBB43C089DA88C00BD8373, 3FEBB43C089DA88C00BD8373,
3FEBB4E908A02F2900BD8373,
3FEBB4EA08A02F2900BD8373,
); );
isa = PBXResourcesBuildPhase; isa = PBXResourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@ -7088,6 +7090,8 @@
3FFE23540847CB0D00D6CAFC, 3FFE23540847CB0D00D6CAFC,
0FB6D99C089B276100414498, 0FB6D99C089B276100414498,
3FEBB43D089DA88C00BD8373, 3FEBB43D089DA88C00BD8373,
3FEBB4EB08A02F2900BD8373,
3FEBB4EC08A02F2900BD8373,
); );
isa = PBXResourcesBuildPhase; isa = PBXResourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@ -10509,6 +10513,46 @@
settings = { settings = {
}; };
}; };
3FEBB4E708A02F2900BD8373 = {
isa = PBXFileReference;
lastKnownFileType = image.tiff;
name = dl_pause.tif;
path = resources/images/toolbar/dl_pause.tif;
refType = 2;
sourceTree = SOURCE_ROOT;
};
3FEBB4E808A02F2900BD8373 = {
isa = PBXFileReference;
lastKnownFileType = image.tiff;
name = dl_resume.tif;
path = resources/images/toolbar/dl_resume.tif;
refType = 2;
sourceTree = SOURCE_ROOT;
};
3FEBB4E908A02F2900BD8373 = {
fileRef = 3FEBB4E708A02F2900BD8373;
isa = PBXBuildFile;
settings = {
};
};
3FEBB4EA08A02F2900BD8373 = {
fileRef = 3FEBB4E808A02F2900BD8373;
isa = PBXBuildFile;
settings = {
};
};
3FEBB4EB08A02F2900BD8373 = {
fileRef = 3FEBB4E708A02F2900BD8373;
isa = PBXBuildFile;
settings = {
};
};
3FEBB4EC08A02F2900BD8373 = {
fileRef = 3FEBB4E808A02F2900BD8373;
isa = PBXBuildFile;
settings = {
};
};
3FECC78F05D1F68E0068E7ED = { 3FECC78F05D1F68E0068E7ED = {
children = ( children = (
3F44AD8705BDFB9F00CB4B08, 3F44AD8705BDFB9F00CB4B08,
@ -13536,6 +13580,8 @@
3FC0FB8605A0D2F4002F47DE, 3FC0FB8605A0D2F4002F47DE,
3FC0FB8705A0D2F4002F47DE, 3FC0FB8705A0D2F4002F47DE,
0382B4D907303CCA00A0228A, 0382B4D907303CCA00A0228A,
3FEBB4E708A02F2900BD8373,
3FEBB4E808A02F2900BD8373,
F5555C8202022F070164C72B, F5555C8202022F070164C72B,
F5555C8302022F070164C72B, F5555C8302022F070164C72B,
F5555C8402022F070164C72B, F5555C8402022F070164C72B,

Двоичные данные
camino/resources/images/toolbar/dl_pause.tif Normal file

Двоичный файл не отображается.

Двоичные данные
camino/resources/images/toolbar/dl_resume.tif Normal file

Двоичный файл не отображается.

Двоичный файл не отображается.

Просмотреть файл

@ -7,16 +7,15 @@
<key>IBEditorPositions</key> <key>IBEditorPositions</key>
<dict> <dict>
<key>5</key> <key>5</key>
<string>445 508 346 92 0 0 1280 832 </string> <string>339 461 346 92 0 0 1024 746 </string>
<key>71</key> <key>71</key>
<string>445 508 346 92 0 0 1280 832 </string> <string>339 462 346 92 0 0 1024 746 </string>
</dict> </dict>
<key>IBFramework Version</key> <key>IBFramework Version</key>
<string>364.0</string> <string>439.0</string>
<key>IBLockedObjects</key> <key>IBLockedObjects</key>
<array> <array>
<integer>5</integer> <integer>5</integer>
<integer>71</integer>
</array> </array>
<key>IBOpenObjects</key> <key>IBOpenObjects</key>
<array> <array>
@ -24,6 +23,6 @@
<integer>5</integer> <integer>5</integer>
</array> </array>
<key>IBSystem Version</key> <key>IBSystem Version</key>
<string>7M34</string> <string>8C46</string>
</dict> </dict>
</plist> </plist>

Двоичные данные
camino/resources/localized/English.lproj/ProgressView.nib/keyedobjects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -96,6 +96,8 @@
-(IBAction)reveal:(id)sender; -(IBAction)reveal:(id)sender;
-(IBAction)cleanUpDownloads:(id)sender; -(IBAction)cleanUpDownloads:(id)sender;
-(IBAction)open:(id)sender; -(IBAction)open:(id)sender;
-(IBAction)pause:(id)sender;
-(IBAction)resume:(id)sender;
-(int)numDownloadsInProgress; -(int)numDownloadsInProgress;
-(void)clearAllDownloads; -(void)clearAllDownloads;

Просмотреть файл

@ -22,6 +22,7 @@
* Contributor(s): * Contributor(s):
* Calum Robinson <calumr@mac.com> * Calum Robinson <calumr@mac.com>
* Josh Aas <josha@mac.com> * Josh Aas <josha@mac.com>
* Nick Kreeger <nick.kreeger@gmail.com>
* *
* Alternatively, the contents of this file may be used under the terms of * Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or * either the GNU General Public License Version 2 or later (the "GPL"), or
@ -95,7 +96,7 @@ static id gSharedProgressController = nil;
-(void)awakeFromNib -(void)awakeFromNib
{ {
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"dlmanager"]; NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"dlmanager1"]; // so pause/resume button will show
[toolbar setDelegate:self]; [toolbar setDelegate:self];
[toolbar setAllowsUserCustomization:YES]; [toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES]; [toolbar setAutosavesConfiguration:YES];
@ -117,9 +118,9 @@ static id gSharedProgressController = nil;
-(IBAction)cancel:(id)sender -(IBAction)cancel:(id)sender
{ {
NSMutableArray* selected = [self getSelectedProgressViewControllers]; NSMutableArray* selected = [self getSelectedProgressViewControllers];
unsigned count = [selected count]; unsigned int count = [selected count];
for (unsigned i = 0; i < count; i++) { for (unsigned int i = 0; i < count; i++) {
[[selected objectAtIndex:i] cancel:self]; [[selected objectAtIndex:i] cancel:sender];
} }
} }
@ -127,9 +128,9 @@ static id gSharedProgressController = nil;
-(IBAction)reveal:(id)sender -(IBAction)reveal:(id)sender
{ {
NSMutableArray* selected = [self getSelectedProgressViewControllers]; NSMutableArray* selected = [self getSelectedProgressViewControllers];
unsigned count = [selected count]; unsigned int count = [selected count];
for (unsigned i = 0; i < count; i++) { for (unsigned int i = 0; i < count; i++) {
[[selected objectAtIndex:i] reveal:self]; [[selected objectAtIndex:i] reveal:sender];
} }
} }
@ -137,9 +138,9 @@ static id gSharedProgressController = nil;
-(IBAction)open:(id)sender -(IBAction)open:(id)sender
{ {
NSMutableArray* selected = [self getSelectedProgressViewControllers]; NSMutableArray* selected = [self getSelectedProgressViewControllers];
unsigned count = [selected count]; unsigned int count = [selected count];
for (unsigned i = 0; i < count; i++) { for (unsigned int i = 0; i < count; i++) {
[[selected objectAtIndex:i] open:self]; [[selected objectAtIndex:i] open:sender];
} }
} }
@ -148,8 +149,8 @@ static id gSharedProgressController = nil;
{ {
// take care of selecting a download instance to replace the selection being removed // take care of selecting a download instance to replace the selection being removed
NSMutableArray* selected = [self getSelectedProgressViewControllers]; NSMutableArray* selected = [self getSelectedProgressViewControllers];
unsigned selectedCount = [selected count]; unsigned int selectedCount = [selected count];
unsigned indexOfLastSelection = [mProgressViewControllers indexOfObject:[selected objectAtIndex:(((int)selectedCount) - 1)]]; unsigned int indexOfLastSelection = [mProgressViewControllers indexOfObject:[selected objectAtIndex:(((int)selectedCount) - 1)]];
// if dl instance after last selection exists, select it or look for something else to select // if dl instance after last selection exists, select it or look for something else to select
if ((indexOfLastSelection + 1) < [mProgressViewControllers count]) { if ((indexOfLastSelection + 1) < [mProgressViewControllers count]) {
[[((ProgressViewController*)[mProgressViewControllers objectAtIndex:(indexOfLastSelection + 1)]) view] setSelected:YES]; [[((ProgressViewController*)[mProgressViewControllers objectAtIndex:(indexOfLastSelection + 1)]) view] setSelected:YES];
@ -166,13 +167,37 @@ static id gSharedProgressController = nil;
mSelectionPivotIndex = -1; // nothing is selected any more so nothing to pivot on mSelectionPivotIndex = -1; // nothing is selected any more so nothing to pivot on
// now remove stuff // now remove stuff
for (unsigned i = 0; i < selectedCount; i++) { for (unsigned int i = 0; i < selectedCount; i++) {
if (![[selected objectAtIndex:i] isActive]) { if (![[selected objectAtIndex:i] isActive]) {
[self removeDownload:[selected objectAtIndex:i]]; [self removeDownload:[selected objectAtIndex:i]];
} }
} }
} }
-(IBAction)pause:(id)sender
{
NSMutableArray* selected = [self getSelectedProgressViewControllers];
unsigned int count = [selected count];
for (unsigned int i = 0; i < count; i++)
{
[[selected objectAtIndex:i] pause:sender];
}
[self rebuildViews];
}
-(IBAction)resume:(id)sender
{
NSMutableArray* selected = [self getSelectedProgressViewControllers];
unsigned int count = [selected count];
for (unsigned int i = 0; i < count; i++)
{
[[selected objectAtIndex:i] resume:sender];
}
[self rebuildViews];
}
// remove all inactive instances // remove all inactive instances
-(IBAction)cleanUpDownloads:(id)sender -(IBAction)cleanUpDownloads:(id)sender
{ {
@ -562,40 +587,66 @@ static id gSharedProgressController = nil;
-(BOOL)shouldAllowCancelAction -(BOOL)shouldAllowCancelAction
{ {
NSMutableArray* selectedArray = [self getSelectedProgressViewControllers]; NSMutableArray* selectedArray = [self getSelectedProgressViewControllers];
unsigned selectedCount = [selectedArray count]; unsigned int selectedCount = [selectedArray count];
// if no selections are inactive or canceled then allow cancel // if no selections are inactive or canceled then allow cancel
for (unsigned i = 0; i < selectedCount; i++) { for (unsigned int i = 0; i < selectedCount; i++) {
if ((![[selectedArray objectAtIndex:i] isActive]) || [[selectedArray objectAtIndex:i] isCanceled]) { if ((![[selectedArray objectAtIndex:i] isActive]) || [[selectedArray objectAtIndex:i] isCanceled]) {
return FALSE; return NO;
} }
} }
return TRUE; return YES;
} }
-(BOOL)shouldAllowRemoveAction -(BOOL)shouldAllowRemoveAction
{ {
NSMutableArray* selectedArray = [self getSelectedProgressViewControllers]; NSMutableArray* selectedArray = [self getSelectedProgressViewControllers];
unsigned selectedCount = [selectedArray count]; unsigned int selectedCount = [selectedArray count];
// if no selections are active then allow remove // if no selections are active then allow remove
for (unsigned i = 0; i < selectedCount; i++) { for (unsigned int i = 0; i < selectedCount; i++) {
if ([[selectedArray objectAtIndex:i] isActive]) { if ([[selectedArray objectAtIndex:i] isActive]) {
return FALSE; return NO;
} }
} }
return TRUE; return YES;
} }
-(BOOL)shouldAllowOpenAction -(BOOL)shouldAllowOpenAction
{ {
NSMutableArray* selectedArray = [self getSelectedProgressViewControllers]; NSMutableArray* selectedArray = [self getSelectedProgressViewControllers];
unsigned selectedCount = [selectedArray count]; unsigned int selectedCount = [selectedArray count];
// if no selections are are active or canceled then allow open // if no selections are are active or canceled then allow open
for (unsigned i = 0; i < selectedCount; i++) { for (unsigned int i = 0; i < selectedCount; i++) {
if ([[selectedArray objectAtIndex:i] isActive] || [[selectedArray objectAtIndex:i] isCanceled]) { if ([[selectedArray objectAtIndex:i] isActive] || [[selectedArray objectAtIndex:i] isCanceled]) {
return FALSE; return NO;
} }
} }
return TRUE; return YES;
}
- (BOOL)shouldAllowPauseAction
{
NSMutableArray* selectedArray = [self getSelectedProgressViewControllers];
unsigned int selectedCount = [selectedArray count];
// if no selections are paused, allow the pause
for (unsigned int i = 0; i < selectedCount; i++) {
if ([[selectedArray objectAtIndex:i] isPaused] || ![[selectedArray objectAtIndex:i] isActive]) {
return NO;
}
}
return YES;
}
-(BOOL)shouldAllowResumeAction
{
NSMutableArray* selectedArray = [self getSelectedProgressViewControllers];
unsigned int selectedCount = [selectedArray count];
// if no selections are paused, allow the pause
for (unsigned int i = 0; i < selectedCount; i++) {
if (![[selectedArray objectAtIndex:i] isPaused] || ![[selectedArray objectAtIndex:i] isActive]) {
return NO;
}
}
return YES;
} }
-(BOOL)validateMenuItem:(id <NSMenuItem>)menuItem -(BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
@ -610,9 +661,39 @@ static id gSharedProgressController = nil;
else if (action == @selector(open:)) { else if (action == @selector(open:)) {
return [self shouldAllowOpenAction]; return [self shouldAllowOpenAction];
} }
else if (action == @selector(pause:)) {
return [self shouldAllowPauseAction];
}
else if (action == @selector(resume:)) {
return [self shouldAllowResumeAction];
}
return YES; return YES;
} }
- (BOOL)setPauseResumeToolbarItem:(NSToolbarItem*)theItem
{
if ([self shouldAllowPauseAction]) {
[theItem setToolTip:NSLocalizedString(@"dlPauseButtonTooltip", nil)];
[theItem setLabel:NSLocalizedString(@"dlPauseButtonLabel", nil)];
[theItem setPaletteLabel:NSLocalizedString(@"dlPauseButtonLabel", nil)];
[theItem setAction:@selector(pause:)];
[theItem setImage:[NSImage imageNamed:@"dl_pause.tif"]];
return YES;
}
else if ([self shouldAllowResumeAction]) {
[theItem setToolTip:NSLocalizedString(@"dlResumeButtonTooltip", nil)];
[theItem setLabel:NSLocalizedString(@"dlResumeButtonLabel", nil)];
[theItem setPaletteLabel:NSLocalizedString(@"dlResumeButtonLabel", nil)];
[theItem setAction:@selector(resume:)];
[theItem setImage:[NSImage imageNamed:@"dl_resume.tif"]];
return YES;
}
else {
return NO;
}
}
-(BOOL)validateToolbarItem:(NSToolbarItem *)theItem -(BOOL)validateToolbarItem:(NSToolbarItem *)theItem
{ {
SEL action = [theItem action]; SEL action = [theItem action];
@ -647,7 +728,11 @@ static id gSharedProgressController = nil;
else if (action == @selector(cancel:)) { else if (action == @selector(cancel:)) {
return [self shouldAllowCancelAction]; return [self shouldAllowCancelAction];
} }
return TRUE; else if (action == @selector(pause:) || action == @selector(resume:)) {
return [self setPauseResumeToolbarItem:theItem];
}
return YES;
} }
-(NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag -(NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
@ -656,35 +741,43 @@ static id gSharedProgressController = nil;
[theItem setTarget:self]; [theItem setTarget:self];
[theItem setEnabled:NO]; [theItem setEnabled:NO];
if ([itemIdentifier isEqualToString:@"removebutton"]) { if ([itemIdentifier isEqualToString:@"removebutton"]) {
[theItem setToolTip:NSLocalizedString(@"dlRemoveButtonTooltip", @"Remove selected download(s)")]; [theItem setToolTip:NSLocalizedString(@"dlRemoveButtonTooltip", nil)];
[theItem setLabel:NSLocalizedString(@"dlRemoveButtonLabel", @"Remove")]; [theItem setLabel:NSLocalizedString(@"dlRemoveButtonLabel", nil)];
[theItem setPaletteLabel:NSLocalizedString(@"dlRemoveButtonLabel", nil)];
[theItem setAction:@selector(remove:)]; [theItem setAction:@selector(remove:)];
[theItem setImage:[NSImage imageNamed:@"dl_remove.tif"]]; [theItem setImage:[NSImage imageNamed:@"dl_remove.tif"]];
} }
else if ([itemIdentifier isEqualToString:@"cancelbutton"]) { else if ([itemIdentifier isEqualToString:@"cancelbutton"]) {
[theItem setToolTip:NSLocalizedString(@"dlCancelButtonTooltip", @"Cancel selected download(s)")]; [theItem setToolTip:NSLocalizedString(@"dlCancelButtonTooltip", nil)];
[theItem setLabel:NSLocalizedString(@"dlCancelButtonLabel", @"Cancel")]; [theItem setLabel:NSLocalizedString(@"dlCancelButtonLabel", nil)];
[theItem setPaletteLabel:NSLocalizedString(@"dlCancelButtonLabel", nil)];
[theItem setAction:@selector(cancel:)]; [theItem setAction:@selector(cancel:)];
[theItem setImage:[NSImage imageNamed:@"dl_cancel.tif"]]; [theItem setImage:[NSImage imageNamed:@"dl_cancel.tif"]];
} }
else if ([itemIdentifier isEqualToString:@"revealbutton"]) { else if ([itemIdentifier isEqualToString:@"revealbutton"]) {
[theItem setToolTip:NSLocalizedString(@"dlRevealButtonTooltip", @"Show selected download(s) in Finder")]; [theItem setToolTip:NSLocalizedString(@"dlRevealButtonTooltip", nil)];
[theItem setLabel:NSLocalizedString(@"dlRevealButtonLabel", @"Show")]; [theItem setLabel:NSLocalizedString(@"dlRevealButtonLabel", nil)];
[theItem setPaletteLabel:NSLocalizedString(@"dlRevealButtonLabel", nil)];
[theItem setAction:@selector(reveal:)]; [theItem setAction:@selector(reveal:)];
[theItem setImage:[NSImage imageNamed:@"dl_reveal.tif"]]; [theItem setImage:[NSImage imageNamed:@"dl_reveal.tif"]];
} }
else if ([itemIdentifier isEqualToString:@"openbutton"]) { else if ([itemIdentifier isEqualToString:@"openbutton"]) {
[theItem setToolTip:NSLocalizedString(@"dlOpenButtonTooltip", @"Open saved file(s)")]; [theItem setToolTip:NSLocalizedString(@"dlOpenButtonTooltip", nil)];
[theItem setLabel:NSLocalizedString(@"dlOpenButtonLabel", @"Open")]; [theItem setLabel:NSLocalizedString(@"dlOpenButtonLabel", nil)];
[theItem setPaletteLabel:NSLocalizedString(@"dlOpenButtonLabel", nil)];
[theItem setAction:@selector(open:)]; [theItem setAction:@selector(open:)];
[theItem setImage:[NSImage imageNamed:@"dl_open.tif"]]; [theItem setImage:[NSImage imageNamed:@"dl_open.tif"]];
} }
else if ([itemIdentifier isEqualToString:@"cleanupbutton"]) { else if ([itemIdentifier isEqualToString:@"cleanupbutton"]) {
[theItem setToolTip:NSLocalizedString(@"dlCleanUpButtonTooltip", @"Remove all inactive download(s)")]; [theItem setToolTip:NSLocalizedString(@"dlCleanUpButtonTooltip", nil)];
[theItem setLabel:NSLocalizedString(@"dlCleanUpButtonLabel", @"Clean Up")]; [theItem setLabel:NSLocalizedString(@"dlCleanUpButtonLabel", nil)];
[theItem setPaletteLabel:NSLocalizedString(@"dlCleanUpButtonLabel", nil)];
[theItem setAction:@selector(cleanUpDownloads:)]; [theItem setAction:@selector(cleanUpDownloads:)];
[theItem setImage:[NSImage imageNamed:@"dl_clearall.tif"]]; [theItem setImage:[NSImage imageNamed:@"dl_clearall.tif"]];
} }
else if ([itemIdentifier isEqualToString:@"pauseresumebutton"]) {
[self setPauseResumeToolbarItem:theItem];
}
else { else {
return nil; return nil;
} }
@ -693,12 +786,12 @@ static id gSharedProgressController = nil;
-(NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar -(NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{ {
return [NSArray arrayWithObjects:@"removebutton", @"cleanupbutton", @"cancelbutton", @"openbutton", @"revealbutton", NSToolbarFlexibleSpaceItemIdentifier, nil]; return [NSArray arrayWithObjects:@"removebutton", @"cleanupbutton", @"cancelbutton", @"pauseresumebutton", @"openbutton", @"revealbutton", NSToolbarFlexibleSpaceItemIdentifier, nil];
} }
-(NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar -(NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{ {
return [NSArray arrayWithObjects:@"cleanupbutton", @"removebutton", @"cancelbutton", @"openbutton", NSToolbarFlexibleSpaceItemIdentifier, @"revealbutton", nil]; return [NSArray arrayWithObjects:@"cleanupbutton", @"removebutton", @"cancelbutton", @"pauseresumebutton", @"openbutton", NSToolbarFlexibleSpaceItemIdentifier, @"revealbutton", nil];
} }
#pragma mark - #pragma mark -

Просмотреть файл

@ -100,10 +100,13 @@ enum {
-(IBAction)remove:(id)sender; -(IBAction)remove:(id)sender;
-(IBAction)reveal:(id)sender; -(IBAction)reveal:(id)sender;
-(IBAction)open:(id)sender; -(IBAction)open:(id)sender;
-(IBAction)pause:(id)sender;
-(IBAction)resume:(id)sender;
-(BOOL)isActive; -(BOOL)isActive;
-(BOOL)isCanceled; -(BOOL)isCanceled;
-(BOOL)isSelected; -(BOOL)isSelected;
-(BOOL)isPaused;
-(NSMenu*)contextualMenu; -(NSMenu*)contextualMenu;

Просмотреть файл

@ -23,6 +23,7 @@
* Calum Robinson <calumr@mac.com> * Calum Robinson <calumr@mac.com>
* Simon Fraser <sfraser@netscape.com> * Simon Fraser <sfraser@netscape.com>
* Josh Aas <josha@mac.com> * Josh Aas <josha@mac.com>
* Nick Kreeger <nick.kreeger@gmail.com>
* *
* Alternatively, the contents of this file may be used under the terms of * Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or * either the GNU General Public License Version 2 or later (the "GPL"), or
@ -101,24 +102,24 @@ enum {
// check for seconds first // check for seconds first
if (seconds < 60) { if (seconds < 60) {
if (seconds < 7) if (seconds < 7)
return [NSString stringWithFormat:NSLocalizedString(@"UnderSec", @"Under %d seconds"), 5]; return [NSString stringWithFormat:NSLocalizedString(@"UnderSec", nil), 5];
if (seconds < 13) if (seconds < 13)
return [NSString stringWithFormat:NSLocalizedString(@"UnderSec", @"Under %d seconds"), 10]; return [NSString stringWithFormat:NSLocalizedString(@"UnderSec", nil), 10];
return [NSString stringWithFormat:NSLocalizedString(@"UnderMin", @"Under a minute")]; return [NSString stringWithFormat:NSLocalizedString(@"UnderMin", nil)];
} }
// seconds becomes minutes and we keep checking. // seconds becomes minutes and we keep checking.
seconds = seconds/60; seconds = seconds/60;
if (seconds < 60) { if (seconds < 60) {
if (seconds < 2) if (seconds < 2)
return [NSString stringWithFormat:NSLocalizedString(@"AboutMin",@"About a minute")]; return [NSString stringWithFormat:NSLocalizedString(@"AboutMin", nil)];
// OK, tell the good people how much time we have left. // OK, tell the good people how much time we have left.
return [NSString stringWithFormat:NSLocalizedString(@"AboutMins",@"About %d minutes"), seconds]; return [NSString stringWithFormat:NSLocalizedString(@"AboutMins", nil), seconds];
} }
//this download will never seemingly never end. now seconds become hours. //this download will never seemingly never end. now seconds become hours.
seconds = seconds/60; seconds = seconds/60;
if (seconds < 2) if (seconds < 2)
return [NSString stringWithFormat:NSLocalizedString(@"AboutHour", @"Over an hour")]; return [NSString stringWithFormat:NSLocalizedString(@"AboutHour", nil)];
return [NSString stringWithFormat:NSLocalizedString(@"AboutHours", @"Over %d hours"), seconds]; return [NSString stringWithFormat:NSLocalizedString(@"AboutHours", nil), seconds];
} }
+(NSString*)formatBytes:(float)bytes +(NSString*)formatBytes:(float)bytes
@ -209,7 +210,10 @@ enum {
-(ProgressView*)view -(ProgressView*)view
{ {
return (mDownloadDone ? mCompletedView : mProgressView); if ([self isPaused] || mDownloadDone)
return mCompletedView;
else
return mProgressView;
} }
-(IBAction)copySourceURL:(id)sender -(IBAction)copySourceURL:(id)sender
@ -252,6 +256,25 @@ enum {
return; return;
} }
-(IBAction)pause:(id)sender
{
if (!mUserCancelled && !mDownloadDone && mDownloader)
{
mDownloader->PauseDownload();
[self refreshDownloadInfo];
[[self view] setSelected:YES]; // likes to unselect its self when switching progress views
}
}
-(IBAction)resume:(id)sender
{
if (!mUserCancelled && !mDownloadDone && mDownloader)
{
mDownloader->ResumeDownload();
[self refreshDownloadInfo];
}
}
-(IBAction)remove:(id)sender -(IBAction)remove:(id)sender
{ {
[mProgressWindowController removeDownload:self]; [mProgressWindowController removeDownload:self];
@ -317,13 +340,13 @@ enum {
if (statusLabel) { if (statusLabel) {
NSString* statusString; NSString* statusString;
if (mUserCancelled) { if (mUserCancelled) {
statusString = NSLocalizedString(@"DownloadCancelled", @"Cancelled"); statusString = NSLocalizedString(@"DownloadCancelled", nil);
} }
else if (mDownloadingError) { else if (mDownloadingError) {
statusString = NSLocalizedString(@"DownloadInterrupted", @"Interrupted"); statusString = NSLocalizedString(@"DownloadInterrupted", nil);
} }
else { else {
statusString = [NSString stringWithFormat:NSLocalizedString(@"DownloadCompleted", @"Completed in %@ (%@)"), statusString = [NSString stringWithFormat:NSLocalizedString(@"DownloadCompleted", nil),
[[self class] formatTime:(int)mDownloadTime], [[self class] formatBytes:mDownloadSize]]; [[self class] formatTime:(int)mDownloadTime], [[self class] formatBytes:mDownloadSize]];
} }
@ -331,13 +354,24 @@ enum {
[statusLabel setStringValue:statusString]; [statusLabel setStringValue:statusString];
} }
} }
else if ([self isPaused]) { // update the status field
id statusLabel = [curView viewWithTag:kLabelTagStatus];
if (statusLabel) {
NSString* statusString = NSLocalizedString(@"DownloadPausedStatusString", nil);
[statusLabel setStringValue:[NSString stringWithFormat:statusString,
[[self class] formatBytes:mCurrentProgress],
(mDownloadSize > 0 ? [[self class] formatBytes:mDownloadSize] : @"?")]];
}
}
else { else {
NSTimeInterval elapsedTime = -[mStartTime timeIntervalSinceNow]; NSTimeInterval elapsedTime = -[mStartTime timeIntervalSinceNow];
// update status field // update status field
id statusLabel = [curView viewWithTag:kLabelTagStatus]; id statusLabel = [curView viewWithTag:kLabelTagStatus];
if (statusLabel) { if (statusLabel) {
NSString *statusLabelString = NSLocalizedString(@"DownloadStatusString", @"%@ of %@ (at %@/sec)"); NSString *statusLabelString = NSLocalizedString(@"DownloadStatusString", nil);
float byteSec = mCurrentProgress / elapsedTime; float byteSec = mCurrentProgress / elapsedTime;
[statusLabel setStringValue:[NSString stringWithFormat:statusLabelString, [statusLabel setStringValue:[NSString stringWithFormat:statusLabelString,
[[self class] formatBytes:mCurrentProgress], [[self class] formatBytes:mCurrentProgress],
@ -352,7 +386,7 @@ enum {
[timeLabel setStringValue:[[self class] formatFuzzyTime:secToGo]]; [timeLabel setStringValue:[[self class] formatFuzzyTime:secToGo]];
} }
else { // mDownloadSize is undetermined. Set remaining time to question marks. else { // mDownloadSize is undetermined. Set remaining time to question marks.
[timeLabel setStringValue:NSLocalizedString(@"DownloadCalculatingString", @"Unknown")]; [timeLabel setStringValue:NSLocalizedString(@"DownloadCalculatingString", nil)];
} }
} }
} }
@ -378,34 +412,52 @@ enum {
return [[self view] isSelected]; return [[self view] isSelected];
} }
-(BOOL)isPaused
{
if (mDownloader)
return mDownloader->IsDownloadPaused();
return NO;
}
-(NSMenu*)contextualMenu -(NSMenu*)contextualMenu
{ {
NSMenu *menu = [[NSMenu alloc] init]; NSMenu *menu = [[NSMenu alloc] init];
NSMenuItem *revealItem; NSMenuItem *revealItem;
NSMenuItem *cancelItem; NSMenuItem *cancelItem;
NSMenuItem *removeItem; NSMenuItem *removeItem;
NSMenuItem *pauseResumeItem; // alternates pause and resume
NSMenuItem *openItem; NSMenuItem *openItem;
NSMenuItem *copySourceURLItem; NSMenuItem *copySourceURLItem;
revealItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlRevealCMLabel", @"Show in Finder") revealItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlRevealCMLabel", nil)
action:@selector(reveal:) keyEquivalent:@""]; action:@selector(reveal:) keyEquivalent:@""];
cancelItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlCancelCMLabel", @"Cancel") cancelItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlCancelCMLabel", nil)
action:@selector(cancel:) keyEquivalent:@""]; action:@selector(cancel:) keyEquivalent:@""];
removeItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlRemoveCMLabel", @"Remove") if ([self isPaused]) {
pauseResumeItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlResumeCMLabel", nil)
action:@selector(resume:) keyEquivalent:@""];
}
else {
pauseResumeItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlPauseCMLabel", nil)
action:@selector(pause:) keyEquivalent:@""];
}
removeItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlRemoveCMLabel", nil)
action:@selector(remove:) keyEquivalent:@""]; action:@selector(remove:) keyEquivalent:@""];
openItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlOpenCMLabel", @"Open") openItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlOpenCMLabel", nil)
action:@selector(open:) keyEquivalent:@""]; action:@selector(open:) keyEquivalent:@""];
copySourceURLItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlCopySourceURLCMLabel", @"Copy Source URL") copySourceURLItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlCopySourceURLCMLabel", nil)
action:@selector(copySourceURL:) keyEquivalent:@""]; action:@selector(copySourceURL:) keyEquivalent:@""];
[revealItem setTarget:mProgressWindowController]; [revealItem setTarget:mProgressWindowController];
[cancelItem setTarget:mProgressWindowController]; [cancelItem setTarget:mProgressWindowController];
[pauseResumeItem setTarget:mProgressWindowController];
[removeItem setTarget:mProgressWindowController]; [removeItem setTarget:mProgressWindowController];
[openItem setTarget:mProgressWindowController]; [openItem setTarget:mProgressWindowController];
[copySourceURLItem setTarget:self]; [copySourceURLItem setTarget:self];
[menu addItem:revealItem]; [menu addItem:revealItem];
[menu addItem:cancelItem]; [menu addItem:cancelItem];
[menu addItem:pauseResumeItem];
[menu addItem:removeItem]; [menu addItem:removeItem];
[menu addItem:openItem]; [menu addItem:openItem];
[menu addItem:[NSMenuItem separatorItem]]; [menu addItem:[NSMenuItem separatorItem]];
@ -413,6 +465,7 @@ enum {
[revealItem release]; [revealItem release];
[cancelItem release]; [cancelItem release];
[pauseResumeItem release];
[removeItem release]; [removeItem release];
[openItem release]; [openItem release];
[copySourceURLItem release]; [copySourceURLItem release];

Просмотреть файл

@ -48,6 +48,7 @@
#include "nsIDownload.h" #include "nsIDownload.h"
#include "nsIWebBrowserPersist.h" #include "nsIWebBrowserPersist.h"
#include "nsIURI.h" #include "nsIURI.h"
#include "nsIRequest.h"
#include "nsILocalFile.h" #include "nsILocalFile.h"
#include "nsIExternalHelperAppService.h" #include "nsIExternalHelperAppService.h"
@ -77,11 +78,12 @@ public:
virtual void CancelDownload(); virtual void CancelDownload();
virtual void DownloadDone(nsresult aStatus); virtual void DownloadDone(nsresult aStatus);
virtual void DetachDownloadDisplay(); virtual void DetachDownloadDisplay();
virtual PRBool IsDownloadPaused();
private: private:
nsCOMPtr<nsICancelable> mCancelable; // Object to cancel the download nsCOMPtr<nsICancelable> mCancelable; // Object to cancel the download
nsCOMPtr<nsIRequest> mRequest; // Request to hook on status change, allows pause/resume
nsCOMPtr<nsIURI> mURI; // The URI of our source file. Null if we're saving a complete document. nsCOMPtr<nsIURI> mURI; // The URI of our source file. Null if we're saving a complete document.
nsCOMPtr<nsIURI> mDestination; // Our destination URL. nsCOMPtr<nsIURI> mDestination; // Our destination URL.
nsCOMPtr<nsILocalFile> mDestinationFile; // Our destination file. nsCOMPtr<nsILocalFile> mDestinationFile; // Our destination file.
@ -92,5 +94,6 @@ private:
PRPackedBool mGotFirstStateChange; // true after we've seen the first OnStateChange PRPackedBool mGotFirstStateChange; // true after we've seen the first OnStateChange
PRPackedBool mUserCanceled; // true if the user canceled the download PRPackedBool mUserCanceled; // true if the user canceled the download
PRPackedBool mSentCancel; // true when we've notified the backend of the cancel PRPackedBool mSentCancel; // true when we've notified the backend of the cancel
PRPackedBool mDownloadPaused; // true when download is paused
}; };

Просмотреть файл

@ -42,7 +42,6 @@
#include "nsDownloadListener.h" #include "nsDownloadListener.h"
#include "nsIWebProgress.h" #include "nsIWebProgress.h"
#include "nsIRequest.h"
#include "nsIFileURL.h" #include "nsIFileURL.h"
#include "netCore.h" #include "netCore.h"
#include "nsNetError.h" #include "nsNetError.h"
@ -54,6 +53,7 @@ nsDownloadListener::nsDownloadListener()
, mGotFirstStateChange(PR_FALSE) , mGotFirstStateChange(PR_FALSE)
, mUserCanceled(PR_FALSE) , mUserCanceled(PR_FALSE)
, mSentCancel(PR_FALSE) , mSentCancel(PR_FALSE)
, mDownloadPaused(PR_FALSE)
{ {
mStartTime = LL_ZERO; mStartTime = LL_ZERO;
} }
@ -198,6 +198,9 @@ nsDownloadListener::OnProgressChange64(nsIWebProgress *aWebProgress,
PRInt64 aCurTotalProgress, PRInt64 aCurTotalProgress,
PRInt64 aMaxTotalProgress) PRInt64 aMaxTotalProgress)
{ {
if (!mRequest)
mRequest = aRequest; // for pause/resume downloading
[mDownloadDisplay setProgressTo:aCurTotalProgress ofMax:aMaxTotalProgress]; [mDownloadDisplay setProgressTo:aCurTotalProgress ofMax:aMaxTotalProgress];
return NS_OK; return NS_OK;
} }
@ -309,13 +312,21 @@ nsDownloadListener::InitDialog()
void void
nsDownloadListener::PauseDownload() nsDownloadListener::PauseDownload()
{ {
// write me if (!mDownloadPaused && mRequest)
{
mRequest->Suspend();
mDownloadPaused = PR_TRUE;
}
} }
void void
nsDownloadListener::ResumeDownload() nsDownloadListener::ResumeDownload()
{ {
// write me if (mDownloadPaused && mRequest)
{
mRequest->Resume();
mDownloadPaused = PR_FALSE;
}
} }
void void
@ -371,4 +382,10 @@ nsDownloadListener::DetachDownloadDisplay()
mDownloadDisplay = nil; mDownloadDisplay = nil;
} }
PRBool
nsDownloadListener::IsDownloadPaused()
{
return mDownloadPaused;
}
#pragma mark - #pragma mark -

Просмотреть файл

@ -148,8 +148,8 @@ public:
virtual void CancelDownload() = 0; virtual void CancelDownload() = 0;
virtual void DownloadDone(nsresult aStatus) = 0; virtual void DownloadDone(nsresult aStatus) = 0;
virtual void DetachDownloadDisplay() = 0; // tell downloader to forget about its display virtual void DetachDownloadDisplay() = 0; // tell downloader to forget about its display
virtual void CreateDownloadDisplay(); virtual void CreateDownloadDisplay();
virtual PRBool IsDownloadPaused() = 0;
protected: protected: