diff --git a/cck/firefox/cckwizard/chrome/cckwizard/content/cckwizard/cckwizard.js b/cck/firefox/cckwizard/chrome/cckwizard/content/cckwizard/cckwizard.js index e6b8c845d92..e69de29bb2d 100755 --- a/cck/firefox/cckwizard/chrome/cckwizard/content/cckwizard/cckwizard.js +++ b/cck/firefox/cckwizard/chrome/cckwizard/content/cckwizard/cckwizard.js @@ -1,1258 +0,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 the Client Customization Kit (CCK). - * - * The Initial Developer of the Original Code is IBM Corp. - * Portions created by the Initial Developer are Copyright (C) 2005 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either 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 ***** */ - -var currentconfigname; -var currentconfigpath; -var haveplugins = false; -var havesearchplugins = false; - - -var gPrefBranch = Components.classes["@mozilla.org/preferences-service;1"] - .getService(Components.interfaces.nsIPrefBranch); - -function choosefile(labelname) -{ - try { - var nsIFilePicker = Components.interfaces.nsIFilePicker; - var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); - fp.init(window, "Choose File...", nsIFilePicker.modeOpen); - fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterText | - nsIFilePicker.filterAll | nsIFilePicker.filterImages | nsIFilePicker.filterXML); - - if (fp.show() == nsIFilePicker.returnOK && fp.fileURL.spec && fp.fileURL.spec.length > 0) { - var label = document.getElementById(labelname); - label.value = fp.file.path; - } - } - catch(ex) { - } -} - -function choosedir(labelname) -{ - try { - var keepgoing = true; - while (keepgoing) { - var nsIFilePicker = Components.interfaces.nsIFilePicker; - var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); - fp.init(window, "Choose File...", nsIFilePicker.modeGetFolder); - fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterText | - nsIFilePicker.filterAll | nsIFilePicker.filterImages | nsIFilePicker.filterXML); - - if (fp.show() == nsIFilePicker.returnOK && fp.fileURL.spec && fp.fileURL.spec.length > 0) { - var label = document.getElementById(labelname); - label.value = fp.file.path; - } - keepgoing = false; - } - } - catch(ex) { - } -} - -function chooseimage(labelname, imagename) -{ - try { - var nsIFilePicker = Components.interfaces.nsIFilePicker; - var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); - fp.init(window, "Choose File...", nsIFilePicker.modeOpen); - fp.appendFilters(nsIFilePicker.filterImages | nsIFilePicker.filterA); - - if (fp.show() == nsIFilePicker.returnOK && fp.fileURL.spec && fp.fileURL.spec.length > 0) { - var label = document.getElementById(labelname); - label.value = fp.file.path; - document.getElementById(imagename).src = fp.fileURL.spec; - } - } - catch(ex) { - } -} - -function initimage(labelname, imagename) -{ - var sourcefile = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); - try { - sourcefile.initWithPath(document.getElementById(labelname).value); - var ioServ = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); - var foo = ioServ.newFileURI(sourcefile); - document.getElementById(imagename).src = foo.spec; - } catch (e) { - document.getElementById(imagename).src = ''; - } -} - - - -function CreateConfig() -{ - window.openDialog("chrome://cckwizard/content/config.xul","createconfig","chrome,modal"); - updateconfiglist(); -} - -function CopyConfig() -{ - window.openDialog("chrome://cckwizard/content/config.xul","copyconfig","chrome,modal"); - - updateconfiglist(); -} - -function DeleteConfig() -{ - var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Components.interfaces.nsIPromptService); - var rv = ps.confirmEx(window, "WizardMachine", "Are you sure you want to delete this configuration?", - ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_0 + - ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_1, - "Yes", "No", null, null, {}); - if (rv == false) { - gPrefBranch.deleteBranch("cck.config."+currentconfigname); - updateconfiglist(); - } -} - - - - - -function ShowMain() -{ - updateconfiglist(); -} - -function updateconfiglist() -{ - var menulist = document.getElementById('byb-configs') - menulist.selectedIndex = -1; - menulist.removeAllItems(); - var configname; - var selecteditem = false; - - - - var list = gPrefBranch.getChildList("cck.config.", {}); - for (var i = 0; i < list.length; ++i) { - configname = list[i].replace(/cck.config./g, ""); - var menulistitem = menulist.appendItem(configname,configname); - menulistitem.minWidth=menulist.width; - if (configname == currentconfigname) { - menulist.selectedItem = menulistitem; - selecteditem = true; - document.getElementById('example-window').canAdvance = true; - document.getElementById('deleteconfig').disabled = false; - } - } - if ((!selecteditem) && (list.length > 0)) { - menulist.selectedIndex = 0; - setcurrentconfig(list[0].replace(/cck.config./g, "")); - } - if (list.length == 0) { - document.getElementById('example-window').canAdvance = false; - document.getElementById('deleteconfig').disabled = true; - } -} - -function setcurrentconfig(newconfig) -{ - var destdir = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); - - if (currentconfigpath) { - destdir.initWithPath(currentconfigpath); - CCKWriteConfigFile(destdir); - } - currentconfigname = newconfig; - currentconfigpath = gPrefBranch.getCharPref("cck.config." + currentconfigname); - destdir.initWithPath(currentconfigpath); - CCKReadConfigFile(destdir); -} - -function saveconfig() -{ - - - if (currentconfigpath) { - var destdir = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); - - - - destdir.initWithPath(currentconfigpath); - CCKWriteConfigFile(destdir); - } - -} - -function OnConfigOK() -{ - var configname = document.getElementById('cnc-name').value; - var configlocation = document.getElementById('cnc-location').value; - if ((configname) && (configlocation)) { - gPrefBranch.setCharPref("cck.config." + configname, configlocation); - this.opener.setcurrentconfig(configname); - if (window.name = 'copyconfig') { -/* copy prefs from current config */ - } - } else { - return false; - } -} - -function CreateCCK() -{ -/* ---------- */ - var destdir = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); - destdir.initWithPath(currentconfigpath); - - CCKWriteConfigFile(destdir); - - destdir.append("jar"); - destdir.append("content"); - destdir.append("cck"); - try { - destdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775); - } catch(ex) {} - - CCKWriteXULOverlay(destdir); - CCKWriteDTD(destdir); - CCKWriteCSS(destdir); - CCKWriteProperties(destdir); - CCKCopyFile(document.getElementById("iconURL").value, destdir); - CCKCopyFile(document.getElementById("LargeAnimPath").value, destdir); - CCKCopyFile(document.getElementById("LargeStillPath").value, destdir); - CCKCopyChromeToFile("cck.js", destdir) - - CCKCopyFile(document.getElementById("CertPath1").value, destdir); - CCKCopyFile(document.getElementById("CertPath2").value, destdir); - CCKCopyFile(document.getElementById("CertPath3").value, destdir); - CCKCopyFile(document.getElementById("CertPath4").value, destdir); - CCKCopyFile(document.getElementById("CertPath5").value, destdir); - -/* copy/create contents.rdf if 1.0 */ - var zipdir = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); - zipdir.initWithPath(currentconfigpath); - zipdir.append("jar"); - CCKZip("cck.jar", zipdir, "content"); - -/* ---------- */ - - destdir.initWithPath(currentconfigpath); - destdir.append("xpi"); - destdir.append("chrome"); - try { - destdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775); - } catch(ex) {} - - zipdir.append("cck.jar"); - - CCKCopyFile(zipdir.path, destdir); - -/* ---------- */ - - destdir.initWithPath(currentconfigpath); - destdir.append("xpi"); - destdir.append("components"); - try { - destdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775); - } catch(ex) {} - - CCKCopyChromeToFile("cckService.js", destdir); - -/* ---------- */ - - destdir.initWithPath(currentconfigpath); - destdir.append("xpi"); - destdir.append("defaults"); - destdir.append("preferences"); - try { - destdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775); - } catch(ex) {} - - CCKWriteDefaultJS(destdir) - -/* ---------- */ - - destdir.initWithPath(currentconfigpath); - destdir.append("xpi"); - destdir.append("plugins"); - try { - destdir.remove(true); - destdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775); - } catch(ex) {} - - haveplugins = CCKCopyFile(document.getElementById("BrowserPluginPath1").value, destdir); - haveplugins |= CCKCopyFile(document.getElementById("BrowserPluginPath2").value, destdir); - haveplugins |= CCKCopyFile(document.getElementById("BrowserPluginPath3").value, destdir); - haveplugins |= CCKCopyFile(document.getElementById("BrowserPluginPath4").value, destdir); - haveplugins |=CCKCopyFile(document.getElementById("BrowserPluginPath5").value, destdir); - - destdir.initWithPath(currentconfigpath); - destdir.append("xpi"); - destdir.append("searchplugins"); - try { - destdir.remove(true); - destdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775); - } catch(ex) {} - - havesearchplugins = CCKCopyFile(document.getElementById("SearchPlugin1").value, destdir); - CCKCopyFile(document.getElementById("SearchPluginIcon1").value, destdir); - havesearchplugins |= CCKCopyFile(document.getElementById("SearchPlugin2").value, destdir); - CCKCopyFile(document.getElementById("SearchPluginIcon2").value, destdir); - havesearchplugins |= CCKCopyFile(document.getElementById("SearchPlugin3").value, destdir); - CCKCopyFile(document.getElementById("SearchPluginIcon3").value, destdir); - havesearchplugins |= CCKCopyFile(document.getElementById("SearchPlugin4").value, destdir); - CCKCopyFile(document.getElementById("SearchPluginIcon4").value, destdir); - havesearchplugins |= CCKCopyFile(document.getElementById("SearchPlugin5").value, destdir); - CCKCopyFile(document.getElementById("SearchPluginIcon5").value, destdir); - - destdir.initWithPath(currentconfigpath); - destdir.append("xpi"); - - CCKCopyChromeToFile("chrome.manifest", destdir) - CCKWriteInstallRDF(destdir); - CCKWriteInstallJS(destdir); - CCKZip("cck.xpi", destdir, - "chrome", "components", "defaults", "plugins", "searchplugins", "chrome.manifest", "install.rdf", "install.js"); -} - -/* This function takes a file in the chromedir and creates a real file */ - -function CCKCopyChromeToFile(chromefile, location) -{ - var file = location.clone(); - file.append(chromefile); - - try { - file.remove(false); - } catch (ex) { - } - var fos = Components.classes["@mozilla.org/network/file-output-stream;1"] - .createInstance(Components.interfaces.nsIFileOutputStream); - - fos.init(file, -1, -1, false); - - var ioService=Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); - var scriptableStream=Components - .classes["@mozilla.org/scriptableinputstream;1"] - .getService(Components.interfaces.nsIScriptableInputStream); - - var channel=ioService.newChannel("chrome://cckwizard/content/srcfiles/" + chromefile + ".in",null,null); - var input=channel.open(); - scriptableStream.init(input); - var str=scriptableStream.read(input.available()); - scriptableStream.close(); - input.close(); - - fos.write(str, str.length); - fos.close(); -} - - -/* This function creates a given zipfile in a given location */ -/* It takes as parameters the names of all the files/directories to be contained in the ZIP file */ -/* It works by creating a CMD file to generate the ZIP */ -/* unless we have the spiffy ZipWriterCompoent from maf.mozdev.org */ - -function CCKZip(zipfile, location) -{ - var file = location.clone(); - file.append(zipfile); - try { - file.remove(false); - } catch (ex) {} - - if (Components.interfaces.IZipWriterComponent) { - var archivefileobj = location.clone(); - archivefileobj.append(zipfile); - - try { - var zipwriterobj = Components.classes["@ottley.org/libzip/zip-writer;1"] - .createInstance(Components.interfaces.IZipWriterComponent); - - zipwriterobj.CURR_COMPRESS_LEVEL = Components.interfaces.IZipWriterComponent.COMPRESS_LEVEL9; - - var sourcepathobj = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); - sourcepathobj.initWithPath(location.path); - - zipwriterobj.init(archivefileobj); - - zipwriterobj.basepath = sourcepathobj; - - var zipentriestoadd = new Array(); - - for (var i=2; i < arguments.length; i++) { - var sourcepathobj = location.clone(); - sourcepathobj.append(arguments[i]); - if (sourcepathobj.exists() && sourcepathobj.isDirectory()) { - var entries = sourcepathobj.directoryEntries; - - while (entries.hasMoreElements()) { - zipentriestoadd.push(entries.getNext()); - } - } else if (sourcepathobj.exists()) { - zipentriestoadd.push(sourcepathobj); - } - } - - // Add files depth first - while (zipentriestoadd.length > 0) { - var zipentry = zipentriestoadd.pop(); - - zipentry.QueryInterface(Components.interfaces.nsILocalFile); - - if (!zipentry.isDirectory()) { - zipwriterobj.add(zipentry); - } - - if (zipentry.exists() && zipentry.isDirectory()) { - var entries = zipentry.directoryEntries; - - while (entries.hasMoreElements()) { - zipentriestoadd.push(entries.getNext()); - } - } - } - - zipwriterobj.commitUpdates(); - - } catch (e) { - alert('ZIPWriterComponent error'); - } - return; - } - - platform = navigator.platform; - var file = location.clone(); - - if (navigator.platform == "Win32") - file.append("ccktemp.cmd"); - else - file.append("ccktemp.sh"); - var fos = Components.classes["@mozilla.org/network/file-output-stream;1"] - .createInstance(Components.interfaces.nsIFileOutputStream); - fos.init(file, -1, -1, false); - var line; - line = "cd \"" + location.path + "\"\n"; - fos.write(line, line.length); - if (navigator.platform == "Win32") - line = "zip -r \"" + location.path + "\\" + zipfile + "\""; - else - line = "zip -r \"" + location.path + "/" + zipfile + "\""; - for (var i=2; i < arguments.length; i++) { - line += " " + arguments[i]; - } - line += "\n"; - fos.write(line, line.length); - fos.close(); - - var sh; - - // create an nsILocalFile for the executable - if (navigator.platform != "Win32") { - sh = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); - sh.initWithPath("/bin/sh"); - } - // create an nsIProcess - var process = Components.classes["@mozilla.org/process/util;1"] - .createInstance(Components.interfaces.nsIProcess); - - if (navigator.platform == "Win32") - process.init(file); - else - process.init(sh); - - var args = [file.path]; - - process.run(true, args, args.length); - file.remove(false); -} - -function CCKWriteXULOverlay(destdir) -{ - var tooltipXUL = '