2006-05-17 02:33:00 +00:00
|
|
|
/* -*- Mode: Java; tab-width: 2; c-basic-offset: 2; -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*/
|
2006-05-17 02:26:44 +00:00
|
|
|
|
|
|
|
var gNewTypeRV = null;
|
|
|
|
var gUpdateTypeRV = null;
|
2006-05-17 02:34:33 +00:00
|
|
|
var gList = null;
|
2006-05-17 02:28:44 +00:00
|
|
|
var gDS = null;
|
|
|
|
var gPrefApplicationsBundle = null;
|
|
|
|
|
|
|
|
var gExtensionField = null;
|
|
|
|
var gMIMETypeField = null;
|
|
|
|
var gHandlerField = null;
|
2006-05-17 02:29:28 +00:00
|
|
|
var gNewTypeButton = null;
|
2006-05-17 02:28:44 +00:00
|
|
|
var gEditButton = null;
|
|
|
|
var gRemoveButton = null;
|
2006-05-17 02:26:44 +00:00
|
|
|
|
|
|
|
function newType()
|
|
|
|
{
|
|
|
|
window.openDialog("chrome://communicator/content/pref/pref-applications-new.xul", "appEdit", "chrome,modal=yes,resizable=no");
|
|
|
|
if (gNewTypeRV) {
|
2006-05-17 02:34:33 +00:00
|
|
|
//gList.builder.rebuild();
|
|
|
|
gList.setAttribute("ref", "urn:mimetypes");
|
2006-05-17 02:26:44 +00:00
|
|
|
gNewTypeRV = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeType()
|
|
|
|
{
|
2006-05-17 02:28:44 +00:00
|
|
|
var titleMsg = gPrefApplicationsBundle.getString("removeHandlerTitle");
|
|
|
|
var dialogMsg = gPrefApplicationsBundle.getString("removeHandler");
|
2006-05-17 02:26:54 +00:00
|
|
|
dialogMsg = dialogMsg.replace(/%n/g, "\n");
|
2006-05-17 02:29:16 +00:00
|
|
|
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
|
2006-05-17 02:29:17 +00:00
|
|
|
var remove = promptService.confirm(window, titleMsg, dialogMsg);
|
2006-05-17 02:26:54 +00:00
|
|
|
if (remove) {
|
2006-05-17 02:34:33 +00:00
|
|
|
var uri = gList.selectedItems[0].id;
|
2006-05-17 02:26:54 +00:00
|
|
|
var handlerOverride = new HandlerOverride(uri);
|
|
|
|
removeOverride(handlerOverride.mimeType);
|
2006-05-17 02:34:33 +00:00
|
|
|
gList.setAttribute("ref", "urn:mimetypes");
|
2006-05-17 02:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function editType()
|
|
|
|
{
|
2006-05-17 02:34:33 +00:00
|
|
|
if (gList.selectedItems && gList.selectedItems[0]) {
|
|
|
|
var uri = gList.selectedItems[0].id;
|
2006-05-17 02:26:44 +00:00
|
|
|
var handlerOverride = new HandlerOverride(uri);
|
|
|
|
window.openDialog("chrome://communicator/content/pref/pref-applications-edit.xul", "appEdit", "chrome,modal=yes,resizable=no", handlerOverride);
|
2006-05-17 02:26:47 +00:00
|
|
|
selectApplication();
|
2006-05-17 02:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function Startup()
|
|
|
|
{
|
|
|
|
// set up the string bundle
|
2006-05-17 02:28:44 +00:00
|
|
|
gPrefApplicationsBundle = document.getElementById("bundle_prefApplications");
|
2006-05-17 02:26:44 +00:00
|
|
|
|
|
|
|
// set up the elements
|
2006-05-17 02:34:33 +00:00
|
|
|
gList = document.getElementById("appList");
|
2006-05-17 02:26:44 +00:00
|
|
|
gExtensionField = document.getElementById("extension");
|
|
|
|
gMIMETypeField = document.getElementById("mimeType");
|
|
|
|
gHandlerField = document.getElementById("handler");
|
2006-05-17 02:29:28 +00:00
|
|
|
gNewTypeButton = document.getElementById("newTypeButton");
|
2006-05-17 02:26:47 +00:00
|
|
|
gEditButton = document.getElementById("editButton");
|
|
|
|
gRemoveButton = document.getElementById("removeButton");
|
2006-05-17 02:26:44 +00:00
|
|
|
|
2006-05-17 02:27:47 +00:00
|
|
|
// Disable the Edit & Remove buttons until we click on something
|
2006-05-17 02:29:30 +00:00
|
|
|
updateLockedButtonState(false);
|
2006-05-17 02:27:47 +00:00
|
|
|
|
2006-05-17 02:27:05 +00:00
|
|
|
const mimeTypes = "UMimTyp";
|
2006-05-17 02:33:00 +00:00
|
|
|
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
|
|
|
|
|
2006-05-17 02:27:05 +00:00
|
|
|
var file = fileLocator.get(mimeTypes, Components.interfaces.nsIFile);
|
2006-05-17 02:33:00 +00:00
|
|
|
|
|
|
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
|
2006-05-17 02:35:18 +00:00
|
|
|
var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
|
|
|
dump("spec is " + fileHandler.getURLSpecFromFile(file));
|
|
|
|
gDS = gRDF.GetDataSource(fileHandler.getURLSpecFromFile(file));
|
2006-05-17 02:26:44 +00:00
|
|
|
|
2006-05-17 02:34:33 +00:00
|
|
|
// intialize the listbox
|
|
|
|
gList.database.AddDataSource(gDS);
|
|
|
|
gList.setAttribute("ref", "urn:mimetypes");
|
2006-05-17 02:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function selectApplication()
|
|
|
|
{
|
2006-05-17 02:34:33 +00:00
|
|
|
if (gList.selectedItems && gList.selectedItems.length && gList.selectedItems[0]) {
|
|
|
|
var uri = gList.selectedItems[0].id;
|
2006-05-17 02:26:44 +00:00
|
|
|
var handlerOverride = new HandlerOverride(uri);
|
|
|
|
gExtensionField.setAttribute("value", handlerOverride.extensions);
|
|
|
|
gMIMETypeField.setAttribute("value", handlerOverride.mimeType);
|
|
|
|
|
|
|
|
// figure out how this type is handled
|
|
|
|
if (handlerOverride.handleInternal == "true")
|
2006-05-17 02:28:44 +00:00
|
|
|
gHandlerField.setAttribute("value",
|
|
|
|
gPrefApplicationsBundle.getString("handleInternally"));
|
2006-05-17 02:26:44 +00:00
|
|
|
else if (handlerOverride.saveToDisk == "true")
|
2006-05-17 02:28:44 +00:00
|
|
|
gHandlerField.setAttribute("value",
|
|
|
|
gPrefApplicationsBundle.getString("saveToDisk"));
|
2006-05-17 02:26:44 +00:00
|
|
|
else
|
|
|
|
gHandlerField.setAttribute("value", handlerOverride.appDisplayName);
|
2006-05-17 02:30:39 +00:00
|
|
|
var ext;
|
|
|
|
var posOfFirstSpace = handlerOverride.extensions.indexOf(" ");
|
|
|
|
if (posOfFirstSpace > -1)
|
2006-05-17 02:30:40 +00:00
|
|
|
ext = handlerOverride.extensions.substr(0, posOfFirstSpace);
|
2006-05-17 02:30:39 +00:00
|
|
|
else
|
|
|
|
ext = handlerOverride.extensions;
|
|
|
|
var imageString = "moz-icon://" + "dummy." + ext.toLowerCase() + "?size=32&contentType=" + handlerOverride.mimeType;
|
|
|
|
document.getElementById("contentTypeImage").setAttribute("src", imageString);
|
2006-05-17 02:29:30 +00:00
|
|
|
updateLockedButtonState(handlerOverride.isEditable == "true");
|
2006-05-17 02:26:44 +00:00
|
|
|
delete handlerOverride;
|
2006-05-17 02:29:30 +00:00
|
|
|
} else {
|
|
|
|
updateLockedButtonState(false)
|
2006-05-17 02:30:41 +00:00
|
|
|
gHandlerField.removeAttribute("value");
|
|
|
|
document.getElementById("contentTypeImage").removeAttribute("src");
|
|
|
|
gExtensionField.removeAttribute("value");
|
|
|
|
gMIMETypeField.removeAttribute("value");
|
2006-05-17 02:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-17 02:29:28 +00:00
|
|
|
|
|
|
|
// disable locked buttons
|
2006-05-17 02:29:30 +00:00
|
|
|
function updateLockedButtonState(handlerEditable)
|
2006-05-17 02:29:28 +00:00
|
|
|
{
|
|
|
|
gNewTypeButton.disabled = parent.hPrefWindow.getPrefIsLocked(gNewTypeButton.getAttribute("prefstring") );
|
2006-05-17 02:29:30 +00:00
|
|
|
if (!handlerEditable ||
|
|
|
|
parent.hPrefWindow.getPrefIsLocked(gEditButton.getAttribute("prefstring"))) {
|
|
|
|
gEditButton.disabled = true;
|
|
|
|
} else {
|
|
|
|
gEditButton.disabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handlerEditable ||
|
|
|
|
parent.hPrefWindow.getPrefIsLocked(gRemoveButton.getAttribute("prefstring"))) {
|
|
|
|
gRemoveButton.disabled = true;
|
|
|
|
} else {
|
|
|
|
gRemoveButton.disabled = false;
|
|
|
|
}
|
2006-05-17 02:29:28 +00:00
|
|
|
}
|
|
|
|
|
2006-05-17 02:30:39 +00:00
|
|
|
function clearRememberedSettings()
|
|
|
|
{
|
|
|
|
var prefBranch = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
if (prefBranch) {
|
|
|
|
prefBranch.setCharPref("browser.helperApps.neverAsk.saveToDisk", "");
|
|
|
|
prefBranch.setCharPref("browser.helperApps.neverAsk.openFile", "");
|
|
|
|
}
|
|
|
|
}
|