!import
1 //@line 36 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/toolkit/components/apppicker/content/appPicker.js"
2
AppPicker
3 function AppPicker() {};
4
5 var g_dialog = null;
6
7 AppPicker.prototype =
8 {
9 // Class members
10 _incomingParams:null,
11
12 /**
13 * Init the dialog and populate the application list
14 */
appPickerLoad
15 appPickerLoad: function appPickerLoad() {
16 const nsILocalHandlerApp = Components.interfaces.nsILocalHandlerApp;
17
18 this._incomingParams = window.arguments[0];
19 this._incomingParams.handlerApp = null;
20
21 document.title = this._incomingParams.title;
22
23 // Header creation - at the very least, we must have
24 // a mime type:
25 //
26 // (icon) Zip File
27 // (icon) filename
28 //
29 // (icon) Web Feed
30 // (icon) mime/type
31 //
32 // (icon) mime/type
33 // (icon)
34
35 var mimeInfo = this._incomingParams.mimeInfo;
36 var filename = this._incomingParams.filename;
37 if (!filename) {
38 filename = mimeInfo.MIMEType;
39 }
40 var description = this._incomingParams.description;
41 if (!description) {
42 description = filename;
43 filename = "";
44 }
45
46 // Setup the dialog header information
47 document.getElementById("content-description").setAttribute("value",
48 description);
49 document.getElementById("suggested-filename").setAttribute("value",
50 filename);
51 document.getElementById("content-icon").setAttribute("src",
52 "moz-icon://" + filename + "?size=32&contentType=" +
53 mimeInfo.MIMEType);
54
55 // Grab a list of nsILocalHandlerApp application helpers to list
56 var fileList = mimeInfo.possibleLocalHandlers;
57
58 /*
59 <richlistitem id="app-picker-item" value=nsfileobject>
60 <hbox align="center">
61 <image id="app-picker-item-image" src=""/>
62 <vbox>
63 <hbox align="center">
64 <listcell id="app-picker-item-cell" label="Outlook"/>
65 </hbox>
66 </vbox>
67 </hbox>
68 </richlistitem>
69 */
70
71 var list = document.getElementById("app-picker-list");
72
73 var primaryCount = 0;
74
75 if (!fileList || fileList.length == 0) {
76 // display a message saying nothing is configured
77 document.getElementById("app-picker-notfound").removeAttribute("hidden");
78 return;
79 }
80
81 for (var idx = 0; idx < fileList.length; idx++) {
82 var file = fileList.queryElementAt(idx, nsILocalHandlerApp);
83 try {
84 if (!file.executable || !file.executable.isFile())
85 continue;
86 } catch (err) {
87 continue;
88 }
89
90 var item = document.createElement("richlistitem");
91 item.setAttribute("id", "app-picker-item");
92 item.value = file;
93 item.label = this.getFileDisplayName(file.executable);
94 item.setAttribute("ondblclick", "g_dialog.appDoubleClick();");
95
96 var hbox1 = document.createElement("hbox");
97 hbox1.setAttribute("align", "center");
98
99 var image = document.createElement("image");
100 image.setAttribute("id", "app-picker-item-image");
101 image.setAttribute("src", this.getFileIconURL(file.executable));
102
103 var vbox1 = document.createElement("vbox");
104 var hbox2 = document.createElement("hbox");
105 hbox2.setAttribute("align", "center");
106
107 var cell = document.createElement("listcell");
108 cell.setAttribute("id", "app-picker-item-cell");
109 cell.setAttribute("label", this.getFileDisplayName(file.executable));
110
111 hbox2.appendChild(cell);
112 vbox1.appendChild(hbox2);
113 hbox1.appendChild(image);
114 hbox1.appendChild(vbox1);
115 item.appendChild(hbox1);
116 list.appendChild(item);
117
118 primaryCount++;
119 }
120
121 if ( primaryCount == 0 ) {
122 // display a message saying nothing is configured
123 document.getElementById("app-picker-notfound").removeAttribute("hidden");
124 }
125 },
126
127 /**
128 * Retrieve the moz-icon for the app
129 */
getFileIconURL
130 getFileIconURL: function getFileIconURL(file) {
131 var ios = Components.classes["@mozilla.org/network/io-service;1"].
132 getService(Components.interfaces.nsIIOService);
133
134 if (!ios) return "";
135 const nsIFileProtocolHandler =
136 Components.interfaces.nsIFileProtocolHandler;
137
138 var fph = ios.getProtocolHandler("file")
139 .QueryInterface(nsIFileProtocolHandler);
140 if (!fph) return "";
141
142 var urlSpec = fph.getURLSpecFromFile(file);
143 return "moz-icon://" + urlSpec + "?size=32";
144 },
145
146 /**
147 * Retrieve the pretty description from the file
148 */
getFileDisplayName
149 getFileDisplayName: function getFileDisplayName(file) {
150 //@line 194 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/toolkit/components/apppicker/content/appPicker.js"
151 const nsILocalFileMac = Components.interfaces.nsILocalFileMac;
152 if (file instanceof nsILocalFileMac) {
153 try {
154 return lfm.bundleDisplayName;
155 } catch (e) {
156 }
157 }
158 //@line 202 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/toolkit/components/apppicker/content/appPicker.js"
159 return file.leafName;
160 },
161
162 /**
163 * Double click accepts an app
164 */
appDoubleClick
165 appDoubleClick: function appDoubleClick() {
166 var list = document.getElementById("app-picker-list");
167 var selItem = list.selectedItem;
168
169 if (!selItem) {
170 this._incomingParams.handlerApp = null;
171 return true;
172 }
173
174 this._incomingParams.handlerApp = selItem.value;
175 window.close();
176
177 return true;
178 },
179
appPickerOK
180 appPickerOK: function appPickerOK() {
181 if (this._incomingParams.handlerApp) return true;
182
183 var list = document.getElementById("app-picker-list");
184 var selItem = list.selectedItem;
185
186 if (!selItem) {
187 this._incomingParams.handlerApp = null;
188 return true;
189 }
190 this._incomingParams.handlerApp = selItem.value;
191
192 return true;
193 },
194
appPickerCancel
195 appPickerCancel: function appPickerCancel() {
196 this._incomingParams.handlerApp = null;
197 return true;
198 },
199
200 /**
201 * User browse for an app.
202 */
appPickerBrowse
203 appPickerBrowse: function appPickerBrowse() {
204 var nsIFilePicker = Components.interfaces.nsIFilePicker;
205 var fp = Components.classes["@mozilla.org/filepicker;1"].
206 createInstance(nsIFilePicker);
207
208 fp.init(window, this._incomingParams.title, nsIFilePicker.modeOpen);
209 fp.appendFilters(nsIFilePicker.filterApps);
210
211 var fileLoc = Components.classes["@mozilla.org/file/directory_service;1"]
212 .getService(Components.interfaces.nsIProperties);
213 var startLocation;
214 //@line 261 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/toolkit/components/apppicker/content/appPicker.js"
215 startLocation = "LocApp"; // Local Applications
216 //@line 266 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/toolkit/components/apppicker/content/appPicker.js"
217 fp.displayDirectory =
218 fileLoc.get(startLocation, Components.interfaces.nsILocalFile);
219
220 if (fp.show() == nsIFilePicker.returnOK && fp.file) {
221 var localHandlerApp =
222 Components.classes["@mozilla.org/uriloader/local-handler-app;1"].
223 createInstance(Components.interfaces.nsILocalHandlerApp);
224 localHandlerApp.executable = fp.file;
225
226 this._incomingParams.handlerApp = localHandlerApp;
227 window.close();
228 }
229 return true;
230 }
231 }
232
233 // Global object
234 var g_dialog = new AppPicker();