Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 147382 Details for
Bug 227374
Cannot easily select alternative helper applications
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
Patch allowing firefox to list all registerd apps for a mime type
firefox-1.5.0.9-multiapps.patch (text/plain), 33.30 KB, created by
Philip Spencer
on 2007-02-05 18:05:25 UTC
(
hide
)
Description:
Patch allowing firefox to list all registerd apps for a mime type
Filename:
MIME Type:
Creator:
Philip Spencer
Created:
2007-02-05 18:05:25 UTC
Size:
33.30 KB
patch
obsolete
>diff -ur mozilla.orig/browser/components/preferences/changeaction.js mozilla/browser/components/preferences/changeaction.js >--- mozilla.orig/browser/components/preferences/changeaction.js 2005-07-16 10:34:10.000000000 -0400 >+++ mozilla/browser/components/preferences/changeaction.js 2007-02-02 18:34:22.000000000 -0500 >@@ -82,6 +82,28 @@ > defaultApp.image = defaultAppIcon || fallbackIconURL; > defaultApp.label = this._item.mimeInfo.defaultDescription; > >+ var numAltApps = this._item.mimeInfo.numberSystemAltApps; >+ var chosenApp = this._item.customHandler; >+ var systemApp = document.getElementById("systemApp"); >+ systemApp.selectedIndex = 0; >+ for (var i=0; i < numAltApps; i++) { >+ var desc = this._item.mimeInfo.getSystemAltAppDescription(i); >+ var altApp = this._item.mimeInfo.getSystemAltAppHandler(i); >+ var altElt = systemApp.insertItemAt(1+i, desc); >+ altElt.hidden = false; >+ if (chosenApp && chosenApp.path && chosenApp.path == >+ this._item.mimeInfo.getSystemAltAppHandler(i).path) >+ systemApp.selectedIndex = i+1; >+ } >+// The label we just set for the default app won't show up on the >+// main menulist if that is the one currently selected (it will >+// show up fine if we select an alternative app then reselect >+// the default one, but, we may not have any alternative apps!). So, we >+// use the same hack as in toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in >+// to get it to reinitialize properly. >+ systemApp.parentNode.removeChild(systemApp); >+ document.getElementById("systemAppBox").appendChild(systemApp); >+ > var pluginName = document.getElementById("pluginName"); > var foundPlugin = false; > for (var i = 0; i < navigator.plugins.length; ++i) { >@@ -144,6 +166,11 @@ > this._item.handleMode = FILEACTION_OPEN_DEFAULT; > var defaultDescr = this._item.mimeInfo.defaultDescription; > this._item.action = this._bundle.getFormattedString("openWith", [defaultDescr]); >+ var i = document.getElementById("systemApp").selectedIndex; >+ if (i > 0) >+ this._item.action = >+ this._bundle.getFormattedString("openWith", >+ [this._item.mimeInfo.getSystemAltAppDescription(i-1)]); > break; > case "app": > this._item.handledOnlyByPlugin = false; >@@ -165,7 +192,7 @@ > > doEnabling: function (aSelectedItem) > { >- var defaultApp = document.getElementById("defaultApp"); >+ var systemApp = document.getElementById("systemApp"); > var saveToDefault = document.getElementById("saveToDefault"); > var saveToCustom = document.getElementById("saveToCustom"); > var customDownloadFolder = document.getElementById("customDownloadFolder"); >@@ -178,10 +205,10 @@ > switch (aSelectedItem.id) { > case "openDefault": > changeApp.disabled = customApp.disabled = saveToDefault.disabled = saveToCustom.disabled = customDownloadFolder.disabled = chooseCustomDownloadFolder.disabled = saveToAskMe.disabled = pluginName.disabled = true; >- defaultApp.disabled = false; >+ systemApp.disabled = false; > break; > case "openApplication": >- defaultApp.disabled = saveToDefault.disabled = saveToCustom.disabled = customDownloadFolder.disabled = chooseCustomDownloadFolder.disabled = saveToAskMe.disabled = pluginName.disabled = true; >+ systemApp.disabled = saveToDefault.disabled = saveToCustom.disabled = customDownloadFolder.disabled = chooseCustomDownloadFolder.disabled = saveToAskMe.disabled = pluginName.disabled = true; > changeApp.disabled = customApp.disabled = false; > if (!customApp.file && !this.changeApp()) { > this._lastSelectedMode.click(); >@@ -189,13 +216,13 @@ > } > break; > case "saveToDisk": >- changeApp.disabled = customApp.disabled = defaultApp.disabled = pluginName.disabled = true; >+ changeApp.disabled = customApp.disabled = systemApp.disabled = pluginName.disabled = true; > var saveToOptions = document.getElementById("saveToOptions"); > customDownloadFolder.disabled = chooseCustomDownloadFolder.disabled = !(saveToOptions.selectedItem.id == "saveToCustom"); > saveToDefault.disabled = saveToCustom.disabled = saveToAskMe.disabled = false; > break; > case "plugin": >- changeApp.disabled = customApp.disabled = defaultApp.disabled = saveToDefault.disabled = saveToCustom.disabled = customDownloadFolder.disabled = chooseCustomDownloadFolder.disabled = saveToAskMe.disabled = true; >+ changeApp.disabled = customApp.disabled = systemApp.disabled = saveToDefault.disabled = saveToCustom.disabled = customDownloadFolder.disabled = chooseCustomDownloadFolder.disabled = saveToAskMe.disabled = true; > pluginName.disabled = false; > break; > } >@@ -250,5 +277,19 @@ > return true; > } > return false; >+ }, >+ >+ changeSystemApp: function () >+ { >+ var systemApp = document.getElementById("systemApp"); >+ var i = systemApp.selectedIndex; >+ if (i > 0) { >+ this._item.customHandler = >+ this._item.mimeInfo.getSystemAltAppHandler(i-1); >+ } else { >+ this._item.customHandler = null; >+ } >+ var handlerGroup = document.getElementById("handlerGroup"); >+ handlerGroup.selectedItem = document.getElementById("openDefault"); > } > }; >diff -ur mozilla.orig/browser/components/preferences/changeaction.xul mozilla/browser/components/preferences/changeaction.xul >--- mozilla.orig/browser/components/preferences/changeaction.xul 2005-08-11 21:10:39.000000000 -0400 >+++ mozilla/browser/components/preferences/changeaction.xul 2007-02-02 18:13:13.000000000 -0500 >@@ -75,7 +75,13 @@ > <separator class="thin"/> > <radio id="openDefault" value="system" > label="&openDefault.label;" accesskey="&openDefault.accesskey;"/> >- <filefield class="indent" id="defaultApp" disabled="true"/> >+ <hbox id="systemAppBox" flex="1"> >+ <menulist id="systemApp" flex="1"> >+ <menupopup id="systemAppPopup" oncommand="gChangeActionDialog.changeSystemApp();"> >+ <menuitem id="defaultApp" default="true" crop="right"/> >+ </menupopup> >+ </menulist> >+ </hbox> > <separator class="thin"/> > <radio id="openApplication" value="app" > label="&openApplication.label;" accesskey="&openApplication.accesskey;"/> >diff -ur mozilla.orig/browser/components/preferences/downloadactions.js mozilla/browser/components/preferences/downloadactions.js >--- mozilla.orig/browser/components/preferences/downloadactions.js 2005-09-27 08:15:45.000000000 -0400 >+++ mozilla/browser/components/preferences/downloadactions.js 2007-02-02 17:11:50.000000000 -0500 >@@ -345,10 +345,16 @@ > handleMode = FILEACTION_SAVE_TO_DISK; > } > else if (useSystemDefault) { >- // Use the System Default handler >+ // Use the System Default handler, or a system Alternate > actionName = this._bundle.getFormattedString("openWith", > [typeInfo.defaultDescription]); > handleMode = FILEACTION_OPEN_DEFAULT; >+ for (var i=0; i < typeInfo.numberSystemAltApps; i++) { >+ if (customHandler && customHandler.path && >+ customHandler.path == typeInfo.getSystemAltAppHandler(i).path) >+ actionName = this._bundle.getFormattedString("openWith", >+ [typeInfo.getSystemAltAppDescription(i)]); >+ } > } > else { > // Custom Handler >@@ -638,6 +644,13 @@ > var handlerRes = this._ensureMIMERegistryEntry(item); > this._setLiteralValue(handlerRes, "useSystemDefault", "true"); > this._setLiteralValue(handlerRes, "saveToDisk", "false"); >+ var extAppRes = this._getChildResource(handlerRes, "externalApplication"); >+ >+ if (item.customHandler) { >+ this._setLiteralValue(extAppRes, "path", item.customHandler.path); >+ } else { >+ this._setLiteralValue(extAppRes, "path", ""); >+ } > break; > case FILEACTION_OPEN_CUSTOM: > this._disablePluginForItem(item); >diff -ur mozilla.orig/browser/locales/en-US/chrome/browser/preferences/changeaction.dtd mozilla/browser/locales/en-US/chrome/browser/preferences/changeaction.dtd >--- mozilla.orig/browser/locales/en-US/chrome/browser/preferences/changeaction.dtd 2005-04-20 07:24:46.000000000 -0400 >+++ mozilla/browser/locales/en-US/chrome/browser/preferences/changeaction.dtd 2007-02-02 18:34:01.000000000 -0500 >@@ -3,7 +3,7 @@ > > <!ENTITY whenDownloading.label "When downloading files like this:"> > >-<!ENTITY openDefault.label "Open them with the default application:"> >+<!ENTITY openDefault.label "Open them with a standard application:"> > <!ENTITY openDefault.accesskey "O"> > <!ENTITY openApplication.label "Open them with this application:"> > <!ENTITY openApplication.accesskey "e"> >diff -ur mozilla.orig/netwerk/mime/public/nsIMIMEInfo.idl mozilla/netwerk/mime/public/nsIMIMEInfo.idl >--- mozilla.orig/netwerk/mime/public/nsIMIMEInfo.idl 2005-04-03 13:25:14.000000000 -0400 >+++ mozilla/netwerk/mime/public/nsIMIMEInfo.idl 2007-02-01 12:59:13.000000000 -0500 >@@ -174,5 +174,32 @@ > * dialog asking how to dispose of this content. > */ > attribute boolean alwaysAskBeforeHandling; >+ >+ /** >+ * numberSystemAltApps: if nonzero, indicates that, in addition >+ * to the "system default" handler, there are alternative >+ * applications registered with the system for this MIME type, >+ * and the user should have the option of selecting one of them >+ * as well as manually browsing for an application. >+ >+ * When numberSystemAltApps is nonzero, the meaning of >+ * preferredAction=useSystemDefault is changed from >+ * "use the system default application" to "check the list >+ * of alternative applications to see if preferredApplicationHandler >+ * matches any of them. If so, use that application; if not, >+ * use the default application." >+ >+ */ >+ readonly attribute PRUint32 numberSystemAltApps; >+ >+ /** >+ * getSystemAltAppDescription, getSystemAltAppHandler: fetch the >+ * description and handler application for the indicated alternative >+ * application. The parameter aWhichAltApp can range from 0 through >+ * numberSystemAltApps-1. These methods can only be called if >+ * numberSystemAltApps is nonzero. >+ */ >+ AString getSystemAltAppDescription(in PRUint32 aWhichAltApp); >+ nsIFile getSystemAltAppHandler(in PRUint32 aWhichApp); > }; > >diff -ur mozilla.orig/toolkit/mozapps/downloads/content/helperApps.js mozilla/toolkit/mozapps/downloads/content/helperApps.js >--- mozilla.orig/toolkit/mozapps/downloads/content/helperApps.js 2005-02-01 12:07:15.000000000 -0500 >+++ mozilla/toolkit/mozapps/downloads/content/helperApps.js 2007-02-02 15:42:05.000000000 -0500 >@@ -157,9 +158,17 @@ > else if (aMIMEInfo.preferredAction == nsIMIMEInfo.useSystemDefault || > aMIMEInfo.preferredApplicationHandler == null) { > entry.useSystemDefault = true; >- if (!isNewMIMEType) { >- // Creating a new entry, set path. >- entry.appPath = ""; >+// set appPath and appDisplayName in the useSystemDefault case just as >+// we do below for the user-selected application case, since we want to >+// allow the user to have selected between multiple system-provided >+// applications. >+ if (aMIMEInfo.preferredApplicationHandler != null) { >+ entry.appPath = aMIMEInfo.preferredApplicationHandler.path; >+ entry.appDisplayName = aMIMEInfo.applicationDescription; >+ } else { >+ entry.appDisplayName = >+ "Default Application (" + aMIMEInfo.defaultDescription + ")"; >+ entry.appPath = ""; > } > } > else { >diff -ur mozilla.orig/toolkit/mozapps/downloads/content/unknownContentType.xul mozilla/toolkit/mozapps/downloads/content/unknownContentType.xul >diff -ur mozilla.orig/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in mozilla/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in >--- mozilla.orig/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in 2006-04-21 18:17:28.000000000 -0400 >+++ mozilla/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in 2007-02-01 14:54:26.000000000 -0500 >@@ -64,6 +64,12 @@ > this.givenDefaultApp = false; > this.updateSelf = true; > this.mTitle = ""; >+// number of alternative system applications >+ this.numAltApps = 0; >+// which system application is selected in the MIMEInfo object >+// (0 if the default is selected, positive integer i if alternative >+// application i-1 is selected) >+ this.origWhichSystemApp = 0; > } > > nsUnknownContentTypeDialog.prototype = { >@@ -626,26 +632,47 @@ > // Initialize "default application" field. > this.initDefaultApp(); > >+ var openHandler = this.dialogElement("openHandler"); >+ var sel = 0; >+ this.numAltApps = this.mLauncher.MIMEInfo.numberSystemAltApps; >+ for (var i=0; i < this.numAltApps; i++) { >+ var desc = this.mLauncher.MIMEInfo.getSystemAltAppDescription(i); >+ var altApp = this.mLauncher.MIMEInfo.getSystemAltAppHandler(i); >+ var altElt = openHandler.insertItemAt(1+i, desc); >+ altElt.setAttribute("path", this.getPath(altApp)); >+ altElt.hidden = false; >+ if (this.chosenApp && this.chosenApp.path && >+ this.getPath(this.chosenApp) == this.getPath(altApp)) { >+ this.origWhichSystemApp = i+1; >+ sel = i+1; >+ this.mLauncher.MIMEInfo.preferredAction = >+ this.nsIMIMEInfo.useSystemDefault; >+ } >+ } >+ openHandler.selectedIndex = 0; >+ > var otherHandler = this.dialogElement("otherHandler"); > > // Fill application name textbox. >- if (this.chosenApp && this.chosenApp.path) { >+ if (this.mLauncher.MIMEInfo.preferredAction != >+ this.nsIMIMEInfo.useSystemDefault && >+ this.chosenApp && this.chosenApp.path) { > otherHandler.setAttribute("path", this.getPath(this.chosenApp)); > otherHandler.label = this.chosenApp.leafName; > otherHandler.hidden = false; > } > > var useDefault = this.dialogElement("useSystemDefault"); >- var openHandler = this.dialogElement("openHandler"); >- openHandler.selectedIndex = 0; > > if (this.mLauncher.MIMEInfo.preferredAction == this.nsIMIMEInfo.useSystemDefault) { > // Open (using system default). > modeGroup.selectedItem = this.dialogElement("open"); >+ openHandler.selectedIndex = sel; > } else if (this.mLauncher.MIMEInfo.preferredAction == this.nsIMIMEInfo.useHelperApp) { > // Open with given helper app. > modeGroup.selectedItem = this.dialogElement("open"); >- openHandler.selectedIndex = 1; >+ openHandler.selectedIndex = this.numAltApps+1; >+ otherHandler.hidden = false; > } else { > // Save to disk. > modeGroup.selectedItem = this.dialogElement("save"); >@@ -660,7 +687,7 @@ > useDefault.hidden = true; > // If that's the default, then switch to "save to disk." > if (isSelected) { >- openHandler.selectedIndex = 1; >+ openHandler.selectedIndex = this.numAltApps+1; > modeGroup.selectedItem = this.dialogElement("save"); > } > } >@@ -685,11 +712,15 @@ > }, > > get useOtherHandler() { >- return this.dialogElement("open").selected && this.dialogElement("openHandler").selectedIndex == 1; >+ return this.dialogElement("open").selected && this.dialogElement("openHandler").selectedIndex == this.numAltApps+1; > }, > > get useSystemDefault() { >- return this.dialogElement("open").selected && this.dialogElement("openHandler").selectedIndex == 0; >+ return this.dialogElement("open").selected && this.dialogElement("openHandler").selectedIndex <= this.numAltApps; >+ }, >+ >+ get whichSystemApp() { >+ return this.dialogElement("openHandler").selectedIndex; > }, > > toggleRememberChoice: function (aCheckbox) { >@@ -712,16 +743,13 @@ > ok = true; > } > else if (this.dialogElement("open").selected) { >- switch (this.dialogElement("openHandler").selectedIndex) { >- case 0: >- // No app need be specified in this case. >- ok = true; >- break; >- case 1: >+ if (this.dialogElement("openHandler").selectedIndex <= this.numAltApps) >+ ok = true; >+ if (this.dialogElement("openHandler").selectedIndex == >+ this.numAltApps + 1) { > // only enable the OK button if we have a default app to use or if > // the user chose an app.... > ok = this.chosenApp || /\S/.test(this.dialogElement("otherHandler").getAttribute("path")); >- break; > } > } > >@@ -747,6 +775,20 @@ > needUpdate = this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.useSystemDefault; > if (needUpdate) > this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.useSystemDefault; >+ if (this.whichSystemApp != this.origWhichSystemApp) { >+ needUpdate = 1; >+ this.origWhichSystemApp = this.whichSystemApp; >+ if (this.whichSystemApp > 0) { >+ this.mLauncher.MIMEInfo.applicationDescription = >+ this.mLauncher.MIMEInfo.getSystemAltAppDescription ( >+ this.whichSystemApp - 1); >+ this.mLauncher.MIMEInfo.preferredApplicationHandler = >+ this.mLauncher.MIMEInfo.getSystemAltAppHandler ( >+ this.whichSystemApp - 1); >+ } else >+ this.mLauncher.MIMEInfo.preferredApplicationHandler = null; >+ >+ } > } > else { > // For "open with", we need to check both preferred action and whether the user chose >@@ -905,7 +947,7 @@ > otherHandler.removeAttribute("hidden"); > otherHandler.setAttribute("path", this.getPath(this.chosenApp)); > otherHandler.label = this.chosenApp.leafName; >- this.dialogElement("openHandler").selectedIndex = 1; >+ this.dialogElement("openHandler").selectedIndex = this.numAltApps+1; > this.dialogElement("openHandler").setAttribute("lastSelectedItemID", "otherHandler"); > > this.dialogElement("mode").selectedItem = this.dialogElement("open"); >diff -ur mozilla.orig/uriloader/exthandler/nsMIMEInfoImpl.cpp mozilla/uriloader/exthandler/nsMIMEInfoImpl.cpp >--- mozilla.orig/uriloader/exthandler/nsMIMEInfoImpl.cpp 2005-02-25 04:02:14.000000000 -0500 >+++ mozilla/uriloader/exthandler/nsMIMEInfoImpl.cpp 2007-02-01 13:02:05.000000000 -0500 >@@ -285,6 +285,39 @@ > return NS_OK; > } > >+/* Base method for retrieving numberSystemAltApps: returns 0 (alternative >+ applications not supported). >+ Overridden in the nsMIMEInfoUnix class. >+*/ >+ >+NS_IMETHODIMP >+nsMIMEInfoBase::GetNumberSystemAltApps(PRUint32 * aNumAltApps) >+{ >+ *aNumAltApps = 0; >+ return NS_OK; >+} >+ >+/* Base method for fetching alternative application description/handlers: >+ Generate NS_ERROR_INVALID_ARG error. These methods cannot be called >+ when numberSystemAltApps is zero. >+ Overridden in the nsMIMEInfoUnix class where numberSystemAltApps can >+ be nonzero. >+*/ >+ >+NS_IMETHODIMP >+nsMIMEInfoBase::GetSystemAltAppDescription(const PRUint32 aWhichAltApp, >+ nsAString &aResult) >+{ >+ return NS_ERROR_INVALID_ARG; >+} >+ >+NS_IMETHODIMP >+nsMIMEInfoBase::GetSystemAltAppHandler(const PRUint32 aWhichAltApp, >+ nsIFile **aResult) >+{ >+ return NS_ERROR_INVALID_ARG; >+} >+ > NS_IMETHODIMP > nsMIMEInfoBase::LaunchWithFile(nsIFile* aFile) > { >diff -ur mozilla.orig/uriloader/exthandler/nsMIMEInfoImpl.h mozilla/uriloader/exthandler/nsMIMEInfoImpl.h >--- mozilla.orig/uriloader/exthandler/nsMIMEInfoImpl.h 2005-02-25 04:02:14.000000000 -0500 >+++ mozilla/uriloader/exthandler/nsMIMEInfoImpl.h 2007-02-01 12:59:59.000000000 -0500 >@@ -91,6 +91,11 @@ > NS_IMETHOD SetPreferredAction(nsMIMEInfoHandleAction aPreferredAction); > NS_IMETHOD GetAlwaysAskBeforeHandling(PRBool *aAlwaysAskBeforeHandling); > NS_IMETHOD SetAlwaysAskBeforeHandling(PRBool aAlwaysAskBeforeHandling); >+ NS_IMETHOD GetNumberSystemAltApps(PRUint32 *aNumberSystemAltApps); >+ NS_IMETHOD GetSystemAltAppDescription(PRUint32 aWhichAltApp, >+ nsAString &_retval); >+ NS_IMETHOD GetSystemAltAppHandler(PRUint32 aWhichAltApp, >+ nsIFile **_retval); > > // nsMIMEInfoBase methods > nsMIMEInfoBase(const char *aMIMEType = "") NS_HIDDEN; >diff -ur mozilla.orig/uriloader/exthandler/unix/nsGNOMERegistry.cpp mozilla/uriloader/exthandler/unix/nsGNOMERegistry.cpp >--- mozilla.orig/uriloader/exthandler/unix/nsGNOMERegistry.cpp 2007-01-24 14:29:00.000000000 -0500 >+++ mozilla/uriloader/exthandler/unix/nsGNOMERegistry.cpp 2007-02-02 15:43:50.000000000 -0500 >@@ -72,9 +72,11 @@ > typedef const char * (*_gnome_vfs_mime_type_from_name_fn)(const char *); > typedef GList * (*_gnome_vfs_mime_get_extensions_list_fn)(const char *); > typedef void (*_gnome_vfs_mime_extensions_list_free_fn)(GList *); >+typedef void (*_gnome_vfs_mime_application_list_free_fn)(GList *); > typedef const char * (*_gnome_vfs_mime_get_description_fn)(const char *); > typedef GnomeVFSMimeApplication * (*_gnome_vfs_mime_get_default_application_fn) > (const char *); >+typedef GList * (*_gnome_vfs_mime_get_all_applications_fn) (const char *); > typedef void (*_gnome_vfs_mime_application_free_fn)(GnomeVFSMimeApplication *); > typedef GnomeProgram * (*_gnome_program_init_fn)(const char *, const char *, > const GnomeModuleInfo *, int, >@@ -91,8 +93,10 @@ > DECL_FUNC_PTR(gnome_vfs_mime_type_from_name); > DECL_FUNC_PTR(gnome_vfs_mime_get_extensions_list); > DECL_FUNC_PTR(gnome_vfs_mime_extensions_list_free); >+DECL_FUNC_PTR(gnome_vfs_mime_application_list_free); > DECL_FUNC_PTR(gnome_vfs_mime_get_description); > DECL_FUNC_PTR(gnome_vfs_mime_get_default_application); >+DECL_FUNC_PTR(gnome_vfs_mime_get_all_applications); > DECL_FUNC_PTR(gnome_vfs_mime_application_free); > DECL_FUNC_PTR(gnome_program_init); > DECL_FUNC_PTR(libgnome_module_info_get); >@@ -166,8 +170,10 @@ > GET_LIB_FUNCTION(vfs, gnome_vfs_mime_type_from_name); > GET_LIB_FUNCTION(vfs, gnome_vfs_mime_get_extensions_list); > GET_LIB_FUNCTION(vfs, gnome_vfs_mime_extensions_list_free); >+ GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_list_free); > GET_LIB_FUNCTION(vfs, gnome_vfs_mime_get_description); > GET_LIB_FUNCTION(vfs, gnome_vfs_mime_get_default_application); >+ GET_LIB_FUNCTION(vfs, gnome_vfs_mime_get_all_applications); > GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_free); > > // Initialize GNOME, if it's not already initialized. It's not >@@ -296,12 +302,16 @@ > if (!handlerApp) > return nsnull; > >+ GList *allApps = _gnome_vfs_mime_get_all_applications(aMIMEType); >+ > nsRefPtr<nsMIMEInfoUnix> mimeInfo = new nsMIMEInfoUnix(aMIMEType); > NS_ENSURE_TRUE(mimeInfo, nsnull); > >- mimeInfo->SetDefaultGnomeVFSMimeApplication(handlerApp); >+ mimeInfo->SetDefaultGnomeVFSMimeApplications(handlerApp, allApps); > > // Get the list of extensions and append then to the mimeInfo. >+ // Note: this does nothing, as in current GNOME versions >+ // gnome_vfs_mime_get_extenions_list always returns an empty list > GList *extensions = _gnome_vfs_mime_get_extensions_list(aMIMEType); > for (GList *extension = extensions; extension; extension = extension->next) > mimeInfo->AppendExtension(nsDependentCString((const char *) extension->data)); >@@ -319,6 +329,7 @@ > if (!nativeCommand) { > NS_ERROR("Could not convert helper app command to filesystem encoding"); > _gnome_vfs_mime_application_free(handlerApp); >+ if (allApps) _gnome_vfs_mime_application_list_free(allApps); > return nsnull; > } > >@@ -327,6 +338,7 @@ > if (!res) { > NS_ERROR("Could not convert helper app command to filesystem encoding"); > _gnome_vfs_mime_application_free(handlerApp); >+ if (allApps) _gnome_vfs_mime_application_list_free(allApps); > return nsnull; > } > >@@ -338,6 +350,7 @@ > if (!commandPath) { > NS_WARNING("could not find command in path"); > _gnome_vfs_mime_application_free(handlerApp); >+ if (allApps) _gnome_vfs_mime_application_list_free(allApps); > return nsnull; > } > >@@ -353,6 +366,7 @@ > g_free(commandPath); > > _gnome_vfs_mime_application_free(handlerApp); >+ _gnome_vfs_mime_application_list_free(allApps); > > nsMIMEInfoUnix* retval; > NS_ADDREF((retval = mimeInfo)); >diff -ur mozilla.orig/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp mozilla/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp >--- mozilla.orig/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp 2007-01-24 14:29:00.000000000 -0500 >+++ mozilla/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp 2007-02-01 14:11:20.000000000 -0500 >@@ -24,6 +24,7 @@ > * > * ***** END LICENSE BLOCK ***** */ > >+#include "nsILocalFile.h" > #include "nsMIMEInfoUnix.h" > #include "prlink.h" > #include "prmem.h" >@@ -40,10 +41,18 @@ > GNOME_VFS_OK // there's more but we don't care about them. > } GnomeVFSResult; > >+struct GnomeVFSMimeApplication { >+ char *id; >+ char *name; >+ char *command; >+ /* there is more here, but we don't need it */ >+}; >+ > typedef GnomeVFSResult (*_gnome_vfs_mime_application_launch_fn) > (GnomeVFSMimeApplication *app, > GList *uris); > typedef void (*_gnome_vfs_mime_application_free_fn)(GnomeVFSMimeApplication *); >+typedef void (*_gnome_vfs_mime_application_list_free_fn)(GList *); > typedef GnomeVFSMimeApplication * (*_gnome_vfs_mime_application_copy_fn)(GnomeVFSMimeApplication *); > typedef GnomeProgram * (*_gnome_program_init_fn)(const char *, const char *, > const GnomeModuleInfo *, int, >@@ -57,6 +66,7 @@ > > DECL_FUNC_PTR(gnome_vfs_mime_application_launch); > DECL_FUNC_PTR(gnome_vfs_mime_application_free); >+DECL_FUNC_PTR(gnome_vfs_mime_application_list_free); > DECL_FUNC_PTR(gnome_vfs_mime_application_copy); > DECL_FUNC_PTR(gnome_vfs_mime_application_get_name); > DECL_FUNC_PTR(gnome_program_init); >@@ -126,6 +136,7 @@ > GET_LIB_FUNCTION(vfs, gnome_vfs_make_uri_from_input, return Cleanup()); > GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_get_name, return Cleanup()); > GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_free, return Cleanup()); >+ GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_list_free, return Cleanup()); > GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_copy, return Cleanup()); > > // Initialize GNOME, if it's not already initialized. It's not >@@ -143,23 +154,48 @@ > } > > void >-nsMIMEInfoUnix::SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication* app) >+nsMIMEInfoUnix::SetDefaultGnomeVFSMimeApplications(GnomeVFSMimeApplication* app, >+ GList *apps) > { >- if (_gnome_vfs_mime_application_copy && _gnome_vfs_mime_application_free) { >- mDefaultVFSApplication = _gnome_vfs_mime_application_copy(app); >+ InitGnomeVFS(); >+ if (_gnome_vfs_mime_application_copy && _gnome_vfs_mime_application_free) { >+ >+/* Create a GList. Put a copy of the system default application into it as >+ the first element. >+ Then go through the list of all registered applications. Skip the one that's >+ the same as the default; otherwise, push a copy of it onto the GList. >+*/ >+ mDefaultVFSApplications = NULL; >+ GnomeVFSMimeApplication* defapp = _gnome_vfs_mime_application_copy(app); >+ mDefaultVFSApplications = g_list_append(mDefaultVFSApplications, defapp); > > mPreferredAction = nsIMIMEInfo::useSystemDefault; > >- const gchar * name = _gnome_vfs_mime_application_get_name(mDefaultVFSApplication); >+ const gchar * name = _gnome_vfs_mime_application_get_name(defapp); > if (name) >- mDefaultAppDescription = NS_ConvertUTF8toUCS2(name); >+ SetDefaultDescription(NS_ConvertUTF8toUCS2(name)); >+ >+ nsCAutoString defcmd; >+ defcmd.Assign(nsDependentCString(defapp->command)); >+ >+ GList *nextAppElt = apps; >+ >+ while (nextAppElt) { >+ GnomeVFSMimeApplication *nextApp = >+ (GnomeVFSMimeApplication *) (nextAppElt->data); >+ if (nextApp && nextApp->command && >+ ! defcmd.Equals(nsDependentCString(nextApp->command))) >+ mDefaultVFSApplications = g_list_append(mDefaultVFSApplications, >+ _gnome_vfs_mime_application_copy(nextApp)); >+ nextAppElt = g_list_next(nextAppElt); >+ } > } > } > > nsMIMEInfoUnix::~nsMIMEInfoUnix() > { >- if (mDefaultVFSApplication) >- _gnome_vfs_mime_application_free(mDefaultVFSApplication); >+ if (mDefaultVFSApplications) >+ _gnome_vfs_mime_application_list_free(mDefaultVFSApplications); > } > > nsresult >@@ -169,7 +205,27 @@ > > InitGnomeVFS(); > >- if (_gnome_vfs_mime_application_launch && mDefaultVFSApplication) { >+ if (_gnome_vfs_mime_application_launch && mDefaultVFSApplications) { >+ >+/* Search the list of alternative applications to see if any matches >+ what is stored in mPreferredApplication. If so, use it; if not, >+ use the default. */ >+ >+ GList *apps = mDefaultVFSApplications; >+ if (mPreferredApplication) { >+ PRUint32 i; >+ nsCAutoString nativePath; >+ mPreferredApplication->GetNativePath(nativePath); >+ for (i=0; i+1 < g_list_length(mDefaultVFSApplications); i++) { >+ gchar *cmd; >+ PRBool alloced = getSystemAltAppPath(i,&cmd); >+ if (nativePath.Equals(nsDependentCString(cmd))) >+ apps = g_list_nth(mDefaultVFSApplications, i+1); >+ if (alloced) g_free(cmd); >+ } >+ } >+ GnomeVFSMimeApplication *app = (GnomeVFSMimeApplication *) (apps->data); >+ > nsCAutoString nativePath; > aFile->GetNativePath(nativePath); > >@@ -178,7 +234,7 @@ > GList *uris = NULL; > uris = g_list_append(uris, uri); > >- GnomeVFSResult result = _gnome_vfs_mime_application_launch(mDefaultVFSApplication, uris); >+ GnomeVFSResult result = _gnome_vfs_mime_application_launch(app, uris); > > g_free(uri); > g_list_free(uris); >@@ -194,3 +250,81 @@ > > return LaunchWithIProcess(mDefaultApplication, aFile); > } >+ >+/* Method overrides for fetching numberSystemAltApps and for fetching >+ the alternative application handlers and descriptions. */ >+ >+nsresult nsMIMEInfoUnix::GetNumberSystemAltApps(PRUint32 *aNumAltApps) >+{ >+ *aNumAltApps = 0; >+ if (mDefaultVFSApplications) >+ *aNumAltApps = g_list_length(mDefaultVFSApplications)-1; >+ return NS_OK; >+} >+ >+nsresult >+nsMIMEInfoUnix::GetSystemAltAppDescription(const PRUint32 aWhichAltApp, >+ nsAString &aResult) >+{ >+ if (mDefaultVFSApplications && >+ aWhichAltApp+1 < g_list_length(mDefaultVFSApplications)) { >+ GList *apps = g_list_nth(mDefaultVFSApplications, aWhichAltApp+1); >+ GnomeVFSMimeApplication *app = (GnomeVFSMimeApplication *) (apps->data); >+ aResult.Assign(NS_ConvertUTF8toUTF16(app->name)); >+ return NS_OK; >+ } >+ return NS_ERROR_INVALID_ARG; >+} >+ >+nsresult >+nsMIMEInfoUnix::GetSystemAltAppHandler(const PRUint32 aWhichAltApp, >+ nsIFile **aResult) >+{ >+ if (mDefaultVFSApplications && >+ aWhichAltApp+1 < g_list_length(mDefaultVFSApplications)) { >+ gchar *cmd; >+ PRBool alloced = getSystemAltAppPath(aWhichAltApp, &cmd); >+ nsCOMPtr<nsILocalFile> appFile; >+ nsresult rv = >+ NS_NewNativeLocalFile(nsDependentCString(cmd), PR_TRUE, >+ getter_AddRefs(appFile)); >+ *aResult = appFile; >+ NS_IF_ADDREF(*aResult); >+ if (alloced) g_free(cmd); >+ return rv; >+ } >+ >+ return NS_ERROR_INVALID_ARG; >+} >+ >+/* Fetch the path associated to one of the alternative applications. >+ Code more or less blindly copied from the corresponding code in >+ nsGNOMERegistry.cpp that prepares the argument for SetDefaultApplication. >+ >+ Returns PR_TRUE if the returned path needs to be g_free'd; PR_FALSE >+ otherwise. >+*/ >+ >+PRBool nsMIMEInfoUnix::getSystemAltAppPath(PRUint32 aWhichAltApp, gchar **rv) { >+ GList *apps = g_list_nth(mDefaultVFSApplications, aWhichAltApp+1); >+ GnomeVFSMimeApplication *app = (GnomeVFSMimeApplication *) (apps->data); >+ gchar *commandPath = NULL; >+ gchar *nativeCommand = g_filename_from_utf8(app->command, >+ -1, NULL, NULL, NULL); >+ if (nativeCommand) { >+ gchar **argv; >+ gboolean res = g_shell_parse_argv(nativeCommand, NULL, &argv, NULL); >+ if (res) { >+ commandPath = g_find_program_in_path(argv[0]); >+ g_strfreev(argv); >+ } >+ g_free(nativeCommand); >+ } >+ if (commandPath) { >+ *rv = commandPath; >+ return PR_TRUE; >+ } else { >+ *rv = app->command; >+ return PR_FALSE; >+ } >+} >diff -ur mozilla.orig/uriloader/exthandler/unix/nsMIMEInfoUnix.h mozilla/uriloader/exthandler/unix/nsMIMEInfoUnix.h >--- mozilla.orig/uriloader/exthandler/unix/nsMIMEInfoUnix.h 2007-01-24 14:29:00.000000000 -0500 >+++ mozilla/uriloader/exthandler/unix/nsMIMEInfoUnix.h 2007-02-01 13:59:06.000000000 -0500 >@@ -30,21 +30,39 @@ > #include "nsMIMEInfoImpl.h" > > struct GnomeVFSMimeApplication; >+typedef struct _GList GList; > > class nsMIMEInfoUnix : public nsMIMEInfoImpl > { > public: >- nsMIMEInfoUnix(const char* aType = "") : nsMIMEInfoImpl(aType), mDefaultVFSApplication(nsnull) {} >+ nsMIMEInfoUnix(const char* aType = "") : nsMIMEInfoImpl(aType), mDefaultVFSApplications(nsnull) {} > nsMIMEInfoUnix(const nsACString& aMIMEType) : nsMIMEInfoImpl(aMIMEType) {}; > > virtual ~nsMIMEInfoUnix(); > >- void SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication *app); >+ void SetDefaultGnomeVFSMimeApplications(GnomeVFSMimeApplication *app, >+ GList *apps); >+ >+/* override base methods */ >+ nsresult GetNumberSystemAltApps(PRUint32 *aNumAltApps); >+ nsresult GetSystemAltAppDescription(const PRUint32 aWhichAltApp, >+ nsAString &aResult); >+ nsresult GetSystemAltAppHandler(const PRUint32 aWhichAltApp, >+ nsIFile **aResult); >+ > > protected: > virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile); > >- GnomeVFSMimeApplication *mDefaultVFSApplication; >+/* Instead of a single mDefaultVFSApplication structure, we have a >+ GList of them. Element 0 is the system default application. Additional >+ elements, if any, are alternative applications. */ >+ GList *mDefaultVFSApplications; >+ >+/* utility method for fetching the application path associated to one >+ of the alternative applications */ >+ PRBool getSystemAltAppPath(PRUint32 aWhichAltApp, char **rv); >+ > }; > > #endif // nsMimeInfoUnix_h__
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 227374
: 147382