Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes
nsMIMEInfoBase Class Reference

Basic implementation of nsIMIMEInfo. More...

#include <nsMIMEInfoImpl.h>

Inheritance diagram for nsMIMEInfoBase:
Inheritance graph
[legend]
Collaboration diagram for nsMIMEInfoBase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS NS_IMETHOD GetFileExtensions (nsIUTF8StringEnumerator **_retval)
NS_IMETHOD SetFileExtensions (const nsACString &aExtensions)
NS_IMETHOD ExtensionExists (const nsACString &aExtension, PRBool *_retval)
NS_IMETHOD AppendExtension (const nsACString &aExtension)
NS_IMETHOD GetPrimaryExtension (nsACString &aPrimaryExtension)
NS_IMETHOD SetPrimaryExtension (const nsACString &aPrimaryExtension)
NS_IMETHOD GetMIMEType (nsACString &aMIMEType)
NS_IMETHOD GetDescription (nsAString &aDescription)
NS_IMETHOD SetDescription (const nsAString &aDescription)
NS_IMETHOD GetMacType (PRUint32 *aMacType)
NS_IMETHOD SetMacType (PRUint32 aMacType)
NS_IMETHOD GetMacCreator (PRUint32 *aMacCreator)
NS_IMETHOD SetMacCreator (PRUint32 aMacCreator)
NS_IMETHOD Equals (nsIMIMEInfo *aMIMEInfo, PRBool *_retval)
NS_IMETHOD GetPreferredApplicationHandler (nsIFile **aPreferredApplicationHandler)
NS_IMETHOD SetPreferredApplicationHandler (nsIFile *aPreferredApplicationHandler)
NS_IMETHOD GetApplicationDescription (nsAString &aApplicationDescription)
NS_IMETHOD SetApplicationDescription (const nsAString &aApplicationDescription)
NS_IMETHOD GetDefaultDescription (nsAString &aDefaultDescription)
NS_IMETHOD LaunchWithFile (nsIFile *aFile)
NS_IMETHOD GetPreferredAction (nsMIMEInfoHandleAction *aPreferredAction)
NS_IMETHOD SetPreferredAction (nsMIMEInfoHandleAction aPreferredAction)
NS_IMETHOD GetAlwaysAskBeforeHandling (PRBool *aAlwaysAskBeforeHandling)
NS_IMETHOD SetAlwaysAskBeforeHandling (PRBool aAlwaysAskBeforeHandling)
 nsMIMEInfoBase (const char *aMIMEType="") NS_HIDDEN
 nsMIMEInfoBase (const nsACString &aMIMEType) NS_HIDDEN
virtual ~nsMIMEInfoBase ()
void SetMIMEType (const nsACString &aMIMEType)
void SetDefaultDescription (const nsString &aDesc)
void CopyBasicDataTo (nsMIMEInfoBase *aOther)
 Copies basic data of this MIME Info Implementation to the given other MIME Info.
PRBool HasExtensions () const
 Return whether this MIMEInfo has any extensions.
nsIUTF8StringEnumerator getFileExtensions ()
 Gives you an array of file types associated with this type.
void setFileExtensions (in AUTF8String aExtensions)
 Set File Extensions.
boolean extensionExists (in AUTF8String aExtension)
 Returns whether or not the given extension is associated with this MIME info.
void appendExtension (in AUTF8String aExtension)
 Append a given extension to the set of extensions.
boolean equals (in nsIMIMEInfo aMIMEInfo)
 Returns whether or not these two MIME infos are logically equivalent maintaining the one-to-many relationship between MIME types and file extensions.
void launchWithFile (in nsIFile aFile)
 Launches the application with the specified file, in a way that depends on the value of preferredAction.

Public Attributes

attribute AUTF8String primaryExtension
 Returns the first extension association in the internal set of extensions.
readonly attribute ACString MIMEType
 The MIME type of this MIMEInfo.
attribute AString description
 A human readable description of the MIME info.
attribute PRUint32 macType
 Mac Type and creator types.
attribute PRUint32 macCreator
attribute nsIFile preferredApplicationHandler
 Returns a nsIFile that points to the application the user has said they want associated with this content type.
