Annotation of chimera/ProgressDlgController.mm, revision 1.5

1.1       hyatt       1: //
                      2: //  ProgressDlgController.m
                      3: //  Chimera
                      4: //
                      5: //  Created by David Hyatt on Sat Feb 02 2002.
                      6: //  Copyright (c) 2001 __MyCompanyName__. All rights reserved.
                      7: //
                      8: 
                      9: #import "ProgressDlgController.h"
                     10: 
1.2       hyatt      11: #include "nsIWebBrowserPersist.h"
                     12: #include "nsIInputStream.h"
                     13: #include "nsIURL.h"
                     14: #include "nsIDOMDocument.h"
1.1       hyatt      15: 
1.3       macserv    16: static NSString *SaveFileToolbarIdentifier                     = @"Save File Dialog Toolbar";
                     17: static NSString *CancelToolbarItemIdentifier           = @"Cancel Toolbar Item";
                     18: static NSString *PauseResumeToolbarItemIdentifier      = @"Pause and Resume Toggle Toolbar Item";
                     19: static NSString *ShowFileToolbarItemIdentifier         = @"Show File Toolbar Item";
                     20: static NSString *OpenFileToolbarItemIdentifier         = @"Open File Toolbar Item";
                     21: static NSString *LeaveOpenToolbarItemIdentifier                = @"Leave Open Toggle Toolbar Item";
                     22: 
                     23: @interface ProgressDlgController(Private)
                     24: -(void)setupToolbar;
                     25: @end
                     26: 
1.1       hyatt      27: @implementation ProgressDlgController
1.2       hyatt      28: 
1.3       macserv    29: - (id)init
                     30: {
1.4       hyatt      31:     if ((self = [super init])) {
1.3       macserv    32:         mDownloadIsPaused = NO;  //Get this value from preferences instead of hardcoding NO.
                     33:         mSaveFileDialogShouldStayOpen = NO;
                     34:     }
                     35:     return self;
                     36: }
                     37: 
                     38: -(void)setWebPersist:(nsIWebBrowserPersist*)aPersist 
                     39:               source:(nsISupports*)aSource
                     40:          destination:(NSString*)aDestination
                     41:          contentType:(const char*)aContentType
                     42:             postData:(nsIInputStream*)aInputStream
                     43:          bypassCache:(BOOL)aBypassCache
                     44: {
                     45: 
                     46: }
                     47: 
                     48: - (void)windowDidLoad
                     49: {
                     50:     [self setupToolbar];
                     51: }
                     52: 
                     53: - (void)setupToolbar
                     54: {
                     55:     NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:SaveFileToolbarIdentifier] autorelease];
                     56: 
                     57:     [toolbar setDisplayMode:NSToolbarDisplayModeDefault];
                     58:     [toolbar setAllowsUserCustomization:YES];
                     59:     [toolbar setAutosavesConfiguration:YES];
                     60:     [toolbar setDelegate:self];
                     61:     [[self window] setToolbar:toolbar];
                     62: }
                     63: 
                     64: - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
                     65: {
                     66:     return [NSArray arrayWithObjects: CancelToolbarItemIdentifier,
                     67:         PauseResumeToolbarItemIdentifier,
                     68:         ShowFileToolbarItemIdentifier,
                     69:         OpenFileToolbarItemIdentifier,
                     70:         LeaveOpenToolbarItemIdentifier,
                     71:         NSToolbarCustomizeToolbarItemIdentifier,
                     72:         NSToolbarFlexibleSpaceItemIdentifier,
                     73:         NSToolbarSpaceItemIdentifier,
                     74:         NSToolbarSeparatorItemIdentifier,
                     75:         nil];
                     76: }
                     77: 
                     78: - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
                     79: {
                     80:     return [NSArray arrayWithObjects: CancelToolbarItemIdentifier,
                     81:         PauseResumeToolbarItemIdentifier,
                     82:         NSToolbarFlexibleSpaceItemIdentifier,
                     83:         LeaveOpenToolbarItemIdentifier,
                     84:         ShowFileToolbarItemIdentifier,
                     85:         OpenFileToolbarItemIdentifier,
                     86:         nil];
                     87: }
                     88: 
                     89: - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
                     90:       itemForItemIdentifier:(NSString *)itemIdent
                     91:   willBeInsertedIntoToolbar:(BOOL)willBeInserted
