home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / msv2dsk.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.2 KB  |  160 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #pragma once
  20. /*=============================================================================
  21.     Save-To-Disk Context
  22.     
  23.     We create a context for saving items to disk and display a
  24.     small status window for progress.
  25. =============================================================================*/
  26. #include "client.h"
  27.  
  28. // class NetscapeContext;
  29. class CNSContext;
  30.  
  31. class CMimeMapper;
  32. class LFileStream;
  33. struct CStr255;
  34.  
  35. int PROGRESS_GetUrl (URL_Struct * request,
  36.                 int format_out, 
  37.                 const FSSpec * destination,
  38.                 Boolean delayed = FALSE);
  39.  
  40. // Are there any load-to-disk downloads happening for this context
  41. // Call this before loading the URL if you do not want to interrupt the download
  42. Boolean HasDownloads(MWContext * context);
  43.  
  44. /*-----------------------------------------------------------------------------
  45.     Pipes
  46.     These are a set of classes for implementing converters which write
  47.     data to disk.
  48. -----------------------------------------------------------------------------*/
  49.  
  50. class Pipe {
  51. public:
  52.                     Pipe ();
  53.     virtual         ~Pipe ();
  54.     
  55.     // base stream functions
  56.     virtual OSErr     Open ();
  57.     virtual int     Write (const char *buffer, int len);
  58.     virtual void     Complete ();
  59.     virtual void     Abort (int reason);
  60.     
  61.     // utilities
  62.     NET_StreamClass * MakeStreamObject (char * name, MWContext * context);
  63.     
  64. private:
  65.     // dispatch functions to our stream (for "C" NetLib)
  66.     static int         HandleProcess (NET_StreamClass *stream, const char *buffer, 
  67.                         int32 buffLen);
  68.     static void     HandleComplete (NET_StreamClass *stream);
  69.     static void     HandleAbort (NET_StreamClass *stream, int reason);
  70.     static unsigned int    HandleWriteReady(NET_StreamClass *stream);
  71. };
  72.  
  73. extern NET_StreamClass * 
  74. NewFilePipe (int format_out, void *registration, URL_Struct * request, MWContext *context);
  75.  
  76.  
  77. // NewExternal is the stream that handles FO_PRESENT of the types
  78. // that are not displayed internally
  79. static NET_StreamClass *NewExternalPipe (int format_out, 
  80.                             void *registration, 
  81.                             URL_Struct *url, 
  82.                             MWContext *context);
  83.  
  84. // NewExternal is the stream that handles FO_VIEW_SOURCE streams
  85. // Fires up an application tied to Source mime type
  86. static NET_StreamClass *NewSourcePipe (int format_out, 
  87.                             void *registration, 
  88.                             URL_Struct *url, 
  89.                             MWContext *context);
  90.  
  91. // NewLoadToDiskPipe writes incoming data to disk
  92. static NET_StreamClass *NewLoadToDiskPipe (int format_out, 
  93.                             void *registration, 
  94.                             URL_Struct *url, 
  95.                             MWContext *context);
  96.  
  97. NET_StreamClass *NewSaveAsPipe (int format_out, 
  98.                                 void *registration,
  99.                                 URL_Struct *request, 
  100.                                 MWContext *context);
  101.  
  102. class PlainFilePipe: public Pipe
  103. {
  104.     public:
  105.                     PlainFilePipe();
  106.                     PlainFilePipe(
  107.                             OSType                 creator,
  108.                             OSType                 fileType,
  109.                             URL_Struct*            url,
  110.                             CNSContext*         inContext = NULL);
  111.  
  112.                     PlainFilePipe(
  113.                             OSType                 creator,
  114.                             OSType                 fileType,
  115.                             FSSpec&             writeTo,
  116.                             CNSContext*         inContext = NULL);
  117.                     
  118.         virtual     ~PlainFilePipe();
  119. // ÑÑ stream interface
  120.     OSErr             Open ();
  121.     int             Write (const char *buffer, int buffLen);
  122.     void             Complete ();
  123.     void             Abort (int reason);
  124. // ÑÑ misc
  125.     void            SetTranslateLF(Boolean doTranslate);    // Should we do linefeed translation
  126. protected:
  127.     LFileStream    *    fFile;            // It will be deleted by CFileMgr
  128.     Boolean            fDeleteFileObj;    // Should we delete the file object?
  129. // Disk flushing routines
  130.     int                fBytesWritten;    // We have an interactivity problem with 
  131.         // hard drives and Mac's disk cache. If system file cache is large, flushing of
  132.         // the large file buffer can result in a hang, and cause TCP connection to drop
  133.         // So, we flush the file every 32K. Should make flush async one day
  134.     CNSContext* mContext;
  135.     Int32        fTotalBytes;
  136.     Int32        fTotalWritten;
  137.     Boolean        fTranslateLF;        // For ViewSource, we want to translate the LF to CR. FALSE by default
  138. };
  139.  
  140. /***************************************************************************************
  141.  * MapperFilePipe
  142.  * file is specified by the mime mapper
  143.  ***************************************************************************************/
  144. class MapperFilePipe: public PlainFilePipe
  145. {    
  146.     public:
  147.                         MapperFilePipe(
  148.                                 URL_Struct*             url,
  149.                                 CMimeMapper*            mapper,
  150.                                 CNSContext*         inContext = NULL);
  151.  
  152.                         ~MapperFilePipe ();
  153.         static FSSpec    MakeSpec (CStr255& filename);
  154.         void             Complete ();
  155.  
  156.     private:
  157.         CMimeMapper *    fMapper;        // Mapper for this file
  158. };
  159.  
  160.