Add options to remove finished download list items automatically, bug 308942. r=smorgan, sr=pinkerton

This commit is contained in:
nick.kreeger%park.edu 2006-06-09 01:48:22 +00:00
Родитель ea26fcff6f
Коммит 51411ce8a6
8 изменённых файлов: 95 добавлений и 20 удалений

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

@ -43,11 +43,13 @@
@interface OrgMozillaChimeraPreferenceDownloads : PreferencePaneBase
{
IBOutlet NSPopUpButton* mDownloadFolder;
IBOutlet NSPopUpButton* mDownloadRemovalPolicy;
IBOutlet NSButton* mAutoCloseDLManager;
IBOutlet NSButton* mEnableHelperApps;
}
- (IBAction)checkboxClicked:(id)sender;
- (IBAction)chooseDownloadFolder:(id)sender;
- (IBAction)chooseDownloadRemovalPolicy:(id)sender;
@end

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

@ -116,6 +116,7 @@ private:
[mAutoCloseDLManager setState:![self getBooleanPref:"browser.download.progressDnldDialog.keepAlive" withSuccess:&gotPref]];
[mEnableHelperApps setState:[self getBooleanPref:"browser.download.autoDispatch" withSuccess:&gotPref]];
[mDownloadRemovalPolicy selectItem:[[mDownloadRemovalPolicy menu] itemWithTag:[self getIntPref:"browser.download.downloadRemoveAction" withSuccess:&gotPref]]];
NSString* downloadFolderDesc = [self getDownloadFolderDescription];
if ([downloadFolderDesc length] == 0)
@ -244,6 +245,17 @@ private:
contextInfo:nil];
}
//
// Set the download removal policy
//
- (IBAction)chooseDownloadRemovalPolicy:(id)sender
{
// The three options in the popup contains tags 0-2, set the pref according to the
// selected menu item's tag.
int selectedTagValue = [mDownloadRemovalPolicy selectedTag];
[self setPref:"browser.download.downloadRemoveAction" toInt:selectedTagValue];
}
// called when the user closes the open panel sheet for selecting a new d/l folder.
// if they clicked ok, change the IC pref and re-display the new choice in the
// popup menu
@ -260,4 +272,5 @@ private:
else
[mDownloadFolder selectItemAtIndex:0];
}
@end

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

@ -72,6 +72,9 @@ pref("browser.download.autoDownload", true);
pref("browser.download.autoDispatch", false);
pref("browser.download.progressDnldDialog.keepAlive", true);
// Download removing policy
pref("browser.download.downloadRemoveAction", 0);
pref("chimera.enable_rendezvous", true);
// set typeahead find to search all text by default, but not invoke

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

@ -347,6 +347,11 @@ const int kReuseWindowOnAE = 2;
// shut down bookmarks (if we made them)
[[BookmarkManager sharedBookmarkManagerDontCreate] shutdown];
// Save or remove the download list according to the users download removal pref
ProgressDlgController* progressWindowController = [ProgressDlgController existingSharedDownloadController];
if (progressWindowController)
[progressWindowController applicationWillTerminate];
// Autosave one of the windows.
NSWindow* curMainWindow = [mApplication mainWindow];
if (curMainWindow && [[curMainWindow windowController] respondsToSelector:@selector(autosaveWindowFrame)])

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

@ -108,6 +108,7 @@
-(void)didEndDownload:(id <CHDownloadProgressDisplay>)progressDisplay withSuccess:(BOOL)completedOK statusCode:(nsresult)status;
-(void)removeDownload:(id <CHDownloadProgressDisplay>)progressDisplay;
-(NSApplicationTerminateReply)allowTerminate;
-(void)applicationWillTerminate;
-(void)saveProgressViewControllers;
-(void)loadProgressViewControllers;

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

