# ***** 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): # Ben Goodger (Original author) # Gavin Sharp # Joe Hughes # Pamela Greene # # 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 configarray = new Array(); const nsIPrefBranch = Components.interfaces.nsIPrefBranch; var gPrefBranch = Components.classes["@mozilla.org/preferences-service;1"] .getService(nsIPrefBranch); var gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); function choosefile(labelname) { try { var nsIFilePicker = Components.interfaces.nsIFilePicker; var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); var bundle = document.getElementById("bundle_cckwizard"); fp.init(window, bundle.getString("chooseFile"), nsIFilePicker.modeOpen); fp.appendFilters(nsIFilePicker.filterAll); 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); var bundle = document.getElementById("bundle_cckwizard"); fp.init(window, bundle.getString("chooseDirectory"), 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); var bundle = document.getElementById("bundle_cckwizard"); fp.init(window, bundle.getString("chooseImage"), nsIFilePicker.modeOpen); fp.appendFilters(nsIFilePicker.filterImages); 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,centerscreen,modal"); updateconfiglist(); } function CopyConfig() { window.openDialog("chrome://cckwizard/content/config.xul","copyconfig","chrome,centerscreen,modal"); updateconfiglist(); } function DeleteConfig() { var bundle = document.getElementById("bundle_cckwizard"); var button = gPromptService.confirmEx(window, bundle.getString("windowTitle"), bundle.getString("deleteConfirm"), gPromptService.BUTTON_TITLE_YES * gPromptService.BUTTON_POS_0 + gPromptService.BUTTON_TITLE_NO * gPromptService.BUTTON_POS_1, null, null, null, null, {}); if (button == 0) { gPrefBranch.deleteBranch("cck.config."+currentconfigname); currentconfigname = ""; currentconfigpath = ""; updateconfiglist(); } } function SetSaveOnExitPref() { gPrefBranch.setBoolPref("cck.save_on_exit", document.getElementById("saveOnExit").checked); } function OpenCCKWizard() { try { document.getElementById("saveOnExit").checked = gPrefBranch.getBoolPref("cck.save_on_exit"); } catch (ex) { } try { document.getElementById("zipLocation").value = gPrefBranch.getCharPref("cck.path_to_zip"); } catch (ex) { } } function ShowMain() { document.getElementById('example-window').canRewind = false; 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('byb-configs').disabled = false; document.getElementById('deleteconfig').disabled = false; document.getElementById('showconfig').disabled = false; document.getElementById('copyconfig').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('byb-configs').disabled = true; document.getElementById('deleteconfig').disabled = true; document.getElementById('showconfig').disabled = true; document.getElementById('copyconfig').disabled = true; currentconfigname = ""; currentconfigpath = ""; } } 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); ClearAll(); 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 CloseCCKWizard() { if (document.getElementById('example-window').pageIndex == 0) return; var saveOnExit; try { saveOnExit = gPrefBranch.getBoolPref("cck.save_on_exit"); } catch (ex) { saveOnExit = false; } var button; if (!saveOnExit) { var bundle = document.getElementById("bundle_cckwizard"); var button = gPromptService.confirmEx(window, bundle.getString("windowTitle"), bundle.getString("cancelConfirm"), (gPromptService.BUTTON_TITLE_YES * gPromptService.BUTTON_POS_0) + (gPromptService.BUTTON_TITLE_NO * gPromptService.BUTTON_POS_1), null, null, null, null, {}); } else { button = 0; } if (button == 0) { saveconfig(); } gPrefBranch.setCharPref("cck.path_to_zip", document.getElementById("zipLocation").value); } function OnConfigLoad() { configCheckOKButton(); } function ClearAll() { /* clear out all data */ var elements = document.getElementsByAttribute("id", "*"); for (var i=0; i < elements.length; i++) { if ((elements[i].nodeName == "textbox") || (elements[i].nodeName == "radiogroup") || (elements[i].id == "RootKey1") || (elements[i].id == "Type1")) { if ((elements[i].id != "saveOnExit") && (elements[i].id != "zipLocation")) { elements[i].value = ""; } } else if (elements[i].nodeName == "checkbox") { if (elements[i].id != "saveOnExit") elements[i].checked = false; } else if (elements[i].className == "ccklist") { document.getElementById(elements[i].id).clear(); } else if (elements[i].id == "defaultSearchEngine") { document.getElementById(elements[i].id).removeAllItems(); document.getElementById(elements[i].id).value = ""; } } } function OnConfigOK() { if (!(ValidateDir('cnc-location'))) { return false; } var configname = document.getElementById('cnc-name').value; var configlocation = document.getElementById('cnc-location').value; if (window.name == 'copyconfig') { var destdir = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); destdir.initWithPath(configlocation); this.opener.CCKWriteConfigFile(destdir); } gPrefBranch.setCharPref("cck.config." + configname, configlocation); this.opener.setcurrentconfig(configname); } function configCheckOKButton() { if ((document.getElementById("cnc-name").value) && (document.getElementById("cnc-location").value)) { document.documentElement.getButton("accept").setAttribute( "disabled", "false" ); } else { document.documentElement.getButton("accept").setAttribute( "disabled", "true" ); } } function onNewPreference() { window.openDialog("chrome://cckwizard/content/pref.xul","newpref","chrome,centerscreen,modal"); } function onEditPreference() { window.openDialog("chrome://cckwizard/content/pref.xul","editpref","chrome,centerscreen,modal"); } Array.prototype.exists = function (x) { for (var i = 0; i < this.length; i++) { if (this[i] == x) return true; } return false; } var prefsLockOnly = ["browser.startup.homepage", "browser.throbber.url", "network.proxy.type", "network.proxy.http", "network.proxy.http_port", "network.proxy.share_proxy_settings", "network.proxy.ssl", "network.proxy.ssl_port", "network.proxy.ftp", "network.proxy.ftp_port", "network.proxy.gopher", "network.proxy.gopher_port", "network.proxy.socks", "network.proxy.socks_port", "network.proxy.socks_version", "network.proxy.no_proxies_on", "network.proxy.autoconfig_url"]; function OnPrefLoad() { var listbox = this.opener.document.getElementById('prefList'); if (window.name == 'editpref') { window.title = listbox.selectedItem.cck['type']; if (listbox.selectedItem.cck['type'] == "integer") { document.getElementById('prefvalue').preftype = nsIPrefBranch.PREF_INT; } document.getElementById('prefname').value = listbox.selectedItem.label; if (prefsLockOnly.exists(listbox.selectedItem.label)) { document.getElementById('prefvalue').disabled = true; document.getElementById('prefvalue').value = this.opener.document.getElementById("bundle_cckwizard").getString("lockError"); } else { document.getElementById('prefvalue').value = listbox.selectedItem.value; } document.getElementById('prefname').disabled = true; if (listbox.selectedItem.cck['lock'] == "true") document.getElementById('lockPref').checked = true; if (listbox.selectedItem.cck['type'] == "boolean") { document.getElementById('prefvalue').hidden = true; document.getElementById('prefvalueboolean').hidden = false; document.getElementById('prefvalueboolean').value = listbox.selectedItem.value; } } prefCheckOKButton(); } function prefCheckOKButton() { if (document.getElementById("prefname").value) { document.documentElement.getButton("accept").setAttribute( "disabled", "false" ); } else { document.documentElement.getButton("accept").setAttribute( "disabled", "true" ); } } function prefSetPrefValue() { var prefname = document.getElementById('prefname').value; try { var preftype = gPrefBranch.getPrefType(prefname); switch (preftype) { case nsIPrefBranch.PREF_STRING: document.getElementById('prefvalue').value = gPrefBranch.getCharPref(prefname); document.getElementById('prefvalue').hidden = false; document.getElementById('prefvalueboolean').hidden = true; document.getElementById('prefvalue').preftype = nsIPrefBranch.PREF_STRING; break; case nsIPrefBranch.PREF_INT: document.getElementById('prefvalue').value = gPrefBranch.getIntPref(prefname); document.getElementById('prefvalue').hidden = false; document.getElementById('prefvalueboolean').hidden = true; document.getElementById('prefvalue').preftype = nsIPrefBranch.PREF_INT; break; case nsIPrefBranch.PREF_BOOL: document.getElementById('prefvalue').value = gPrefBranch.getBoolPref(prefname); document.getElementById('prefvalue').hidden = true; document.getElementById('prefvalueboolean').hidden = false; document.getElementById('prefvalueboolean').value = gPrefBranch.getBoolPref(prefname); document.getElementById('prefvalue').preftype = nsIPrefBranch.PREF_BOOL; break; default: document.getElementById('prefvalue').hidden = false; document.getElementById('prefvalueboolean').hidden = true; break; } } catch (ex) { document.getElementById('prefvalue').hidden = false; document.getElementById('prefvalueboolean').hidden = true; } if (prefsLockOnly.exists(prefname)) { document.getElementById('prefvalue').disabled = true; document.getElementById('prefvalue').value = this.opener.document.getElementById("bundle_cckwizard").getString("lockError"); } else { document.getElementById('prefvalue').disabled = false; } } function OnPrefOK() { var bundle = this.opener.document.getElementById("bundle_cckwizard"); var listbox = this.opener.document.getElementById("prefList"); for (var i=0; i < listbox.getRowCount(); i++) { if ((document.getElementById('prefname').value == listbox.getItemAtIndex(i).label) && (window.name == 'newpref')) { gPromptService.alert(window, bundle.getString("windowTitle"), bundle.getString("prefExistsError")); return false; } } if (prefsLockOnly.exists(document.getElementById('prefname').value)) { document.getElementById('prefvalue').value = ""; } var value = document.getElementById('prefvalue').value; if ((document.getElementById('prefvalue').preftype == nsIPrefBranch.PREF_INT) && (!(prefsLockOnly.exists(document.getElementById('prefname').value)))) { if (parseInt(value) != value) { gPromptService.alert(window, bundle.getString("windowTitle"), bundle.getString("intError")); return false; } } listbox = this.opener.document.getElementById('prefList'); var listitem; if (window.name == 'newpref') { var preftype; if ((value.toLowerCase() == "true") || (value.toLowerCase() == "false")) { preftype = "boolean"; } else if (parseInt(value) == value) { preftype = "integer"; } else { preftype = "string"; if (value.charAt(0) == '"') value = value.substring(1,value.length); if (value.charAt(value.length-1) == '"') if (value.charAt(value.length-2) != '\\') value = value.substring(0,value.length-1); } listitem = listbox.appendItem(document.getElementById('prefname').value, value); listitem.cck['type'] = preftype; } else { listitem = listbox.selectedItem; listitem.setAttribute("label", document.getElementById('prefname').value); value = document.getElementById('prefvalue').value; if (value.charAt(0) == '"') value = value.substring(1,value.length); if (value.charAt(value.length-1) == '"') if (value.charAt(value.length-2) != '\\') value = value.substring(0,value.length-1); listitem.setAttribute("value", value); } if (document.getElementById('lockPref').checked) { listitem.cck['lock'] = "true"; } else { listitem.cck['lock'] = ""; } } function getPageId() { var temp = document.getElementById('example-window'); if (!temp) temp = this.opener.document.getElementById('example-window'); return temp.currentPage.id; } function onNewBookmark() { window.openDialog("chrome://cckwizard/content/bookmark.xul","newbookmark","chrome,centerscreen,modal"); } function onEditBookmark() { window.openDialog("chrome://cckwizard/content/bookmark.xul","editbookmark","chrome,centerscreen,modal"); } function OnBookmarkLoad() { var listbox = this.opener.document.getElementById(getPageId() +'.bookmarkList'); if (window.name == 'editbookmark') { document.getElementById('bookmarkname').value = listbox.selectedItem.label; document.getElementById('bookmarkurl').value = listbox.selectedItem.value; document.getElementById('bookmarktype').value = listbox.selectedItem.cck['type']; } bookmarkCheckOKButton(); } function bookmarkCheckOKButton() { if (document.getElementById('bookmarktype').value == "separator") { document.getElementById('bookmarkname').disabled = true; document.getElementById('bookmarkurl').disabled = true; } else { document.getElementById('bookmarkname').disabled = false; document.getElementById('bookmarkurl').disabled = false; } if ((document.getElementById('bookmarktype').value == "separator") || ((document.getElementById("bookmarkname").value) && (document.getElementById("bookmarkurl").value))) { document.documentElement.getButton("accept").disabled = false; } else { document.documentElement.getButton("accept").disabled = true; } } function OnBookmarkOK() { var listbox = this.opener.document.getElementById(getPageId() +'.bookmarkList'); var listitem; if (window.name == 'newbookmark') { if (document.getElementById('bookmarktype').value == "separator") { listitem = listbox.appendItem("----------", ""); } else { listitem = listbox.appendItem(document.getElementById('bookmarkname').value, document.getElementById('bookmarkurl').value); } listitem.setAttribute("class", "listitem-iconic"); } else { listitem = listbox.selectedItem; if (document.getElementById('bookmarktype').value == "separator") { listitem.setAttribute("label", "----------"); listitem.setAttribute("value", ""); } else { listitem.setAttribute("label", document.getElementById('bookmarkname').value); listitem.setAttribute("value", document.getElementById('bookmarkurl').value); } } listitem.cck['type'] = document.getElementById('bookmarktype').value; if (document.getElementById('bookmarktype').value == "live") { listitem.setAttribute("image", "chrome://browser/skin/page-livemarks.png"); } else if (document.getElementById('bookmarktype').value == "separator") { listitem.setAttribute("image", ""); } else { listitem.setAttribute("image", "chrome://browser/skin/Bookmarks-folder.png"); } } function enableBookmarkButtons() { var listbox = document.getElementById(getPageId() +'.bookmarkList'); if (listbox.selectedItem) { document.getElementById(getPageId() +'editBookmarkButton').disabled = false; document.getElementById(getPageId() +'deleteBookmarkButton').disabled = false; } else { document.getElementById(getPageId() +'editBookmarkButton').disabled = true; document.getElementById(getPageId() +'deleteBookmarkButton').disabled = true; } } function onNewBrowserPlugin() { window.openDialog("chrome://cckwizard/content/plugin.xul","newplugin","chrome,centerscreen,modal"); } function onEditBrowserPlugin() { window.openDialog("chrome://cckwizard/content/plugin.xul","editplugin","chrome,centerscreen,modal"); } function OnPluginLoad() { var listbox = this.opener.document.getElementById('browserPluginList'); if (window.name == 'editplugin') { document.getElementById('pluginpath').value = listbox.selectedItem.label; document.getElementById('plugintype').value = listbox.selectedItem.value; } pluginCheckOKButton(); } function pluginCheckOKButton() { if (document.getElementById("pluginpath").value) { document.documentElement.getButton("accept").setAttribute( "disabled", "false" ); } else { document.documentElement.getButton("accept").setAttribute( "disabled", "true" ); } } function OnBrowserPluginOK() { if (!(ValidateFile('pluginpath'))) { return false; } var listbox = this.opener.document.getElementById('browserPluginList'); if (window.name == 'newplugin') { var listitem = listbox.appendItem(document.getElementById('pluginpath').value, document.getElementById('plugintype').value); } else { listbox.selectedItem.label = document.getElementById('pluginpath').value; listbox.selectedItem.value = document.getElementById('plugintype').selectedItem.value; } } function onNewRegKey() { window.openDialog("chrome://cckwizard/content/reg.xul","newreg","chrome,centerscreen,modal"); } function onEditRegKey() { window.openDialog("chrome://cckwizard/content/reg.xul","editreg","chrome,centerscreen,modal"); } function OnRegLoad() { var listbox = this.opener.document.getElementById('regList'); if (window.name == 'editreg') { document.getElementById('PrettyName').value = listbox.selectedItem.label; document.getElementById('RootKey').value = listbox.selectedItem.cck['rootkey']; document.getElementById('Key').value = listbox.selectedItem.cck['key']; document.getElementById('Name').value = listbox.selectedItem.cck['name']; document.getElementById('NameValue').value = listbox.selectedItem.cck['namevalue']; document.getElementById('Type').value = listbox.selectedItem.cck['type']; } regCheckOKButton(); } function regCheckOKButton() { if ((document.getElementById("PrettyName").value) && (document.getElementById("Key").value) && (document.getElementById("Name").value) && (document.getElementById("NameValue").value)) { document.documentElement.getButton("accept").setAttribute( "disabled", "false" ); } else { document.documentElement.getButton("accept").setAttribute( "disabled", "true" ); } } function OnRegOK() { var listbox = this.opener.document.getElementById('regList'); var listitem; if (window.name == 'newreg') { listitem = listbox.appendItem(document.getElementById('PrettyName').value, ""); } else { listitem = listbox.selectedItem; listitem.setAttribute("label", document.getElementById('PrettyName').value); } listitem.cck['rootkey'] = document.getElementById('RootKey').value; listitem.cck['key'] = document.getElementById('Key').value; listitem.cck['name'] = document.getElementById('Name').value; listitem.cck['namevalue'] = document.getElementById('NameValue').value; listitem.cck['type'] = document.getElementById('Type').value; } function RefreshDefaultSearchEngines() { var menulist; menulist = document.getElementById('defaultSearchEngine'); if (!menulist) menulist = this.opener.document.getElementById('defaultSearchEngine'); var listbox; listbox = document.getElementById('searchEngineList'); if (!listbox) listbox = this.opener.document.getElementById('searchEngineList'); var curitem = menulist.value; menulist.selectedIndex = -1; menulist.removeAllItems(); var setcuritem = false; var bundle = document.getElementById("bundle_cckwizard"); var menulistitem = menulist.appendItem(bundle.getString("useBrowserDefault"), ""); menulistitem.minWidth=menulist.width; for (var i=0; i < listbox.getRowCount(); i++) { var listitem = listbox.getItemAtIndex(i); name = listitem.getAttribute("label"); menulistitem = menulist.appendItem(name, name); if (name == curitem) setcuritem = true; menulistitem.minWidth=menulist.width; } if (setcuritem) menulist.value = curitem; else menulist.selectedIndex = 0; } function onNewSearchEngine() { window.openDialog("chrome://cckwizard/content/searchengine.xul","newsearchengine","chrome,centerscreen,modal"); } function onEditSearchEngine() { window.openDialog("chrome://cckwizard/content/searchengine.xul","editsearchengine","chrome,centerscreen,modal"); } function OnSearchEngineLoad() { var listbox = this.opener.document.getElementById('searchEngineList'); if (window.name == 'editsearchengine') { document.getElementById('searchengine').value = listbox.selectedItem.cck['engineurl']; document.getElementById('searchengineicon').value = listbox.selectedItem.cck['iconurl']; if (listbox.selectedItem.cck['iconurl'].length > 0) { document.getElementById('icon').src = listbox.selectedItem.cck['iconurl']; } else { document.getElementById('icon').src = getSearchEngineImage(listbox.selectedItem.cck['engineurl']); } } searchEngineCheckOKButton(); } function searchEngineCheckOKButton() { if (document.getElementById("searchengine").value) { document.documentElement.getButton("accept").setAttribute( "disabled", "false" ); } else { document.documentElement.getButton("accept").setAttribute( "disabled", "true" ); } if (!(document.getElementById("searchengineicon").value)) { var searchengineimage; if (searchengineimage = getSearchEngineImage(document.getElementById("searchengine").value)) { document.getElementById('icon').src = searchengineimage; document.getElementById("searchengineicon").setAttribute( "disabled", "true" ); } else { document.getElementById('icon').src = ""; document.getElementById("searchengineicon").removeAttribute( "disabled"); } } else { try { var sourcefile = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); sourcefile.initWithPath(document.getElementById('searchengineicon').value); var ioServ = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var imgfile = ioServ.newFileURI(sourcefile); document.getElementById('icon').src = imgfile.spec; } catch (ex) { document.getElementById('icon').src = ""; } } } function OnSearchEngineOK() { if (!(ValidateFile('searchengine', 'searchengineicon'))) { return false; } var listbox = this.opener.document.getElementById('searchEngineList'); var listitem; var name = getSearchEngineName(document.getElementById('searchengine').value); if (!name) { var bundle = document.getElementById("bundle_cckwizard"); gPromptService.alert(window, bundle.getString("windowTitle"), bundle.getString("searchEngine.error")); return false; } if (window.name == 'newsearchengine') { listitem = listbox.appendItem(name, ""); listitem.setAttribute("class", "listitem-iconic"); } else { listitem = listbox.selectedItem; listbox.selectedItem.label = name; } if (document.getElementById('searchengineicon').value) { var sourcefile = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); sourcefile.initWithPath(document.getElementById('searchengineicon').value); var ioServ = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var imgfile = ioServ.newFileURI(sourcefile); listitem.setAttribute("image", imgfile.spec); } else { listitem.setAttribute("image", getSearchEngineImage(document.getElementById('searchengine').value)); } listitem.cck['name'] = name; listitem.cck['engineurl'] = document.getElementById('searchengine').value; listitem.cck['iconurl'] = document.getElementById('searchengineicon').value; RefreshDefaultSearchEngines(); } /* This code was lifted from nsSearchService.js. It's only purpose is to get the name of the search engine */ const kUselessLine = /^\s*($|#)/i; function onNewCert() { window.openDialog("chrome://cckwizard/content/cert.xul","newcert","chrome,centerscreen,modal"); } function onEditCert() { window.openDialog("chrome://cckwizard/content/cert.xul","editcert","chrome,centerscreen,modal") } function OnCertLoad() { var listbox = this.opener.document.getElementById('certList'); if (window.name == 'editcert') { document.getElementById('certpath').value = listbox.selectedItem.label; var trustString = listbox.selectedItem.value; if (trustString.charAt(0) == 'C') { document.getElementById("trustSSL").checked = true; } if (trustString.charAt(2) == 'C') { document.getElementById("trustEmail").checked = true; } if (trustString.charAt(4) == 'C') { document.getElementById("trustObjSign").checked = true; } } certCheckOKButton(); } function certCheckOKButton() { if (document.getElementById("certpath").value) { document.documentElement.getButton("accept").setAttribute( "disabled", "false" ); } else { document.documentElement.getButton("accept").setAttribute( "disabled", "true" ); } } function OnCertOK() { if (!(ValidateFile('certpath'))) { return false; } var trustString = ""; if (document.getElementById("trustSSL").checked) { trustString += "C," } else { trustString += "c," } if (document.getElementById("trustEmail").checked) { trustString += "C," } else { trustString += "c," } if (document.getElementById("trustObjSign").checked) { trustString += "C" } else { trustString += "c" } var listbox = this.opener.document.getElementById('certList'); var listitem; if (window.name == 'newcert') { listitem = listbox.appendItem(document.getElementById('certpath').value, trustString); } else { listitem = listbox.selectedItem; listbox.selectedItem.label = document.getElementById('certpath').value; listbox.selectedItem.value = trustString; } } function onNewBundle() { try { var nsIFilePicker = Components.interfaces.nsIFilePicker; var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); var bundle = document.getElementById("bundle_cckwizard"); fp.init(window, bundle.getString("chooseFile"), 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 listbox = document.getElementById('bundleList'); var listitem = listbox.appendItem(fp.file.path, ""); } } catch(ex) { } } function onEditBundle() { var listbox = document.getElementById('bundleList'); var filename = listbox.selectedItem.label; var sourcefile = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); try { sourcefile.initWithPath(filename); var ioServ = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); } catch (ex) { } try { var nsIFilePicker = Components.interfaces.nsIFilePicker; var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); var bundle = document.getElementById("bundle_cckwizard"); fp.init(window, bundle.getString("chooseFile"), nsIFilePicker.modeOpen); fp.displayDirectory = sourcefile.parent; fp.defaultString = sourcefile.leafName; fp.appendFilters(nsIFilePicker.filterAll); if (fp.show() == nsIFilePicker.returnOK && fp.fileURL.spec && fp.fileURL.spec.length > 0) { listbox.selectedItem.label = fp.file.path; } } catch(ex) { } } function CreateCCK() { gPrefBranch.setCharPref("cck.path_to_zip", document.getElementById("zipLocation").value); /* ---------- */ var destdir = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); destdir.initWithPath(currentconfigpath); CCKWriteConfigFile(destdir); destdir.append("jar"); try { destdir.remove(true); } catch(ex) {} 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) if (document.getElementById("noaboutconfig").checked) CCKCopyChromeToFile("cck-config.css", destdir) var listbox = document.getElementById('certList'); for (var i=0; i < listbox.getRowCount(); i++) { var listitem = listbox.getItemAtIndex(i); CCKCopyFile(listitem.getAttribute("label"), destdir); } if (document.getElementById("ProxyType").value == "5") { CCKCopyFile(document.getElementById("autoproxyfile").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"); try { destdir.remove(true); } catch(ex) {} try { destdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775); } catch(ex) {} CCKWriteConfigFile(destdir); 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); CCKWriteCCKServiceJS(destdir); if (document.getElementById("noaboutconfig").checked) CCKCopyChromeToFile("disableAboutConfig.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("platform"); try { destdir.remove(true); destdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775); } catch(ex) {} listbox = document.getElementById('browserPluginList'); for (var i=0; i < listbox.getRowCount(); i++) { listitem = listbox.getItemAtIndex(i); var pluginsubdir = destdir.clone(); /* If there is no value, assume windows - this should only happen for migration */ if (listitem.getAttribute("value")) { pluginsubdir.append(listitem.getAttribute("value")); } else { pluginsubdir.append("WINNT_x86-msvc"); } pluginsubdir.append("plugins"); try { pluginsubdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775); } catch(ex) {} CCKCopyFile(listitem.getAttribute("label"), pluginsubdir); } listbox = document.getElementById('searchEngineList'); destdir.initWithPath(currentconfigpath); destdir.append("xpi"); destdir.append("searchplugins"); try { destdir.remove(true); if (listbox.getRowCount() > 0) destdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775); } catch(ex) {} for (var i=0; i < listbox.getRowCount(); i++) { listitem = listbox.getItemAtIndex(i); CCKCopyFile(listitem.cck['engineurl'], destdir); if (listitem.cck['iconurl'].length > 0) CCKCopyFile(listitem.cck['iconurl'], destdir); } destdir.initWithPath(currentconfigpath); destdir.append("xpi"); CCKCopyChromeToFile("chrome.manifest", destdir) CCKWriteInstallRDF(destdir); CCKWriteInstallJS(destdir); var filename = document.getElementById("filename").value; if (filename.length == 0) filename = "cck"; filename += ".xpi"; CCKZip("cck.xpi", destdir, "chrome", "components", "defaults", "platform", "searchplugins", "chrome.manifest", "install.rdf", "install.js", "cck.config"); var outputdir = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); outputdir.initWithPath(currentconfigpath); destdir.append("cck.xpi"); if (document.getElementById('bundleList').getRowCount() == 0) { outputdir.append(filename); try { outputdir.remove(true); } catch(ex) {} outputdir = outputdir.parent; destdir.copyTo(outputdir, filename); } else { var packagedir = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); packagedir.initWithPath(currentconfigpath); packagedir.append("package"); try { packagedir.remove(true); packagedir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775); } catch(ex) {} CCKCopyFile(destdir.path, packagedir); listbox = document.getElementById('bundleList'); for (var i=0; i < listbox.getRowCount(); i++) { listitem = listbox.getItemAtIndex(i); CCKCopyFile(listitem.getAttribute("label"), packagedir); } CCKCopyChromeToFile("install.rdf.mip", packagedir) packagedir.append("install.rdf.mip"); packagedir.moveTo(packagedir.parent, "install.rdf"); packagedir = packagedir.parent; CCKZip("cck.zip", packagedir, "*.xpi", "*.jar", "install.rdf"); packagedir.append("cck.zip"); outputdir.append(filename); try { outputdir.remove(true); } catch(ex) {} outputdir = outputdir.parent; packagedir.copyTo(outputdir, filename); } var bundle = document.getElementById("bundle_cckwizard"); outputdir.append(filename); gPromptService.alert(window, bundle.getString("windowTitle"), bundle.getString("outputLocation") + outputdir.path); } /* 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 ((document.getElementById("zipLocation").value == "") && (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(); return; } catch (e) { gPromptService.alert(window, "", "ZIPWriterComponent error - attempting ZIP"); } } var zipLocation = document.getElementById("zipLocation").value; if (zipLocation.length == 0) { zipLocation = "zip"; } var platform = navigator.platform; var scriptfile = location.clone(); if ((navigator.platform == "Win32") || (navigator.platform == "OS/2")) scriptfile.append("ccktemp.cmd"); else scriptfile.append("ccktemp.sh"); var fos = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance(Components.interfaces.nsIFileOutputStream); fos.init(scriptfile, -1, -1, false); var line = "cd "; // this param causes a drive switch on win32 if (navigator.platform == "Win32") line += "/d "; line += "\"" + location.path + "\"\n"; fos.write(line, line.length); var zipParams = "-r"; /* check for 7zip */ if (zipLocation.match("7z")) { zipParams = "a -tZIP"; } if ((navigator.platform == "Win32") || (navigator.platform == "OS/2")) line = "\"" + zipLocation + "\" " + zipParams + " \"" + location.path + "\\" + zipfile + "\""; else line = zipLocation + " " + zipParams + " \"" + 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") && (navigator.platform != "OS/2")) { 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") || (navigator.platform == "OS/2")) process.init(scriptfile); else process.init(sh); var args = [scriptfile.path]; try { process.run(true, args, args.length); } catch (ex) { } var file = location.clone(); file.append(zipfile); if (navigator.platform == "OS/2") { var bundle = document.getElementById("bundle_cckwizard"); gPromptService.alert(window, bundle.getString("windowTitle"), "OS/2 problem workaround - Click OK to continue"); } if (!file.exists()) { var bundle = document.getElementById("bundle_cckwizard"); gPromptService.alert(window, bundle.getString("windowTitle"), bundle.getString("zipError")); } scriptfile.remove(false); } function CCKWriteXULOverlay(destdir) { var tooltipXUL = '