зеркало из https://github.com/mozilla/pjs.git
add pause/resume to download manager (bug 187483)
This commit is contained in:
Родитель
fc97cdf23e
Коммит
f8e5d82100
|
@ -3236,6 +3236,8 @@
|
|||
0F5187C408858E620091F3FB,
|
||||
0FB6D99B089B276100414498,
|
||||
3FEBB43C089DA88C00BD8373,
|
||||
3FEBB4E908A02F2900BD8373,
|
||||
3FEBB4EA08A02F2900BD8373,
|
||||
);
|
||||
isa = PBXResourcesBuildPhase;
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
@ -7088,6 +7090,8 @@
|
|||
3FFE23540847CB0D00D6CAFC,
|
||||
0FB6D99C089B276100414498,
|
||||
3FEBB43D089DA88C00BD8373,
|
||||
3FEBB4EB08A02F2900BD8373,
|
||||
3FEBB4EC08A02F2900BD8373,
|
||||
);
|
||||
isa = PBXResourcesBuildPhase;
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
@ -10509,6 +10513,46 @@
|
|||
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 = {
|
||||
children = (
|
||||
3F44AD8705BDFB9F00CB4B08,
|
||||
|
@ -13536,6 +13580,8 @@
|
|||
3FC0FB8605A0D2F4002F47DE,
|
||||
3FC0FB8705A0D2F4002F47DE,
|
||||
0382B4D907303CCA00A0228A,
|
||||
3FEBB4E708A02F2900BD8373,
|
||||
3FEBB4E808A02F2900BD8373,
|
||||
F5555C8202022F070164C72B,
|
||||
F5555C8302022F070164C72B,
|
||||
F5555C8402022F070164C72B,
|
||||
|
|
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичные данные
camino/resources/localized/English.lproj/Localizable.strings
Двоичные данные
camino/resources/localized/English.lproj/Localizable.strings
Двоичный файл не отображается.
|
@ -7,16 +7,15 @@
|
|||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<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>
|
||||
<string>445 508 346 92 0 0 1280 832 </string>
|
||||
<string>339 462 346 92 0 0 1024 746 </string>
|
||||
</dict>
|
||||
<key>IBFramework Version</key>
|
||||
<string>364.0</string>
|
||||
<string>439.0</string>
|
||||
<key>IBLockedObjects</key>
|
||||
<array>
|
||||
<integer>5</integer>
|
||||
<integer>71</integer>
|
||||
</array>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
|
@ -24,6 +23,6 @@
|
|||
<integer>5</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>7M34</string>
|
||||
<string>8C46</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
Двоичные данные
camino/resources/localized/English.lproj/ProgressView.nib/keyedobjects.nib
сгенерированный
Двоичные данные
camino/resources/localized/English.lproj/ProgressView.nib/keyedobjects.nib
сгенерированный
Двоичный файл не отображается.
|
@ -96,6 +96,8 @@
|
|||
-(IBAction)reveal:(id)sender;
|
||||
-(IBAction)cleanUpDownloads:(id)sender;
|
||||
-(IBAction)open:(id)sender;
|
||||
-(IBAction)pause:(id)sender;
|
||||
-(IBAction)resume:(id)sender;
|
||||
|
||||
-(int)numDownloadsInProgress;
|
||||
-(void)clearAllDownloads;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
* Contributor(s):
|
||||
* Calum Robinson <calumr@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
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -95,7 +96,7 @@ static id gSharedProgressController = nil;
|
|||
|
||||
-(void)awakeFromNib
|
||||
{
|
||||
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"dlmanager"];
|
||||
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"dlmanager1"]; // so pause/resume button will show
|
||||
[toolbar setDelegate:self];
|
||||
[toolbar setAllowsUserCustomization:YES];
|
||||
[toolbar setAutosavesConfiguration:YES];
|
||||
|
@ -117,9 +118,9 @@ static id gSharedProgressController = nil;
|
|||
-(IBAction)cancel:(id)sender
|
||||
{
|
||||
NSMutableArray* selected = [self getSelectedProgressViewControllers];
|
||||
unsigned count = [selected count];
|
||||
for (unsigned i = 0; i < count; i++) {
|
||||
[[selected objectAtIndex:i] cancel:self];
|
||||
unsigned int count = [selected count];
|
||||
for (unsigned int i = 0; i < count; i++) {
|
||||
[[selected objectAtIndex:i] cancel:sender];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,9 +128,9 @@ static id gSharedProgressController = nil;
|
|||
-(IBAction)reveal:(id)sender
|
||||
{
|
||||
NSMutableArray* selected = [self getSelectedProgressViewControllers];
|
||||
unsigned count = [selected count];
|
||||
for (unsigned i = 0; i < count; i++) {
|
||||
[[selected objectAtIndex:i] reveal:self];
|
||||
unsigned int count = [selected count];
|
||||
for (unsigned int i = 0; i < count; i++) {
|
||||
[[selected objectAtIndex:i] reveal:sender];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,9 +138,9 @@ static id gSharedProgressController = nil;
|
|||
-(IBAction)open:(id)sender
|
||||
{
|
||||
NSMutableArray* selected = [self getSelectedProgressViewControllers];
|
||||
unsigned count = [selected count];
|
||||
for (unsigned i = 0; i < count; i++) {
|
||||
[[selected objectAtIndex:i] open:self];
|
||||
unsigned int count = [selected count];
|
||||
for (unsigned int i = 0; i < count; i++) {
|
||||
[[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
|
||||
NSMutableArray* selected = [self getSelectedProgressViewControllers];
|
||||
unsigned selectedCount = [selected count];
|
||||
unsigned indexOfLastSelection = [mProgressViewControllers indexOfObject:[selected objectAtIndex:(((int)selectedCount) - 1)]];
|
||||
unsigned int selectedCount = [selected count];
|
||||
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 ((indexOfLastSelection + 1) < [mProgressViewControllers count]) {
|
||||
[[((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
|
||||
|
||||
// now remove stuff
|
||||
for (unsigned i = 0; i < selectedCount; i++) {
|
||||
for (unsigned int i = 0; i < selectedCount; i++) {
|
||||
if (![[selected objectAtIndex:i] isActive]) {
|
||||
[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
|
||||
-(IBAction)cleanUpDownloads:(id)sender
|
||||
{
|
||||
|
@ -562,40 +587,66 @@ static id gSharedProgressController = nil;
|
|||
-(BOOL)shouldAllowCancelAction
|
||||
{
|
||||
NSMutableArray* selectedArray = [self getSelectedProgressViewControllers];
|
||||
unsigned selectedCount = [selectedArray count];
|
||||
unsigned int selectedCount = [selectedArray count];
|
||||
// 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]) {
|
||||
return FALSE;
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(BOOL)shouldAllowRemoveAction
|
||||
{
|
||||
NSMutableArray* selectedArray = [self getSelectedProgressViewControllers];
|
||||
unsigned selectedCount = [selectedArray count];
|
||||
unsigned int selectedCount = [selectedArray count];
|
||||
// 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]) {
|
||||
return FALSE;
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(BOOL)shouldAllowOpenAction
|
||||
{
|
||||
NSMutableArray* selectedArray = [self getSelectedProgressViewControllers];
|
||||
unsigned selectedCount = [selectedArray count];
|
||||
unsigned int selectedCount = [selectedArray count];
|
||||
// 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]) {
|
||||
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
|
||||
|
@ -610,9 +661,39 @@ static id gSharedProgressController = nil;
|
|||
else if (action == @selector(open:)) {
|
||||
return [self shouldAllowOpenAction];
|
||||
}
|
||||
else if (action == @selector(pause:)) {
|
||||
return [self shouldAllowPauseAction];
|
||||
}
|
||||
else if (action == @selector(resume:)) {
|
||||
return [self shouldAllowResumeAction];
|
||||
}
|
||||
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
|
||||
{
|
||||
SEL action = [theItem action];
|
||||
|
@ -647,7 +728,11 @@ static id gSharedProgressController = nil;
|
|||
else if (action == @selector(cancel:)) {
|
||||
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
|
||||
|
@ -656,35 +741,43 @@ static id gSharedProgressController = nil;
|
|||
[theItem setTarget:self];
|
||||
[theItem setEnabled:NO];
|
||||
if ([itemIdentifier isEqualToString:@"removebutton"]) {
|
||||
[theItem setToolTip:NSLocalizedString(@"dlRemoveButtonTooltip", @"Remove selected download(s)")];
|
||||
[theItem setLabel:NSLocalizedString(@"dlRemoveButtonLabel", @"Remove")];
|
||||
[theItem setToolTip:NSLocalizedString(@"dlRemoveButtonTooltip", nil)];
|
||||
[theItem setLabel:NSLocalizedString(@"dlRemoveButtonLabel", nil)];
|
||||
[theItem setPaletteLabel:NSLocalizedString(@"dlRemoveButtonLabel", nil)];
|
||||
[theItem setAction:@selector(remove:)];
|
||||
[theItem setImage:[NSImage imageNamed:@"dl_remove.tif"]];
|
||||
}
|
||||
else if ([itemIdentifier isEqualToString:@"cancelbutton"]) {
|
||||
[theItem setToolTip:NSLocalizedString(@"dlCancelButtonTooltip", @"Cancel selected download(s)")];
|
||||
[theItem setLabel:NSLocalizedString(@"dlCancelButtonLabel", @"Cancel")];
|
||||
[theItem setToolTip:NSLocalizedString(@"dlCancelButtonTooltip", nil)];
|
||||
[theItem setLabel:NSLocalizedString(@"dlCancelButtonLabel", nil)];
|
||||
[theItem setPaletteLabel:NSLocalizedString(@"dlCancelButtonLabel", nil)];
|
||||
[theItem setAction:@selector(cancel:)];
|
||||
[theItem setImage:[NSImage imageNamed:@"dl_cancel.tif"]];
|
||||
}
|
||||
else if ([itemIdentifier isEqualToString:@"revealbutton"]) {
|
||||
[theItem setToolTip:NSLocalizedString(@"dlRevealButtonTooltip", @"Show selected download(s) in Finder")];
|
||||
[theItem setLabel:NSLocalizedString(@"dlRevealButtonLabel", @"Show")];
|
||||
[theItem setToolTip:NSLocalizedString(@"dlRevealButtonTooltip", nil)];
|
||||
[theItem setLabel:NSLocalizedString(@"dlRevealButtonLabel", nil)];
|
||||
[theItem setPaletteLabel:NSLocalizedString(@"dlRevealButtonLabel", nil)];
|
||||
[theItem setAction:@selector(reveal:)];
|
||||
[theItem setImage:[NSImage imageNamed:@"dl_reveal.tif"]];
|
||||
}
|
||||
else if ([itemIdentifier isEqualToString:@"openbutton"]) {
|
||||
[theItem setToolTip:NSLocalizedString(@"dlOpenButtonTooltip", @"Open saved file(s)")];
|
||||
[theItem setLabel:NSLocalizedString(@"dlOpenButtonLabel", @"Open")];
|
||||
[theItem setToolTip:NSLocalizedString(@"dlOpenButtonTooltip", nil)];
|
||||
[theItem setLabel:NSLocalizedString(@"dlOpenButtonLabel", nil)];
|
||||
[theItem setPaletteLabel:NSLocalizedString(@"dlOpenButtonLabel", nil)];
|
||||
[theItem setAction:@selector(open:)];
|
||||
[theItem setImage:[NSImage imageNamed:@"dl_open.tif"]];
|
||||
}
|
||||
else if ([itemIdentifier isEqualToString:@"cleanupbutton"]) {
|
||||
[theItem setToolTip:NSLocalizedString(@"dlCleanUpButtonTooltip", @"Remove all inactive download(s)")];
|
||||
[theItem setLabel:NSLocalizedString(@"dlCleanUpButtonLabel", @"Clean Up")];
|
||||
[theItem setToolTip:NSLocalizedString(@"dlCleanUpButtonTooltip", nil)];
|
||||
[theItem setLabel:NSLocalizedString(@"dlCleanUpButtonLabel", nil)];
|
||||
[theItem setPaletteLabel:NSLocalizedString(@"dlCleanUpButtonLabel", nil)];
|
||||
[theItem setAction:@selector(cleanUpDownloads:)];
|
||||
[theItem setImage:[NSImage imageNamed:@"dl_clearall.tif"]];
|
||||
}
|
||||
else if ([itemIdentifier isEqualToString:@"pauseresumebutton"]) {
|
||||
[self setPauseResumeToolbarItem:theItem];
|
||||
}
|
||||
else {
|
||||
return nil;
|
||||
}
|
||||
|
@ -693,12 +786,12 @@ static id gSharedProgressController = nil;
|
|||
|
||||
-(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
|
||||
{
|
||||
return [NSArray arrayWithObjects:@"cleanupbutton", @"removebutton", @"cancelbutton", @"openbutton", NSToolbarFlexibleSpaceItemIdentifier, @"revealbutton", nil];
|
||||
return [NSArray arrayWithObjects:@"cleanupbutton", @"removebutton", @"cancelbutton", @"pauseresumebutton", @"openbutton", NSToolbarFlexibleSpaceItemIdentifier, @"revealbutton", nil];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
|
|
@ -100,10 +100,13 @@ enum {
|
|||
-(IBAction)remove:(id)sender;
|
||||
-(IBAction)reveal:(id)sender;
|
||||
-(IBAction)open:(id)sender;
|
||||
-(IBAction)pause:(id)sender;
|
||||
-(IBAction)resume:(id)sender;
|
||||
|
||||
-(BOOL)isActive;
|
||||
-(BOOL)isCanceled;
|
||||
-(BOOL)isSelected;
|
||||
-(BOOL)isPaused;
|
||||
|
||||
-(NSMenu*)contextualMenu;
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
* Calum Robinson <calumr@mac.com>
|
||||
* Simon Fraser <sfraser@netscape.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
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -101,24 +102,24 @@ enum {
|
|||
// check for seconds first
|
||||
if (seconds < 60) {
|
||||
if (seconds < 7)
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"UnderSec", @"Under %d seconds"), 5];
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"UnderSec", nil), 5];
|
||||
if (seconds < 13)
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"UnderSec", @"Under %d seconds"), 10];
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"UnderMin", @"Under a minute")];
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"UnderSec", nil), 10];
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"UnderMin", nil)];
|
||||
}
|
||||
// seconds becomes minutes and we keep checking.
|
||||
seconds = seconds/60;
|
||||
if (seconds < 60) {
|
||||
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.
|
||||
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.
|
||||
seconds = seconds/60;
|
||||
if (seconds < 2)
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"AboutHour", @"Over an hour")];
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"AboutHours", @"Over %d hours"), seconds];
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"AboutHour", nil)];
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"AboutHours", nil), seconds];
|
||||
}
|
||||
|
||||
+(NSString*)formatBytes:(float)bytes
|
||||
|
@ -209,7 +210,10 @@ enum {
|
|||
|
||||
-(ProgressView*)view
|
||||
{
|
||||
return (mDownloadDone ? mCompletedView : mProgressView);
|
||||
if ([self isPaused] || mDownloadDone)
|
||||
return mCompletedView;
|
||||
else
|
||||
return mProgressView;
|
||||
}
|
||||
|
||||
-(IBAction)copySourceURL:(id)sender
|
||||
|
@ -252,6 +256,25 @@ enum {
|
|||
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
|
||||
{
|
||||
[mProgressWindowController removeDownload:self];
|
||||
|
@ -317,13 +340,13 @@ enum {
|
|||
if (statusLabel) {
|
||||
NSString* statusString;
|
||||
if (mUserCancelled) {
|
||||
statusString = NSLocalizedString(@"DownloadCancelled", @"Cancelled");
|
||||
statusString = NSLocalizedString(@"DownloadCancelled", nil);
|
||||
}
|
||||
else if (mDownloadingError) {
|
||||
statusString = NSLocalizedString(@"DownloadInterrupted", @"Interrupted");
|
||||
statusString = NSLocalizedString(@"DownloadInterrupted", nil);
|
||||
}
|
||||
else {
|
||||
statusString = [NSString stringWithFormat:NSLocalizedString(@"DownloadCompleted", @"Completed in %@ (%@)"),
|
||||
statusString = [NSString stringWithFormat:NSLocalizedString(@"DownloadCompleted", nil),
|
||||
[[self class] formatTime:(int)mDownloadTime], [[self class] formatBytes:mDownloadSize]];
|
||||
}
|
||||
|
||||
|
@ -331,13 +354,24 @@ enum {
|
|||
[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 {
|
||||
NSTimeInterval elapsedTime = -[mStartTime timeIntervalSinceNow];
|
||||
|
||||
// update status field
|
||||
id statusLabel = [curView viewWithTag:kLabelTagStatus];
|
||||
if (statusLabel) {
|
||||
NSString *statusLabelString = NSLocalizedString(@"DownloadStatusString", @"%@ of %@ (at %@/sec)");
|
||||
NSString *statusLabelString = NSLocalizedString(@"DownloadStatusString", nil);
|
||||
float byteSec = mCurrentProgress / elapsedTime;
|
||||
[statusLabel setStringValue:[NSString stringWithFormat:statusLabelString,
|
||||
[[self class] formatBytes:mCurrentProgress],
|
||||
|
@ -352,7 +386,7 @@ enum {
|
|||
[timeLabel setStringValue:[[self class] formatFuzzyTime:secToGo]];
|
||||
}
|
||||
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];
|
||||
}
|
||||
|
||||
-(BOOL)isPaused
|
||||
{
|
||||
if (mDownloader)
|
||||
return mDownloader->IsDownloadPaused();
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(NSMenu*)contextualMenu
|
||||
{
|
||||
NSMenu *menu = [[NSMenu alloc] init];
|
||||
NSMenuItem *revealItem;
|
||||
NSMenuItem *cancelItem;
|
||||
NSMenuItem *removeItem;
|
||||
NSMenuItem *pauseResumeItem; // alternates pause and resume
|
||||
NSMenuItem *openItem;
|
||||
NSMenuItem *copySourceURLItem;
|
||||
|
||||
revealItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlRevealCMLabel", @"Show in Finder")
|
||||
revealItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlRevealCMLabel", nil)
|
||||
action:@selector(reveal:) keyEquivalent:@""];
|
||||
cancelItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlCancelCMLabel", @"Cancel")
|
||||
cancelItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlCancelCMLabel", nil)
|
||||
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:@""];
|
||||
openItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlOpenCMLabel", @"Open")
|
||||
openItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlOpenCMLabel", nil)
|
||||
action:@selector(open:) keyEquivalent:@""];
|
||||
copySourceURLItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlCopySourceURLCMLabel", @"Copy Source URL")
|
||||
copySourceURLItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlCopySourceURLCMLabel", nil)
|
||||
action:@selector(copySourceURL:) keyEquivalent:@""];
|
||||
|
||||
[revealItem setTarget:mProgressWindowController];
|
||||
[cancelItem setTarget:mProgressWindowController];
|
||||
[pauseResumeItem setTarget:mProgressWindowController];
|
||||
[removeItem setTarget:mProgressWindowController];
|
||||
[openItem setTarget:mProgressWindowController];
|
||||
[copySourceURLItem setTarget:self];
|
||||
|
||||
[menu addItem:revealItem];
|
||||
[menu addItem:cancelItem];
|
||||
[menu addItem:pauseResumeItem];
|
||||
[menu addItem:removeItem];
|
||||
[menu addItem:openItem];
|
||||
[menu addItem:[NSMenuItem separatorItem]];
|
||||
|
@ -413,6 +465,7 @@ enum {
|
|||
|
||||
[revealItem release];
|
||||
[cancelItem release];
|
||||
[pauseResumeItem release];
|
||||
[removeItem release];
|
||||
[openItem release];
|
||||
[copySourceURLItem release];
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#include "nsIDownload.h"
|
||||
#include "nsIWebBrowserPersist.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
#include "nsIExternalHelperAppService.h"
|
||||
|
@ -77,11 +78,12 @@ public:
|
|||
virtual void CancelDownload();
|
||||
virtual void DownloadDone(nsresult aStatus);
|
||||
virtual void DetachDownloadDisplay();
|
||||
virtual PRBool IsDownloadPaused();
|
||||
|
||||
private:
|
||||
|
||||
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> mDestination; // Our destination URL.
|
||||
nsCOMPtr<nsILocalFile> mDestinationFile; // Our destination file.
|
||||
|
@ -92,5 +94,6 @@ private:
|
|||
PRPackedBool mGotFirstStateChange; // true after we've seen the first OnStateChange
|
||||
PRPackedBool mUserCanceled; // true if the user canceled the download
|
||||
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 "nsIWebProgress.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "netCore.h"
|
||||
#include "nsNetError.h"
|
||||
|
@ -54,6 +53,7 @@ nsDownloadListener::nsDownloadListener()
|
|||
, mGotFirstStateChange(PR_FALSE)
|
||||
, mUserCanceled(PR_FALSE)
|
||||
, mSentCancel(PR_FALSE)
|
||||
, mDownloadPaused(PR_FALSE)
|
||||
{
|
||||
mStartTime = LL_ZERO;
|
||||
}
|
||||
|
@ -198,6 +198,9 @@ nsDownloadListener::OnProgressChange64(nsIWebProgress *aWebProgress,
|
|||
PRInt64 aCurTotalProgress,
|
||||
PRInt64 aMaxTotalProgress)
|
||||
{
|
||||
if (!mRequest)
|
||||
mRequest = aRequest; // for pause/resume downloading
|
||||
|
||||
[mDownloadDisplay setProgressTo:aCurTotalProgress ofMax:aMaxTotalProgress];
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -309,13 +312,21 @@ nsDownloadListener::InitDialog()
|
|||
void
|
||||
nsDownloadListener::PauseDownload()
|
||||
{
|
||||
// write me
|
||||
if (!mDownloadPaused && mRequest)
|
||||
{
|
||||
mRequest->Suspend();
|
||||
mDownloadPaused = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsDownloadListener::ResumeDownload()
|
||||
{
|
||||
// write me
|
||||
if (mDownloadPaused && mRequest)
|
||||
{
|
||||
mRequest->Resume();
|
||||
mDownloadPaused = PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -371,4 +382,10 @@ nsDownloadListener::DetachDownloadDisplay()
|
|||
mDownloadDisplay = nil;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsDownloadListener::IsDownloadPaused()
|
||||
{
|
||||
return mDownloadPaused;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
|
|
@ -148,8 +148,8 @@ public:
|
|||
virtual void CancelDownload() = 0;
|
||||
virtual void DownloadDone(nsresult aStatus) = 0;
|
||||
virtual void DetachDownloadDisplay() = 0; // tell downloader to forget about its display
|
||||
|
||||
virtual void CreateDownloadDisplay();
|
||||
virtual PRBool IsDownloadPaused() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче