more fixes for #15402, general cleanup of the profile code. Close button is now Exit. remove GetSingleProfile(), use GetFirstProfile() instead. Add ForgetCurrentProfile() for use in getting cancel to work properly.

This commit is contained in:
sspitzer%netscape.com 1999-10-07 06:57:38 +00:00
Родитель 1a94cc9c2e
Коммит d0101dc3f5
7 изменённых файлов: 85 добавлений и 65 удалений

Просмотреть файл

@ -49,7 +49,6 @@ interface nsIProfile : nsISupports {
[noscript] void getProfileDir(in string profileName,
in nsFileSpec profileDir);
readonly attribute long profileCount;
string getSingleProfile();
readonly attribute string currentProfile;
readonly attribute string firstProfile;
@ -84,8 +83,8 @@ interface nsIProfile : nsISupports {
long get4xProfileCount();
void migrateAllProfiles();
void CloneProfile(in string profileName);
void cloneProfile(in string profileName);
void forgetCurrentProfile();
};
#endif /* nsIProfile_h__ */

Просмотреть файл

@ -7,6 +7,9 @@ var content;
var wizardHash = new Array;
var firstTime = true;
var profile = Components.classes["component://netscape/profile/manager"].createInstance();
profile = profile.QueryInterface(Components.interfaces.nsIProfile);
var testMap = {
newProfile1_1: { previous: null, next: "newProfile1_2" },
newProfile1_2: { previous: "newProfile1_1", next: null},
@ -129,10 +132,20 @@ function saveData()
function onCancel()
{
// we came from the profile manager window...
if (top.window.opener)
if (top.window.opener) {
//dump("just close\n");
window.close();
else
ExitApp()
}
else {
//dump("exit\n");
try {
profile.forgetCurrentProfile();
}
catch (ex) {
dump("failed to forget current profile.\n");
}
ExitApp();
}
}
// utility functions
@ -153,13 +166,20 @@ function Finish(opener)
return null;
try {
saveData();
processCreateProfileData();
if (opener) {
opener.CreateProfile();
proceed = processCreateProfileData();
if (proceed) {
if (opener) {
opener.CreateProfile();
window.close();
}
else {
ExitApp();
}
}
}
catch (ex) {
alert("Failed to create a profile.");
return;
}
}
@ -176,23 +196,21 @@ function processCreateProfileData()
profDir = wizardHash[i];
}
}
var profile = Components.classes["component://netscape/profile/manager"].createInstance();
profile = profile.QueryInterface(Components.interfaces.nsIProfile);
try {
//dump("name,dir = " + profName + "," + profDir + "\n");
if (profName == "") {
alert("You need to enter a profile name.");
return;
return false;
}
profile.createNewProfile(profName, profDir);
profile.startCommunicator(profName);
return true;
}
catch (ex) {
alert("Failed to create a profile.");
return;
return false;
}
ExitApp();
return false;
}
function ExitApp()

Просмотреть файл

@ -32,7 +32,7 @@
</box>
<box align="horizontal" style="width: 450px;">
<spring flex="100%"/>
<titledbutton id="cancel" value="&cancel.label;" onclick="ExitApp()" align="left" style=" margin-top: 1em;"/>
<titledbutton id="cancel" value="&cancel.label;" onclick="onCancel()" align="left" style=" margin-top: 1em;"/>
<spring flex="20%"/>
<titledbutton id="back" value="&back.label;" onclick="onBack()" align="left" style="margin-top: 1em;"/>
<titledbutton id="next" value="&next.label;" onclick="onNext()" align="left" style="margin-top: 1em;"/>

Просмотреть файл