attribute AString applicationDescription
 A pretty name description of the preferred application.
readonly attribute boolean hasDefaultHandler
 Indicates whether a default application handler exists, i.e.
readonly attribute AString defaultDescription
 A pretty name description of the associated default application.
const long saveToDisk = 0
const long alwaysAsk = 1
const long useHelperApp = 2
const long handleInternally = 3
const long useSystemDefault = 4
attribute nsMIMEInfoHandleAction preferredAction
 preferredAction is how the user specified they would like to handle this content type: save to disk, use specified helper app, use OS default handler or handle using navigator.
attribute boolean alwaysAskBeforeHandling
 alwaysAskBeforeHandling: if true, we should always give the user a dialog asking how to dispose of this content.

Protected Member Functions

virtual NS_HIDDEN_ (nsresult) LaunchDefaultWithFile(nsIFile *aFile)=0
 Launch the default application for the given file.

Static Protected Member Functions

static NS_HIDDEN_ (nsresult) LaunchWithIProcess(nsIFile *aApp
 This method can be used to launch the file using nsIProcess, with the path of the file being the first parameter to the executable.

Protected Attributes

static nsIFileaFile
nsCStringArray mExtensions
 array of file extensions associated w/ this MIME obj
nsString mDescription
 human readable description
PRUint32 mMacType
PRUint32 mMacCreator
 Mac file type and creator.
nsCString mMIMEType
nsCOMPtr< nsIFilemPreferredApplication
 preferred application associated with this type.
nsMIMEInfoHandleAction mPreferredAction
 preferred action to associate with this type
nsString mPreferredAppDescription
nsString mDefaultAppDescription
PRBool mAlwaysAskBeforeHandling

Detailed Description

Basic implementation of nsIMIMEInfo.

Incomplete - it is meant to be subclassed, and GetHasDefaultHandler as well as LaunchDefaultWithFile need to be implemented.

Definition at line 65 of file nsMIMEInfoImpl.h.


Constructor & Destructor Documentation

nsMIMEInfoBase::nsMIMEInfoBase ( const char *  aMIMEType = "")
nsMIMEInfoBase::nsMIMEInfoBase ( const nsACString &  aMIMEType)

Definition at line 67 of file nsMIMEInfoImpl.cpp.

{
}

Member Function Documentation

NS_IMETHODIMP nsMIMEInfoBase::AppendExtension ( const nsACString &  aExtension)

Definition at line 131 of file nsMIMEInfoImpl.cpp.

{
  mExtensions.AppendCString(aExtension);
  return NS_OK;
}

Here is the caller graph for this function:

void nsIMIMEInfo::appendExtension ( in AUTF8String  aExtension) [inherited]

Append a given extension to the set of extensions.

Copies basic data of this MIME Info Implementation to the given other MIME Info.

The data consists of the MIME Type, the (default) description, the MacOS type and creator, and the extension list (this object's extension list will replace aOther's list, not append to it). This function also ensures that aOther's primary extension will be the same as the one of this object.

Definition at line 317 of file nsMIMEInfoImpl.cpp.

NS_IMETHODIMP nsMIMEInfoBase::Equals ( nsIMIMEInfo aMIMEInfo,
PRBool _retval 
)

Definition at line 162 of file nsMIMEInfoImpl.cpp.

{
    if (!aMIMEInfo) return NS_ERROR_NULL_POINTER;

    nsCAutoString type;
    nsresult rv = aMIMEInfo->GetMIMEType(type);
    if (NS_FAILED(rv)) return rv;

    *_retval = mMIMEType.Equals(type);

    return NS_OK;
}
boolean nsIMIMEInfo::equals ( in nsIMIMEInfo  aMIMEInfo) [inherited]

Returns whether or not these two MIME infos are logically equivalent maintaining the one-to-many relationship between MIME types and file extensions.

Returns:
TRUE if the two are considered equal
NS_IMETHODIMP nsMIMEInfoBase::ExtensionExists ( const nsACString &  aExtension,
PRBool _retval 
)

Definition at line 78 of file nsMIMEInfoImpl.cpp.

{
    NS_ASSERTION(!aExtension.IsEmpty(), "no extension");
    PRBool found = PR_FALSE;
    PRUint32 extCount = mExtensions.Count();
    if (extCount < 1) return NS_OK;

    for (PRUint8 i=0; i < extCount; i++) {
        nsCString* ext = (nsCString*)mExtensions.CStringAt(i);
        if (ext->Equals(aExtension, nsCaseInsensitiveCStringComparator())) {
            found = PR_TRUE;
            break;
        }
    }

    *_retval = found;
    return NS_OK;
}
boolean nsIMIMEInfo::extensionExists ( in AUTF8String  aExtension) [inherited]

Returns whether or not the given extension is associated with this MIME info.

Returns:
TRUE if the association exists.

Definition at line 286 of file nsMIMEInfoImpl.cpp.

{
  *aAlwaysAsk = mAlwaysAskBeforeHandling;

  return NS_OK;
}
NS_IMETHODIMP nsMIMEInfoBase::GetApplicationDescription ( nsAString &  aApplicationDescription)

Definition at line 229 of file nsMIMEInfoImpl.cpp.

{
  if (mPreferredAppDescription.IsEmpty() && mPreferredApplication) {
    // Don't want to cache this, just in case someone resets the app
    // without changing the description....
    mPreferredApplication->GetLeafName(aApplicationDescription);
  } else {
    aApplicationDescription = mPreferredAppDescription;
  }
  
  return NS_OK;
}
NS_IMETHODIMP nsMIMEInfoBase::GetDefaultDescription ( nsAString &  aDefaultDescription)

Reimplemented in nsMIMEInfoImpl.

Definition at line 250 of file nsMIMEInfoImpl.cpp.

{
  aDefaultDescription = mDefaultAppDescription;
  return NS_OK;
}
NS_IMETHODIMP nsMIMEInfoBase::GetDescription ( nsAString &  aDescription)

Definition at line 148 of file nsMIMEInfoImpl.cpp.

{
    aDescription = mDescription;
    return NS_OK;
}

Gives you an array of file types associated with this type.

Returns:
Number of elements in the array.
Array of extensions.

Definition at line 72 of file nsMIMEInfoImpl.cpp.

Here is the call graph for this function:

Definition at line 194 of file nsMIMEInfoImpl.cpp.

{
    *aMacCreator = mMacCreator;

    if (!mMacCreator)
        return NS_ERROR_NOT_INITIALIZED;

    return NS_OK;
}

Definition at line 176 of file nsMIMEInfoImpl.cpp.

{
    *aMacType = mMacType;

    if (!mMacType)
        return NS_ERROR_NOT_INITIALIZED;

    return NS_OK;
}
NS_IMETHODIMP nsMIMEInfoBase::GetMIMEType ( nsACString &  aMIMEType)

Definition at line 138 of file nsMIMEInfoImpl.cpp.

{
    if (mMIMEType.IsEmpty())
        return NS_ERROR_NOT_INITIALIZED;

    aMIMEType = mMIMEType;
    return NS_OK;
}

Definition at line 272 of file nsMIMEInfoImpl.cpp.

{
  *aPreferredAction = mPreferredAction;
  return NS_OK;
}

Definition at line 257 of file nsMIMEInfoImpl.cpp.

{
  *aPreferredAppHandler = mPreferredApplication;
  NS_IF_ADDREF(*aPreferredAppHandler);
  return NS_OK;
}
NS_IMETHODIMP nsMIMEInfoBase::GetPrimaryExtension ( nsACString &  aPrimaryExtension)

Definition at line 98 of file nsMIMEInfoImpl.cpp.

{
    PRUint32 extCount = mExtensions.Count();
    if (extCount < 1) return NS_ERROR_NOT_INITIALIZED;

    _retval = *(mExtensions.CStringAt(0));
    return NS_OK;    
}

Return whether this MIMEInfo has any extensions.

Definition at line 117 of file nsMIMEInfoImpl.h.

{ return mExtensions.Count() != 0; }

Reimplemented in nsMIMEInfoOS2, and nsMIMEInfoMac.

Definition at line 301 of file nsMIMEInfoImpl.cpp.

{
  if (mPreferredAction == useHelperApp) {
    if (!mPreferredApplication)
      return NS_ERROR_FILE_NOT_FOUND;

    return LaunchWithIProcess(mPreferredApplication, aFile);
  }
  else if (mPreferredAction == useSystemDefault) {
    return LaunchDefaultWithFile(aFile);
  }

  return NS_ERROR_INVALID_ARG;
}
void nsIMIMEInfo::launchWithFile ( in nsIFile  aFile) [inherited]

Launches the application with the specified file, in a way that depends on the value of preferredAction.

preferredAction must be useHelperApp or useSystemDefault.

Parameters:
aFileThe file to launch this application with.
Exceptions:
NS_ERROR_INVALID_ARGif action is not valid for this function. Other exceptions may be thrown.
virtual nsMIMEInfoBase::NS_HIDDEN_ ( nsresult  ) [protected, pure virtual]

Launch the default application for the given file.

For even more control over the launching, override launchWithFile. Also see the comment about nsIMIMEInfo in general, above.

Parameters:
aFileThe file that should be opened

Implemented in nsMIMEInfoImpl, and nsMIMEInfoBeOS.

static nsMIMEInfoBase::NS_HIDDEN_ ( nsresult  ) [static, protected]

This method can be used to launch the file using nsIProcess, with the path of the file being the first parameter to the executable.

This is meant as a helper method for implementations of LaunchWithFile/LaunchDefaultWithFile. Neither aApp nor aFile may be null.

Parameters:
aAppThe application to launch
aFileThe file to open in the application

Reimplemented in nsMIMEInfoImpl, and nsMIMEInfoBeOS.

Definition at line 294 of file nsMIMEInfoImpl.cpp.

{
  mAlwaysAskBeforeHandling = aAlwaysAsk;
  return NS_OK;
}
NS_IMETHODIMP nsMIMEInfoBase::SetApplicationDescription ( const nsAString &  aApplicationDescription)

Definition at line 243 of file nsMIMEInfoImpl.cpp.

{
  mPreferredAppDescription = aApplicationDescription;
  return NS_OK;
}

Definition at line 102 of file nsMIMEInfoImpl.h.

Here is the caller graph for this function:

NS_IMETHODIMP nsMIMEInfoBase::SetDescription ( const nsAString &  aDescription)

Definition at line 155 of file nsMIMEInfoImpl.cpp.

{
    mDescription = aDescription;
    return NS_OK;
}

Here is the caller graph for this function:

void nsIMIMEInfo::setFileExtensions ( in AUTF8String  aExtensions) [inherited]

Set File Extensions.

Input is a comma delimited list of extensions.

NS_IMETHODIMP nsMIMEInfoBase::SetFileExtensions ( const nsACString &  aExtensions)

Definition at line 212 of file nsMIMEInfoImpl.cpp.

{
    mExtensions.Clear();
    nsCString extList( aExtensions );
    
    PRInt32 breakLocation = -1;
    while ( (breakLocation= extList.FindChar(',') )!= -1)
    {
        mExtensions.AppendCString(Substring(extList.get(), extList.get() + breakLocation));
        extList.Cut(0, breakLocation+1 );
    }
    if ( !extList.IsEmpty() )
        mExtensions.AppendCString( extList );
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 205 of file nsMIMEInfoImpl.cpp.

{
    mMacCreator = aMacCreator;
    return NS_OK;
}

Definition at line 187 of file nsMIMEInfoImpl.cpp.

{
    mMacType = aMacType;
    return NS_OK;
}
void nsMIMEInfoBase::SetMIMEType ( const nsACString &  aMIMEType) [inline]

Definition at line 100 of file nsMIMEInfoImpl.h.

{ mMIMEType = aMIMEType; }

Here is the caller graph for this function:

Definition at line 279 of file nsMIMEInfoImpl.cpp.

{
  mPreferredAction = aPreferredAction;
  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 265 of file nsMIMEInfoImpl.cpp.

{
  mPreferredApplication = aPreferredAppHandler;
  return NS_OK;
}
NS_IMETHODIMP nsMIMEInfoBase::SetPrimaryExtension ( const nsACString &  aPrimaryExtension)

Definition at line 108 of file nsMIMEInfoImpl.cpp.

{
  NS_ASSERTION(!aExtension.IsEmpty(), "no extension");
  PRUint32 extCount = mExtensions.Count();
  PRUint8 i;
  PRBool found = PR_FALSE;
  for (i=0; i < extCount; i++) {
    nsCString* ext = (nsCString*)mExtensions.CStringAt(i);
    if (ext->Equals(aExtension, nsCaseInsensitiveCStringComparator())) {
      found = PR_TRUE;
      break;
    }
  }
  if (found) {
    mExtensions.RemoveCStringAt(i);
  }

  mExtensions.InsertCStringAt(aExtension, 0);
  
  return NS_OK;
}

Member Data Documentation

Definition at line 139 of file nsMIMEInfoImpl.h.

Definition at line 160 of file nsIMIMEInfo.idl.

alwaysAskBeforeHandling: if true, we should always give the user a dialog asking how to dispose of this content.

Definition at line 176 of file nsIMIMEInfo.idl.

A pretty name description of the preferred application.

Definition at line 132 of file nsIMIMEInfo.idl.

readonly attribute AString nsIMIMEInfo::defaultDescription [inherited]

A pretty name description of the associated default application.

Only usable if hasDefaultHandler is true.

Definition at line 145 of file nsIMIMEInfo.idl.

attribute AString nsIMIMEInfo::description [inherited]

A human readable description of the MIME info.

Returns:
The description

Definition at line 105 of file nsIMIMEInfo.idl.

Definition at line 162 of file nsIMIMEInfo.idl.

Indicates whether a default application handler exists, i.e.

whether launchWithFile with action = useSystemDefault is possible and applicationDescription will contain usable information.

Definition at line 139 of file nsIMIMEInfo.idl.

Definition at line 111 of file nsIMIMEInfo.idl.

Mac Type and creator types.

Definition at line 110 of file nsIMIMEInfo.idl.

Definition at line 150 of file nsMIMEInfoImpl.h.

Definition at line 149 of file nsMIMEInfoImpl.h.

human readable description

Definition at line 143 of file nsMIMEInfoImpl.h.

nsCStringArray nsMIMEInfoBase::mExtensions [protected]

array of file extensions associated w/ this MIME obj

Definition at line 142 of file nsMIMEInfoImpl.h.

readonly attribute ACString nsIMIMEInfo::MIMEType [inherited]

The MIME type of this MIMEInfo.

Returns:
String representing the MIME type.

Definition at line 98 of file nsIMIMEInfo.idl.

Mac file type and creator.

Definition at line 144 of file nsMIMEInfoImpl.h.

Definition at line 144 of file nsMIMEInfoImpl.h.

Definition at line 145 of file nsMIMEInfoImpl.h.

preferred action to associate with this type

Definition at line 147 of file nsMIMEInfoImpl.h.

Definition at line 148 of file nsMIMEInfoImpl.h.

preferred application associated with this type.

Definition at line 146 of file nsMIMEInfoImpl.h.

preferredAction is how the user specified they would like to handle this content type: save to disk, use specified helper app, use OS default handler or handle using navigator.

Definition at line 170 of file nsIMIMEInfo.idl.

Returns a nsIFile that points to the application the user has said they want associated with this content type.

This is not always guaranteed to be set!!

Definition at line 127 of file nsIMIMEInfo.idl.

attribute AUTF8String nsIMIMEInfo::primaryExtension [inherited]

Returns the first extension association in the internal set of extensions.

Returns:
The first extension.

Definition at line 91 of file nsIMIMEInfo.idl.

Definition at line 159 of file nsIMIMEInfo.idl.

Definition at line 161 of file nsIMIMEInfo.idl.

Definition at line 163 of file nsIMIMEInfo.idl.


The documentation for this class was generated from the following files: