1
# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
# The contents of this file are subject to the Mozilla Public License Version
5
# 1.1 (the "License"); you may not use this file except in compliance with
6
# the License. You may obtain a copy of the License at
7
# http://www.mozilla.org/MPL/
9
# Software distributed under the License is distributed on an "AS IS" basis,
10
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
# for the specific language governing rights and limitations under the
14
# The Original Code is Mozilla.org Code.
16
# The Initial Developer of the Original Code is
18
# Portions created by the Initial Developer are Copyright (C) 2001
19
# the Initial Developer. All Rights Reserved.
22
# Ben Goodger <ben@bengoodger.com>
24
# Alternatively, the contents of this file may be used under the terms of
25
# either the GNU General Public License Version 2 or later (the "GPL"), or
26
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
# in which case the provisions of the GPL or the LGPL are applicable instead
28
# of those above. If you wish to allow use of your version of this file only
29
# under the terms of either the GPL or the LGPL, and not to allow others to
30
# use your version of this file under the terms of the MPL, indicate your
31
# decision by deleting the provisions above and replace them with the notice
32
# and other provisions required by the GPL or the LGPL. If you do not delete
33
# the provisions above, a recipient may use your version of this file under
34
# the terms of any one of the MPL, the GPL or the LGPL.
36
# ***** END LICENSE BLOCK *****
38
var gRDF, gItemRes, gHelperApps;
40
var gHandlerRes, gExtAppRes;
42
var gLastSelectedActionItem = null;
46
gRDF = window.opener.gRDF;
47
gItemRes = window.arguments[0];
49
gHelperApps = window.opener.gHelperApps;
50
gHandlerPropArc = gHelperApps._handlerPropArc;
51
gExternalAppArc = gHelperApps._externalAppArc;
52
gFileHandlerArc = gHelperApps._fileHandlerArc;
54
gNC_URI = window.opener.NC_URI;
56
var typeField = document.getElementById("typeField");
57
var str = gHelperApps.getLiteralValue(gItemRes.Value, "FileType");
59
str += " (" + gHelperApps.getLiteralValue(gItemRes.Value, "FileExtensions") + ")";
60
typeField.value = str;
61
var typeIcon = document.getElementById("typeIcon");
62
typeIcon.src = gHelperApps.getLiteralValue(gItemRes.Value, "FileIcon");
64
var handlerGroup = document.getElementById("handlerGroup");
66
gHandlerRes = gHelperApps.GetTarget(gItemRes, gHandlerPropArc, true);
68
gHandlerRes = gHandlerRes.QueryInterface(Components.interfaces.nsIRDFResource);
70
// Custom App Handler Path - this must be set before we set the selected
71
// radio button because the selection event handler for the radio group
72
// requires the extapp handler field to be non-empty for the extapp radio
73
// button to be selected.
74
var gExtAppRes = gHelperApps.GetTarget(gHandlerRes, gExternalAppArc, true);
76
gExtAppRes = gExtAppRes.QueryInterface(Components.interfaces.nsIRDFResource);
78
var customAppPath = document.getElementById("customAppPath");
79
customAppPath.value = gHelperApps.getLiteralValue(gExtAppRes.Value, "path");
82
// Selected Action Radiogroup
83
var handleInternal = gHelperApps.getLiteralValue(gHandlerRes.Value, "useSystemDefault");
84
var saveToDisk = gHelperApps.getLiteralValue(gHandlerRes.Value, "saveToDisk");
85
if (handleInternal == "true")
86
handlerGroup.selectedItem = document.getElementById("openDefault");
87
else if (saveToDisk == "true")
88
handlerGroup.selectedItem = document.getElementById("saveToDisk");
90
handlerGroup.selectedItem = document.getElementById("openApplication");
92
gLastSelectedActionItem = handlerGroup.selectedItem;
95
// No Handler/ExtApp Resources for this type for some reason
96
handlerGroup.selectedItem = document.getElementById("openDefault");
99
var defaultAppName = document.getElementById("defaultAppName");
100
var mimeInfo = gHelperApps.getMIMEInfo(gItemRes);
101
defaultAppName.value = mimeInfo.defaultDescription;
103
handlerGroup.focus();
105
// We don't let users open .exe files or random binary data directly
106
// from the browser at the moment because of security concerns.
107
var mimeType = mimeInfo.MIMEType;
108
if (mimeType == "application/object-stream" ||
109
mimeType == "application/x-msdownload") {
110
document.getElementById("openApplication").disabled = true;
111
document.getElementById("openDefault").disabled = true;
112
handlerGroup.selectedItem = document.getElementById("saveToDisk");
115
var x = document.documentElement.getAttribute("screenX");
117
setTimeout(centerOverParent, 0);
120
function setLiteralValue(aResource, aProperty, aValue)
122
var prop = gRDF.GetResource(gNC_URI(aProperty));
123
var val = gRDF.GetLiteral(aValue);
124
var oldVal = gHelperApps.GetTarget(aResource, prop, true);
126
gHelperApps.Change(aResource, prop, oldVal, val);
128
gHelperApps.Assert(aResource, prop, val, true);
136
var handlerGroup = document.getElementById("handlerGroup");
137
var value = handlerGroup.selectedItem.getAttribute("value");
140
setLiteralValue(gHandlerRes, "saveToDisk", "false");
141
setLiteralValue(gHandlerRes, "useSystemDefault", "true");
144
setLiteralValue(gHandlerRes, "saveToDisk", "false");
145
setLiteralValue(gHandlerRes, "useSystemDefault", "false");
148
setLiteralValue(gHandlerRes, "saveToDisk", "true");
149
setLiteralValue(gHandlerRes, "useSystemDefault", "false");
157
var customAppPath = document.getElementById("customAppPath");
158
if (customAppPath.value != "") {
159
setLiteralValue(gExtAppRes, "path", customAppPath.value);
160
setLiteralValue(gExtAppRes, "prettyName", customAppPath.getAttribute("prettyName"));
169
// Get the template builder to refresh the display by announcing our imaginary
170
// "FileHandler" property has been updated. (NC:FileHandler is a property
171
// that our wrapper DS uses, its value is built dynamically based on real
172
// values of other properties.
173
var newHandler = gHelperApps.GetTarget(gItemRes, gFileHandlerArc, true);
174
gHelperApps.onChange(gHelperApps, gItemRes, gFileHandlerArc, newHandler);
176
// ... this doesn't seem to work, so...
177
var fileHandlersList = window.opener.document.getElementById("fileHandlersList");
178
fileHandlersList.builder.rebuild();
184
function centerOverParent()
186
var parent = window.opener;
188
x = parent.screenX + (parent.outerWidth / 2) - (window.outerWidth / 2);
189
y = parent.screenY + (parent.outerHeight / 2) - (window.outerHeight / 2);
193
function doEnabling(aSelectedItem)
195
if (aSelectedItem.id == "openApplication") {
196
var customAppPath = document.getElementById("customAppPath")
197
customAppPath.disabled = false;
198
document.getElementById("changeApp").disabled = false;
200
if (customAppPath.value == "" && !changeApp()) {
201
gLastSelectedActionItem.click();
206
document.getElementById("customAppPath").disabled = true;
207
document.getElementById("changeApp").disabled = true;
210
gLastSelectedActionItem = aSelectedItem;
215
const nsIFilePicker = Components.interfaces.nsIFilePicker;
216
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
218
// extract the window title
219
var winTitle = document.getElementById('changeApp').getAttribute('filepickertitle');
220
fp.init(window, winTitle, nsIFilePicker.modeOpen);
222
fp.appendFilters(nsIFilePicker.filterApps);
223
if (fp.show() == nsIFilePicker.returnOK && fp.file) {
224
var customAppPath = document.getElementById("customAppPath");
225
customAppPath.value = fp.file.path;
227
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
228
var uri = ioService.newFileURI(fp.file);
229
var url = uri.QueryInterface(Components.interfaces.nsIURL);
230
customAppPath.setAttribute("prettyName", url.fileName);
232
var mimeInfo = gHelperApps.getMIMEInfo(gItemRes);
233
gExtAppRes = gRDF.GetResource("urn:mimetype:externalApplication:" + mimeInfo.MIMEType);