home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / umimemap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.2 KB  |  192 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. // umimemap.h
  22. // MIME to Mac application/filetype mappings
  23. // Created by atotic, June 13th, 1994
  24. // ===========================================================================
  25.  
  26. #include <LArray.h>
  27. #include "AppleEvents.h"
  28. #include "PascalString.h"
  29.  
  30. class LFileBufferStream;
  31. class CPrefs;
  32.  
  33. typedef struct URL_Struct_ URL_Struct;
  34.  
  35. /*****************************************************************************
  36.  * class CMimeMapper
  37.  * Maps a mime type to record describing what external application to use
  38.  * with this mime type, and how to launch it.
  39.  * Mappings are stored in a preference file, as resources of type MIME
  40.  *****************************************************************************/
  41.  
  42. class CMimeMapper {
  43. public:
  44.         // All these must be non-zero because of a presumed bug in back end
  45.     enum LoadAction { Save = 0, Launch = 1, Internal = 2, Unknown = 3, Plugin = 4};
  46.     
  47.     // ÑÑ Constructors/destructors
  48.     void        InitMapper();
  49.     CMimeMapper(Handle resRecord);    // Takes in a resource of type 'MIME'
  50.     CMimeMapper(const CMimeMapper& clone);    // Duplicate
  51.     CMimeMapper(LoadAction loadAction, const CStr255& mimeType,
  52.         const CStr255& appName, const CStr255& extensions, 
  53.         OSType appSignature, OSType fileType );
  54.     ~CMimeMapper();
  55.  
  56.     static    Boolean    NetscapeCanHandle(CStr255& mimeType);
  57.  
  58.     // ÑÑ╩XP prefs
  59.     CMimeMapper( const char* basepref );
  60.     static CMimeMapper*    CreateMapperFor(const char* basepref, Boolean newPrefFormat = true);
  61.     static CMimeMapper*    CreateMapperForRes(Handle res);
  62.     
  63.     void        ReadMimePrefs();
  64.     void        WriteMimePrefs(Boolean isDefault = false);
  65.  
  66.  
  67.     // ÑÑ Access
  68.     
  69.         // Set functions are used by app setup box
  70.     void SetAppName(const CStr255& newName);
  71.     void SetMimeType(const CStr255& newType);
  72.     void SetExtensions(const CStr255& newExtensions);
  73.     void SetPluginName(const CStr255& newName)            { fPluginName = newName; }
  74.     void SetDescription(const CStr255& newDesc)            { fDescription = newDesc; }
  75.     void SetAppSig(OSType newSig);
  76.     void SetAppSig(FSSpec& appSpec);    // Set the signature, given the file spec. Will THROW on error
  77.     void SetDocType(OSType newType);
  78.     void SetLoadAction(LoadAction newAction);
  79.     void SetLatentPlugin();
  80.     void SetDefaultDescription();
  81.     
  82.         // External viewers
  83.     void SetTemporary(Boolean isTemporary)    {fTemporary = isTemporary;}
  84.     void RegisterViewer(OSType tempAppSig, OSType tempFileType);
  85.     void UnregisterViewer();
  86.     Boolean IsViewerRegistered() const { return fRegisteredViewer; }
  87.  
  88.         // Get functions
  89.     CStr255 GetAppName() {return fAppName;};
  90.     CStr255 GetMimeName() {return fMimeType;};
  91.     CStr255 GetExtensions() {return fExtensions;};
  92.     CStr255 GetPluginName() { return fPluginName; }
  93.     CStr255 GetDescription() { return fDescription; }
  94.     OSType GetAppSig() {return fRegisteredViewer ? fTempAppSig : fAppSig;};
  95.     OSType GetDocType() {return fRegisteredViewer ? fTempFileType :fFileType;};
  96.     LoadAction GetLoadAction() {return fRegisteredViewer ? Launch : fLoadAction;};    
  97.     Boolean IsTemporary() {return fTemporary;}
  98.     Boolean FromOldPrefs() { return fFromOldPrefs; }
  99.     Boolean LatentPlugin() { return fLatentPlugin; }
  100.     char* GetBasePref() { return fBasePref; }
  101.     
  102.     // ÑÑ╩operators
  103.     CMimeMapper & operator = (const CMimeMapper& mapper);
  104.     
  105.     // ÑÑ╩utility
  106.     // Get the spec for this MIME mapper
  107.     OSErr    GetFileSpec(URL_Struct * request, 
  108.                         FSSpec & destination);
  109.     OSErr    LaunchFile(LFileBufferStream * fFile,    // File to launch
  110.                         URL_Struct * request,    // URL associated with the file
  111.                         Int32 windowID);        // ID of the parent window
  112.     void SyncNetlib();
  113. private:
  114.     OSErr    MakeSpyEvent(AppleEvent & event, 
  115.                         URL_Struct * request,
  116.                         AEEventID id,
  117.                         AEKeyword urlAttribute);
  118.  
  119.     Boolean    PrintableChars(const void *inBuffer, Int32 inLength);
  120.     
  121.     // Basic mapper information
  122.     CStr255        fMimeType;            // MIME type
  123.     CStr255        fAppName;            // Application's name
  124.     CStr255        fExtensions;        // Extensions for this file type
  125.     OSType        fAppSig;            // Application signature
  126.     OSType        fFileType;            // Mac file type
  127.     LoadAction    fLoadAction;        // What to do after launch
  128.     // Information about the registered viewers
  129.     Boolean        fTemporary;            // This is only a temporary mapper
  130.     Boolean        fRegisteredViewer;    // This is a registered viewer, use all the special codes
  131.     OSType        fTempAppSig;        // Application
  132.     OSType        fTempFileType;        // File signature
  133.     CStr255        fPluginName;        // Plug-in's name
  134.     CStr255        fDescription;        // Description of the type
  135.     Boolean        fFromOldPrefs;        // Was this mapper from pre-plugin prefs?
  136.     Boolean        fLatentPlugin;        // Was the plug-in disabled only because it╒s missing?
  137.     char*        fBasePref;            // Corresponding XP pref branch name
  138. };
  139.  
  140.  
  141.  
  142. /*****************************************************************************
  143.  * class CMimeList
  144.  * Holds a list of CMimeMappers. Has utility functions for mime list manipulation
  145.  * Also handles registration of special viewers
  146.  *****************************************************************************/
  147.  
  148. class CMimeList : public LArray {
  149. friend class CPrefs;
  150. public:
  151.     enum BuiltIn { HTMLViewer = 0, Telnet = 1, Tn3270 = 2, Last};
  152.     
  153.     // ÑÑ Constructors/destructors
  154.                         CMimeList();
  155.     virtual                ~CMimeList();
  156.     
  157.     // Overrode this on the assumption that every time you add a MIME mapper
  158.     // to this list, you want to sync up the netlib
  159.     virtual ArrayIndexT    InsertItemsAt(
  160.                             Uint32            inCount,
  161.                             ArrayIndexT        inAtIndex,
  162.                             const void        *inItem,
  163.                             Uint32            inItemSize = 0);
  164.  
  165.     // ÑÑ╩Utility functions
  166.     // Deletes all the items in the list. Can also delete static MIME mappers
  167.     void                DeleteAll(Boolean unused = false);
  168.      
  169.      // Returns mimemapper with given mime type
  170.      //    NULL if none
  171.      CMimeMapper*        FindMimeType( char* mimeType );
  172.     CMimeMapper*        FindMimeType( BuiltIn mimeBuiltin );
  173.     CMimeMapper*        FindMimeType( const FSSpec& file );
  174.      
  175.      // Returns mimemapper with given application signature
  176.     CMimeMapper*         FindCreator( OSType appSig );    // NULL if none
  177.  
  178.     // Returns mimemapper with given XP pref branch name
  179.     CMimeMapper*        FindBasePref( const char* basepref );
  180.  
  181.     // ÑÑ Apple event handling
  182.     void                 HandleRegisterViewerEvent(const AppleEvent    &inAppleEvent,
  183.                                     AppleEvent            &outAEReply,
  184.                                     AEDesc                &outResult,
  185.                                     long                inAENumber);
  186.     void                 HandleUnregisterViewerEvent(const AppleEvent    &inAppleEvent,
  187.                                     AppleEvent            &outAEReply,
  188.                                     AEDesc                &outResult,
  189.                                     long                inAENumber);
  190.  
  191. };
  192.