Diff for /chimera/ProgressDlgController.mm between versions 1.8 and 1.13

version 1.8, 2002/02/04 02:55:17 version 1.13, 2002/03/07 18:42:43
Line 1 Line 1
///* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
//  ProgressDlgController.m/* ***** BEGIN LICENSE BLOCK *****
//  Chimera * Version: NPL 1.1/GPL 2.0/LGPL 2.1
// *
//  Created by David Hyatt on Sat Feb 02 2002. * The contents of this file are subject to the Netscape Public License
//  Copyright (c) 2001 __MyCompanyName__. All rights reserved. * Version 1.1 (the "License"); you may not use this file except in
// * compliance with the License. You may obtain a copy of the License at
  * http://www.mozilla.org/NPL/
  *
  * Software distributed under the License is distributed on an "AS IS" basis,
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  * for the specific language governing rights and limitations under the
  * License.
  *
  * The Original Code is mozilla.org code.
  *
  * The Initial Developer of the Original Code is 
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 2002
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *
  * 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 
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the NPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the NPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
   
 #import "ProgressDlgController.h"  #import "ProgressDlgController.h"
   
Line 14 Line 43
 #include "nsIInputStream.h"  #include "nsIInputStream.h"
 #include "nsIURL.h"  #include "nsIURL.h"
 #include "nsILocalFile.h"  #include "nsILocalFile.h"
#include "nsIDOMDocument.h"#include "nsIDOMHTMLDocument.h"
 #include "nsIWebProgressListener.h"  #include "nsIWebProgressListener.h"
 #include "nsIComponentManager.h"  #include "nsIComponentManager.h"
   #include "nsIPrefBranch.h"
   
   const char* prefContractID = "@mozilla.org/preferences-service;1";
   
 class nsDownloadListener : public nsIWebProgressListener  class nsDownloadListener : public nsIWebProgressListener
 {  {
Line 50  public: Line 82  public:
       
 public:  public:
     void BeginDownload();      void BeginDownload();
    void InitDialog();
     
 private: // Member variables  private: // Member variables
     ProgressDlgController* mController; // Controller for our UI.      ProgressDlgController* mController; // Controller for our UI.
     nsCOMPtr<nsIWebBrowserPersist> mWebPersist; // Our web persist object.      nsCOMPtr<nsIWebBrowserPersist> mWebPersist; // Our web persist object.
     nsCOMPtr<nsIURL> mURL; // The URL of our source file. Null if we're saving a complete document.      nsCOMPtr<nsIURL> mURL; // The URL of our source file. Null if we're saving a complete document.
     nsCOMPtr<nsILocalFile> mDestination; // Our destination URL.      nsCOMPtr<nsILocalFile> mDestination; // Our destination URL.
     nsCString mContentType; // Our content type string.      nsCString mContentType; // Our content type string.
    nsCOMPtr<nsIDOMDocument> mDocument; // A DOM document.  Null if we're only saving a simple URL.    nsCOMPtr<nsIDOMHTMLDocument> mDocument; // A DOM document.  Null if we're only saving a simple URL.
     nsCOMPtr<nsIInputStream> mPostData;  // For complete documents, this is our post data from session history.      nsCOMPtr<nsIInputStream> mPostData;  // For complete documents, this is our post data from session history.
     PRBool mBypassCache; // Whether we should bypass the cache or not.      PRBool mBypassCache; // Whether we should bypass the cache or not.
 };  };
Line 130  nsDownloadListener::BeginDownload() Line 163  nsDownloadListener::BeginDownload()
         if (mURL)          if (mURL)
             mWebPersist->SaveURI(mURL, mPostData, mDestination);              mWebPersist->SaveURI(mURL, mPostData, mDestination);
         else {          else {
               PRInt32 encodingFlags = 0;
               nsCOMPtr<nsILocalFile> filesFolder;
                           
               if (!mContentType.Equals("text/plain")) {
                   // Create a local directory in the same dir as our file.  It
                   // will hold our associated files.
                   filesFolder = do_CreateInstance("@mozilla.org/file/local;1");
                   nsXPIDLString unicodePath;
                   mDestination->GetUnicodePath(getter_Copies(unicodePath));
                   filesFolder->InitWithUnicodePath(unicodePath.get());
                   
                   nsXPIDLCString leafName;
                   filesFolder->GetLeafName(getter_Copies(leafName));
                   nsCAutoString nameMinusExt(leafName.get());
                   PRInt32 index = nameMinusExt.RFind(".");
                   if (index >= 0)
                       nameMinusExt.Left(nameMinusExt, index);
                   nameMinusExt += " Files"; // XXXdwh needs to be localizable!
                   filesFolder->SetLeafName(nameMinusExt.get());
                   PRBool exists = PR_FALSE;
                   filesFolder->Exists(&exists);
                   if (!exists)
                       filesFolder->Create(nsILocalFile::DIRECTORY_TYPE, 0755);
               }
               else
                   encodingFlags |= nsIWebBrowserPersist::ENCODE_FLAGS_FORMATTED |
                                    nsIWebBrowserPersist::ENCODE_FLAGS_ABSOLUTE_LINKS |
                                    nsIWebBrowserPersist::ENCODE_FLAGS_NOFRAMES_CONTENT;
                                    
               mWebPersist->SaveDocument(mDocument, mDestination, filesFolder, mContentType.get(),
                                         encodingFlags, 80);
         }          }
     }      }
       
       InitDialog();
   }
   
   void
   nsDownloadListener::InitDialog()
   {
       if (!mURL && !mDocument)
           return;
           
       if (mWebPersist) {
           if (mURL) {
               nsCAutoString spec;
               mURL->GetSpec(spec);
               [mController setSourceURL: spec.get()];
           }
           else {
               nsAutoString spec;
               mDocument->GetURL(spec);
               nsCAutoString spec2; spec2.AssignWithConversion(spec);
               [mController setSourceURL: spec2.get()];
           }
       }
       
       nsXPIDLString path;
       mDestination->GetUnicodePath(getter_Copies(path));
       nsCAutoString pathStr; pathStr.AssignWithConversion(path.get());
       [mController setDestination: pathStr.get()];
       
       
 }  }
   
 static NSString *SaveFileToolbarIdentifier      = @"Save File Dialog Toolbar";  static NSString *SaveFileToolbarIdentifier      = @"Save File Dialog Toolbar";
Line 148  static NSString *LeaveOpenToolbarItemIde Line 241  static NSString *LeaveOpenToolbarItemIde
   
 @implementation ProgressDlgController  @implementation ProgressDlgController
   
 - (id)init  
 {  
     if ((self = [super init])) {  
         mDownloadIsPaused = NO;  //Get this value from preferences instead of hardcoding NO.  
         mSaveFileDialogShouldStayOpen = NO;  
     }  
       
     mDownloadListener = nsnull;  
       
     return self;  
 }  
   
 -(void)setWebPersist:(nsIWebBrowserPersist*)aPersist   -(void)setWebPersist:(nsIWebBrowserPersist*)aPersist 
               source:(nsISupports*)aSource                source:(nsISupports*)aSource
          destination:(NSString*)aDestination           destination:(NSString*)aDestination
Line 170  static NSString *LeaveOpenToolbarItemIde Line 251  static NSString *LeaveOpenToolbarItemIde
     mDownloadListener = new nsDownloadListener(self, aPersist, aSource,      mDownloadListener = new nsDownloadListener(self, aPersist, aSource,
                                                aDestination, aContentType,                                                 aDestination, aContentType,
                                                aInputStream, aBypassCache);                                                 aInputStream, aBypassCache);
       NS_ADDREF(mDownloadListener);
   }
   
   -(void) setSourceURL: (const char*)aSource
   {
       [mFromField setStringValue: [NSString stringWithCString: aSource]];
   }
   
   -(void) setDestination: (const char*)aDestination
   {
       [mToField setStringValue: [NSString stringWithCString: aDestination]];
 }  }
   
 - (void)windowDidLoad  - (void)windowDidLoad
 {  {
       mDownloadIsPaused = NO; 
       nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
       PRBool save = PR_FALSE;
       prefs->GetBoolPref("browser.download.progressDnldDialog.keepAlive", 
                           &save);
       mSaveFileDialogShouldStayOpen = save;
   
     [self setupToolbar];      [self setupToolbar];
     if (mDownloadListener)      if (mDownloadListener)
         mDownloadListener->BeginDownload();          mDownloadListener->BeginDownload();
Line 210  static NSString *LeaveOpenToolbarItemIde Line 309  static NSString *LeaveOpenToolbarItemIde
         PauseResumeToolbarItemIdentifier,          PauseResumeToolbarItemIdentifier,
         NSToolbarFlexibleSpaceItemIdentifier,          NSToolbarFlexibleSpaceItemIdentifier,
         LeaveOpenToolbarItemIdentifier,          LeaveOpenToolbarItemIdentifier,
           NSToolbarFlexibleSpaceItemIdentifier,
         ShowFileToolbarItemIdentifier,          ShowFileToolbarItemIdentifier,
         OpenFileToolbarItemIdentifier,          OpenFileToolbarItemIdentifier,
         nil];          nil];
