Back to index

lightning-sunbird  0.9+nobinonly
nsMIMEInfoWin.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
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 the Mozilla browser.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications, Inc.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Scott MacGregor <mscott@netscape.com>
00025  *   Christian Biesinger <cbiesinger@web.de>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #include "nsArrayEnumerator.h"
00042 #include "nsCOMArray.h"
00043 #include "nsILocalFile.h"
00044 #include "nsIVariant.h"
00045 #include "nsMIMEInfoWin.h"
00046 #include "nsNetUtil.h"
00047 
00048 NS_IMPL_ISUPPORTS_INHERITED1(nsMIMEInfoWin, nsMIMEInfoBase, nsIPropertyBag)
00049 
00050 nsMIMEInfoWin::~nsMIMEInfoWin()
00051 {
00052 }
00053 
00054 nsresult
00055 nsMIMEInfoWin::LaunchDefaultWithFile(nsIFile* aFile)
00056 {
00057   // Launch the file, unless it is an executable.
00058   nsCOMPtr<nsILocalFile> local(do_QueryInterface(aFile));
00059   if (!local)
00060     return NS_ERROR_FAILURE;
00061 
00062   PRBool executable = PR_TRUE;
00063   local->IsExecutable(&executable);
00064   if (executable)
00065     return NS_ERROR_FAILURE;
00066 
00067   return local->Launch();
00068 }
00069 
00070 NS_IMETHODIMP
00071 nsMIMEInfoWin::GetHasDefaultHandler(PRBool * _retval)
00072 {
00073   // We have a default application if we have a description
00074   // We can ShellExecute anything; however, callers are probably interested if
00075   // there is really an application associated with this type of file
00076   *_retval = !mDefaultAppDescription.IsEmpty();
00077   return NS_OK;
00078 }
00079 
00080 NS_IMETHODIMP
00081 nsMIMEInfoWin::GetEnumerator(nsISimpleEnumerator* *_retval)
00082 {
00083   nsCOMArray<nsIVariant> properties;
00084 
00085   nsCOMPtr<nsIVariant> variant;
00086   GetProperty(NS_LITERAL_STRING("defaultApplicationIconURL"), getter_AddRefs(variant));
00087   if (variant)
00088     properties.AppendObject(variant);
00089 
00090   GetProperty(NS_LITERAL_STRING("customApplicationIconURL"), getter_AddRefs(variant));
00091   if (variant)
00092     properties.AppendObject(variant);
00093 
00094   return NS_NewArrayEnumerator(_retval, properties);
00095 }
00096 
00097 static nsresult GetIconURLVariant(nsIFile* aApplication, nsIVariant* *_retval)
00098 {
00099   nsresult rv = CallCreateInstance("@mozilla.org/variant;1", _retval);
00100   if (NS_FAILED(rv))
00101     return rv;
00102   nsCAutoString fileURLSpec;
00103   NS_GetURLSpecFromFile(aApplication, fileURLSpec);
00104   nsCAutoString iconURLSpec; iconURLSpec.AssignLiteral("moz-icon://");
00105   iconURLSpec += fileURLSpec;
00106   nsCOMPtr<nsIWritableVariant> writable(do_QueryInterface(*_retval));
00107   writable->SetAsAUTF8String(iconURLSpec);
00108   return NS_OK;
00109 }
00110 
00111 NS_IMETHODIMP
00112 nsMIMEInfoWin::GetProperty(const nsAString& aName, nsIVariant* *_retval)
00113 {
00114   nsresult rv = NS_ERROR_FAILURE;
00115   if (mDefaultApplication && aName.EqualsLiteral(PROPERTY_DEFAULT_APP_ICON_URL))
00116     rv = GetIconURLVariant(mDefaultApplication, _retval);
00117   else if (mPreferredApplication && aName.EqualsLiteral(PROPERTY_CUSTOM_APP_ICON_URL))
00118     rv = GetIconURLVariant(mPreferredApplication, _retval);
00119   return rv;
00120 }
00121