File:  [mozdev] / chimera / ProgressDlgController.mm
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Sun Feb 3 19:40:10 2002 UTC (17 years, 9 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Fix warning.

    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: 
   11: #include "nsIWebBrowserPersist.h"
   12: #include "nsIInputStream.h"
   13: #include "nsIURL.h"
   14: #include "nsIDOMDocument.h"
   15: 
   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: 
   27: @implementation ProgressDlgController
   28: 
   29: - (id)init
   30: {
   31:     if ((self = [super init])) {
   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
   92: {
   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:     }
  144: 
  145:     return toolbarItem;
  146: }
  147: 
  148: -(void)cancel
  149: {
  150:     NSLog(@"Request to cancel download.");
  151:     //Put logic here!
  152: }
  153: 
  154: -(void)pauseAndResumeDownload
  155: {
  156: /*
  157:     if ( ! mDownloadIsPaused ) {
  158:         //Do logic to pause download
  159:         mDownloadIsPaused = YES;
  160:         [pauseResumeToggleToolbarItem setLabel:@"Resume"];
  161:         [pauseResumeToggleToolbarItem setPaletteLabel:@"Resume Download"];
  162:         [pauseResumeToggleToolbarItem setToolTip:@"Resume the paused FTP download"];
  163:         [pauseResumeToggleToolbarItem setImage:[NSImage imageNamed:@"saveResume"]];
  164:     } else {
  165:         //Do logic to resume download
  166:         mDownloadIsPaused = NO;
  167:         [pauseResumeToggleToolbarItem setLabel:@"Pause"];
  168:         [pauseResumeToggleToolbarItem setPaletteLabel:@"Pause Download"];
  169:         [pauseResumeToggleToolbarItem setToolTip:@"Pause this FTP file download"];
  170:         [pauseResumeToggleToolbarItem setImage:[NSImage imageNamed:@"savePause"]];
  171:     }
  172:  */
  173: }
  174: 
  175: -(void)showFile
  176: {
  177:     NSLog(@"Request to show file.");
  178: }
  179: 
  180: -(void)openFile
  181: {
  182:     NSLog(@"Request to open file.");
  183: }
  184: 
  185: -(void)toggleLeaveOpen
  186: {
  187:     if ( ! mSaveFileDialogShouldStayOpen ) {
  188:         //Do logic to set the preference and make it take effect
  189:         mSaveFileDialogShouldStayOpen = YES;
  190:         [leaveOpenToggleToolbarItem setLabel:@"Leave Open"];
  191:         [leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
  192:         [leaveOpenToggleToolbarItem setToolTip:@"Window will stay open when download finishes."];
  193:         [leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];
  194:     } else {
  195:         //Do logic to set the preference and make it take effect
  196:         mSaveFileDialogShouldStayOpen = NO;
  197:         [leaveOpenToggleToolbarItem setLabel:@"Close When Done"];
  198:         [leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
  199:         [leaveOpenToggleToolbarItem setToolTip:@"Window will close automatically when download finishes."];
  200:         [leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];
  201:     }
  202: }
  203: 
  204: @end

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