Back to index

lightning-sunbird  0.9+nobinonly
nsMIMEInfoImpl.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* vim:set ts=2 sw=2 sts=2 et: */
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #ifndef __nsmimeinfoimpl_h___
00039 #define __nsmimeinfoimpl_h___
00040 
00041 #include "nsIMIMEInfo.h"
00042 #include "nsIAtom.h"
00043 #include "nsString.h"
00044 #include "nsVoidArray.h"
00045 #include "nsIFile.h"
00046 #include "nsCOMPtr.h"
00047 #include "nsIURI.h"
00048 
00053 #define PROPERTY_DEFAULT_APP_ICON_URL "defaultApplicationIconURL"
00054 
00058 #define PROPERTY_CUSTOM_APP_ICON_URL "customApplicationIconURL"
00059 
00065 class nsMIMEInfoBase : public nsIMIMEInfo {
00066   public:
00067     NS_DECL_ISUPPORTS
00068 
00069     // I'd use NS_DECL_NSIMIMEINFO, but I don't want GetHasDefaultHandler
00070     NS_IMETHOD GetFileExtensions(nsIUTF8StringEnumerator **_retval);
00071     NS_IMETHOD SetFileExtensions(const nsACString & aExtensions);
00072     NS_IMETHOD ExtensionExists(const nsACString & aExtension, PRBool *_retval);
00073     NS_IMETHOD AppendExtension(const nsACString & aExtension);
00074     NS_IMETHOD GetPrimaryExtension(nsACString & aPrimaryExtension);
00075     NS_IMETHOD SetPrimaryExtension(const nsACString & aPrimaryExtension);
00076     NS_IMETHOD GetMIMEType(nsACString & aMIMEType);
00077     NS_IMETHOD GetDescription(nsAString & aDescription);
00078     NS_IMETHOD SetDescription(const nsAString & aDescription);
00079     NS_IMETHOD GetMacType(PRUint32 *aMacType);
00080     NS_IMETHOD SetMacType(PRUint32 aMacType);
00081     NS_IMETHOD GetMacCreator(PRUint32 *aMacCreator);
00082     NS_IMETHOD SetMacCreator(PRUint32 aMacCreator);
00083     NS_IMETHOD Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval);
00084     NS_IMETHOD GetPreferredApplicationHandler(nsIFile * *aPreferredApplicationHandler);
00085     NS_IMETHOD SetPreferredApplicationHandler(nsIFile * aPreferredApplicationHandler);
00086     NS_IMETHOD GetApplicationDescription(nsAString & aApplicationDescription);
00087     NS_IMETHOD SetApplicationDescription(const nsAString & aApplicationDescription);
00088     NS_IMETHOD GetDefaultDescription(nsAString & aDefaultDescription);
00089     NS_IMETHOD LaunchWithFile(nsIFile *aFile);
00090     NS_IMETHOD GetPreferredAction(nsMIMEInfoHandleAction *aPreferredAction);
00091     NS_IMETHOD SetPreferredAction(nsMIMEInfoHandleAction aPreferredAction);
00092     NS_IMETHOD GetAlwaysAskBeforeHandling(PRBool *aAlwaysAskBeforeHandling);
00093     NS_IMETHOD SetAlwaysAskBeforeHandling(PRBool aAlwaysAskBeforeHandling); 
00094 
00095     // nsMIMEInfoBase methods
00096     nsMIMEInfoBase(const char *aMIMEType = "") NS_HIDDEN;
00097     nsMIMEInfoBase(const nsACString& aMIMEType) NS_HIDDEN;
00098     virtual ~nsMIMEInfoBase();        // must be virtual, as the the base class's Release should call the subclass's destructor
00099 
00100     void SetMIMEType(const nsACString & aMIMEType) { mMIMEType = aMIMEType; }
00101 
00102     void SetDefaultDescription(const nsString& aDesc) { mDefaultAppDescription = aDesc; }
00103 
00112     void CopyBasicDataTo(nsMIMEInfoBase* aOther);
00113 
00117     PRBool HasExtensions() const { return mExtensions.Count() != 0; }
00118 
00119   protected:
00127     virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile) = 0;
00128 
00139     static NS_HIDDEN_(nsresult) LaunchWithIProcess(nsIFile* aApp, nsIFile* aFile);
00140 
00141     // member variables
00142     nsCStringArray         mExtensions; 
00143     nsString               mDescription; 
00144     PRUint32               mMacType, mMacCreator; 
00145     nsCString              mMIMEType;
00146     nsCOMPtr<nsIFile>      mPreferredApplication; 
00147     nsMIMEInfoHandleAction mPreferredAction; 
00148     nsString               mPreferredAppDescription;
00149     nsString               mDefaultAppDescription;
00150     PRBool                 mAlwaysAskBeforeHandling;
00151 };
00152 
00153 
00161 class nsMIMEInfoImpl : public nsMIMEInfoBase {
00162   public:
00163     nsMIMEInfoImpl(const char *aMIMEType = "") : nsMIMEInfoBase(aMIMEType) {}
00164     nsMIMEInfoImpl(const nsACString& aMIMEType) : nsMIMEInfoBase(aMIMEType) {}
00165     virtual ~nsMIMEInfoImpl() {}
00166 
00167     // nsIMIMEInfo methods
00168     NS_IMETHOD GetHasDefaultHandler(PRBool *_retval);
00169     NS_IMETHOD GetDefaultDescription(nsAString& aDefaultDescription);
00170 
00171     // additional methods
00176     void SetDefaultApplication(nsIFile* aApp) { if (!mDefaultApplication) mDefaultApplication = aApp; }
00177   protected:
00178     // nsMIMEInfoBase methods
00183     virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile);
00184 
00185 
00186     nsCOMPtr<nsIFile>      mDefaultApplication; 
00187 };
00188 
00189 #endif //__nsmimeinfoimpl_h___