Line 235  static NSString *LeaveOpenToolbarItemIde Line 335  static NSString *LeaveOpenToolbarItemIde
         [toolbarItem setImage:[NSImage imageNamed:@"savePause"]];          [toolbarItem setImage:[NSImage imageNamed:@"savePause"]];
         [toolbarItem setTarget:self];          [toolbarItem setTarget:self];
         [toolbarItem setAction:@selector(pauseAndResumeDownload)];          [toolbarItem setAction:@selector(pauseAndResumeDownload)];
        pauseResumeToggleToolbarItem = toolbarItem; //establish reference        if ( willBeInserted ) {
             pauseResumeToggleToolbarItem = toolbarItem; //establish reference
         }
     } else if ( [itemIdent isEqual:ShowFileToolbarItemIdentifier] ) {      } else if ( [itemIdent isEqual:ShowFileToolbarItemIdentifier] ) {
         [toolbarItem setLabel:@"Show File"];          [toolbarItem setLabel:@"Show File"];
         [toolbarItem setPaletteLabel:@"Show File"];          [toolbarItem setPaletteLabel:@"Show File"];
Line 266  static NSString *LeaveOpenToolbarItemIde Line 368  static NSString *LeaveOpenToolbarItemIde
             [toolbarItem setTarget:self];              [toolbarItem setTarget:self];
             [toolbarItem setAction:@selector(toggleLeaveOpen)];              [toolbarItem setAction:@selector(toggleLeaveOpen)];
         }          }
        leaveOpenToggleToolbarItem = toolbarItem; //establish reference        if ( willBeInserted ) {
             leaveOpenToggleToolbarItem = toolbarItem; //establish reference
         }
     } else {      } else {
         toolbarItem = nil;          toolbarItem = nil;
     }      }
Line 277  static NSString *LeaveOpenToolbarItemIde Line 381  static NSString *LeaveOpenToolbarItemIde
 -(void)cancel  -(void)cancel
 {  {
     NSLog(@"Request to cancel download.");      NSLog(@"Request to cancel download.");
     //Put logic here!  
 }  }
   
 -(void)pauseAndResumeDownload  -(void)pauseAndResumeDownload
Line 312  static NSString *LeaveOpenToolbarItemIde Line 415  static NSString *LeaveOpenToolbarItemIde
 -(void)toggleLeaveOpen  -(void)toggleLeaveOpen
 {  {
     if ( ! mSaveFileDialogShouldStayOpen ) {      if ( ! mSaveFileDialogShouldStayOpen ) {
         //Do logic to set the preference and make it take effect  
         mSaveFileDialogShouldStayOpen = YES;          mSaveFileDialogShouldStayOpen = YES;
         [leaveOpenToggleToolbarItem setLabel:@"Leave Open"];          [leaveOpenToggleToolbarItem setLabel:@"Leave Open"];
         [leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];          [leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
         [leaveOpenToggleToolbarItem setToolTip:@"Window will stay open when download finishes."];          [leaveOpenToggleToolbarItem setToolTip:@"Window will stay open when download finishes."];
         [leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];          [leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];
     } else {      } else {
         //Do logic to set the preference and make it take effect  
         mSaveFileDialogShouldStayOpen = NO;          mSaveFileDialogShouldStayOpen = NO;
         [leaveOpenToggleToolbarItem setLabel:@"Close When Done"];          [leaveOpenToggleToolbarItem setLabel:@"Close When Done"];
         [leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];          [leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
         [leaveOpenToggleToolbarItem setToolTip:@"Window will close automatically when download finishes."];          [leaveOpenToggleToolbarItem setToolTip:@"Window will close automatically when download finishes."];
         [leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];          [leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];
     }      }
       
       nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
       prefs->SetBoolPref("browser.download.progressDnldDialog.keepAlive", mSaveFileDialogShouldStayOpen);
 }  }
   
 - (void)windowWillClose:(NSNotification *)notification  - (void)windowWillClose:(NSNotification *)notification
 {  {
    [self release];    [self autorelease];
 }  }
   
 - (void)dealloc  - (void)dealloc
 {  {
    delete mDownloadListener;    NS_IF_RELEASE(mDownloadListener);
    mDownloadListener = nsnull; 
    [pauseResumeToggleToolbarItem release]; 
    [leaveOpenToggleToolbarItem release]; 
     [super dealloc];      [super dealloc];
 }  }
   

Removed from v.1.8  
changed lines
  Added in v.1.13


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