@ -89,6 +89,17 @@ function StartCommunicator()
ExitApp();
}
function onExit()
{
try {
profile.forgetCurrentProfile();
}
catch (ex) {
dump("failed to forget current profile.\n");
}
ExitApp();
}
function ExitApp()
{
// Need to call this to stop the event loop

Просмотреть файл

@ -76,7 +76,7 @@ xmlns:html="http://www.w3.org/TR/REC-html40"
</box>
<box align="horizontal">
<titledbutton value="&startCmd.label;" onclick="StartCommunicator();" />
<titledbutton value="&closeCmd.label;" onclick="ExitApp();" />
<titledbutton value="&exitCmd.label;" onclick="onExit();" />
</box>
</box>
</box>

Просмотреть файл

@ -11,5 +11,5 @@
<!ENTITY renameCmd.label "Rename...">
<!ENTITY deleteCmd.label "Delete">
<!ENTITY startCmd.label "Start">
<!ENTITY closeCmd.label "Close">
<!ENTITY exitCmd.label "Exit">
<!ENTITY windowtitle.label "Profiles and Migration">

Просмотреть файл

@ -332,13 +332,6 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
* Start up the main event loop...
*/
rv = profAppShell->Run();
char *currentProfileStr = nsnull;
rv = GetCurrentProfile(&currentProfileStr);
if (NS_FAILED(rv) || !currentProfileStr) {
return NS_ERROR_FAILURE;
}
PR_DELETE(currentProfileStr);
}
if (pregPref && PL_strcmp(isPregInfoSet, REGISTRY_TRUE_STRING) != 0)
@ -699,15 +692,14 @@ NS_IMETHODIMP nsProfile::GetProfileCount(PRInt32 *numProfiles)
// If only a single profile exists
// and returns the name of the single profile.
// Otherwise it returns the name of the first valid profile.
// Commonly used in picking the current profile name if it is not set.
NS_IMETHODIMP nsProfile::GetSingleProfile(char **profileName)
// return the name of the single profile.
// Otherwise it return the name of the first valid profile.
NS_IMETHODIMP nsProfile::GetFirstProfile(char **profileName)
{
nsresult rv = NS_OK;
#if defined(DEBUG_profile)
printf("ProfileManager : GetSingleProfile\n");
printf("ProfileManager : GetFirstProfile\n");
#endif
// Enumerate all subkeys (immediately) under the given node.
@ -855,7 +847,7 @@ nsProfile::GetCurrentProfile(char **profileName)
// if fails to get the current profile set the value to null
if (NS_FAILED(rv))
{
profileName = '\0';
*profileName = nsnull;
#if defined(DEBUG_profile)
printf("Profiles:Can't get Current Profile value.\n" );
@ -868,35 +860,12 @@ nsProfile::GetCurrentProfile(char **profileName)
printf("Registry : Couldn't get Profiles subtree.\n");
#endif
}
#if defined(DEBUG_profile)
printf("current profile = %s\n", *profileName?*profileName:"(null)");
#endif
return rv;
}
// Returns the name of the first profile in the Registry
// This is essentially GetSingleProfile(). Should go away.
// Check for dependencies.
NS_IMETHODIMP nsProfile::GetFirstProfile(char **profileName)
{
nsresult rv = NS_OK;
#if defined(DEBUG_profile)
printf("ProfileManager : GetFirstProfile\n");
#endif
rv = GetSingleProfile(profileName);
if (NS_FAILED(rv))
{
#if defined(DEBUG_profile)
printf("Couldn't get the first profile.\n" );
#endif
}
return rv;
}
// Returns the name of the current profile directory
NS_IMETHODIMP nsProfile::GetCurrentProfileDir(nsFileSpec* profileDir)
{
@ -928,11 +897,7 @@ NS_IMETHODIMP nsProfile::GetCurrentProfileDir(nsFileSpec* profileDir)
#endif
}
if (profileName) {
PR_DELETE(profileName);
}
PR_FREEIF(profileName);
return rv;
}
@ -1238,6 +1203,7 @@ NS_IMETHODIMP nsProfile::RenameProfile(const char* oldName, const char* newName)
}
mRenameCurrProfile = PR_FALSE;
}
PR_FREEIF(currProfile);
return rv;
}
@ -1306,6 +1272,31 @@ nsresult nsProfile::CopyRegKey(const char *oldProfile, const char *newProfile)
return rv;
}
NS_IMETHODIMP nsProfile::ForgetCurrentProfile()
{
nsresult rv;
rv = OpenRegistry();
if (NS_FAILED(rv)) return rv;
nsRegistryKey profileRootKey;
rv = m_reg->GetSubtree(nsIRegistry::Common, REGISTRY_PROFILE_SUBTREE_STRING, &profileRootKey);
if (NS_FAILED(rv)) return rv;
// Remove the current profile subtree from the registry.
rv = m_reg->SetString(profileRootKey, REGISTRY_CURRENT_PROFILE_STRING, "");
if (NS_FAILED(rv)) return rv;
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
if (NS_FAILED(rv)) return rv;
if (!locator) return NS_ERROR_FAILURE;
rv = locator->ForgetProfileDir();
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
// Delete a profile from the registry
// Not deleting the directories on the harddisk yet.
@ -1368,7 +1359,8 @@ NS_IMETHODIMP nsProfile::DeleteProfile(const char* profileName, const char* canD
#endif
}
}
}
PR_FREEIF(oldCurrProfile);
}
// If user asks for it, delete profile directory
if (PL_strcmp(canDeleteFiles, REGISTRY_TRUE_STRING) == 0)
@ -2025,11 +2017,10 @@ NS_IMETHODIMP nsProfile::ProcessPREGInfo(const char* data)
if (userServiceDenial.mLength > 0)
userProfileName.SetString("");
char *curProfile = nsnull;
rv = OpenRegistry();
if (NS_FAILED(rv)) return rv;
char *curProfile = nsnull;
rv = GetCurrentProfile(&curProfile);
if (NS_SUCCEEDED(rv))
@ -2093,6 +2084,7 @@ NS_IMETHODIMP nsProfile::ProcessPREGInfo(const char* data)
}
}
}
PR_FREEIF(curProfile);
return rv;
}