1.2       hyatt      92: {
1.3       macserv    93:     NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
                     94: 
                     95:     if ( [itemIdent isEqual:CancelToolbarItemIdentifier] ) {
                     96:         [toolbarItem setLabel:@"Cancel"];
                     97:         [toolbarItem setPaletteLabel:@"Cancel Download"];
                     98:         [toolbarItem setToolTip:@"Cancel this file download"];
                     99:         [toolbarItem setImage:[NSImage imageNamed:@"saveCancel"]];
                    100:         [toolbarItem setTarget:self];
                    101:         [toolbarItem setAction:@selector(cancel)];
                    102:     } else if ( [itemIdent isEqual:PauseResumeToolbarItemIdentifier] ) {
                    103:         [toolbarItem setLabel:@"Pause"];
                    104:         [toolbarItem setPaletteLabel:@"Pause Download"];
                    105:         [toolbarItem setToolTip:@"Pause this FTP file download"];
                    106:         [toolbarItem setImage:[NSImage imageNamed:@"savePause"]];
                    107:         [toolbarItem setTarget:self];
                    108:         [toolbarItem setAction:@selector(pauseAndResumeDownload)];
                    109:         pauseResumeToggleToolbarItem = toolbarItem; //establish reference
                    110:     } else if ( [itemIdent isEqual:ShowFileToolbarItemIdentifier] ) {
                    111:         [toolbarItem setLabel:@"Show File"];
                    112:         [toolbarItem setPaletteLabel:@"Show File"];
                    113:         [toolbarItem setToolTip:@"Show the saved file in the Finder"];
                    114:         [toolbarItem setImage:[NSImage imageNamed:@"saveShowFile"]];
                    115:         [toolbarItem setTarget:self];
                    116:         [toolbarItem setAction:@selector(showFile)];
                    117:     } else if ( [itemIdent isEqual:OpenFileToolbarItemIdentifier] ) {
                    118:         [toolbarItem setLabel:@"Open File"];
                    119:         [toolbarItem setPaletteLabel:@"Open File"];
                    120:         [toolbarItem setToolTip:@"Open the saved file in its default application."];
                    121:         [toolbarItem setImage:[NSImage imageNamed:@"saveOpenFile"]];
                    122:         [toolbarItem setTarget:self];
                    123:         [toolbarItem setAction:@selector(openFile)];
                    124:     } else if ( [itemIdent isEqual:LeaveOpenToolbarItemIdentifier] ) {
                    125:         if ( mSaveFileDialogShouldStayOpen ) {
                    126:             [toolbarItem setLabel:@"Leave Open"];
                    127:             [toolbarItem setPaletteLabel:@"Toggle Close Behavior"];
                    128:             [toolbarItem setToolTip:@"Window will stay open when download finishes."];
                    129:             [toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];
                    130:             [toolbarItem setTarget:self];
                    131:             [toolbarItem setAction:@selector(toggleLeaveOpen)];
                    132:         } else {
                    133:             [toolbarItem setLabel:@"Close When Done"];
                    134:             [toolbarItem setPaletteLabel:@"Toggle Close Behavior"];
                    135:             [toolbarItem setToolTip:@"Window will close automatically when download finishes."];
                    136:             [toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];
                    137:             [toolbarItem setTarget:self];
                    138:             [toolbarItem setAction:@selector(toggleLeaveOpen)];
                    139:         }
                    140:         leaveOpenToggleToolbarItem = toolbarItem; //establish reference
                    141:     } else {
                    142:         toolbarItem = nil;
                    143:     }
1.2       hyatt     144: 
1.3       macserv   145:     return toolbarItem;
                    146: }
1.2       hyatt     147: 
1.3       macserv   148: -(void)cancel
                    149: {
                    150:     NSLog(@"Request to cancel download.");
                    151:     //Put logic here!
                    152: }
                    153: 
                    154: -(void)pauseAndResumeDownload
                    155: {
                    156:     if ( ! mDownloadIsPaused ) {
                    157:         //Do logic to pause download
                    158:         mDownloadIsPaused = YES;
                    159:         [pauseResumeToggleToolbarItem setLabel:@"Resume"];
                    160:         [pauseResumeToggleToolbarItem setPaletteLabel:@"Resume Download"];
                    161:         [pauseResumeToggleToolbarItem setToolTip:@"Resume the paused FTP download"];
                    162:         [pauseResumeToggleToolbarItem setImage:[NSImage imageNamed:@"saveResume"]];
                    163:     } else {
                    164:         //Do logic to resume download
                    165:         mDownloadIsPaused = NO;
                    166:         [pauseResumeToggleToolbarItem setLabel:@"Pause"];
                    167:         [pauseResumeToggleToolbarItem setPaletteLabel:@"Pause Download"];
                    168:         [pauseResumeToggleToolbarItem setToolTip:@"Pause this FTP file download"];
                    169:         [pauseResumeToggleToolbarItem setImage:[NSImage imageNamed:@"savePause"]];
                    170:     }
                    171: }
                    172: 
                    173: -(void)showFile
                    174: {
                    175:     NSLog(@"Request to show file.");
                    176: }
                    177: 
                    178: -(void)openFile
                    179: {
                    180:     NSLog(@"Request to open file.");
                    181: }
                    182: 
                    183: -(void)toggleLeaveOpen
                    184: {
                    185:     if ( ! mSaveFileDialogShouldStayOpen ) {
                    186:         //Do logic to set the preference and make it take effect
                    187:         mSaveFileDialogShouldStayOpen = YES;
                    188:         [leaveOpenToggleToolbarItem setLabel:@"Leave Open"];
                    189:         [leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
                    190:         [leaveOpenToggleToolbarItem setToolTip:@"Window will stay open when download finishes."];
                    191:         [leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];
                    192:     } else {
                    193:         //Do logic to set the preference and make it take effect
                    194:         mSaveFileDialogShouldStayOpen = NO;
                    195:         [leaveOpenToggleToolbarItem setLabel:@"Close When Done"];
                    196:         [leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
                    197:         [leaveOpenToggleToolbarItem setToolTip:@"Window will close automatically when download finishes."];
                    198:         [leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];
                    199:     }
1.2       hyatt     200: }
1.1       hyatt     201: 
                    202: @end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>