mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-19 01:10:22 +00:00
Update to generic modules and add field map support
This commit is contained in:
parent
d4e579608c
commit
1abe7ce7f9
@ -34,181 +34,8 @@ static NS_DEFINE_CID(kEudoraImportCID, NS_EUDORAIMPORT_CID);
|
||||
static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID);
|
||||
|
||||
/*
|
||||
This doesn't work for me because I need to do some
|
||||
additional work in RegisterSelf.
|
||||
However, I should be able to delegate to the generic implementation
|
||||
and just do the extra work I need?
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEudoraImport)
|
||||
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ "Eudora Import Component",
|
||||
NS_EUDORAIMPORT_CID,
|
||||
"component://mozilla/import/import-eudora",
|
||||
nsEudoraImportConstructor}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsEudoraImportModule", components)
|
||||
*/
|
||||
|
||||
// Module implementation for the Eudora import library
|
||||
class nsEudoraImportModule : public nsIModule
|
||||
{
|
||||
public:
|
||||
nsEudoraImportModule();
|
||||
virtual ~nsEudoraImportModule();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIMODULE
|
||||
|
||||
protected:
|
||||
nsresult Initialize();
|
||||
|
||||
void Shutdown();
|
||||
|
||||
PRBool mInitialized;
|
||||
nsCOMPtr<nsIGenericFactory> mFactory;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Functions used to create new instances of a given object by the
|
||||
// generic factory.
|
||||
|
||||
#define MAKE_CTOR(_iface, _name) \
|
||||
static NS_IMETHODIMP \
|
||||
CreateNew##_name(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
|
||||
{ \
|
||||
if (!aResult) { \
|
||||
return NS_ERROR_INVALID_POINTER; \
|
||||
} \
|
||||
if (aOuter) { \
|
||||
*aResult = nsnull; \
|
||||
return NS_ERROR_NO_AGGREGATION; \
|
||||
} \
|
||||
nsI##_iface* inst; \
|
||||
nsresult rv = NS_New##_name(&inst); \
|
||||
if (NS_FAILED(rv)) { \
|
||||
*aResult = nsnull; \
|
||||
return rv; \
|
||||
} \
|
||||
rv = inst->QueryInterface(aIID, aResult); \
|
||||
if (NS_FAILED(rv)) { \
|
||||
*aResult = nsnull; \
|
||||
} \
|
||||
NS_RELEASE(inst); /* get rid of extra refcnt */ \
|
||||
return rv; \
|
||||
}
|
||||
|
||||
MAKE_CTOR(ImportModule, EudoraImport)
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
|
||||
|
||||
nsEudoraImportModule::nsEudoraImportModule()
|
||||
: mInitialized(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsEudoraImportModule::~nsEudoraImportModule()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsEudoraImportModule, kIModuleIID)
|
||||
|
||||
// Perform our one-time intialization for this module
|
||||
nsresult
|
||||
nsEudoraImportModule::Initialize()
|
||||
{
|
||||
if (mInitialized) {
|
||||
return NS_OK;
|
||||
}
|
||||
mInitialized = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Shutdown this module, releasing all of the module resources
|
||||
void
|
||||
nsEudoraImportModule::Shutdown()
|
||||
{
|
||||
// Release the factory object
|
||||
mFactory = nsnull;
|
||||
}
|
||||
|
||||
// Create a factory object for creating instances of aClass.
|
||||
NS_IMETHODIMP
|
||||
nsEudoraImportModule::GetClassObject(nsIComponentManager *aCompMgr,
|
||||
const nsCID& aClass,
|
||||
const nsIID& aIID,
|
||||
void** r_classObj)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Defensive programming: Initialize *r_classObj in case of error below
|
||||
if (!r_classObj) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*r_classObj = NULL;
|
||||
|
||||
// Do one-time-only initialization if necessary
|
||||
if (!mInitialized) {
|
||||
rv = Initialize();
|
||||
if (NS_FAILED(rv)) {
|
||||
// Initialization failed! yikes!
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// Choose the appropriate factory, based on the desired instance
|
||||
// class type (aClass).
|
||||
nsCOMPtr<nsIGenericFactory> fact;
|
||||
if (aClass.Equals(kEudoraImportCID)) {
|
||||
if (!mFactory) {
|
||||
// Create and save away the factory object for creating
|
||||
// new instances of Sample. This way if we are called
|
||||
// again for the factory, we won't need to create a new
|
||||
// one.
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(mFactory),
|
||||
CreateNewEudoraImport);
|
||||
}
|
||||
fact = mFactory;
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
#ifdef DEBUG
|
||||
char* cs = aClass.ToString();
|
||||
printf("+++ nsEudoraImportModule: unable to create factory for %s\n", cs);
|
||||
nsCRT::free(cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (fact) {
|
||||
rv = fact->QueryInterface(aIID, r_classObj);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
struct Components {
|
||||
const char* mDescription;
|
||||
const nsID* mCID;
|
||||
const char* mProgID;
|
||||
};
|
||||
|
||||
// The list of components we register
|
||||
static Components gComponents[] = {
|
||||
{ "Eudora Import Component", &kEudoraImportCID,
|
||||
"component://mozilla/import/import-eudora", },
|
||||
};
|
||||
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
nsresult GetImportModulesRegKey( nsIRegistry *reg, nsRegistryKey *pKey)
|
||||
{
|
||||
nsRegistryKey nScapeKey;
|
||||
@ -237,133 +64,60 @@ nsresult GetImportModulesRegKey( nsIRegistry *reg, nsRegistryKey *pKey)
|
||||
return( rv);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEudoraImportModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation,
|
||||
const char* componentType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
NS_METHOD EudoraRegister(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec *aPath,
|
||||
const char *registryLocation,
|
||||
const char *componentType)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("*** Registering Eudora import components\n");
|
||||
#endif
|
||||
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end) {
|
||||
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
|
||||
cp->mProgID, aPath, PR_TRUE,
|
||||
PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsEudoraImportModule: unable to register %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
{
|
||||
NS_WITH_SERVICE( nsIRegistry, reg, kRegistryCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import Eudora, ERROR GETTING THE Registry\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = reg->OpenDefault();
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import Eudora, ERROR OPENING THE REGISTRY\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
nsRegistryKey importKey;
|
||||
|
||||
rv = GetImportModulesRegKey( reg, &importKey);
|
||||
if (NS_FAILED( rv)) {
|
||||
IMPORT_LOG0( "*** Import Eudora, ERROR getting Netscape/Import registry key\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
nsRegistryKey key;
|
||||
rv = reg->AddSubtree( importKey, "Eudora", &key);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
|
||||
rv = reg->SetString( key, "Supports", kEudoraSupportsString);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
char *myCID = kEudoraImportCID.ToString();
|
||||
rv = reg->SetString( key, "CLSID", myCID);
|
||||
delete [] myCID;
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
NS_WITH_SERVICE( nsIRegistry, reg, kRegistryCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import Eudora, ERROR GETTING THE Registry\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEudoraImportModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("*** Unregistering Eudora import components\n");
|
||||
#endif
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end) {
|
||||
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsEudoraImportModule: unable to unregister %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEudoraImportModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
||||
{
|
||||
if (!okToUnload) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*okToUnload = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static nsEudoraImportModule *gModule = NULL;
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
|
||||
nsIFileSpec* location,
|
||||
nsIModule** return_cobj)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_ASSERTION(return_cobj, "Null argument");
|
||||
NS_ASSERTION(gModule == NULL, "nsEudoraImportModule: Module already created.");
|
||||
|
||||
// Create an initialize the layout module instance
|
||||
nsEudoraImportModule *m = new nsEudoraImportModule();
|
||||
if (!m) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Increase refcnt and store away nsIModule interface to m in return_cobj
|
||||
rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
|
||||
rv = reg->OpenDefault();
|
||||
if (NS_FAILED(rv)) {
|
||||
delete m;
|
||||
m = nsnull;
|
||||
IMPORT_LOG0( "*** Import Eudora, ERROR OPENING THE REGISTRY\n");
|
||||
return( rv);
|
||||
}
|
||||
gModule = m; // WARNING: Weak Reference
|
||||
return rv;
|
||||
|
||||
nsRegistryKey importKey;
|
||||
|
||||
rv = GetImportModulesRegKey( reg, &importKey);
|
||||
if (NS_FAILED( rv)) {
|
||||
IMPORT_LOG0( "*** Import Eudora, ERROR getting Netscape/Import registry key\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
nsRegistryKey key;
|
||||
rv = reg->AddSubtree( importKey, "Eudora", &key);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
|
||||
rv = reg->SetString( key, "Supports", kEudoraSupportsString);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
char *myCID = kEudoraImportCID.ToString();
|
||||
rv = reg->SetString( key, "CLSID", myCID);
|
||||
delete [] myCID;
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
|
||||
return( rv);
|
||||
}
|
||||
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEudoraImport)
|
||||
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ "Text Import Component",
|
||||
NS_EUDORAIMPORT_CID,
|
||||
"component://mozilla/import/import-eudora",
|
||||
nsEudoraImportConstructor,
|
||||
&EudoraRegister,
|
||||
nsnull
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsEudoraImportModule", components)
|
||||
|
||||
|
||||
|
@ -148,6 +148,11 @@ public:
|
||||
/* unsigned long GetImportProgress (); */
|
||||
NS_IMETHOD GetImportProgress(PRUint32 *_retval);
|
||||
|
||||
NS_IMETHOD GetSampleData( PRInt32 index, PRBool *pFound, PRUnichar **pStr)
|
||||
{ return( NS_ERROR_FAILURE);}
|
||||
|
||||
NS_IMETHOD SetSampleLocation( nsIFileSpec *) { return( NS_OK); }
|
||||
|
||||
private:
|
||||
static void ReportSuccess( nsString& name, nsString *pStream);
|
||||
|
||||
@ -162,21 +167,6 @@ private:
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult NS_NewEudoraImport(nsIImportModule** aImport)
|
||||
{
|
||||
NS_PRECONDITION(aImport != nsnull, "null ptr");
|
||||
if (! aImport)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aImport = new nsEudoraImport();
|
||||
if (! *aImport)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aImport);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
@ -52,7 +52,5 @@ public:
|
||||
protected:
|
||||
};
|
||||
|
||||
extern nsresult NS_NewEudoraImport(nsIImportModule** aImport);
|
||||
|
||||
|
||||
#endif /* nsEudoraImport_h___ */
|
||||
|
@ -38,163 +38,7 @@ static NS_DEFINE_CID(kOEImportCID, NS_OEIMPORT_CID);
|
||||
static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID);
|
||||
|
||||
|
||||
// Module implementation for the Outlook Express import library
|
||||
class nsOEImportModule : public nsIModule
|
||||
{
|
||||
public:
|
||||
nsOEImportModule();
|
||||
virtual ~nsOEImportModule();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIMODULE
|
||||
|
||||
protected:
|
||||
nsresult Initialize();
|
||||
|
||||
void Shutdown();
|
||||
|
||||
PRBool mInitialized;
|
||||
nsCOMPtr<nsIGenericFactory> mFactory;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Functions used to create new instances of a given object by the
|
||||
// generic factory.
|
||||
|
||||
#define MAKE_CTOR(_iface, _name) \
|
||||
static NS_IMETHODIMP \
|
||||
CreateNew##_name(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
|
||||
{ \
|
||||
if (!aResult) { \
|
||||
return NS_ERROR_INVALID_POINTER; \
|
||||
} \
|
||||
if (aOuter) { \
|
||||
*aResult = nsnull; \
|
||||
return NS_ERROR_NO_AGGREGATION; \
|
||||
} \
|
||||
nsI##_iface* inst; \
|
||||
nsresult rv = NS_New##_name(&inst); \
|
||||
if (NS_FAILED(rv)) { \
|
||||
*aResult = nsnull; \
|
||||
return rv; \
|
||||
} \
|
||||
rv = inst->QueryInterface(aIID, aResult); \
|
||||
if (NS_FAILED(rv)) { \
|
||||
*aResult = nsnull; \
|
||||
} \
|
||||
NS_RELEASE(inst); /* get rid of extra refcnt */ \
|
||||
return rv; \
|
||||
}
|
||||
|
||||
MAKE_CTOR(ImportModule, OEImport)
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
|
||||
|
||||
nsOEImportModule::nsOEImportModule()
|
||||
: mInitialized(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsOEImportModule::~nsOEImportModule()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsOEImportModule, kIModuleIID)
|
||||
|
||||
// Perform our one-time intialization for this module
|
||||
nsresult
|
||||
nsOEImportModule::Initialize()
|
||||
{
|
||||
if (mInitialized) {
|
||||
return NS_OK;
|
||||
}
|
||||
mInitialized = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Shutdown this module, releasing all of the module resources
|
||||
void
|
||||
nsOEImportModule::Shutdown()
|
||||
{
|
||||
// Release the factory object
|
||||
mFactory = nsnull;
|
||||
}
|
||||
|
||||
// Create a factory object for creating instances of aClass.
|
||||
NS_IMETHODIMP
|
||||
nsOEImportModule::GetClassObject(nsIComponentManager *aCompMgr,
|
||||
const nsCID& aClass,
|
||||
const nsIID& aIID,
|
||||
void** r_classObj)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Defensive programming: Initialize *r_classObj in case of error below
|
||||
if (!r_classObj) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*r_classObj = NULL;
|
||||
|
||||
// Do one-time-only initialization if necessary
|
||||
if (!mInitialized) {
|
||||
rv = Initialize();
|
||||
if (NS_FAILED(rv)) {
|
||||
// Initialization failed! yikes!
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// Choose the appropriate factory, based on the desired instance
|
||||
// class type (aClass).
|
||||
nsCOMPtr<nsIGenericFactory> fact;
|
||||
if (aClass.Equals(kOEImportCID)) {
|
||||
if (!mFactory) {
|
||||
// Create and save away the factory object for creating
|
||||
// new instances of Sample. This way if we are called
|
||||
// again for the factory, we won't need to create a new
|
||||
// one.
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(mFactory),
|
||||
CreateNewOEImport);
|
||||
}
|
||||
fact = mFactory;
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
#ifdef DEBUG
|
||||
char* cs = aClass.ToString();
|
||||
printf("+++ nsOEImportModule: unable to create factory for %s\n", cs);
|
||||
nsCRT::free(cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (fact) {
|
||||
rv = fact->QueryInterface(aIID, r_classObj);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
struct Components {
|
||||
const char* mDescription;
|
||||
const nsID* mCID;
|
||||
const char* mProgID;
|
||||
};
|
||||
|
||||
// The list of components we register
|
||||
static Components gComponents[] = {
|
||||
{ "Outlook Express Import Component", &kOEImportCID,
|
||||
"component://mozilla/import/import-oe", },
|
||||
};
|
||||
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult GetImportModulesRegKey( nsIRegistry *reg, nsRegistryKey *pKey)
|
||||
{
|
||||
@ -224,133 +68,57 @@ nsresult GetImportModulesRegKey( nsIRegistry *reg, nsRegistryKey *pKey)
|
||||
return( rv);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOEImportModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation,
|
||||
const char* componentType)
|
||||
NS_METHOD OERegister(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec *aPath,
|
||||
const char *registryLocation,
|
||||
const char *componentType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsresult rv;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("*** Registering Outlook Express import components\n");
|
||||
#endif
|
||||
NS_WITH_SERVICE( nsIRegistry, reg, kRegistryCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import OExpress, ERROR GETTING THE Registry\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end) {
|
||||
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
|
||||
cp->mProgID, aPath, PR_TRUE,
|
||||
PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsOEImportModule: unable to register %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
rv = reg->OpenDefault();
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import OExpress, ERROR OPENING THE REGISTRY\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
{
|
||||
NS_WITH_SERVICE( nsIRegistry, reg, kRegistryCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import OExpress, ERROR GETTING THE Registry\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = reg->OpenDefault();
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import OExpress, ERROR OPENING THE REGISTRY\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
nsRegistryKey importKey;
|
||||
|
||||
rv = GetImportModulesRegKey( reg, &importKey);
|
||||
if (NS_FAILED( rv)) {
|
||||
IMPORT_LOG0( "*** Import OExpress, ERROR getting Netscape/Import registry key\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
nsRegistryKey key;
|
||||
rv = reg->AddSubtree( importKey, "Outlook Express", &key);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
|
||||
rv = reg->SetString( key, "Supports", kOESupportsString);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
char *myCID = kOEImportCID.ToString();
|
||||
rv = reg->SetString( key, "CLSID", myCID);
|
||||
delete [] myCID;
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOEImportModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("*** Unregistering Outlook Express import components\n");
|
||||
#endif
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end) {
|
||||
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsOEImportModule: unable to unregister %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOEImportModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
||||
{
|
||||
if (!okToUnload) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*okToUnload = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static nsOEImportModule *gModule = NULL;
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
|
||||
nsIFileSpec* location,
|
||||
nsIModule** return_cobj)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_ASSERTION(return_cobj, "Null argument");
|
||||
NS_ASSERTION(gModule == NULL, "nsOEImportModule: Module already created.");
|
||||
|
||||
// Create an initialize the layout module instance
|
||||
nsOEImportModule *m = new nsOEImportModule();
|
||||
if (!m) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Increase refcnt and store away nsIModule interface to m in return_cobj
|
||||
rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete m;
|
||||
m = nsnull;
|
||||
}
|
||||
gModule = m; // WARNING: Weak Reference
|
||||
return rv;
|
||||
nsRegistryKey importKey;
|
||||
|
||||
rv = GetImportModulesRegKey( reg, &importKey);
|
||||
if (NS_FAILED( rv)) {
|
||||
IMPORT_LOG0( "*** Import OExpress, ERROR getting Netscape/Import registry key\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
nsRegistryKey key;
|
||||
rv = reg->AddSubtree( importKey, "Outlook Express", &key);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
|
||||
rv = reg->SetString( key, "Supports", kOESupportsString);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
char *myCID = kOEImportCID.ToString();
|
||||
rv = reg->SetString( key, "CLSID", myCID);
|
||||
delete [] myCID;
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
|
||||
return( rv);
|
||||
}
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsOEImport)
|
||||
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ "Outlook Express Import Component",
|
||||
NS_OEIMPORT_CID,
|
||||
"component://mozilla/import/import-oe",
|
||||
nsOEImportConstructor,
|
||||
&OERegister,
|
||||
nsnull
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsOEImport", components)
|
||||
|
@ -136,25 +136,16 @@ public:
|
||||
/* unsigned long GetImportProgress (); */
|
||||
NS_IMETHOD GetImportProgress(PRUint32 *_retval);
|
||||
|
||||
NS_IMETHOD GetSampleData( PRInt32 index, PRBool *pFound, PRUnichar **pStr)
|
||||
{ return( NS_ERROR_FAILURE);}
|
||||
|
||||
NS_IMETHOD SetSampleLocation( nsIFileSpec *) { return( NS_OK); }
|
||||
|
||||
private:
|
||||
CWAB * m_pWab;
|
||||
};
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult NS_NewOEImport(nsIImportModule** aImport)
|
||||
{
|
||||
NS_PRECONDITION(aImport != nsnull, "null ptr");
|
||||
if (! aImport)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aImport = new nsOEImport();
|
||||
if (! *aImport)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aImport);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -54,7 +54,6 @@ public:
|
||||
protected:
|
||||
};
|
||||
|
||||
extern nsresult NS_NewOEImport(nsIImportModule** aImport);
|
||||
|
||||
|
||||
#endif /* nsOEImport_h___ */
|
||||
|
@ -38,163 +38,7 @@ static NS_DEFINE_CID(kOutlookImportCID, NS_OUTLOOKIMPORT_CID);
|
||||
static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID);
|
||||
|
||||
|
||||
// Module implementation for the Outlook Express import library
|
||||
class nsOutlookImportModule : public nsIModule
|
||||
{
|
||||
public:
|
||||
nsOutlookImportModule();
|
||||
virtual ~nsOutlookImportModule();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIMODULE
|
||||
|
||||
protected:
|
||||
nsresult Initialize();
|
||||
|
||||
void Shutdown();
|
||||
|
||||
PRBool mInitialized;
|
||||
nsCOMPtr<nsIGenericFactory> mFactory;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Functions used to create new instances of a given object by the
|
||||
// generic factory.
|
||||
|
||||
#define MAKE_CTOR(_iface, _name) \
|
||||
static NS_IMETHODIMP \
|
||||
CreateNew##_name(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
|
||||
{ \
|
||||
if (!aResult) { \
|
||||
return NS_ERROR_INVALID_POINTER; \
|
||||
} \
|
||||
if (aOuter) { \
|
||||
*aResult = nsnull; \
|
||||
return NS_ERROR_NO_AGGREGATION; \
|
||||
} \
|
||||
nsI##_iface* inst; \
|
||||
nsresult rv = NS_New##_name(&inst); \
|
||||
if (NS_FAILED(rv)) { \
|
||||
*aResult = nsnull; \
|
||||
return rv; \
|
||||
} \
|
||||
rv = inst->QueryInterface(aIID, aResult); \
|
||||
if (NS_FAILED(rv)) { \
|
||||
*aResult = nsnull; \
|
||||
} \
|
||||
NS_RELEASE(inst); /* get rid of extra refcnt */ \
|
||||
return rv; \
|
||||
}
|
||||
|
||||
MAKE_CTOR(ImportModule, OutlookImport)
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
|
||||
|
||||
nsOutlookImportModule::nsOutlookImportModule()
|
||||
: mInitialized(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsOutlookImportModule::~nsOutlookImportModule()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsOutlookImportModule, kIModuleIID)
|
||||
|
||||
// Perform our one-time intialization for this module
|
||||
nsresult
|
||||
nsOutlookImportModule::Initialize()
|
||||
{
|
||||
if (mInitialized) {
|
||||
return NS_OK;
|
||||
}
|
||||
mInitialized = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Shutdown this module, releasing all of the module resources
|
||||
void
|
||||
nsOutlookImportModule::Shutdown()
|
||||
{
|
||||
// Release the factory object
|
||||
mFactory = nsnull;
|
||||
}
|
||||
|
||||
// Create a factory object for creating instances of aClass.
|
||||
NS_IMETHODIMP
|
||||
nsOutlookImportModule::GetClassObject(nsIComponentManager *aCompMgr,
|
||||
const nsCID& aClass,
|
||||
const nsIID& aIID,
|
||||
void** r_classObj)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Defensive programming: Initialize *r_classObj in case of error below
|
||||
if (!r_classObj) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*r_classObj = NULL;
|
||||
|
||||
// Do one-time-only initialization if necessary
|
||||
if (!mInitialized) {
|
||||
rv = Initialize();
|
||||
if (NS_FAILED(rv)) {
|
||||
// Initialization failed! yikes!
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// Choose the appropriate factory, based on the desired instance
|
||||
// class type (aClass).
|
||||
nsCOMPtr<nsIGenericFactory> fact;
|
||||
if (aClass.Equals(kOutlookImportCID)) {
|
||||
if (!mFactory) {
|
||||
// Create and save away the factory object for creating
|
||||
// new instances of Sample. This way if we are called
|
||||
// again for the factory, we won't need to create a new
|
||||
// one.
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(mFactory),
|
||||
CreateNewOutlookImport);
|
||||
}
|
||||
fact = mFactory;
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
#ifdef DEBUG
|
||||
char* cs = aClass.ToString();
|
||||
printf("+++ nsOutlookImportModule: unable to create factory for %s\n", cs);
|
||||
nsCRT::free(cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (fact) {
|
||||
rv = fact->QueryInterface(aIID, r_classObj);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
struct Components {
|
||||
const char* mDescription;
|
||||
const nsID* mCID;
|
||||
const char* mProgID;
|
||||
};
|
||||
|
||||
// The list of components we register
|
||||
static Components gComponents[] = {
|
||||
{ "Outlook Import Component", &kOutlookImportCID,
|
||||
"component://mozilla/import/import-outlook", },
|
||||
};
|
||||
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult GetImportModulesRegKey( nsIRegistry *reg, nsRegistryKey *pKey)
|
||||
{
|
||||
@ -224,133 +68,58 @@ nsresult GetImportModulesRegKey( nsIRegistry *reg, nsRegistryKey *pKey)
|
||||
return( rv);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOutlookImportModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation,
|
||||
const char* componentType)
|
||||
NS_METHOD OutlookRegister(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec *aPath,
|
||||
const char *registryLocation,
|
||||
const char *componentType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsresult rv;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("*** Registering Outlook import components\n");
|
||||
#endif
|
||||
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end) {
|
||||
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
|
||||
cp->mProgID, aPath, PR_TRUE,
|
||||
PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsOutlookImportModule: unable to register %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
{
|
||||
NS_WITH_SERVICE( nsIRegistry, reg, kRegistryCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import Outlook, ERROR GETTING THE Registry\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = reg->OpenDefault();
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import Outlook, ERROR OPENING THE REGISTRY\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
nsRegistryKey importKey;
|
||||
|
||||
rv = GetImportModulesRegKey( reg, &importKey);
|
||||
if (NS_FAILED( rv)) {
|
||||
IMPORT_LOG0( "*** Import Outlook, ERROR getting Netscape/Import registry key\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
nsRegistryKey key;
|
||||
rv = reg->AddSubtree( importKey, "Outlook", &key);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
|
||||
rv = reg->SetString( key, "Supports", kOutlookSupportsString);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
char *myCID = kOutlookImportCID.ToString();
|
||||
rv = reg->SetString( key, "CLSID", myCID);
|
||||
delete [] myCID;
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
NS_WITH_SERVICE( nsIRegistry, reg, kRegistryCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import Outlook, ERROR GETTING THE Registry\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOutlookImportModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("*** Unregistering Outlook import components\n");
|
||||
#endif
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end) {
|
||||
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsOutlookImportModule: unable to unregister %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOutlookImportModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
||||
{
|
||||
if (!okToUnload) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*okToUnload = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static nsOutlookImportModule *gModule = NULL;
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
|
||||
nsIFileSpec* location,
|
||||
nsIModule** return_cobj)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_ASSERTION(return_cobj, "Null argument");
|
||||
NS_ASSERTION(gModule == NULL, "nsOutlookImportModule: Module already created.");
|
||||
|
||||
// Create an initialize the layout module instance
|
||||
nsOutlookImportModule *m = new nsOutlookImportModule();
|
||||
if (!m) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Increase refcnt and store away nsIModule interface to m in return_cobj
|
||||
rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
|
||||
rv = reg->OpenDefault();
|
||||
if (NS_FAILED(rv)) {
|
||||
delete m;
|
||||
m = nsnull;
|
||||
IMPORT_LOG0( "*** Import Outlook, ERROR OPENING THE REGISTRY\n");
|
||||
return( rv);
|
||||
}
|
||||
gModule = m; // WARNING: Weak Reference
|
||||
return rv;
|
||||
|
||||
nsRegistryKey importKey;
|
||||
|
||||
rv = GetImportModulesRegKey( reg, &importKey);
|
||||
if (NS_FAILED( rv)) {
|
||||
IMPORT_LOG0( "*** Import Outlook, ERROR getting Netscape/Import registry key\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
nsRegistryKey key;
|
||||
rv = reg->AddSubtree( importKey, "Outlook", &key);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
|
||||
rv = reg->SetString( key, "Supports", kOutlookSupportsString);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
char *myCID = kOutlookImportCID.ToString();
|
||||
rv = reg->SetString( key, "CLSID", myCID);
|
||||
delete [] myCID;
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
|
||||
return( rv);
|
||||
}
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsOutlookImport)
|
||||
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ "Outlook Import Component",
|
||||
NS_OUTLOOKIMPORT_CID,
|
||||
"component://mozilla/import/import-outlook",
|
||||
nsOutlookImportConstructor,
|
||||
&OutlookRegister,
|
||||
nsnull
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsOutlookImport", components)
|
||||
|
||||
|
@ -139,6 +139,11 @@ public:
|
||||
/* unsigned long GetImportProgress (); */
|
||||
NS_IMETHOD GetImportProgress(PRUint32 *_retval);
|
||||
|
||||
NS_IMETHOD GetSampleData( PRInt32 index, PRBool *pFound, PRUnichar **pStr)
|
||||
{ return( NS_ERROR_FAILURE);}
|
||||
|
||||
NS_IMETHOD SetSampleLocation( nsIFileSpec *) { return( NS_OK); }
|
||||
|
||||
private:
|
||||
void GetOEInterface( void);
|
||||
|
||||
@ -148,19 +153,6 @@ private:
|
||||
};
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult NS_NewOutlookImport(nsIImportModule** aImport)
|
||||
{
|
||||
NS_PRECONDITION(aImport != nsnull, "null ptr");
|
||||
if (! aImport)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aImport = new nsOutlookImport();
|
||||
if (! *aImport)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aImport);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
protected:
|
||||
};
|
||||
|
||||
extern nsresult NS_NewOutlookImport(nsIImportModule** aImport);
|
||||
|
||||
|
||||
|
||||
#endif /* nsOutlookImport_h___ */
|
||||
|
@ -138,7 +138,22 @@ interface nsIImportAddressBooks : nsISupports
|
||||
a different thread than ImportAddressBook()
|
||||
*/
|
||||
unsigned long GetImportProgress();
|
||||
|
||||
|
||||
/*
|
||||
Set the location for reading sample data, this should be the same
|
||||
as what is passed later to FindAddressBooks
|
||||
*/
|
||||
void SetSampleLocation( in nsIFileSpec location);
|
||||
|
||||
/*
|
||||
Return a string of sample data for a record, each field
|
||||
is separated by a newline (which means no newlines in the fields!)
|
||||
This is only supported by address books which use field maps and
|
||||
is used by the field map UI to allow the user to properly
|
||||
align fields to be imported.
|
||||
*/
|
||||
wstring GetSampleData( in long recordNumber, out boolean recordExists);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -71,6 +71,16 @@ interface nsIImportFieldMap : nsISupports
|
||||
*/
|
||||
void SetFieldMapByDescription( in long index, in wstring fieldDesc);
|
||||
|
||||
/*
|
||||
Return if this field is "active" in the map.
|
||||
*/
|
||||
boolean GetFieldActive( in long index);
|
||||
|
||||
/*
|
||||
Set the active state of this field
|
||||
*/
|
||||
void SetFieldActive( in long index, in boolean active);
|
||||
|
||||
/*
|
||||
Set the value of the given field in the database row
|
||||
*/
|
||||
|
@ -58,6 +58,9 @@ static NS_DEFINE_IID(kIStandardUrlIID, NS_IURL_IID);
|
||||
static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_IID(kIImportFieldMapIID, NS_IIMPORTFIELDMAP_IID);
|
||||
static NS_DEFINE_CID(kSupportsWStringCID, NS_SUPPORTS_WSTRING_CID);
|
||||
static NS_DEFINE_IID(kISupportsWStringIID, NS_ISUPPORTSWSTRING_IID);
|
||||
|
||||
|
||||
static const char *kDirectoryDataSourceRoot = "abdirectory://";
|
||||
static const char *kCardDataSourceRoot = "abcard://";
|
||||
@ -277,6 +280,35 @@ NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId, nsISuppor
|
||||
}
|
||||
}
|
||||
|
||||
if (!nsCRT::strncasecmp( dataId, "sampleData-", 11)) {
|
||||
// extra the record number
|
||||
const char *pNum = dataId + 11;
|
||||
PRInt32 rNum = 0;
|
||||
while (*pNum) {
|
||||
rNum *= 10;
|
||||
rNum += (*pNum - '0');
|
||||
pNum++;
|
||||
}
|
||||
IMPORT_LOG1( "Requesting sample data #: %ld\n", rNum);
|
||||
if (m_pInterface) {
|
||||
nsCOMPtr<nsISupportsWString> data;
|
||||
rv = nsComponentManager::CreateInstance( kSupportsWStringCID, nsnull, kISupportsWStringIID, getter_AddRefs( data));
|
||||
if (NS_FAILED( rv))
|
||||
return( rv);
|
||||
PRUnichar * pData = nsnull;
|
||||
PRBool found = PR_FALSE;
|
||||
rv = m_pInterface->GetSampleData( rNum, &found, &pData);
|
||||
if (NS_FAILED( rv))
|
||||
return( rv);
|
||||
if (found) {
|
||||
data->SetData( pData);
|
||||
*_retval = data;
|
||||
NS_ADDREF( *_retval);
|
||||
}
|
||||
nsCRT::free( pData);
|
||||
}
|
||||
}
|
||||
|
||||
return( NS_OK);
|
||||
}
|
||||
|
||||
@ -302,6 +334,8 @@ NS_IMETHODIMP nsImportGenericAddressBooks::SetData( const char *dataId, nsISuppo
|
||||
NS_IF_RELEASE( m_pLocation);
|
||||
if (item)
|
||||
item->QueryInterface( nsIFileSpec::GetIID(), (void **) &m_pLocation);
|
||||
if (m_pInterface)
|
||||
m_pInterface->SetSampleLocation( m_pLocation);
|
||||
}
|
||||
|
||||
if (!nsCRT::strcasecmp( dataId, "addressDestination")) {
|
||||
@ -322,7 +356,7 @@ NS_IMETHODIMP nsImportGenericAddressBooks::SetData( const char *dataId, nsISuppo
|
||||
if (item)
|
||||
item->QueryInterface( nsIImportFieldMap::GetIID(), (void **) &m_pFieldMap);
|
||||
}
|
||||
|
||||
|
||||
return( NS_OK);
|
||||
}
|
||||
|
||||
@ -898,6 +932,22 @@ PR_STATIC_CALLBACK( void) ImportAddressThread( void *stuff)
|
||||
if (pDestDB) {
|
||||
PRUnichar *pSuccess = nsnull;
|
||||
PRUnichar *pError = nsnull;
|
||||
|
||||
/*
|
||||
if (pData->fieldMap) {
|
||||
PRInt32 sz = 0;
|
||||
PRInt32 mapIndex;
|
||||
PRBool active;
|
||||
pData->fieldMap->GetMapSize( &sz);
|
||||
IMPORT_LOG1( "**** Field Map Size: %d\n", (int) sz);
|
||||
for (PRInt32 i = 0; i < sz; i++) {
|
||||
pData->fieldMap->GetFieldMap( i, &mapIndex);
|
||||
pData->fieldMap->GetFieldActive( i, &active);
|
||||
IMPORT_LOG3( "Field map #%d: index=%d, active=%d\n", (int) i, (int) mapIndex, (int) active);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
rv = pData->addressImport->ImportAddressBook( book,
|
||||
pDestDB, // destination
|
||||
pData->fieldMap, // fieldmap
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "nsImportFieldMap.h"
|
||||
#include "nsImportStringBundle.h"
|
||||
|
||||
#include "ImportDebug.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@ -52,6 +54,7 @@ nsImportFieldMap::nsImportFieldMap()
|
||||
NS_INIT_ISUPPORTS();
|
||||
m_numFields = 0;
|
||||
m_pFields = nsnull;
|
||||
m_pActive = nsnull;
|
||||
m_allocated = 0;
|
||||
// need to init the description array
|
||||
m_mozFieldCount = 0;
|
||||
@ -70,6 +73,9 @@ nsImportFieldMap::~nsImportFieldMap()
|
||||
{
|
||||
if (m_pFields)
|
||||
delete [] m_pFields;
|
||||
if (m_pActive)
|
||||
delete [] m_pActive;
|
||||
|
||||
nsString * pStr;
|
||||
for (PRInt32 i = 0; i < m_mozFieldCount; i++) {
|
||||
pStr = (nsString *) m_descriptions.ElementAt( i);
|
||||
@ -130,8 +136,10 @@ NS_IMETHODIMP nsImportFieldMap::DefaultFieldMap(PRInt32 size)
|
||||
nsresult rv = SetFieldMapSize( size);
|
||||
if (NS_FAILED( rv))
|
||||
return( rv);
|
||||
for (PRInt32 i = 0; i < size; i++)
|
||||
for (PRInt32 i = 0; i < size; i++) {
|
||||
m_pFields[i] = i;
|
||||
m_pActive[i] = PR_TRUE;
|
||||
}
|
||||
|
||||
return( NS_OK);
|
||||
}
|
||||
@ -184,6 +192,29 @@ NS_IMETHODIMP nsImportFieldMap::SetFieldMapByDescription(PRInt32 index, const PR
|
||||
return( SetFieldMap( index, i));
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::GetFieldActive(PRInt32 index, PRBool *active)
|
||||
{
|
||||
NS_PRECONDITION(active != nsnull, "null ptr");
|
||||
if (!active)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if ((index < 0) || (index >= m_numFields))
|
||||
return( NS_ERROR_FAILURE);
|
||||
|
||||
*active = m_pActive[index];
|
||||
return( NS_OK);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::SetFieldActive(PRInt32 index, PRBool active)
|
||||
{
|
||||
if ((index < 0) || (index >= m_numFields))
|
||||
return( NS_ERROR_FAILURE);
|
||||
|
||||
m_pActive[index] = active;
|
||||
return( NS_OK);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImportFieldMap::SetFieldValue(nsIAddrDatabase *database, nsIMdbRow *row, PRInt32 fieldNum, const PRUnichar *value)
|
||||
{
|
||||
NS_PRECONDITION(database != nsnull, "null ptr");
|
||||
@ -505,20 +536,29 @@ nsresult nsImportFieldMap::Allocate( PRInt32 newSize)
|
||||
sz += 30;
|
||||
|
||||
PRInt32 *pData = new PRInt32[ sz];
|
||||
|
||||
if (!pData)
|
||||
return( NS_ERROR_FAILURE);
|
||||
PRBool *pActive = new PRBool[sz];
|
||||
if (!pActive)
|
||||
return( NS_ERROR_FAILURE);
|
||||
|
||||
|
||||
PRInt32 i;
|
||||
for (i = 0; i < sz; i++)
|
||||
for (i = 0; i < sz; i++) {
|
||||
pData[i] = -1;
|
||||
pActive[i] = PR_TRUE;
|
||||
}
|
||||
if (m_numFields) {
|
||||
for (i = 0; i < m_numFields; i++)
|
||||
for (i = 0; i < m_numFields; i++) {
|
||||
pData[i] = m_pFields[i];
|
||||
pActive[i] = m_pActive[i];
|
||||
}
|
||||
delete [] m_pFields;
|
||||
delete [] m_pActive;
|
||||
}
|
||||
m_allocated = sz;
|
||||
m_pFields = pData;
|
||||
m_pActive = pActive;
|
||||
return( NS_OK);
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,7 @@ private:
|
||||
private:
|
||||
PRInt32 m_numFields;
|
||||
PRInt32 * m_pFields;
|
||||
PRBool * m_pActive;
|
||||
PRInt32 m_allocated;
|
||||
nsVoidArray m_descriptions;
|
||||
PRInt32 m_mozFieldCount;
|
||||
|
@ -60,7 +60,6 @@ nsresult nsTextAddress::ImportLDIF( PRBool *pAbort, const PRUnichar *pName, nsIF
|
||||
NS_IF_RELEASE( m_fieldMap);
|
||||
m_database = pDb;
|
||||
m_fieldMap = nsnull;
|
||||
NS_ADDREF( m_fieldMap);
|
||||
NS_ADDREF( m_database);
|
||||
|
||||
nsresult rv = pSrc->OpenStreamForReading();
|
||||
@ -413,16 +412,22 @@ nsresult nsTextAddress::DetermineDelim( nsIFileSpec *pSrc)
|
||||
PRInt32 lineCount = 0;
|
||||
PRInt32 tabCount = 0;
|
||||
PRInt32 commaCount = 0;
|
||||
PRInt32 tabLines = 0;
|
||||
PRInt32 commaLines = 0;
|
||||
|
||||
while (!eof && NS_SUCCEEDED( rv) && (lineCount < 50)) {
|
||||
while (!eof && NS_SUCCEEDED( rv) && (lineCount < 100)) {
|
||||
wasTruncated = PR_FALSE;
|
||||
rv = pSrc->ReadLine( &pLine, kTextAddressBufferSz, &wasTruncated);
|
||||
if (wasTruncated)
|
||||
pLine[kTextAddressBufferSz - 1] = 0;
|
||||
if (NS_SUCCEEDED( rv)) {
|
||||
lineLen = nsCRT::strlen( pLine);
|
||||
tabCount += CountFields( pLine, lineLen, 9);
|
||||
commaCount += CountFields( pLine, lineLen, ',');
|
||||
tabCount = CountFields( pLine, lineLen, 9);
|
||||
commaCount = CountFields( pLine, lineLen, ',');
|
||||
if (tabCount > commaCount)
|
||||
tabLines++;
|
||||
else if (commaCount)
|
||||
commaLines++;
|
||||
rv = pSrc->Eof( &eof);
|
||||
}
|
||||
lineCount++;
|
||||
@ -432,15 +437,10 @@ nsresult nsTextAddress::DetermineDelim( nsIFileSpec *pSrc)
|
||||
|
||||
delete [] pLine;
|
||||
|
||||
if ((commaCount <= lineCount) && (tabCount <= lineCount)) {
|
||||
IMPORT_LOG0( "*** Does not appear to be a tab or comma separated file\n");
|
||||
return( NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
if (commaCount > tabCount)
|
||||
m_delim = ',';
|
||||
else
|
||||
if (tabLines > commaLines)
|
||||
m_delim = 9;
|
||||
else
|
||||
m_delim = ',';
|
||||
|
||||
return( NS_OK);
|
||||
}
|
||||
@ -468,10 +468,14 @@ nsresult nsTextAddress::ProcessLine( const char *pLine, PRInt32 len, nsString& e
|
||||
nsCString fieldVal;
|
||||
PRInt32 fieldNum;
|
||||
PRInt32 numFields = 0;
|
||||
PRBool active;
|
||||
rv = m_fieldMap->GetMapSize( &numFields);
|
||||
for (PRInt32 i = 0; (i < numFields) && NS_SUCCEEDED( rv); i++) {
|
||||
active = PR_FALSE;
|
||||
rv = m_fieldMap->GetFieldMap( i, &fieldNum);
|
||||
if (NS_SUCCEEDED( rv)) {
|
||||
if (NS_SUCCEEDED( rv))
|
||||
rv = m_fieldMap->GetFieldActive( i, &active);
|
||||
if (NS_SUCCEEDED( rv) && active) {
|
||||
if (GetField( pLine, len, i, fieldVal, m_delim)) {
|
||||
if (fieldVal.Length()) {
|
||||
if (!newRow) {
|
||||
@ -491,7 +495,9 @@ nsresult nsTextAddress::ProcessLine( const char *pLine, PRInt32 len, nsString& e
|
||||
|
||||
}
|
||||
else {
|
||||
IMPORT_LOG1( "*** Error getting field map for index %ld\n", i);
|
||||
if (active) {
|
||||
IMPORT_LOG1( "*** Error getting field map for index %ld\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -548,7 +554,7 @@ nsresult nsTextAddress::IsLDIFFile( nsIFileSpec *pSrc, PRBool *pIsLDIF)
|
||||
char field[kMaxLDIFLen];
|
||||
PRInt32 fLen = 0;
|
||||
char * pChar;
|
||||
PRInt32 rCount = 0;
|
||||
PRInt32 rCount = 1;
|
||||
PRInt32 i;
|
||||
PRBool gotLDIF = PR_FALSE;
|
||||
PRInt32 commaCount = 0;
|
||||
@ -596,9 +602,11 @@ nsresult nsTextAddress::IsLDIFFile( nsIFileSpec *pSrc, PRBool *pIsLDIF)
|
||||
if (!nsCRT::strcmp( sLDIFFields[i], field)) {
|
||||
ldifFields++;
|
||||
gotLDIF = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -611,19 +619,23 @@ nsresult nsTextAddress::IsLDIFFile( nsIFileSpec *pSrc, PRBool *pIsLDIF)
|
||||
|
||||
delete [] pLine;
|
||||
|
||||
// Hmmm... what happened here!
|
||||
if (!rCount)
|
||||
rCount = 1;
|
||||
if (!lineCount)
|
||||
lineCount = 1;
|
||||
|
||||
ldifFields /= rCount;
|
||||
tabCount /= lineCount;
|
||||
commaCount /= lineCount;
|
||||
|
||||
/*
|
||||
if ((tabCount <= ldifFields) && (commaCount <= ldifFields) && (ldifFields > 1)) {
|
||||
*pIsLDIF = PR_TRUE;
|
||||
}
|
||||
*/
|
||||
if (rCount == 1) {
|
||||
if ((ldifFields >= 3) && (lineCount < 500))
|
||||
*pIsLDIF = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
if (ldifFields >= 3)
|
||||
*pIsLDIF = PR_TRUE;
|
||||
}
|
||||
|
||||
return( NS_OK);
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
nsresult ImportLDIF( PRBool *pAbort, const PRUnichar *pName, nsIFileSpec *pSrc, nsIAddrDatabase *pDb, nsString& errors);
|
||||
|
||||
nsresult DetermineDelim( nsIFileSpec *pSrc);
|
||||
char GetDelim( void) { return( m_delim);}
|
||||
|
||||
static nsresult IsLDIFFile( nsIFileSpec *pSrc, PRBool *pIsLDIF);
|
||||
|
||||
|
@ -39,172 +39,8 @@ static NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID);
|
||||
additional work in RegisterSelf.
|
||||
However, I should be able to delegate to the generic implementation
|
||||
and just do the extra work I need?
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEudoraImport)
|
||||
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ "Eudora Import Component",
|
||||
NS_EUDORAIMPORT_CID,
|
||||
"component://mozilla/import/import-eudora",
|
||||
nsEudoraImportConstructor}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsEudoraImportModule", components)
|
||||
*/
|
||||
|
||||
// Module implementation for the Eudora import library
|
||||
class nsTextImportModule : public nsIModule
|
||||
{
|
||||
public:
|
||||
nsTextImportModule();
|
||||
virtual ~nsTextImportModule();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIMODULE
|
||||
|
||||
protected:
|
||||
nsresult Initialize();
|
||||
|
||||
void Shutdown();
|
||||
|
||||
PRBool mInitialized;
|
||||
nsCOMPtr<nsIGenericFactory> mFactory;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Functions used to create new instances of a given object by the
|
||||
// generic factory.
|
||||
|
||||
#define MAKE_CTOR(_iface, _name) \
|
||||
static NS_IMETHODIMP \
|
||||
CreateNew##_name(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
|
||||
{ \
|
||||
if (!aResult) { \
|
||||
return NS_ERROR_INVALID_POINTER; \
|
||||
} \
|
||||
if (aOuter) { \
|
||||
*aResult = nsnull; \
|
||||
return NS_ERROR_NO_AGGREGATION; \
|
||||
} \
|
||||
nsI##_iface* inst; \
|
||||
nsresult rv = NS_New##_name(&inst); \
|
||||
if (NS_FAILED(rv)) { \
|
||||
*aResult = nsnull; \
|
||||
return rv; \
|
||||
} \
|
||||
rv = inst->QueryInterface(aIID, aResult); \
|
||||
if (NS_FAILED(rv)) { \
|
||||
*aResult = nsnull; \
|
||||
} \
|
||||
NS_RELEASE(inst); /* get rid of extra refcnt */ \
|
||||
return rv; \
|
||||
}
|
||||
|
||||
MAKE_CTOR(ImportModule, TextImport)
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
|
||||
|
||||
nsTextImportModule::nsTextImportModule()
|
||||
: mInitialized(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsTextImportModule::~nsTextImportModule()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsTextImportModule, kIModuleIID)
|
||||
|
||||
// Perform our one-time intialization for this module
|
||||
nsresult nsTextImportModule::Initialize()
|
||||
{
|
||||
if (mInitialized) {
|
||||
return NS_OK;
|
||||
}
|
||||
mInitialized = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Shutdown this module, releasing all of the module resources
|
||||
void nsTextImportModule::Shutdown()
|
||||
{
|
||||
// Release the factory object
|
||||
mFactory = nsnull;
|
||||
}
|
||||
|
||||
// Create a factory object for creating instances of aClass.
|
||||
NS_IMETHODIMP nsTextImportModule::GetClassObject(nsIComponentManager *aCompMgr,
|
||||
const nsCID& aClass,
|
||||
const nsIID& aIID,
|
||||
void** r_classObj)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Defensive programming: Initialize *r_classObj in case of error below
|
||||
if (!r_classObj) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*r_classObj = NULL;
|
||||
|
||||
// Do one-time-only initialization if necessary
|
||||
if (!mInitialized) {
|
||||
rv = Initialize();
|
||||
if (NS_FAILED(rv)) {
|
||||
// Initialization failed! yikes!
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// Choose the appropriate factory, based on the desired instance
|
||||
// class type (aClass).
|
||||
nsCOMPtr<nsIGenericFactory> fact;
|
||||
if (aClass.Equals(kTextImportCID)) {
|
||||
if (!mFactory) {
|
||||
// Create and save away the factory object for creating
|
||||
// new instances of Sample. This way if we are called
|
||||
// again for the factory, we won't need to create a new
|
||||
// one.
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(mFactory),
|
||||
CreateNewTextImport);
|
||||
}
|
||||
fact = mFactory;
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
#ifdef DEBUG
|
||||
char* cs = aClass.ToString();
|
||||
printf("+++ nsTextImportModule: unable to create factory for %s\n", cs);
|
||||
nsCRT::free(cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (fact) {
|
||||
rv = fact->QueryInterface(aIID, r_classObj);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
struct Components {
|
||||
const char* mDescription;
|
||||
const nsID* mCID;
|
||||
const char* mProgID;
|
||||
};
|
||||
|
||||
// The list of components we register
|
||||
static Components gComponents[] = {
|
||||
{ "Text Import Component", &kTextImportCID,
|
||||
"component://mozilla/import/import-text", },
|
||||
};
|
||||
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
||||
|
||||
nsresult GetImportModulesRegKey( nsIRegistry *reg, nsRegistryKey *pKey)
|
||||
{
|
||||
@ -234,132 +70,60 @@ nsresult GetImportModulesRegKey( nsIRegistry *reg, nsRegistryKey *pKey)
|
||||
return( rv);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextImportModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation,
|
||||
const char* componentType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
NS_METHOD TextRegister(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec *aPath,
|
||||
const char *registryLocation,
|
||||
const char *componentType)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("*** Registering Text import components\n");
|
||||
#endif
|
||||
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end) {
|
||||
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
|
||||
cp->mProgID, aPath, PR_TRUE,
|
||||
PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsTextImportModule: unable to register %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
{
|
||||
NS_WITH_SERVICE( nsIRegistry, reg, kRegistryCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import Text, ERROR GETTING THE Registry\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = reg->OpenDefault();
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import Text, ERROR OPENING THE REGISTRY\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
nsRegistryKey importKey;
|
||||
|
||||
rv = GetImportModulesRegKey( reg, &importKey);
|
||||
if (NS_FAILED( rv)) {
|
||||
IMPORT_LOG0( "*** Import Text, ERROR getting Netscape/Import registry key\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
nsRegistryKey key;
|
||||
rv = reg->AddSubtree( importKey, "Text", &key);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
|
||||
rv = reg->SetString( key, "Supports", kTextSupportsString);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
char *myCID = kTextImportCID.ToString();
|
||||
rv = reg->SetString( key, "CLSID", myCID);
|
||||
delete [] myCID;
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
NS_WITH_SERVICE( nsIRegistry, reg, kRegistryCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Import Text, ERROR GETTING THE Registry\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextImportModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("*** Unregistering Text import components\n");
|
||||
#endif
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end) {
|
||||
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsTextImportModule: unable to unregister %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextImportModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
||||
{
|
||||
if (!okToUnload) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*okToUnload = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static nsTextImportModule *gModule = nsnull;
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
|
||||
nsIFileSpec* location,
|
||||
nsIModule** return_cobj)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_ASSERTION(return_cobj, "Null argument");
|
||||
NS_ASSERTION(gModule == nsnull, "nsTextImportModule: Module already created.");
|
||||
|
||||
// Create an initialize the layout module instance
|
||||
nsTextImportModule *m = new nsTextImportModule();
|
||||
if (!m) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Increase refcnt and store away nsIModule interface to m in return_cobj
|
||||
rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
|
||||
rv = reg->OpenDefault();
|
||||
if (NS_FAILED(rv)) {
|
||||
delete m;
|
||||
m = nsnull;
|
||||
IMPORT_LOG0( "*** Import Text, ERROR OPENING THE REGISTRY\n");
|
||||
return( rv);
|
||||
}
|
||||
gModule = m; // WARNING: Weak Reference
|
||||
return rv;
|
||||
|
||||
nsRegistryKey importKey;
|
||||
|
||||
rv = GetImportModulesRegKey( reg, &importKey);
|
||||
if (NS_FAILED( rv)) {
|
||||
IMPORT_LOG0( "*** Import Text, ERROR getting Netscape/Import registry key\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
nsRegistryKey key;
|
||||
rv = reg->AddSubtree( importKey, "Text", &key);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
|
||||
rv = reg->SetString( key, "Supports", kTextSupportsString);
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
char *myCID = kTextImportCID.ToString();
|
||||
rv = reg->SetString( key, "CLSID", myCID);
|
||||
delete [] myCID;
|
||||
if (NS_FAILED(rv)) return( rv);
|
||||
|
||||
return( rv);
|
||||
}
|
||||
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextImport)
|
||||
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ "Text Import Component",
|
||||
NS_TEXTIMPORT_CID,
|
||||
"component://mozilla/import/import-text",
|
||||
nsTextImportConstructor,
|
||||
&TextRegister,
|
||||
nsnull
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsTextImportModule", components)
|
||||
|
||||
|
||||
|
@ -93,32 +93,27 @@ public:
|
||||
/* unsigned long GetImportProgress (); */
|
||||
NS_IMETHOD GetImportProgress(PRUint32 *_retval);
|
||||
|
||||
NS_IMETHOD GetSampleData( PRInt32 index, PRBool *pFound, PRUnichar **pStr);
|
||||
|
||||
NS_IMETHOD SetSampleLocation( nsIFileSpec *);
|
||||
|
||||
private:
|
||||
void ClearSampleFile( void);
|
||||
|
||||
static void ReportSuccess( nsString& name, nsString *pStream);
|
||||
static void SetLogs( nsString& success, nsString& error, PRUnichar **pError, PRUnichar **pSuccess);
|
||||
static void ReportError( PRInt32 errorNum, nsString& name, nsString *pStream);
|
||||
static void SanitizeSampleData( nsCString& val);
|
||||
|
||||
private:
|
||||
nsTextAddress m_text;
|
||||
PRBool m_haveDelim;
|
||||
nsIFileSpec * m_fileLoc;
|
||||
char m_delim;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult NS_NewTextImport(nsIImportModule** aImport)
|
||||
{
|
||||
NS_PRECONDITION(aImport != nsnull, "null ptr");
|
||||
if (! aImport)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aImport = new nsTextImport();
|
||||
if (! *aImport)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aImport);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@ -242,11 +237,21 @@ nsresult ImportAddressImpl::Create(nsIImportAddressBooks** aImport)
|
||||
ImportAddressImpl::ImportAddressImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
m_fileLoc = nsnull;
|
||||
m_haveDelim = PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
ImportAddressImpl::~ImportAddressImpl()
|
||||
{
|
||||
if (m_fileLoc) {
|
||||
PRBool open = PR_FALSE;
|
||||
m_fileLoc->IsStreamOpen( &open);
|
||||
if (open)
|
||||
m_fileLoc->CloseStream();
|
||||
NS_RELEASE( m_fileLoc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -294,6 +299,8 @@ NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFileSpec *pLoc, nsISupports
|
||||
if (!pLoc || !ppArray)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
ClearSampleFile();
|
||||
|
||||
*ppArray = nsnull;
|
||||
PRBool exists = PR_FALSE;
|
||||
nsresult rv = pLoc->Exists( &exists);
|
||||
@ -306,12 +313,16 @@ NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFileSpec *pLoc, nsISupports
|
||||
return( NS_ERROR_FAILURE);
|
||||
|
||||
rv = m_text.DetermineDelim( pLoc);
|
||||
|
||||
|
||||
if (NS_FAILED( rv)) {
|
||||
IMPORT_LOG0( "*** Error determining delimitter\n");
|
||||
return( rv);
|
||||
}
|
||||
|
||||
m_haveDelim = PR_TRUE;
|
||||
m_delim = m_text.GetDelim();
|
||||
|
||||
m_fileLoc = pLoc;
|
||||
NS_ADDREF( m_fileLoc);
|
||||
|
||||
/* Build an address book descriptor based on the file passed in! */
|
||||
nsCOMPtr<nsISupportsArray> array;
|
||||
@ -426,7 +437,9 @@ NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *pSour
|
||||
SetLogs( success, error, pErrorLog, pSuccessLog);
|
||||
return( NS_ERROR_NULL_POINTER);
|
||||
}
|
||||
|
||||
|
||||
ClearSampleFile();
|
||||
|
||||
PRBool abort = PR_FALSE;
|
||||
nsString name;
|
||||
PRUnichar * pName;
|
||||
@ -533,3 +546,110 @@ NS_IMETHODIMP ImportAddressImpl::GetNeedsFieldMap(nsIFileSpec *location, PRBool
|
||||
|
||||
return( NS_OK);
|
||||
}
|
||||
|
||||
void ImportAddressImpl::SanitizeSampleData( nsCString& val)
|
||||
{
|
||||
// remove any line-feeds...
|
||||
val.ReplaceSubstring( "\x0D\x0A", ", ");
|
||||
val.ReplaceChar( 13, ',');
|
||||
val.ReplaceChar( 10, ',');
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportAddressImpl::GetSampleData( PRInt32 index, PRBool *pFound, PRUnichar **pStr)
|
||||
{
|
||||
NS_PRECONDITION(pFound != nsnull, "null ptr");
|
||||
NS_PRECONDITION(pStr != nsnull, "null ptr");
|
||||
if (!pFound || !pStr)
|
||||
return( NS_ERROR_NULL_POINTER);
|
||||
|
||||
if (!m_fileLoc) {
|
||||
IMPORT_LOG0( "*** Error, called GetSampleData before SetSampleLocation\n");
|
||||
return( NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
*pStr = nsnull;
|
||||
PRBool open = PR_FALSE;
|
||||
PRUnichar term = 0;
|
||||
|
||||
if (!m_haveDelim) {
|
||||
rv = m_fileLoc->IsStreamOpen( &open);
|
||||
if (open) {
|
||||
m_fileLoc->CloseStream();
|
||||
open = PR_FALSE;
|
||||
}
|
||||
rv = m_text.DetermineDelim( m_fileLoc);
|
||||
if (NS_FAILED( rv))
|
||||
return( rv);
|
||||
m_haveDelim = PR_TRUE;
|
||||
m_delim = m_text.GetDelim();
|
||||
}
|
||||
else {
|
||||
rv = m_fileLoc->IsStreamOpen( &open);
|
||||
}
|
||||
|
||||
if (!open) {
|
||||
rv = m_fileLoc->OpenStreamForReading();
|
||||
if (NS_FAILED( rv)) {
|
||||
*pFound = PR_FALSE;
|
||||
*pStr = nsCRT::strdup( &term);
|
||||
return( NS_OK);
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32 lineLen;
|
||||
PRInt32 bufSz = 10240;
|
||||
char *pLine = new char[bufSz];
|
||||
|
||||
rv = nsTextAddress::ReadRecordNumber( m_fileLoc, pLine, bufSz, m_delim, &lineLen, index);
|
||||
if (NS_SUCCEEDED( rv)) {
|
||||
nsString str;
|
||||
nsCString field;
|
||||
PRInt32 fNum = 0;
|
||||
while (nsTextAddress::GetField( pLine, lineLen, fNum, field, m_delim)) {
|
||||
if (fNum)
|
||||
str.Append( "\n");
|
||||
SanitizeSampleData( field);
|
||||
str.Append( field);
|
||||
fNum++;
|
||||
field.Truncate();
|
||||
}
|
||||
|
||||
*pStr = nsCRT::strdup( str.GetUnicode());
|
||||
*pFound = PR_TRUE;
|
||||
|
||||
IMPORT_LOG1( "Sample data: %S\n", str.GetUnicode());
|
||||
}
|
||||
else {
|
||||
*pFound = PR_FALSE;
|
||||
*pStr = nsCRT::strdup( &term);
|
||||
}
|
||||
|
||||
delete [] pLine;
|
||||
|
||||
return( NS_OK);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ImportAddressImpl::SetSampleLocation( nsIFileSpec *pLocation)
|
||||
{
|
||||
NS_IF_RELEASE( m_fileLoc);
|
||||
m_haveDelim = PR_FALSE;
|
||||
m_fileLoc = pLocation;
|
||||
NS_IF_ADDREF( m_fileLoc);
|
||||
|
||||
return( NS_OK);
|
||||
}
|
||||
|
||||
|
||||
void ImportAddressImpl::ClearSampleFile( void)
|
||||
{
|
||||
if (m_fileLoc) {
|
||||
PRBool open = PR_FALSE;
|
||||
m_fileLoc->IsStreamOpen( &open);
|
||||
if (open)
|
||||
m_fileLoc->CloseStream();
|
||||
NS_RELEASE( m_fileLoc);
|
||||
m_fileLoc = nsnull;
|
||||
m_haveDelim = PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,6 @@ public:
|
||||
protected:
|
||||
};
|
||||
|
||||
extern nsresult NS_NewTextImport(nsIImportModule** aImport);
|
||||
|
||||
|
||||
#endif /* nsTextImport_h___ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user