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

version 1.8, 2002/02/04 02:55:17 version 1.9, 2002/02/04 03:44:35
Line 14 Line 14
 #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 53  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 134  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) {
               nsXPIDLCString spec;
               mURL->GetSpec(getter_Copies(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 212  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 222  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 312  static NSString *LeaveOpenToolbarItemIde Line 382  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.9


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