gecko-dev/suite/common/pref/pref-applications-edit.xul

475 lines
18 KiB
XML

<?xml version="1.0"?>
<!-- ***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is Mozilla Communicator client code, released
March 31, 1998.
The Initial Developer of the Original Code is
Netscape Communications Corporation.
Portions created by the Initial Developer are Copyright (C) 1998-1999
the Initial Developer. All Rights Reserved.
Contributor(s):
Ben Goodger <ben@netscape.com>, original implementor
Alternatively, the contents of this file may be used under the terms of
either of the GNU General Public License Version 2 or later (the "GPL"),
or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
***** END LICENSE BLOCK ***** -->
<?xml-stylesheet href="chrome://communicator/skin/"?>
<?xml-stylesheet href="chrome://communicator/skin/prefpanels.css" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://communicator/locale/pref/pref-applications-edit.dtd">
<dialog id="pickAppHandler"
style="width: 30em;"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="&editType.label;"
newtitle="&newType.label;"
onload="Startup();"
ondialogaccept="return onAccept();">
<stringbundle id="bundle_prefApplications"
src="chrome://communicator/locale/pref/pref-applications.properties"/>
<stringbundle id="bundle_Brand" src="chrome://branding/locale/brand.properties"/>
<script type="application/x-javascript" src="chrome://global/content/dialogOverlay.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/pref/overrideHandler.js"/>
<script type="application/x-javascript">
<![CDATA[
var gExtension = null;
var gMIMEField = null;
var gHandlerGroup = null;
var gAppPath = null;
var gAskBeforeOpen = null;
var gDescription = null;
var gPrefApplicationsBundle = null;
var gOldMIME = null;
var gOldDesc = null;
var gOldExtensions = null;
const nsIMIMEInfo = Components.interfaces.nsIMIMEInfo;
function Startup()
{
gDescription = document.getElementById("description");
gExtension = document.getElementById("extension");
gMIMEField = document.getElementById("mimeType");
gHandlerGroup = document.getElementById("handler");
gAppPath = document.getElementById("appPath");
gAskBeforeOpen = document.getElementById("askBeforeOpen");
gPrefApplicationsBundle = document.getElementById("bundle_prefApplications");
// Set values for radio items to nsIMIMEInfo constants
var rSaveToDisk = document.getElementById("saveToDisk");
var rUseHelperApp = document.getElementById("useHelperApp");
var rUseSystemDefault = document.getElementById("useSystemDefault");
rSaveToDisk.value = nsIMIMEInfo.saveToDisk;
rUseHelperApp.value = nsIMIMEInfo.useHelperApp;
rUseSystemDefault.value = nsIMIMEInfo.useSystemDefault;
var handlerInfo = window.arguments[0];
// Test to see if this dialog is being called from the helper app dialog.
if ( !( "URI" in handlerInfo ) ) {
// Arg is an nsHelperAppDlg object in this case.
window.gHelperAppDlg = window.arguments[0];
var info = window.arguments[0].mLauncher.MIMEInfo;
// Update entry (without dialog showing).
try {
updateEntry(info);
} catch(e) { dump("updateEntry failed: " + e + "\n"); }
// Close the dialog.
window.close();
// Done.
return;
}
// Default to true in case the preference cannot be retrieved
var forceAlwaysAsk = true;
try {
var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var prefBranch = prefService.getBranch("browser.helperApps.alwaysAsk.");
forceAlwaysAsk = prefBranch.getBoolPref("force");
} catch(e) {
dump("forceAlwaysAsk defaulting to true since preference couldn't be opened\n");
}
if ( !handlerInfo.URI )
{
// Opening for "New Type".
document.title = document.documentElement.getAttribute("newtitle");
// Initialize some stuff to blank for new types.
gOldMIME = gOldDesc = gOldExtensions = "";
// Make default "use system default."
gHandlerGroup.value = nsIMIMEInfo.useSystemDefault;
// Always ask box default depends on pref.
gAskBeforeOpen.checked = forceAlwaysAsk;
gAskBeforeOpen.disabled = forceAlwaysAsk;
// Put focus on mime type field.
gMIMEField.focus();
// Size/position the dialog.
sizeToContent();
window.moveToAlertPosition();
// Avoid the normal "edit" case code.
return;
}
gExtension.setAttribute("value", handlerInfo.extensions);
gMIMEField.value = handlerInfo.mimeType;
gOldMIME = handlerInfo.mimeType;
gOldDesc = handlerInfo.description;
gOldExtensions = handlerInfo.extensions;
// figure out how this type is handled
var data = nsIMIMEInfo.saveToDisk;
if (handlerInfo.saveToDisk == "true")
data = nsIMIMEInfo.saveToDisk;
else if (handlerInfo.useSystemDefault == "true")
data = nsIMIMEInfo.useSystemDefault;
else
data = nsIMIMEInfo.useHelperApp;
gHandlerGroup.value = data;
doEnabling();
var appPath = handlerInfo.appPath;
if (appPath != undefined)
gAppPath.value = appPath;
if (forceAlwaysAsk)
{
gAskBeforeOpen.checked = true;
gAskBeforeOpen.disabled = true;
}
else
{
gAskBeforeOpen.checked = handlerInfo.alwaysAsk == "true" ? true : false;
}
gDescription.setAttribute("value", handlerInfo.description);
var ext;
var posOfFirstSpace = handlerInfo.extensions.indexOf(" ");
if (posOfFirstSpace > -1)
ext = handlerInfo.extensions.substr(0, posOfFirstSpace);
else
ext = handlerInfo.extensions;
var imageString = "moz-icon://" + "dummy." + ext.toLowerCase() + "?size=32&contentType=" + handlerInfo.mimeType;
document.getElementById("contentTypeImage").setAttribute("src", imageString);
// If opened from helper app dialog, then focus goes to radio buttons.
if ( "gHelperAppDlg" in window )
gHandlerGroup.focus();
else
gMIMEField.focus();
sizeToContent();
moveToAlertPosition();
}
function doEnabling()
{
}
function chooseApp()
{
var filePicker = Components.classes["@mozilla.org/filepicker;1"].createInstance();
if (filePicker)
filePicker = filePicker.QueryInterface(Components.interfaces.nsIFilePicker);
if (filePicker) {
const FP = Components.interfaces.nsIFilePicker
var windowTitle = gPrefApplicationsBundle.getString("chooseHandler");
var programsFilter = gPrefApplicationsBundle.getString("programsFilter");
filePicker.init(window, windowTitle, FP.modeOpen);
if (navigator.platform == "Win32")
filePicker.appendFilter(programsFilter, "*.exe; *.com");
else
filePicker.appendFilters(FP.filterAll);
if ( filePicker.show() == FP.returnOK ) {
var file = filePicker.file.QueryInterface(Components.interfaces.nsILocalFile);
gAppPath.value = file.path;
gAppPath.select();
selectAppRadio();
}
}
}
function selectAppRadio()
{
if (gHandlerGroup.value != nsIMIMEInfo.useHelperApp)
gHandlerGroup.value = nsIMIMEInfo.useHelperApp;
doEnabling();
}
var gDS = null;
function getDS()
{
const mimeTypes = "UMimTyp";
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"].getService();
if (fileLocator)
fileLocator = fileLocator.QueryInterface(Components.interfaces.nsIProperties);
var file = fileLocator.get(mimeTypes, Components.interfaces.nsIFile);
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
gDS = gRDF.GetDataSource(fileHandler.getURLSpecFromFile(file));
}
function updateEntry(info)
{
// Initialize data source.
getDS();
// Get mime type from which we can construct a HandlerInfo...
var mimeType = info.MIMEType.toLowerCase();
// Create HandlerOverride and populate it.
var entry = new HandlerOverride(MIME_URI(mimeType));
entry.mUpdateMode = mimeHandlerExists(mimeType);
entry.mimeType = mimeType;
entry.isEditable = true;
entry.alwaysAsk = info.alwaysAskBeforeHandling;
// If not updating (i.e., a newly encountered mime type),
// then update extension list and description.
if (!entry.mUpdateMode) {
var extEnumerator = info.getFileExtensions();
while (extEnumerator.hasMore()) {
entry.addExtension(extEnumerator.getNext());
}
entry.description = info.description;
entry.appDisplayName = "";
}
if (info.preferredAction == nsIMIMEInfo.saveToDisk) {
entry.saveToDisk = true;
if (!entry.mUpdateMode) {
// Creating a new entry, set path.
entry.appPath = "";
}
} else if (info.preferredAction == nsIMIMEInfo.useSystemDefault ||
info.preferredApplicationHandler == null) {
entry.useSystemDefault = true;
if (!entry.mUpdateMode) {
// Creating a new entry, set path.
entry.appPath = "";
}
} else {
entry.saveToDisk = false;
entry.useSystemDefault = false;
entry.handleInternal = false;
entry.appPath = info.preferredApplicationHandler.path;
entry.appDisplayName = info.applicationDescription;
}
// Do RDF magic.
entry.buildLinks();
// flush the ds to disk.
var remoteDS = gDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
if (remoteDS)
remoteDS.Flush();
}
function onAccept()
{
// Validate input.
if ( !checkInput() ) {
return false;
}
getDS();
gMIMEField.value = gMIMEField.value.toLowerCase();
// Get the promptservice, we will need it
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
// Check if Mozilla can handle this type internally, in which case
// an entry would have no effect
try {
var webNavigationInfo =
Components.classes["@mozilla.org/webnavigation-info;1"]
.getService(Components.interfaces.nsIWebNavigationInfo);
if (webNavigationInfo.isTypeSupported(gMIMEField.value, null)) {
var brandBundle = document.getElementById("bundle_Brand");
var text = gPrefApplicationsBundle.getString("canHandleInternally");
text = text.replace(/%brand%/g, brandBundle.getString("brandShortName"));
if (promptService.confirmEx(
window,
gPrefApplicationsBundle.getString("canHandleInternallyTitle"),
text,
(Components.interfaces.nsIPromptService.BUTTON_POS_1 *
Components.interfaces.nsIPromptService.BUTTON_TITLE_IS_STRING) |
(Components.interfaces.nsIPromptService.BUTTON_POS_0 *
Components.interfaces.nsIPromptService.BUTTON_TITLE_CANCEL),
null,
gPrefApplicationsBundle.getString("canHandleInternallyContinue"),
null,
null,
{}
) == 0)
return false;
}
}
catch (ex) {}
// figure out if this mime type already exists.
if (gMIMEField.value != gOldMIME) {
var exists = mimeHandlerExists(gMIMEField.value);
if (exists) {
var titleMsg = gPrefApplicationsBundle.getString("handlerExistsTitle");
var dialogMsg = gPrefApplicationsBundle.getString("handlerExists");
dialogMsg = dialogMsg.replace(/%mime%/g, gMIMEField.value);
var replace = promptService.confirm(window, titleMsg, dialogMsg);
if (!replace)
return true;
// delete mimetype we're overwriting
if (gMIMEField.value)
removeOverride(gMIMEField.value);
}
}
if (gOldMIME && gOldMIME != gMIMEField.value)
removeOverride(gOldMIME); // delete old handler
// now save the information
var handlerInfo = new HandlerOverride(MIME_URI(gMIMEField.value));
handlerInfo.mUpdateMode = (gOldMIME == gMIMEField.value);
handlerInfo.mimeType = gMIMEField.value;
// set description, editable, and extensions
handlerInfo.isEditable = true;
handlerInfo.description = gDescription.value;
handlerInfo.clearExtensions();
var extensions = gExtension.value.toLowerCase().split(" ");
for (var i = 0; i < extensions.length; i++) {
var currExtension = extensions[i];
handlerInfo.addExtension(currExtension);
}
// other info we need to set (not reflected in UI)
if (gHandlerGroup.value == nsIMIMEInfo.useHelperApp) {
handlerInfo.appPath = gAppPath.value;
handlerInfo.setHandlerProcedure("saveToDisk", "false");
handlerInfo.setHandlerProcedure("useSystemDefault", "false");
handlerInfo.setHandlerProcedure("handleInternal", "false");
}
else if (gHandlerGroup.value == nsIMIMEInfo.saveToDisk)
handlerInfo.saveToDisk = true;
else if (gHandlerGroup.value == nsIMIMEInfo.useSystemDefault)
handlerInfo.useSystemDefault = true;
else
handlerInfo.handleInternal = true;
handlerInfo.alwaysAsk = gAskBeforeOpen.checked;
// need to make the following dynamic to track changes. otherwise the
// app pretty name remains the same.
// better still, find a way to XP dynamically discover the pretty name of the app
// from the OS.
var file = Components.classes["@mozilla.org/file/local;1"].createInstance();
if (file)
file = file.QueryInterface(Components.interfaces.nsILocalFile);
if (file) {
try {
file.initWithPath(gAppPath.value);
handlerInfo.appDisplayName = file.leafName;
}
catch(e) {
handlerInfo.appDisplayName = gAppPath.value;
}
}
// do the rest of the work (ugly yes, but it works)
handlerInfo.buildLinks();
// flush the ds to disk.
var remoteDS = gDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
if (remoteDS)
remoteDS.Flush();
window.opener.gUpdateTypeRV = true;
return true;
}
]]>
</script>
<vbox>
<hbox align="center">
<image id="contentTypeImage"/>
<grid flex="1">
<columns>
<column/>
<column flex="1"/>
</columns>
<rows>
<row align="center">
<label value="&mimetype.label;" accesskey="&mimetype.accesskey;" control="mimeType"/>
<textbox id="mimeType"/>
</row>
<row align="center">
<label value="&description.label;" accesskey="&description.accesskey;" control="description"/>
<textbox id="description" crop="right" flex="1"/>
</row>
<row align="center">
<label value="&extension.label;" accesskey="&extension.accesskey;" control="extension"/>
<textbox id="extension"/>
</row>
</rows>
</grid>
</hbox>
<separator class="thin"/>
<groupbox>
<caption label="&handling.label;"/>
<radiogroup id="handler">
<radio id="useSystemDefault" label="&useDefault.label;" accesskey="&useDefault.accesskey;" oncommand="doEnabling();"/>
<hbox align="center">
<radio id="useHelperApp" label="&application.label;" accesskey="&application.accesskey;" oncommand="doEnabling();"/>
<textbox id="appPath" flex="1" onchange="selectAppRadio();"/>
<button label="&browse.label;" accesskey="&browse.accesskey;"
oncommand="chooseApp();"/>
</hbox>
<radio id="saveToDisk" label="&saveToDisk.label;" accesskey="&saveToDisk.accesskey;" oncommand="doEnabling();"/>
</radiogroup>
</groupbox>
<separator class="thin"/>
<hbox align="center">
<checkbox id="askBeforeOpen" label="&askBeforeOpen.label;" accesskey="&askBeforeOpen.accesskey;"/>
</hbox>
</vbox>
</dialog>