From 4fb772d656ec689b8823fa6bfc8be33798a5d42c Mon Sep 17 00:00:00 2001 From: "bsmedberg%covad.net" Date: Mon, 14 Jun 2004 00:17:48 +0000 Subject: [PATCH] Landing semi-single-profile on the trunk (merge from the AVIARY_1_0_20040515_BRANCH). --- toolkit/profile/Makefile.in | 37 + .../profile/content/createProfileWizard.js | 224 +++++ .../profile/content/createProfileWizard.xul | 63 ++ toolkit/profile/content/profileSelection.js | 257 ++++++ toolkit/profile/content/profileSelection.xul | 88 ++ toolkit/profile/jar.mn | 10 + .../profile/locale/createProfileWizard.dtd | 0 toolkit/profile/locale/profileSelection.dtd | 49 ++ .../locale/profileSelection.properties | 0 toolkit/profile/public/Makefile.in | 53 ++ toolkit/profile/public/nsIProfileMigrator.idl | 108 +++ toolkit/profile/public/nsIToolkitProfile.idl | 63 ++ .../public/nsIToolkitProfileService.idl | 93 ++ toolkit/profile/skin/Makefile.in | 29 + toolkit/profile/skin/jar.mn | 3 + toolkit/profile/skin/profileSelection.css | 52 ++ toolkit/profile/skin/profileicon.png | Bin 0 -> 795 bytes toolkit/profile/src/Makefile.in | 55 ++ toolkit/profile/src/nsINIParser.cpp | 253 ++++++ toolkit/profile/src/nsINIParser.h | 96 ++ .../profile/src/nsToolkitProfileService.cpp | 820 ++++++++++++++++++ 21 files changed, 2353 insertions(+) create mode 100644 toolkit/profile/Makefile.in create mode 100644 toolkit/profile/content/createProfileWizard.js create mode 100644 toolkit/profile/content/createProfileWizard.xul create mode 100644 toolkit/profile/content/profileSelection.js create mode 100644 toolkit/profile/content/profileSelection.xul create mode 100644 toolkit/profile/jar.mn create mode 100644 toolkit/profile/locale/createProfileWizard.dtd create mode 100644 toolkit/profile/locale/profileSelection.dtd create mode 100644 toolkit/profile/locale/profileSelection.properties create mode 100644 toolkit/profile/public/Makefile.in create mode 100644 toolkit/profile/public/nsIProfileMigrator.idl create mode 100644 toolkit/profile/public/nsIToolkitProfile.idl create mode 100644 toolkit/profile/public/nsIToolkitProfileService.idl create mode 100644 toolkit/profile/skin/Makefile.in create mode 100644 toolkit/profile/skin/jar.mn create mode 100644 toolkit/profile/skin/profileSelection.css create mode 100644 toolkit/profile/skin/profileicon.png create mode 100644 toolkit/profile/src/Makefile.in create mode 100644 toolkit/profile/src/nsINIParser.cpp create mode 100644 toolkit/profile/src/nsINIParser.h create mode 100644 toolkit/profile/src/nsToolkitProfileService.cpp diff --git a/toolkit/profile/Makefile.in b/toolkit/profile/Makefile.in new file mode 100644 index 00000000000..8ea765c45b9 --- /dev/null +++ b/toolkit/profile/Makefile.in @@ -0,0 +1,37 @@ +# +# The contents of this file are subject to the Netscape 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/NPL/ +# +# 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 mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = public src + +# Use Qute for non-Phoenix apps +ifndef MOZ_PHOENIX +DIRS += skin +endif + + +include $(topsrcdir)/config/rules.mk diff --git a/toolkit/profile/content/createProfileWizard.js b/toolkit/profile/content/createProfileWizard.js new file mode 100644 index 00000000000..73b21f9fe2b --- /dev/null +++ b/toolkit/profile/content/createProfileWizard.js @@ -0,0 +1,224 @@ +/* + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Mozilla Communicator client code, released + * March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998-1999 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Ben Goodger (30/09/99) + * Brant Gurganus (23/03/03) + * Stefan Borggraefe (17/10/03) + * Benjamin Smedberg - 8-Apr-2004 + */ + +const C = Components.classes; +const I = Components.interfaces; + +const ToolkitProfileService = "@mozilla.org/toolkit/profile-service;1"; + +var gProfileService; +var gProfileManagerBundle; + +var gDefaultProfileParent; +var gOldProfileName; + +// The directory where the profile will be created. +var gProfileRoot; + +// Text node to display the location and name of the profile to create. +var gProfileDisplay; + +// Called once when the wizard is opened. +function initWizard() +{ + try { + gProfileService = C[ToolkitProfileService].getService(I.nsIToolkitProfileService); + gProfileManagerBundle = document.getElementById("bundle_profileManager"); + + var dirService = C["@mozilla.org/file/directory_service;1"].getService(I.nsIProperties); + gDefaultProfileParent = dirService.get("DefProfRt", I.nsIFile); + + gOldProfileName = document.getElementById("profileName").value; + + // Initialize the profile location display. + gProfileDisplay = document.getElementById("profileDisplay").firstChild; + setDisplayToDefaultFolder(); + } + catch(e) { + window.close(); + throw (e); + } +} + +// Called every time the second wizard page is displayed. +function initSecondWizardPage() +{ + var profileName = document.getElementById("profileName"); + profileName.select(); + profileName.focus(); + + // Initialize profile name validation. + checkCurrentInput(profileName.value); +} + +function setDisplayToDefaultFolder() +{ + var defaultProfileDir = gDefaultProfileParent.clone(); + defaultProfileDir.append(document.getElementById("profileName").value); + gProfileRoot = defaultProfileDir; + document.getElementById("useDefault").disabled = true; +} + +function updateProfileDisplay() +{ + gProfileDisplay.data = gProfileRoot.path; +} + +// Invoke a folder selection dialog for choosing the directory of profile storage. +function chooseProfileFolder() +{ + var newProfileRoot; + + var dirChooser = C["@mozilla.org/filepicker;1"].createInstance(I.nsIFilePicker); + dirChooser.init(window, gProfileManagerBundle.getString("chooseFolder"), + I.nsIFilePicker.modeGetFolder); + dirChooser.appendFilters(I.nsIFilePicker.filterAll); + dirChooser.show(); + newProfileRoot = dirChooser.file; + + // Disable the "Default Folder..." button when the default profile folder + // was selected manually in the File Picker. + // This is always false on Windows, until bug 221872 is fixed. + document.getElementById("useDefault").disabled = + (newProfileRoot.parent.equals(gDefaultProfileParent)); + + gProfileRoot = newProfileRoot; + updateProfileDisplay(); +} + +// Checks the current user input for validity and triggers an error message accordingly. +function checkCurrentInput(currentInput) +{ + var finishButton = document.documentElement.getButton("finish"); + var finishText = document.getElementById("finishText"); + var canAdvance; + + var errorMessage = checkProfileName(currentInput); + + if (!errorMessage) { + finishText.className = ""; + finishText.firstChild.data = gProfileManagerBundle.getString("profileFinishText"); + canAdvance = true; + } + else { + finishText.className = "error"; + finishText.firstChild.data = errorMessage; + canAdvance = false; + } + + document.documentElement.canAdvance = canAdvance; + finishButton.disabled = !canAdvance; + + updateProfileDisplay(); +} + +function updateProfileName(aNewName) { + checkCurrentInput(aNewName); + + if (gProfileRoot.leafName == gOldProfileName) { + gProfileRoot.leafName = aNewName; + updateProfileDisplay(); + } + gOldProfileName = aNewName; +} + +// Checks whether the given string is a valid profile name. +// Returns an error message describing the error in the name or "" when it's valid. +function checkProfileName(profileNameToCheck) +{ + // Check for emtpy profile name. + if (!/\S/.test(profileNameToCheck)) + return gProfileManagerBundle.getString("profileNameEmpty"); + + // Check whether all characters in the profile name are allowed. + if (/([\\*:?<>|\/\"])/.test(profileNameToCheck)) + return gProfileManagerBundle.getFormattedString("invalidChar", [RegExp.$1]); + + // Check whether a profile with the same name already exists. + if (profileExists(profileNameToCheck)) + return gProfileManagerBundle.getString("profileExists"); + + // profileNameToCheck is valid. + return ""; +} + +function profileExists(aName) +{ + var profiles = gProfileService.profiles; + while (profiles.hasMoreElements()) { + var profile = profiles.getNext().QueryInterface(I.nsIToolkitProfile); + if (profile.name.toLowerCase() == aName.toLowerCase()) + return true; + } + + return false; +} + +// Called when the first wizard page is shown. +function enableNextButton() +{ + document.documentElement.canAdvance = true; +} + +function onFinish() +{ + var profileName = document.getElementById("profileName").value; + var profile; + + // Create profile named profileName in profileRoot. + try { + profile = gProfileService.createProfile(gProfileRoot, profileName); + } + catch (e) { + var profileCreationFailed = + gProfileManagerBundle.getString("profileCreationFailed"); + var profileCreationFailedTitle = + gProfileManagerBundle.getString("profileCreationFailedTitle"); + var promptService = C["@mozilla.org/embedcomp/prompt-service;1"]. + getService(I.nsIPromptService); + promptService.alert(window, profileCreationFailedTitle, + profileCreationFailed + "\n" + e); + + return false; + } + + // window.opener is false if the Create Profile Wizard was opened from the + // command line. + if (window.opener) { + // Add new profile to the list in the Profile Manager. + window.opener.CreateProfile(profile); + } + else { + // Use the newly created Profile. + var profileLock = profile.lock(); + + var dialogParams = window.arguments[0].QueryInterface(I.nsIDialogParamBlock); + dialogParams.objects.insertElementAt(profileLock, 0, false); + } + + // Exit the wizard. + return true; +} diff --git a/toolkit/profile/content/createProfileWizard.xul b/toolkit/profile/content/createProfileWizard.xul new file mode 100644 index 00000000000..65b9be4fa31 --- /dev/null +++ b/toolkit/profile/content/createProfileWizard.xul @@ -0,0 +1,63 @@ + + + + +%brandDTD; + +%profileDTD; +]> + + + + + +