Files
Mozilla/mozilla/profile/idlservices/nsProfileServices.cpp
sspitzer%netscape.com 2547d3df7b propagate errors. right now, -installer doesn't work
on the mac.  now, we through up and and tell the user, which is better than crashing.  I'm still working on getting it to work on the Mac.


git-svn-id: svn://10.0.0.236/trunk@47857 18797224-902f-48f8-a5cc-f745e15eee43
1999-09-16 23:00:21 +00:00

212 lines
4.8 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
A sample of XPConnect. This file contains an implementation of
nsIProfileServices.
*/
#include "nscore.h"
#include "nsIProfileServices.h"
#include "nsIAllocator.h"
#include "plstr.h"
#include "stdio.h"
#include "nsIProfile.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsINetSupportDialogService.h"
static NS_DEFINE_CID(kCNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
class ProfileServicesImpl : public nsIProfileServices
{
public:
ProfileServicesImpl();
virtual ~ProfileServicesImpl();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIProfile interface
NS_DECL_NSIPROFILESERVICES
private:
nsIProfile *mProfile;
};
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewProfileServices(nsIProfileServices** aProfile)
{
nsresult rv;
NS_PRECONDITION(aProfile != nsnull, "null ptr");
if (! aProfile)
return NS_ERROR_NULL_POINTER;
*aProfile = new ProfileServicesImpl();
if (! *aProfile)
return NS_ERROR_OUT_OF_MEMORY;
rv = (*aProfile)->Init();
if (NS_FAILED(rv)) {
delete *aProfile;
*aProfile = nsnull;
return rv;
}
NS_ADDREF(*aProfile);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
ProfileServicesImpl::ProfileServicesImpl()
: mProfile(nsnull)
{
NS_INIT_REFCNT();
}
ProfileServicesImpl::~ProfileServicesImpl()
{
}
NS_IMPL_ISUPPORTS(ProfileServicesImpl, nsIProfileServices::GetIID());
NS_IMETHODIMP
ProfileServicesImpl::Init()
{
nsresult rv = nsServiceManager::GetService(kProfileCID,
nsIProfile::GetIID(),
(nsISupports **)&mProfile);
return rv;
}
NS_IMETHODIMP
ProfileServicesImpl::CreateNewProfile(const char* data)
{
NS_PRECONDITION(data != nsnull, "null ptr");
if (! data)
return NS_ERROR_NULL_POINTER;
mProfile->CreateNewProfile((char *)data);
return NS_OK;
}
NS_IMETHODIMP
ProfileServicesImpl::RenameProfile(const char* oldName, const char* newName)
{
mProfile->RenameProfile(oldName, newName);
return NS_OK;
}
NS_IMETHODIMP
ProfileServicesImpl::DeleteProfile(const char* profileName, const char *canDeleteFiles)
{
NS_PRECONDITION(profileName != nsnull, "null ptr");
if (! profileName)
return NS_ERROR_NULL_POINTER;
mProfile->DeleteProfile(profileName, canDeleteFiles);
return NS_OK;
}
NS_IMETHODIMP
ProfileServicesImpl::GetProfileList(char** profileList)
{
nsString localVar;
mProfile->GetProfileList(localVar);
*profileList = PL_strdup(localVar.ToNewCString());
return NS_OK;
}
NS_IMETHODIMP
ProfileServicesImpl::StartCommunicator(const char* profileName)
{
NS_PRECONDITION(profileName != nsnull, "null ptr");
if (! profileName)
return NS_ERROR_NULL_POINTER;
mProfile->StartCommunicator(profileName);
return NS_OK;
}
NS_IMETHODIMP
ProfileServicesImpl::GetCurrentProfile(char** profileName)
{
mProfile->GetCurrentProfile(profileName);
return NS_OK;
}
NS_IMETHODIMP
ProfileServicesImpl::MigrateProfile(const char* profileName)
{
nsresult rv;
NS_PRECONDITION(profileName != nsnull, "null ptr");
if (! profileName)
return NS_ERROR_NULL_POINTER;
rv = mProfile->MigrateProfile(profileName);
if (NS_FAILED(rv)) {
nsresult rv2;
NS_WITH_SERVICE(nsIPrompt, dialog, kCNetSupportDialogCID, &rv2);
if (NS_SUCCEEDED(rv2) || dialog) {
nsString errorText("Failed to migrate the following profile: ");
errorText += profileName;
rv2 = dialog->Alert(errorText.GetUnicode());
}
}
return rv;
}
NS_IMETHODIMP
ProfileServicesImpl::ProcessPREGInfo(const char* data)
{
NS_PRECONDITION(data != nsnull, "null ptr");
if (! data)
return NS_ERROR_NULL_POINTER;
mProfile->ProcessPREGInfo((char *)data);
return NS_OK;
}
NS_IMETHODIMP
ProfileServicesImpl::CloneProfile(const char* aProfileName)
{
NS_PRECONDITION(aProfileName != nsnull, "null ptr");
if (! aProfileName)
return NS_ERROR_NULL_POINTER;
mProfile->CloneProfile(aProfileName);
return NS_OK;
}