2000-07-06 01:43:17 +00:00
|
|
|
var gDescriptionField = null;
|
|
|
|
var gExtensionField = null;
|
|
|
|
var gMIMEField = null;
|
|
|
|
var gAppPath = null;
|
|
|
|
|
2001-03-21 02:08:19 +00:00
|
|
|
var gPrefApplicationsBundle = null;
|
2000-07-06 01:43:17 +00:00
|
|
|
|
|
|
|
function Startup()
|
|
|
|
{
|
|
|
|
doSetOKCancel(onOK);
|
|
|
|
|
|
|
|
gDescriptionField = document.getElementById("description");
|
|
|
|
gExtensionField = document.getElementById("extensions");
|
|
|
|
gMIMEField = document.getElementById("mimeType");
|
|
|
|
gAppPath = document.getElementById("appPath");
|
|
|
|
|
2001-03-21 02:08:19 +00:00
|
|
|
gPrefApplicationsBundle = document.getElementById("bundle_prefApplications");
|
2001-05-03 21:03:55 +00:00
|
|
|
|
|
|
|
// If an arg was passed, then it's an nsIHelperAppLauncherDialog
|
|
|
|
if ( "arguments" in window && window.arguments[0] ) {
|
|
|
|
// Get mime info.
|
|
|
|
var info = window.arguments[0].mLauncher.MIMEInfo;
|
|
|
|
|
|
|
|
// Fill the fields we can from this.
|
|
|
|
gDescriptionField.value = info.Description;
|
|
|
|
gExtensionField.value = info.FirstExtension();
|
|
|
|
gMIMEField.value = info.MIMEType;
|
|
|
|
var app = info.preferredApplicationHandler;
|
|
|
|
if ( app ) {
|
|
|
|
gAppPath.value = app.unicodePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't let user change mime type.
|
|
|
|
gMIMEField.setAttribute( "readonly", "true" );
|
|
|
|
|
|
|
|
// Start user in app field.
|
|
|
|
gAppPath.focus();
|
|
|
|
} else {
|
|
|
|
gDescriptionField.focus();
|
|
|
|
}
|
2000-07-06 01:43:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function chooseApp()
|
|
|
|
{
|
2000-08-24 23:30:29 +00:00
|
|
|
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
2000-09-13 23:57:52 +00:00
|
|
|
var filePicker = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
|
2000-07-06 01:43:17 +00:00
|
|
|
if (filePicker) {
|
|
|
|
const FP = Components.interfaces.nsIFilePicker
|
2001-03-21 02:08:19 +00:00
|
|
|
var windowTitle = gPrefApplicationsBundle.getString("chooseHandler");
|
|
|
|
var programsFilter = gPrefApplicationsBundle.getString("programsFilter");
|
2000-07-06 01:43:17 +00:00
|
|
|
filePicker.init(window, windowTitle, FP.modeOpen);
|
2000-09-22 04:52:22 +00:00
|
|
|
if (navigator.platform == "Win32")
|
2000-07-06 01:43:17 +00:00
|
|
|
filePicker.appendFilter(programsFilter, "*.exe; *.com");
|
|
|
|
else
|
|
|
|
filePicker.appendFilters(FP.filterAll);
|
2000-09-07 18:52:02 +00:00
|
|
|
var filePicked = filePicker.show();
|
|
|
|
if (filePicked == nsIFilePicker.returnOK && filePicker.file) {
|
|
|
|
var file = filePicker.file.QueryInterface(Components.interfaces.nsILocalFile);
|
|
|
|
gAppPath.value = file.path;
|
|
|
|
gAppPath.select();
|
|
|
|
}
|
2000-07-06 01:43:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var gDS = null;
|
|
|
|
function onOK()
|
|
|
|
{
|
2000-08-22 00:36:55 +00:00
|
|
|
const mimeTypes = "UMimTyp";
|
2000-09-13 23:57:52 +00:00
|
|
|
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"].getService();
|
2000-07-06 01:43:17 +00:00
|
|
|
if (fileLocator)
|
2000-08-22 00:36:55 +00:00
|
|
|
fileLocator = fileLocator.QueryInterface(Components.interfaces.nsIProperties);
|
|
|
|
var file = fileLocator.get(mimeTypes, Components.interfaces.nsIFile);
|
2001-06-21 22:02:47 +00:00
|
|
|
gDS = gRDF.GetDataSource(file.URL);
|
2000-07-06 01:43:17 +00:00
|
|
|
if (gDS)
|
|
|
|
gDS = gDS.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
|
|
|
|
|
|
|
// figure out if this mime type already exists.
|
|
|
|
var exists = mimeHandlerExists(gMIMEField.value);
|
|
|
|
if (exists) {
|
2001-03-21 02:08:19 +00:00
|
|
|
var titleMsg = gPrefApplicationsBundle.getString("handlerExistsTitle");
|
|
|
|
var dialogMsg = gPrefApplicationsBundle.getString("handlerExists");
|
2000-07-06 01:43:17 +00:00
|
|
|
dialogMsg = dialogMsg.replace(/%mime%/g, gMIMEField.value);
|
2001-04-09 02:08:05 +00:00
|
|
|
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
|
2001-04-09 20:38:20 +00:00
|
|
|
var replace = promptService.confirm(window, titleMsg, dialogMsg);
|
2000-07-06 01:43:17 +00:00
|
|
|
if (!replace)
|
2001-07-04 03:53:38 +00:00
|
|
|
{
|
2000-07-06 01:43:17 +00:00
|
|
|
window.close();
|
2001-07-04 03:53:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-07-06 01:43:17 +00:00
|
|
|
}
|
|
|
|
|
2000-07-07 05:44:53 +00:00
|
|
|
|
2000-07-06 01:43:17 +00:00
|
|
|
// now save the information
|
|
|
|
var handlerInfo = new HandlerOverride(MIME_URI(gMIMEField.value));
|
2000-07-07 05:44:53 +00:00
|
|
|
handlerInfo.mUpdateMode = exists; // XXX Somewhat sleazy, I know...
|
2000-07-06 01:43:17 +00:00
|
|
|
handlerInfo.mimeType = gMIMEField.value;
|
|
|
|
handlerInfo.description = gDescriptionField.value;
|
|
|
|
|
|
|
|
var extensionString = gExtensionField.value.replace(/[*.;]/g, "");
|
|
|
|
var extensions = extensionString.split(" ");
|
|
|
|
for (var i = 0; i < extensions.length; i++) {
|
|
|
|
var currExtension = extensions[i];
|
|
|
|
handlerInfo.addExtension(currExtension);
|
|
|
|
}
|
|
|
|
handlerInfo.appPath = gAppPath.value;
|
|
|
|
|
|
|
|
// other info we need to set (not reflected in UI)
|
|
|
|
handlerInfo.isEditable = true;
|
|
|
|
handlerInfo.saveToDisk = false;
|
|
|
|
handlerInfo.handleInternal = false;
|
|
|
|
handlerInfo.alwaysAsk = true;
|
2000-09-13 23:57:52 +00:00
|
|
|
var file = Components.classes["@mozilla.org/file/local;1"].createInstance();
|
2000-07-06 01:43:17 +00:00
|
|
|
if (file)
|
|
|
|
file = file.QueryInterface(Components.interfaces.nsILocalFile);
|
|
|
|
if (file) {
|
|
|
|
try {
|
|
|
|
file.initWithPath(gAppPath.value);
|
|
|
|
handlerInfo.appDisplayName = file.unicodeLeafName;
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
handlerInfo.appDisplayName = gAppPath.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// do the rest of the work (ugly yes, but it works)
|
|
|
|
handlerInfo.buildLinks();
|
|
|
|
|
|
|
|
// flush the ds to disk.
|
2001-05-03 21:03:55 +00:00
|
|
|
var remoteDS = gDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
|
|
|
if (remoteDS)
|
|
|
|
remoteDS.Flush();
|
2000-07-06 01:43:17 +00:00
|
|
|
|
2001-05-03 21:03:55 +00:00
|
|
|
// If an arg was passed, then it's an nsIHelperAppLauncherDialog
|
|
|
|
// and we need to update its MIMEInfo.
|
|
|
|
if ( "arguments" in window && window.arguments[0] ) {
|
|
|
|
// Get mime info.
|
|
|
|
var info = window.arguments[0].mLauncher.MIMEInfo;
|
|
|
|
|
|
|
|
// Update fields that might have changed.
|
|
|
|
info.preferredAction = Components.interfaces.nsIMIMEInfo.useHelperApp;
|
|
|
|
info.Description = gDescriptionField.value;
|
|
|
|
info.preferredApplicationHandler = file;
|
|
|
|
info.applicationDescription = handlerInfo.appDisplayName;
|
|
|
|
}
|
|
|
|
|
2000-08-08 04:18:23 +00:00
|
|
|
window.opener.gNewTypeRV = gMIMEField.value;
|
2000-07-06 01:43:17 +00:00
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
|