@ -68,6 +68,9 @@ static NSString* const kProgressWindowFrameSaveName = @"ProgressWindow";
-(BOOL)shouldAllowOpenAction;
-(BOOL)fileExistsForSelectedItems;
-(void)maybeCloseWindow;
-(void)removeSavedDownloadPlist;
-(BOOL)shouldRemoveDownloadsOnQuit;
-(NSString*)downloadsPlistPath;
@end
@ -648,6 +651,8 @@ static id gSharedProgressController = nil;
// Stop doing stuff if there aren't any downloads going on
[self killDownloadTimer];
}
[self rebuildViews];
}
-(void)rebuildViews
@ -709,7 +714,11 @@ static id gSharedProgressController = nil;
-(NSApplicationTerminateReply)allowTerminate
{
if ([self numDownloadsInProgress] > 0) {
BOOL shouldTerminate = YES;
BOOL downloadsInProgress = ([self numDownloadsInProgress] > 0 ? YES : NO);
if (downloadsInProgress)
{
// make sure the window is visible
[self showWindow:self];
@ -747,19 +756,24 @@ static id gSharedProgressController = nil;
mShouldCloseWindow = NO;
}
return NSTerminateCancel;
shouldTerminate = NO;
}
}
else {
// need to save here because downloads that were downloading aren't
// cancelled just terminated.
return shouldTerminate ? NSTerminateNow : NSTerminateCancel;
}
// Called by MainController when the application is about to terminate.
// Either save the progress view's or remove them according to the download removal pref.
-(void)applicationWillTerminate
{
// Check the download item removal policy here to see if downloads should be removed when camino quits.
if ([self shouldRemoveDownloadsOnQuit])
[self removeSavedDownloadPlist];
// Since the pref is not set to remove the downloads when Camino quits, save them here before the app terminates.
else
[self saveProgressViewControllers];
return NSTerminateNow;
}
}
return NSTerminateNow;
}
-(void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
@ -779,15 +793,13 @@ static id gSharedProgressController = nil;
[downloadArray addObject:[curController downloadInfoDictionary]];
}
// now save
NSString *profileDir = [[PreferenceManager sharedInstance] profilePath];
[downloadArray writeToFile: [profileDir stringByAppendingPathComponent:@"downloads.plist"] atomically: YES];
// now save the array
[downloadArray writeToFile:[self downloadsPlistPath] atomically: YES];
}
-(void)loadProgressViewControllers
{
NSString* downloadsPath = [[[PreferenceManager sharedInstance] profilePath] stringByAppendingPathComponent:@"downloads.plist"];
NSArray* downloads = [NSArray arrayWithContentsOfFile:downloadsPath];
NSArray* downloads = [NSArray arrayWithContentsOfFile:[self downloadsPlistPath]];
if (downloads)
{
@ -804,6 +816,27 @@ static id gSharedProgressController = nil;
}
}
// Remove the saved downloads plist
-(void)removeSavedDownloadPlist
{
[[NSFileManager defaultManager] removeFileAtPath:[self downloadsPlistPath] handler:NULL];
}
// Return true if the pref is set to remove downloads when the application quits
-(BOOL)shouldRemoveDownloadsOnQuit
{
int downloadRemovalPolicy = [[PreferenceManager sharedInstance] getIntPref:"browser.download.downloadRemoveAction"
withSuccess:NULL];
return downloadRemovalPolicy == kRemoveDownloadsOnQuitPrefValue ? YES : NO;
}
// Get the downloads.plist path
-(NSString*)downloadsPlistPath
{
return [[[PreferenceManager sharedInstance] profilePath] stringByAppendingPathComponent:@"downloads.plist"];
}
-(BOOL)shouldAllowCancelAction
{
// if no selections are inactive or canceled then allow cancel

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

@ -56,6 +56,12 @@ enum {
kCommandKey = 2
};
// Define these auto remove download pref values here
// becase both ProgressViewController and ProgressDlgController
// need to use them. Note that the manual removal pref value is 0.
const int kRemoveDownloadsOnQuitPrefValue = 1;
const int kRemoveUponSuccessfulDownloadPrefValue = 2;
//
// interface ProgressViewController
//

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

@ -74,6 +74,7 @@ static void FileSystemNotificationProc(FNMessage message, OptionBits flags, void
-(void)refreshDownloadInfo;
-(void)launchFileIfAppropriate;
-(void)setProgressViewFromDictionary:(NSDictionary*)aDict;
-(void)removeFromDownloadListIfAppropriate;
@end
@ -380,6 +381,7 @@ static void FileSystemNotificationProc(FNMessage message, OptionBits flags, void
[self refreshDownloadInfo];
[self launchFileIfAppropriate];
[self removeFromDownloadListIfAppropriate];
}
}
@ -392,6 +394,16 @@ static void FileSystemNotificationProc(FNMessage message, OptionBits flags, void
}
}
// Remove the download from the view if the pref is set to remove upon successful download
-(void)removeFromDownloadListIfAppropriate
{
int downloadRemoveActionValue = [[PreferenceManager sharedInstance] getIntPref:"browser.download.downloadRemoveAction"
withSuccess:NULL];
if (!mUserCancelled && !mDownloadingError && downloadRemoveActionValue == kRemoveUponSuccessfulDownloadPrefValue)
[mProgressWindowController removeDownload:self];
}
// this handles lots of things - all of the status updates
-(void)refreshDownloadInfo
{